use of android.view.MotionEvent in project MaterialList by dexafree.
the class ListCardProvider method render.
@Override
public void render(@NonNull final View view, @NonNull final Card card) {
super.render(view, card);
if (getAdapter() != null) {
final ListView listView = (ListView) view.findViewById(R.id.listView);
listView.setScrollbarFadingEnabled(true);
listView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// That the gesture detection is correct
return false;
}
});
listView.setAdapter(getAdapter());
listView.getAdapter().registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
super.onChanged();
calculateListHeight(listView);
}
});
listView.setOnItemClickListener(getOnItemClickListener());
calculateListHeight(listView);
}
}
use of android.view.MotionEvent in project photo-picker-plus-android by chute.
the class RippleView method init.
private void init(final Context context, final AttributeSet attrs) {
if (isInEditMode())
return;
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView);
rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, getResources().getColor(android.R.color.white));
rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0);
hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false);
isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false);
DURATION = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, DURATION);
FRAME_RATE = typedArray.getInteger(R.styleable.RippleView_rv_framerate, FRAME_RATE);
PAINT_ALPHA = typedArray.getInteger(R.styleable.RippleView_rv_alpha, PAINT_ALPHA);
ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0);
canvasHandler = new Handler();
zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f);
zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL);
paint.setColor(rippleColor);
paint.setAlpha(PAINT_ALPHA);
this.setWillNotDraw(false);
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public void onLongPress(MotionEvent event) {
super.onLongPress(event);
animateRipple(event);
sendClickEvent(true);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
this.setDrawingCacheEnabled(true);
this.setClickable(true);
}
use of android.view.MotionEvent in project Launcher3 by chislon.
the class Folder method onDragOver.
public void onDragOver(DragObject d) {
final DragView dragView = d.dragView;
final int scrollOffset = mScrollView.getScrollY();
final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
r[0] -= getPaddingLeft();
r[1] -= getPaddingTop();
final long downTime = SystemClock.uptimeMillis();
final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);
if (!mAutoScrollHelper.isEnabled()) {
mAutoScrollHelper.setEnabled(true);
}
final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
translatedEv.recycle();
if (handled) {
mReorderAlarm.cancelAlarm();
} else {
mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
if (isLayoutRtl()) {
mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
}
if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
mReorderAlarm.cancelAlarm();
mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
mReorderAlarm.setAlarm(REORDER_DELAY);
mPreviousTargetCell[0] = mTargetCell[0];
mPreviousTargetCell[1] = mTargetCell[1];
mDragMode = DRAG_MODE_REORDER;
} else {
mDragMode = DRAG_MODE_NONE;
}
}
}
use of android.view.MotionEvent in project StickyListHeaders by emilsjolander.
the class StickyListHeadersListView method dispatchTouchEvent.
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int action = ev.getAction() & MotionEvent.ACTION_MASK;
if (action == MotionEvent.ACTION_DOWN) {
mDownY = ev.getY();
mHeaderOwnsTouch = mHeader != null && mDownY <= mHeader.getHeight() + mHeaderOffset;
}
boolean handled;
if (mHeaderOwnsTouch) {
if (mHeader != null && Math.abs(mDownY - ev.getY()) <= mTouchSlop) {
handled = mHeader.dispatchTouchEvent(ev);
} else {
if (mHeader != null) {
MotionEvent cancelEvent = MotionEvent.obtain(ev);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
mHeader.dispatchTouchEvent(cancelEvent);
cancelEvent.recycle();
}
MotionEvent downEvent = MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), ev.getX(), mDownY, ev.getMetaState());
downEvent.setAction(MotionEvent.ACTION_DOWN);
handled = mList.dispatchTouchEvent(downEvent);
downEvent.recycle();
mHeaderOwnsTouch = false;
}
} else {
handled = mList.dispatchTouchEvent(ev);
}
return handled;
}
use of android.view.MotionEvent in project materialistic by hidroh.
the class ItemActivityTest method testNavButtonDrag.
@Test
public void testNavButtonDrag() {
PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_comments)).putBoolean(activity.getString(R.string.pref_navigation), true).apply();
startWithIntent();
View navButton = activity.findViewById(R.id.navigation_button);
assertThat(navButton).isVisible();
getDetector(navButton).getListener().onLongPress(mock(MotionEvent.class));
assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.hint_drag));
MotionEvent motionEvent = mock(MotionEvent.class);
when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(motionEvent.getRawX()).thenReturn(1f);
when(motionEvent.getRawY()).thenReturn(1f);
shadowOf(navButton).getOnTouchListener().onTouch(navButton, motionEvent);
motionEvent = mock(MotionEvent.class);
when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_UP);
shadowOf(navButton).getOnTouchListener().onTouch(navButton, motionEvent);
assertThat(navButton).hasX(1f).hasY(1f);
}
Aggregations