Phone Listener changed.
This commit is contained in:
parent
0a0399c2b0
commit
9a8519d3e3
@ -605,7 +605,7 @@ public class Rule implements Comparable<Rule>
|
||||
String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split);
|
||||
// state dir number
|
||||
|
||||
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny) || PhoneStatusListener.getLastPhoneNumber().matches(elements[2]))
|
||||
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny) || Miscellaneous.comparePhoneNumbers(PhoneStatusListener.getLastPhoneNumber(), elements[2]) || (Miscellaneous.isRegularExpression(elements[2]) && PhoneStatusListener.getLastPhoneNumber().matches(elements[2])))
|
||||
{
|
||||
//if(PhoneStatusListener.isInACall() == oneTrigger.getTriggerParameter())
|
||||
if(
|
||||
|
@ -602,7 +602,7 @@ public class Rule implements Comparable<Rule>
|
||||
String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split);
|
||||
// state dir number
|
||||
|
||||
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny) || PhoneStatusListener.getLastPhoneNumber().matches(elements[2]))
|
||||
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny) || Miscellaneous.comparePhoneNumbers(PhoneStatusListener.getLastPhoneNumber(), elements[2]) || (Miscellaneous.isRegularExpression(elements[2]) && PhoneStatusListener.getLastPhoneNumber().matches(elements[2])))
|
||||
{
|
||||
//if(PhoneStatusListener.isInACall() == oneTrigger.getTriggerParameter())
|
||||
if(
|
||||
|
@ -7,6 +7,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -603,7 +604,7 @@ public class Rule implements Comparable<Rule>
|
||||
String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split);
|
||||
// state dir number
|
||||
|
||||
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny) || PhoneStatusListener.getLastPhoneNumber().matches(elements[2]))
|
||||
if(elements[2].equals(Trigger.triggerPhoneCallNumberAny) || Miscellaneous.comparePhoneNumbers(PhoneStatusListener.getLastPhoneNumber(), elements[2]) || (Miscellaneous.isRegularExpression(elements[2]) && PhoneStatusListener.getLastPhoneNumber().matches(elements[2])))
|
||||
{
|
||||
//if(PhoneStatusListener.isInACall() == oneTrigger.getTriggerParameter())
|
||||
if(
|
||||
|
@ -25,6 +25,7 @@ public class ActivityManageActionSendTextMessage extends Activity
|
||||
EditText etPhoneNumber, etSendTextMessage;
|
||||
|
||||
protected final static int requestCodeForContactsPermissions = 9876;
|
||||
protected final static int requestCodeGetContact = 3235;
|
||||
|
||||
// private String existingUrl = "";
|
||||
|
||||
@ -145,16 +146,14 @@ public class ActivityManageActionSendTextMessage extends Activity
|
||||
|
||||
private void openContactsDialogue()
|
||||
{
|
||||
// Toast.makeText(ActivityEditSendTextMessage.this, "Opening contacts dialogue", Toast.LENGTH_LONG).show();
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
|
||||
startActivityForResult(intent, 1000);
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
|
||||
startActivityForResult(intent, requestCodeGetContact);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if(requestCode == 1000)
|
||||
if(requestCode == requestCodeGetContact)
|
||||
{
|
||||
if(resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
|
@ -3,12 +3,19 @@ package com.jens.automation2;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import static com.jens.automation2.Trigger.triggerParameter2Split;
|
||||
|
||||
public class ActivityManageTriggerPhoneCall extends Activity
|
||||
@ -17,6 +24,8 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
||||
boolean edit = false;
|
||||
public static Trigger resultingTrigger;
|
||||
ProgressDialog progressDialog = null;
|
||||
protected final static int requestCodeForContactsPermissions = 2345;
|
||||
protected final static int requestCodeGetContact = 3235;
|
||||
|
||||
EditText etTriggerPhoneCallPhoneNumber;
|
||||
RadioButton rbTriggerPhoneCallStateRinging, rbTriggerPhoneCallStateStarted, rbTriggerPhoneCallStateStopped, rbTriggerPhoneCallDirectionAny, rbTriggerPhoneCallDirectionIncoming, rbTriggerPhoneCallDirectionOutgoing;
|
||||
@ -86,6 +95,20 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
||||
}
|
||||
});
|
||||
|
||||
bTriggerPhoneCallImportFromContacts.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !ActivityPermissions.havePermission("android.permission.READ_CONTACTS", ActivityManageTriggerPhoneCall.this))
|
||||
{
|
||||
requestPermissions("android.permission.READ_CONTACTS");
|
||||
}
|
||||
else
|
||||
openContactsDialogue();
|
||||
}
|
||||
});
|
||||
|
||||
Intent i = getIntent();
|
||||
if(i.getBooleanExtra("edit", false) == true)
|
||||
{
|
||||
@ -94,6 +117,31 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
protected void requestPermissions(String... requiredPermissions)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
if(requiredPermissions.length > 0)
|
||||
{
|
||||
StringBuilder permissions = new StringBuilder();
|
||||
for (String perm : requiredPermissions)
|
||||
permissions.append(perm + "; ");
|
||||
if (permissions.length() > 0)
|
||||
permissions.delete(permissions.length() - 2, permissions.length());
|
||||
|
||||
Miscellaneous.logEvent("i", "Permissions", "Requesting permissions: " + permissions, 2);
|
||||
|
||||
requestPermissions(requiredPermissions, requestCodeForContactsPermissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void openContactsDialogue()
|
||||
{
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
|
||||
startActivityForResult(intent, requestCodeGetContact);
|
||||
}
|
||||
|
||||
private void loadValuesIntoGui()
|
||||
{
|
||||
String[] parts = editedPhoneCallTrigger.getTriggerParameter2().split(triggerParameter2Split);
|
||||
@ -115,4 +163,50 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
||||
if(!parts[2].equals(Trigger.triggerPhoneCallNumberAny))
|
||||
etTriggerPhoneCallPhoneNumber.setText(parts[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if(requestCode == requestCodeGetContact)
|
||||
{
|
||||
if(resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
String phoneNo = null;
|
||||
String name = null;
|
||||
|
||||
Uri uri = data.getData();
|
||||
Cursor cursor = ActivityManageTriggerPhoneCall.this.getContentResolver().query(uri, null, null, null, null);
|
||||
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
int phoneIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
||||
int nameIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
|
||||
|
||||
phoneNo = cursor.getString(phoneIndex);
|
||||
name = cursor.getString(nameIndex);
|
||||
|
||||
etTriggerPhoneCallPhoneNumber.setText(phoneNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
//super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
|
||||
{
|
||||
if(requestCode == requestCodeForContactsPermissions)
|
||||
{
|
||||
for(int i=0; i<permissions.length; i++)
|
||||
{
|
||||
if(permissions[i].equals("android.permission.READ_CONTACTS"))
|
||||
{
|
||||
if(grantResults[i] == PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
openContactsDialogue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
@ -1471,4 +1473,31 @@ public class Miscellaneous extends Service
|
||||
{
|
||||
return intent.resolveActivityInfo(context.getPackageManager(), 0) != null;
|
||||
}
|
||||
|
||||
public static boolean isRegularExpression(String regex)
|
||||
{
|
||||
try
|
||||
{
|
||||
"compareString".matches(regex); //will cause expection if no valid regex
|
||||
return true;
|
||||
}
|
||||
catch(java.util.regex.PatternSyntaxException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean comparePhoneNumbers(String number1, String number2)
|
||||
{
|
||||
/* To be activated when Android S SDK comes out
|
||||
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.Q)
|
||||
{
|
||||
TelephonyManager tm = (TelephonyManager)Miscellaneous.getAnyContext().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return PhoneNumberUtils.areSamePhoneNumber(number1, number2, tm.getNetworkCountryIso());
|
||||
}
|
||||
else*/
|
||||
return PhoneNumberUtils.compare(number1, number2);
|
||||
}
|
||||
}
|
@ -153,6 +153,19 @@
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_span="2"
|
||||
android:text="@string/urlRegex" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
@ -653,7 +653,7 @@
|
||||
<string name="noFilesImported">Keine Dateien konnten importiert werden.</string>
|
||||
<string name="notAllFilesImported">Nicht alle passenden Dateien konnten importiert werden.</string>
|
||||
<string name="openExamplesPage">Webseite mit Beispielen öffnen</string>
|
||||
<string name="phoneNumberExplanation">Sie können eine bestimmte Nummer eingeben, aber müssen nicht. Wenn Sie eine angeben wollen, können Sie auch eine aus dem Adressbuch auswählen. Außerdem können Sie reguläre Audrücke verwenden.</string>
|
||||
<string name="phoneNumberExplanation">Sie können eine bestimmte Nummer eingeben, aber müssen nicht. Wenn Sie eine angeben wollen, können Sie auch eine aus dem Adressbuch auswählen. Außerdem können Sie reguläre Audrücke verwenden. Zum Testen selbiger mag ich die Seite:</string>
|
||||
<string name="prefsImportError">Fehler beim Importieren der Einstellungen.</string>
|
||||
<string name="rulesImportedSuccessfully">Regeln und Orte wurden erfolgreich importiert.</string>
|
||||
<string name="rulesImportError">Fehler beim Importieren der Regeln.</string>
|
||||
|
@ -312,5 +312,5 @@
|
||||
<string name="parameterValue">Valor del parámetro</string>
|
||||
<string name="addIntentValue">Añadir pareja intento</string>
|
||||
<string name="parameterType">Tipo del parámetro</string>
|
||||
<string name="phoneNumberExplanation">Puedes entrar un numero, pero es opciónal. Si quieres usar un puedes elegir un de su directorio o entrar un manualmente. Adiciónalmente puedes usar expresiónes regulares.</string>
|
||||
<string name="phoneNumberExplanation">Puedes entrar un numero, pero es opciónal. Si quieres usar un puedes elegir un de su directorio o entrar un manualmente. Adiciónalmente puedes usar expresiónes regulares. Para testar esos me gusta la pagina:</string>
|
||||
</resources>
|
@ -644,7 +644,7 @@
|
||||
<string name="enterValidAction">Enter a valid action</string>
|
||||
<string name="enterPackageName">Enter a valid package name.</string>
|
||||
<string name="state">State</string>
|
||||
<string name="phoneNumberExplanation">You can enter a specific phone number, but you don\'t have to. If you want to specify one you can either pick one from your address book or enter it manually. In addition you may use regular expressions.</string>
|
||||
<string name="phoneNumberExplanation">You can enter a specific phone number, but you don\'t have to. If you want to specify one you can either pick one from your address book or enter it manually. In addition you may use regular expressions. To test a regular expression I like this page:</string>
|
||||
<string name="importConfiguration">Import configuration</string>
|
||||
<string name="exportConfiguration">Export configuration</string>
|
||||
<string name="moreSettings">More settings</string>
|
||||
@ -671,5 +671,5 @@
|
||||
<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="urlRegex" translatable="false">https://regex101.com/</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user