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.cssweb.android.view.FTrendView.java

/**
 * true?,false??/*from  ww  w .  j  av  a  2  s  . co m*/
 */
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        touchesBegan(event);
        break;

    case MotionEvent.ACTION_MOVE:
        touchesMoved(event);
        break;

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

    case MotionEvent.ACTION_CANCEL:
        break;
    }
    return true;
}

From source file:com.muzima.view.forms.FormWebViewActivity.java

private View.OnTouchListener createCompleteFormListenerToDisableInput() {
    return new View.OnTouchListener() {
        @Override//from  w ww.  ja  v a  2  s .  c o  m
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() != MotionEvent.ACTION_MOVE) {
                view.setFocusable(false);
                view.setEnabled(false);
                return true;
            }
            return false;
        }
    };
}

From source file:android.support.v7.widget.ListViewCompat.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mMotionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
        break;/*from   w  ww.  j a va2  s.c o m*/
    }
    return super.onTouchEvent(ev);
}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mNotInitialized)
            touchStart(x, y);//from  w w w.ja  v  a 2s . c  o  m
        break;

    case MotionEvent.ACTION_MOVE:
        if (!mNotInitialized) {
            touchMove(x, y);
            postInvalidate();
        }
        break;

    case MotionEvent.ACTION_UP:
        int posX = getWidth() - mClearImageSize - mClearBuff;
        //Log.d(Constants.TAG, "x: " + event.getX() + " y: " + event.getY() + " posX: " + posX + " posY: " + mClearBuff);
        if (event.getX() > posX && event.getY() < mClearImageSize + mClearBuff) {
            onClearSign();
        } else if (!mNotInitialized) {
            touchUp();
            invalidate();
        }
        break;

    default:
        break;
    }

    return true;
}

From source file:com.bottomsheetbehavior.ReactNestedScrollView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mScrollEnabled) {
        return false;
    }//from   ww  w .jav  a 2  s  . c o  m

    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    if (action == MotionEvent.ACTION_UP && mDragging) {
        ReactNestedScrollViewHelper.emitScrollEndDragEvent(this);
        mDragging = false;
        disableFpsListener();
    }
    return super.onTouchEvent(ev);
}

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);//from  w  w w .  j  av  a2 s .co m
        break;

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

    return super.onTouchEvent(event);
}

From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (isEnabled() && event.getAction() == MotionEvent.ACTION_UP) {
        if (!popupWindow.isShowing()) {
            showDropDown();//from   w w  w .j a  v  a 2 s.c  o m
        } else {
            dismissDropDown();
        }
    }
    return super.onTouchEvent(event);
}

From source file:cn.edu.zafu.easemob.CoverFlowLib.VelocityViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    // give all the events to the gesture detector. I'm returning true here so the viewpager doesn't
    // get any events at all, I'm sure you could adjust this to make that not true.
    mGestureDetector.onTouchEvent(event);

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        downX = event.getX();/*from  ww  w  . j a v  a  2  s  .  com*/
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        onUp(event.getX() - downX);
    }
    return true;
}

From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    // MotionEvent reports input details from the touch screen
    // and other input controls. In this case, you are only
    // interested in events where the touch position changed.

    switch (e.getAction()) {

    case MotionEvent.ACTION_DOWN:
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } else {/*  ww w  . j  a va 2s .c o  m*/
            mVelocityTracker.clear();
        }

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.touchHasStarted();
            }
        });

        // No break is intentional

    case MotionEvent.ACTION_MOVE:

        mVelocityTracker.addMovement(e);

        // Compute velocity in pixels per second
        mVelocityTracker.computeCurrentVelocity(1);

        final ArrayList<TouchData> touchDataList = new ArrayList<>(e.getHistorySize() + 1);
        Vector2 viewportPosition;

        Vector2 viewportVelocity = new Vector2(
                VelocityTrackerCompat.getXVelocity(mVelocityTracker, e.getActionIndex()),
                VelocityTrackerCompat.getYVelocity(mVelocityTracker, e.getActionIndex()));

        // Add previous touch coordinates
        for (int i = 0; i < e.getHistorySize(); i++) {
            viewportPosition = new Vector2(e.getHistoricalX(i), e.getHistoricalY(i));

            touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity,
                    e.getHistoricalSize(i), e.getHistoricalPressure(i)));
        }

        // Add current touch coordinates
        viewportPosition = new Vector2(e.getX(), e.getY());
        touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity,
                e.getSize(), e.getPressure()));

        // Ensure we call switchMode() on the OpenGL thread.
        // queueEvent() is a method of GLSurfaceView that will do this for us.
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.addTouchData(touchDataList);
            }
        });

        requestRender();
        break;

    case MotionEvent.ACTION_UP:

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.touchHasEnded();
            }
        });
        requestRender();
        break;
    }
    return true;
}

From source file:com.mimo.service.api.MimoOauth2Client.java

/**
 * Instantiate a webview and allows the user to login to the Api form within
 * the application//from  ww w.  j  av a2  s . c  o  m
 * 
 * @param p_view
 *            : Calling view
 * 
 * @param p_activity
 *            : Calling Activity reference
 **/

@SuppressLint("SetJavaScriptEnabled")
public void login(View p_view, Activity p_activity) {

    final Activity m_activity;
    m_activity = p_activity;
    String m_url = this.m_api.getAuthUrl();
    WebView m_webview = new WebView(p_view.getContext());
    m_webview.getSettings().setJavaScriptEnabled(true);
    m_webview.setVisibility(View.VISIBLE);
    m_activity.setContentView(m_webview);

    m_webview.requestFocus(View.FOCUS_DOWN);
    /**
     * Open the softkeyboard of the device to input the text in form which
     * loads in webview.
     */
    m_webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View p_v, MotionEvent p_event) {
            switch (p_event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!p_v.hasFocus()) {
                    p_v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    /**
     * Show the progressbar in the title of the activity untill the page
     * loads the give url.
     */
    m_webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView p_view, int p_newProgress) {
            ((Activity) m_context).setProgress(p_newProgress * 100);
            ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING);

            if (p_newProgress == 100)
                ((Activity) m_context).setTitle(m_context.getString(R.string.app_name));
        }
    });

    m_webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) {
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url,
                String p_realm) {
            p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD);
        }

        public void onPageFinished(WebView p_view, String p_url) {
            if (MimoAPIConstants.DEBUG) {
                Log.d(TAG, "Page Url = " + p_url);
            }
            if (p_url.contains("?code=")) {
                if (p_url.indexOf("code=") != -1) {
                    String[] m_urlSplit = p_url.split("=");

                    String m_tempString1 = m_urlSplit[1];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "TempString1 = " + m_tempString1);
                    }
                    String[] m_urlSplit1 = m_tempString1.split("&");

                    String m_code = m_urlSplit1[0];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "code = " + m_code);
                    }
                    MimoOauth2Client.this.m_code = m_code;
                    Thread m_thread = new Thread() {
                        public void run() {
                            String m_token = requesttoken(MimoOauth2Client.this.m_code);

                            Log.d(TAG, "Token = " + m_token);

                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);

                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);

                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                } else {
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "going in else");
                    }
                }
            } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) {
                if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) {
                    String[] m_urlSplit = p_url.split("=");
                    final String m_token = m_urlSplit[1];

                    Thread m_thread = new Thread() {
                        public void run() {
                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);
                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);
                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                }
            }
        };
    });

    m_webview.loadUrl(m_url);
}