forked from jens/Automation
notification trigger
This commit is contained in:
parent
53f46c10da
commit
87edd595ba
@ -152,6 +152,7 @@
|
|||||||
<activity android:name=".ActivityMaintenance" />
|
<activity android:name=".ActivityMaintenance" />
|
||||||
<activity android:name=".ActivityManageTriggerPhoneCall" />
|
<activity android:name=".ActivityManageTriggerPhoneCall" />
|
||||||
<activity android:name=".ActivityManageActionBrightnessSetting" />
|
<activity android:name=".ActivityManageActionBrightnessSetting" />
|
||||||
|
<activity android:name=".ActivityManageActionCreateNotification" />
|
||||||
<activity android:name=".ActivityManageTriggerDeviceOrientation" />
|
<activity android:name=".ActivityManageTriggerDeviceOrientation" />
|
||||||
<activity android:name=".ActivityHelp" />
|
<activity android:name=".ActivityHelp" />
|
||||||
<activity android:name=".ActivityManageActionVibrate" />
|
<activity android:name=".ActivityManageActionVibrate" />
|
||||||
|
@ -44,6 +44,7 @@ public class Action
|
|||||||
setScreenBrightness,
|
setScreenBrightness,
|
||||||
playSound,
|
playSound,
|
||||||
vibrate,
|
vibrate,
|
||||||
|
createNotification,
|
||||||
sendTextMessage;
|
sendTextMessage;
|
||||||
|
|
||||||
public String getFullName(Context context)
|
public String getFullName(Context context)
|
||||||
@ -108,6 +109,8 @@ public class Action
|
|||||||
return context.getResources().getString(R.string.sendTextMessage);
|
return context.getResources().getString(R.string.sendTextMessage);
|
||||||
case setScreenBrightness:
|
case setScreenBrightness:
|
||||||
return context.getResources().getString(R.string.setScreenBrightness);
|
return context.getResources().getString(R.string.setScreenBrightness);
|
||||||
|
case createNotification:
|
||||||
|
return context.getResources().getString(R.string.createNotification);
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
public class ActivityManageActionBrightnessSetting extends Activity
|
public class ActivityManageActionBrightnessSetting extends Activity
|
||||||
{
|
{
|
||||||
|
public static final String intentNameAutoBrightness = "autoBrightness";
|
||||||
|
public static final String intentNameBrightnessValue = "brightnessValue";
|
||||||
|
|
||||||
CheckBox chkAutoBrightness;
|
CheckBox chkAutoBrightness;
|
||||||
SeekBar sbBrightness;
|
SeekBar sbBrightness;
|
||||||
Button bApplyBrightness;
|
Button bApplyBrightness;
|
||||||
@ -32,11 +35,11 @@ public class ActivityManageActionBrightnessSetting extends Activity
|
|||||||
|
|
||||||
Intent input = getIntent();
|
Intent input = getIntent();
|
||||||
|
|
||||||
if(input.hasExtra("autoBrightness"))
|
if(input.hasExtra(intentNameAutoBrightness))
|
||||||
chkAutoBrightness.setChecked(input.getBooleanExtra("autoBrightness", false));
|
chkAutoBrightness.setChecked(input.getBooleanExtra(intentNameAutoBrightness, false));
|
||||||
|
|
||||||
if(input.hasExtra("brightnessValue"))
|
if(input.hasExtra(intentNameBrightnessValue))
|
||||||
sbBrightness.setProgress(input.getIntExtra("brightnessValue", 0));
|
sbBrightness.setProgress(input.getIntExtra(intentNameBrightnessValue, 0));
|
||||||
|
|
||||||
bApplyBrightness.setOnClickListener(new View.OnClickListener()
|
bApplyBrightness.setOnClickListener(new View.OnClickListener()
|
||||||
{
|
{
|
||||||
@ -44,8 +47,8 @@ public class ActivityManageActionBrightnessSetting extends Activity
|
|||||||
public void onClick(View view)
|
public void onClick(View view)
|
||||||
{
|
{
|
||||||
Intent answer = new Intent();
|
Intent answer = new Intent();
|
||||||
answer.putExtra("autoBrightness", chkAutoBrightness.isChecked());
|
answer.putExtra(intentNameAutoBrightness, chkAutoBrightness.isChecked());
|
||||||
answer.putExtra("brightnessValue", sbBrightness.getProgress());
|
answer.putExtra(intentNameBrightnessValue, sbBrightness.getProgress());
|
||||||
setResult(RESULT_OK, answer);
|
setResult(RESULT_OK, answer);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class ActivityManageActionCreateNotification extends Activity
|
||||||
|
{
|
||||||
|
public static final String intentNameNotificationTitle = "notificationTitle";
|
||||||
|
public static final String intentNameNotificationText = "notificationText";
|
||||||
|
|
||||||
|
EditText etNotificationTitle, etNotificationText;
|
||||||
|
Button bSaveActionNotification;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_manage_action_create_notification);
|
||||||
|
|
||||||
|
etNotificationTitle = (EditText) findViewById(R.id.etNotificationTitle);
|
||||||
|
etNotificationText = (EditText)findViewById(R.id.etNotificationText);
|
||||||
|
bSaveActionNotification = (Button)findViewById(R.id.bSaveActionNotification);
|
||||||
|
|
||||||
|
Intent input = getIntent();
|
||||||
|
|
||||||
|
if(input.hasExtra(intentNameNotificationTitle))
|
||||||
|
etNotificationTitle.setText(input.getStringExtra(intentNameNotificationTitle));
|
||||||
|
|
||||||
|
if(input.hasExtra(intentNameNotificationText))
|
||||||
|
etNotificationText.setText(input.getStringExtra(intentNameNotificationText));
|
||||||
|
|
||||||
|
bSaveActionNotification.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
if(StringUtils.isBlank(etNotificationTitle.getText().toString()))
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityManageActionCreateNotification.this, getResources().getString(R.string.enterTitle), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(StringUtils.isBlank(etNotificationText.getText().toString()))
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityManageActionCreateNotification.this, getResources().getString(R.string.enterText), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent answer = new Intent();
|
||||||
|
answer.putExtra(intentNameNotificationTitle, etNotificationTitle.getText().toString());
|
||||||
|
answer.putExtra(intentNameNotificationText, etNotificationText.getText().toString());
|
||||||
|
setResult(RESULT_OK, answer);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -115,6 +115,8 @@ public class ActivityManageRule extends Activity
|
|||||||
final static int requestCodeActionSendTextMessageEdit = 5002;
|
final static int requestCodeActionSendTextMessageEdit = 5002;
|
||||||
final static int requestCodeActionVibrateAdd = 801;
|
final static int requestCodeActionVibrateAdd = 801;
|
||||||
final static int requestCodeActionVibrateEdit = 802;
|
final static int requestCodeActionVibrateEdit = 802;
|
||||||
|
final static int requestCodeActionCreateNotificationAdd = 803;
|
||||||
|
final static int requestCodeActionCreateNotificationEdit = 804;
|
||||||
|
|
||||||
public static ActivityManageRule getInstance()
|
public static ActivityManageRule getInstance()
|
||||||
{
|
{
|
||||||
@ -353,8 +355,8 @@ public class ActivityManageRule extends Activity
|
|||||||
break;
|
break;
|
||||||
case setScreenBrightness:
|
case setScreenBrightness:
|
||||||
Intent activityEditScreenBrightnessIntent = new Intent(ActivityManageRule.this, ActivityManageActionBrightnessSetting.class);
|
Intent activityEditScreenBrightnessIntent = new Intent(ActivityManageRule.this, ActivityManageActionBrightnessSetting.class);
|
||||||
activityEditScreenBrightnessIntent.putExtra("autoBrightness", a.getParameter1());
|
activityEditScreenBrightnessIntent.putExtra(ActivityManageActionBrightnessSetting.intentNameAutoBrightness, a.getParameter1());
|
||||||
activityEditScreenBrightnessIntent.putExtra("brightnessValue", Integer.parseInt(a.getParameter2()));
|
activityEditScreenBrightnessIntent.putExtra(ActivityManageActionBrightnessSetting.intentNameBrightnessValue, Integer.parseInt(a.getParameter2()));
|
||||||
startActivityForResult(activityEditScreenBrightnessIntent, requestCodeActionScreenBrightnessEdit);
|
startActivityForResult(activityEditScreenBrightnessIntent, requestCodeActionScreenBrightnessEdit);
|
||||||
break;
|
break;
|
||||||
case vibrate:
|
case vibrate:
|
||||||
@ -362,6 +364,13 @@ public class ActivityManageRule extends Activity
|
|||||||
activityEditVibrateIntent.putExtra("vibratePattern", a.getParameter2());
|
activityEditVibrateIntent.putExtra("vibratePattern", a.getParameter2());
|
||||||
startActivityForResult(activityEditVibrateIntent, requestCodeActionVibrateEdit);
|
startActivityForResult(activityEditVibrateIntent, requestCodeActionVibrateEdit);
|
||||||
break;
|
break;
|
||||||
|
case createNotification:
|
||||||
|
Intent activityEditCreateNotificationIntent = new Intent(ActivityManageRule.this, ActivityManageActionCreateNotification.class);
|
||||||
|
String[] elements = a.getParameter2().split(Action.actionParameter2Split);
|
||||||
|
activityEditCreateNotificationIntent.putExtra(ActivityManageActionCreateNotification.intentNameNotificationTitle, elements[0]);
|
||||||
|
activityEditCreateNotificationIntent.putExtra(ActivityManageActionCreateNotification.intentNameNotificationText, elements[1]);
|
||||||
|
startActivityForResult(activityEditCreateNotificationIntent, requestCodeActionCreateNotificationEdit);
|
||||||
|
break;
|
||||||
case playSound:
|
case playSound:
|
||||||
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
||||||
actionPlaySoundIntent.putExtra("edit", true);
|
actionPlaySoundIntent.putExtra("edit", true);
|
||||||
@ -1336,8 +1345,8 @@ public class ActivityManageRule extends Activity
|
|||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
newAction.setParameter1(data.getBooleanExtra("autoBrightness", false));
|
newAction.setParameter1(data.getBooleanExtra(ActivityManageActionBrightnessSetting.intentNameAutoBrightness, false));
|
||||||
newAction.setParameter2(String.valueOf(data.getIntExtra("brightnessValue", 0)));
|
newAction.setParameter2(String.valueOf(data.getIntExtra(ActivityManageActionBrightnessSetting.intentNameBrightnessValue, 0)));
|
||||||
newAction.setParentRule(ruleToEdit);
|
newAction.setParentRule(ruleToEdit);
|
||||||
ruleToEdit.getActionSet().add(newAction);
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
@ -1368,6 +1377,20 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeActionCreateNotificationAdd)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
newAction.setParentRule(ruleToEdit);
|
||||||
|
newAction.setParameter2(
|
||||||
|
data.getStringExtra(ActivityManageActionCreateNotification.intentNameNotificationTitle)
|
||||||
|
+ Action.actionParameter2Split +
|
||||||
|
data.getStringExtra(ActivityManageActionCreateNotification.intentNameNotificationText)
|
||||||
|
);
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeActionVibrateEdit)
|
else if(requestCode == requestCodeActionVibrateEdit)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
@ -1380,6 +1403,22 @@ public class ActivityManageRule extends Activity
|
|||||||
this.refreshActionList();
|
this.refreshActionList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(requestCode == requestCodeActionCreateNotificationEdit)
|
||||||
|
{
|
||||||
|
if(resultCode == RESULT_OK)
|
||||||
|
{
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||||
|
|
||||||
|
if(data.hasExtra(ActivityManageActionCreateNotification.intentNameNotificationTitle))
|
||||||
|
ruleToEdit.getActionSet().get(editIndex).setParameter2(
|
||||||
|
data.getStringExtra(ActivityManageActionCreateNotification.intentNameNotificationTitle)
|
||||||
|
+ Action.actionParameter2Split +
|
||||||
|
data.getStringExtra(ActivityManageActionCreateNotification.intentNameNotificationText)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.refreshActionList();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(requestCode == requestCodeActionPlaySoundAdd)
|
else if(requestCode == requestCodeActionPlaySoundAdd)
|
||||||
{
|
{
|
||||||
if(resultCode == RESULT_OK)
|
if(resultCode == RESULT_OK)
|
||||||
@ -1682,6 +1721,12 @@ public class ActivityManageRule extends Activity
|
|||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
||||||
startActivityForResult(intent, requestCodeActionVibrateAdd);
|
startActivityForResult(intent, requestCodeActionVibrateAdd);
|
||||||
}
|
}
|
||||||
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.createNotification.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.createNotification);
|
||||||
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCreateNotification.class);
|
||||||
|
startActivityForResult(intent, requestCodeActionCreateNotificationAdd);
|
||||||
|
}
|
||||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setScreenBrightness.toString()))
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setScreenBrightness.toString()))
|
||||||
{
|
{
|
||||||
newAction.setAction(Action_Enum.setScreenBrightness);
|
newAction.setAction(Action_Enum.setScreenBrightness);
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/default_margin" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/createNotification"
|
||||||
|
android:textSize="25dp"
|
||||||
|
android:layout_marginBottom="@dimen/default_margin" />
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:shrinkColumns="1"
|
||||||
|
android:stretchColumns="1">
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_marginBottom="@dimen/activity_vertical_margin">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginRight="@dimen/default_margin"
|
||||||
|
android:text="@string/title" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etNotificationTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:layout_marginVertical="@dimen/default_margin"
|
||||||
|
android:background="#aa000000" />
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_marginBottom="@dimen/activity_vertical_margin">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:text="@string/text" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etNotificationText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10" />
|
||||||
|
|
||||||
|
</TableRow>>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:layout_marginVertical="@dimen/default_margin"
|
||||||
|
android:background="#aa000000" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLegend"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dip"
|
||||||
|
android:text="@string/urlLegend" />
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/bSaveActionNotification"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/default_margin"
|
||||||
|
android:text="@string/save" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
@ -755,4 +755,7 @@
|
|||||||
<string name="pickActivityManually">Choose activity manually</string>
|
<string name="pickActivityManually">Choose activity manually</string>
|
||||||
<string name="launcherOrManualExplanation">Easy mode: Automation can try to identify the launcher activity of the desired program. Alternatively you can also pick one of the application\'s activities manually. What would you like?</string>
|
<string name="launcherOrManualExplanation">Easy mode: Automation can try to identify the launcher activity of the desired program. Alternatively you can also pick one of the application\'s activities manually. What would you like?</string>
|
||||||
<string name="launcherNotFound">A launcher activity of this app could not be identified. You will have to pick one manually.</string>
|
<string name="launcherNotFound">A launcher activity of this app could not be identified. You will have to pick one manually.</string>
|
||||||
|
<string name="createNotification">Create notification</string>
|
||||||
|
<string name="enterTitle">Enter a title.</string>
|
||||||
|
<string name="enterText">Enter a text.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user