notification dismiss with button

This commit is contained in:
jens 2022-07-24 14:22:17 +02:00
parent f97bfbb732
commit d17e8b70fe
10 changed files with 100 additions and 40 deletions

View File

@ -336,6 +336,14 @@ public class Action
if (parts.length > 4 && !StringUtils.isBlank(parts[4]))
returnString.append(", " + Miscellaneous.getAnyContext().getResources().getString(R.string.ifString) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.text) + " " + Trigger.getMatchString(parts[3]) + " " + parts[4]);
if(parts.length >= 6)
{
if(!parts[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
{
returnString.append(" " + String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.withButton), parts[5]));
}
}
}
else if(this.getAction().equals(Action_Enum.setWifi))
{

View File

@ -125,11 +125,14 @@ public class Actions
String myTitleDir = params[1];
String requiredTitle = params[2];
String myTextDir = params[3];
String requiredText;
if (params.length >= 5)
String requiredText = "";
String method = ActivityManageActionCloseNotification.dismissRegularString;
if(params.length >= 5)
requiredText = params[4];
else
requiredText = "";
if(params.length >= 6 && !params[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
method = params[5];
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
{
@ -183,7 +186,12 @@ public class Actions
Miscellaneous.logEvent("i", "NotificationCloseCheck", "All criteria matches. Closing notification: " + sbn.getNotification().toString(), 3);
if(NotificationListener.getInstance() != null)
NotificationListener.getInstance().dismissNotification(sbn);
{
if(method == ActivityManageActionCloseNotification.dismissRegularString)
NotificationListener.getInstance().dismissNotification(sbn);
else
NotificationListener.getInstance().clickNotificationButton(sbn, method);
}
else
Miscellaneous.logEvent("i", "NotificationCloseCheck", "NotificationListener instance is null. Can\'t close notification.", 3);
}

View File

@ -314,13 +314,6 @@ public class ActivityManageActionCloseNotification extends Activity
String text = etNotificationText.getText().toString();
Intent responseData = new Intent();
// if(edit)
// {
// responseData.putExtra(ActivityManageRule.intentNameActionParameter2, app + Action.actionParameter2Split + titleDir + Action.actionParameter2Split + title + Action.actionParameter2Split + textDir + Action.actionParameter2Split + text);
// ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
// }
// else
// {
String dismissMethod;
if (rbNotificationDismissSimple.isChecked())
@ -336,17 +329,16 @@ public class ActivityManageActionCloseNotification extends Activity
dismissMethod = etNotificationDismissalButtonText.getText().toString();
}
responseData.putExtra(ActivityManageRule.intentNameActionParameter2,
app + Action.actionParameter2Split +
titleDir + Action.actionParameter2Split +
title + Action.actionParameter2Split +
textDir + Action.actionParameter2Split +
text + Action.actionParameter2Split +
dismissMethod
);
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
// }
responseData.putExtra(ActivityManageRule.intentNameActionParameter2,
app + Action.actionParameter2Split +
titleDir + Action.actionParameter2Split +
title + Action.actionParameter2Split +
textDir + Action.actionParameter2Split +
text + Action.actionParameter2Split +
dismissMethod
);
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
finish();
}
});
@ -387,14 +379,17 @@ public class ActivityManageActionCloseNotification extends Activity
be incorrectly interpreted as a text notification text.
*/
if (params.length >= 6)
if (params.length >= 6 && !params[5].equals(dismissRegularString))
{
rbNotificationDismissButton.setChecked(true);
etNotificationDismissalButtonText.setText(params[5]);
etNotificationDismissalButtonText.setEnabled(true);
}
else
{
rbNotificationDismissSimple.setChecked(true);
etNotificationDismissalButtonText.setText("");
etNotificationDismissalButtonText.setEnabled(false);
}
if(!app.equals(Trigger.anyAppString))

View File

@ -245,21 +245,24 @@ public class NotificationListener extends NotificationListenerService// implemen
{
boolean buttonFound = false;
for (Notification.Action a : sbn.getNotification().actions)
if(sbn.getNotification().actions != null)
{
if(a.toString().equalsIgnoreCase(buttonText))
for (Notification.Action a : sbn.getNotification().actions)
{
if(!buttonFound)
buttonFound = true;
if((Miscellaneous.isRegularExpression(buttonText) && a.title.toString().matches(buttonText)) || a.title.toString().equalsIgnoreCase(buttonText))
{
if (!buttonFound)
buttonFound = true;
try
{
Miscellaneous.logEvent("w", "clickNotificationButton()", "Pressing button with text \"" + a.title.toString() + "\".", 2);
a.actionIntent.send();
}
catch (PendingIntent.CanceledException e)
{
Miscellaneous.logEvent("w", "clickNotificationButton()", Log.getStackTraceString(e), 2);
try
{
Miscellaneous.logEvent("w", "clickNotificationButton()", "Pressing button with text \"" + a.title.toString() + "\".", 2);
a.actionIntent.send();
}
catch (PendingIntent.CanceledException e)
{
Miscellaneous.logEvent("w", "clickNotificationButton()", Log.getStackTraceString(e), 2);
}
}
}
}

View File

@ -119,6 +119,22 @@
android:layout_margin="10dp"
android:layout_marginVertical="@dimen/default_margin"
android:background="#aa000000" />
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/comparisonCaseInsensitive"
android:layout_marginBottom="@dimen/default_margin"/>
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/regularExpressionsIfEquals"
android:layout_marginBottom="@dimen/default_margin"/>
<TableRow
android:layout_marginBottom="@dimen/activity_vertical_margin">
@ -177,13 +193,41 @@
<EditText
android:layout_gravity="bottom"
android:id="@+id/etNotificationDismissalButtonText"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView />
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/comparisonCaseInsensitive"
android:layout_marginBottom="@dimen/default_margin"/>
</TableRow>
<TableRow>
<TextView />
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/mayUseRegularExpressions"
android:layout_marginBottom="@dimen/default_margin"/>
</TableRow>
</TableLayout>
<Button

View File

@ -519,7 +519,7 @@
<string name="notification">Benachrichtigung</string>
<string name="title">Titel</string>
<string name="text">Text</string>
<string name="anyApp">Irgendeine Anwendung</string>
<string name="anyApp">irgendeine Anwendung</string>
<string name="postsNotification">%1$s zeigt eine Benachrichtung an</string>
<string name="removedNotification">Benachrichtigung von %1$s wurde entfernt</string>
<string name="notificationAppears">Benachrichtigung wird angezeigt</string>

View File

@ -90,7 +90,7 @@
<string name="anotherProfileByThatName">Nome già usato per un altro profilo.</string>
<string name="anotherRuleByThatName">Nome già usato per un\'altra regola.</string>
<string name="any">qualsiasi</string>
<string name="anyApp">Qualsiasi applicazione</string>
<string name="anyApp">qualsiasi applicazione</string>
<string name="anyDevice">qualsiasi dispositivo</string>
<string name="anyLocation">qualsiasi posizione</string>
<string name="anyNumber">qualsiasi numero</string>

View File

@ -516,7 +516,7 @@
<string name="directionStringStartsWith">begint met</string>
<string name="directionStringEndsWith">eindigt met</string>
<string name="directionStringNotEquals">is niet gelijk aan</string>
<string name="anyApp">Elke app</string>
<string name="anyApp">elke app</string>
<string name="notificationTriggerExplanation">Deze trigger zal reageren op andere applicaties die meldingen openen in het meldingsgebied (of die worden gesloten). Je kunt een andere applicatie specificeren waar de melding vandaan moet komen. Als je dat niet doet, tellen de meldingen van een andere toepassing mee. U kunt ook tekenreeksen opgeven die wel of niet in de titel of de body van de melding moeten voorkomen. De vergelijking gebeurt hoofdletter-IN-sensitief.</string>
<string name="postsNotification">%1$s berichten notificatie</string>
<string name="removedNotification">kennisgeving van %1$s verwijderd</string>

View File

@ -618,7 +618,7 @@
<string name="directionStringStartsWith">starts with</string>
<string name="directionStringEndsWith">ends with</string>
<string name="directionStringNotEquals">not equals</string>
<string name="anyApp">Any app</string>
<string name="anyApp">any app</string>
<string name="notificationTriggerExplanation">This trigger will respond to other applications opening notifications in the notification area (or such being closed). You can specify another application from which the notification has to come from. If you don\'t the notifications from any other application will count. You can also specify strings that must be or must not be in their title or notification body. The comparison is done case-INsensitive.</string>
<string name="postsNotification">%1$s posts notification</string>
<string name="removedNotification">notification from %1$s removed</string>
@ -844,4 +844,5 @@
<string name="locationRequiredToDetermineWifiName">To get the wifi SSID, the app requires location permissions. Because the Google version cannot get that, you can only use this trigger if you do not specify an SSID. So it can only be used to detect if wifi is connected or not.</string>
<string name="simplyDismissNotification">Simply dismiss</string>
<string name="clickNotificationButton">Click a button</string>
<string name="withButton">with button %1$s</string>
</resources>

View File

@ -1,5 +1,6 @@
* New action: Keep phone turned on
* New: Regular expressions enabled where comparisons apply (one has to use "equals")
* New: Notification closing can now also be achieved by clicking a button of the target notification.
* Fixed: Changed input type for decimal numbers when adding intent data
* Fixed: Battery level trigger not working when using direction falling-below
* New: Wifi trigger can now use Regex for SSID