Example usage for android.view MotionEvent getActionMasked

List of usage examples for android.view MotionEvent getActionMasked

Introduction

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

Prototype

public final int getActionMasked() 

Source Link

Document

Return the masked action being performed, without pointer index information.

Usage

From source file:com.hippo.largeimageview.GestureRecognizer.java

public void onTouchEvent(MotionEvent event) {
    // If pointer count is more than 1, must be scale action
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_UP:
        mListener.onUp();// w  w w.j  a v a 2s  .  com
        break;
    case MotionEvent.ACTION_CANCEL:
        mListener.onCancel();
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        mScale = event.getPointerCount() > 1;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        mScale = (event.getPointerCount() - 1) > 1;
        break;
    }

    mGestureDetector.onTouchEvent(event);
    mScaleDetector.onTouchEvent(event);
}

From source file:org.mariotaku.twidere.fragment.support.AbsContentListViewFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final View view = getView();
    if (view == null)
        throw new AssertionError();
    final Context context = view.getContext();
    final boolean compact = Utils.isCompactCards(context);
    final int backgroundColor = ThemeUtils.getThemeBackgroundColor(context);
    final int colorRes = TwidereColorUtils.getContrastYIQ(backgroundColor,
            R.color.bg_refresh_progress_color_light, R.color.bg_refresh_progress_color_dark);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(colorRes);
    mAdapter = onCreateAdapter(context, compact);
    mListView.setOnTouchListener(new View.OnTouchListener() {
        @Override/* w  ww.j  ava2 s.c  om*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                updateRefreshProgressOffset();
            }
            return false;
        }
    });
    mListView.setAdapter(mAdapter);

}

From source file:com.android.calculator2.CalculatorPadViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean shouldIntercept = super.onInterceptTouchEvent(ev);

    // Only allow the current item to receive touch events.
    if (!shouldIntercept && ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
        final int x = (int) ev.getX() + getScrollX();
        final int y = (int) ev.getY() + getScrollY();

        final int childCount = getChildCount();
        for (int i = childCount - 1; i >= 0; --i) {
            final int childIndex = getChildDrawingOrder(childCount, i);
            final View child = getChildAt(childIndex);
            if (child.getVisibility() == View.VISIBLE && x >= child.getLeft() && x < child.getRight()
                    && y >= child.getTop() && y < child.getBottom()) {
                shouldIntercept = (childIndex != getCurrentItem());
                break;
            }/*w  w w . j a  v  a 2 s  .  com*/
        }
    }

    return shouldIntercept;
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

public boolean handleRootTouchEvent(MotionEvent event) {
    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN || mSlideState == SlideState.SkipThisRound) {
        return false;
    }/*  ww w  .  jav  a2 s  . co  m*/

    final float x = event.getRawX();
    final float y = event.getRawY();
    final float horzOffset = Math.abs(x - mLastX);
    final float vertOffset = Math.abs(y - mLastY);

    if (action == MotionEvent.ACTION_MOVE && handleTouchMove(x, y, horzOffset, vertOffset)) {
        return true;
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        int width = getMeasuredWidth();
        long timeOffset = System.currentTimeMillis() - mDownTimestamp;
        mSlideState = SlideState.None;

        if (horzOffset > width / 2 || (timeOffset <= 600 && horzOffset > width / 6)) {
            continueAnimation(horzOffset, width);
        } else {
            updateSlideOffset(0);
        }

        return true;
    }

    return false;
}

From source file:com.finchuk.clock2.alarms.ui.BaseAlarmViewHolder.java

@OnTouch(R.id.on_off_switch)
boolean slide(MotionEvent event) {
    if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
        mSwitch.setPressed(true); // needed so the OnCheckedChange event calls through
    }/*from   ww w. java 2  s .  c o m*/
    return false; // proceed as usual
}

From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (onPageSelectedListener != null) {
        switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
            int position = hitTest(event.getX());
            if (position >= 0) {
                onPageSelectedListener.onPageStripSelected(position);
            }//from ww w .  j  a  v  a2 s. c  om
            return true;
        }
    }
    return super.onTouchEvent(event);
}

From source file:org.mariotaku.twidere.fragment.AbsContentListViewFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final View view = getView();
    assert view != null;
    final Context context = view.getContext();
    final int backgroundColor = ThemeUtils.getThemeBackgroundColor(context);
    final int colorRes = TwidereColorUtils.getContrastYIQ(backgroundColor,
            R.color.bg_refresh_progress_color_light, R.color.bg_refresh_progress_color_dark);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(colorRes);
    mAdapter = onCreateAdapter(context);
    mListView.setOnTouchListener(new View.OnTouchListener() {
        @Override//from  ww w . j av a 2 s .  c  o m
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                updateRefreshProgressOffset();
            }
            return false;
        }
    });
    mListView.setAdapter(mAdapter);
    mListView.setClipToPadding(false);
    mScrollHandler = new ListViewScrollHandler(this, new ListViewScrollHandler.ListViewCallback(mListView));
    mScrollHandler.setTouchSlop(ViewConfiguration.get(context).getScaledTouchSlop());
    mScrollHandler.setOnScrollListener(this);
}

From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mOnPageSelectedListener != null) {
        switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
            int position = hitTest(event.getX());
            if (position >= 0) {
                mOnPageSelectedListener.onPageStripSelected(position);
            }/*  w w w  .j a va  2 s .  c om*/
            return true;
        }
    }
    return super.onTouchEvent(event);
}

From source file:me.wizos.loread.view.webview.NestedScrollWebView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int actionMasked = ev.getActionMasked();

    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN:
        mIsBeingDragged = false;/*from  w w w. j  a va2s  .  com*/

        // Remember where the motion event started
        mLastMotionY = (int) ev.getY();
        //                downY = (int) ev.getY();

        mActivePointerId = ev.getPointerId(0);
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;

    case MotionEvent.ACTION_MOVE:
        //                KLog.e("");
        final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
        if (activePointerIndex == -1) {
            break;
        }
        //                if( !onlyVerticalMove(ev) ){
        //                    break;
        //                }

        final int y = (int) ev.getY(activePointerIndex);
        int deltaY = mLastMotionY - y;
        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
        }
        // Scroll to follow the motion event
        mLastMotionY = y - mScrollOffset[1];

        final int oldY = getScrollY();
        final int scrolledDeltaY = Math.max(0, oldY + deltaY) - oldY;
        final int unconsumedY = deltaY - scrolledDeltaY;
        if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) {
            mLastMotionY -= mScrollOffset[1];
        }
        //                KLog.e("?");
        break;
    case MotionEvent.ACTION_UP:
        mActivePointerId = INVALID_POINTER;
        endDrag();
        break;
    case MotionEvent.ACTION_CANCEL:
        mActivePointerId = INVALID_POINTER;
        endDrag();
        break;
    case MotionEvent.ACTION_POINTER_DOWN: {
        final int index = ev.getActionIndex();
        mLastMotionY = (int) ev.getY(index);
        mActivePointerId = ev.getPointerId(index);
        break;
    }
    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId));
        break;
    default:
        break;
    }
    return super.onTouchEvent(ev);
}

From source file:com.google.android.apps.dashclock.configuration.ConfigureAppearanceFragment.java

private void configureStylePager(final ViewPager pager, final PagerPositionStrip positionStrip,
        final String[] styleNames, final String styleComponent, final int gravity, final String preference) {
    String currentStyleName = mCurrentStyleNames.get(preference);

    final LayoutInflater inflater = getActivity().getLayoutInflater();
    pager.setAdapter(new PagerAdapter() {
        @Override/*from   w ww.  java  2 s . c  om*/
        public int getCount() {
            return styleNames.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object o) {
            return view == o;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            FrameLayout wrapper = new FrameLayout(getActivity());
            ViewPager.LayoutParams wrapperLp = new ViewPager.LayoutParams();
            wrapper.setLayoutParams(wrapperLp);
            String styleName = styleNames[position];
            if (styleName.contains("analog")) {
                styleName += "_white";
            }
            View v = inflater.inflate(
                    AppearanceConfig.getLayoutByStyleName(getActivity(), styleComponent, styleName), container,
                    false);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.gravity = gravity;
            v.setLayoutParams(lp);
            wrapper.addView(v);
            container.addView(wrapper);
            return wrapper;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });

    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            mCurrentStyleNames.put(preference, styleNames[position]);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            positionStrip.setPosition(position + positionOffset);
        }
    });

    positionStrip.setPageCount(styleNames.length);

    pager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                showPositionStrips(true, -1);
                break;

            case MotionEvent.ACTION_UP:
                showPositionStrips(false, AUTO_HIDE_DELAY_MILLIS);
                break;
            }
            return false;
        }
    });

    for (int i = 0; i < styleNames.length; i++) {
        if (currentStyleName.equals(styleNames[i])) {
            pager.setCurrentItem(i);
            positionStrip.setPosition(i);
            break;
        }
    }
}