Example usage for android.view MotionEvent ACTION_DOWN

List of usage examples for android.view MotionEvent ACTION_DOWN

Introduction

In this page you can find the example usage for android.view MotionEvent ACTION_DOWN.

Prototype

int ACTION_DOWN

To view the source code for android.view MotionEvent ACTION_DOWN.

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has started, the motion contains the initial starting location.

Usage

From source file:gov.sfmta.sfpark.AnnotationsOverlay.java

@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
    int fingers = e.getPointerCount();
    int action = e.getAction();

    Log.v(TAG, "onTouchEvent " + action);

    if (action == MotionEvent.ACTION_DOWN) {
        isPinch = false;//  www . java2 s .  c  o m
    }

    if (action == MotionEvent.ACTION_MOVE && fingers == 2) {
        isPinch = true;
    }

    if (popupView != null) {
        MainScreenActivity.mapView.removeView(popupView);
        popupView = null;
    }

    return super.onTouchEvent(e, mapView);
}

From source file:com.android.ex.photo.PhotoViewPager.java

/**
 * {@inheritDoc}/*from   w  w  w . j a va2  s . co m*/
 * <p>
 * We intercept touch event intercepts so we can prevent switching views when the
 * current view is internally scrollable.
 */
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY)
            : InterceptType.NONE;
    final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT);
    final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT);

    // Only check ability to page if we can't scroll in one / both directions
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mActivePointerId = INVALID_POINTER;
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        if (ignoreScrollLeft || ignoreScrollRight) {
            final int activePointerId = mActivePointerId;
            if (activePointerId == INVALID_POINTER) {
                // If we don't have a valid id, the touch down wasn't on content.
                break;
            }

            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
            final float x = MotionEventCompat.getX(ev, pointerIndex);

            if (ignoreScrollLeft && ignoreScrollRight) {
                mLastMotionX = x;
                return false;
            } else if (ignoreScrollLeft && (x > mLastMotionX)) {
                mLastMotionX = x;
                return false;
            } else if (ignoreScrollRight && (x < mLastMotionX)) {
                mLastMotionX = x;
                return false;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        mLastMotionX = ev.getX();
        // Use the raw x/y as the children can be located anywhere and there isn't a
        // single offset that would be meaningful
        mActivatedX = ev.getRawX();
        mActivatedY = ev.getRawY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP: {
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            // Our active pointer going up; select a new active pointer
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        break;
    }
    }

    return super.onInterceptTouchEvent(ev);
}

From source file:com.example.castCambot.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));

    // When the user clicks on the button, use Android voice recognition to
    // get text// ww w  .  j  a v  a  2  s .c o m

    Button voiceButton = (Button) findViewById(R.id.voiceButton);
    voiceButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startVoiceRecognitionActivity();
        }
    });

    Button buttonOK = (Button) findViewById(R.id.buttonOK);
    buttonOK.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //startVoiceRecognitionActivity();
            EditText editText1 = (EditText) findViewById(R.id.editText1);
            cambotIP = editText1.getText().toString();
            Button buttonOK = (Button) findViewById(R.id.buttonOK);
            buttonOK.setVisibility(View.INVISIBLE);

            /*
            WebView   mWebView = (WebView) findViewById(R.id.webView1);
            mWebView.getSettings().setJavaScriptEnabled(true);     
            mWebView.getSettings().setLoadWithOverviewMode(true);
            mWebView.getSettings().setUseWideViewPort(true);     
            //mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
            mWebView.loadUrl("file:///android_asset/cambot.html");
            */
        }
    });

    Button button2 = (Button) findViewById(R.id.button2);
    button2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("go_forward");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button4 = (Button) findViewById(R.id.button4);
    button4.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("turn_left");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button6 = (Button) findViewById(R.id.button6);
    button6.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("turn_right");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button8 = (Button) findViewById(R.id.button8);
    button8.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("go_backward");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

private boolean onTouchEventUseViewRotation(MotionEvent event) {
    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        attemptClaimDrag(true);/*www  . j av  a2 s  .  c  o  m*/
        break;

    case MotionEvent.ACTION_UP:
        attemptClaimDrag(false);
        break;
    }

    return super.onTouchEvent(event);
}

From source file:com.aako.zjp2p.widget.superrecycler.swipe.SwipeDismissRecyclerViewTouchListener.java

@SuppressLint("AndroidLintClickableViewAccessibility")
@Override/* w w w .j a  v  a 2  s . c  o  m*/
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }

    switch (MotionEventCompat.getActionMasked(motionEvent)) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            return false;
        }

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mRecyclerView.getChildCount();
        int[] listViewCoords = new int[2];
        mRecyclerView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;
        for (int i = 0; i < childCount; i++) {
            child = mRecyclerView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                mDownView = child;
                break;
            }
        }

        if (mDownView != null) {
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildPosition(mDownView);
            if (mCallbacks.canDismiss(mDownPosition)) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        return false;
    }

    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }

        if (mDownView != null && mSwiping) {
            // cancel
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss && mDownPosition != INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            performDismiss(downView, downPosition);
                        }
                    });
        } else {
            // cancel
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mPaused) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mRecyclerView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                    .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
            mRecyclerView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
        }

        if (mSwiping) {
            setTranslationX(mDownView, deltaX - mSwipingSlop);
            setAlpha(mDownView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:com.adamin.superrecyclerview.superrecycer.swipe.SwipeDismissRecyclerViewTouchListener.java

@SuppressLint("AndroidLintClickableViewAccessibility")
@Override//from ww  w.  j a  v a 2 s.  c  o m
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }

    switch (MotionEventCompat.getActionMasked(motionEvent)) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            return false;
        }

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mRecyclerView.getChildCount();
        int[] listViewCoords = new int[2];
        mRecyclerView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;
        for (int i = 0; i < childCount; i++) {
            child = mRecyclerView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                mDownView = child;
                break;
            }
        }

        if (mDownView != null) {
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildPosition(mDownView);
            if (mCallbacks.canDismiss(mDownPosition)) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        return false;
    }

    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }

        if (mDownView != null && mSwiping) {
            // cancel
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss && mDownPosition != INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime)
                    .setListener(new com.nineoldandroids.animation.AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(com.nineoldandroids.animation.Animator animation) {
                            super.onAnimationEnd(animation);
                            performDismiss(downView, downPosition);
                        }
                    });
        } else {
            // cancel
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mPaused) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mRecyclerView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                    .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
            mRecyclerView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
        }

        if (mSwiping) {
            setTranslationX(mDownView, deltaX - mSwipingSlop);
            setAlpha(mDownView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java

@SuppressLint({ "NewApi", "SimpleDateFormat" })
public VerticalSingleItemView(final DataMgr dataMgr, final Context context, final String uid, final View menu,
        final VerticalItemViewCtrl itemViewCtrl) {
    this.dataMgr = dataMgr;
    this.context = context;
    this.item = dataMgr.getItemByUid(uid, ITEM_PROJECTION);
    this.fontSize = new SettingFontSize(dataMgr).getData();
    this.theme = new SettingTheme(dataMgr).getData();
    this.showTop = false;
    this.showBottom = false;
    this.menu = menu;
    this.itemViewCtrl = itemViewCtrl;
    this.imageClickTime = 0;

    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.view = inflater.inflate(R.layout.single_item_view, null);
    // Disable hardware acceleration on Android 3.0-4.1 devices.
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
            && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }//from  w  w  w .j  a  v a  2  s .com

    lastItemView = view.findViewById(R.id.LastItemView);
    nextItemView = view.findViewById(R.id.NextItemView);
    itemScrollView = (OverScrollView) view.findViewById(R.id.ItemScrollView);
    itemScrollView.setTopScrollView(lastItemView);
    itemScrollView.setBottomScrollView(nextItemView);
    itemScrollView.setOnScrollChangeListener(this);
    itemScrollView.setOnTouchListener(this);

    final View btnShowOriginal = view.findViewById(R.id.BtnShowOriginal);
    btnShowOriginal.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            boolean ret = false;
            final TextView txt = (TextView) view.findViewById(R.id.BtnText);
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                txt.setTextColor(0xFF787878);
                ret = true;
                break;
            case MotionEvent.ACTION_MOVE:
                ret = true;
                break;
            case MotionEvent.ACTION_CANCEL:
                txt.setTextColor(0xBB787878);
                ret = false;
                break;
            case MotionEvent.ACTION_UP:
                txt.setTextColor(0xBB787878);
                final SettingBrowserChoice setting = new SettingBrowserChoice(dataMgr);
                if (setting.getData() == SettingBrowserChoice.BROWSER_CHOICE_EXTERNAL) {
                    final Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setData(Uri.parse(item.getHref()));
                    context.startActivity(intent);
                } else if (VerticalSingleItemView.this.listener != null) {
                    VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), false);
                }
                break;
            default:
            }
            return ret;
        }
    });

    final View btnShowMobilized = view.findViewById(R.id.BtnShowMobilized);
    btnShowMobilized.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            boolean ret = false;
            final TextView txt = (TextView) view.findViewById(R.id.BtnText);
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                txt.setTextColor(0xFF787878);
                ret = true;
                break;
            case MotionEvent.ACTION_MOVE:
                ret = true;
                break;
            case MotionEvent.ACTION_CANCEL:
                txt.setTextColor(0xBB787878);
                ret = false;
                break;
            case MotionEvent.ACTION_UP:
                txt.setTextColor(0xBB787878);
                if (VerticalSingleItemView.this.listener != null) {
                    VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), true);
                }
                ret = true;
                break;
            default:
            }
            return ret;
        }
    });

    {
        final ListItemItem lastItem = itemViewCtrl.getLastItem(item.getUid());
        final TextView txt = (TextView) lastItemView.findViewById(R.id.LastItemTitle);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
        if (lastItem == null) {
            lastUid = null;
            menu.findViewById(R.id.BtnPrevious).setEnabled(false);
            final ImageView img = (ImageView) lastItemView.findViewById(R.id.LastItemArrow);
            img.setImageResource(R.drawable.no_more_circle);
            txt.setText(R.string.TxtNoPreviousItem);
        } else {
            lastUid = lastItem.getId();
            final View btnLast = menu.findViewById(R.id.BtnPrevious);
            btnLast.setEnabled(true);
            btnLast.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View view) {
                    if (listener != null) {
                        listener.showLastItem();
                    }
                }
            });
            txt.setText(lastItem.getTitle());
        }
    }

    {
        final ListItemItem nextItem = itemViewCtrl.getNextItem(item.getUid());
        final TextView txt = (TextView) nextItemView.findViewById(R.id.NextItemTitle);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
        if (nextItem == null) {
            nextUid = null;
            menu.findViewById(R.id.BtnNext).setEnabled(false);
            final ImageView img = (ImageView) nextItemView.findViewById(R.id.NextItemArrow);
            img.setImageResource(R.drawable.no_more_circle);
            txt.setText(R.string.TxtNoNextItem);
        } else {
            nextUid = nextItem.getId();
            final View btnNext = menu.findViewById(R.id.BtnNext);
            btnNext.setEnabled(true);
            btnNext.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View view) {
                    if (listener != null) {
                        listener.showNextItem();
                    }
                }
            });
            txt.setText(nextItem.getTitle());
        }
    }

    final TextView title = (TextView) view.findViewById(R.id.ItemTitle);
    title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 3);
    title.setText(item.getTitle());
    final TextView info = (TextView) view.findViewById(R.id.ItemInfo);
    info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5);
    final StringBuilder infoText = new StringBuilder();
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    sdf.setTimeZone(TimeZone.getDefault());
    infoText.append(sdf.format(Utils.timestampToDate(item.getTimestamp())));
    if (item.getAuthor() != null && item.getAuthor().length() > 0) {
        infoText.append(" | By ");
        infoText.append(item.getAuthor());
    }
    if (item.getSourceTitle() != null && item.getSourceTitle().length() > 0) {
        infoText.append(" (");
        infoText.append(item.getSourceTitle());
        infoText.append(")");
    }
    info.setText(infoText);

    webView = (WebView) view.findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setBackgroundColor(context.getResources()
            .getColor(theme == SettingTheme.THEME_NORMAL ? R.color.NormalBackground : R.color.DarkBackground));
    webView.setFocusable(false);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            if (VerticalSingleItemView.this.imageClickTime > System.currentTimeMillis() - 1000) {
                return true;
            }
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse(url));
            context.startActivity(intent);
            return true;
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(final WebView view, final String url, final String message,
                final JsResult result) {
            if (VerticalSingleItemView.this.listener != null) {
                if (message.endsWith(".erss")) {
                    VerticalSingleItemView.this.listener
                            .onImageViewRequired(item.getStoragePath() + "/" + message);
                } else {
                    VerticalSingleItemView.this.listener.onImageViewRequired(message);
                }
            }
            VerticalSingleItemView.this.imageClickTime = System.currentTimeMillis();
            result.cancel();
            return true;
        }
    });

    updateButtonStar();
    updateButtonSharing();
    updateButtonOpenLink();

    if (!item.getState().isRead()) {
        dataMgr.markItemAsReadWithTransactionByUid(uid);
        NetworkMgr.getInstance().startImmediateItemStateSyncing();
    }
}

From source file:cn.meiqu.baseproject.view.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }//from   w w w  .j a  v  a  2 s.  com

    switch (MotionEventCompat.getActionMasked(motionEvent)) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            return false;
        }

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mRecyclerView.getChildCount();
        int[] listViewCoords = new int[2];
        mRecyclerView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;
        for (int i = 0; i < childCount; i++) {
            child = mRecyclerView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                mDownView = child;
                break;
            }
        }

        if (mDownView != null) {
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildPosition(mDownView);
            if (mCallbacks.canDismiss(mDownPosition)) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        return false;
    }

    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }

        if (mDownView != null && mSwiping) {
            // cancel
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss && mDownPosition != INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            performDismiss(downView, downPosition);
                        }
                    });
        } else {
            // cancel
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mPaused) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mRecyclerView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                    .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
            mRecyclerView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
        }

        if (mSwiping) {
            setTranslationX(mDownView, deltaX - mSwipingSlop);
            setAlpha(mDownView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = ev.getActionMasked();

    if (canChildScrollUp()) {
        // Fail fast if we're not in a state where a swipe is possible
        return super.onInterceptTouchEvent(ev);
    }//from   www.jav a  2s.c  om

    if (action == MotionEvent.ACTION_DOWN) {
        mVelocityTracker.clear();
    }

    mVelocityTracker.addMovement(ev);

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialTouchX = x;
        mInitialTouchY = mLastTouchY = y;
        mOpenOnClick = isListChildUnderClipped(x, y) && mCollapsibleHeight > 0;
    }
        break;

    case MotionEvent.ACTION_MOVE: {
        final float x = ev.getX();
        final float y = ev.getY();
        final float dy = y - mInitialTouchY;
        boolean isSlidingUp = Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null && mCollapseOffset > 0;
        boolean isSlidingDown = mCollapseOffset == 0 && dy > mTouchSlop;
        if (isSlidingUp || isSlidingDown) {
            mActivePointerId = ev.getPointerId(0);
            mIsDragging = true;
            mLastTouchY = Math.max(mLastTouchY - mTouchSlop,
                    Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop));
        }
    }
        break;

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
    }
        break;

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        resetTouch();
    }
        break;
    }

    if (mIsDragging) {
        mScroller.abortAnimation();
    }
    return mIsDragging || mOpenOnClick;
}

From source file:com.appsummary.luoxf.myappsummary.recyclerView.fastscroll.Views.FastScroller.java

/**
 * Handles the touch event and determines whether to show the fast scroller (or updates it if
 * it is already showing)./*from  www. jav  a 2s  .c om*/
 */
public void handleTouchEvent(MotionEvent ev, int downX, int downY, int lastY) {
    ViewConfiguration config = ViewConfiguration.get(mRecyclerView.getContext());

    int action = ev.getAction();
    int y = (int) ev.getY();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (isNearPoint(downX, downY)) {
            mTouchOffset = downY - mThumbPosition.y;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        // Check if we should start scrolling
        if (!mIsDragging && isNearPoint(downX, downY) && Math.abs(y - downY) > config.getScaledTouchSlop()) {
            mRecyclerView.getParent().requestDisallowInterceptTouchEvent(true);
            mIsDragging = true;
            mTouchOffset += (lastY - downY);
            mPopup.animateVisibility(true);
        }
        if (mIsDragging) {
            // Update the fastscroller section name at this touch position
            int top = 0;
            int bottom = mRecyclerView.getHeight() - mThumbHeight;
            float boundedY = (float) Math.max(top, Math.min(bottom, y - mTouchOffset));
            String sectionName = mRecyclerView.scrollToPositionAtProgress((boundedY - top) / (bottom - top));
            mPopup.setSectionName(sectionName);
            mPopup.animateVisibility(!sectionName.isEmpty());
            mRecyclerView.invalidate(mPopup.updateFastScrollerBounds(mRecyclerView, mThumbPosition.y));
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mTouchOffset = 0;
        if (mIsDragging) {
            mIsDragging = false;
            mPopup.animateVisibility(false);
        }
        break;
    }
}