Haptics everywhere
This commit is contained in:
parent
724384db88
commit
be6ad84398
7 changed files with 51 additions and 0 deletions
|
@ -3,6 +3,8 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
|
|
|
@ -209,6 +209,8 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
return true;
|
||||
});
|
||||
binding.fab.setOnClickListener(view -> {
|
||||
Utils.hapticTick(view);
|
||||
|
||||
// Finalize values
|
||||
this.eventContainer.comment = this.binding.eventEditContent.eventEditComment.getText().toString().trim();
|
||||
|
||||
|
|
|
@ -124,6 +124,8 @@ public class EventListActivity extends AppCompatActivity {
|
|||
return true;
|
||||
});
|
||||
binding.fab.setOnClickListener(view -> {
|
||||
Utils.hapticTick(view);
|
||||
|
||||
Bundle extra = new Bundle();
|
||||
extra.putInt("queue_id", this.queue.getId());
|
||||
|
||||
|
|
|
@ -121,6 +121,8 @@ class EventRecyclerViewAdapter extends RecyclerView.Adapter<EventRecyclerViewAda
|
|||
return true;
|
||||
});
|
||||
viewHolder.getBinding().eventListItemItem.setOnClickListener((View view) -> {
|
||||
Utils.hapticTick(view);
|
||||
|
||||
Bundle extra = new Bundle();
|
||||
extra.putInt("event_id", this.events[position].getId());
|
||||
extra.putInt("queue_id", this.queue.getId());
|
||||
|
|
|
@ -156,6 +156,8 @@ public class QueueListActivity extends AppCompatActivity {
|
|||
return true;
|
||||
});
|
||||
binding.fab.setOnClickListener(view -> {
|
||||
Utils.hapticTick(view);
|
||||
|
||||
Queue q = Wrapper.getQueueMaker().create();
|
||||
q.setName("New Queue");
|
||||
|
||||
|
|
|
@ -17,11 +17,16 @@
|
|||
package art.pegasko.yeeemp.ui.activity;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -100,6 +105,8 @@ class QueueRecyclerViewAdapter extends RecyclerView.Adapter<QueueRecyclerViewAda
|
|||
return true;
|
||||
});
|
||||
viewHolder.getBinding().queueListItemItem.setOnClickListener((View view) -> {
|
||||
Utils.hapticTick(view);
|
||||
|
||||
Bundle extra = new Bundle();
|
||||
extra.putInt("queue_id", queues[position].getId());
|
||||
|
||||
|
@ -112,6 +119,8 @@ class QueueRecyclerViewAdapter extends RecyclerView.Adapter<QueueRecyclerViewAda
|
|||
viewHolder.getBinding().queueListItemStats.setText(Integer.toString(queues[position].getEventCount()));
|
||||
|
||||
viewHolder.getBinding().queueListItemPlus.setOnClickListener((View view) -> {
|
||||
Utils.hapticTick(view);
|
||||
|
||||
Bundle extra = new Bundle();
|
||||
extra.putInt("queue_id", this.queues[position].getId());
|
||||
|
||||
|
|
|
@ -16,6 +16,13 @@
|
|||
|
||||
package art.pegasko.yeeemp.ui.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.View;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -55,4 +62,29 @@ public class Utils {
|
|||
return 0;
|
||||
return Math.abs(o.hashCode()) & ((1 << 16) - 1);
|
||||
}
|
||||
|
||||
public static void hapticTick(View view) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// Vibration muted, do nothing
|
||||
if (!view.isHapticFeedbackEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Success only if haptics available and worked
|
||||
if (view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to basic vibration
|
||||
Vibrator vibrator = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibrator != null) {
|
||||
// TODO: Respect silent mode
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(10, 50));
|
||||
} else {
|
||||
vibrator.vibrate(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue