Example usage for android.view MotionEvent getAction

List of usage examples for android.view MotionEvent getAction

Introduction

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

Prototype

public final int getAction() 

Source Link

Document

Return the kind of action being performed.

Usage

From source file:com.android.cts.uiautomator.TestGenericDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View rootView = inflater.inflate(R.layout.test_results_detail_fragment, container, false);
    if (mItem != null) {
        ((TextView) rootView.findViewById(R.id.testResultsTextView)).setText(mItem.mName);
    }//from   w w  w .j av a 2s .co  m

    // listen to touch events to verify the multiPointerGesture APIs
    // Since API Level 18
    rootView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                // Reset any collected touch coordinate results on the primary touch down
                resetTouchResults();
                // collect this event
                collectStartAction(event, v, 0);
                break;

            case MotionEvent.ACTION_POINTER_DOWN:
                // collect this event
                collectStartAction(event, v, getPointerIndex(event));
                break;

            case MotionEvent.ACTION_POINTER_UP:
                // collect this event
                collectEndAction(event, v, getPointerIndex(event));
                break;

            case MotionEvent.ACTION_UP:
                // collect this event
                collectEndAction(event, v, 0);
                // on the primary touch up display results collected for all pointers
                displayTouchResults();
                break;
            }
            return true;
        }
    });

    return rootView;
}

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

@Override
public boolean onTouchEvent(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  a va  2 s.  c  om
            //launchFullPhotoActivity(imageUrls);// WE HAVE A CLICK!!
        } else {
            super.onTouchEvent(event);
        }
    }

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

    /*if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP)
    {
    super.onTouchEvent(event);
    }*/

    float[] difference = handleMotionEvent(event);

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

    return false;
}

From source file:com.anykey.balala.activity.BaseActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {
            hideSoftInputView();/*from ww w.  jav a2 s .  c  o m*/
        }
    }
    return super.onTouchEvent(event);
}

From source file:com.bobomee.android.recyclerviewhelper.fastscroll.FastScroller.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (event.getX() < handle.getX() - ViewCompat.getPaddingStart(handle))
            return false;
        if (currentAnimator != null)
            currentAnimator.cancel();//from www  .  j  ava2s .c o  m
        handle.setSelected(true);
        mOnScrollStateChange.onFastScrollerStateChange(true);
        showBubble();
    case MotionEvent.ACTION_MOVE:
        float y = event.getY();
        setBubbleAndHandlePosition(y);
        onScrollPosition(y);
        return true;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        handle.setSelected(false);
        mOnScrollStateChange.onFastScrollerStateChange(false);
        hideBubble();
        return true;
    }
    return super.onTouchEvent(event);
}

From source file:cn.limc.androidcharts.event.SlipGestureDetector.java

public boolean onTouchEvent(MotionEvent event) {
    int pointers = event.getPointerCount();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // ?/* w w w  .j  a va  2 s  . com*/
    case MotionEvent.ACTION_DOWN:
        initalX = event.getX();
        if (pointers > 1) {
            touchMode = TOUCH_MODE_MULTI;
        } else {
            touchMode = TOUCH_MODE_SINGLE;
        }
        break;
    case MotionEvent.ACTION_UP:
        startPointA = null;
        startPointB = null;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        startPointA = null;
        startPointB = null;
    case MotionEvent.ACTION_POINTER_DOWN:
        olddistance = calcDistance(event);
        if (olddistance > MIN_DISTANCE) {
            touchMode = TOUCH_MODE_MULTI;
            startPointA = new PointF(event.getX(0), event.getY(0));
            startPointB = new PointF(event.getX(1), event.getY(1));
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (touchMode == TOUCH_MODE_SINGLE) {
            final float finalX = event.getX();
            // MotionEvent finalEvent = event;
            if (performLongClick) {
                return super.onTouchEvent(event);
            } else {
                if (finalX - initalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveRight((ISlipable) instance, event);
                    }
                } else if (initalX - finalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveLeft((ISlipable) instance, event);
                    }
                }
                initalX = finalX;
                // initalEvent = finalEvent;
                return true;
            }
        } else if (touchMode == TOUCH_MODE_MULTI) {
            newdistance = calcDistance(event);
            if (Math.abs(newdistance - olddistance) > MIN_DISTANCE) {
                if (onZoomGestureListener != null) {
                    if (newdistance > olddistance) {
                        onZoomGestureListener.onZoomIn((IZoomable) instance, event);
                    } else {
                        onZoomGestureListener.onZoomOut((IZoomable) instance, event);
                    }
                }
            }
            olddistance = newdistance;
            return true;
            // startPointA = new PointF(event.getX(), event.getY());
            // startPointB = new PointF(event.getX(1), event.getY(1));
        }
        break;
    }
    return super.onTouchEvent(event);
}

From source file:com.easemob.helpdeskdemo.ui.SatisfactionActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

    // Edittext //w  w w . j  a  v  a 2 s  .  c o m
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        View v = getCurrentFocus();
        if (isShouldHideInput(v, ev)) {
            InputMethodManager inputManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            if (inputManager != null) {
                inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }

        return super.dispatchTouchEvent(ev);
    }
    // ????TouchEvent
    if (getWindow().superDispatchTouchEvent(ev)) {
        return true;
    }
    return onTouchEvent(ev);
}

From source file:au.com.wallaceit.reddinator.TabWebFragment.java

@SuppressLint("SetJavaScriptEnabled")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = this.getActivity();
    if (container == null) {
        return null;
    }//from w w  w.  j  ava 2  s  .c o  m
    if (mFirstTime) {
        // get shared preferences
        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(this.getActivity().getApplicationContext());
        // work out the url this instance should load
        boolean commentswv = false;
        if (this.getArguments() != null) {
            commentswv = this.getArguments().getBoolean("loadcom", false);
        }

        int fontsize;
        String url;
        if (commentswv) {
            url = "http://reddit.com" + getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_PERMALINK)
                    + ".compact";
            fontsize = Integer.parseInt(prefs.getString("commentfontpref", "22"));
        } else {
            url = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_URL);
            fontsize = Integer.parseInt(prefs.getString("contentfontpref", "18"));
        }
        // setup progressbar
        mActivity = this.getActivity();
        mActivity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
        ll = (LinearLayout) inflater.inflate(R.layout.tab1, container, false);
        mWebView = (WebView) ll.findViewById(R.id.webView1);
        // fixes for webview not taking keyboard input on some devices
        mWebView.requestFocus(View.FOCUS_DOWN);
        mWebView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                    break;
                }
                return false;
            }
        });
        mWebView.getSettings().setJavaScriptEnabled(true); // enable ecmascript
        mWebView.getSettings().setSupportZoom(true);
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setDisplayZoomControls(true);
        mWebView.getSettings().setDefaultFontSize(fontsize);
        mChromeClient = newchromeclient;
        mWebView.setWebChromeClient(mChromeClient);
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.loadUrl(url);
        mFirstTime = false;
        //System.out.println("Created fragment");
    } else {
        ((ViewGroup) ll.getParent()).removeView(ll);
    }

    return ll;
}

From source file:adapters.PagerContainer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    //We capture any touches not already handled by the ViewPager
    // to implement scrolling from a touch outside the pager bounds.
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mInitialTouch.x = (int) ev.getX();
        mInitialTouch.y = (int) ev.getY();
    default://from w ww  . j  a  v a  2  s  .co m
        ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y);
        break;
    }

    return mPager.dispatchTouchEvent(ev);
}

From source file:com.barchart.tester.pager.PagerContainer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    // We capture any touches not already handled by the ViewPager
    // to implement scrolling from a touch outside the pager bounds.
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mInitialTouch.x = (int) ev.getX();
        mInitialTouch.y = (int) ev.getY();
    default:/*from  w  w w .  j  a  v  a2s . c  om*/
        ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y);
        break;
    }

    return mPager.dispatchTouchEvent(ev);
}

From source file:android.hawkencompanionapp.fragments.MechGuideFragment.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float xPos = event.getX();

    if (xPos > mSwipeXPxOffset) { //Prevent the nav drawer from registering the event
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mPrevXdp = xPos;/*  ww  w.  j  av  a  2  s .  co m*/
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
            if (mPrevXdp < xPos) { //Right swipe
                switchTab("Right");
            } else { //Left swipe
                switchTab("Left");
            }
        }
        return true;
    }
    return false;
}