2021-02-16 13:42:49 +01:00
|
|
|
package com.jens.automation2;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.InputType;
|
|
|
|
import android.text.util.Linkify;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnTouchListener;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
|
|
|
import android.widget.AdapterView.OnItemLongClickListener;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ListAdapter;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2021-02-16 20:24:12 +01:00
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
2021-02-16 13:42:49 +01:00
|
|
|
import com.jens.automation2.Action.Action_Enum;
|
|
|
|
import com.jens.automation2.Trigger.Trigger_Enum;
|
|
|
|
import com.jens.automation2.receivers.NfcReceiver;
|
|
|
|
|
2021-02-16 20:24:12 +01:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
2021-02-16 13:42:49 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
2021-02-17 22:27:53 +01:00
|
|
|
public class ActivityManageRule extends Activity
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-02-16 23:38:38 +01:00
|
|
|
final static String activityDetectionClassPath = "com.jens.automation2.receivers.ActivityDetectionReceiver";
|
|
|
|
|
2021-02-16 13:42:49 +01:00
|
|
|
public Context context;
|
|
|
|
private Button cmdTriggerAdd, cmdActionAdd, cmdSaveRule;
|
|
|
|
private ListView triggerListView, actionListView;
|
|
|
|
private EditText etRuleName;
|
|
|
|
private CheckBox chkRuleActive, chkRuleToggle;
|
2021-02-17 22:27:53 +01:00
|
|
|
private static ActivityManageRule instance = null;
|
2021-02-16 13:42:49 +01:00
|
|
|
ImageView imageHelpButton;
|
|
|
|
|
|
|
|
private static ProgressDialog progressDialog = null;
|
|
|
|
|
|
|
|
private static Trigger_Enum triggerType;
|
|
|
|
private static boolean triggerParameter;
|
|
|
|
private static PointOfInterest triggerPoi;
|
|
|
|
private static String triggerProcess;
|
|
|
|
private static int triggerBattery;
|
|
|
|
private static double triggerSpeed;
|
|
|
|
private static double triggerNoise;
|
|
|
|
private static TimeFrame triggerTimeFrame;
|
|
|
|
private static String triggerWifiName;
|
|
|
|
|
|
|
|
private static Rule ruleToEdit;
|
|
|
|
private static boolean newRule;
|
|
|
|
|
|
|
|
private static Trigger newTrigger;
|
|
|
|
private static Action newAction;
|
|
|
|
|
|
|
|
ArrayAdapter<Trigger> triggerListViewAdapter;
|
|
|
|
ArrayAdapter<Action> actionListViewAdapter;
|
|
|
|
|
|
|
|
int editIndex = 0;
|
|
|
|
|
|
|
|
final static int requestCodeActionTriggerUrlAdd = 1000;
|
|
|
|
final static int requestCodeActionTriggerUrlEdit = 1001;
|
|
|
|
final static int requestCodeTriggerTimeframeAdd = 2000;
|
|
|
|
final static int requestCodeTriggerTimeframeEdit = 2001;
|
|
|
|
final static int requestCodeActionStartActivityAdd = 3000;
|
|
|
|
final static int requestCodeActionStartActivityEdit = 3001;
|
|
|
|
final static int requestCodeTriggerNfcTagAdd = 4000;
|
|
|
|
final static int requestCodeTriggerNfcTagEdit = 4001;
|
|
|
|
final static int requestCodeActionSpeakTextAdd = 5000;
|
|
|
|
final static int requestCodeActionSpeakTextEdit = 1001;
|
|
|
|
final static int requestCodeTriggerBluetoothAdd = 6000;
|
|
|
|
final static int requestCodeTriggerBluetoothEdit = 6001;
|
|
|
|
final static int requestCodeActionScreenBrightnessAdd = 401;
|
|
|
|
final static int requestCodeActionScreenBrightnessEdit = 402;
|
|
|
|
final static int requestCodeActionSendTextMessage = 7001;
|
2021-03-26 19:58:27 +01:00
|
|
|
final static int requestCodeTriggerNotificationAdd = 8000;
|
|
|
|
final static int requestCodeTriggerNfcNotificationEdit = 8001;
|
2021-03-28 20:33:44 +02:00
|
|
|
final static int requestCodeActionPlaySoundAdd = 501;
|
|
|
|
final static int requestCodeActionPlaySoundEdit = 502;
|
2021-05-13 23:50:14 +02:00
|
|
|
final static int requestCodeTriggerPhoneCallAdd = 601;
|
|
|
|
final static int requestCodeTriggerPhoneCallEdit = 602;
|
2021-05-16 14:27:54 +02:00
|
|
|
final static int requestCodeTriggerWifiAdd = 723;
|
|
|
|
final static int requestCodeTriggerWifiEdit = 724;
|
2021-07-04 15:53:24 +02:00
|
|
|
final static int requestCodeActionSendTextMessageAdd = 5001;
|
|
|
|
final static int requestCodeActionVibrateAdd = 801;
|
|
|
|
final static int requestCodeActionVibrateEdit = 802;
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-02-17 22:27:53 +01:00
|
|
|
public static ActivityManageRule getInstance()
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
if(instance == null)
|
2021-02-17 22:27:53 +01:00
|
|
|
instance = new ActivityManageRule();
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
context = this;
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.manage_specific_rule);
|
|
|
|
|
|
|
|
instance = this;
|
|
|
|
|
|
|
|
cmdTriggerAdd = (Button)findViewById(R.id.cmdTriggerAdd);
|
|
|
|
cmdActionAdd = (Button)findViewById(R.id.cmdActionAdd);
|
|
|
|
triggerListView = (ListView)findViewById(R.id.lvTriggerListView);
|
|
|
|
actionListView = (ListView)findViewById(R.id.lvActionListView);
|
|
|
|
etRuleName = (EditText)findViewById(R.id.etRuleName);
|
|
|
|
cmdSaveRule = (Button)findViewById(R.id.cmdSaveRule);
|
|
|
|
chkRuleActive = (CheckBox)findViewById(R.id.chkRuleActive);
|
|
|
|
chkRuleToggle = (CheckBox)findViewById(R.id.chkRuleToggle);
|
|
|
|
imageHelpButton = (ImageView)findViewById(R.id.imageHelpButton);
|
|
|
|
|
|
|
|
//decide if it will be created anew or loaded to edit an existing one
|
|
|
|
if(ActivityMainRules.ruleToEdit == null)
|
|
|
|
{
|
|
|
|
// new rule
|
|
|
|
Miscellaneous.logEvent("i", "Rule", "Cache empty, assuming create request.", 3);
|
|
|
|
newRule = true;
|
|
|
|
ruleToEdit = new Rule();
|
|
|
|
ruleToEdit.setTriggerSet(new ArrayList<Trigger>());
|
|
|
|
ruleToEdit.setActionSet(new ArrayList<Action>());
|
|
|
|
triggerListViewAdapter = new ArrayAdapter<Trigger>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getTriggerSet());
|
|
|
|
actionListViewAdapter = new ArrayAdapter<Action>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getActionSet());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// change existing rule
|
|
|
|
Miscellaneous.logEvent("i", "Rule", "Cache not empty, assuming change request.", 3);
|
|
|
|
newRule = false;
|
|
|
|
ruleToEdit = ActivityMainRules.ruleToEdit;
|
|
|
|
triggerListViewAdapter = new ArrayAdapter<Trigger>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getTriggerSet());
|
|
|
|
actionListViewAdapter = new ArrayAdapter<Action>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ruleToEdit.getActionSet());
|
|
|
|
loadVariablesIntoGui();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdTriggerAdd.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
hideKeyboard();
|
|
|
|
newTrigger = new Trigger();
|
|
|
|
getTriggerTypeDialog(context).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cmdActionAdd.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
hideKeyboard();
|
|
|
|
getActionTypeDialog().show();
|
|
|
|
}
|
2021-03-18 23:37:21 +01:00
|
|
|
});
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
cmdSaveRule.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
if(newRule)
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("i", "Rule", "Will create a new rule.", 3);
|
|
|
|
loadFormValuesToVariable();
|
|
|
|
if(ruleToEdit.create(context))
|
|
|
|
{
|
|
|
|
ActivityPermissions.getRequiredPermissions(false);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else
|
2021-02-17 22:27:53 +01:00
|
|
|
Toast.makeText(ActivityManageRule.this, getResources().getString(R.string.errorWritingConfig), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("i", "Rule", "Will change an existing rule.", 3);
|
|
|
|
loadFormValuesToVariable();
|
|
|
|
if(ruleToEdit.change(context))
|
|
|
|
{
|
|
|
|
ActivityPermissions.getRequiredPermissions(false);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else
|
2021-02-17 22:27:53 +01:00
|
|
|
Toast.makeText(ActivityManageRule.this, getResources().getString(R.string.errorWritingConfig), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
triggerListView.setClickable(true);
|
|
|
|
actionListView.setClickable(true);
|
|
|
|
|
|
|
|
triggerListView.setOnItemLongClickListener(new OnItemLongClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
|
|
|
{
|
|
|
|
getTriggerDeleteDialog(context, (Trigger)triggerListView.getItemAtPosition(arg2)).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
triggerListView.setOnItemClickListener(new OnItemClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
|
|
|
{
|
|
|
|
editIndex = arg2;
|
|
|
|
Trigger selectedTrigger = (Trigger)triggerListView.getItemAtPosition(arg2);
|
|
|
|
switch(selectedTrigger.getTriggerType())
|
|
|
|
{
|
|
|
|
case timeFrame:
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger;
|
|
|
|
Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTimeFrame.class);
|
2021-02-16 13:42:49 +01:00
|
|
|
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeEdit);
|
|
|
|
break;
|
|
|
|
case bluetoothConnection:
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageTriggerBluetooth.editedBluetoothTrigger = selectedTrigger;
|
|
|
|
Intent bluetoothEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerBluetooth.class);
|
2021-02-16 13:42:49 +01:00
|
|
|
startActivityForResult(bluetoothEditor, requestCodeTriggerBluetoothEdit);
|
|
|
|
break;
|
2021-03-28 20:33:44 +02:00
|
|
|
case notification:
|
|
|
|
ActivityManageTriggerNotification.editedNotificationTrigger = selectedTrigger;
|
|
|
|
Intent notificationEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerNotification.class);
|
|
|
|
notificationEditor.putExtra("edit", true);
|
|
|
|
startActivityForResult(notificationEditor, requestCodeTriggerNfcNotificationEdit);
|
|
|
|
break;
|
2021-05-14 13:00:25 +02:00
|
|
|
case phoneCall:
|
|
|
|
ActivityManageTriggerPhoneCall.editedPhoneCallTrigger = selectedTrigger;
|
|
|
|
Intent phoneCallEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerPhoneCall.class);
|
|
|
|
phoneCallEditor.putExtra("edit", true);
|
|
|
|
startActivityForResult(phoneCallEditor, requestCodeTriggerPhoneCallEdit);
|
|
|
|
break;
|
2021-05-16 14:27:54 +02:00
|
|
|
case wifiConnection:
|
|
|
|
Intent wifiEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerWifi.class);
|
|
|
|
wifiEditor.putExtra("edit", true);
|
|
|
|
wifiEditor.putExtra("wifiState", selectedTrigger.getTriggerParameter());
|
|
|
|
wifiEditor.putExtra("wifiName", selectedTrigger.getTriggerParameter2());
|
|
|
|
startActivityForResult(wifiEditor, requestCodeTriggerWifiEdit);
|
|
|
|
break;
|
2021-02-16 13:42:49 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
triggerListView.setOnTouchListener(new OnTouchListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event)
|
|
|
|
{
|
|
|
|
v.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
actionListView.setOnItemLongClickListener(new OnItemLongClickListener()
|
|
|
|
{
|
|
|
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
|
|
|
{
|
|
|
|
getActionDeleteDialog(context, (Action)actionListView.getItemAtPosition(arg2)).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
actionListView.setOnItemClickListener(new OnItemClickListener()
|
|
|
|
{
|
|
|
|
// editing triggers
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
|
|
|
{
|
|
|
|
editIndex = arg2;
|
|
|
|
Action a = (Action)actionListView.getItemAtPosition(arg2);
|
|
|
|
switch(a.getAction())
|
|
|
|
{
|
|
|
|
case startOtherActivity:
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class);
|
|
|
|
ActivityManageActionStartActivity.resultingAction = a;
|
2021-02-16 13:42:49 +01:00
|
|
|
intent.putExtra("edit", true);
|
|
|
|
startActivityForResult(intent, requestCodeActionStartActivityEdit);
|
|
|
|
break;
|
|
|
|
case triggerUrl:
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent activityEditTriggerUrlIntent = new Intent(ActivityManageRule.this, ActivityManageActionTriggerUrl.class);
|
|
|
|
ActivityManageActionTriggerUrl.resultingAction = a;
|
2021-02-16 13:42:49 +01:00
|
|
|
activityEditTriggerUrlIntent.putExtra("edit", true);
|
|
|
|
startActivityForResult(activityEditTriggerUrlIntent, requestCodeActionTriggerUrlEdit);
|
|
|
|
break;
|
|
|
|
case speakText:
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent activitySpeakTextIntent = new Intent(ActivityManageRule.this, ActivityManageActionSpeakText.class);
|
|
|
|
ActivityManageActionSpeakText.resultingAction = a;
|
2021-02-16 13:42:49 +01:00
|
|
|
activitySpeakTextIntent.putExtra("edit", true);
|
|
|
|
startActivityForResult(activitySpeakTextIntent, requestCodeActionSpeakTextEdit);
|
|
|
|
break;
|
|
|
|
case sendTextMessage:
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent activitySendTextMessageIntent = new Intent(ActivityManageRule.this, ActivityManageActionSendTextMessage.class);
|
|
|
|
ActivityManageActionSendTextMessage.resultingAction = a;
|
2021-02-16 13:42:49 +01:00
|
|
|
activitySendTextMessageIntent.putExtra("edit", true);
|
|
|
|
startActivityForResult(activitySendTextMessageIntent, requestCodeActionSendTextMessage);
|
|
|
|
break;
|
|
|
|
case setScreenBrightness:
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent activityEditScreenBrightnessIntent = new Intent(ActivityManageRule.this, ActivityManageActionBrightnessSetting.class);
|
2021-02-16 13:42:49 +01:00
|
|
|
activityEditScreenBrightnessIntent.putExtra("autoBrightness", a.getParameter1());
|
|
|
|
activityEditScreenBrightnessIntent.putExtra("brightnessValue", Integer.parseInt(a.getParameter2()));
|
|
|
|
startActivityForResult(activityEditScreenBrightnessIntent, requestCodeActionScreenBrightnessEdit);
|
|
|
|
break;
|
2021-07-04 15:53:24 +02:00
|
|
|
case vibrate:
|
|
|
|
Intent activityEditVibrateIntent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
|
|
|
activityEditVibrateIntent.putExtra("vibratePattern", a.getParameter2());
|
|
|
|
startActivityForResult(activityEditVibrateIntent, requestCodeActionVibrateEdit);
|
|
|
|
break;
|
2021-03-28 20:33:44 +02:00
|
|
|
case playSound:
|
|
|
|
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
|
|
|
actionPlaySoundIntent.putExtra("edit", true);
|
|
|
|
actionPlaySoundIntent.putExtra("actionParameter1", a.getParameter1());
|
|
|
|
actionPlaySoundIntent.putExtra("actionParameter2", a.getParameter2());
|
|
|
|
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundEdit);
|
|
|
|
break;
|
2021-02-16 13:42:49 +01:00
|
|
|
default:
|
|
|
|
Miscellaneous.logEvent("w", "Edit action", "Editing of action type " + a.getAction().toString() + " not implemented, yet.", 4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
actionListView.setOnTouchListener(new OnTouchListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event)
|
|
|
|
{
|
|
|
|
v.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
chkRuleToggle.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
|
|
|
{
|
|
|
|
private boolean guiEditing = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
|
|
{
|
|
|
|
if(!guiEditing)
|
|
|
|
if(!plausibilityCheck())
|
|
|
|
{
|
|
|
|
guiEditing = true;
|
|
|
|
chkRuleToggle.setChecked(false);
|
|
|
|
guiEditing = false;
|
2021-02-17 22:27:53 +01:00
|
|
|
Toast.makeText(ActivityManageRule.this, getResources().getString(R.string.toggleNotAllowed), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
imageHelpButton.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
// Open help popup
|
2021-02-17 22:27:53 +01:00
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.whatsThis), getResources().getString(R.string.helpTextToggable), ActivityManageRule.this).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean plausibilityCheck()
|
|
|
|
{
|
|
|
|
boolean nfcFound = false;
|
|
|
|
if(chkRuleToggle.isChecked())
|
|
|
|
{
|
|
|
|
for(Trigger trigger : ruleToEdit.getTriggerSet())
|
|
|
|
{
|
|
|
|
if(trigger.getTriggerType().equals(Trigger_Enum.nfcTag))
|
|
|
|
nfcFound = true;
|
|
|
|
}
|
|
|
|
if(!nfcFound)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void loadFormValuesToVariable()
|
|
|
|
{
|
|
|
|
ruleToEdit.setName(etRuleName.getText().toString());
|
|
|
|
ruleToEdit.setRuleActive(chkRuleActive.isChecked());
|
|
|
|
ruleToEdit.setRuleToggle(chkRuleToggle.isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadVariablesIntoGui()
|
|
|
|
{
|
|
|
|
// Set all gui fields to the values of the to-be-edited-object
|
|
|
|
|
|
|
|
etRuleName.setText(ruleToEdit.getName());
|
|
|
|
chkRuleActive.setChecked(ruleToEdit.isRuleActive());
|
|
|
|
chkRuleToggle.setChecked(ruleToEdit.isRuleToggle());
|
|
|
|
|
|
|
|
refreshTriggerList();
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getTriggerTypeDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
final ArrayList<Item> items = new ArrayList<Item>();
|
|
|
|
|
|
|
|
CharSequence[] types = Trigger.getTriggerTypesAsArray();
|
|
|
|
CharSequence[] typesLong = Trigger.getTriggerTypesStringAsArray(myContext);
|
|
|
|
|
|
|
|
for(int i=0; i<types.length; i++)
|
|
|
|
{
|
|
|
|
//pointOfInterest, timeFrame, charging, batteryLevel, usb_host_connection, speed, noiseLevel, wifiConnection, process_started_stopped;
|
|
|
|
if(types[i].toString().equals(Trigger_Enum.pointOfInterest.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.compass_small));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.timeFrame.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.alarm));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.charging.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.power));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.batteryLevel.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.battery));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.usb_host_connection.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.usb));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.speed.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.speed));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.noiseLevel.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.ear));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.wifiConnection.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.wifi));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.process_started_stopped.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.startprogram));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.airplaneMode.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.plane));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.roaming.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.roaming));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.phoneCall.toString()))
|
|
|
|
{
|
|
|
|
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
|
2021-02-17 22:27:53 +01:00
|
|
|
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, "android.permission.SEND_SMS"))
|
2021-02-16 13:42:49 +01:00
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
|
|
|
}
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.nfcTag.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.nfc));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.activityDetection.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.activitydetection));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.bluetoothConnection.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.bluetooth));
|
|
|
|
else if(types[i].toString().equals(Trigger_Enum.headsetPlugged.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.headphone));
|
2021-03-26 19:58:27 +01:00
|
|
|
else if(types[i].toString().equals(Trigger_Enum.notification.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
2021-02-16 13:42:49 +01:00
|
|
|
else
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
|
|
|
}
|
|
|
|
|
|
|
|
ListAdapter adapter = new ArrayAdapter<Item>(this, android.R.layout.select_dialog_item, android.R.id.text1, items)
|
|
|
|
{
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent)
|
|
|
|
{
|
|
|
|
//User super class to create the View
|
|
|
|
View v = super.getView(position, convertView, parent);
|
|
|
|
|
|
|
|
TextView tv = (TextView)v.findViewById(android.R.id.text1);
|
|
|
|
|
|
|
|
//Put the image on the TextView
|
|
|
|
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, 0, 0, 0);
|
|
|
|
|
|
|
|
//Add margin between image and text (support various screen densities)
|
|
|
|
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
|
|
|
|
tv.setCompoundDrawablePadding(dp5);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setTitle(getResources().getString(R.string.selectTypeOfTrigger))
|
|
|
|
.setAdapter(adapter, new DialogInterface.OnClickListener()
|
|
|
|
{
|
2021-02-16 20:24:12 +01:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
triggerType = Trigger_Enum.values()[which];
|
|
|
|
|
|
|
|
String[] booleanChoices = null;
|
|
|
|
if(triggerType == Trigger_Enum.pointOfInterest)
|
|
|
|
{
|
2021-03-20 02:44:27 +01:00
|
|
|
if(Miscellaneous.googleToBlameForLocation(false))
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-03-18 23:37:21 +01:00
|
|
|
ActivityMainScreen.openGoogleBlamingWindow();
|
2021-02-16 13:42:49 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-03-18 23:37:21 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PointOfInterest.getPointOfInterestCollection() != null && PointOfInterest.getPointOfInterestCollection().size() > 0)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.entering), getResources().getString(R.string.leaving)};
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Toast.makeText(myContext, getResources().getString(R.string.noPoisSpecified), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.timeFrame)
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.timeFrame);
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = newTrigger;
|
|
|
|
Intent timeFrameEditor = new Intent(myContext, ActivityManageTriggerTimeFrame.class);
|
2021-02-16 13:42:49 +01:00
|
|
|
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeAdd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.charging)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
|
|
|
else if(triggerType == Trigger_Enum.usb_host_connection)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
|
|
|
else if(triggerType == Trigger_Enum.speed | triggerType == Trigger_Enum.noiseLevel | triggerType == Trigger_Enum.batteryLevel)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.exceeds), getResources().getString(R.string.dropsBelow)};
|
|
|
|
else if(triggerType == Trigger_Enum.wifiConnection)
|
2021-05-16 14:27:54 +02:00
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.wifiConnection);
|
|
|
|
Intent wifiTriggerEditor = new Intent(myContext, ActivityManageTriggerWifi.class);
|
|
|
|
startActivityForResult(wifiTriggerEditor, requestCodeTriggerWifiAdd);
|
|
|
|
return;
|
|
|
|
// booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
|
|
|
}
|
|
|
|
// else if(triggerType == Trigger_Enum.wifiConnection)
|
|
|
|
// booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
2021-02-16 13:42:49 +01:00
|
|
|
else if(triggerType == Trigger_Enum.process_started_stopped)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
2021-03-26 19:58:27 +01:00
|
|
|
else if(triggerType == Trigger_Enum.notification)
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.notification);
|
2021-03-27 14:11:39 +01:00
|
|
|
Intent nfcEditor = new Intent(myContext, ActivityManageTriggerNotification.class);
|
2021-03-26 19:58:27 +01:00
|
|
|
startActivityForResult(nfcEditor, requestCodeTriggerNotificationAdd);
|
|
|
|
return;
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
else if(triggerType == Trigger_Enum.airplaneMode)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.activated), getResources().getString(R.string.deactivated)};
|
|
|
|
else if(triggerType == Trigger_Enum.roaming)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.activated), getResources().getString(R.string.deactivated)};
|
|
|
|
else if(triggerType == Trigger_Enum.phoneCall)
|
2021-05-13 23:50:14 +02:00
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.phoneCall);
|
|
|
|
Intent phoneTriggerEditor = new Intent(myContext, ActivityManageTriggerPhoneCall.class);
|
|
|
|
startActivityForResult(phoneTriggerEditor, requestCodeTriggerPhoneCallAdd);
|
|
|
|
return;
|
|
|
|
// booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
else if(triggerType == Trigger_Enum.activityDetection)
|
|
|
|
{
|
2021-02-16 20:24:12 +01:00
|
|
|
try
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-02-16 23:38:38 +01:00
|
|
|
Method m = Miscellaneous.getClassMethodReflective(activityDetectionClassPath, "isPlayServiceAvailable");
|
2021-02-16 20:24:12 +01:00
|
|
|
if(m != null)
|
|
|
|
{
|
|
|
|
boolean available = (Boolean)m.invoke(null);
|
|
|
|
if(available)
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.activityDetection);
|
|
|
|
getTriggerActivityDetectionDialog().show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Toast.makeText(myContext, getResources().getString(R.string.triggerOnlyAvailableIfPlayServicesInstalled), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2021-02-16 23:38:38 +01:00
|
|
|
else
|
2021-02-17 22:27:53 +01:00
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.error), getResources().getString(R.string.featureNotInFdroidVersion), ActivityManageRule.this).show();
|
2021-02-16 20:24:12 +01:00
|
|
|
}
|
|
|
|
catch (IllegalAccessException | InvocationTargetException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.nfcTag)
|
|
|
|
{
|
2021-02-17 22:27:53 +01:00
|
|
|
if(NfcReceiver.checkNfcRequirements(ActivityManageRule.this, true))
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.nfcTag);
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent nfcEditor = new Intent(myContext, ActivityManageTriggerNfc.class);
|
2021-02-16 13:42:49 +01:00
|
|
|
startActivityForResult(nfcEditor, requestCodeTriggerNfcTagAdd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.bluetoothConnection)
|
|
|
|
{
|
|
|
|
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
2021-02-17 22:27:53 +01:00
|
|
|
Miscellaneous.messageBox("Bluetooth", getResources().getString(R.string.deviceDoesNotHaveBluetooth), ActivityManageRule.this).show();;
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.bluetoothConnection);
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageTriggerBluetooth.editedBluetoothTrigger = newTrigger;
|
|
|
|
Intent bluetoothEditor = new Intent(myContext, ActivityManageTriggerBluetooth.class);
|
2021-02-16 13:42:49 +01:00
|
|
|
startActivityForResult(bluetoothEditor, requestCodeTriggerBluetoothAdd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.headsetPlugged)
|
|
|
|
booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
|
|
|
|
|
|
|
if(triggerType == Trigger_Enum.nfcTag)
|
|
|
|
{
|
2021-02-17 22:27:53 +01:00
|
|
|
if (NfcReceiver.checkNfcRequirements(ActivityManageRule.this, true))
|
2021-02-16 13:42:49 +01:00
|
|
|
getTriggerParamterDialog(context, booleanChoices).show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
getTriggerParamterDialog(context, booleanChoices).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerParamterDialog(final Context myContext, final String[] choices)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectTypeOfTrigger));
|
|
|
|
alertDialogBuilder.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
if(which==0)
|
|
|
|
newTrigger.setTriggerParameter(true);
|
|
|
|
else
|
|
|
|
newTrigger.setTriggerParameter(false);
|
|
|
|
|
|
|
|
if(triggerType == Trigger_Enum.pointOfInterest)
|
|
|
|
{
|
|
|
|
ArrayList<String> choices = new ArrayList<String>();
|
|
|
|
choices.add("< " + getResources().getString(R.string.none) + " >");
|
|
|
|
for(String s : PointOfInterest.getNamesInArray())
|
|
|
|
choices.add(s);
|
|
|
|
|
|
|
|
getTriggerPoiDialog(myContext, choices.toArray(new String[choices.size()])).show();
|
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.batteryLevel)
|
|
|
|
{
|
|
|
|
ArrayList<String> choicesList = new ArrayList<String>();
|
|
|
|
for(int i=1; i<=100; i+=1)
|
|
|
|
choicesList.add(String.valueOf(i) + " %");
|
|
|
|
String[] choices = (String[]) choicesList.toArray(new String[choicesList.size()]);
|
|
|
|
getTriggerBatteryDialog(myContext, choices).show();
|
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.speed)
|
|
|
|
{
|
|
|
|
ArrayList<String> choicesList = new ArrayList<String>();
|
|
|
|
for(int i=5; i<=150; i+=5)
|
|
|
|
choicesList.add(String.valueOf(i) + " km/h");
|
|
|
|
String[] choices = (String[]) choicesList.toArray(new String[choicesList.size()]);
|
|
|
|
getTriggerSpeedDialog(myContext, choices).show();
|
|
|
|
}
|
|
|
|
else if(triggerType == Trigger_Enum.noiseLevel)
|
|
|
|
{
|
|
|
|
ArrayList<String> choicesList = new ArrayList<String>();
|
|
|
|
for(int i=5; i<=150; i+=5)
|
|
|
|
choicesList.add(String.valueOf(i) + " dB");
|
|
|
|
String[] choices = (String[]) choicesList.toArray(new String[choicesList.size()]);
|
|
|
|
getTriggerNoiseDialog(myContext, choices).show();
|
|
|
|
}
|
|
|
|
else if(triggerType.equals(Trigger_Enum.wifiConnection))
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.wifiConnection);
|
|
|
|
getTriggerWifiDialog(myContext).show();
|
|
|
|
}
|
|
|
|
else if(triggerType.equals(Trigger_Enum.process_started_stopped))
|
|
|
|
{
|
|
|
|
progressDialog = ProgressDialog.show(myContext, null, getResources().getString(R.string.gettingListOfInstalledApplications), true, false);
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.process_started_stopped);
|
2021-02-17 22:27:53 +01:00
|
|
|
new GenerateApplicationSelectionsDialogTask().execute(ActivityManageRule.this);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
else if(triggerType.equals(Trigger_Enum.phoneCall))
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.phoneCall);
|
|
|
|
getTriggerPhoneDirectionDialog(myContext).show();
|
|
|
|
}
|
|
|
|
else if(triggerType.equals(Trigger_Enum.headsetPlugged))
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.headsetPlugged);
|
|
|
|
getTriggerHeadphoneDialog(myContext).show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerType(triggerType);
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerBatteryDialog(final Context myContext, final String[] choices)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectBattery));
|
|
|
|
alertDialogBuilder.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
triggerBattery = (which+1);
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.batteryLevel);
|
|
|
|
newTrigger.setBatteryLevel(triggerBattery);
|
|
|
|
// Log.i("test", newTrigger.toString());
|
|
|
|
// Log.i("test", String.valueOf(newTrigger.getBatteryLevel()));
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerSpeedDialog(final Context myContext, final String[] choices)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectSpeed));
|
|
|
|
alertDialogBuilder.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
triggerSpeed = (which+1)*5;
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.speed);
|
|
|
|
newTrigger.setSpeed(triggerSpeed);
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerNoiseDialog(final Context myContext, final String[] choices)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectNoiseLevel));
|
|
|
|
alertDialogBuilder.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
triggerNoise = (which+1)*5;
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.noiseLevel);
|
|
|
|
newTrigger.setNoiseLevelDb(Math.round(triggerNoise));
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Comment about the physical reference value.
|
|
|
|
*/
|
|
|
|
if(!Rule.isAnyRuleUsing(Trigger_Enum.noiseLevel))
|
|
|
|
{
|
|
|
|
AlertDialog noiseHintDialog = Miscellaneous.messageBox(myContext.getResources().getString(R.string.hint), myContext.getResources().getString(R.string.noiseDetectionHint), myContext);
|
|
|
|
noiseHintDialog.show();
|
|
|
|
Linkify.addLinks((TextView) noiseHintDialog.findViewById(android.R.id.message), Linkify.ALL);
|
|
|
|
// ((TextView)noiseHintDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerWifiDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
alertDialog.setTitle(myContext.getResources().getString(R.string.wifiName));
|
|
|
|
alertDialog.setMessage(myContext.getResources().getString(R.string.enterWifiName));
|
|
|
|
|
|
|
|
// Set an EditText view to get user input
|
|
|
|
final EditText input = new EditText(this);
|
|
|
|
alertDialog.setView(input);
|
|
|
|
|
|
|
|
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
2021-05-16 14:27:54 +02:00
|
|
|
// newTrigger.setWifiName(input.getText().toString());
|
2021-02-16 13:42:49 +01:00
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
alertDialog.setNegativeButton(myContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
|
|
|
// Canceled.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return alertDialog.create();
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerPhoneDirectionDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
alertDialog.setTitle(myContext.getResources().getString(R.string.phoneDirection));
|
|
|
|
String[] choices = new String[] { myContext.getResources().getString(R.string.any), myContext.getResources().getString(R.string.incoming), myContext.getResources().getString(R.string.outgoing) };
|
|
|
|
alertDialog.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
newTrigger.setPhoneDirection(which);
|
2021-02-17 22:27:53 +01:00
|
|
|
getTriggerPhoneNumberDialog(ActivityManageRule.this).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return alertDialog.create();
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerPhoneNumberDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
alertDialog.setTitle(myContext.getResources().getString(R.string.phoneNumber));
|
|
|
|
alertDialog.setMessage(myContext.getResources().getString(R.string.enterPhoneNumber));
|
|
|
|
|
|
|
|
// Set an EditText view to get user input
|
|
|
|
final EditText input = new EditText(this);
|
|
|
|
input.setInputType(InputType.TYPE_CLASS_PHONE);
|
|
|
|
alertDialog.setView(input);
|
|
|
|
|
|
|
|
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
|
|
|
String number = input.getText().toString();
|
|
|
|
if(number.length() == 0)
|
|
|
|
number = "any";
|
|
|
|
|
|
|
|
newTrigger.setPhoneNumber(number);
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
alertDialog.setNegativeButton(myContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
|
|
|
// Canceled.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return alertDialog.create();
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerPoiDialog(final Context myContext, final String[] choices)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectPoi));
|
|
|
|
alertDialogBuilder.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(which > 0)
|
|
|
|
triggerPoi = PointOfInterest.getByName(choices[which]);
|
|
|
|
else
|
|
|
|
triggerPoi = null;
|
|
|
|
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.pointOfInterest);
|
|
|
|
newTrigger.setPointOfInterest(triggerPoi);
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
private AlertDialog getTriggerHeadphoneDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.headphoneSelectType));
|
|
|
|
alertDialogBuilder.setItems(new String[]{ myContext.getResources().getString(R.string.headphoneSimple), myContext.getResources().getString(R.string.headphoneMicrophone), myContext.getResources().getString(R.string.headphoneAny) }, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
newTrigger.setHeadphoneType(which);
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
2021-02-16 20:24:12 +01:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
2021-02-16 13:42:49 +01:00
|
|
|
private AlertDialog getTriggerActivityDetectionDialog()
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
alertDialog.setTitle(Miscellaneous.getAnyContext().getResources().getString(R.string.selectTypeOfActivity));
|
2021-02-16 20:24:12 +01:00
|
|
|
|
2021-02-16 23:38:38 +01:00
|
|
|
Method m = Miscellaneous.getClassMethodReflective(activityDetectionClassPath, "getAllDescriptions");
|
2021-02-16 20:24:12 +01:00
|
|
|
if(m != null)
|
|
|
|
{
|
|
|
|
String[] choices = new String[0];
|
|
|
|
try
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-02-16 20:24:12 +01:00
|
|
|
choices = (String[])m.invoke(null);
|
|
|
|
alertDialog.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
2021-02-16 23:38:38 +01:00
|
|
|
Method m = Miscellaneous.getClassMethodReflective(activityDetectionClassPath, "getAllTypes");
|
2021-02-16 20:24:12 +01:00
|
|
|
if(m != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-02-16 23:38:38 +01:00
|
|
|
int[] choices = (int[])m.invoke(null);
|
2021-02-16 20:24:12 +01:00
|
|
|
|
|
|
|
newTrigger.setActivityDetectionType(choices[which]);
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
catch (IllegalAccessException | InvocationTargetException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
2021-02-16 20:24:12 +01:00
|
|
|
catch (IllegalAccessException | InvocationTargetException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
return alertDialog.create();
|
2021-02-16 20:24:12 +01:00
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-02-17 22:27:53 +01:00
|
|
|
private static class GenerateApplicationSelectionsDialogTask extends AsyncTask<ActivityManageRule, Void, String[]>
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
@Override
|
2021-02-17 22:27:53 +01:00
|
|
|
protected String[] doInBackground(ActivityManageRule... params)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
// Looper.prepare();
|
2021-03-29 16:36:21 +02:00
|
|
|
final String[] applicationArray = ActivityManageActionStartActivity.getApplicationNameListString(params[0]);
|
2021-02-16 13:42:49 +01:00
|
|
|
return applicationArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(String[] result)
|
|
|
|
{
|
|
|
|
if(progressDialog != null)
|
|
|
|
{
|
|
|
|
progressDialog.dismiss();
|
|
|
|
progressDialog = null;
|
|
|
|
}
|
|
|
|
|
2021-02-17 22:27:53 +01:00
|
|
|
ActivityManageRule.getInstance().showProcessDialog(result);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void showProcessDialog(String[] programStrings)
|
|
|
|
{
|
2021-02-17 22:27:53 +01:00
|
|
|
getTriggerRunningProcessDialog1(ActivityManageRule.this, programStrings).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getTriggerRunningProcessDialog1(final Context myContext, final String[] applicationArray)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(myContext);
|
|
|
|
alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectApplication));
|
|
|
|
alertDialogBuilder.setItems(applicationArray, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
String applicationName = applicationArray[which];
|
|
|
|
getTriggerRunningProcessDialog2(myContext, applicationName).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
// Log.i("Amount of Applications", String.valueOf(applicationArray.length));
|
|
|
|
// Log.i("Amount of Packages", String.valueOf(ActivityManageStartActivity.getPackageListString(myContext).length));
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getTriggerRunningProcessDialog2(final Context myContext, String applicationName)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(myContext);
|
|
|
|
alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectPackageOfApplication));
|
2021-03-29 16:36:21 +02:00
|
|
|
final String[] packageArray = ActivityManageActionStartActivity.getPackageListString(myContext, applicationName);
|
2021-02-16 13:42:49 +01:00
|
|
|
alertDialogBuilder.setItems(packageArray, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
String packageName = packageArray[which];
|
|
|
|
getTriggerRunningProcessDialog3(myContext, packageName).show();
|
2021-02-17 22:27:53 +01:00
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.hint), getResources().getString(R.string.chooseActivityHint), ActivityManageRule.this).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getTriggerRunningProcessDialog3(final Context myContext, final String packageName)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(myContext);
|
|
|
|
alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectActivityToBeStarted));
|
2021-03-29 16:36:21 +02:00
|
|
|
final String activityArray[] = ActivityManageActionStartActivity.getActivityListForPackageName(packageName);
|
2021-02-16 13:42:49 +01:00
|
|
|
alertDialogBuilder.setItems(activityArray, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
triggerProcess = activityArray[which];
|
|
|
|
newTrigger.setTriggerType(Trigger_Enum.process_started_stopped);
|
|
|
|
newTrigger.setProcessName(triggerProcess);
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
|
{
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
|
|
if(requestCode == requestCodeActionTriggerUrlAdd)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
//add TriggerUrl
|
2021-03-29 16:36:21 +02:00
|
|
|
ruleToEdit.getActionSet().add(ActivityManageActionTriggerUrl.resultingAction);
|
2021-02-16 13:42:49 +01:00
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeActionTriggerUrlEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
//edit TriggerUrl
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeTriggerTimeframeAdd)
|
|
|
|
{
|
|
|
|
//add TimeFrame
|
2021-03-29 16:36:21 +02:00
|
|
|
if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.logEvent("w", "TimeFrameEdit", "No timeframe returned. Assuming abort.", 5);
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeTriggerTimeframeEdit)
|
|
|
|
{
|
|
|
|
//edit TimeFrame
|
2021-03-29 16:36:21 +02:00
|
|
|
if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.logEvent("w", "TimeFrameEdit", "No timeframe returned. Assuming abort.", 5);
|
|
|
|
}
|
2021-05-16 14:27:54 +02:00
|
|
|
else if(requestCode == requestCodeTriggerWifiAdd)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
|
|
|
newTrigger.setTriggerParameter2(data.getStringExtra("wifiName"));
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeTriggerWifiEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
|
|
|
newTrigger.setTriggerParameter2(data.getStringExtra("wifiName"));
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
else if(requestCode == requestCodeActionStartActivityAdd)
|
|
|
|
{
|
|
|
|
// manage start of other activity
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
newAction = ActivityManageActionStartActivity.resultingAction;
|
2021-02-16 13:42:49 +01:00
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeActionStartActivityEdit)
|
|
|
|
{
|
|
|
|
// manage start of other activity
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
newAction = ActivityManageActionStartActivity.resultingAction;
|
2021-02-16 13:42:49 +01:00
|
|
|
// ruleToEdit.getActionSet().add(newAction);
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeTriggerNfcTagAdd)
|
|
|
|
{
|
|
|
|
//add TimeFrame
|
2021-03-29 16:36:21 +02:00
|
|
|
if(resultCode == RESULT_OK && ActivityManageTriggerNfc.generatedId != null)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
newTrigger.setNfcTagId(ActivityManageTriggerNfc.generatedId);
|
2021-02-16 13:42:49 +01:00
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.logEvent("w", "ActivityManageNfc", "No nfc id returned. Assuming abort.", 5);
|
|
|
|
}
|
2021-03-26 19:58:27 +01:00
|
|
|
else if(requestCode == requestCodeTriggerNotificationAdd)
|
|
|
|
{
|
|
|
|
//add notification
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
2021-03-27 14:11:39 +01:00
|
|
|
|
|
|
|
newTrigger.setTriggerParameter2(
|
|
|
|
data.getStringExtra("app") + Trigger.triggerParameter2Split +
|
|
|
|
data.getStringExtra("titleDir") + Trigger.triggerParameter2Split +
|
|
|
|
data.getStringExtra("title") + Trigger.triggerParameter2Split +
|
|
|
|
data.getStringExtra("textDir") + Trigger.triggerParameter2Split +
|
|
|
|
data.getStringExtra("text")
|
|
|
|
);
|
2021-03-26 19:58:27 +01:00
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
}
|
2021-03-28 20:33:44 +02:00
|
|
|
else if(requestCode == requestCodeTriggerNfcNotificationEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
newTrigger = ActivityManageTriggerNotification.resultingTrigger;
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 23:50:14 +02:00
|
|
|
else if(requestCode == requestCodeTriggerPhoneCallAdd)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
newTrigger.setTriggerParameter2(data.getStringExtra("triggerParameter2"));
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeTriggerPhoneCallEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
newTrigger = ActivityManageTriggerPhoneCall.resultingTrigger;
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
else if(requestCode == requestCodeActionSpeakTextAdd)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
//add SpeakText
|
2021-03-29 16:36:21 +02:00
|
|
|
ruleToEdit.getActionSet().add(ActivityManageActionSpeakText.resultingAction);
|
2021-02-16 13:42:49 +01:00
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeActionSpeakTextEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
//add SpeakText
|
2021-03-29 16:36:21 +02:00
|
|
|
ruleToEdit.getActionSet().add(ActivityManageActionSendTextMessage.resultingAction);
|
2021-02-16 13:42:49 +01:00
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeTriggerBluetoothAdd)
|
|
|
|
{
|
|
|
|
//add bluetooth trigger
|
2021-03-29 16:36:21 +02:00
|
|
|
if(resultCode == RESULT_OK && ActivityManageTriggerBluetooth.editedBluetoothTrigger != null)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
ruleToEdit.getTriggerSet().add(newTrigger);
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.logEvent("w", "BluetoothTriggerEdit", "No bluetooth trigger returned. Assuming abort.", 5);
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeTriggerBluetoothEdit)
|
|
|
|
{
|
|
|
|
//edit bluetooth trigger
|
2021-03-29 16:36:21 +02:00
|
|
|
if(resultCode == RESULT_OK && ActivityManageTriggerBluetooth.editedBluetoothTrigger != null)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
this.refreshTriggerList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.logEvent("w", "BluetoothTriggerEdit", "No bluetooth trigger returned. Assuming abort.", 5);
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeActionScreenBrightnessAdd)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
newAction.setParameter1(data.getBooleanExtra("autoBrightness", false));
|
|
|
|
newAction.setParameter2(String.valueOf(data.getIntExtra("brightnessValue", 0)));
|
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeActionScreenBrightnessEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
if(data.hasExtra("autoBrightness"))
|
|
|
|
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra("autoBrightness", false));
|
|
|
|
|
|
|
|
if(data.hasExtra("brightnessValue"))
|
|
|
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(String.valueOf(data.getIntExtra("brightnessValue", 0)));
|
|
|
|
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
2021-07-04 15:53:24 +02:00
|
|
|
else if(requestCode == requestCodeActionVibrateAdd)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
newAction.setParameter2(data.getStringExtra("vibratePattern"));
|
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeActionVibrateEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
if(data.hasExtra("vibratePattern"))
|
|
|
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra("vibratePattern"));
|
|
|
|
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
2021-03-28 23:23:29 +02:00
|
|
|
else if(requestCode == requestCodeActionPlaySoundAdd)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
newAction.setParameter1(data.getBooleanExtra("actionParameter1", false));
|
2021-03-29 16:36:21 +02:00
|
|
|
newAction.setParameter2(data.getStringExtra("actionParameter2"));
|
2021-03-28 23:23:29 +02:00
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(requestCode == requestCodeActionPlaySoundEdit)
|
|
|
|
{
|
|
|
|
if(resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
if(data.hasExtra("actionParameter1"))
|
|
|
|
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra("actionParameter1", false));
|
|
|
|
|
|
|
|
if(data.hasExtra("actionParameter2"))
|
2021-03-29 16:36:21 +02:00
|
|
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra("actionParameter2"));
|
2021-03-28 23:23:29 +02:00
|
|
|
|
|
|
|
this.refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
//TODO: Check with has data been changed or something like that.
|
|
|
|
/*try
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("i", "ActivityManageSpecificRule", getResources().getString(R.string.noDataChangedReadingAnyway), 4);
|
|
|
|
XmlFileInterface.readFile();
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException e)
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("e", "ActivityManageSpecificRule", getResources().getString(R.string.errorReadingPoisAndRulesFromFile) + ": " + Log.getStackTraceString(e), 5);
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Dialog getActionTypeDialog()
|
|
|
|
{
|
|
|
|
final ArrayList<Item> items = new ArrayList<Item>();
|
|
|
|
|
|
|
|
CharSequence[] types = Action.getActionTypesAsArray();
|
|
|
|
CharSequence[] typesLong = Action.getActionTypesFullNameStringAsArray(this);
|
|
|
|
|
|
|
|
for(int i=0; i<types.length; i++)
|
|
|
|
{
|
|
|
|
if(types[i].toString().equals(Action_Enum.setWifi.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.wifi));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.setBluetooth.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.bluetooth));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.setUsbTethering.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.setWifiTethering.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.setDisplayRotation.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.displayrotation));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.waitBeforeNextAction.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.wait));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.setAirplaneMode.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.plane));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.wakeupDevice.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.alarm));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.changeSoundProfile.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.sound));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.triggerUrl.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.triggerurl));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.startOtherActivity.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.startprogram));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.setDataConnection.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.dataconnection));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.speakText.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.talking));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.playMusic.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.tune));
|
|
|
|
else if(types[i].toString().equals(Action_Enum.setScreenBrightness.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.brightness));
|
2021-03-28 20:33:44 +02:00
|
|
|
else if(types[i].toString().equals(Action_Enum.playSound.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.sound));
|
2021-07-04 15:53:24 +02:00
|
|
|
else if(types[i].toString().equals(Action_Enum.vibrate.toString()))
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.vibrate));
|
2021-02-16 13:42:49 +01:00
|
|
|
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
|
|
|
{
|
|
|
|
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
|
2021-02-17 22:27:53 +01:00
|
|
|
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, "android.permission.SEND_SMS"))
|
2021-02-16 13:42:49 +01:00
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.message));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
|
|
|
}
|
|
|
|
|
2021-03-28 20:33:44 +02:00
|
|
|
ListAdapter adapter = new ArrayAdapter<Item>(this, android.R.layout.select_dialog_item, android.R.id.text1, items)
|
|
|
|
{
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent)
|
|
|
|
{
|
|
|
|
//User super class to create the View
|
|
|
|
View v = super.getView(position, convertView, parent);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-03-28 20:33:44 +02:00
|
|
|
TextView tv = (TextView)v.findViewById(android.R.id.text1);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-03-28 20:33:44 +02:00
|
|
|
//Put the image on the TextView
|
|
|
|
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, 0, 0, 0);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-03-28 20:33:44 +02:00
|
|
|
//Add margin between image and text (support various screen densities)
|
|
|
|
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
|
|
|
|
tv.setCompoundDrawablePadding(dp5);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-03-28 20:33:44 +02:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setTitle(getResources().getString(R.string.selectTypeOfAction))
|
|
|
|
.setAdapter(adapter, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
newAction = new Action();
|
|
|
|
|
|
|
|
if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.triggerUrl.toString()))
|
|
|
|
{
|
|
|
|
//launch other activity to enter a url and parameters;
|
|
|
|
newAction.setAction(Action_Enum.triggerUrl);
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionTriggerUrl.resultingAction = null;
|
|
|
|
Intent editTriggerIntent = new Intent(context, ActivityManageActionTriggerUrl.class);
|
2021-03-28 20:33:44 +02:00
|
|
|
startActivityForResult(editTriggerIntent, 1000);
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setWifi.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.setWifi);
|
|
|
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
|
|
|
Toast.makeText(context, context.getResources().getString(R.string.android10WifiToggleNotice), Toast.LENGTH_LONG).show();
|
|
|
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setBluetooth.toString()))
|
|
|
|
{
|
|
|
|
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
|
|
|
Miscellaneous.messageBox("Bluetooth", getResources().getString(R.string.deviceDoesNotHaveBluetooth), ActivityManageRule.this).show();;
|
|
|
|
newAction.setAction(Action_Enum.setBluetooth);
|
|
|
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setUsbTethering.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.setUsbTethering);
|
|
|
|
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1)
|
2021-05-13 18:37:34 +02:00
|
|
|
Miscellaneous.messageBox(context.getResources().getString(R.string.warning), context.getResources().getString(R.string.usbTetheringFailForAboveGingerbread), context).show();
|
2021-03-28 20:33:44 +02:00
|
|
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setWifiTethering.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.setWifiTethering);
|
2021-06-16 23:12:00 +02:00
|
|
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
2021-03-28 20:33:44 +02:00
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setDisplayRotation.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.setDisplayRotation);
|
|
|
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.changeSoundProfile.toString()))
|
|
|
|
{
|
|
|
|
if(Profile.getProfileCollection().size() > 0)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-03-28 20:33:44 +02:00
|
|
|
newAction.setAction(Action_Enum.changeSoundProfile);
|
|
|
|
getActionSoundProfileDialog(context).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
2021-03-28 20:33:44 +02:00
|
|
|
else
|
|
|
|
Toast.makeText(context, getResources().getString(R.string.noProfilesCreateOneFirst), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.startOtherActivity.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.startOtherActivity);
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class);
|
2021-03-28 20:33:44 +02:00
|
|
|
startActivityForResult(intent, 3000);
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.waitBeforeNextAction.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.waitBeforeNextAction);
|
|
|
|
getActionWaitBeforeNextActionDialog(ActivityManageRule.this).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.wakeupDevice.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.wakeupDevice);
|
|
|
|
getActionWakeupDeviceDialog(ActivityManageRule.this).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setAirplaneMode.toString()))
|
|
|
|
{
|
2021-05-30 20:03:30 +02:00
|
|
|
newAction.setAction(Action_Enum.setAirplaneMode);
|
|
|
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
2021-03-28 20:33:44 +02:00
|
|
|
if(Build.VERSION.SDK_INT >= 17)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-05-30 20:03:30 +02:00
|
|
|
// Toast.makeText(context, getResources().getString(R.string.airplaneModeSdk17Warning), Toast.LENGTH_LONG).show();
|
2021-03-28 20:33:44 +02:00
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.airplaneMode), getResources().getString(R.string.rootExplanation), ActivityManageRule.this).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
2021-03-28 20:33:44 +02:00
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setDataConnection.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.setDataConnection);
|
|
|
|
getActionParameter1Dialog(ActivityManageRule.this).show();
|
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.actionDataConnection), getResources().getString(R.string.rootExplanation), ActivityManageRule.this).show();
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.speakText.toString()))
|
|
|
|
{
|
|
|
|
//launch other activity to enter a url and parameters;
|
|
|
|
newAction.setAction(Action_Enum.speakText);
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionSpeakText.resultingAction = null;
|
|
|
|
Intent editTriggerIntent = new Intent(context, ActivityManageActionSpeakText.class);
|
2021-03-28 20:33:44 +02:00
|
|
|
startActivityForResult(editTriggerIntent, 5000);
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendTextMessage.toString()))
|
|
|
|
{
|
|
|
|
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, "android.permission.SEND_SMS"))
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-03-28 20:33:44 +02:00
|
|
|
//launch other activity to enter parameters;
|
|
|
|
newAction.setAction(Action_Enum.sendTextMessage);
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionSendTextMessage.resultingAction = null;
|
|
|
|
Intent editTriggerIntent = new Intent(context, ActivityManageActionSendTextMessage.class);
|
2021-07-04 15:53:24 +02:00
|
|
|
startActivityForResult(editTriggerIntent, requestCodeActionSendTextMessageAdd);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
2021-03-28 20:33:44 +02:00
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.playMusic.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.playMusic);
|
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
refreshActionList();
|
|
|
|
}
|
2021-07-04 15:53:24 +02:00
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.vibrate.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.vibrate);
|
|
|
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
|
|
|
startActivityForResult(intent, requestCodeActionVibrateAdd);
|
|
|
|
}
|
2021-03-28 20:33:44 +02:00
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setScreenBrightness.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.setScreenBrightness);
|
2021-03-29 16:36:21 +02:00
|
|
|
Intent actionScreenBrightnessIntent = new Intent(context, ActivityManageActionBrightnessSetting.class);
|
2021-03-28 20:33:44 +02:00
|
|
|
startActivityForResult(actionScreenBrightnessIntent, requestCodeActionScreenBrightnessAdd);
|
|
|
|
}
|
|
|
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.playSound.toString()))
|
|
|
|
{
|
|
|
|
newAction.setAction(Action_Enum.playSound);
|
|
|
|
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
|
|
|
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundAdd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return builder.create();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
private AlertDialog getActionSoundProfileDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectSoundProfile));
|
|
|
|
|
|
|
|
final String[] choices;
|
|
|
|
// choices = new String[]{"silent", "vibrate", "normal"};
|
|
|
|
ArrayList<String> list = Profile.getProfileCollectionString();
|
|
|
|
choices = list.toArray(new String[list.size()]);
|
|
|
|
|
|
|
|
alertDialogBuilder.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
newAction.setParameter2(choices[which]);
|
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getTriggerDeleteDialog(Context myContext, final Trigger triggerToBeDeleted)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithTrigger));
|
|
|
|
alertDialogBuilder.setItems(new String[]{getResources().getString(R.string.delete)}, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
// Only 1 choice at the moment, no need to check
|
|
|
|
ruleToEdit.getTriggerSet().remove(triggerToBeDeleted);
|
|
|
|
refreshTriggerList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
private AlertDialog getActionDeleteDialog(Context myContext, final Action actionToBeDeleted)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithAction));
|
|
|
|
alertDialogBuilder.setItems(new String[] { getResources().getString(R.string.delete), getResources().getString(R.string.moveUp), getResources().getString(R.string.moveDown)}, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
int positionOfSelected;
|
|
|
|
switch(which)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
// Delete
|
|
|
|
if(ruleToEdit.getActionSet().remove(actionToBeDeleted))
|
|
|
|
{
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// Move up
|
|
|
|
positionOfSelected = ruleToEdit.getActionSet().indexOf(actionToBeDeleted);
|
|
|
|
if(positionOfSelected > 0)
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("i", "Swap", "Swapping positions " + String.valueOf(positionOfSelected) + " and " + String.valueOf(positionOfSelected-1), 4);
|
|
|
|
Collections.swap(ruleToEdit.getActionSet(), positionOfSelected, positionOfSelected-1);
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Is already at the top
|
2021-02-17 22:27:53 +01:00
|
|
|
Toast.makeText(ActivityManageRule.this, getResources().getString(R.string.cantMoveUp), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// Move down
|
|
|
|
positionOfSelected = ruleToEdit.getActionSet().indexOf(actionToBeDeleted);
|
|
|
|
Miscellaneous.logEvent("i", "Swap", "Swapping positions " + String.valueOf(positionOfSelected) + " and " + String.valueOf(positionOfSelected+1), 4);
|
|
|
|
if(positionOfSelected < ruleToEdit.getActionSet().size()-1)
|
|
|
|
{
|
|
|
|
Collections.swap(ruleToEdit.getActionSet(), positionOfSelected, positionOfSelected+1);
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Is already at the bottom
|
2021-02-17 22:27:53 +01:00
|
|
|
Toast.makeText(ActivityManageRule.this, getResources().getString(R.string.cantMoveDown), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getActionWaitBeforeNextActionDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
alertDialog.setTitle(myContext.getResources().getString(R.string.waitBeforeNextAction));
|
|
|
|
alertDialog.setMessage(myContext.getResources().getString(R.string.waitBeforeNextActionEnterValue));
|
|
|
|
|
|
|
|
// Set an EditText view to get user input
|
|
|
|
final EditText input = new EditText(this);
|
|
|
|
input.setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
|
alertDialog.setView(input);
|
|
|
|
|
|
|
|
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
|
|
|
if(input.getText().toString().length() == 0| input.getText().toString().equals("0") | input.getText().toString().contains(",") | input.getText().toString().contains("."))
|
|
|
|
{
|
2021-02-17 22:27:53 +01:00
|
|
|
Toast.makeText(myContext, ActivityManageRule.this.getResources().getString(R.string.enterAPositiveValidNonDecimalNumber), Toast.LENGTH_LONG).show();
|
|
|
|
getActionWaitBeforeNextActionDialog(ActivityManageRule.this).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newAction.setParameter2(input.getText().toString());
|
|
|
|
newAction.toString();
|
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
alertDialog.setNegativeButton(myContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
|
|
|
// Canceled.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return alertDialog.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getActionWakeupDeviceDialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
alertDialog.setTitle(myContext.getResources().getString(R.string.wakeupDevice));
|
|
|
|
alertDialog.setMessage(myContext.getResources().getString(R.string.wakeupDeviceValue));
|
|
|
|
|
|
|
|
// Set an EditText view to get user input
|
|
|
|
final EditText input = new EditText(this);
|
|
|
|
input.setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
|
alertDialog.setView(input);
|
|
|
|
|
|
|
|
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
|
|
|
if(input.getText().toString().length() == 0| input.getText().toString().contains(",") | input.getText().toString().contains("."))
|
|
|
|
{
|
2021-02-17 22:27:53 +01:00
|
|
|
Toast.makeText(myContext, ActivityManageRule.this.getResources().getString(R.string.enterAPositiveValidNonDecimalNumber), Toast.LENGTH_LONG).show();
|
|
|
|
getActionWakeupDeviceDialog(ActivityManageRule.this).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newAction.setParameter2(input.getText().toString());
|
|
|
|
newAction.toString();
|
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
alertDialog.setNegativeButton(myContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton)
|
|
|
|
{
|
|
|
|
// Canceled.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return alertDialog.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getActionParameter1Dialog(final Context myContext)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
|
|
|
alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectToggleDirection));
|
|
|
|
final String choices[] = { myContext.getString(R.string.activate), myContext.getString(R.string.deactivate) };
|
|
|
|
alertDialogBuilder.setItems(choices, new DialogInterface.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
if(which == 0)
|
|
|
|
newAction.setParameter1(true);
|
|
|
|
else
|
|
|
|
newAction.setParameter1(false);
|
|
|
|
|
|
|
|
ruleToEdit.getActionSet().add(newAction);
|
|
|
|
refreshActionList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void refreshTriggerList()
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("i", "ListView", "Attempting to update TriggerListView", 4);
|
|
|
|
if(triggerListView.getAdapter() == null)
|
|
|
|
{
|
|
|
|
triggerListView.setAdapter(triggerListViewAdapter);
|
|
|
|
}
|
|
|
|
triggerListViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
protected void refreshActionList()
|
|
|
|
{
|
|
|
|
Miscellaneous.logEvent("i", "ListView", "Attempting to update ActionListView", 4);
|
|
|
|
if(actionListView.getAdapter() == null)
|
|
|
|
{
|
|
|
|
actionListView.setAdapter(actionListViewAdapter);
|
|
|
|
}
|
|
|
|
actionListViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Item
|
|
|
|
{
|
|
|
|
public final String text;
|
|
|
|
public final int icon;
|
|
|
|
|
|
|
|
public Item(String text, Integer icon)
|
|
|
|
{
|
|
|
|
this.text = text;
|
|
|
|
this.icon = icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void hideKeyboard()
|
|
|
|
{
|
|
|
|
View view = this.getCurrentFocus();
|
|
|
|
if (view != null)
|
|
|
|
{
|
|
|
|
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|