Notification listener started.

This commit is contained in:
jens 2021-03-27 19:57:39 +01:00
parent 80f8f9cfe2
commit 712a374adb
7 changed files with 74 additions and 60 deletions

View File

@ -289,7 +289,7 @@ public class ActivityManageStartActivity extends Activity
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair); bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity); bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType); spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType);
tvSelectedActivity = (TextView)findViewById(R.id.tvSelectedActivity); tvSelectedActivity = (TextView)findViewById(R.id.tvSelectedApplication);
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageStartActivity.supportedIntentTypes); intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageStartActivity.supportedIntentTypes);
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter); spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);

View File

@ -16,10 +16,11 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.jens.automation2.Action.Action_Enum; import com.jens.automation2.Action.Action_Enum;
@ -33,12 +34,13 @@ public class ActivityManageTriggerNotification extends Activity
EditText etNotificationTitle, etNotificationText; EditText etNotificationTitle, etNotificationText;
Button bSelectApp, bSaveTriggerNotification; Button bSelectApp, bSaveTriggerNotification;
Spinner spinnerTitleDirection, spinnerTextDirection; Spinner spinnerTitleDirection, spinnerTextDirection;
TextView tvSelectedActivity; TextView tvSelectedApplication;
CheckBox chkNotificationDirection;
boolean edit = false; boolean edit = false;
ProgressDialog progressDialog = null; ProgressDialog progressDialog = null;
private static List<PackageInfo> pInfos = null; private static List<PackageInfo> pInfos = null;
public static Action resultingAction; public static Trigger resultingTrigger;
private static String[] directions; private static String[] directions;
@ -217,7 +219,7 @@ public class ActivityManageTriggerNotification extends Activity
{ {
//getActionStartActivityDialog3(packageArray[which]).show(); //getActionStartActivityDialog3(packageArray[which]).show();
//Miscellaneous.messageBox(getResources().getString(R.string.hint), getResources().getString(R.string.chooseActivityHint), ActivityManageNotificationTrigger.this).show(); //Miscellaneous.messageBox(getResources().getString(R.string.hint), getResources().getString(R.string.chooseActivityHint), ActivityManageNotificationTrigger.this).show();
tvSelectedActivity.setText(packageArray[which]); tvSelectedApplication.setText(packageArray[which]);
} }
}); });
AlertDialog alertDialog = alertDialogBuilder.create(); AlertDialog alertDialog = alertDialogBuilder.create();
@ -235,7 +237,7 @@ public class ActivityManageTriggerNotification extends Activity
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
ActivityInfo ai = ActivityManageTriggerNotification.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]); ActivityInfo ai = ActivityManageTriggerNotification.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]);
tvSelectedActivity.setText(ai.packageName + ";" + ai.name); tvSelectedApplication.setText(ai.packageName + ";" + ai.name);
} }
}); });
AlertDialog alertDialog = alertDialogBuilder.create(); AlertDialog alertDialog = alertDialogBuilder.create();
@ -255,7 +257,8 @@ public class ActivityManageTriggerNotification extends Activity
bSaveTriggerNotification = (Button)findViewById(R.id.bSaveTriggerNotification); bSaveTriggerNotification = (Button)findViewById(R.id.bSaveTriggerNotification);
spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection); spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection);
spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection); spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection);
tvSelectedActivity = (TextView)findViewById(R.id.tvSelectedActivity); tvSelectedApplication = (TextView)findViewById(R.id.tvSelectedApplication);
chkNotificationDirection = (CheckBox)findViewById(R.id.chkNotificationDirection);
directions = new String[] { directions = new String[] {
getResources().getString(R.string.directionStringEquals), getResources().getString(R.string.directionStringEquals),
@ -281,34 +284,44 @@ public class ActivityManageTriggerNotification extends Activity
} }
}); });
chkNotificationDirection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
chkNotificationDirection.setText(getResources().getString(R.string.notificationAppears));
else
chkNotificationDirection.setText(getResources().getString(R.string.notificationDisappears));
}
});
bSaveTriggerNotification.setOnClickListener(new OnClickListener() bSaveTriggerNotification.setOnClickListener(new OnClickListener()
{ {
@Override @Override
public void onClick(View v) public void onClick(View v)
{ {
if(saveAction()) String app;
{ if(tvSelectedApplication.getText().toString().equalsIgnoreCase(getResources().getString(R.string.anyApp)))
String app; app = "-1";
if(tvSelectedActivity.getText().toString().equalsIgnoreCase(getResources().getString(R.string.anyApp))) else
app = "-1"; app = tvSelectedApplication.getText().toString();
else
app = tvSelectedActivity.getText().toString();
String titleDir = Trigger.getMatchCode(spinnerTitleDirection.getSelectedItem().toString()); String titleDir = Trigger.getMatchCode(spinnerTitleDirection.getSelectedItem().toString());
String title = etNotificationTitle.getText().toString(); String title = etNotificationTitle.getText().toString();
String textDir = Trigger.getMatchCode(spinnerTextDirection.getSelectedItem().toString()); String textDir = Trigger.getMatchCode(spinnerTextDirection.getSelectedItem().toString());
String text = etNotificationText.getText().toString(); String text = etNotificationText.getText().toString();
Intent data = new Intent(); Intent data = new Intent();
data.putExtra("app", app); data.putExtra("direction", chkNotificationDirection.isChecked());
data.putExtra("titleDir", titleDir); data.putExtra("app", app);
data.putExtra("title", title); data.putExtra("titleDir", titleDir);
data.putExtra("textDir", textDir); data.putExtra("title", title);
data.putExtra("text", text); data.putExtra("textDir", textDir);
data.putExtra("text", text);
ActivityManageTriggerNotification.this.setResult(RESULT_OK, data); ActivityManageTriggerNotification.this.setResult(RESULT_OK, data);
finish(); finish();
}
} }
}); });
@ -341,32 +354,6 @@ public class ActivityManageTriggerNotification extends Activity
// } // }
} }
private boolean saveAction()
{
if(tvSelectedActivity.getText().toString().length() == 0)
{
Toast.makeText(ActivityManageTriggerNotification.this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show();
return false;
}
if(tvSelectedActivity.getText().toString().equals(getResources().getString(R.string.selectApplication)))
{
Toast.makeText(this, getResources().getString(R.string.selectApplication), Toast.LENGTH_LONG).show();
return false;
}
if(resultingAction == null)
resultingAction = new Action();
resultingAction.setAction(Action_Enum.startOtherActivity);
String parameter2 = tvSelectedActivity.getText().toString();
resultingAction.setParameter2(parameter2);
return true;
}
private class GetActivityListTask extends AsyncTask<Void, Void, Void> private class GetActivityListTask extends AsyncTask<Void, Void, Void>
{ {
@Override @Override

View File

@ -461,7 +461,11 @@ public class Trigger
String titleDir = params[1]; String titleDir = params[1];
String title = params[2]; String title = params[2];
String textDir = params[3]; String textDir = params[3];
String text = params[4]; String text;
if(params.length >=5)
text = params[4];
else
text = "";
StringBuilder triggerBuilder = new StringBuilder(); StringBuilder triggerBuilder = new StringBuilder();
String appString; String appString;

View File

@ -21,7 +21,7 @@
android:text="@string/selectApplication" /> android:text="@string/selectApplication" />
<TextView <TextView
android:id="@+id/tvSelectedActivity" android:id="@+id/tvSelectedApplication"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="" android:text=""

View File

@ -17,7 +17,7 @@
android:background="@color/barBackgroundColor" > android:background="@color/barBackgroundColor" >
<TextView <TextView
android:id="@+id/tvSelectedActivity" android:id="@+id/tvSelectedApplication"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/general" android:text="@string/general"

View File

@ -20,7 +20,25 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TableRow> <TableRow
android:layout_marginBottom="@dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/direction"/>
<CheckBox
android:id="@+id/chkNotificationDirection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/notificationAppears"
android:checked="true"/>
</TableRow>
<TableRow
android:layout_marginBottom="@dimen/activity_vertical_margin">
<TextView <TextView
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
@ -34,7 +52,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/tvSelectedActivity" android:id="@+id/tvSelectedApplication"
android:layout_marginHorizontal="@dimen/default_margin" android:layout_marginHorizontal="@dimen/default_margin"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -51,7 +69,8 @@
</TableRow> </TableRow>
<TableRow> <TableRow
android:layout_marginBottom="@dimen/activity_vertical_margin">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -79,7 +98,8 @@
</TableRow> </TableRow>
<TableRow> <TableRow
android:layout_marginBottom="@dimen/activity_vertical_margin">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -622,4 +622,7 @@
<string name="anyApp">Any app</string> <string name="anyApp">Any app</string>
<string name="notificationTriggerExplanation">This trigger will respond to other applications opening notifications in the notification area. You can specify another application from which the notification has to come from. If you don\'t the notifications from any other application will count.\nYou can also specify strings that must be or must not be in the notification title or notification body.</string> <string name="notificationTriggerExplanation">This trigger will respond to other applications opening notifications in the notification area. You can specify another application from which the notification has to come from. If you don\'t the notifications from any other application will count.\nYou can also specify strings that must be or must not be in the notification title or notification body.</string>
<string name="postsNotification">%1$s posts notification</string> <string name="postsNotification">%1$s posts notification</string>
<string name="notificationAppears">Notification appears</string>
<string name="notificationDisappears">Notification disappears</string>
<string name="direction">Direction</string>
</resources> </resources>