Notification trigger.
This commit is contained in:
parent
864ed2111e
commit
13bcb02ffc
@ -51,9 +51,20 @@ public class Rule implements Comparable<Rule>
|
||||
private String name;
|
||||
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
||||
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
||||
private Calendar lastExecution;
|
||||
|
||||
private static Date lastActivatedRuleActivationTime;
|
||||
|
||||
|
||||
public Calendar getLastExecution()
|
||||
{
|
||||
return lastExecution;
|
||||
}
|
||||
|
||||
public void setLastExecution(Calendar lastExecution)
|
||||
{
|
||||
this.lastExecution = lastExecution;
|
||||
}
|
||||
|
||||
public boolean isRuleToggle()
|
||||
{
|
||||
return ruleToggle;
|
||||
@ -757,40 +768,44 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||
{
|
||||
String app = sbn.getPackageName();
|
||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
||||
|
||||
if (!myApp.equals("-1"))
|
||||
if(lastExecution == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
||||
{
|
||||
if (!app.equalsIgnoreCase(myApp))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
String app = sbn.getPackageName();
|
||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||
|
||||
if (myTitle.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
||||
|
||||
if (myText.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTextDir, myText, text))
|
||||
if (!myApp.equals("-1"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||
continue;
|
||||
if (!app.equalsIgnoreCase(myApp))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foundMatch = true;
|
||||
if (myTitle.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (myText.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTextDir, myText, text))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foundMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundMatch)
|
||||
@ -859,7 +874,7 @@ public class Rule implements Comparable<Rule>
|
||||
if (Looper.myLooper() == null)
|
||||
Looper.prepare();
|
||||
|
||||
activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -883,6 +898,7 @@ public class Rule implements Comparable<Rule>
|
||||
*/
|
||||
if(wasActivated)
|
||||
{
|
||||
setLastExecution(Calendar.getInstance());
|
||||
AutomationService.updateNotification();
|
||||
ActivityMainScreen.updateMainScreen();
|
||||
super.onPostExecute(result);
|
||||
|
@ -46,8 +46,19 @@ public class Rule implements Comparable<Rule>
|
||||
private String name;
|
||||
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
||||
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
||||
private Calendar lastExecution;
|
||||
|
||||
private static Date lastActivatedRuleActivationTime;
|
||||
|
||||
public Calendar getLastExecution()
|
||||
{
|
||||
return lastExecution;
|
||||
}
|
||||
|
||||
public void setLastExecution(Calendar lastExecution)
|
||||
{
|
||||
this.lastExecution = lastExecution;
|
||||
}
|
||||
|
||||
public boolean isRuleToggle()
|
||||
{
|
||||
@ -762,29 +773,43 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||
{
|
||||
String app = sbn.getPackageName();
|
||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||
|
||||
if (!myApp.equals("-1"))
|
||||
if(getLastExecution() == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
||||
{
|
||||
if (!app.equalsIgnoreCase(myApp))
|
||||
continue;
|
||||
}
|
||||
String app = sbn.getPackageName();
|
||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||
|
||||
if (myTitle.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTitleDir, title, myTitle))
|
||||
continue;
|
||||
}
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
||||
|
||||
if (myText.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTextDir, text, myText))
|
||||
continue;
|
||||
}
|
||||
if (!myApp.equals("-1"))
|
||||
{
|
||||
if (!app.equalsIgnoreCase(myApp))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foundMatch = true;
|
||||
if (myTitle.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (myText.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTextDir, myText, text))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foundMatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundMatch)
|
||||
@ -852,8 +877,8 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
if (Looper.myLooper() == null)
|
||||
Looper.prepare();
|
||||
|
||||
activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||
|
||||
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -877,6 +902,7 @@ public class Rule implements Comparable<Rule>
|
||||
*/
|
||||
if(wasActivated)
|
||||
{
|
||||
setLastExecution(Calendar.getInstance());
|
||||
AutomationService.updateNotification();
|
||||
ActivityMainScreen.updateMainScreen();
|
||||
super.onPostExecute(result);
|
||||
|
@ -48,8 +48,19 @@ public class Rule implements Comparable<Rule>
|
||||
private String name;
|
||||
private boolean ruleActive = true; // rules can be deactivated, so they won't fire if you don't want them temporarily
|
||||
private boolean ruleToggle = false; // rule will run again and do the opposite of its actions if applicable
|
||||
private Calendar lastExecution;
|
||||
|
||||
private static Date lastActivatedRuleActivationTime;
|
||||
|
||||
public Calendar getLastExecution()
|
||||
{
|
||||
return lastExecution;
|
||||
}
|
||||
|
||||
public void setLastExecution(Calendar lastExecution)
|
||||
{
|
||||
this.lastExecution = lastExecution;
|
||||
}
|
||||
|
||||
public boolean isRuleToggle()
|
||||
{
|
||||
@ -793,29 +804,43 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||
{
|
||||
String app = sbn.getPackageName();
|
||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||
|
||||
if (!myApp.equals("-1"))
|
||||
if(getLastExecution() == null || sbn.getPostTime() > this.lastExecution.getTimeInMillis())
|
||||
{
|
||||
if (!app.equalsIgnoreCase(myApp))
|
||||
continue;
|
||||
}
|
||||
String app = sbn.getPackageName();
|
||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||
|
||||
if (myTitle.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTitleDir, title, myTitle))
|
||||
continue;
|
||||
}
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Checking if this notification matches our rule " + this.getName() + ". App: " + app + ", title: " + title + ", text: " + text, 5);
|
||||
|
||||
if (myText.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTextDir, text, myText))
|
||||
continue;
|
||||
}
|
||||
if (!myApp.equals("-1"))
|
||||
{
|
||||
if (!app.equalsIgnoreCase(myApp))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification app name does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foundMatch = true;
|
||||
if (myTitle.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTitleDir, myTitle, title))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification title does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (myText.length() > 0)
|
||||
{
|
||||
if (!Miscellaneous.compare(myTextDir, myText, text))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationCheck", "Notification text does not match rule.", 5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foundMatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundMatch)
|
||||
@ -883,8 +908,8 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
if (Looper.myLooper() == null)
|
||||
Looper.prepare();
|
||||
|
||||
activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||
|
||||
wasActivated = activateInternally((AutomationService)params[0], (Boolean)params[1]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -908,6 +933,7 @@ public class Rule implements Comparable<Rule>
|
||||
*/
|
||||
if(wasActivated)
|
||||
{
|
||||
setLastExecution(Calendar.getInstance());
|
||||
AutomationService.updateNotification();
|
||||
ActivityMainScreen.updateMainScreen();
|
||||
super.onPostExecute(result);
|
||||
|
@ -74,7 +74,7 @@ public class NotificationListener extends NotificationListenerService
|
||||
checkNotification(false, sbn);
|
||||
}
|
||||
|
||||
boolean checkNotification(boolean created, StatusBarNotification sbn)
|
||||
synchronized boolean checkNotification(boolean created, StatusBarNotification sbn)
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
@ -89,9 +89,9 @@ public class NotificationListener extends NotificationListenerService
|
||||
lastNotification.title = title;
|
||||
lastNotification.text = text;
|
||||
|
||||
if(lastResponseToNotification == null || lastResponseToNotification.getTimeInMillis() < lastNotification.publishTime.getTimeInMillis())
|
||||
{
|
||||
lastResponseToNotification = Calendar.getInstance();
|
||||
// if(lastResponseToNotification == null || lastResponseToNotification.getTimeInMillis() < lastNotification.publishTime.getTimeInMillis())
|
||||
// {
|
||||
// lastResponseToNotification = Calendar.getInstance();
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
@ -99,9 +99,9 @@ public class NotificationListener extends NotificationListenerService
|
||||
if (ruleCandidates.get(i).applies(NotificationListener.this))
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("e", "NotificationCheck", "Ignoring notification as it is old.", 5);
|
||||
// }
|
||||
// else
|
||||
// Miscellaneous.logEvent("e", "NotificationCheck", "Ignoring notification as it is old.", 5);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user