diff --git a/app/src/apkFlavor/AndroidManifest.xml b/app/src/apkFlavor/AndroidManifest.xml index 3e0abe21..8137dc3d 100644 --- a/app/src/apkFlavor/AndroidManifest.xml +++ b/app/src/apkFlavor/AndroidManifest.xml @@ -137,12 +137,12 @@ - + - + - - + + - - - - + + + + @@ -218,6 +218,12 @@ + + \ No newline at end of file diff --git a/app/src/fdroidFlavor/AndroidManifest.xml b/app/src/fdroidFlavor/AndroidManifest.xml index a2120b00..d3a0df13 100644 --- a/app/src/fdroidFlavor/AndroidManifest.xml +++ b/app/src/fdroidFlavor/AndroidManifest.xml @@ -132,11 +132,11 @@ - + - - - + + + - - - + + + - + @@ -196,6 +196,12 @@ + + \ 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 1aa8e1d3..af80b78a 100644 --- a/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java @@ -3,7 +3,9 @@ package com.jens.automation2; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.os.AsyncTask; +import android.os.Build; import android.os.Looper; +import android.service.notification.StatusBarNotification; import android.util.Log; import android.widget.Toast; @@ -14,6 +16,7 @@ import com.jens.automation2.receivers.ConnectivityReceiver; import com.jens.automation2.receivers.HeadphoneJackListener; import com.jens.automation2.receivers.NfcReceiver; import com.jens.automation2.receivers.NoiseListener; +import com.jens.automation2.receivers.NotificationListener; import com.jens.automation2.receivers.PhoneStatusListener; import com.jens.automation2.receivers.ProcessListener; @@ -22,6 +25,9 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import static com.jens.automation2.Trigger.triggerParameter2Split; +import static com.jens.automation2.receivers.NotificationListener.EXTRA_TEXT; +import static com.jens.automation2.receivers.NotificationListener.EXTRA_TITLE; public class Rule implements Comparable { @@ -831,6 +837,8 @@ public class Rule implements Comparable private class ActivateRuleTask extends AsyncTask { + boolean wasActivated = false; + @Override protected Void doInBackground(Object... params) { @@ -863,16 +871,23 @@ public class Rule implements Comparable @Override protected void onPostExecute(Void result) { - AutomationService.updateNotification(); - ActivityMainScreen.updateMainScreen(); - super.onPostExecute(result); + /* + Only update if the rules was actually executed. Became necessary for the notification trigger. If a user created a rule + with a notification trigger and this app creates a notification itself this will otherwise end in an infinite loop. + */ + if(wasActivated) + { + AutomationService.updateNotification(); + ActivityMainScreen.updateMainScreen(); + super.onPostExecute(result); + } } /** * Will activate the rule. Should be called by a separate execution thread * @param automationService */ - protected void activateInternally(AutomationService automationService, boolean force) + protected boolean activateInternally(AutomationService automationService, boolean force) { boolean isActuallyToggable = isActuallyToggable(); @@ -919,8 +934,11 @@ public class Rule implements Comparable else { Miscellaneous.logEvent("i", "Rule", "Request to activate rule " + Rule.this.getName() + ", but it is the last one that was activated. Won't do it again.", 3); + return false; } - } + + return true; + } } public void activate(AutomationService automationService, boolean force) diff --git a/app/src/googlePlayFlavor/AndroidManifest.xml b/app/src/googlePlayFlavor/AndroidManifest.xml index 10d86187..0062673f 100644 --- a/app/src/googlePlayFlavor/AndroidManifest.xml +++ b/app/src/googlePlayFlavor/AndroidManifest.xml @@ -126,12 +126,12 @@ - + - + - - + + - - - - + + + + @@ -204,6 +204,12 @@ + + \ No newline at end of file diff --git a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java index 641342d8..37168334 100644 --- a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java @@ -3,7 +3,9 @@ package com.jens.automation2; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.os.AsyncTask; +import android.os.Build; import android.os.Looper; +import android.service.notification.StatusBarNotification; import android.util.Log; import android.widget.Toast; @@ -16,6 +18,7 @@ import com.jens.automation2.receivers.ConnectivityReceiver; import com.jens.automation2.receivers.HeadphoneJackListener; import com.jens.automation2.receivers.NfcReceiver; import com.jens.automation2.receivers.NoiseListener; +import com.jens.automation2.receivers.NotificationListener; import com.jens.automation2.receivers.PhoneStatusListener; import com.jens.automation2.receivers.ProcessListener; @@ -24,6 +27,9 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import static com.jens.automation2.Trigger.triggerParameter2Split; +import static com.jens.automation2.receivers.NotificationListener.EXTRA_TEXT; +import static com.jens.automation2.receivers.NotificationListener.EXTRA_TITLE; public class Rule implements Comparable { diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index b3fb9cd2..eb6c1f2f 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -217,11 +217,11 @@ public class Action } else if(this.getAction().equals(Action_Enum.playSound)) { - returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.playSound) + ": " + getParameter2()); + returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.playSound)); } else returnString.append(action.toString()); - + if(this.getAction().equals(Action_Enum.triggerUrl)) { String[] components = parameter2.split(";"); diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index 2cf9aa78..fba5ce6d 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -7,9 +7,12 @@ import android.bluetooth.BluetoothAdapter; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; +import android.content.res.AssetFileDescriptor; +import android.content.res.AssetManager; import android.media.AudioManager; import android.media.MediaPlayer; import android.net.ConnectivityManager; +import android.net.Uri; import android.net.wifi.WifiManager; import android.os.Build; import android.os.PowerManager; @@ -473,7 +476,17 @@ public class Actions MediaPlayer mp = new MediaPlayer(); try { - mp.setDataSource(soundFileLocation); + Uri fileUri = Uri.parse(soundFileLocation); + mp.setLooping(false); + mp.setDataSource(Miscellaneous.getAnyContext(), fileUri); + mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() + { + @Override + public void onCompletion(MediaPlayer mp) + { + mp.release(); + } + }); mp.prepare(); mp.start(); } diff --git a/app/src/main/java/com/jens/automation2/ActivityMainScreen.java b/app/src/main/java/com/jens/automation2/ActivityMainScreen.java index 89f7a844..d4a509c2 100644 --- a/app/src/main/java/com/jens/automation2/ActivityMainScreen.java +++ b/app/src/main/java/com/jens/automation2/ActivityMainScreen.java @@ -10,6 +10,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.util.Log; +import android.util.Xml; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; @@ -29,6 +30,8 @@ import com.jens.automation2.AutomationService.serviceCommands; import com.jens.automation2.Trigger.Trigger_Enum; import com.jens.automation2.location.LocationProvider; +import java.io.File; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Calendar; @@ -39,7 +42,7 @@ public class ActivityMainScreen extends ActivityGeneric private static ActivityMainScreen activityMainScreenInstance = null; private ToggleButton toggleService, tbLockSound; - private Button bShowHelp, bPrivacy, bSettingsErase, bSettingsSetToDefault, bVolumeTest, bAddSoundLockTIme; + private Button bShowHelp, bPrivacy, bSettingsErase, bSettingsSetToDefault, bVolumeTest, bAddSoundLockTIme, bShareConfigAndLog; private TextView tvActivePoi, tvClosestPoi, tvLastRule, tvMainScreenNotePermissions, tvMainScreenNoteFeaturesFromOtherFlavor, tvMainScreenNoteLocationImpossibleBlameGoogle, tvMainScreenNoteNews, tvlockSoundDuration, tvFileStoreLocation; private ListView lvRuleHistory; @@ -76,6 +79,9 @@ public class ActivityMainScreen extends ActivityGeneric tvlockSoundDuration = (TextView)findViewById(R.id.tvlockSoundDuration); tvFileStoreLocation = (TextView)findViewById(R.id.tvFileStoreLocation); tbLockSound = (ToggleButton) findViewById(R.id.tbLockSound); + bVolumeTest = (Button) findViewById(R.id.bVolumeTest); + bSettingsSetToDefault = (Button) findViewById(R.id.bSettingsSetToDefault); + bShareConfigAndLog = (Button) findViewById(R.id.bShareConfigAndLog); toggleService = (ToggleButton) findViewById(R.id.tbArmMastListener); toggleService.setChecked(AutomationService.isMyServiceRunning(this)); toggleService.setOnCheckedChangeListener(new OnCheckedChangeListener() @@ -135,7 +141,6 @@ public class ActivityMainScreen extends ActivityGeneric } }); - Button bVolumeTest = (Button) findViewById(R.id.bVolumeTest); bVolumeTest.setOnClickListener(new OnClickListener() { @Override @@ -179,16 +184,6 @@ public class ActivityMainScreen extends ActivityGeneric } }); - /*bSettingsErase = (Button)findViewById(R.id.bSettingsErase); - bSettingsErase.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - getEraseSettingsDialog(ActivityMainScreen.this).show(); - } - });*/ - bSettingsSetToDefault = (Button) findViewById(R.id.bSettingsSetToDefault); bSettingsSetToDefault.setOnClickListener(new OnClickListener() { @Override @@ -198,6 +193,15 @@ public class ActivityMainScreen extends ActivityGeneric } }); + bShareConfigAndLog.setOnClickListener(new OnClickListener() + { + @Override + public void onClick(View v) + { + getShareConfigAndLogDialogue(ActivityMainScreen.this).show(); + } + }); + lvRuleHistory.setOnTouchListener(new OnTouchListener() { @Override @@ -279,6 +283,58 @@ public class ActivityMainScreen extends ActivityGeneric return alertDialog; } + AlertDialog getShareConfigAndLogDialogue(final Context context) + { + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); + alertDialogBuilder.setTitle(context.getResources().getString(R.string.shareConfigAndLogFilesWithDev)); + alertDialogBuilder.setMessage(context.getResources().getString(R.string.shareConfigAndLogExplanation)); + alertDialogBuilder.setPositiveButton(context.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) + { + File dstZipFile = new File(Miscellaneous.getAnyContext().getCacheDir() + "/" + Settings.zipFileName); + + ArrayList srcFilesList = new ArrayList<>(); + srcFilesList.add(Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName); + + String logFilePath = Miscellaneous.getWriteableFolder() + "/" + Miscellaneous.logFileName; + if((new File(logFilePath)).exists()) + srcFilesList.add(logFilePath); + + String[] srcFiles = srcFilesList.toArray(new String[srcFilesList.size()]); + + if(dstZipFile.exists()) + dstZipFile.delete(); + + Miscellaneous.zip(srcFiles, dstZipFile.getAbsolutePath()); + + /* + Without root the zip file in the cache directory is not directly accessible. + But have to route it through this content provider crap. + */ + + String subject = "Automation logs"; + + StringBuilder emailBody = new StringBuilder(); + emailBody.append("Device details" + Miscellaneous.lineSeparator); + emailBody.append("OS version: " + System.getProperty("os.version") + Miscellaneous.lineSeparator); + emailBody.append("API Level: " + android.os.Build.VERSION.SDK + Miscellaneous.lineSeparator); + emailBody.append("Device: " + android.os.Build.DEVICE + Miscellaneous.lineSeparator); + emailBody.append("Model: " + android.os.Build.MODEL + Miscellaneous.lineSeparator); + emailBody.append("Product: " + android.os.Build.PRODUCT); + + Uri uri = Uri.parse("content://com.jens.automation2/" + Settings.zipFileName); + + Miscellaneous.sendEmail(ActivityMainScreen.this, "android-development@gmx.de", "Automation logs", emailBody.toString(), uri); + } + }); + alertDialogBuilder.setNegativeButton(context.getResources().getString(R.string.no), null); + AlertDialog alertDialog = alertDialogBuilder.create(); + + return alertDialog; + } + public static ActivityMainScreen getActivityMainScreenInstance() { return activityMainScreenInstance; @@ -458,7 +514,31 @@ public class ActivityMainScreen extends ActivityGeneric String folder = Miscellaneous.getWriteableFolder(); if(folder != null && folder.length() > 0) + { activityMainScreenInstance.tvFileStoreLocation.setText(String.format(activityMainScreenInstance.getResources().getString(R.string.filesStoredAt), folder)); + activityMainScreenInstance.tvFileStoreLocation.setOnClickListener(new OnClickListener() + { + @Override + public void onClick(View v) + { + Uri selectedUri = Uri.parse(folder); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(selectedUri, "resource/folder"); + + if (intent.resolveActivityInfo(activityMainScreenInstance.getPackageManager(), 0) != null) + { + activityMainScreenInstance.startActivity(intent); + } + else + { + // if you reach this place, it means there is no any file + // explorer app installed on your device + Toast.makeText(activityMainScreenInstance, activityMainScreenInstance.getResources().getString(R.string.noFileManageInstalled), Toast.LENGTH_LONG).show(); + } + + } + }); + } } } diff --git a/app/src/main/java/com/jens/automation2/ActivityManageBrightnessSetting.java b/app/src/main/java/com/jens/automation2/ActivityManageActionBrightnessSetting.java similarity index 96% rename from app/src/main/java/com/jens/automation2/ActivityManageBrightnessSetting.java rename to app/src/main/java/com/jens/automation2/ActivityManageActionBrightnessSetting.java index fc798536..1225e7e8 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageBrightnessSetting.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionBrightnessSetting.java @@ -12,7 +12,7 @@ import android.widget.TextView; import androidx.annotation.Nullable; -public class ActivityManageBrightnessSetting extends Activity +public class ActivityManageActionBrightnessSetting extends Activity { CheckBox chkAutoBrightness; SeekBar sbBrightness; diff --git a/app/src/main/java/com/jens/automation2/ActivityManageActionPlaySound.java b/app/src/main/java/com/jens/automation2/ActivityManageActionPlaySound.java index acc63974..229df671 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageActionPlaySound.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionPlaySound.java @@ -7,17 +7,20 @@ import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; +import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; +import java.io.File; + public class ActivityManageActionPlaySound extends Activity { final static int PICKFILE_RESULT_CODE = 4711; CheckBox chkPlaySoundAlwaysPlay; - TextView tvSelectedSoundFile; + EditText etSelectedSoundFile; Button bSelectSoundFile, bSavePlaySound; @Override @@ -27,7 +30,7 @@ public class ActivityManageActionPlaySound extends Activity setContentView(R.layout.activity_manage_play_sound); chkPlaySoundAlwaysPlay = (CheckBox)findViewById(R.id.chkPlaySoundAlwaysPlay); - tvSelectedSoundFile = (TextView)findViewById(R.id.tvSelectedSoundFile); + etSelectedSoundFile = (EditText)findViewById(R.id.etSelectedSoundFile); bSelectSoundFile = (Button)findViewById(R.id.bSelectSoundFile); bSavePlaySound = (Button)findViewById(R.id.bSavePlaySound); @@ -38,7 +41,7 @@ public class ActivityManageActionPlaySound extends Activity boolean param1 = getIntent().getBooleanExtra("actionParameter1", false); String param2 = getIntent().getStringExtra("actionParameter2"); chkPlaySoundAlwaysPlay.setChecked(param1); - tvSelectedSoundFile.setText(param2); + etSelectedSoundFile.setText(param2); } bSelectSoundFile.setOnClickListener(new View.OnClickListener() @@ -66,15 +69,24 @@ public class ActivityManageActionPlaySound extends Activity void savePlaySoundSettings() { - if(tvSelectedSoundFile.getText().toString() == null || tvSelectedSoundFile.getText().toString().length() == 0) + if(etSelectedSoundFile.getText().toString() == null || etSelectedSoundFile.getText().toString().length() == 0) { Toast.makeText(ActivityManageActionPlaySound.this, getResources().getString(R.string.selectSoundFile), Toast.LENGTH_LONG).show(); return; } + else + { + File soundFile = new File(etSelectedSoundFile.getText().toString()); + if(!soundFile.exists()) + { + Toast.makeText(ActivityManageActionPlaySound.this, getResources().getString(R.string.fileDoesNotExist), Toast.LENGTH_LONG).show(); + return; + } + } Intent returnData = new Intent(); returnData.putExtra("actionParameter1", chkPlaySoundAlwaysPlay.isChecked()); - returnData.putExtra("actionParameter2", tvSelectedSoundFile.getText().toString()); + returnData.putExtra("actionParameter2", etSelectedSoundFile.getText().toString()); setResult(RESULT_OK, returnData); finish(); @@ -90,8 +102,8 @@ public class ActivityManageActionPlaySound extends Activity if(requestCode == PICKFILE_RESULT_CODE) { Uri fileUri = data.getData(); - String filePath = fileUri.getPath(); - tvSelectedSoundFile.setText(filePath); + String filePath = CompensateCrappyAndroidPaths.getPath(ActivityManageActionPlaySound.this, fileUri); + etSelectedSoundFile.setText(filePath); } } } diff --git a/app/src/main/java/com/jens/automation2/ActivityEditSendTextMessage.java b/app/src/main/java/com/jens/automation2/ActivityManageActionSendTextMessage.java similarity index 88% rename from app/src/main/java/com/jens/automation2/ActivityEditSendTextMessage.java rename to app/src/main/java/com/jens/automation2/ActivityManageActionSendTextMessage.java index 8c3307a5..5419eeae 100644 --- a/app/src/main/java/com/jens/automation2/ActivityEditSendTextMessage.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionSendTextMessage.java @@ -19,7 +19,7 @@ import androidx.annotation.NonNull; import com.jens.automation2.Action.Action_Enum; -public class ActivityEditSendTextMessage extends Activity +public class ActivityManageActionSendTextMessage extends Activity { Button bSaveSendTextMessage, bImportNumberFromContacts; EditText etPhoneNumber, etSendTextMessage; @@ -67,7 +67,7 @@ public class ActivityEditSendTextMessage extends Activity @Override public void onClick(View view) { - if(!ActivityPermissions.havePermission("android.permission.READ_CONTACTS", ActivityEditSendTextMessage.this)) + if(!ActivityPermissions.havePermission("android.permission.READ_CONTACTS", ActivityManageActionSendTextMessage.this)) { requestPermissions("android.permission.READ_CONTACTS"); } @@ -76,10 +76,10 @@ public class ActivityEditSendTextMessage extends Activity } }); - ActivityEditSendTextMessage.edit = getIntent().getBooleanExtra("edit", false); + ActivityManageActionSendTextMessage.edit = getIntent().getBooleanExtra("edit", false); if(edit) { - String[] parameters = ActivityEditSendTextMessage.resultingAction.getParameter2().split(Actions.smsSeparator); + String[] parameters = ActivityManageActionSendTextMessage.resultingAction.getParameter2().split(Actions.smsSeparator); etPhoneNumber.setText(parameters[0]); etSendTextMessage.setText(parameters[1]); } @@ -99,7 +99,7 @@ public class ActivityEditSendTextMessage extends Activity if(edit && resultingAction != null) { - ActivityEditSendTextMessage.resultingAction.setParameter2(etPhoneNumber.getText().toString() + Actions.smsSeparator + etSendTextMessage.getText().toString()); + ActivityManageActionSendTextMessage.resultingAction.setParameter2(etPhoneNumber.getText().toString() + Actions.smsSeparator + etSendTextMessage.getText().toString()); } setResult(RESULT_OK); @@ -162,7 +162,7 @@ public class ActivityEditSendTextMessage extends Activity String name = null; Uri uri = data.getData(); - Cursor cursor = ActivityEditSendTextMessage.this.getContentResolver().query(uri, null, null, null, null); + Cursor cursor = ActivityManageActionSendTextMessage.this.getContentResolver().query(uri, null, null, null, null); if (cursor.moveToFirst()) { diff --git a/app/src/main/java/com/jens/automation2/ActivityEditSpeakText.java b/app/src/main/java/com/jens/automation2/ActivityManageActionSpeakText.java similarity index 83% rename from app/src/main/java/com/jens/automation2/ActivityEditSpeakText.java rename to app/src/main/java/com/jens/automation2/ActivityManageActionSpeakText.java index 00689f9e..6cd3d4c9 100644 --- a/app/src/main/java/com/jens/automation2/ActivityEditSpeakText.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionSpeakText.java @@ -10,7 +10,7 @@ import android.widget.Toast; import com.jens.automation2.Action.Action_Enum; -public class ActivityEditSpeakText extends Activity +public class ActivityManageActionSpeakText extends Activity { private Button bSaveSpeakText; private EditText etSpeakText; @@ -48,9 +48,9 @@ public class ActivityEditSpeakText extends Activity } }); - ActivityEditSpeakText.edit = getIntent().getBooleanExtra("edit", false); + ActivityManageActionSpeakText.edit = getIntent().getBooleanExtra("edit", false); if(edit) - etSpeakText.setText(ActivityEditSpeakText.resultingAction.getParameter2()); + etSpeakText.setText(ActivityManageActionSpeakText.resultingAction.getParameter2()); // String url = getIntent().getStringExtra("urlToTrigger"); @@ -66,7 +66,7 @@ public class ActivityEditSpeakText extends Activity // setResult(RESULT_OK, returnIntent); if(edit && resultingAction != null) - ActivityEditSpeakText.resultingAction.setParameter2(etSpeakText.getText().toString()); + ActivityManageActionSpeakText.resultingAction.setParameter2(etSpeakText.getText().toString()); setResult(RESULT_OK); diff --git a/app/src/main/java/com/jens/automation2/ActivityManageStartActivity.java b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java similarity index 86% rename from app/src/main/java/com/jens/automation2/ActivityManageStartActivity.java rename to app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java index c9d6b871..fe8af7f9 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageStartActivity.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionStartActivity.java @@ -35,7 +35,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -public class ActivityManageStartActivity extends Activity +public class ActivityManageActionStartActivity extends Activity { ListView lvIntentPairs; EditText etParameterName, etParameterValue; @@ -56,12 +56,12 @@ public class ActivityManageStartActivity extends Activity ApplicationInfo aInfo1 = this.applicationInfo; if (aInfo1 != null) { - name1 = (String) ActivityManageStartActivity.this.getPackageManager().getApplicationLabel(aInfo1); + name1 = (String) ActivityManageActionStartActivity.this.getPackageManager().getApplicationLabel(aInfo1); } ApplicationInfo aInfo2 = another.applicationInfo; if (aInfo2 != null) { - name2 = (String) ActivityManageStartActivity.this.getPackageManager().getApplicationLabel(aInfo2); + name2 = (String) ActivityManageActionStartActivity.this.getPackageManager().getApplicationLabel(aInfo2); } return name1.compareTo(name2); @@ -224,7 +224,7 @@ public class ActivityManageStartActivity extends Activity { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(getResources().getString(R.string.selectApplication)); - final String[] applicationArray = ActivityManageStartActivity.getApplicationNameListString(this); + final String[] applicationArray = ActivityManageActionStartActivity.getApplicationNameListString(this); alertDialogBuilder.setItems(applicationArray, new DialogInterface.OnClickListener() { @Override @@ -242,14 +242,14 @@ public class ActivityManageStartActivity extends Activity { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(getResources().getString(R.string.selectPackageOfApplication)); - final String[] packageArray = ActivityManageStartActivity.getPackageListString(this, applicationName); + final String[] packageArray = ActivityManageActionStartActivity.getPackageListString(this, applicationName); alertDialogBuilder.setItems(packageArray, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getActionStartActivityDialog3(packageArray[which]).show(); - Miscellaneous.messageBox(getResources().getString(R.string.hint), getResources().getString(R.string.chooseActivityHint), ActivityManageStartActivity.this).show(); + Miscellaneous.messageBox(getResources().getString(R.string.hint), getResources().getString(R.string.chooseActivityHint), ActivityManageActionStartActivity.this).show(); } }); @@ -261,13 +261,13 @@ public class ActivityManageStartActivity extends Activity { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(getResources().getString(R.string.selectActivityToBeStarted)); - final String activityArray[] = ActivityManageStartActivity.getActivityListForPackageName(packageName); + final String activityArray[] = ActivityManageActionStartActivity.getActivityListForPackageName(packageName); alertDialogBuilder.setItems(activityArray, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - ActivityInfo ai = ActivityManageStartActivity.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]); + ActivityInfo ai = ActivityManageActionStartActivity.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]); tvSelectedActivity.setText(ai.packageName + ";" + ai.name); } }); @@ -291,7 +291,7 @@ public class ActivityManageStartActivity extends Activity spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType); tvSelectedActivity = (TextView)findViewById(R.id.tvSelectedApplication); - intentTypeSpinnerAdapter = new ArrayAdapter(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageStartActivity.supportedIntentTypes); + intentTypeSpinnerAdapter = new ArrayAdapter(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes); spinnerParameterType.setAdapter(intentTypeSpinnerAdapter); intentTypeSpinnerAdapter.notifyDataSetChanged(); @@ -304,7 +304,7 @@ public class ActivityManageStartActivity extends Activity { GetActivityListTask getActivityListTask = new GetActivityListTask(); getActivityListTask.execute(); - progressDialog = ProgressDialog.show(ActivityManageStartActivity.this, "", ActivityManageStartActivity.this.getResources().getString(R.string.gettingListOfInstalledApplications)); + progressDialog = ProgressDialog.show(ActivityManageActionStartActivity.this, "", ActivityManageActionStartActivity.this.getResources().getString(R.string.gettingListOfInstalledApplications)); } }); @@ -316,19 +316,19 @@ public class ActivityManageStartActivity extends Activity // type;name;value if(spinnerParameterType.getSelectedItem().toString().length() == 0) { - Toast.makeText(ActivityManageStartActivity.this, getResources().getString(R.string.selectTypeOfIntentPair), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectTypeOfIntentPair), Toast.LENGTH_LONG).show(); return; } if(etParameterName.getText().toString().length() == 0) { - Toast.makeText(ActivityManageStartActivity.this, getResources().getString(R.string.enterNameForIntentPair), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterNameForIntentPair), Toast.LENGTH_LONG).show(); return; } if(etParameterValue.getText().toString().length() == 0) { - Toast.makeText(ActivityManageStartActivity.this, getResources().getString(R.string.enterValueForIntentPair), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterValueForIntentPair), Toast.LENGTH_LONG).show(); return; } @@ -360,7 +360,7 @@ public class ActivityManageStartActivity extends Activity { if(saveAction()) { - ActivityManageStartActivity.this.setResult(RESULT_OK); + ActivityManageActionStartActivity.this.setResult(RESULT_OK); finish(); } } @@ -382,9 +382,9 @@ public class ActivityManageStartActivity extends Activity public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { if(supportedIntentTypes[arg2].equals("double") | supportedIntentTypes[arg2].equals("float") | supportedIntentTypes[arg2].equals("int") | supportedIntentTypes[arg2].equals("long") | supportedIntentTypes[arg2].equals("short")) - ActivityManageStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER); + ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER); else - ActivityManageStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT); + ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT); } @Override @@ -436,7 +436,7 @@ public class ActivityManageStartActivity extends Activity { if(tvSelectedActivity.getText().toString().length() == 0) { - Toast.makeText(ActivityManageStartActivity.this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show(); return false; } @@ -462,7 +462,7 @@ public class ActivityManageStartActivity extends Activity private AlertDialog getIntentPairDialog(final int itemPosition) { - AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityManageStartActivity.this); + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityManageActionStartActivity.this); alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithIntentPair)); alertDialogBuilder.setItems(new String[]{getResources().getString(R.string.delete)}, new DialogInterface.OnClickListener() { @@ -470,7 +470,7 @@ public class ActivityManageStartActivity extends Activity public void onClick(DialogInterface dialog, int which) { // Only 1 choice at the moment, no need to check - ActivityManageStartActivity.this.intentPairList.remove(itemPosition); + ActivityManageActionStartActivity.this.intentPairList.remove(itemPosition); updateIntentPairList(); } }); @@ -484,7 +484,7 @@ public class ActivityManageStartActivity extends Activity @Override protected Void doInBackground(Void... params) { - getActivityList(ActivityManageStartActivity.this); + getActivityList(ActivityManageActionStartActivity.this); return null; } diff --git a/app/src/main/java/com/jens/automation2/ActivityEditTriggerUrl.java b/app/src/main/java/com/jens/automation2/ActivityManageActionTriggerUrl.java similarity index 88% rename from app/src/main/java/com/jens/automation2/ActivityEditTriggerUrl.java rename to app/src/main/java/com/jens/automation2/ActivityManageActionTriggerUrl.java index fc3fc541..66a766cb 100644 --- a/app/src/main/java/com/jens/automation2/ActivityEditTriggerUrl.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionTriggerUrl.java @@ -20,7 +20,7 @@ import com.jens.automation2.Action.Action_Enum; import java.util.Map; -public class ActivityEditTriggerUrl extends Activity +public class ActivityManageActionTriggerUrl extends Activity { Button bSaveTriggerUrl; EditText etTriggerUrl, etTriggerUrlUsername, etTriggerUrlPassword; @@ -70,7 +70,7 @@ public class ActivityEditTriggerUrl extends Activity if(password == null) password = ""; - ActivityEditTriggerUrl.resultingAction.setParameter2( + ActivityManageActionTriggerUrl.resultingAction.setParameter2( username + ";" + password + ";" + etTriggerUrl.getText().toString().trim() @@ -110,16 +110,16 @@ public class ActivityEditTriggerUrl extends Activity updateListView(); - ActivityEditTriggerUrl.edit = getIntent().getBooleanExtra("edit", false); + ActivityManageActionTriggerUrl.edit = getIntent().getBooleanExtra("edit", false); if(edit) { // username,password,URL - String[] components = ActivityEditTriggerUrl.resultingAction.getParameter2().split(";"); + String[] components = ActivityManageActionTriggerUrl.resultingAction.getParameter2().split(";"); if(components.length >= 3) { etTriggerUrl.setText(components[2]); - chkTriggerUrlUseAuthentication.setChecked(ActivityEditTriggerUrl.resultingAction.getParameter1()); + chkTriggerUrlUseAuthentication.setChecked(ActivityManageActionTriggerUrl.resultingAction.getParameter1()); etTriggerUrlUsername.setText(components[0]); etTriggerUrlPassword.setText(components[1]); } @@ -141,9 +141,9 @@ public class ActivityEditTriggerUrl extends Activity if(password == null) password = ""; - ActivityEditTriggerUrl.resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked()); + ActivityManageActionTriggerUrl.resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked()); - ActivityEditTriggerUrl.resultingAction.setParameter2( + ActivityManageActionTriggerUrl.resultingAction.setParameter2( username + ";" + password + ";" + etTriggerUrl.getText().toString() diff --git a/app/src/main/java/com/jens/automation2/ActivityManageRule.java b/app/src/main/java/com/jens/automation2/ActivityManageRule.java index c258a319..c9f0e539 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageRule.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageRule.java @@ -237,8 +237,8 @@ public class ActivityManageRule extends Activity // case speed: // break; case timeFrame: - ActivityManageTimeFrame.editedTimeFrameTrigger = selectedTrigger; - Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTimeFrame.class); + ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger; + Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTimeFrame.class); startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeEdit); break; // case usb_host_connection: @@ -246,8 +246,8 @@ public class ActivityManageRule extends Activity // case wifiConnection: // break; case bluetoothConnection: - ActivityManageBluetoothTrigger.editedBluetoothTrigger = selectedTrigger; - Intent bluetoothEditor = new Intent(ActivityManageRule.this, ActivityManageBluetoothTrigger.class); + ActivityManageTriggerBluetooth.editedBluetoothTrigger = selectedTrigger; + Intent bluetoothEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerBluetooth.class); startActivityForResult(bluetoothEditor, requestCodeTriggerBluetoothEdit); break; case notification: @@ -298,15 +298,15 @@ public class ActivityManageRule extends Activity // case setAirplaneMode: // break; case startOtherActivity: - Intent intent = new Intent(ActivityManageRule.this, ActivityManageStartActivity.class); - ActivityManageStartActivity.resultingAction = a; + Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class); + ActivityManageActionStartActivity.resultingAction = a; intent.putExtra("edit", true); startActivityForResult(intent, requestCodeActionStartActivityEdit); break; case triggerUrl: - Intent activityEditTriggerUrlIntent = new Intent(ActivityManageRule.this, ActivityEditTriggerUrl.class); + Intent activityEditTriggerUrlIntent = new Intent(ActivityManageRule.this, ActivityManageActionTriggerUrl.class); // activityEditTriggerUrlIntent.putExtra("urlToTrigger", a.getParameter2()); - ActivityEditTriggerUrl.resultingAction = a; + ActivityManageActionTriggerUrl.resultingAction = a; activityEditTriggerUrlIntent.putExtra("edit", true); startActivityForResult(activityEditTriggerUrlIntent, requestCodeActionTriggerUrlEdit); break; @@ -331,19 +331,19 @@ public class ActivityManageRule extends Activity // case wakeupDevice: // break; case speakText: - Intent activitySpeakTextIntent = new Intent(ActivityManageRule.this, ActivityEditSpeakText.class); - ActivityEditSpeakText.resultingAction = a; + Intent activitySpeakTextIntent = new Intent(ActivityManageRule.this, ActivityManageActionSpeakText.class); + ActivityManageActionSpeakText.resultingAction = a; activitySpeakTextIntent.putExtra("edit", true); startActivityForResult(activitySpeakTextIntent, requestCodeActionSpeakTextEdit); break; case sendTextMessage: - Intent activitySendTextMessageIntent = new Intent(ActivityManageRule.this, ActivityEditSendTextMessage.class); - ActivityEditSendTextMessage.resultingAction = a; + Intent activitySendTextMessageIntent = new Intent(ActivityManageRule.this, ActivityManageActionSendTextMessage.class); + ActivityManageActionSendTextMessage.resultingAction = a; activitySendTextMessageIntent.putExtra("edit", true); startActivityForResult(activitySendTextMessageIntent, requestCodeActionSendTextMessage); break; case setScreenBrightness: - Intent activityEditScreenBrightnessIntent = new Intent(ActivityManageRule.this, ActivityManageBrightnessSetting.class); + Intent activityEditScreenBrightnessIntent = new Intent(ActivityManageRule.this, ActivityManageActionBrightnessSetting.class); // ActivityEditTriggerUrl.resultingAction = a; activityEditScreenBrightnessIntent.putExtra("autoBrightness", a.getParameter1()); activityEditScreenBrightnessIntent.putExtra("brightnessValue", Integer.parseInt(a.getParameter2())); @@ -540,8 +540,8 @@ public class ActivityManageRule extends Activity else if(triggerType == Trigger_Enum.timeFrame) { newTrigger.setTriggerType(Trigger_Enum.timeFrame); - ActivityManageTimeFrame.editedTimeFrameTrigger = newTrigger; - Intent timeFrameEditor = new Intent(myContext, ActivityManageTimeFrame.class); + ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = newTrigger; + Intent timeFrameEditor = new Intent(myContext, ActivityManageTriggerTimeFrame.class); startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeAdd); return; } @@ -598,7 +598,7 @@ public class ActivityManageRule extends Activity if(NfcReceiver.checkNfcRequirements(ActivityManageRule.this, true)) { newTrigger.setTriggerType(Trigger_Enum.nfcTag); - Intent nfcEditor = new Intent(myContext, ActivityManageNfc.class); + Intent nfcEditor = new Intent(myContext, ActivityManageTriggerNfc.class); startActivityForResult(nfcEditor, requestCodeTriggerNfcTagAdd); return; } @@ -609,8 +609,8 @@ public class ActivityManageRule extends Activity Miscellaneous.messageBox("Bluetooth", getResources().getString(R.string.deviceDoesNotHaveBluetooth), ActivityManageRule.this).show();; newTrigger.setTriggerType(Trigger_Enum.bluetoothConnection); - ActivityManageBluetoothTrigger.editedBluetoothTrigger = newTrigger; - Intent bluetoothEditor = new Intent(myContext, ActivityManageBluetoothTrigger.class); + ActivityManageTriggerBluetooth.editedBluetoothTrigger = newTrigger; + Intent bluetoothEditor = new Intent(myContext, ActivityManageTriggerBluetooth.class); startActivityForResult(bluetoothEditor, requestCodeTriggerBluetoothAdd); return; } @@ -1005,7 +1005,7 @@ public class ActivityManageRule extends Activity protected String[] doInBackground(ActivityManageRule... params) { // Looper.prepare(); - final String[] applicationArray = ActivityManageStartActivity.getApplicationNameListString(params[0]); + final String[] applicationArray = ActivityManageActionStartActivity.getApplicationNameListString(params[0]); return applicationArray; } @@ -1052,7 +1052,7 @@ public class ActivityManageRule extends Activity { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(myContext); alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectPackageOfApplication)); - final String[] packageArray = ActivityManageStartActivity.getPackageListString(myContext, applicationName); + final String[] packageArray = ActivityManageActionStartActivity.getPackageListString(myContext, applicationName); alertDialogBuilder.setItems(packageArray, new DialogInterface.OnClickListener() { @Override @@ -1072,7 +1072,7 @@ public class ActivityManageRule extends Activity { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(myContext); alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectActivityToBeStarted)); - final String activityArray[] = ActivityManageStartActivity.getActivityListForPackageName(packageName); + final String activityArray[] = ActivityManageActionStartActivity.getActivityListForPackageName(packageName); alertDialogBuilder.setItems(activityArray, new DialogInterface.OnClickListener() { @Override @@ -1100,7 +1100,7 @@ public class ActivityManageRule extends Activity if(resultCode == RESULT_OK) { //add TriggerUrl - ruleToEdit.getActionSet().add(ActivityEditTriggerUrl.resultingAction); + ruleToEdit.getActionSet().add(ActivityManageActionTriggerUrl.resultingAction); this.refreshActionList(); } } @@ -1115,7 +1115,7 @@ public class ActivityManageRule extends Activity else if(requestCode == requestCodeTriggerTimeframeAdd) { //add TimeFrame - if(resultCode == RESULT_OK && ActivityManageTimeFrame.editedTimeFrameTrigger != null) + if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null) { ruleToEdit.getTriggerSet().add(newTrigger); this.refreshTriggerList(); @@ -1126,7 +1126,7 @@ public class ActivityManageRule extends Activity else if(requestCode == requestCodeTriggerTimeframeEdit) { //edit TimeFrame - if(resultCode == RESULT_OK && ActivityManageTimeFrame.editedTimeFrameTrigger != null) + if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null) { this.refreshTriggerList(); } @@ -1138,7 +1138,7 @@ public class ActivityManageRule extends Activity // manage start of other activity if(resultCode == RESULT_OK) { - newAction = ActivityManageStartActivity.resultingAction; + newAction = ActivityManageActionStartActivity.resultingAction; ruleToEdit.getActionSet().add(newAction); this.refreshActionList(); } @@ -1148,7 +1148,7 @@ public class ActivityManageRule extends Activity // manage start of other activity if(resultCode == RESULT_OK) { - newAction = ActivityManageStartActivity.resultingAction; + newAction = ActivityManageActionStartActivity.resultingAction; // ruleToEdit.getActionSet().add(newAction); this.refreshActionList(); } @@ -1156,9 +1156,9 @@ public class ActivityManageRule extends Activity else if(requestCode == requestCodeTriggerNfcTagAdd) { //add TimeFrame - if(resultCode == RESULT_OK && ActivityManageNfc.generatedId != null) + if(resultCode == RESULT_OK && ActivityManageTriggerNfc.generatedId != null) { - newTrigger.setNfcTagId(ActivityManageNfc.generatedId); + newTrigger.setNfcTagId(ActivityManageTriggerNfc.generatedId); ruleToEdit.getTriggerSet().add(newTrigger); this.refreshTriggerList(); } @@ -1198,7 +1198,7 @@ public class ActivityManageRule extends Activity if(resultCode == RESULT_OK) { //add SpeakText - ruleToEdit.getActionSet().add(ActivityEditSpeakText.resultingAction); + ruleToEdit.getActionSet().add(ActivityManageActionSpeakText.resultingAction); this.refreshActionList(); } } @@ -1207,14 +1207,14 @@ public class ActivityManageRule extends Activity if(resultCode == RESULT_OK) { //add SpeakText - ruleToEdit.getActionSet().add(ActivityEditSendTextMessage.resultingAction); + ruleToEdit.getActionSet().add(ActivityManageActionSendTextMessage.resultingAction); this.refreshActionList(); } } else if(requestCode == requestCodeTriggerBluetoothAdd) { //add bluetooth trigger - if(resultCode == RESULT_OK && ActivityManageBluetoothTrigger.editedBluetoothTrigger != null) + if(resultCode == RESULT_OK && ActivityManageTriggerBluetooth.editedBluetoothTrigger != null) { ruleToEdit.getTriggerSet().add(newTrigger); this.refreshTriggerList(); @@ -1225,7 +1225,7 @@ public class ActivityManageRule extends Activity else if(requestCode == requestCodeTriggerBluetoothEdit) { //edit bluetooth trigger - if(resultCode == RESULT_OK && ActivityManageBluetoothTrigger.editedBluetoothTrigger != null) + if(resultCode == RESULT_OK && ActivityManageTriggerBluetooth.editedBluetoothTrigger != null) { this.refreshTriggerList(); } @@ -1260,7 +1260,7 @@ public class ActivityManageRule extends Activity if(resultCode == RESULT_OK) { newAction.setParameter1(data.getBooleanExtra("actionParameter1", false)); - newAction.setParameter2(String.valueOf(data.getIntExtra("actionParameter2", 0))); + newAction.setParameter2(data.getStringExtra("actionParameter2")); ruleToEdit.getActionSet().add(newAction); this.refreshActionList(); } @@ -1273,7 +1273,7 @@ public class ActivityManageRule extends Activity ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra("actionParameter1", false)); if(data.hasExtra("actionParameter2")) - ruleToEdit.getActionSet().get(editIndex).setParameter2(String.valueOf(data.getIntExtra("actionParameter2", 0))); + ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra("actionParameter2")); this.refreshActionList(); } @@ -1374,8 +1374,8 @@ public class ActivityManageRule extends Activity { //launch other activity to enter a url and parameters; newAction.setAction(Action_Enum.triggerUrl); - ActivityEditTriggerUrl.resultingAction = null; - Intent editTriggerIntent = new Intent(context, ActivityEditTriggerUrl.class); + ActivityManageActionTriggerUrl.resultingAction = null; + Intent editTriggerIntent = new Intent(context, ActivityManageActionTriggerUrl.class); startActivityForResult(editTriggerIntent, 1000); } else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setWifi.toString())) @@ -1422,7 +1422,7 @@ public class ActivityManageRule extends Activity else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.startOtherActivity.toString())) { newAction.setAction(Action_Enum.startOtherActivity); - Intent intent = new Intent(ActivityManageRule.this, ActivityManageStartActivity.class); + Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class); startActivityForResult(intent, 3000); } else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.waitBeforeNextAction.toString())) @@ -1455,8 +1455,8 @@ public class ActivityManageRule extends Activity { //launch other activity to enter a url and parameters; newAction.setAction(Action_Enum.speakText); - ActivityEditSpeakText.resultingAction = null; - Intent editTriggerIntent = new Intent(context, ActivityEditSpeakText.class); + ActivityManageActionSpeakText.resultingAction = null; + Intent editTriggerIntent = new Intent(context, ActivityManageActionSpeakText.class); startActivityForResult(editTriggerIntent, 5000); } else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendTextMessage.toString())) @@ -1466,8 +1466,8 @@ public class ActivityManageRule extends Activity { //launch other activity to enter parameters; newAction.setAction(Action_Enum.sendTextMessage); - ActivityEditSendTextMessage.resultingAction = null; - Intent editTriggerIntent = new Intent(context, ActivityEditSendTextMessage.class); + ActivityManageActionSendTextMessage.resultingAction = null; + Intent editTriggerIntent = new Intent(context, ActivityManageActionSendTextMessage.class); startActivityForResult(editTriggerIntent, 5001); } } @@ -1480,7 +1480,7 @@ public class ActivityManageRule extends Activity else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setScreenBrightness.toString())) { newAction.setAction(Action_Enum.setScreenBrightness); - Intent actionScreenBrightnessIntent = new Intent(context, ActivityManageBrightnessSetting.class); + Intent actionScreenBrightnessIntent = new Intent(context, ActivityManageActionBrightnessSetting.class); startActivityForResult(actionScreenBrightnessIntent, requestCodeActionScreenBrightnessAdd); } else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.playSound.toString())) diff --git a/app/src/main/java/com/jens/automation2/ActivityManageBluetoothTrigger.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerBluetooth.java similarity index 96% rename from app/src/main/java/com/jens/automation2/ActivityManageBluetoothTrigger.java rename to app/src/main/java/com/jens/automation2/ActivityManageTriggerBluetooth.java index 6f6d5dc9..2bdd6563 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageBluetoothTrigger.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerBluetooth.java @@ -16,7 +16,7 @@ import android.widget.Toast; import com.jens.automation2.receivers.BluetoothReceiver; -public class ActivityManageBluetoothTrigger extends Activity +public class ActivityManageTriggerBluetooth extends Activity { protected static Trigger editedBluetoothTrigger; RadioButton radioAnyBluetoothDevice, radioNoDevice, radioDeviceFromList, radioBluetoothConnected, radioBluetoothDisconnected, radioBluetoothInRange, radioBluetoothOutRange; @@ -109,7 +109,7 @@ public class ActivityManageBluetoothTrigger extends Activity } else { - Toast.makeText(ActivityManageBluetoothTrigger.this, getResources().getString(R.string.selectDeviceOption), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageTriggerBluetooth.this, getResources().getString(R.string.selectDeviceOption), Toast.LENGTH_LONG).show(); return false; } @@ -138,7 +138,7 @@ public class ActivityManageBluetoothTrigger extends Activity } else { - Toast.makeText(ActivityManageBluetoothTrigger.this, getResources().getString(R.string.selectConnectionOption), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageTriggerBluetooth.this, getResources().getString(R.string.selectConnectionOption), Toast.LENGTH_LONG).show(); return false; } diff --git a/app/src/main/java/com/jens/automation2/ActivityManageNfc.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerNfc.java similarity index 84% rename from app/src/main/java/com/jens/automation2/ActivityManageNfc.java rename to app/src/main/java/com/jens/automation2/ActivityManageTriggerNfc.java index 59fe242d..7f83691b 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageNfc.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerNfc.java @@ -21,7 +21,7 @@ import android.widget.Toast; import com.jens.automation2.receivers.NfcReceiver; @SuppressLint("NewApi") -public class ActivityManageNfc extends Activity +public class ActivityManageTriggerNfc extends Activity { public static String generatedId = null; private static Tag discoveredTag = null; @@ -39,7 +39,7 @@ public class ActivityManageNfc extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.manage_nfc); + setContentView(R.layout.activity_manage_trigger_nfc); etNewNfcIdValue = (EditText)findViewById(R.id.etNewNfcIdValue); bReadNfcTag = (Button)findViewById(R.id.bReadNfcTag); @@ -59,7 +59,7 @@ public class ActivityManageNfc extends Activity } else { - progressDialog = ProgressDialog.show(ActivityManageNfc.this, null, getResources().getString(R.string.nfcBringTagIntoRange), false, true, new OnCancelListener() + progressDialog = ProgressDialog.show(ActivityManageTriggerNfc.this, null, getResources().getString(R.string.nfcBringTagIntoRange), false, true, new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) @@ -88,7 +88,7 @@ public class ActivityManageNfc extends Activity } else { - progressDialog = ProgressDialog.show(ActivityManageNfc.this, null, getResources().getString(R.string.nfcBringTagIntoRange), false, true, new OnCancelListener() + progressDialog = ProgressDialog.show(ActivityManageTriggerNfc.this, null, getResources().getString(R.string.nfcBringTagIntoRange), false, true, new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) @@ -118,7 +118,7 @@ public class ActivityManageNfc extends Activity } else { - progressDialog = ProgressDialog.show(ActivityManageNfc.this, null, getResources().getString(R.string.nfcBringTagIntoRange), false, true, new OnCancelListener() + progressDialog = ProgressDialog.show(ActivityManageTriggerNfc.this, null, getResources().getString(R.string.nfcBringTagIntoRange), false, true, new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) @@ -255,7 +255,7 @@ public class ActivityManageNfc extends Activity if(generatedId.length() == 0) { generatedId = null; - Toast.makeText(ActivityManageNfc.this, getResources().getString(R.string.nfcEnterValidIdentifier), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageTriggerNfc.this, getResources().getString(R.string.nfcEnterValidIdentifier), Toast.LENGTH_LONG).show(); return false; } else @@ -267,14 +267,14 @@ public class ActivityManageNfc extends Activity if(NfcReceiver.writeTag(generatedId, discoveredTag)) { currentStatus = 0; - Toast.makeText(ActivityManageNfc.this, getResources().getString(R.string.nfcTagWrittenSuccessfully), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageTriggerNfc.this, getResources().getString(R.string.nfcTagWrittenSuccessfully), Toast.LENGTH_LONG).show(); setResult(RESULT_OK); finish(); } else { currentStatus = 0; - Toast.makeText(ActivityManageNfc.this, getResources().getString(R.string.nfcTagWriteError), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageTriggerNfc.this, getResources().getString(R.string.nfcTagWriteError), Toast.LENGTH_LONG).show(); Miscellaneous.logEvent("e", "NFC", getResources().getString(R.string.nfcTagWriteError), 2); } } @@ -285,14 +285,14 @@ public class ActivityManageNfc extends Activity if(checkEnteredText(false)) { currentStatus = 0; - Toast.makeText(ActivityManageNfc.this, getResources().getString(R.string.nfcTagReadSuccessfully), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageTriggerNfc.this, getResources().getString(R.string.nfcTagReadSuccessfully), Toast.LENGTH_LONG).show(); setResult(RESULT_OK); finish(); } else { currentStatus = 0; - Toast.makeText(ActivityManageNfc.this, getResources().getString(R.string.nfcValueNotSuitable), Toast.LENGTH_LONG).show(); + Toast.makeText(ActivityManageTriggerNfc.this, getResources().getString(R.string.nfcValueNotSuitable), Toast.LENGTH_LONG).show(); generatedId = null; } } diff --git a/app/src/main/java/com/jens/automation2/ActivityManageTimeFrame.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerTimeFrame.java similarity index 98% rename from app/src/main/java/com/jens/automation2/ActivityManageTimeFrame.java rename to app/src/main/java/com/jens/automation2/ActivityManageTriggerTimeFrame.java index ffd81d1f..1a8b54c2 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageTimeFrame.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerTimeFrame.java @@ -14,7 +14,7 @@ import java.sql.Time; import java.util.ArrayList; import java.util.Calendar; -public class ActivityManageTimeFrame extends Activity +public class ActivityManageTriggerTimeFrame extends Activity { Button bSaveTimeFrame; TimePicker startPicker, stopPicker; diff --git a/app/src/main/java/com/jens/automation2/ActivityPermissions.java b/app/src/main/java/com/jens/automation2/ActivityPermissions.java index ff1b31ff..a7b18e9a 100644 --- a/app/src/main/java/com/jens/automation2/ActivityPermissions.java +++ b/app/src/main/java/com/jens/automation2/ActivityPermissions.java @@ -244,6 +244,12 @@ public class ActivityPermissions extends Activity if (!havePermission(s, context)) return true; } + else if(s.equalsIgnoreCase("android.permission.ACTIVITY_RECOGNITION") || s.equalsIgnoreCase("com.google.android.gms.permission.ACTIVITY_RECOGNITION")) + { + if(!BuildConfig.FLAVOR.equalsIgnoreCase("fdroidFlavor")) + if (!havePermission(s, context)) + return true; + } else if (!havePermission(s, context)) return true; @@ -302,12 +308,15 @@ public class ActivityPermissions extends Activity // if (!havePermission(ActivityPermissions.writeExternalStoragePermissionName, workingContext)) // addToArrayListUnique(ActivityPermissions.writeExternalStoragePermissionName, requiredPermissions); - for(Profile profile : Profile.getProfileCollection()) + if(!havePermission(writeSystemSettingsPermissionName, workingContext)) { - if(profile.changeIncomingCallsRingtone) - { - addToArrayListUnique("android.permission.WRITE_SETTINGS", requiredPermissions); - } + for (Profile profile : Profile.getProfileCollection()) + { + if (profile.changeIncomingCallsRingtone) + { + addToArrayListUnique(writeSystemSettingsPermissionName, requiredPermissions); + } + } } if (!onlyGeneral) @@ -329,6 +338,11 @@ public class ActivityPermissions extends Activity if (!Miscellaneous.googleToBlameForLocation(true)) addToArrayListUnique(singlePermission, requiredPermissions); } + else if(singlePermission.equalsIgnoreCase("android.permission.ACTIVITY_RECOGNITION") || singlePermission.equalsIgnoreCase("com.google.android.gms.permission.ACTIVITY_RECOGNITION")) + { + if(!BuildConfig.FLAVOR.equalsIgnoreCase("fdroidFlavor")) + addToArrayListUnique(singlePermission, requiredPermissions); + } else addToArrayListUnique(singlePermission, requiredPermissions); } diff --git a/app/src/main/java/com/jens/automation2/CompensateCrappyAndroidPaths.java b/app/src/main/java/com/jens/automation2/CompensateCrappyAndroidPaths.java index cbf2d625..535acf0b 100644 --- a/app/src/main/java/com/jens/automation2/CompensateCrappyAndroidPaths.java +++ b/app/src/main/java/com/jens/automation2/CompensateCrappyAndroidPaths.java @@ -33,7 +33,8 @@ public class CompensateCrappyAndroidPaths * @param uri The Uri to query. */ @SuppressLint("NewApi") - public static String getPath(final Context context, final Uri uri) { + public static String getPath(final Context context, final Uri uri) + { // check here to KITKAT or new version final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; String selection = null; diff --git a/app/src/main/java/com/jens/automation2/FileShareProvider.java b/app/src/main/java/com/jens/automation2/FileShareProvider.java new file mode 100644 index 00000000..574fa728 --- /dev/null +++ b/app/src/main/java/com/jens/automation2/FileShareProvider.java @@ -0,0 +1,65 @@ +package com.jens.automation2; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.ParcelFileDescriptor; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.io.File; +import java.io.FileNotFoundException; +import java.security.Provider; + +public class FileShareProvider extends ContentProvider +{ + @Override + public boolean onCreate() + { + return false; + } + + @Nullable + @Override + public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) + { + return null; + } + + @Nullable + @Override + public String getType(@NonNull Uri uri) + { + return null; + } + + @Nullable + @Override + public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) + { + return null; + } + + @Override + public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) + { + return 0; + } + + @Override + public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) + { + return 0; + } + + @Override + public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException + { + File cacheDir = getContext().getCacheDir(); + File privateFile = new File(cacheDir, Settings.zipFileName); + + return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_ONLY); + } +} diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index d16d2f88..247ca00f 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -22,6 +22,7 @@ import android.provider.MediaStore; import android.provider.Settings.Secure; import android.util.Base64; import android.util.Log; +import android.widget.Toast; import com.jens.automation2.location.LocationProvider; import com.jens.automation2.receivers.PhoneStatusListener; @@ -42,6 +43,8 @@ import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -71,6 +74,9 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.Scanner; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; @@ -84,11 +90,12 @@ import javax.xml.parsers.ParserConfigurationException; import androidx.core.app.NotificationCompat; +import static android.provider.CalendarContract.CalendarCache.URI; import static com.jens.automation2.AutomationService.NOTIFICATION_CHANNEL_ID; import static com.jens.automation2.AutomationService.channelName; public class Miscellaneous extends Service -{ +{ protected static String writeableFolderStringCache = null; public static final String lineSeparator = System.getProperty("line.separator"); @@ -1226,4 +1233,98 @@ public class Miscellaneous extends Service return false; } + + public static void zip(String[] _files, String zipFileName) + { + int BUFFER = 2048; + try + { + BufferedInputStream origin = null; + FileOutputStream dest = new FileOutputStream(zipFileName); + ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream( + dest)); + byte data[] = new byte[BUFFER]; + + for (int i = 0; i < _files.length; i++) + { + Log.v("Compress", "Adding: " + _files[i]); + FileInputStream fi = new FileInputStream(_files[i]); + origin = new BufferedInputStream(fi, BUFFER); + + ZipEntry entry = new ZipEntry(_files[i].substring(_files[i].lastIndexOf("/") + 1)); + out.putNextEntry(entry); + int count; + + while ((count = origin.read(data, 0, BUFFER)) != -1) + { + out.write(data, 0, count); + } + origin.close(); + } + + out.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static void unzip(String _zipFile, String _targetLocation) + { + int BUFFER = 2048; + + try + { + FileInputStream fin = new FileInputStream(_zipFile); + ZipInputStream zin = new ZipInputStream(fin); + ZipEntry ze = null; + while ((ze = zin.getNextEntry()) != null) + { + //create dir if required while unzipping + if (ze.isDirectory()) + { + // dirChecker(ze.getName()); + } + else + { + FileOutputStream fout = new FileOutputStream(_targetLocation + ze.getName()); + for (int c = zin.read(); c != -1; c = zin.read()) + { + fout.write(c); + } + + zin.closeEntry(); + fout.close(); + } + + } + zin.close(); + } + catch (Exception e) + { + System.out.println(e); + } + } + + public static void sendEmail(Context context, String targetAddress, String subject, String message, Uri fileAttachment) + { + try + { + final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); + emailIntent.setType("plain/text"); + emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{targetAddress}); + emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); + if (fileAttachment != null) + { + emailIntent.putExtra(Intent.EXTRA_STREAM, fileAttachment); + } + emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); + context.startActivity(Intent.createChooser(emailIntent, "Sending email...")); + } + catch (Throwable t) + { + Toast.makeText(context, "Request failed try again: "+ t.toString(), Toast.LENGTH_LONG).show(); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/jens/automation2/News.java b/app/src/main/java/com/jens/automation2/News.java index b79cb237..b7e2340d 100644 --- a/app/src/main/java/com/jens/automation2/News.java +++ b/app/src/main/java/com/jens/automation2/News.java @@ -68,7 +68,13 @@ public class News Calendar now = Calendar.getInstance(); String newsContent; - String filePath = context.getFilesDir() + "/appNews.xml"; + String newsFileName = "appNews.xml"; + + String filePath = context.getCacheDir() + "/" + newsFileName; + + File oldFilePath = new File(context.getFilesDir() + "/" + newsFileName); + if(oldFilePath.exists()) + oldFilePath.delete(); if (!(new File(filePath)).exists() || Settings.lastNewsPolltime == -1 || now.getTimeInMillis() >= Settings.lastNewsPolltime + (long)(Settings.newsDisplayForXDays * 24 * 60 * 60 * 1000)) { @@ -80,14 +86,14 @@ public class News { Settings.lastNewsPolltime = now.getTimeInMillis(); Settings.writeSettings(context); - Miscellaneous.logEvent("i", "appNews.xml", "File stored to " + filePath, 5); + Miscellaneous.logEvent("i", newsFileName, "File stored to " + filePath, 5); } } else { // Just read local cache file newsContent = Miscellaneous.readFileToString(filePath); - Miscellaneous.logEvent("i", "appNews.xml", "Using cache to retrieve news: " + filePath, 5); + Miscellaneous.logEvent("i", newsFileName, "Using cache to retrieve news: " + filePath, 5); } ArrayList returnList = new ArrayList<>(); diff --git a/app/src/main/java/com/jens/automation2/Settings.java b/app/src/main/java/com/jens/automation2/Settings.java index 8e7cfc68..319bdc36 100644 --- a/app/src/main/java/com/jens/automation2/Settings.java +++ b/app/src/main/java/com/jens/automation2/Settings.java @@ -16,6 +16,7 @@ public class Settings implements SharedPreferences public static final int newsPollEveryXDays = 3; public static final int newsDisplayForXDays = 3; public static final String folderName = "Automation"; + public static final String zipFileName = "automation.zip"; public static final String constNewsOptInDone ="newsOptInDone"; diff --git a/app/src/main/java/com/jens/automation2/XmlFileInterface.java b/app/src/main/java/com/jens/automation2/XmlFileInterface.java index 4781cb19..6df59de3 100644 --- a/app/src/main/java/com/jens/automation2/XmlFileInterface.java +++ b/app/src/main/java/com/jens/automation2/XmlFileInterface.java @@ -379,7 +379,7 @@ public class XmlFileInterface } catch (XmlPullParserException e) { - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } catch(FileNotFoundException e) { @@ -394,12 +394,12 @@ public class XmlFileInterface } catch(Exception ex) { - + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } } catch (IOException e) { - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } catch(Exception e) { @@ -534,11 +534,11 @@ public class XmlFileInterface } catch (NumberFormatException e) { - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } catch (Exception e) { - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } } else @@ -751,13 +751,11 @@ public class XmlFileInterface } catch (XmlPullParserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } } else if (name.equals("ActionCollection")) @@ -768,13 +766,11 @@ public class XmlFileInterface } catch (XmlPullParserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Miscellaneous.logEvent("e", "XmlFileInterface", Log.getStackTraceString(e), 1); } } else @@ -865,42 +861,45 @@ public class XmlFileInterface if (name.equals("TriggerEvent")) { String triggerEventString = readTag(parser, "TriggerEvent"); - if(triggerEventString.equals("pointOfInterest")) - newTrigger.setTriggerType(Trigger_Enum.pointOfInterest); - else if(triggerEventString.equals("timeFrame")) - newTrigger.setTriggerType(Trigger_Enum.timeFrame); - else if(triggerEventString.equals("charging")) - newTrigger.setTriggerType(Trigger_Enum.charging); - else if(triggerEventString.equals("usb_host_connection")) - newTrigger.setTriggerType(Trigger_Enum.usb_host_connection); - else if(triggerEventString.equals("batteryLevel")) - newTrigger.setTriggerType(Trigger_Enum.batteryLevel); - else if(triggerEventString.equals("speed")) - newTrigger.setTriggerType(Trigger_Enum.speed); - else if(triggerEventString.equals("noiseLevel")) - newTrigger.setTriggerType(Trigger_Enum.noiseLevel); - else if(triggerEventString.equals("wifiConnection")) - newTrigger.setTriggerType(Trigger_Enum.wifiConnection); - else if(triggerEventString.equals("process_started_stopped") | triggerEventString.equals("process_running")) +// if(triggerEventString.equals("pointOfInterest")) +// newTrigger.setTriggerType(Trigger_Enum.pointOfInterest); +// else if(triggerEventString.equals("timeFrame")) +// newTrigger.setTriggerType(Trigger_Enum.timeFrame); +// else if(triggerEventString.equals("charging")) +// newTrigger.setTriggerType(Trigger_Enum.charging); +// else if(triggerEventString.equals("usb_host_connection")) +// newTrigger.setTriggerType(Trigger_Enum.usb_host_connection); +// else if(triggerEventString.equals("batteryLevel")) +// newTrigger.setTriggerType(Trigger_Enum.batteryLevel); +// else if(triggerEventString.equals("speed")) +// newTrigger.setTriggerType(Trigger_Enum.speed); +// else if(triggerEventString.equals("noiseLevel")) +// newTrigger.setTriggerType(Trigger_Enum.noiseLevel); +// else if(triggerEventString.equals("wifiConnection")) +// newTrigger.setTriggerType(Trigger_Enum.wifiConnection); +// else + if(triggerEventString.equals("process_started_stopped") | triggerEventString.equals("process_running")) newTrigger.setTriggerType(Trigger_Enum.process_started_stopped); - else if(triggerEventString.equals("airplaneMode")) - newTrigger.setTriggerType(Trigger_Enum.airplaneMode); - else if(triggerEventString.equals("roaming")) - newTrigger.setTriggerType(Trigger_Enum.roaming); - else if(triggerEventString.equals("phoneCall")) - newTrigger.setTriggerType(Trigger_Enum.phoneCall); - else if(triggerEventString.equals("nfcTag")) - newTrigger.setTriggerType(Trigger_Enum.nfcTag); - else if(triggerEventString.equals("notification")) - newTrigger.setTriggerType(Trigger_Enum.notification); - else if(triggerEventString.equals("activityDetection")) - newTrigger.setTriggerType(Trigger_Enum.activityDetection); - else if(triggerEventString.equals("bluetoothConnection")) - newTrigger.setTriggerType(Trigger_Enum.bluetoothConnection); - else if(triggerEventString.equals("headsetPlugged")) - newTrigger.setTriggerType(Trigger_Enum.headsetPlugged); - else if(triggerEventString.equals("notification")) - newTrigger.setTriggerType(Trigger_Enum.notification); +// else if(triggerEventString.equals("airplaneMode")) +// newTrigger.setTriggerType(Trigger_Enum.airplaneMode); +// else if(triggerEventString.equals("roaming")) +// newTrigger.setTriggerType(Trigger_Enum.roaming); +// else if(triggerEventString.equals("phoneCall")) +// newTrigger.setTriggerType(Trigger_Enum.phoneCall); +// else if(triggerEventString.equals("nfcTag")) +// newTrigger.setTriggerType(Trigger_Enum.nfcTag); +// else if(triggerEventString.equals("notification")) +// newTrigger.setTriggerType(Trigger_Enum.notification); +// else if(triggerEventString.equals("activityDetection")) +// newTrigger.setTriggerType(Trigger_Enum.activityDetection); +// else if(triggerEventString.equals("bluetoothConnection")) +// newTrigger.setTriggerType(Trigger_Enum.bluetoothConnection); +// else if(triggerEventString.equals("headsetPlugged")) +// newTrigger.setTriggerType(Trigger_Enum.headsetPlugged); +// else if(triggerEventString.equals("notification")) +// newTrigger.setTriggerType(Trigger_Enum.notification); + else + newTrigger.setTriggerType(Trigger_Enum.valueOf(triggerEventString)); } else if (name.equals("TriggerParameter1")) { @@ -1080,19 +1079,20 @@ public class XmlFileInterface { String actionNameString = readTag(parser, "ActionName"); - if(actionNameString.equals("setWifi")) - newAction.setAction(Action_Enum.setWifi); - else if(actionNameString.equals("setBluetooth")) - newAction.setAction(Action_Enum.setBluetooth); - else if(actionNameString.equals("setUsbTethering")) - newAction.setAction(Action_Enum.setUsbTethering); - else if(actionNameString.equals("setWifiTethering")) - newAction.setAction(Action_Enum.setWifiTethering); - else if(actionNameString.equals("setDisplayRotation")) - newAction.setAction(Action_Enum.setDisplayRotation); +// if(actionNameString.equals("setWifi")) +// newAction.setAction(Action_Enum.setWifi); +// else if(actionNameString.equals("setBluetooth")) +// newAction.setAction(Action_Enum.setBluetooth); +// else if(actionNameString.equals("setUsbTethering")) +// newAction.setAction(Action_Enum.setUsbTethering); +// else if(actionNameString.equals("setWifiTethering")) +// newAction.setAction(Action_Enum.setWifiTethering); +// else if(actionNameString.equals("setDisplayRotation")) +// newAction.setAction(Action_Enum.setDisplayRotation); // *** deprecated - else if(actionNameString.equals("turnWifiOn")) + //else + if(actionNameString.equals("turnWifiOn")) newAction.setAction(Action_Enum.turnWifiOn); else if(actionNameString.equals("turnWifiOff")) newAction.setAction(Action_Enum.turnWifiOff); @@ -1114,28 +1114,30 @@ public class XmlFileInterface newAction.setAction(Action_Enum.disableScreenRotation); // *** deprecated - else if(actionNameString.equals("triggerUrl")) - newAction.setAction(Action_Enum.triggerUrl); - else if(actionNameString.equals("changeSoundProfile")) - newAction.setAction(Action_Enum.changeSoundProfile); - else if(actionNameString.equals("startOtherActivity")) - newAction.setAction(Action_Enum.startOtherActivity); - else if(actionNameString.equals("waitBeforeNextAction")) - newAction.setAction(Action_Enum.waitBeforeNextAction); - else if(actionNameString.equals("wakeupDevice")) - newAction.setAction(Action_Enum.wakeupDevice); - else if(actionNameString.equals("setAirplaneMode")) - newAction.setAction(Action_Enum.setAirplaneMode); - else if(actionNameString.equals("setDataConnection")) - newAction.setAction(Action_Enum.setDataConnection); - else if(actionNameString.equals("speakText")) - newAction.setAction(Action_Enum.speakText); - else if(actionNameString.equals("sendTextMessage")) - newAction.setAction(Action_Enum.sendTextMessage); - else if(actionNameString.equals("playMusic")) - newAction.setAction(Action_Enum.playMusic); - else if(actionNameString.equals("setScreenBrightness")) - newAction.setAction(Action_Enum.setScreenBrightness); +// else if(actionNameString.equals("triggerUrl")) +// newAction.setAction(Action_Enum.triggerUrl); +// else if(actionNameString.equals("changeSoundProfile")) +// newAction.setAction(Action_Enum.changeSoundProfile); +// else if(actionNameString.equals("startOtherActivity")) +// newAction.setAction(Action_Enum.startOtherActivity); +// else if(actionNameString.equals("waitBeforeNextAction")) +// newAction.setAction(Action_Enum.waitBeforeNextAction); +// else if(actionNameString.equals("wakeupDevice")) +// newAction.setAction(Action_Enum.wakeupDevice); +// else if(actionNameString.equals("setAirplaneMode")) +// newAction.setAction(Action_Enum.setAirplaneMode); +// else if(actionNameString.equals("setDataConnection")) +// newAction.setAction(Action_Enum.setDataConnection); +// else if(actionNameString.equals("speakText")) +// newAction.setAction(Action_Enum.speakText); +// else if(actionNameString.equals("sendTextMessage")) +// newAction.setAction(Action_Enum.sendTextMessage); +// else if(actionNameString.equals("playMusic")) +// newAction.setAction(Action_Enum.playMusic); +// else if(actionNameString.equals("setScreenBrightness")) +// newAction.setAction(Action_Enum.setScreenBrightness); + else + newAction.setAction(Action_Enum.valueOf(actionNameString)); } else if (name.equals("ActionParameter1")) { diff --git a/app/src/main/res/layout/activity_manage_play_sound.xml b/app/src/main/res/layout/activity_manage_play_sound.xml index 214b42b5..f5c2d56d 100644 --- a/app/src/main/res/layout/activity_manage_play_sound.xml +++ b/app/src/main/res/layout/activity_manage_play_sound.xml @@ -24,8 +24,8 @@ android:layout_height="wrap_content" android:text="@string/alwaysPlayExplanation" /> - diff --git a/app/src/main/res/layout/manage_nfc.xml b/app/src/main/res/layout/activity_manage_trigger_nfc.xml similarity index 100% rename from app/src/main/res/layout/manage_nfc.xml rename to app/src/main/res/layout/activity_manage_trigger_nfc.xml diff --git a/app/src/main/res/layout/main_overview_layout.xml b/app/src/main/res/layout/main_overview_layout.xml index e4d849ba..078060a2 100644 --- a/app/src/main/res/layout/main_overview_layout.xml +++ b/app/src/main/res/layout/main_overview_layout.xml @@ -376,6 +376,13 @@ android:gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" /> + +