Search in sources :

Example 91 with MotionEvent

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);
    }
}
Also used : ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) DataSetObserver(android.database.DataSetObserver) MotionEvent(android.view.MotionEvent)

Example 92 with MotionEvent

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);
}
Also used : TypedArray(android.content.res.TypedArray) Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 93 with MotionEvent

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;
        }
    }
}
Also used : MotionEvent(android.view.MotionEvent)

Example 94 with MotionEvent

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;
}
Also used : SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent)

Example 95 with MotionEvent

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);
}
Also used : View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) MotionEvent(android.view.MotionEvent) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

MotionEvent (android.view.MotionEvent)717 View (android.view.View)255 TextView (android.widget.TextView)113 ImageView (android.widget.ImageView)91 Point (android.graphics.Point)63 OnTouchListener (android.view.View.OnTouchListener)48 GestureDetector (android.view.GestureDetector)47 Paint (android.graphics.Paint)40 ViewGroup (android.view.ViewGroup)36 Test (org.junit.Test)35 AdapterView (android.widget.AdapterView)34 RecyclerView (android.support.v7.widget.RecyclerView)33 ListView (android.widget.ListView)33 SuppressLint (android.annotation.SuppressLint)31 Intent (android.content.Intent)30 Instrumentation (android.app.Instrumentation)27 AbsListView (android.widget.AbsListView)27 OnClickListener (android.view.View.OnClickListener)24 Rect (android.graphics.Rect)22 Handler (android.os.Handler)20