use of android.view.GestureDetector in project enroscar by stanfy.
the class LoadableImageSwitcher method init.
private void init(final Context context) {
super.setFactory(this);
gestureDetector = new GestureDetector(context, this);
gestureDetector.setIsLongpressEnabled(true);
}
use of android.view.GestureDetector in project android_frameworks_base by ParanoidAndroid.
the class KeyboardView method initGestureDetector.
private void initGestureDetector() {
mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
if (mPossiblePoly)
return false;
final float absX = Math.abs(velocityX);
final float absY = Math.abs(velocityY);
float deltaX = me2.getX() - me1.getX();
float deltaY = me2.getY() - me1.getY();
// Half the keyboard width
int travelX = getWidth() / 2;
// Half the keyboard height
int travelY = getHeight() / 2;
mSwipeTracker.computeCurrentVelocity(1000);
final float endingVelocityX = mSwipeTracker.getXVelocity();
final float endingVelocityY = mSwipeTracker.getYVelocity();
boolean sendDownKey = false;
if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
sendDownKey = true;
} else {
swipeRight();
return true;
}
} else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
sendDownKey = true;
} else {
swipeLeft();
return true;
}
} else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
sendDownKey = true;
} else {
swipeUp();
return true;
}
} else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
sendDownKey = true;
} else {
swipeDown();
return true;
}
}
if (sendDownKey) {
detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
}
return false;
}
});
mGestureDetector.setIsLongpressEnabled(false);
}
use of android.view.GestureDetector in project platform_frameworks_base by android.
the class KeyboardView method initGestureDetector.
private void initGestureDetector() {
if (mGestureDetector == null) {
mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
if (mPossiblePoly)
return false;
final float absX = Math.abs(velocityX);
final float absY = Math.abs(velocityY);
float deltaX = me2.getX() - me1.getX();
float deltaY = me2.getY() - me1.getY();
// Half the keyboard width
int travelX = getWidth() / 2;
// Half the keyboard height
int travelY = getHeight() / 2;
mSwipeTracker.computeCurrentVelocity(1000);
final float endingVelocityX = mSwipeTracker.getXVelocity();
final float endingVelocityY = mSwipeTracker.getYVelocity();
boolean sendDownKey = false;
if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
sendDownKey = true;
} else {
swipeRight();
return true;
}
} else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
sendDownKey = true;
} else {
swipeLeft();
return true;
}
} else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
sendDownKey = true;
} else {
swipeUp();
return true;
}
} else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
sendDownKey = true;
} else {
swipeDown();
return true;
}
}
if (sendDownKey) {
detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
}
return false;
}
});
mGestureDetector.setIsLongpressEnabled(false);
}
}
use of android.view.GestureDetector in project NewPipe by TeamNewPipe.
the class PopupVideoPlayer method initPopup.
@SuppressLint({ "RtlHardcoded" })
private void initPopup() {
if (DEBUG)
Log.d(TAG, "initPopup() called");
View rootView = View.inflate(this, R.layout.player_popup, null);
viewHolder = new PopupViewHolder(rootView);
viewHolder.getPlaybackSeekBar().setOnSeekBarChangeListener(internalListener);
emVideoView = viewHolder.getVideoView();
emVideoView.setOnPreparedListener(internalListener);
emVideoView.setOnCompletionListener(internalListener);
emVideoView.setOnErrorListener(internalListener);
emVideoView.setOnSeekCompletionListener(internalListener);
windowLayoutParams = new WindowManager.LayoutParams((int) getMinimumVideoWidth(currentPopupHeight), (int) currentPopupHeight, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
MySimpleOnGestureListener listener = new MySimpleOnGestureListener();
gestureDetector = new GestureDetector(this, listener);
gestureDetector.setIsLongpressEnabled(false);
rootView.setOnTouchListener(listener);
updateScreenSize();
windowManager.addView(rootView, windowLayoutParams);
}
use of android.view.GestureDetector in project Reader by TheKeeperOfPie.
the class ActivityMain method inflateNavigationDrawer.
private void inflateNavigationDrawer() {
// TODO: Adhere to guidelines by making the increment 56dp on mobile and 64dp on tablet
float standardIncrement = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
float screenWidth = getResources().getDisplayMetrics().widthPixels;
float navigationWidth = screenWidth - UtilsTheme.getAttributeDimension(this, R.attr.actionBarSize, standardIncrement);
if (navigationWidth > standardIncrement * 6) {
navigationWidth = standardIncrement * 6;
}
layoutNavigation.getLayoutParams().width = (int) navigationWidth;
textAccountName.setTextColor(colorFilterPrimary.getColor());
textAccountInfo.setTextColor(colorFilterPrimary.getColor());
buttonAccounts.setColorFilter(colorFilterPrimary);
View.OnClickListener onClickListener = v -> setAccountsVisible(!accountsVisible);
textAccountName.setOnClickListener(onClickListener);
textAccountInfo.setOnClickListener(onClickListener);
buttonAccounts.setOnClickListener(onClickListener);
adapterAccounts = new AccountsAdapter(colorFilterPrimary.getColor(), this);
recyclerAccounts.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recyclerAccounts.setAdapter(adapterAccounts);
resetAccountList();
final GestureDetectorCompat gestureDetector = new GestureDetectorCompat(this, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
loadHeaderImage(true);
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
String permalink = sharedPreferences.getString(AppSettings.HEADER_PERMALINK, "");
if (!TextUtils.isEmpty(permalink)) {
Intent intentActivity = new Intent(ActivityMain.this, ActivityMain.class);
intentActivity.setAction(Intent.ACTION_VIEW);
intentActivity.setData(Uri.parse(Reddit.BASE_URL + permalink));
startActivity(intentActivity);
return true;
}
return super.onSingleTapConfirmed(e);
}
});
// Add an empty view to remove extra margin on top
viewNavigation.addHeaderView(new View(this));
viewNavigation.setNavigationItemSelectedListener(menuItem -> {
loadId = menuItem.getItemId();
layoutDrawer.closeDrawer(GravityCompat.START);
return true;
});
scrollHeaderVertical.setDispatchTouchListener((v, event) -> {
gestureDetector.onTouchEvent(event);
switch(MotionEventCompat.getActionMasked(event)) {
case MotionEvent.ACTION_DOWN:
layoutDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
layoutDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
break;
}
return false;
});
loadHeaderImage(false);
}
Aggregations