Search in sources :

Example 36 with MotionEvent

use of android.view.MotionEvent in project superCleanMaster by joyoyao.

the class RippleView method init.

@SuppressLint("Recycle")
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(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 boolean onSingleTapConfirmed(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });
    this.setDrawingCacheEnabled(true);
}
Also used : TypedArray(android.content.res.TypedArray) Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent) SuppressLint(android.annotation.SuppressLint)

Example 37 with MotionEvent

use of android.view.MotionEvent in project QLibrary by DragonsQC.

the class QLazyViewPager method fakeDragBy.

/**
     * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
     *
     * @param xOffset Offset in pixels to drag by.
     * @see #beginFakeDrag()
     * @see #endFakeDrag()
     */
public void fakeDragBy(float xOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }
    mLastMotionX += xOffset;
    float scrollX = getScrollX() - xOffset;
    final int width = getWidth();
    final int widthWithMargin = width + mPageMargin;
    final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin);
    final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin;
    if (scrollX < leftBound) {
        scrollX = leftBound;
    } else if (scrollX > rightBound) {
        scrollX = rightBound;
    }
    // Don't lose the rounded component
    mLastMotionX += scrollX - (int) scrollX;
    scrollTo((int) scrollX, getScrollY());
    if (mOnPageChangeListener != null) {
        final int position = (int) scrollX / widthWithMargin;
        final int positionOffsetPixels = (int) scrollX % widthWithMargin;
        final float positionOffset = (float) positionOffsetPixels / widthWithMargin;
        mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
    }
    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}
Also used : MotionEvent(android.view.MotionEvent)

Example 38 with MotionEvent

use of android.view.MotionEvent in project XobotOS by xamarin.

the class Switch method cancelSuperTouch.

private void cancelSuperTouch(MotionEvent ev) {
    MotionEvent cancel = MotionEvent.obtain(ev);
    cancel.setAction(MotionEvent.ACTION_CANCEL);
    super.onTouchEvent(cancel);
    cancel.recycle();
}
Also used : MotionEvent(android.view.MotionEvent)

Example 39 with MotionEvent

use of android.view.MotionEvent in project android_frameworks_base by ResurrectionRemix.

the class StatusBarWindowView method onInterceptTouchEvent.

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean intercept = false;
    if (mDoubleTapToSleepEnabled && ev.getY() < mStatusBarHeaderHeight) {
        if (DEBUG)
            Log.w(TAG, "logging double tap gesture");
        mDoubleTapGesture.onTouchEvent(ev);
    }
    if (mNotificationPanel.isFullyExpanded() && mStackScrollLayout.getVisibility() == View.VISIBLE && mService.getBarState() == StatusBarState.KEYGUARD && !mService.isBouncerShowing()) {
        intercept = mDragDownHelper.onInterceptTouchEvent(ev);
        // wake up on a touch down event, if dozing
        if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
            mService.wakeUpIfDozing(ev.getEventTime(), ev);
        }
    }
    if (!intercept) {
        super.onInterceptTouchEvent(ev);
    }
    if (intercept) {
        MotionEvent cancellation = MotionEvent.obtain(ev);
        cancellation.setAction(MotionEvent.ACTION_CANCEL);
        mStackScrollLayout.onInterceptTouchEvent(cancellation);
        mNotificationPanel.onInterceptTouchEvent(cancellation);
        cancellation.recycle();
    }
    return intercept;
}
Also used : MotionEvent(android.view.MotionEvent)

Example 40 with MotionEvent

use of android.view.MotionEvent in project android_frameworks_base by ResurrectionRemix.

the class ZoomButtonsController method onTouch.

/**
     * @hide The ZoomButtonsController implements the OnTouchListener, but this
     *       does not need to be shown in its public API.
     */
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    if (event.getPointerCount() > 1) {
        // ZoomButtonsController doesn't handle mutitouch. Give up control.
        return false;
    }
    if (mReleaseTouchListenerOnUp) {
        // The controls were dismissed but we need to throw away all events until the up
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            mOwnerView.setOnTouchListener(null);
            setTouchTargetView(null);
            mReleaseTouchListenerOnUp = false;
        }
        // Eat this event
        return true;
    }
    dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT);
    View targetView = mTouchTargetView;
    switch(action) {
        case MotionEvent.ACTION_DOWN:
            targetView = findViewForTouch((int) event.getRawX(), (int) event.getRawY());
            setTouchTargetView(targetView);
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            setTouchTargetView(null);
            break;
    }
    if (targetView != null) {
        // The upperleft corner of the target view in raw coordinates
        int targetViewRawX = mContainerRawLocation[0] + mTouchTargetWindowLocation[0];
        int targetViewRawY = mContainerRawLocation[1] + mTouchTargetWindowLocation[1];
        MotionEvent containerEvent = MotionEvent.obtain(event);
        // Convert the motion event into the target view's coordinates (from
        // owner view's coordinates)
        containerEvent.offsetLocation(mOwnerViewRawLocation[0] - targetViewRawX, mOwnerViewRawLocation[1] - targetViewRawY);
        /* Disallow negative coordinates (which can occur due to
             * ZOOM_CONTROLS_TOUCH_PADDING) */
        // These are floats because we need to potentially offset away this exact amount
        float containerX = containerEvent.getX();
        float containerY = containerEvent.getY();
        if (containerX < 0 && containerX > -ZOOM_CONTROLS_TOUCH_PADDING) {
            containerEvent.offsetLocation(-containerX, 0);
        }
        if (containerY < 0 && containerY > -ZOOM_CONTROLS_TOUCH_PADDING) {
            containerEvent.offsetLocation(0, -containerY);
        }
        boolean retValue = targetView.dispatchTouchEvent(containerEvent);
        containerEvent.recycle();
        return retValue;
    } else {
        return false;
    }
}
Also used : View(android.view.View) MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)1088 View (android.view.View)497 TextView (android.widget.TextView)264 ImageView (android.widget.ImageView)190 GestureDetector (android.view.GestureDetector)95 Point (android.graphics.Point)81 AdapterView (android.widget.AdapterView)80 ViewGroup (android.view.ViewGroup)75 Paint (android.graphics.Paint)72 ListView (android.widget.ListView)70 SuppressLint (android.annotation.SuppressLint)69 OnTouchListener (android.view.View.OnTouchListener)69 Intent (android.content.Intent)68 RecyclerView (android.support.v7.widget.RecyclerView)53 Test (org.junit.Test)47 ScrollView (android.widget.ScrollView)46 Handler (android.os.Handler)43 AbsListView (android.widget.AbsListView)42 WindowManager (android.view.WindowManager)41 LinearLayout (android.widget.LinearLayout)40