Vibrate pattern

This commit is contained in:
jens 2021-07-04 15:53:24 +02:00
parent 71d9791603
commit a8bfc6f7ec
10 changed files with 128 additions and 122 deletions

View File

@ -15,6 +15,7 @@ public class Action
{
public static final String actionParameter2Split = "ap2split";
public static final String intentPairSeperator = "intPairSplit";
public static final String vibrateSeparator = ",";
public enum Action_Enum {
setWifi,
@ -38,6 +39,7 @@ public class Action
playMusic,
setScreenBrightness,
playSound,
vibrate,
sendTextMessage;
public String getFullName(Context context)
@ -84,6 +86,8 @@ public class Action
return context.getResources().getString(R.string.waitBeforeNextAction);
case wakeupDevice:
return context.getResources().getString(R.string.wakeupDevice);
case vibrate:
return context.getResources().getString(R.string.vibrate);
case setAirplaneMode:
return context.getResources().getString(R.string.airplaneMode);
case setDataConnection:
@ -405,6 +409,9 @@ public class Action
case setScreenBrightness:
Actions.setScreenBrightness(getParameter1(), Integer.parseInt(getParameter2()));
break;
case vibrate:
Actions.vibrate(getParameter1(), getParameter2());
break;
case playSound:
Actions.playSound(getParameter1(), getParameter2());
break;

View File

@ -16,6 +16,8 @@ import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.telephony.SmsManager;
import android.telephony.SubscriptionManager;
@ -544,6 +546,37 @@ public class Actions
Miscellaneous.logEvent("i", "Play sound file", "Not playing sound file because phone is on some kind of mute state.", 2);
}
public static void vibrate(boolean parameter1, String parameter2)
{
String vibrateDurations[] = parameter2.split(Action.vibrateSeparator);
int counter = 1;
for(String vibrate : vibrateDurations)
{
if(counter % 2 != 0)
{
Vibrator vibrator = (Vibrator) Miscellaneous.getAnyContext().getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
vibrator.vibrate(VibrationEffect.createOneShot(Long.parseLong(vibrate), VibrationEffect.DEFAULT_AMPLITUDE));
else
vibrator.vibrate(Long.parseLong(vibrate));
}
else
{
try
{
Thread.sleep(Long.parseLong(vibrate));
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "VibrateSleep", Log.getStackTraceString(e), 5);
}
}
counter++;
}
}
public void useDownloadedWebpage(String result)
{
// Toast.makeText(context, "Result: " + result, Toast.LENGTH_LONG).show();

View File

@ -84,20 +84,10 @@ public class ActivityManageActionSendTextMessage extends Activity
etPhoneNumber.setText(parameters[0]);
etSendTextMessage.setText(parameters[1]);
}
// String url = getIntent().getStringExtra("urlToTrigger");
// if(url != null)
// existingUrl = url;
}
private void backToRuleManager()
{
// Intent returnIntent = new Intent();
// returnIntent.putExtra("urlToTrigger", existingUrl);
// setResult(RESULT_OK, returnIntent);
if(edit && resultingAction != null)
{
ActivityManageActionSendTextMessage.resultingAction.setParameter2(etPhoneNumber.getText().toString() + Actions.smsSeparator + etSendTextMessage.getText().toString());

View File

@ -3,6 +3,7 @@ package com.jens.automation2;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.VibrationEffect;
@ -11,9 +12,12 @@ import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
public class ActivityManageActionVibrate extends Activity
{
TextView etVibratePattern;
@ -29,29 +33,53 @@ public class ActivityManageActionVibrate extends Activity
bTestVibratePattern = (Button)findViewById(R.id.bTestVibratePattern);
bSaveVibratePattern = (Button)findViewById(R.id.bSaveVibratePattern);
bSaveVibratePattern.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if(checkInput())
{
Intent answer = new Intent();
answer.putExtra("vibratePattern", etVibratePattern.getText().toString());
setResult(RESULT_OK, answer);
finish();
}
}
});
bTestVibratePattern.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if(ActivityPermissions.havePermission(Manifest.permission.VIBRATE, ActivityManageActionVibrate.this))
if(checkInput())
{
String vibrateDurations[] = etVibratePattern.getText().toString().split(",");
for(String duration : vibrateDurations)
if (ActivityPermissions.havePermission(Manifest.permission.VIBRATE, ActivityManageActionVibrate.this))
{
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
vibrator.vibrate(VibrationEffect.createOneShot(Long.parseLong(duration), VibrationEffect.DEFAULT_AMPLITUDE));
}
else
{
vibrator.vibrate(Long.parseLong(duration));
}
String pattern = etVibratePattern.getText().toString();
Actions.vibrate(false, pattern);
}
}
}
});
Intent input = getIntent();
if(input.hasExtra("vibratePattern"))
etVibratePattern.setText(input.getStringExtra("vibratePattern"));
}
boolean checkInput()
{
String vibratePattern = etVibratePattern.getText().toString();
String regex = "^[0-9,]+$";
if(StringUtils.isEmpty(vibratePattern) || !vibratePattern.matches(regex) || vibratePattern.substring(0, 1).equals(",") || vibratePattern.substring(vibratePattern.length()-1).equals(","))
{
Toast.makeText(ActivityManageActionVibrate.this, getResources().getString(R.string.pleaseEnterValidVibrationPattern), Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
}

View File

@ -103,6 +103,9 @@ public class ActivityManageRule extends Activity
final static int requestCodeTriggerPhoneCallEdit = 602;
final static int requestCodeTriggerWifiAdd = 723;
final static int requestCodeTriggerWifiEdit = 724;
final static int requestCodeActionSendTextMessageAdd = 5001;
final static int requestCodeActionVibrateAdd = 801;
final static int requestCodeActionVibrateEdit = 802;
public static ActivityManageRule getInstance()
{
@ -228,27 +231,11 @@ public class ActivityManageRule extends Activity
Trigger selectedTrigger = (Trigger)triggerListView.getItemAtPosition(arg2);
switch(selectedTrigger.getTriggerType())
{
// case batteryLevel:
// break;
// case charging:
// break;
// case noiseLevel:
// break;
// case pointOfInterest:
// break;
// case process_started_stopped:
// break;
// case speed:
// break;
case timeFrame:
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger;
Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTimeFrame.class);
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeEdit);
break;
// case usb_host_connection:
// break;
// case wifiConnection:
// break;
case bluetoothConnection:
ActivityManageTriggerBluetooth.editedBluetoothTrigger = selectedTrigger;
Intent bluetoothEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerBluetooth.class);
@ -306,14 +293,6 @@ public class ActivityManageRule extends Activity
Action a = (Action)actionListView.getItemAtPosition(arg2);
switch(a.getAction())
{
// case changeSoundProfile:
// break;
// case disableScreenRotation:
// break;
// case enableScreenRotation:
// break;
// case setAirplaneMode:
// break;
case startOtherActivity:
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class);
ActivityManageActionStartActivity.resultingAction = a;
@ -340,11 +319,15 @@ public class ActivityManageRule extends Activity
break;
case setScreenBrightness:
Intent activityEditScreenBrightnessIntent = new Intent(ActivityManageRule.this, ActivityManageActionBrightnessSetting.class);
// ActivityEditTriggerUrl.resultingAction = a;
activityEditScreenBrightnessIntent.putExtra("autoBrightness", a.getParameter1());
activityEditScreenBrightnessIntent.putExtra("brightnessValue", Integer.parseInt(a.getParameter2()));
startActivityForResult(activityEditScreenBrightnessIntent, requestCodeActionScreenBrightnessEdit);
break;
case vibrate:
Intent activityEditVibrateIntent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
activityEditVibrateIntent.putExtra("vibratePattern", a.getParameter2());
startActivityForResult(activityEditVibrateIntent, requestCodeActionVibrateEdit);
break;
case playSound:
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
actionPlaySoundIntent.putExtra("edit", true);
@ -686,13 +669,6 @@ public class ActivityManageRule extends Activity
String[] choices = (String[]) choicesList.toArray(new String[choicesList.size()]);
getTriggerNoiseDialog(myContext, choices).show();
}
// else if(triggerType.equals(Trigger.Event_Enum.timeFrame))
// {
// newTrigger.setTriggerType(Trigger.Event_Enum.timeFrame);
// ActivityManageTimeFrame.editedTimeFrameTrigger = null;
// Intent timeFrameEditor = new Intent(myContext, ActivityManageTimeFrame.class);
// startActivityForResult(timeFrameEditor, 2000);
// }
else if(triggerType.equals(Trigger_Enum.wifiConnection))
{
newTrigger.setTriggerType(Trigger_Enum.wifiConnection);
@ -703,7 +679,6 @@ public class ActivityManageRule extends Activity
progressDialog = ProgressDialog.show(myContext, null, getResources().getString(R.string.gettingListOfInstalledApplications), true, false);
newTrigger.setTriggerType(Trigger_Enum.process_started_stopped);
new GenerateApplicationSelectionsDialogTask().execute(ActivityManageRule.this);
// getTriggerRunningProcessDialog1(myContext).show();
}
else if(triggerType.equals(Trigger_Enum.phoneCall))
{
@ -1298,6 +1273,25 @@ public class ActivityManageRule extends Activity
this.refreshActionList();
}
}
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();
}
}
else if(requestCode == requestCodeActionPlaySoundAdd)
{
if(resultCode == RESULT_OK)
@ -1375,6 +1369,8 @@ public class ActivityManageRule extends Activity
items.add(new Item(typesLong[i].toString(), R.drawable.brightness));
else if(types[i].toString().equals(Action_Enum.playSound.toString()))
items.add(new Item(typesLong[i].toString(), R.drawable.sound));
else if(types[i].toString().equals(Action_Enum.vibrate.toString()))
items.add(new Item(typesLong[i].toString(), R.drawable.vibrate));
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
{
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
@ -1504,14 +1500,13 @@ public class ActivityManageRule extends Activity
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendTextMessage.toString()))
{
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, "android.permission.SEND_SMS"))
{
//launch other activity to enter parameters;
newAction.setAction(Action_Enum.sendTextMessage);
ActivityManageActionSendTextMessage.resultingAction = null;
Intent editTriggerIntent = new Intent(context, ActivityManageActionSendTextMessage.class);
startActivityForResult(editTriggerIntent, 5001);
startActivityForResult(editTriggerIntent, requestCodeActionSendTextMessageAdd);
}
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.playMusic.toString()))
@ -1520,6 +1515,12 @@ public class ActivityManageRule extends Activity
ruleToEdit.getActionSet().add(newAction);
refreshActionList();
}
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);
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setScreenBrightness.toString()))
{
newAction.setAction(Action_Enum.setScreenBrightness);
@ -1637,63 +1638,6 @@ public class ActivityManageRule extends Activity
return alertDialog;
}
/*private AlertDialog getActionStartActivityDialog1(final Context myContext)
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectApplication));
final String[] applicationArray = ActivityManageStartActivity.getApplicationNameListString(ActivityManageSpecificRule.this);
alertDialogBuilder.setItems(applicationArray, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
getActionStartActivityDialog2(myContext, applicationArray[which]).show();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
return alertDialog;
}
private AlertDialog getActionStartActivityDialog2(final Context myContext, String applicationName)
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectPackageOfApplication));
final String[] packageArray = ActivityManageStartActivity.getPackageListString(ActivityManageSpecificRule.this, applicationName);
alertDialogBuilder.setItems(packageArray, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
getActionStartActivityDialog3(ActivityManageSpecificRule.this, packageArray[which]).show();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
return alertDialog;
}
private AlertDialog getActionStartActivityDialog3(final Context myContext, final String packageName)
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(myContext.getResources().getString(R.string.selectActivityToBeStarted));
final String activityArray[] = ActivityManageStartActivity.getActivityListForPackageName(packageName);
alertDialogBuilder.setItems(activityArray, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
ActivityInfo ai = ActivityManageStartActivity.getActivityInfoForPackageNameAndActivityName(packageName, activityArray[which]);
// Log.i("Selected", ai.packageName + " / " + ai.name);
newAction.setParameter2(ai.packageName + ";" + ai.name);
newAction.toString();
ruleToEdit.getActionSet().add(newAction);
refreshActionList();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
return alertDialog;
}*/
private AlertDialog getActionWaitBeforeNextActionDialog(final Context myContext)
{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

View File

@ -852,9 +852,7 @@ public class ActivityPermissions extends Activity
{
if (requestCode == requestCodeForPermissionsBackgroundLocation)
{
NotificationManager mNotificationManager = (NotificationManager) ActivityPermissions.this.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager.isNotificationPolicyAccessGranted())
if (havePermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION, ActivityPermissions.this))
requestPermissions(cachedPermissionsToRequest, true);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -26,7 +26,8 @@
<EditText
android:id="@+id/etVibratePattern"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/default_margin"/>
<Button
android:id="@+id/bTestVibratePattern"

View File

@ -586,4 +586,8 @@
<string name="locationFoundInaccurate">Es konnte nur eine ungenaue Position gefunden werden. Das funktioniert u.U. nicht zuverlässig. Der vorgeschlagene Mindestradius für Orte beträgt %1$d m.</string>
<string name="pleaseGiveBgLocation">Gehen Sie auf dem nächsten Bildschirm bitte auf Berechtigungen, dann Position. Wählen Sie dort Immer erlauben aus, um Automation zu ermöglichen, die Position im Hintergrund zu ermitteln.</string>
<string name="noLocationCouldBeFound">Leider konnte nach einem Limit von %1$s Sekunden keine Position gefunden werden.</string>
<string name="vibrate">Vibrieren</string>
<string name="test">Ausprobieren</string>
<string name="VibrateExplanation">Geben Sie eine Vibrationsdauer, gefolgt von einem Komma ein, dann eine Pausendauer. Sie können so viele Vibrationen eingeben, wie sie möchten. Trennen Sie sie wieder mit Kommata.\nZ.B. wird das Muster 100,500,500,1000,100 100ms vibrieren, 500ms warten, 500ms vibrieren, 1000ms warten, 100ms vibrieren.\nWenn Sie denken, daß eine Vibration verschluckt wird, verlängern Sie die Pause vor ihr.</string>
<string name="pleaseEnterValidVibrationPattern">Bitte geben Sie ein gültiges Vibrationsmuster ein.</string>
</resources>

View File

@ -683,6 +683,7 @@
<string name="noLocationCouldBeFound">No position could be found after a timeout of %1$s seconds.</string>
<string name="pleaseGiveBgLocation">In the next screen please go to permissions, then location. There select \"Allow all the time\" to allow Automation to determine your location in the background.</string>
<string name="vibrate">Vibrate</string>
<string name="test">Test</string>
<string name="VibrateExplanation">Enter one or many vibrate durations in milliseconds. Separate them by kommas.</string>
<string name="test">Try</string>
<string name="VibrateExplanation">Enter a vibration duration, followed by a comma, then a pause duration. You can concatenate as many vibrations as you like. Separate them by commas again.\nE.g. the pattern 100,500,500,1000,100 will vibrate 100, wait 500, vibrate 500, wait 1000, vibrate 100.\nIf you think a vibration is dropped try increasing the pause before them.</string>
<string name="pleaseEnterValidVibrationPattern">Please enter a valid vibration pattern.</string>
</resources>