Moved vibration handling to UIUtils
This commit is contained in:
parent
cf0f76b5bd
commit
7170dc9548
|
@ -67,7 +67,6 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
private View downView;
|
||||
|
||||
private Context context;
|
||||
private Vibrator vibrator;
|
||||
|
||||
/**
|
||||
* Constructor for a repeat listener
|
||||
|
@ -104,10 +103,7 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
this.animDown = animDown;
|
||||
this.animUp = animUp;
|
||||
|
||||
if (context != null) {
|
||||
this.context = context;
|
||||
this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
}
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +118,7 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
switch (motionEvent.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
handleVibration();
|
||||
UIUtils.handleVibration(context);
|
||||
repeatHandler.removeCallbacks(handlerRunnable);
|
||||
if (initialInterval >= 0) {
|
||||
repeatHandler.postDelayed(handlerRunnable, initialInterval);
|
||||
|
@ -150,18 +146,4 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
// Consume the event for views other than buttons
|
||||
return !((view instanceof Button) || (view instanceof ImageButton));
|
||||
}
|
||||
|
||||
private void handleVibration() {
|
||||
if(context != null) {
|
||||
//Check if we should vibrate
|
||||
boolean vibrateOnPress = PreferenceManager
|
||||
.getDefaultSharedPreferences(context)
|
||||
.getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS,
|
||||
Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS);
|
||||
if (vibrateOnPress) {
|
||||
vibrator.vibrate(UIUtils.buttonVibrationDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,8 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -395,6 +397,20 @@ public class UIUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void handleVibration(Context context) {
|
||||
if(context != null) {
|
||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
//Check if we should vibrate
|
||||
boolean vibrateOnPress = PreferenceManager
|
||||
.getDefaultSharedPreferences(context)
|
||||
.getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS,
|
||||
Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS);
|
||||
if (vibrateOnPress) {
|
||||
vibrator.vibrate(UIUtils.buttonVibrationDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the remote activity, performing a circular reveal animation if
|
||||
* Lollipop or later
|
||||
|
|
Loading…
Reference in New Issue