Vibrate pattern

This commit is contained in:
2021-07-04 02:14:26 +02:00
parent eef6c3234a
commit d71177f3da
8 changed files with 125 additions and 10 deletions

View File

@ -0,0 +1,57 @@
package com.jens.automation2;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.Nullable;
public class ActivityManageActionVibrate extends Activity
{
TextView etVibratePattern;
Button bTestVibratePattern, bSaveVibratePattern;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_action_vibrate);
etVibratePattern = (EditText)findViewById(R.id.etVibratePattern);
bTestVibratePattern = (Button)findViewById(R.id.bTestVibratePattern);
bSaveVibratePattern = (Button)findViewById(R.id.bSaveVibratePattern);
bTestVibratePattern.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if(ActivityPermissions.havePermission(Manifest.permission.VIBRATE, ActivityManageActionVibrate.this))
{
String vibrateDurations[] = etVibratePattern.getText().toString().split(",");
for(String duration : vibrateDurations)
{
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));
}
}
}
}
});
}
}

View File

@ -0,0 +1,46 @@
<?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:layout_span="2"
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginBottom="@dimen/default_margin"
android:text="@string/vibrate" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/VibrateExplanation" />
<EditText
android:id="@+id/etVibratePattern"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/bTestVibratePattern"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/default_margin"
android:text="@string/test" />
<Button
android:id="@+id/bSaveVibratePattern"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save" />
</LinearLayout>
</ScrollView>

View File

@ -4,6 +4,15 @@
android:layout_height="match_parent"
android:layout_margin="@dimen/default_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginBottom="@dimen/default_margin"
android:text="@string/setScreenBrightness" />
<CheckBox
android:id="@+id/chkAutoBrightness"
android:layout_width="match_parent"

View File

@ -682,4 +682,7 @@
<string name="clone">Clone</string>
<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>
</resources>