2021-02-16 13:42:49 +01:00
|
|
|
package com.jens.automation2;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
import android.content.pm.PackageInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
2021-05-12 17:16:56 +02:00
|
|
|
import android.net.Uri;
|
2021-02-16 13:42:49 +01:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.InputType;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnTouchListener;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemLongClickListener;
|
|
|
|
import android.widget.AdapterView.OnItemSelectedListener;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
2021-05-09 14:42:24 +02:00
|
|
|
import android.widget.CompoundButton;
|
2021-02-16 13:42:49 +01:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ListView;
|
2021-05-08 15:14:31 +02:00
|
|
|
import android.widget.RadioButton;
|
2021-02-16 13:42:49 +01:00
|
|
|
import android.widget.Spinner;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.jens.automation2.Action.Action_Enum;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.List;
|
|
|
|
|
2021-03-29 16:36:21 +02:00
|
|
|
public class ActivityManageActionStartActivity extends Activity
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-05-12 17:16:56 +02:00
|
|
|
/*
|
|
|
|
This page might qualify as a help page: https://stackoverflow.com/questions/55323947/open-url-in-firefox-for-android-using-intent
|
|
|
|
*/
|
|
|
|
|
2021-02-16 13:42:49 +01:00
|
|
|
ListView lvIntentPairs;
|
2021-05-09 14:42:24 +02:00
|
|
|
EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath;
|
2021-05-12 17:16:56 +02:00
|
|
|
Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity, showStartProgramExamples;
|
2021-02-16 13:42:49 +01:00
|
|
|
Spinner spinnerParameterType;
|
|
|
|
boolean edit = false;
|
|
|
|
ProgressDialog progressDialog = null;
|
2021-05-12 17:16:56 +02:00
|
|
|
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast;
|
|
|
|
|
|
|
|
final String urlShowExamples = "https://server47.de/automation/examples_startProgram.html";
|
|
|
|
final static String startByActivityString = "0";
|
|
|
|
final static String startByBroadcastString = "1";
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
private class CustomPackageInfo extends PackageInfo implements Comparable<CustomPackageInfo>
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public int compareTo(CustomPackageInfo another)
|
|
|
|
{
|
|
|
|
String name1 = "";
|
|
|
|
String name2 = "";
|
|
|
|
|
|
|
|
ApplicationInfo aInfo1 = this.applicationInfo;
|
|
|
|
if (aInfo1 != null)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
name1 = (String) ActivityManageActionStartActivity.this.getPackageManager().getApplicationLabel(aInfo1);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
ApplicationInfo aInfo2 = another.applicationInfo;
|
|
|
|
if (aInfo2 != null)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
name2 = (String) ActivityManageActionStartActivity.this.getPackageManager().getApplicationLabel(aInfo2);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return name1.compareTo(name2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static List<PackageInfo> pInfos = null;
|
|
|
|
public static Action resultingAction;
|
|
|
|
|
2021-05-11 20:00:50 +02:00
|
|
|
private static final String[] supportedIntentTypes = { "boolean", "byte", "char", "double", "float", "int", "long", "short", "String", "Uri" };
|
2021-02-16 13:42:49 +01:00
|
|
|
private ArrayList<String> intentPairList = new ArrayList<String>();
|
|
|
|
|
|
|
|
ArrayAdapter<String> intentTypeSpinnerAdapter, intentPairAdapter;
|
|
|
|
|
|
|
|
public static void getActivityList(final Context context)
|
|
|
|
{
|
|
|
|
if(pInfos == null)
|
|
|
|
{
|
|
|
|
pInfos = context.getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
|
|
|
|
Collections.sort(pInfos, new Comparator<PackageInfo>()
|
|
|
|
{
|
|
|
|
public int compare(PackageInfo obj1, PackageInfo obj2)
|
|
|
|
{
|
|
|
|
String name1 = "";
|
|
|
|
String name2 = "";
|
|
|
|
|
|
|
|
ApplicationInfo aInfo1 = obj1.applicationInfo;
|
|
|
|
if (aInfo1 != null)
|
|
|
|
{
|
|
|
|
name1 = (String) context.getPackageManager().getApplicationLabel(aInfo1);
|
|
|
|
}
|
|
|
|
ApplicationInfo aInfo2 = obj2.applicationInfo;
|
|
|
|
if (aInfo2 != null)
|
|
|
|
{
|
|
|
|
name2 = (String) context.getPackageManager().getApplicationLabel(aInfo2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return name1.compareTo(name2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String[] getApplicationNameListString(Context myContext)
|
|
|
|
{
|
|
|
|
// Generate the actual list
|
|
|
|
getActivityList(myContext);
|
|
|
|
|
|
|
|
ArrayList<String> returnList = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (PackageInfo pInfo : pInfos)
|
|
|
|
{
|
|
|
|
ApplicationInfo aInfo = pInfo.applicationInfo;
|
|
|
|
if (aInfo != null)
|
|
|
|
{
|
|
|
|
String aLabel;
|
|
|
|
|
|
|
|
aLabel = (String) myContext.getPackageManager().getApplicationLabel(aInfo);
|
|
|
|
|
|
|
|
ActivityInfo[] aInfos = pInfo.activities;
|
|
|
|
if (aInfos != null && aInfos.length > 0) // Only put Applications into the list that have packages.
|
|
|
|
{
|
|
|
|
if(!returnList.contains(aLabel))
|
|
|
|
returnList.add(aLabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnList.toArray(new String[returnList.size()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String[] getPackageListString(Context myContext, String applicationLabel)
|
|
|
|
{
|
|
|
|
// Generate the actual list
|
|
|
|
getActivityList(myContext);
|
|
|
|
|
|
|
|
ArrayList<String> returnList = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (PackageInfo pInfo : pInfos)
|
|
|
|
{
|
|
|
|
if(myContext.getPackageManager().getApplicationLabel(pInfo.applicationInfo).equals(applicationLabel))
|
|
|
|
{
|
|
|
|
ActivityInfo[] aInfos = pInfo.activities;
|
|
|
|
if (aInfos != null && aInfos.length > 0)
|
|
|
|
{
|
|
|
|
returnList.add(pInfo.packageName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnList.toArray(new String[returnList.size()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String[] getPackageListString(Context myContext)
|
|
|
|
{
|
|
|
|
// Generate the actual list
|
|
|
|
getActivityList(myContext);
|
|
|
|
|
|
|
|
ArrayList<String> returnList = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (PackageInfo pInfo : pInfos)
|
|
|
|
{
|
|
|
|
ActivityInfo[] aInfos = pInfo.activities;
|
|
|
|
if (aInfos != null && aInfos.length > 0)
|
|
|
|
{
|
|
|
|
returnList.add(pInfo.packageName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Miscellaneous.logEvent("w", "Empty Application", "Application " + myContext.getPackageManager().getApplicationLabel(pInfo.applicationInfo) + " doesn\'t have packages.", 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnList.toArray(new String[returnList.size()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String[] getActivityListForPackageName(String packageName)
|
|
|
|
{
|
|
|
|
ArrayList<String> returnList = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (PackageInfo pInfo : pInfos)
|
|
|
|
{
|
|
|
|
if(pInfo.packageName.equals(packageName))
|
|
|
|
{
|
|
|
|
ActivityInfo[] aInfos = pInfo.activities;
|
|
|
|
if (aInfos != null)
|
|
|
|
{
|
|
|
|
for (ActivityInfo activityInfo : aInfos)
|
|
|
|
{
|
|
|
|
returnList.add(activityInfo.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnList.toArray(new String[returnList.size()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ActivityInfo getActivityInfoForPackageNameAndActivityName(String packageName, String activityName)
|
|
|
|
{
|
|
|
|
for (PackageInfo pInfo : pInfos)
|
|
|
|
{
|
|
|
|
if(pInfo.packageName.equals(packageName))
|
|
|
|
{
|
|
|
|
ActivityInfo[] aInfos = pInfo.activities;
|
|
|
|
if (aInfos != null)
|
|
|
|
{
|
|
|
|
for (ActivityInfo activityInfo : aInfos)
|
|
|
|
{
|
|
|
|
if(activityInfo.name.equals(activityName))
|
|
|
|
return activityInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getActionStartActivityDialog1()
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectApplication));
|
2021-03-29 16:36:21 +02:00
|
|
|
final String[] applicationArray = ActivityManageActionStartActivity.getApplicationNameListString(this);
|
2021-02-16 13:42:49 +01:00
|
|
|
alertDialogBuilder.setItems(applicationArray, new DialogInterface.OnClickListener()
|
2022-01-08 14:46:01 +01:00
|
|
|
{
|
2021-02-16 13:42:49 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
dialog.dismiss();
|
2022-01-08 14:46:01 +01:00
|
|
|
getActionStartActivityDialog2(applicationArray[which]);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
2022-01-08 14:46:01 +01:00
|
|
|
private void getActionStartActivityDialog2(String applicationName)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.selectPackageOfApplication));
|
2021-03-29 16:36:21 +02:00
|
|
|
final String[] packageArray = ActivityManageActionStartActivity.getPackageListString(this, applicationName);
|
2022-01-08 14:46:01 +01:00
|
|
|
if(packageArray.length > 1)
|
|
|
|
{
|
|
|
|
alertDialogBuilder.setItems(packageArray, new DialogInterface.OnClickListener()
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2022-01-08 14:46:01 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
getActionStartActivityDialog3(packageArray[which]).show();
|
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.hint), getResources().getString(R.string.chooseActivityHint), ActivityManageActionStartActivity.this).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
alertDialog.show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getActionStartActivityDialog3(packageArray[0]).show();
|
|
|
|
Miscellaneous.messageBox(getResources().getString(R.string.hint), getResources().getString(R.string.chooseActivityHint), ActivityManageActionStartActivity.this).show();
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
2022-01-08 14:46:01 +01:00
|
|
|
|
2021-02-16 13:42:49 +01:00
|
|
|
private AlertDialog getActionStartActivityDialog3(final String packageName)
|
|
|
|
{
|
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
alertDialogBuilder.setTitle(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)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityInfo ai = ActivityManageActionStartActivity.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]);
|
2021-05-12 17:16:56 +02:00
|
|
|
etPackageName.setText(ai.packageName);
|
|
|
|
etActivityOrActionPath.setText(ai.name);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
2021-05-11 20:00:50 +02:00
|
|
|
setContentView(R.layout.activity_manage_action_start_activity);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
lvIntentPairs = (ListView)findViewById(R.id.lvIntentPairs);
|
|
|
|
etParameterName = (EditText)findViewById(R.id.etParameterName);
|
|
|
|
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
|
|
|
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
|
|
|
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
|
|
|
|
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
|
|
|
|
spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType);
|
2021-05-09 14:42:24 +02:00
|
|
|
etPackageName = (EditText) findViewById(R.id.etPackageName);
|
|
|
|
etActivityOrActionPath = (EditText) findViewById(R.id.etActivityOrActionPath);
|
2021-05-08 15:14:31 +02:00
|
|
|
rbStartAppSelectByActivity = (RadioButton)findViewById(R.id.rbStartAppSelectByActivity);
|
|
|
|
rbStartAppSelectByAction = (RadioButton)findViewById(R.id.rbStartAppSelectByAction);
|
2021-05-12 17:16:56 +02:00
|
|
|
showStartProgramExamples = (Button)findViewById(R.id.showStartProgramExamples);
|
|
|
|
|
|
|
|
rbStartAppByActivity = (RadioButton)findViewById(R.id.rbStartAppByActivity);
|
|
|
|
rbStartAppByBroadcast = (RadioButton)findViewById(R.id.rbStartAppByBroadcast);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-03-29 16:36:21 +02:00
|
|
|
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes);
|
2021-02-16 13:42:49 +01:00
|
|
|
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
|
|
|
|
intentTypeSpinnerAdapter.notifyDataSetChanged();
|
|
|
|
|
2021-04-09 17:39:59 +02:00
|
|
|
intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, intentPairList);
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
bSelectApp.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
GetActivityListTask getActivityListTask = new GetActivityListTask();
|
|
|
|
getActivityListTask.execute();
|
2021-03-29 16:36:21 +02:00
|
|
|
progressDialog = ProgressDialog.show(ActivityManageActionStartActivity.this, "", ActivityManageActionStartActivity.this.getResources().getString(R.string.gettingListOfInstalledApplications));
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bAddIntentPair.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
// type;name;value
|
|
|
|
if(spinnerParameterType.getSelectedItem().toString().length() == 0)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectTypeOfIntentPair), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(etParameterName.getText().toString().length() == 0)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterNameForIntentPair), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-05-11 20:00:50 +02:00
|
|
|
else if(etParameterName.getText().toString().contains(Action.intentPairSeperator))
|
|
|
|
{
|
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeperator), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(etParameterName.getText().toString().contains(";"))
|
|
|
|
{
|
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
if(etParameterValue.getText().toString().length() == 0)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterValueForIntentPair), Toast.LENGTH_LONG).show();
|
2021-02-16 13:42:49 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-05-11 20:00:50 +02:00
|
|
|
else if(etParameterValue.getText().toString().contains(Action.intentPairSeperator))
|
|
|
|
{
|
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeperator), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(etParameterValue.getText().toString().contains(";"))
|
|
|
|
{
|
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
|
2021-05-11 20:00:50 +02:00
|
|
|
String param = supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()] + Action.intentPairSeperator + etParameterName.getText().toString() + Action.intentPairSeperator + etParameterValue.getText().toString();
|
2021-02-16 13:42:49 +01:00
|
|
|
intentPairList.add(param);
|
|
|
|
|
|
|
|
spinnerParameterType.setSelection(0);
|
|
|
|
etParameterName.setText("");
|
|
|
|
etParameterValue.setText("");
|
|
|
|
|
|
|
|
updateIntentPairList();
|
2021-04-30 13:52:06 +02:00
|
|
|
|
|
|
|
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
|
|
|
lvIntentPairs.setVisibility(View.VISIBLE);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
2021-05-12 17:16:56 +02:00
|
|
|
|
|
|
|
showStartProgramExamples.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlShowExamples));
|
|
|
|
startActivity(browserIntent);
|
|
|
|
}
|
|
|
|
});
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
lvIntentPairs.setOnItemLongClickListener(new OnItemLongClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
|
|
|
{
|
|
|
|
getIntentPairDialog(arg2).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bSaveActionStartOtherActivity.setOnClickListener(new OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
if(saveAction())
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionStartActivity.this.setResult(RESULT_OK);
|
2021-02-16 13:42:49 +01:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
lvIntentPairs.setOnTouchListener(new OnTouchListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event)
|
|
|
|
{
|
|
|
|
v.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
spinnerParameterType.setOnItemSelectedListener(new OnItemSelectedListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
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"))
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER);
|
2021-02-16 13:42:49 +01:00
|
|
|
else
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> arg0)
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2021-05-09 14:42:24 +02:00
|
|
|
|
|
|
|
rbStartAppSelectByActivity.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
|
|
{
|
|
|
|
if(isChecked)
|
|
|
|
bSelectApp.setEnabled(isChecked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
rbStartAppSelectByAction.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
|
|
{
|
|
|
|
if(isChecked)
|
|
|
|
bSelectApp.setEnabled(!isChecked);
|
|
|
|
}
|
|
|
|
});
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
Intent i = getIntent();
|
|
|
|
if(i.getBooleanExtra("edit", false) == true)
|
|
|
|
{
|
|
|
|
edit = true;
|
|
|
|
loadValuesIntoGui();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadValuesIntoGui()
|
|
|
|
{
|
2021-05-10 19:56:54 +02:00
|
|
|
boolean selectionByAction = resultingAction.getParameter1();
|
|
|
|
rbStartAppSelectByActivity.setChecked(!selectionByAction);
|
|
|
|
rbStartAppSelectByAction.setChecked(selectionByAction);
|
2021-05-08 15:14:31 +02:00
|
|
|
|
2021-02-16 13:42:49 +01:00
|
|
|
String[] params = resultingAction.getParameter2().split(";");
|
2021-05-08 15:14:31 +02:00
|
|
|
|
2021-05-12 17:16:56 +02:00
|
|
|
rbStartAppByActivity.setChecked(params[2].equals(startByActivityString));
|
|
|
|
rbStartAppByBroadcast.setChecked(params[2].equals(startByBroadcastString));
|
|
|
|
|
2021-05-08 15:14:31 +02:00
|
|
|
int startIndex = -1;
|
|
|
|
|
2021-05-10 19:56:54 +02:00
|
|
|
if(!selectionByAction)
|
2021-05-09 14:42:24 +02:00
|
|
|
{
|
|
|
|
etPackageName.setText(params[0]);
|
2021-05-12 17:16:56 +02:00
|
|
|
etActivityOrActionPath.setText(params[1]);
|
2021-05-09 14:42:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-12 17:16:56 +02:00
|
|
|
if(!params[0].contains(Actions.dummyPackageString))
|
|
|
|
etPackageName.setText(params[0]);
|
|
|
|
|
|
|
|
etActivityOrActionPath.setText(params[1]);
|
2021-05-09 14:42:24 +02:00
|
|
|
}
|
2021-05-08 15:14:31 +02:00
|
|
|
|
2021-05-12 17:16:56 +02:00
|
|
|
if (params.length >= 3)
|
|
|
|
startIndex = 3;
|
|
|
|
|
2021-05-08 15:14:31 +02:00
|
|
|
if(startIndex > -1 && params.length > startIndex)
|
|
|
|
{
|
|
|
|
intentPairList.clear();
|
|
|
|
|
|
|
|
for(int i=startIndex; i<params.length; i++)
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-05-08 15:14:31 +02:00
|
|
|
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
|
|
|
lvIntentPairs.setVisibility(View.VISIBLE);
|
2021-04-30 13:52:06 +02:00
|
|
|
|
2021-05-08 15:14:31 +02:00
|
|
|
intentPairList.add(params[i]);
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
2021-05-08 15:14:31 +02:00
|
|
|
|
|
|
|
updateIntentPairList();
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateIntentPairList()
|
|
|
|
{
|
|
|
|
if(lvIntentPairs.getAdapter() == null)
|
|
|
|
lvIntentPairs.setAdapter(intentPairAdapter);
|
|
|
|
|
|
|
|
intentPairAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean saveAction()
|
|
|
|
{
|
2021-05-09 14:42:24 +02:00
|
|
|
if(rbStartAppSelectByActivity.isChecked())
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-05-09 14:42:24 +02:00
|
|
|
if (etPackageName.getText().toString().length() == 0)
|
|
|
|
{
|
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterPackageName), Toast.LENGTH_LONG).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (etActivityOrActionPath.getText().toString().length() == 0)
|
|
|
|
{
|
|
|
|
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show();
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
2021-05-09 14:42:24 +02:00
|
|
|
else
|
2021-02-16 13:42:49 +01:00
|
|
|
{
|
2021-05-09 14:42:24 +02:00
|
|
|
if(etActivityOrActionPath.getText().toString().contains(";"))
|
|
|
|
{
|
|
|
|
Toast.makeText(this, getResources().getString(R.string.enterValidAction), Toast.LENGTH_LONG).show();
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-16 13:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(resultingAction == null)
|
|
|
|
resultingAction = new Action();
|
2021-05-08 15:14:31 +02:00
|
|
|
|
2021-05-10 19:56:54 +02:00
|
|
|
resultingAction.setParameter1(rbStartAppSelectByAction.isChecked());
|
2021-02-16 13:42:49 +01:00
|
|
|
|
|
|
|
resultingAction.setAction(Action_Enum.startOtherActivity);
|
|
|
|
|
2021-05-12 17:16:56 +02:00
|
|
|
String parameter2 = "";
|
2021-04-09 17:39:59 +02:00
|
|
|
|
2021-05-09 14:42:24 +02:00
|
|
|
if(rbStartAppSelectByActivity.isChecked())
|
2021-05-12 17:16:56 +02:00
|
|
|
parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString();
|
2021-05-09 14:42:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(etPackageName.getText().toString() != null && etPackageName.getText().toString().length() > 0)
|
2021-05-12 17:16:56 +02:00
|
|
|
parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString();
|
2021-05-09 14:42:24 +02:00
|
|
|
else
|
2021-05-12 17:16:56 +02:00
|
|
|
parameter2 += Actions.dummyPackageString + ";" + etActivityOrActionPath.getText().toString();
|
2021-05-09 14:42:24 +02:00
|
|
|
}
|
2021-04-09 17:39:59 +02:00
|
|
|
|
2021-05-12 17:16:56 +02:00
|
|
|
if(rbStartAppByActivity.isChecked())
|
|
|
|
parameter2 += ";" + startByActivityString;
|
|
|
|
else
|
|
|
|
parameter2 += ";" + startByBroadcastString;
|
|
|
|
|
2021-02-16 13:42:49 +01:00
|
|
|
for(String s : intentPairList)
|
|
|
|
parameter2 += ";" + s;
|
|
|
|
|
|
|
|
resultingAction.setParameter2(parameter2);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private AlertDialog getIntentPairDialog(final int itemPosition)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityManageActionStartActivity.this);
|
2021-02-16 13:42:49 +01:00
|
|
|
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithIntentPair));
|
|
|
|
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
|
2021-03-29 16:36:21 +02:00
|
|
|
ActivityManageActionStartActivity.this.intentPairList.remove(itemPosition);
|
2021-02-16 13:42:49 +01:00
|
|
|
updateIntentPairList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
|
|
return alertDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class GetActivityListTask extends AsyncTask<Void, Void, Void>
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params)
|
|
|
|
{
|
2021-03-29 16:36:21 +02:00
|
|
|
getActivityList(ActivityManageActionStartActivity.this);
|
2021-02-16 13:42:49 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result)
|
|
|
|
{
|
|
|
|
progressDialog.dismiss();
|
|
|
|
getActionStartActivityDialog1().show();
|
|
|
|
}
|
|
|
|
}
|
2022-01-08 14:46:01 +01:00
|
|
|
}
|