From 6c31b67b1434d416950ba01fad105789c54dbf3a Mon Sep 17 00:00:00 2001 From: jens Date: Thu, 25 Jan 2024 16:53:43 +0100 Subject: [PATCH] Battery charging type differentiation and other fixes --- app/src/apkFlavor/AndroidManifest.xml | 3 +- .../java/com/jens/automation2/Rule.java | 19 +++++-- .../java/com/jens/automation2/Rule.java | 13 +++++ .../java/com/jens/automation2/Rule.java | 13 +++++ .../jens/automation2/ActivityMainScreen.java | 14 ++++- .../jens/automation2/ReceiverCoordinator.java | 13 +++++ .../receivers/NotificationListener.java | 13 +---- .../main/res/layout/activity_help_text.xml | 57 +++++++++++++++---- app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-it/strings.xml | 2 + app/src/main/res/values-nl/strings.xml | 2 + app/src/main/res/values-pl/strings.xml | 2 + app/src/main/res/values-ru/strings.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 17 files changed, 129 insertions(+), 34 deletions(-) diff --git a/app/src/apkFlavor/AndroidManifest.xml b/app/src/apkFlavor/AndroidManifest.xml index d1f8b475..083cd1ea 100644 --- a/app/src/apkFlavor/AndroidManifest.xml +++ b/app/src/apkFlavor/AndroidManifest.xml @@ -192,6 +192,7 @@ + + @@ -241,7 +243,6 @@ - Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4); return true; } -// else if(hasTriggerOfType(Trigger.Trigger_Enum.notification) && NotificationListener.mayRuleStillBeActivatedForPendingNotifications(this)) -// { -// Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other notifications.", 4); -// return true; -// } else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this)) { Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4); @@ -871,4 +865,17 @@ public class Rule implements Comparable return amount; } + + public static int getAmountOfActivatedRules() + { + int amount = 0; + + for(Rule r : Rule.getRuleCollection()) + { + if(r.isRuleActive()) + amount++; + } + + return amount; + } } \ No newline at end of file diff --git a/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java b/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java index 81d34a7c..80e9a86f 100644 --- a/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java @@ -838,4 +838,17 @@ public class Rule implements Comparable return amount; } + + public static int getAmountOfActivatedRules() + { + int amount = 0; + + for(Rule r : Rule.getRuleCollection()) + { + if(r.isRuleActive()) + amount++; + } + + return amount; + } } diff --git a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java index 85b05de3..904aa287 100644 --- a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java @@ -865,4 +865,17 @@ public class Rule implements Comparable return amount; } + + public static int getAmountOfActivatedRules() + { + int amount = 0; + + for(Rule r : Rule.getRuleCollection()) + { + if(r.isRuleActive()) + amount++; + } + + return amount; + } } diff --git a/app/src/main/java/com/jens/automation2/ActivityMainScreen.java b/app/src/main/java/com/jens/automation2/ActivityMainScreen.java index 16711e3b..258f6b70 100644 --- a/app/src/main/java/com/jens/automation2/ActivityMainScreen.java +++ b/app/src/main/java/com/jens/automation2/ActivityMainScreen.java @@ -526,15 +526,23 @@ public class ActivityMainScreen extends ActivityGeneric { if (Rule.getRuleCollection().size() > 0) { + if(Rule.getAmountOfActivatedRules() == 0) + { + Toast.makeText(context, context.getResources().getString(R.string.serviceWontStartNoActivatedRules), Toast.LENGTH_LONG).show(); + activityMainScreenInstance.toggleService.setChecked(false); + return; + } + if (!AutomationService.isMyServiceRunning(context)) { -// if(myServiceIntent == null) //do we need that line????? myServiceIntent = new Intent(context, AutomationService.class); myServiceIntent.putExtra("startAtBoot", startAtBoot); context.startService(myServiceIntent); - } else + } + else Miscellaneous.logEvent("w", "Service", context.getResources().getString(R.string.logServiceAlreadyRunning), 3); - } else + } + else { Toast.makeText(context, context.getResources().getString(R.string.serviceWontStart), Toast.LENGTH_LONG).show(); activityMainScreenInstance.toggleService.setChecked(false); diff --git a/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java b/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java index 65b144d2..914b56d5 100644 --- a/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java +++ b/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java @@ -469,6 +469,19 @@ public class ReceiverCoordinator } } + if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent)) + { + if(!CalendarReceiver.getInstance().isListenerRunning()) + CalendarReceiver.getInstance().startListener(AutomationService.getInstance()); + else + CalendarReceiver.armOrRearmTimer(); + } + else + { + if(CalendarReceiver.getInstance().isListenerRunning()) + CalendarReceiver.getInstance().stopListener(AutomationService.getInstance()); + } + AutomationService.updateNotification(); } } diff --git a/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java b/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java index ec94a6f5..5e66f8b3 100644 --- a/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/NotificationListener.java @@ -66,18 +66,6 @@ public class NotificationListener extends NotificationListenerService// implemen } } - public static void addUsedPair(RuleNotificationPair pair) - { - // Add pair only if it's not in the list already. - for(RuleNotificationPair usedPair : notificationUsed) - { - if(usedPair.rule.equals(pair.rule) && usedPair.notification.equals(pair.notification)) - return; - } - - notificationUsed.add(pair); - } - @Override public void onCreate() { @@ -112,6 +100,7 @@ public class NotificationListener extends NotificationListenerService// implemen synchronized boolean checkNotification(boolean created, StatusBarNotification sbn) { + //TODO: Merge with functino in Trigger class if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { lastNotification = convertNotificationToSimpleNotification(created, sbn); diff --git a/app/src/main/res/layout/activity_help_text.xml b/app/src/main/res/layout/activity_help_text.xml index ca357572..434ae673 100644 --- a/app/src/main/res/layout/activity_help_text.xml +++ b/app/src/main/res/layout/activity_help_text.xml @@ -88,21 +88,54 @@ android:textAppearance="?android:attr/textAppearanceLarge" /> - + - + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:layout_margin="10dp" > + - + android:id="@+id/tvRuleHelpText" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/helpTextRules" /> + - + + + + + + + + + + + + + + + laden nicht laden Der Typ wird nur ausgewertet, wenn das Gerät aufgeladen wird. Wenn \"Nicht laden\" ausgewählt ist, wird es bei jedem vorherigen Ladetyp ausgelöst. Wenn Sie dies auswerten möchten, sollten Sie die Verwendung der Variablen trigger/action in Betracht ziehen. + Ein Profil ist eine Sammlung von Einstellungen für Klingeltöne, Lautstärke und andere audiobezogene Einstellungen, die Sie über Regeln oder manuell anwenden können.\\n\\nEs ist auch möglich, das zuletzt aktivierte Profil als Auslöser abzufragen. Im Normalfall wird nur abgefragt, ob das Profil das zuletzt aktivierte war (unabhängig davon, ob in der Zwischenzeit bestimmte Audioeinstellungen geändert wurden). Sie können aber auch die einzelnen Einstellungen vergleichen lassen. + Es sind keine aktivierten Regeln definiert. Der Dienst wird nicht gestartet. \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4e836e00..12cce52f 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -852,4 +852,6 @@ cargando no cargando El tipo solo se evaluará si el dispositivo se está cargando. Si se elige no cargar, se disparará en cualquier tipo de carga anterior. Si desea evaluar eso, considere la posibilidad de usar las variables trigger/action. + Un perfil es una colección de ajustes para tonos de llamada, volúmenes y otros ajustes relacionados con el audio que puede aplicar desde reglas o aplicarlo manualmente.\\n\\nTambién es posible consultar el último perfil activado como disparador. En el caso normal, solo consultará si el perfil fue el último activado (independientemente de si se han cambiado configuraciones de audio específicas mientras tanto). Pero también puede comparar los ajustes individuales. + No se han definido reglas activadas. El servicio no se inicia. \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index ea188a76..d2bf3d88 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -852,4 +852,6 @@ Charge Ne charge pas Le type ne sera évalué que si l\'appareil est en charge. Si l\'option Ne pas charger est sélectionnée, elle se déclenchera à n\'importe quel type de charge précédent. Si vous souhaitez évaluer cela, envisagez d\'utiliser les variables déclencheur/action. + Un profil est un ensemble de paramètres pour les sonneries, les volumes et d\'autres paramètres liés à l\'audio que vous pouvez faire appliquer à partir de règles ou appliquer manuellement.\\n\\nIl est également possible d\'interroger le dernier profil activé en tant que déclencheur. Dans le cas normal, il ne demandera que si le profil était le dernier activé (indépendamment si des paramètres audio spécifiques ont été modifiés entre-temps). Mais vous pouvez également comparer les différents paramètres. + Aucune règle activée n\'a été définie. Le service ne démarre pas. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 8aab0c1d..ee2df3ef 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -853,4 +853,6 @@ caricamento non in carica Il tipo verrà valutato solo se il dispositivo è in carica. Se si sceglie di non caricare, si attiverà a qualsiasi tipo di ricarica precedente. Se si desidera valutarlo, prendere in considerazione l\'utilizzo delle variabili trigger/action. + Un profilo è una raccolta di impostazioni per suonerie, volumi e altre impostazioni relative all\'audio che è possibile applicare dalle regole o applicare manualmente.\\n\\nÈ anche possibile eseguire una query per l\'ultimo profilo attivato come trigger. In caso normale, chiederà solo se il profilo è stato l\'ultimo attivato (indipendentemente dal fatto che nel frattempo siano state modificate impostazioni audio specifiche). Ma è anche possibile confrontare le singole impostazioni. + Nessuna regola attivata definita. Il servizio non si avvia. diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 1f99cfa5..87972f70 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -851,5 +851,7 @@ Opladen laadt niet op Het type wordt alleen geëvalueerd als het apparaat wordt opgeladen. Als er niet wordt gekozen voor opladen, wordt het geactiveerd bij elk eerder oplaadtype. Als je dat wilt evalueren, overweeg dan om de variabelen trigger/actie te gebruiken. + Een profiel is een verzameling instellingen voor beltonen, volumes en andere audiogerelateerde instellingen die u kunt laten toepassen vanuit regels of handmatig kunt toepassen.\\n\\nHet is ook mogelijk om het laatst geactiveerde profiel als trigger op te vragen. In het normale geval zal het alleen opvragen of het profiel het laatst geactiveerde profiel was (ongeacht of specifieke audio-instellingen in de tussentijd zijn gewijzigd). Maar u kunt ook de individuele instellingen laten vergelijken. + Er zijn geen geactiveerde regels gedefinieerd. De service wordt niet gestart. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index b02f1b13..8ebc1736 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -950,4 +950,6 @@ Ładowania Nie ładuje się Typ zostanie oceniony tylko wtedy, gdy urządzenie się ładuje. Jeśli nie zostanie wybrane ładowanie, zostanie uruchomione przy dowolnym poprzednim typie ładowania. Jeśli chcesz to ocenić, rozważ użycie zmiennych trigger/action. + Profil jest zbiorem ustawień dzwonków, głośności i innych ustawień związanych z dźwiękiem, które można zastosować z reguł lub zastosować ręcznie.\\n\\nMożliwe jest również zapytanie o ostatnio aktywowany profil jako wyzwalacz. W normalnym przypadku zapyta tylko, czy profil był ostatnio aktywowany (niezależnie od tego, czy określone ustawienia dźwięku zostały zmienione w międzyczasie). Ale możesz także porównać poszczególne ustawienia. + Nie zdefiniowano aktywowanych reguł. Usługa nie uruchamia się. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index e4c96f7b..9aab9db6 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -910,4 +910,6 @@ зарядка не заряжается Тип будет оцениваться только в том случае, если устройство заряжается. Если зарядка не выбрана, он будет срабатывать при любом предыдущем типе зарядки. Если вы хотите это оценить, подумайте об использовании переменных trigger/action. + Профиль — это набор настроек рингтонов, громкости и других настроек, связанных со звуком, которые можно применить из правил или вручную.\\n\\nТакже в качестве триггера можно запросить последний активированный профиль. В обычном случае он будет запрашивать только то, был ли профиль последним активированным (независимо от того, были ли за это время изменены определенные настройки звука). Но вы также можете сравнить отдельные настройки. + Активированные правила не определены. Служба не запускается. diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 7d912da6..4c2ac2db 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -851,4 +851,6 @@ 充电 不充电 仅当设备正在充电时,才会评估类型。如果未选择充电,它将以任何以前的充电类型点火。如果要对此进行评估,请考虑使用变量 trigger/action。 + 配置文件是铃声、音量和其他音频相关设置的集合,您可以从规则中应用这些设置,也可以手动应用。\\n\\n还可以查询上次激活的配置文件作为触发器。在正常情况下,它只会查询配置文件是否是上次激活的配置文件(无论在此期间是否更改了特定的音频设置)。但您也可以比较各个设置。 + 未定义已激活的规则。服务无法启动。 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bcea4257..dd4559f7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,6 +12,7 @@ Please specify at least one trigger. Please specify at least one action. No rules defined. Service won\'t start. + No activated rules defined. Service won\'t start. Automation Service started. Version %1$s. Starting service. @@ -945,4 +946,5 @@ charging not charging The type will only be evaluated if the device is charging. If not charging is chosen, it will fire at any previous charging type. If you want to evaluate that, consider using the variables trigger/action. + A profile is a collection of settings for ringtones, volumes and other audio related settings that you can have applied from rules or apply it manually.\n\nIt is also possible to query for the last activated profile as a trigger. In the normal case it will only query if the profile was the last activated one (regardless if specific audio settings have been changed in the meantime). But you can also have the individual settings compared. \ No newline at end of file