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:com.intel.xdk.multitouch.MultiTouch.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();// ww  w  .ja v a  2 s . c  o m

    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                try {
                    Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
                    m.invoke(WebView.class, true);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //WebView.setWebContentsDebuggingEnabled(true);
            }
        }
    });

    touchy = new View.OnTouchListener() {

        private SparseArray<Long> pointerId2Identifier = new SparseArray<Long>();

        @Override
        public boolean onTouch(View v, MotionEvent ev) {
            if (isMultitouchEnabled) {
                int pointerCount = ev.getPointerCount();

                //get the correct action
                int maskedAction = ev.getActionMasked();
                int idx = ev.getActionIndex();
                try {
                    String js = null;
                    if (maskedAction == MotionEvent.ACTION_POINTER_DOWN
                            || maskedAction == MotionEvent.ACTION_DOWN) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        //make a timestamp identifier and store it
                        long identifier = System.currentTimeMillis();
                        pointerId2Identifier.put(id, identifier);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchstart'},", identifier, x, y,
                                h, w);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_POINTER_UP
                            || maskedAction == MotionEvent.ACTION_UP) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchend'},",
                                pointerId2Identifier.get(id), x, y, h, w);
                        pointerId2Identifier.remove(id);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_MOVE) {
                        //send all events if it is a move
                        for (int i = 0; i < pointerCount; i++) {
                            int x = (int) ev.getX(i);
                            int y = (int) ev.getY(i);
                            int h = (int) v.getHeight();
                            int w = (int) v.getWidth();
                            int id = ev.getPointerId(i);
                            js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchmove'},",
                                    pointerId2Identifier.get(id), x, y, h, w);
                            queueMultitouchData(js, id, maskedAction);
                        }
                    } else {
                        Log.e("[intel.xdk]", "got a MotionEvent that is not up/down/move:" + ev);
                    }
                    //Log.i("[intel.xdk]", "onTouchEvent:"+js);
                } catch (Exception e) {
                    Log.e("[intel.xdk]", "Got an exception back from WebView: ", e);
                }

                return true;
            } else {
                return false;
            }
        }
    };
    webView.setOnTouchListener(touchy);

    lock = this;
    messages = new ArrayList<String>(0);
}

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:// w  ww . j ava  2  s  .  co m
        ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y);
        break;
    }

    return mPager.dispatchTouchEvent(ev);
}

From source file:ch.jeda.platform.android.CanvasFragment.java

@Override
public boolean onTouch(final View view, final MotionEvent event) {
    int index;/* ww w . j  a v a2 s .  c  om*/
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        index = event.getActionIndex();
        this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_DOWN, event.getPointerId(index),
                (int) event.getX(index), (int) event.getY(index)));
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        index = event.getActionIndex();
        this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_UP, event.getPointerId(index),
                (int) event.getX(index), (int) event.getY(index)));
        break;
    case MotionEvent.ACTION_MOVE:
        for (index = 0; index < event.getPointerCount(); ++index) {
            this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_MOVED,
                    event.getPointerId(index), (int) event.getX(index), (int) event.getY(index)));
        }

        break;
    }
    return true;
}

From source file:ca.uqac.florentinth.speakerauthentication.MainActivity.java

private void initGUI() {
    view = findViewById(R.id.main_layout);
    usernameInput = (EditText) findViewById(R.id.username_input);
    passwordInput = (EditText) findViewById(R.id.password_input);
    visibiltyImage = (ImageView) findViewById(R.id.visibility);
    loginBtn = (Button) findViewById(R.id.btn_login);
    newAccountBtn = (Button) findViewById(R.id.btn_new_account);

    visibiltyImage.setOnTouchListener(new View.OnTouchListener() {
        @Override/*  www .ja va  2  s  .c om*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                passwordInput.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            } else {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    passwordInput
                            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
            return true;
        }
    });

    loginBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkExternalStoragePermissions();
        }
    });

    newAccountBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(getApplicationContext(), CreateActivity.class));
        }
    });
}

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;/* ww w  .  ja  v a2  s . c  o  m*/
    }
    return super.onTouchEvent(ev);
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private void onTouchActivePointer(int action, MotionEvent ev) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = ev.getPointerId(0);
        break;// www . ja v a 2  s .com
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mActivePointerId = INVALID_POINTER_ID;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
            mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
            mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
        }

        break;
    }

    mActivePointerIndex = MotionEventCompat.findPointerIndex(ev,
            mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}

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

@Override
public boolean onTouchEvent(MotionEvent ev) {
    // ActionBarViews always eat touch events, but should still respect the touch event dispatch
    // contract. If the normal View implementation doesn't want the events, we'll just silently
    // eat the rest of the gesture without reporting the events to the default implementation
    // since that's what it expects.

    final int action = MotionEventCompat.getActionMasked(ev);
    if (action == MotionEvent.ACTION_DOWN) {
        mEatingTouch = false;//w ww .  ja v  a2  s.  c  o  m
    }

    if (!mEatingTouch) {
        final boolean handled = super.onTouchEvent(ev);
        if (action == MotionEvent.ACTION_DOWN && !handled) {
            mEatingTouch = true;
        }
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        mEatingTouch = false;
    }

    return true;
}

From source file:com.alex.vmandroid.display.main.fragments.fragments.LoopAdvertisementFragment.java

@Override
public void setViewPagerData(List<Integer> pictureList) {
    LoopAdvertisementAdapter mBannerPagerAdapter = new LoopAdvertisementAdapter(getActivity(), pictureList);

    mViewPager.setAdapter(mBannerPagerAdapter);

    mViewPager.setOnTouchListener(new View.OnTouchListener() {
        int flage = 0;

        @Override//from w  w w.  j  a  v a  2 s  .  co  m
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                flage = 0;
                mIsUserTouched = true;
                break;
            case MotionEvent.ACTION_MOVE:
                mIsUserTouched = true;
                flage = 1;
                break;
            case MotionEvent.ACTION_UP:
                mIsUserTouched = false;
                if (flage == 0) {
                    int item = mViewPager.getCurrentItem();
                    mPresenter.onViewPagerItemClick(item);
                }
                break;
            }
            return false;
        }
    });

    startBannerTimer();
}

From source file:ca.hoogit.garagepi.Controls.DoorView.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.door_view, this);
    ButterKnife.bind(this);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DoorView, defStyle, 0);
    mOpenedColor = a.getColor(R.styleable.DoorView_openedColor,
            ContextCompat.getColor(context, R.color.colorAccent));
    mClosedColor = a.getColor(R.styleable.DoorView_closedColor,
            ContextCompat.getColor(context, R.color.colorPrimary));
    mDoorName = a.getString(R.styleable.DoorView_doorName);
    a.recycle();/*from   w  w w.j a v a2  s. co  m*/

    mContext = context;

    mToggleContainer.setOnClickListener(OnSingleClickListener.wrap(v -> {
        if (mOnToggle != null) {
            mOnToggle.onToggle(mDoorName);
        }
    }));

    mToggleContainer.setOnTouchListener((v, event) -> {
        int origColor = mDoorValue ? mOpenedColor : mClosedColor;
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mToggleContainer.setBackgroundColor(ColorUtil.darken(origColor));
        } else if (event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_CANCEL) {
            mToggleContainer.setBackgroundColor(origColor);
        }
        return false;
    });

    setupViews();
}

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;
            }/*ww  w. ja  va2  s. c o  m*/
        }
    }

    return shouldIntercept;
}