Skip to content

Instantly share code, notes, and snippets.

@matthewmorrone
Created November 21, 2020 21:01
Show Gist options
  • Save matthewmorrone/cfaf715e292b272d55cf7f132c616a28 to your computer and use it in GitHub Desktop.
Save matthewmorrone/cfaf715e292b272d55cf7f132c616a28 to your computer and use it in GitHub Desktop.
private int longClickDuration = 3000;
private boolean isLongPress = false;
numEquipeCheat.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
isLongPress = true;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (isLongPress) {
Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(100);
// set your code here
// Don't forgot to add <uses-permission android:name="android.permission.VIBRATE" /> to vibrate.
}
}
}, longClickDuration);
}
else if (event.getAction() == MotionEvent.ACTION_UP) {
isLongPress = false;
}
return true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment