Skip to content

Commit

Permalink
Improve haptic feedback of the control pad (#973)
Browse files Browse the repository at this point in the history
* Use HapticFeedbackConstants for consistent vibrations

* Added vibrations to all ControlPad buttons

* Removed vibration on key release
  • Loading branch information
Drumber authored Aug 13, 2023
1 parent 237bdc5 commit 389abee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/org/xbmc/kore/ui/widgets/ControlPad.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.xbmc.kore.ui.viewgroups.SquareGridLayout;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.RepeatListener;
import org.xbmc.kore.utils.UIUtils;

public class ControlPad extends SquareGridLayout
implements View.OnClickListener, View.OnLongClickListener {
Expand Down Expand Up @@ -154,6 +155,7 @@ private void setupListeners(Context context) {
OnTouchListener feedbackTouchListener = (v, event) -> {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
UIUtils.handleVibration(context, v);
buttonInAnim.setFillAfter(true);
v.startAnimation(buttonInAnim);
break;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/xbmc/kore/utils/RepeatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public RepeatListener(int initialInterval, int repeatInterval, View.OnClickListe
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
UIUtils.handleVibration(context);
UIUtils.handleVibration(context, view);
repeatHandler.removeCallbacks(handlerRunnable);
if (initialInterval >= 0) {
repeatHandler.postDelayed(handlerRunnable, initialInterval);
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/xbmc/kore/utils/UIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.text.style.ForegroundColorSpan;
import android.text.style.TextAppearanceSpan;
import android.util.DisplayMetrics;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
Expand Down Expand Up @@ -78,7 +79,6 @@ public class UIUtils {
public static final float IMAGE_RESIZE_FACTOR = 1.0f;

public static final int buttonRepeatInterval = 80; // ms
public static final int buttonVibrationDuration = 50; //ms

/**
* Formats time based on seconds
Expand Down Expand Up @@ -390,7 +390,7 @@ public static int changeColorAlpha(int color, int alpha)
return (alpha << 24) | (color & 0x00ffffff);
}

public static void handleVibration(Context context) {
public static void handleVibration(Context context, View view) {
if(context == null) return;

Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
Expand All @@ -402,7 +402,7 @@ public static void handleVibration(Context context) {
.getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS,
Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS);
if (vibrateOnPress) {
vibrator.vibrate(UIUtils.buttonVibrationDuration);
view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
}
}

Expand Down

0 comments on commit 389abee

Please sign in to comment.