Phone Listener changed.

This commit is contained in:
jens 2021-05-14 13:00:25 +02:00
parent 9a7f66fa22
commit e988cedf7c
5 changed files with 112 additions and 44 deletions

View File

@ -258,6 +258,12 @@ public class ActivityManageRule extends Activity
notificationEditor.putExtra("edit", true); notificationEditor.putExtra("edit", true);
startActivityForResult(notificationEditor, requestCodeTriggerNfcNotificationEdit); startActivityForResult(notificationEditor, requestCodeTriggerNfcNotificationEdit);
break; break;
case phoneCall:
ActivityManageTriggerPhoneCall.editedPhoneCallTrigger = selectedTrigger;
Intent phoneCallEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerPhoneCall.class);
phoneCallEditor.putExtra("edit", true);
startActivityForResult(phoneCallEditor, requestCodeTriggerPhoneCallEdit);
break;
default: default:
break; break;
} }

View File

@ -1,33 +1,13 @@
package com.jens.automation2; package com.jens.automation2;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static com.jens.automation2.Trigger.triggerParameter2Split; import static com.jens.automation2.Trigger.triggerParameter2Split;
@ -46,7 +26,7 @@ public class ActivityManageTriggerPhoneCall extends Activity
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_trigger_notification); setContentView(R.layout.activity_manage_trigger_phone_call);
etTriggerPhoneCallPhoneNumber = (EditText)findViewById(R.id.etTriggerPhoneCallPhoneNumber); etTriggerPhoneCallPhoneNumber = (EditText)findViewById(R.id.etTriggerPhoneCallPhoneNumber);
rbTriggerPhoneCallStateAny = (RadioButton)findViewById(R.id.rbTriggerPhoneCallStateAny); rbTriggerPhoneCallStateAny = (RadioButton)findViewById(R.id.rbTriggerPhoneCallStateAny);
@ -80,7 +60,7 @@ public class ActivityManageTriggerPhoneCall extends Activity
if(rbTriggerPhoneCallDirectionAny.isChecked()) if(rbTriggerPhoneCallDirectionAny.isChecked())
tp2Result += Trigger.triggerPhoneCallDirectionAny; tp2Result += Trigger.triggerPhoneCallDirectionAny;
else if(rbTriggerPhoneCallDirectionIncoming.isChecked()) else if(rbTriggerPhoneCallDirectionIncoming.isChecked())
tp2Result += Trigger.triggerPhoneCallDirectionImcoming; tp2Result += Trigger.triggerPhoneCallDirectionIncoming;
else if(rbTriggerPhoneCallDirectionOutgoing.isChecked()) else if(rbTriggerPhoneCallDirectionOutgoing.isChecked())
tp2Result += Trigger.triggerPhoneCallDirectionOutgoing; tp2Result += Trigger.triggerPhoneCallDirectionOutgoing;
@ -132,9 +112,9 @@ public class ActivityManageTriggerPhoneCall extends Activity
if(parts[1].equals(Trigger.triggerPhoneCallDirectionAny)) if(parts[1].equals(Trigger.triggerPhoneCallDirectionAny))
rbTriggerPhoneCallDirectionAny.setChecked(true); rbTriggerPhoneCallDirectionAny.setChecked(true);
else if(parts[0].equals(Trigger.triggerPhoneCallDirectionImcoming)) else if(parts[1].equals(Trigger.triggerPhoneCallDirectionIncoming))
rbTriggerPhoneCallDirectionIncoming.setChecked(true); rbTriggerPhoneCallDirectionIncoming.setChecked(true);
else if(parts[0].equals(Trigger.triggerPhoneCallDirectionOutgoing)) else if(parts[1].equals(Trigger.triggerPhoneCallDirectionOutgoing))
rbTriggerPhoneCallDirectionOutgoing.setChecked(true); rbTriggerPhoneCallDirectionOutgoing.setChecked(true);
if(!parts[2].equals(Trigger.triggerPhoneCallNumberAny)) if(!parts[2].equals(Trigger.triggerPhoneCallNumberAny))

View File

@ -81,7 +81,7 @@ public class Trigger
public static String triggerPhoneCallStateStarted = "started"; public static String triggerPhoneCallStateStarted = "started";
public static String triggerPhoneCallStateStopped = "stopped"; public static String triggerPhoneCallStateStopped = "stopped";
public static String triggerPhoneCallStateAny = "any"; public static String triggerPhoneCallStateAny = "any";
public static String triggerPhoneCallDirectionImcoming = "incoming"; public static String triggerPhoneCallDirectionIncoming = "incoming";
public static String triggerPhoneCallDirectionOutgoing = "outgoing"; public static String triggerPhoneCallDirectionOutgoing = "outgoing";
public static String triggerPhoneCallDirectionAny = "any"; public static String triggerPhoneCallDirectionAny = "any";
public static String triggerPhoneCallNumberAny = "any"; public static String triggerPhoneCallNumberAny = "any";
@ -348,21 +348,47 @@ public class Trigger
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.roaming)); returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.roaming));
break; break;
case phoneCall: case phoneCall:
if(getPhoneDirection() == 1) String[] elements = triggerParameter2.split(triggerParameter2Split);
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingAdjective) + " ");
else if(getPhoneDirection() == 2)
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingAdjective) + " ");
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.phoneCall)); returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.phoneCall));
if(phoneNumber != null && !phoneNumber.equals("any"))
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.with) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.number) + " " + phoneNumber); returnString.append(" ");
if(elements[1].equals(triggerPhoneCallDirectionAny))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.with));
else if(elements[1].equals(triggerPhoneCallDirectionIncoming))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.from));
else if(elements[1].equals(triggerPhoneCallDirectionOutgoing))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.to));
returnString.append(" ");
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.any) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.number));
else else
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.with) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.anyNumber)); returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.number) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.matching) + " " + elements[2]);
if(getTriggerParameter()) returnString.append(" ");
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.started));
else if(elements[0].equals(Trigger.triggerPhoneCallStateAny))
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.stopped)); returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.any) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.state));
else if(elements[0].equals(Trigger.triggerPhoneCallStateRinging))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.ringing));
else if(elements[0].equals(Trigger.triggerPhoneCallStateStarted))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.started));
else if(elements[0].equals(Trigger.triggerPhoneCallStateStopped))
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.stopped));
// returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.phoneCall));
// if(phoneNumber != null && !phoneNumber.equals("any"))
// returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.with) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.number) + " " + phoneNumber);
// else
// returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.with) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.anyNumber));
//
// if(getTriggerParameter())
// returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.started));
// else
// returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.stopped));
break; break;
case nfcTag: case nfcTag:
// This type doesn't have an activate/deactivate equivalent // This type doesn't have an activate/deactivate equivalent

View File

@ -23,6 +23,8 @@ import java.security.GeneralSecurityException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import static com.jens.automation2.Trigger.triggerParameter2Split;
public class XmlFileInterface public class XmlFileInterface
{ {
public static String settingsFileName = "Automation_settings.xml"; public static String settingsFileName = "Automation_settings.xml";
@ -888,42 +890,90 @@ public class XmlFileInterface
Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 2); Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 2);
Toast.makeText(context, "Error while writing file: " + Log.getStackTraceString(e), Toast.LENGTH_LONG).show(); Toast.makeText(context, "Error while writing file: " + Log.getStackTraceString(e), Toast.LENGTH_LONG).show();
} }
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.timeFrame) else if(newTrigger.getTriggerType() == Trigger_Enum.timeFrame)
{ {
newTrigger.setTimeFrame(new TimeFrame(triggerParameter2)); newTrigger.setTimeFrame(new TimeFrame(triggerParameter2));
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.batteryLevel) else if(newTrigger.getTriggerType() == Trigger_Enum.batteryLevel)
{ {
newTrigger.setBatteryLevel(Integer.parseInt(triggerParameter2)); newTrigger.setBatteryLevel(Integer.parseInt(triggerParameter2));
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.speed) else if(newTrigger.getTriggerType() == Trigger_Enum.speed)
{ {
newTrigger.setSpeed(Double.parseDouble(triggerParameter2)); newTrigger.setSpeed(Double.parseDouble(triggerParameter2));
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.noiseLevel) else if(newTrigger.getTriggerType() == Trigger_Enum.noiseLevel)
{ {
newTrigger.setNoiseLevelDb(Long.parseLong(triggerParameter2)); newTrigger.setNoiseLevelDb(Long.parseLong(triggerParameter2));
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.wifiConnection) else if(newTrigger.getTriggerType() == Trigger_Enum.wifiConnection)
{ {
newTrigger.setWifiName(triggerParameter2); newTrigger.setWifiName(triggerParameter2);
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.process_started_stopped) else if(newTrigger.getTriggerType() == Trigger_Enum.process_started_stopped)
{ {
newTrigger.setProcessName(triggerParameter2); newTrigger.setProcessName(triggerParameter2);
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.phoneCall) else if(newTrigger.getTriggerType() == Trigger_Enum.phoneCall)
{ {
// 0/1/2,number String[] elements = triggerParameter2.split(",");
int direction = Integer.parseInt(triggerParameter2.substring(0, 1)); if(elements.length < 3) //old format
String number = triggerParameter2.substring(2); {
newTrigger.setPhoneDirection(direction); // 0/1/2,number
newTrigger.setPhoneNumber(number); int direction = Integer.parseInt(triggerParameter2.substring(0, 1));
String number = triggerParameter2.substring(2);
newTrigger.setPhoneDirection(direction);
newTrigger.setPhoneNumber(number);
String tp2String = "";
if(newTrigger.getTriggerParameter())
tp2String+= Trigger.triggerPhoneCallStateStarted;
else
tp2String+= Trigger.triggerPhoneCallStateStopped;
tp2String += triggerParameter2Split;
switch(direction)
{
case 0:
tp2String += Trigger.triggerPhoneCallDirectionAny;
break;
case 1:
tp2String += Trigger.triggerPhoneCallDirectionIncoming;
break;
case 2:
tp2String += Trigger.triggerPhoneCallDirectionOutgoing;
break;
}
tp2String += triggerParameter2Split;
tp2String += number;
newTrigger.setTriggerParameter2(tp2String);
}
/*else // new format
{
//tp1 is now irrelevant
elements = triggerParameter2.split(Trigger.triggerParameter2Split);
// state/direction/number
}*/
else
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.nfcTag) else if(newTrigger.getTriggerType() == Trigger_Enum.nfcTag)
{ {
newTrigger.setNfcTagId(triggerParameter2); newTrigger.setNfcTagId(triggerParameter2);
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.activityDetection) else if(newTrigger.getTriggerType() == Trigger_Enum.activityDetection)
{ {
@ -935,6 +985,7 @@ public class XmlFileInterface
{ {
newTrigger.setActivityDetectionType(0); newTrigger.setActivityDetectionType(0);
} }
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.bluetoothConnection) else if(newTrigger.getTriggerType() == Trigger_Enum.bluetoothConnection)
{ {
@ -944,6 +995,7 @@ public class XmlFileInterface
newTrigger.setBluetoothEvent(substrings[0]); newTrigger.setBluetoothEvent(substrings[0]);
newTrigger.setBluetoothDeviceAddress(substrings[1]); newTrigger.setBluetoothDeviceAddress(substrings[1]);
} }
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else if(newTrigger.getTriggerType() == Trigger_Enum.headsetPlugged) else if(newTrigger.getTriggerType() == Trigger_Enum.headsetPlugged)
{ {
@ -955,9 +1007,10 @@ public class XmlFileInterface
{ {
newTrigger.setHeadphoneType(-1); newTrigger.setHeadphoneType(-1);
} }
newTrigger.setTriggerParameter2(triggerParameter2);
} }
else
newTrigger.setTriggerParameter2(triggerParameter2); newTrigger.setTriggerParameter2(triggerParameter2);
} }
else else
{ {

View File

@ -668,5 +668,8 @@
<string name="activityOrActionName">Activity/action name</string> <string name="activityOrActionName">Activity/action name</string>
<string name="warning">Warning</string> <string name="warning">Warning</string>
<string name="ringing">ringing</string> <string name="ringing">ringing</string>
<string name="from">from</string>
<string name="to">to</string>
<string name="matching">matching</string>
<!-- <string name="net.kollnig.missioncontrol.permission.ADMIN">Control the app Tracker Control</string>--> <!-- <string name="net.kollnig.missioncontrol.permission.ADMIN">Control the app Tracker Control</string>-->
</resources> </resources>