Example usage for android.view MotionEvent ACTION_MASK

List of usage examples for android.view MotionEvent ACTION_MASK

Introduction

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

Prototype

int ACTION_MASK

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

Click Source Link

Document

Bit mask of the parts of the action code that are the action itself.

Usage

From source file:ch.fhnw.comgr.GLES3Activity.java

@Override
public boolean onTouch(View v, final MotionEvent event) {
    if (event == null) {
        Log.i(TAG, "onTouch: null event");
        return false;
    }/*from w  w w  . j a v a2  s . c  o  m*/

    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;

    try {
        if (actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN)
            return handleTouchDown(event);
        else if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP)
            return handleTouchUp(event);
        else if (actionCode == MotionEvent.ACTION_MOVE)
            return handleTouchMove(event);
        else
            Log.i(TAG, "Unhandeled Event: " + actionCode);
    } catch (Exception ex) {
        Log.i(TAG, "onTouch (Exception: " + actionCode);
    }

    return false;
}

From source file:com.putao.widget.touchgallery.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);
        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }//from   ww w  .j a va2s .  c  o  m
        } else {
            super.onInterceptTouchEvent(event);
        }
    }
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }
    float[] difference = handleMotionEvent(event);
    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

From source file:com.touchgallery.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }/*  w ww .jav  a 2 s .  c  o m*/
        } else {
            super.onInterceptTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        try {
            return super.onInterceptTouchEvent(event);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }/*from ww w. java2  s  .  co m*/
        } else {
            super.onInterceptTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

From source file:com.tsoliveira.android.listeners.DragDropTouchListener.java

@Override
public void onTouchEvent(RecyclerView view, MotionEvent event) {
    if (!dragging)
        return;//from ww  w .java2s.c  om

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_MOVE:
        move(event);
        break;

    case MotionEvent.ACTION_UP:
        up(event);
        break;

    case MotionEvent.ACTION_CANCEL:
        cancel(event);
        break;

    }
}

From source file:com.example.manan.enhancedurdureader.EpubReader.BookView.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*from   w ww  . j a va  2  s . c  o m*/
public void onActivityCreated(Bundle saved) {
    super.onActivityCreated(saved);
    view = (WebView) getView().findViewById(R.id.Viewport);
    view.getSettings().setTextZoom(textSize);

    mScaleDetector = new ScaleGestureDetector(getActivity().getBaseContext(),
            new ScaleGestureDetector.OnScaleGestureListener() {
                @Override
                public void onScaleEnd(ScaleGestureDetector detector) {
                }

                @Override
                public boolean onScaleBegin(ScaleGestureDetector detector) {
                    return true;
                }

                @Override
                public boolean onScale(ScaleGestureDetector detector) {
                    //Log.w(LOG_KEY, "zoom ongoing, scale: " + detector.getScaleFactor());
                    return false;
                }

            });

    // enable JavaScript for cool things to happen!
    view.getSettings().setJavaScriptEnabled(true);

    // ----- SWIPE PAGE
    view.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            /*   if (state == ViewStateEnum.books)
                  swipePage(v, event, 0);
               //int fontSize, newFont;*/
            WebView view = (WebView) v;

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                x1 = event.getX();
                break;
            case MotionEvent.ACTION_UP:
                if (mode != ZOOM && swipeFlag) {
                    //if (state == ViewStateEnum.books)
                    //swipePage(v, event, 0);

                }
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                oldDist = spacing(event);
                if (oldDist > 10f) {
                    mode = ZOOM;
                }
                break;
            case MotionEvent.ACTION_POINTER_UP:
                mode = NONE;
                break;

            case MotionEvent.ACTION_MOVE:

                if (mode == ZOOM) {
                    float newDist = spacing(event);
                    if (newDist > 10f) {
                        float scale = newDist / oldDist;
                        if (scale > 1) {
                            int currentTextSize = view.getSettings().getTextZoom();
                            textSize = currentTextSize + 15;
                            view.getSettings().setTextZoom(textSize);

                            mode = NONE;
                            swipeFlag = false;
                        } else {
                            int currentTextSize = view.getSettings().getTextZoom();
                            textSize = currentTextSize - 15;
                            view.getSettings().setTextZoom(textSize);
                            mode = NONE;
                            swipeFlag = false;
                        }
                    }
                }
                break;

            }
            return view.onTouchEvent(event);
        }

    });

    // ----- NOTE & LINK
    view.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Message msg = new Message();
            msg.setTarget(new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    String url = msg.getData().getString(getString(R.string.url));

                    if (url != null)
                        navigator.setNote(url, index);
                }
            });
            view.requestFocusNodeHref(msg);

            return false;
        }
    });

    view.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                navigator.setBookPage(url, index);
            } catch (Exception e) {
                errorMessage(getString(R.string.error_LoadPage));
            }
            return true;
        }
    });

    loadPage(viewedPage);
}

From source file:info.guardianproject.iocipher.camera.VideoCameraActivity.java

@Override
public boolean onTouch(View v, MotionEvent ev) {

    //if short tap then take a picture

    //if long and hold then start video, then end on release

    //if location is on top half then front camera, on bottom have then back camera

    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mDownX = ev.getX();//from ww w.j a  va2s .  c om
        mDownY = ev.getY();
        mIsOnClick = true;
        handler.postDelayed(mLongPressed, 1000);

        mInTopHalf = mDownY < (mLastHeight / 2);

        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsRecording) {

            //take a picture
            mPreviewing = false;
            try {
                camera.takePicture(null, null, this);
            } catch (RuntimeException re) {
                //don't crash if the picture didn't work
            }
            handler.removeCallbacks(mLongPressed);

        } else {
            stopRecording();
        }

        break;
    case MotionEvent.ACTION_MOVE:

        mLastX = ev.getX();
        mLastY = ev.getY();

        mInTopHalf = mLastY < (mDownY - 100);

        toggleCamera(mInTopHalf);

        if (mIsOnClick && (Math.abs(mDownX - ev.getX()) > SCROLL_THRESHOLD
                || Math.abs(mDownY - ev.getY()) > SCROLL_THRESHOLD)) {
            mIsOnClick = false;

        }

        break;
    default:
        break;
    }
    return true;

}

From source file:com.fw.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());

            }//from   w w w . ja v  a2s  .  c  o m
        } else {
            super.onInterceptTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

From source file:com.kinth.football.friend.touchgallery.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }//  w w w.  j av  a 2s.c  o m
        } else {
            try {
                super.onInterceptTouchEvent(event);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        try {
            return super.onInterceptTouchEvent(event);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    } else {
        try {
            if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
            {
                return super.onInterceptTouchEvent(event);
            }
            if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
            {
                return super.onInterceptTouchEvent(event);
            }
            if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
                return super.onInterceptTouchEvent(event);
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }
    return false;

}

From source file:com.common.view.touchgallery.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        // super.onInterceptTouchEvent(event);
        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }/*from   ww  w. ja va2 s .  c  o m*/
        } else {
            super.onInterceptTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    float[] difference = handleMotionEvent(event);

    if (null == mCurrentView)
        return false;

    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) {// move right
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) {// move left
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}