From fa8ec01167f4e97cc6f24fefb134bb52b692dccd Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Tue, 20 May 2025 18:49:18 -0700 Subject: [PATCH 01/10] javahome --- gradlew.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/gradlew.bat b/gradlew.bat index f9553162f..0515e38e2 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -17,6 +17,7 @@ set APP_HOME=%DIRNAME% set DEFAULT_JVM_OPTS= @rem Find java.exe +set JAVA_HOME="C:\Program Files\Android\Android Studio\jbr" if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe From ee4115658a9dca82326157815d63ed75f74e1362 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Tue, 20 May 2025 22:40:18 -0700 Subject: [PATCH 02/10] i know i shouldn't add this but doing it anyways: --- local.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 local.properties diff --git a/local.properties b/local.properties new file mode 100644 index 000000000..301ae9681 --- /dev/null +++ b/local.properties @@ -0,0 +1 @@ +sdk.dir=C:/Users/csm10495/AppData/Local/Android/Sdk \ No newline at end of file From 97a555460e9cd46bbeb71a5ba5924604d2f4cd82 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 20:33:49 -0700 Subject: [PATCH 03/10] back button is there but hangs the app --- .../core/database/entity/DatabaseEnums.kt | 4 ++- .../compat/CompatDeserializer.kt | 17 ++++++++- .../core/domain/model/SmartActionExecutor.kt | 5 ++- .../core/domain/model/action/Action.kt | 1 + .../core/domain/model/action/ActionMapper.kt | 24 +++++++++++-- .../core/domain/model/action/BackButton.kt | 36 +++++++++++++++++++ .../data/processor/ActionExecutor.kt | 2 ++ .../smart/config/domain/EditedItemsBuilder.kt | 25 ++++++++++--- .../config/domain/EditionDefaultValues.kt | 5 ++- .../brief/SmartActionsBriefViewModel.kt | 4 ++- .../ui/action/selection/ActionTypeChoices.kt | 10 +++++- .../config/ui/common/model/action/UiAction.kt | 5 +-- .../ui/common/model/action/UiBackButton.kt | 24 +++++++++++++ .../src/main/res/values/strings.xml | 6 +++- .../SmartAutoClickerService.kt | 6 +++- .../actions/ServiceActionExecutor.kt | 10 +++++- 16 files changed, 166 insertions(+), 18 deletions(-) create mode 100644 core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/BackButton.kt create mode 100644 feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt diff --git a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt index 0f7870234..5596cac2a 100644 --- a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt +++ b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt @@ -49,6 +49,8 @@ enum class ActionType { CHANGE_COUNTER, /** Send a notification. */ NOTIFICATION, + /** Press the Android back button using accessibility services. */ + BACK_BUTTON, } @@ -156,4 +158,4 @@ enum class IntentExtraType { FLOAT, SHORT, STRING -} \ No newline at end of file +} diff --git a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt index e2298f458..08022e900 100644 --- a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt +++ b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt @@ -364,9 +364,24 @@ internal open class CompatDeserializer : Deserializer { ActionType.TOGGLE_EVENT -> deserializeActionToggleEvent(jsonAction) ActionType.CHANGE_COUNTER -> deserializeActionChangeCounter(jsonAction) ActionType.NOTIFICATION -> deserializeActionNotification(jsonAction) + ActionType.BACK_BUTTON -> deserializeActionBackButton(jsonAction) null -> null } + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + open fun deserializeActionBackButton(jsonBackButton: JsonObject): ActionEntity? { + val id = jsonBackButton.getLong("id", true) ?: return null + val eventId = jsonBackButton.getLong("eventId", true) ?: return null + + return ActionEntity( + id = id, + eventId = eventId, + name = jsonBackButton.getString("name") ?: "", + priority = jsonBackButton.getInt("priority")?.coerceAtLeast(0) ?: 0, + type = ActionType.BACK_BUTTON, + ) + } + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) open fun deserializeActionClick( jsonClick: JsonObject, @@ -588,4 +603,4 @@ internal open class CompatDeserializer : Deserializer { return EventToggleEntity(id, actionId, type, toggleEventId) } -} \ No newline at end of file +} diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt index 7859390f4..68fa121b3 100644 --- a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt @@ -31,6 +31,9 @@ interface SmartActionExecutor : AndroidExecutor { /** Send a notification defined by the provided NotificationRequest. */ fun executeNotification(notification: NotificationRequest) + /** Press the Android back button using accessibility services. */ + fun executeBackButton() + /** Request to reset any state related to action execution, most likely because a new session is starting. */ fun clearState() } @@ -42,4 +45,4 @@ data class NotificationRequest( val message: String, val groupName: String, val importance: Int, -) \ No newline at end of file +) diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt index 6fe0c5c4b..90aa652df 100644 --- a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt @@ -51,5 +51,6 @@ sealed class Action : Identifiable, Completable, Prioritizable { is Swipe -> copy(id = id, eventId = eventId, name = name, priority = priority) is ToggleEvent -> copy(id = id, eventId = eventId, name = name, priority = priority) is Notification -> copy(id = id, eventId = eventId, name = name, priority = priority) + is BackButton -> copy(id = id, eventId = eventId, name = name, priority = priority) } } diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt index 70e4792b2..e5f98ab49 100644 --- a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt @@ -1,16 +1,16 @@ /* * Copyright (C) 2024 Kevin Buzeau - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -43,6 +43,7 @@ internal fun Action.toEntity(): ActionEntity { is ToggleEvent -> toToggleEventEntity() is ChangeCounter -> toChangeCounterEntity() is Notification -> toNotificationEntity() + is BackButton -> toBackButtonEntity() } } @@ -151,8 +152,25 @@ internal fun CompleteActionEntity.toDomain(cleanIds: Boolean = false): Action = ActionType.TOGGLE_EVENT -> toDomainToggleEvent(cleanIds) ActionType.CHANGE_COUNTER -> toDomainChangeCounter(cleanIds) ActionType.NOTIFICATION -> toDomainNotification(cleanIds) + ActionType.BACK_BUTTON -> toDomainBackButton(cleanIds) } +private fun BackButton.toBackButtonEntity(): ActionEntity = + ActionEntity( + id = id.databaseId, + eventId = eventId.databaseId, + priority = priority, + name = name!!, + type = ActionType.BACK_BUTTON, + ) + +private fun CompleteActionEntity.toDomainBackButton(cleanIds: Boolean = false) = BackButton( + id = Identifier(id = action.id, asTemporary = cleanIds), + eventId = Identifier(id = action.eventId, asTemporary = cleanIds), + name = action.name, + priority = action.priority, +) + private fun CompleteActionEntity.toDomainClick(cleanIds: Boolean = false) = Click( id = Identifier(id = action.id, asTemporary = cleanIds), eventId = Identifier(id = action.eventId, asTemporary = cleanIds), diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/BackButton.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/BackButton.kt new file mode 100644 index 000000000..8e915d3ee --- /dev/null +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/BackButton.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2024 Kevin Buzeau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.buzbuz.smartautoclicker.core.domain.model.action + +import com.buzbuz.smartautoclicker.core.base.identifier.Identifier + +/** Press the Android back button using accessibility services. */ +data class BackButton( + override val id: Identifier, + override val eventId: Identifier, + override val name: String?, + override var priority: Int, +) : Action() { + + override fun hashCodeNoIds(): Int { + var result = name?.hashCode() ?: 0 + result = 31 * result + priority + return result + } + + override fun deepCopy(): Action = copy() +} diff --git a/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt b/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt index c2dc2a32b..3281099b2 100644 --- a/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt +++ b/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt @@ -38,6 +38,7 @@ import com.buzbuz.smartautoclicker.core.domain.model.action.Pause import com.buzbuz.smartautoclicker.core.domain.model.action.Swipe import com.buzbuz.smartautoclicker.core.domain.model.action.ToggleEvent import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.Notification import com.buzbuz.smartautoclicker.core.domain.model.action.intent.putDomainExtra import com.buzbuz.smartautoclicker.core.domain.model.event.Event @@ -95,6 +96,7 @@ internal class ActionExecutor( is ToggleEvent -> executeToggleEvent(action) is ChangeCounter -> executeChangeCounter(action) is Notification -> executeNotification(event, action) + is BackButton -> withContext(Dispatchers.Main) { androidExecutor.executeBackButton() } } } } diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt index e550f2961..0ebdba06a 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt @@ -1,16 +1,16 @@ /* * Copyright (C) 2024 Kevin Buzeau - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -26,6 +26,7 @@ import com.buzbuz.smartautoclicker.core.base.identifier.IdentifierCreator import com.buzbuz.smartautoclicker.core.domain.IRepository import com.buzbuz.smartautoclicker.core.domain.model.CounterOperationValue import com.buzbuz.smartautoclicker.core.domain.model.action.Action +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter import com.buzbuz.smartautoclicker.core.domain.model.action.Click import com.buzbuz.smartautoclicker.core.domain.model.action.Click.PositionType @@ -303,6 +304,14 @@ class EditedItemsBuilder internal constructor( priority = 0, ) + fun createNewBackButton(context: Context): BackButton = + BackButton( + id = actionsIdCreator.generateNewIdentifier(), + eventId = getEditedEventIdOrThrow(), + name = defaultValues.backButtonName(context), + priority = 0, + ) + fun createNewActionFrom(from: Action, eventId: Identifier = getEditedEventIdOrThrow()): Action = when (from) { is Click -> createNewClickFrom(from, eventId) is Swipe -> createNewSwipeFrom(from, eventId) @@ -311,6 +320,7 @@ class EditedItemsBuilder internal constructor( is ToggleEvent -> createNewToggleEventFrom(from, eventId) is ChangeCounter -> createNewChangeCounterFrom(from, eventId) is Notification -> createNewNotificationFrom(from, eventId) + is BackButton -> createNewBackButtonFrom(from, eventId) } private fun createNewClickFrom(from: Click, eventId: Identifier): Click { @@ -327,6 +337,13 @@ class EditedItemsBuilder internal constructor( ) } + private fun createNewBackButtonFrom(from: BackButton, eventId: Identifier): BackButton = + from.copy( + id = actionsIdCreator.generateNewIdentifier(), + eventId = eventId, + name = "" + from.name, + ) + private fun createNewSwipeFrom(from: Swipe, eventId: Identifier): Swipe = from.copy( id = actionsIdCreator.generateNewIdentifier(), @@ -425,4 +442,4 @@ class EditedItemsBuilder internal constructor( ?: throw IllegalStateException("Can't create items without an edited action") private fun getEditedImageEventsCountOrThrow(): Int = editor.getEditedImageEventsCount() -} \ No newline at end of file +} diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt index 7b1789005..beac1b14d 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt @@ -83,9 +83,12 @@ internal class EditionDefaultValues(private val scenarioRepository: IRepository) fun notificationName(context: Context): String = context.getString(R.string.default_notification_name) + fun backButtonName(context: Context): String = + context.getString(R.string.item_back_button_title) + fun counterComparisonOperation(): TriggerCondition.OnCounterCountReached.ComparisonOperation = TriggerCondition.OnCounterCountReached.ComparisonOperation.EQUALS private fun isTutorialModeEnabled(): Boolean = scenarioRepository.isTutorialModeEnabled() -} \ No newline at end of file +} diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt index 77ff1bf1e..6fb825a2b 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt @@ -127,6 +127,7 @@ class SmartActionsBriefViewModel @Inject constructor( add(ActionTypeChoice.ToggleEvent) add(ActionTypeChoice.Notification) add(ActionTypeChoice.Intent) + add(ActionTypeChoice.BackButton) } }.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList()) @@ -169,6 +170,7 @@ class SmartActionsBriefViewModel @Inject constructor( ActionTypeChoice.ToggleEvent -> editionRepository.editedItemsBuilder.createNewToggleEvent(context) ActionTypeChoice.ChangeCounter -> editionRepository.editedItemsBuilder.createNewChangeCounter(context) ActionTypeChoice.Notification -> editionRepository.editedItemsBuilder.createNewNotification(context) + ActionTypeChoice.BackButton -> editionRepository.editedItemsBuilder.createNewBackButton(context) ActionTypeChoice.Copy -> throw IllegalArgumentException("Unsupported action type for creation $choice") } @@ -326,4 +328,4 @@ class SmartActionsBriefViewModel @Inject constructor( private data class BriefVisualizationState( val focusedIndex: Int, val gestureCaptureStarted: Boolean, -) \ No newline at end of file +) diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt index ee2f0a018..abeeae234 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt @@ -18,6 +18,7 @@ package com.buzbuz.smartautoclicker.feature.smart.config.ui.action.selection import com.buzbuz.smartautoclicker.core.common.overlays.dialog.implementation.DialogChoice import com.buzbuz.smartautoclicker.feature.smart.config.R +import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getBackButtonIconRes import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getChangeCounterIconRes import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getClickIconRes import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getIntentIconRes @@ -88,4 +89,11 @@ sealed class ActionTypeChoice( R.string.item_notification_desc, getNotificationIconRes(), ) -} \ No newline at end of file + + /** Back Button Action choice. */ + data object BackButton : ActionTypeChoice( + R.string.item_back_button_title, + R.string.item_back_button_desc, + getBackButtonIconRes(), + ) +} diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt index 01b22a0cf..1e89f2029 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt @@ -19,6 +19,7 @@ package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action import android.content.Context import androidx.annotation.DrawableRes import com.buzbuz.smartautoclicker.core.domain.model.action.Action +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter import com.buzbuz.smartautoclicker.core.domain.model.action.Click import com.buzbuz.smartautoclicker.core.domain.model.action.Intent @@ -55,7 +56,7 @@ internal fun Action.getIconRes(): Int = when (this) { is ToggleEvent -> getToggleEventIconRes() is ChangeCounter -> getChangeCounterIconRes() is Notification -> getNotificationIconRes() - else -> throw IllegalArgumentException("Not yet supported") + is BackButton -> getBackButtonIconRes() } internal fun Action.getActionDescription(context: Context, parent: Event, inError: Boolean): String = when (this) { @@ -66,5 +67,5 @@ internal fun Action.getActionDescription(context: Context, parent: Event, inErro is ToggleEvent -> getDescription(context, inError) is ChangeCounter -> getDescription(context, inError) is Notification -> getDescription(context, inError) - else -> throw IllegalArgumentException("Not yet supported") + is BackButton -> context.getString(com.buzbuz.smartautoclicker.feature.smart.config.R.string.item_back_button_details) } diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt new file mode 100644 index 000000000..4ea182be8 --- /dev/null +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 Kevin Buzeau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action + +import androidx.annotation.DrawableRes + +import com.buzbuz.smartautoclicker.feature.smart.config.R + +@DrawableRes +internal fun getBackButtonIconRes(): Int = R.drawable.ic_back diff --git a/feature/smart-config/src/main/res/values/strings.xml b/feature/smart-config/src/main/res/values/strings.xml index f0db1a2ba..2ce22c9ee 100644 --- a/feature/smart-config/src/main/res/values/strings.xml +++ b/feature/smart-config/src/main/res/values/strings.xml @@ -89,6 +89,10 @@ Send \"%1$s\" Send %1$s value + Back Button + Press the Android back button + Press back button + Search by event name @@ -389,4 +393,4 @@ Open the event list The icon of the application to start. - \ No newline at end of file + diff --git a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt index 97a9da7b5..1974f96ea 100644 --- a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt +++ b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt @@ -198,6 +198,10 @@ class SmartAutoClickerService : AccessibilityService(), SmartActionExecutor { userNotificationsController.showNotification(this, notification) } + override fun executeBackButton() { + serviceActionExecutor?.safePerformGlobalBack() + } + override fun clearState() { userNotificationsController.clearAll() } @@ -231,4 +235,4 @@ class SmartAutoClickerService : AccessibilityService(), SmartActionExecutor { } /** Tag for the logs. */ -private const val TAG = "SmartAutoClickerService" \ No newline at end of file +private const val TAG = "SmartAutoClickerService" diff --git a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt index dda01ca70..71bd1a3d5 100644 --- a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt +++ b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt @@ -66,9 +66,17 @@ class ServiceActionExecutor(private val service: AccessibilityService) : Dumpabl } } + fun safePerformGlobalBack() { + try { + service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK) + } catch (ex: Exception) { + Log.w(TAG, "Can't execute back button action", ex) + } + } + override fun dump(writer: PrintWriter, prefix: CharSequence) { gestureExecutor.dump(writer, prefix) } } -private const val TAG = "ServiceActionExecutor" \ No newline at end of file +private const val TAG = "ServiceActionExecutor" From 39fe32ec77ffdbc786548b9ee6727b4e0abdff07 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 20:43:49 -0700 Subject: [PATCH 04/10] works? --- .../config/ui/action/brief/BaseSmartActionUiFlow.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt index 5fcd2cda5..497175667 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt @@ -21,6 +21,7 @@ import com.buzbuz.smartautoclicker.core.common.overlays.base.BaseOverlay import com.buzbuz.smartautoclicker.core.common.permissions.model.PermissionPostNotification import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.starters.RequestNotificationPermissionActivity import com.buzbuz.smartautoclicker.core.domain.model.action.Action +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter import com.buzbuz.smartautoclicker.core.domain.model.action.Click import com.buzbuz.smartautoclicker.core.domain.model.action.Intent @@ -102,7 +103,11 @@ internal fun BaseOverlay.showActionConfigDialog(configurator: ActionConfigurator if (PermissionPostNotification().checkIfGranted(context)) NotificationDialog(actionConfigDialogListener) else newNotificationPermissionStarterOverlay(context) } - else -> throw IllegalArgumentException("Not yet supported") + is BackButton -> { + configurator.upsertEditedAction() + return + } + else -> throw IllegalArgumentException("Unsupported action type") } @@ -111,4 +116,4 @@ internal fun BaseOverlay.showActionConfigDialog(configurator: ActionConfigurator newOverlay = overlay, hideCurrent = true, ) -} \ No newline at end of file +} From a616c42bdd789324a29b1d71d4842ccdf0850859 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 20:44:14 -0700 Subject: [PATCH 05/10] no return --- .../smart/config/ui/action/brief/BaseSmartActionUiFlow.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt index 497175667..82ab66e63 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt @@ -105,7 +105,6 @@ internal fun BaseOverlay.showActionConfigDialog(configurator: ActionConfigurator } is BackButton -> { configurator.upsertEditedAction() - return } else -> throw IllegalArgumentException("Unsupported action type") } From c37a7a60c0f30723bc6c987376b028e9542964f6 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 20:45:36 -0700 Subject: [PATCH 06/10] add return back --- .../smart/config/ui/action/brief/BaseSmartActionUiFlow.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt index 82ab66e63..497175667 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt @@ -105,6 +105,7 @@ internal fun BaseOverlay.showActionConfigDialog(configurator: ActionConfigurator } is BackButton -> { configurator.upsertEditedAction() + return } else -> throw IllegalArgumentException("Unsupported action type") } From 8cb77d4ec8416b77d242ce4143aa49f704578e4e Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 21:05:55 -0700 Subject: [PATCH 07/10] Remove some local changes for testing --- gradlew.bat | 1 - local.properties | 1 - 2 files changed, 2 deletions(-) delete mode 100644 local.properties diff --git a/gradlew.bat b/gradlew.bat index 0515e38e2..f9553162f 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -17,7 +17,6 @@ set APP_HOME=%DIRNAME% set DEFAULT_JVM_OPTS= @rem Find java.exe -set JAVA_HOME="C:\Program Files\Android\Android Studio\jbr" if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe diff --git a/local.properties b/local.properties deleted file mode 100644 index 301ae9681..000000000 --- a/local.properties +++ /dev/null @@ -1 +0,0 @@ -sdk.dir=C:/Users/csm10495/AppData/Local/Android/Sdk \ No newline at end of file From 7feb67c814cdc6f3d3e0543aa3f81c8a6bd53b19 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 21:09:42 -0700 Subject: [PATCH 08/10] Log if we fail to perform the back press. Remove extra try/catch. --- .../smartautoclicker/actions/ServiceActionExecutor.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt index 71bd1a3d5..f293caf6e 100644 --- a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt +++ b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt @@ -67,10 +67,8 @@ class ServiceActionExecutor(private val service: AccessibilityService) : Dumpabl } fun safePerformGlobalBack() { - try { - service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK) - } catch (ex: Exception) { - Log.w(TAG, "Can't execute back button action", ex) + if (!service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)) { + Log.w(TAG, "Failed to execute back action") } } From 6c6c43aab755461d422c712ab11238c282cd40e3 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 21:15:09 -0700 Subject: [PATCH 09/10] Update to match style a bit more --- .../smart/config/ui/common/model/action/UiAction.kt | 2 +- .../smart/config/ui/common/model/action/UiBackButton.kt | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt index 1e89f2029..58d23b710 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt @@ -67,5 +67,5 @@ internal fun Action.getActionDescription(context: Context, parent: Event, inErro is ToggleEvent -> getDescription(context, inError) is ChangeCounter -> getDescription(context, inError) is Notification -> getDescription(context, inError) - is BackButton -> context.getString(com.buzbuz.smartautoclicker.feature.smart.config.R.string.item_back_button_details) + is BackButton -> getDescription(context) } diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt index 4ea182be8..c59c99253 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt @@ -16,9 +16,14 @@ */ package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action +import android.content.Context import androidx.annotation.DrawableRes - +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.feature.smart.config.R + @DrawableRes internal fun getBackButtonIconRes(): Int = R.drawable.ic_back + +internal fun BackButton.getDescription(context: Context): String = + context.getString(R.string.item_back_button_details) From e662036de85564828420a177cd51677303b147b7 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Wed, 21 May 2025 21:22:42 -0700 Subject: [PATCH 10/10] Re-add missing exception throws --- .../feature/smart/config/ui/common/model/action/UiAction.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt index 58d23b710..0e833942b 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt @@ -57,6 +57,7 @@ internal fun Action.getIconRes(): Int = when (this) { is ChangeCounter -> getChangeCounterIconRes() is Notification -> getNotificationIconRes() is BackButton -> getBackButtonIconRes() + else -> throw IllegalArgumentException("Not yet supported") } internal fun Action.getActionDescription(context: Context, parent: Event, inError: Boolean): String = when (this) { @@ -68,4 +69,5 @@ internal fun Action.getActionDescription(context: Context, parent: Event, inErro is ChangeCounter -> getDescription(context, inError) is Notification -> getDescription(context, inError) is BackButton -> getDescription(context) + else -> throw IllegalArgumentException("Not yet supported") }