Skip to content

Commit

Permalink
Performed additional formatting via Android Studio.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve1316 committed Apr 9, 2021
1 parent cf2bbaa commit 2bcbd7d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.accessibilityservice.GestureDescription
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Path
import android.os.Bundle
import android.util.Log
Expand Down Expand Up @@ -127,6 +129,7 @@ class MyAccessibilityService : AccessibilityService() {
*
* @param x The x coordinate of the point.
* @param y The y coordinate of the point.
* @param buttonName The name of the image to tap.
* @param ignoreWait Whether or not to not wait 0.5 seconds after dispatching the gesture.
* @param longPress Whether or not to long press.
* @return True if the tap gesture was executed successfully. False otherwise.
Expand Down Expand Up @@ -176,9 +179,9 @@ class MyAccessibilityService : AccessibilityService() {
* @return True if the scroll gesture was executed successfully. False otherwise.
*/
fun scroll(
action: AccessibilityNodeInfo.AccessibilityAction = AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN, duration: Long
= 500L, ignoreWait: Boolean = false
): Boolean {
action: AccessibilityNodeInfo.AccessibilityAction = AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN, duration: Long
= 500L, ignoreWait: Boolean = false
): Boolean {
val scrollPath = Path()

// Get certain portions of the screen's dimensions.
Expand All @@ -188,20 +191,20 @@ class MyAccessibilityService : AccessibilityService() {
val bottom: Float = (displayMetrics.heightPixels * 0.25).toFloat()

when (action) {
AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP -> {
// Create a Path to scroll the screen up starting from the bottom and swiping to the top.
scrollPath.apply {
moveTo(middle, bottom)
lineTo(middle, top)
}
}
AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN -> {
// Create a Path to scroll the screen down starting from the top and swiping to the bottom.
scrollPath.apply {
moveTo(middle, top)
lineTo(middle, bottom)
}
}
AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP -> {
// Create a Path to scroll the screen up starting from the bottom and swiping to the top.
scrollPath.apply {
moveTo(middle, bottom)
lineTo(middle, top)
}
}
AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN -> {
// Create a Path to scroll the screen down starting from the top and swiping to the bottom.
scrollPath.apply {
moveTo(middle, top)
lineTo(middle, bottom)
}
}
else -> {
Log.e(TAG, "Invalid action received.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class ImageUtils(context: Context, private val game: Game) {
// debugging purposes to see if this algorithm found the match accurately or not.
if (matchFilePath != "") {
Imgproc.rectangle(
sourceMat, matchLocation, Point(matchLocation.x + templateMat.cols(), matchLocation.y + templateMat.rows()),
Scalar(0.0, 128.0, 0.0), 5
)
sourceMat, matchLocation, Point(matchLocation.x + templateMat.cols(), matchLocation.y + templateMat.rows()),
Scalar(0.0, 128.0, 0.0), 5
)
Imgcodecs.imwrite("$matchFilePath/match.png", sourceMat)
}

Expand Down Expand Up @@ -152,11 +152,11 @@ class ImageUtils(context: Context, private val game: Game) {

// Draw a rectangle around the match and then save it to the specified file.
Imgproc.rectangle(
sourceMat, tempMatchLocation, Point(
tempMatchLocation.x + templateMat.cols(), tempMatchLocation.y +
templateMat.rows()
), Scalar(255.0, 255.0, 255.0), 5
)
sourceMat, tempMatchLocation, Point(
tempMatchLocation.x + templateMat.cols(), tempMatchLocation.y +
templateMat.rows()
), Scalar(255.0, 255.0, 255.0), 5
)
Imgcodecs.imwrite("$matchFilePath/matchAll.png", sourceMat)

// Center the location coordinates and then save it to the arrayList.
Expand All @@ -170,11 +170,11 @@ class ImageUtils(context: Context, private val game: Game) {

// Draw a rectangle around the match and then save it to the specified file.
Imgproc.rectangle(
sourceMat, tempMatchLocation, Point(
tempMatchLocation.x + templateMat.cols(), tempMatchLocation.y +
templateMat.rows()
), Scalar(255.0, 255.0, 255.0), 5
)
sourceMat, tempMatchLocation, Point(
tempMatchLocation.x + templateMat.cols(), tempMatchLocation.y +
templateMat.rows()
), Scalar(255.0, 255.0, 255.0), 5
)
Imgcodecs.imwrite("$matchFilePath/matchAll.png", sourceMat)

// Center the location coordinates and then save it to the arrayList.
Expand Down Expand Up @@ -238,7 +238,7 @@ class ImageUtils(context: Context, private val game: Game) {
var numberOfTries = tries

while (numberOfTries > 0) {
val (sourceBitmap, templateBitmap) = getBitmaps(templateName, folderName)
val (sourceBitmap, templateBitmap) = getBitmaps(templateName, folderName)

if (sourceBitmap != null && templateBitmap != null) {
val resultFlag: Boolean = match(sourceBitmap, templateBitmap)
Expand All @@ -247,9 +247,9 @@ class ImageUtils(context: Context, private val game: Game) {
if (numberOfTries <= 0) {
if (!suppressError) {
game.printToLog(
"[WARNING] Failed to find the ${templateName.toUpperCase(Locale.ROOT)} button.",
MESSAGE_TAG = TAG
)
"[WARNING] Failed to find the ${templateName.toUpperCase(Locale.ROOT)} button.",
MESSAGE_TAG = TAG
)
}

return null
Expand Down Expand Up @@ -279,7 +279,7 @@ class ImageUtils(context: Context, private val game: Game) {
val folderName = "headers"
var numberOfTries = tries
while (numberOfTries > 0) {
val (sourceBitmap, templateBitmap) = getBitmaps(templateName + "_header", folderName)
val (sourceBitmap, templateBitmap) = getBitmaps(templateName + "_header", folderName)

if (sourceBitmap != null && templateBitmap != null) {
val resultFlag: Boolean = match(sourceBitmap, templateBitmap)
Expand All @@ -292,9 +292,9 @@ class ImageUtils(context: Context, private val game: Game) {
game.wait(1.0)
} else {
game.printToLog(
"[SUCCESS] Current location confirmed to be at ${templateName.toUpperCase(Locale.ROOT)}.",
MESSAGE_TAG = TAG
)
"[SUCCESS] Current location confirmed to be at ${templateName.toUpperCase(Locale.ROOT)}.",
MESSAGE_TAG = TAG
)
return true
}
} else {
Expand All @@ -304,9 +304,9 @@ class ImageUtils(context: Context, private val game: Game) {

if (!suppressError) {
game.printToLog(
"[WARNING] Failed to confirm the bot's location at ${templateName.toUpperCase(Locale.ROOT)}.",
MESSAGE_TAG = TAG
)
"[WARNING] Failed to confirm the bot's location at ${templateName.toUpperCase(Locale.ROOT)}.",
MESSAGE_TAG = TAG
)
}

return false
Expand Down Expand Up @@ -338,7 +338,7 @@ class ImageUtils(context: Context, private val game: Game) {
while (summonLocation == null && summonIndex <= summonList.size) {
// Go through each Summon detected on the Summon Selection screen and see if they match with the selected Summon.
val summonName = summonList[summonIndex]
val (sourceBitmap, templateBitmap) = getBitmaps(summonName, folderName)
val (sourceBitmap, templateBitmap) = getBitmaps(summonName, folderName)

if (sourceBitmap != null && templateBitmap != null && match(sourceBitmap, templateBitmap)) {
summonLocation = matchLocation
Expand Down Expand Up @@ -388,7 +388,7 @@ class ImageUtils(context: Context, private val game: Game) {
var numberOfTries = tries

while (numberOfTries > 0) {
val (sourceBitmap, templateBitmap) = getBitmaps(templateName, folderName)
val (sourceBitmap, templateBitmap) = getBitmaps(templateName, folderName)

if (sourceBitmap != null && templateBitmap != null) {
val resultFlag: Boolean = match(sourceBitmap, templateBitmap)
Expand Down Expand Up @@ -428,8 +428,8 @@ class ImageUtils(context: Context, private val game: Game) {
} else {
"items"
}
val (sourceBitmap, templateBitmap) = getBitmaps(templateName, folderName)
val (sourceBitmap, templateBitmap) = getBitmaps(templateName, folderName)

// Clear the ArrayList first before attempting to find all matches.
matchLocations.clear()
Expand Down Expand Up @@ -462,15 +462,15 @@ class ImageUtils(context: Context, private val game: Game) {
val itemLocations: ArrayList<Point> = findAll(templateName, isItem = true)

// Grab a reference to the source bitmap.
val (sourceBitmap, _) = getBitmaps(templateName, "items")
val (sourceBitmap, _) = getBitmaps(templateName, "items")

if (sourceBitmap != null) {
for (itemLocation in itemLocations) {
// Crop the source bitmap to hold only the item amount.
val croppedItemAmountBitmap = Bitmap.createBitmap(
sourceBitmap, (itemLocation.x + 50).toInt(), (itemLocation.y).toInt() - 10,
35, 50
)
sourceBitmap, (itemLocation.x + 50).toInt(), (itemLocation.y).toInt() - 10,
35, 50
)

// Create a InputImage object for Google's ML OCR.
val inputImage = InputImage.fromBitmap(croppedItemAmountBitmap, 0)
Expand Down

0 comments on commit 2bcbd7d

Please # to comment.