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:co.dift.ui.SwipeToAction.java

/** Private methods **/
private void init() {
    gestureDetector = new GestureDetectorCompat(recyclerView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override// w w  w  .  ja v a 2s . c o m
                public void onLongPress(MotionEvent e) {
                    logger.d("onLongPress called!");
                    if (touchedViewHolder != null) {
                        swipeListener.onLongClick(touchedViewHolder.getItemData());
                    }
                }

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    logger.d("onSingleTapUp called!");
                    if (touchedViewHolder != null) {
                        swipeListener.onClick(touchedViewHolder.getItemData());
                        return true;
                    }
                    return super.onSingleTapUp(e);
                }
            });

    recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {

        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) {
            gestureDetector.onTouchEvent(ev);

            switch (ev.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN: {
                // starting point
                downX = ev.getX();
                downY = ev.getY();

                downTime = new Date().getTime();

                // which item are we touching
                resolveItem(downX, downY);

                break;
            }

            case MotionEvent.ACTION_UP: {
                upX = ev.getX();
                upY = ev.getY();
                upTime = new Date().getTime();

                resolveState();
                break;
            }

            case MotionEvent.ACTION_MOVE: {
                final float x = ev.getX();
                final float dx = x - downX;

                if (!shouldMove(dx))
                    break;

                // current position. moving only over x-axis
                frontViewLastX = frontViewX + dx + (dx > 0 ? -getRevealThreshold() : getRevealThreshold());
                //                        logger.d("dx: %f, frontViewLastX: %f", dx, frontViewLastX);
                if (maxSwipeXPosition != null) {
                    if (frontViewLastX > 0 && frontViewLastX > maxSwipeXPosition) {
                        frontViewLastX = maxSwipeXPosition;
                    } else if (frontViewLastX <= -maxSwipeXPosition) {
                        frontViewLastX = -maxSwipeXPosition;
                    }
                }
                frontView.setX(frontViewLastX);

                if (frontViewLastX > 0) {
                    revealRight();
                } else {
                    revealLeft();
                }

                break;
            }

            case MotionEvent.ACTION_CANCEL: {
                resolveState();

                break;
            }
            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
            logger.d("onTouchEvent called");
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
            logger.d("onRequestDisallowInterceptTouchEvent called");
        }
    });
}

From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();//www. j  a v  a2s  . c o m
    boolean handled = false;
    if (returningToStart && ev.getAction() == MotionEvent.ACTION_DOWN) {
        returningToStart = false;
    }
    if (isEnabled() && !returningToStart && !canChildScrollUp()) {
        handled = onTouchEvent(ev);
    }
    return !handled ? super.onInterceptTouchEvent(ev) : handled;
}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java

@Override
public void onStart() {
    formulaEditorKeyboard.setClickable(true);
    formularEditorFieldDeleteButton.setClickable(true);

    getView().requestFocus();//from  w ww .j a v a 2 s .  c  om
    View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            Log.i("info", "viewId: " + view.getId());
            if (event.getAction() == MotionEvent.ACTION_UP) {
                updateButtonViewOnKeyboard();
                view.setPressed(false);
                return true;
            }

            if (event.getAction() == MotionEvent.ACTION_DOWN) {

                view.setPressed(true);

                switch (view.getId()) {
                case R.id.formula_editor_keyboard_compute:
                    InternFormulaParser internFormulaParser = formulaEditorEditText.getFormulaParser();
                    FormulaElement formulaElement = internFormulaParser.parseFormula();
                    if (formulaElement == null) {
                        if (internFormulaParser.getErrorTokenIndex() >= 0) {
                            formulaEditorEditText.setParseErrorCursorAndSelection();
                        }
                        return false;
                    }
                    Formula formulaToCompute = new Formula(formulaElement);
                    FormulaEditorComputeDialog computeDialog = new FormulaEditorComputeDialog(context);
                    computeDialog.setFormula(formulaToCompute);
                    computeDialog.show();
                    return true;
                case R.id.formula_editor_keyboard_undo:
                    formulaEditorEditText.undo();
                    return true;
                case R.id.formula_editor_keyboard_redo:
                    formulaEditorEditText.redo();
                    return true;
                case R.id.formula_editor_keyboard_math:
                    showFormulaEditorListFragment(FormulaEditorListFragment.MATH_TAG,
                            R.string.formula_editor_math);
                    return true;
                case R.id.formula_editor_keyboard_logic:
                    showFormulaEditorListFragment(FormulaEditorListFragment.LOGIC_TAG,
                            R.string.formula_editor_logic);
                    return true;
                case R.id.formula_editor_keyboard_object:
                    showFormulaEditorListFragment(FormulaEditorListFragment.OBJECT_TAG,
                            R.string.formula_editor_choose_object_variable);
                    return true;
                case R.id.formula_editor_keyboard_scripts:
                    showFormulaEditorScriptListFragment(FormulaEditorScriptListFragment.SCRIPT_TAG,
                            R.string.formula_editor_scripts);
                    return true;
                case R.id.formula_editor_keyboard_variables:
                    showFormulaEditorVariableListFragment(FormulaEditorVariableListFragment.VARIABLE_TAG,
                            R.string.formula_editor_variables);
                    return true;
                case R.id.formula_editor_keyboard_ok:
                    endFormulaEditor();
                    return true;
                default:
                    formulaEditorEditText.handleKeyEvent(view.getId(), "");
                    return true;
                }

            }
            return false;
        }
    };

    for (int index = 0; index < formulaEditorKeyboard.getChildCount(); index++) {
        LinearLayout child = (LinearLayout) formulaEditorKeyboard.getChildAt(index);
        for (int nestedIndex = 0; nestedIndex < child.getChildCount(); nestedIndex++) {
            View view = child.getChildAt(nestedIndex);
            view.setOnTouchListener(touchListener);
        }
    }
    formularEditorFieldDeleteButton.setOnTouchListener(touchListener);

    updateButtonViewOnKeyboard();

    super.onStart();
}

From source file:am.widget.scalerecyclerview.ScaleRecyclerView.java

/**
 * ??/*from   w ww.  j a v a2  s  . co m*/
 *
 * @param e 
 */
protected boolean dispatchDoubleTapEvent(MotionEvent e) {
    // ?ACTION_UP??
    if (e.getAction() != MotionEvent.ACTION_UP)
        return false;
    // ????View?
    if (!mShouldReactDoubleTab)
        return false;
    // ??
    onDoubleTapEvent(e);
    if (mListener != null && mListener.onDoubleTap(this))
        return true;
    // ?
    final float targetScale = getDoubleTapScale(mScale);
    if (targetScale == mScale)
        return false;
    mScaleHelper.scale(mScale, targetScale, e.getX(), e.getY());
    return true;
}

From source file:am.widget.scalerecyclerview.ScaleRecyclerView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (!mScaleEnable)
        return super.dispatchTouchEvent(ev);
    final int action = ev.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        mScaleHelper.stop();/*  w w w  . j  a v  a  2  s  .co  m*/
        mShouldReactDoubleTab = true;
        mShouldReactSingleTab = true;
    }
    final boolean superResult = super.dispatchTouchEvent(ev);
    if (!mInterceptTouch) {
        // ??
        // ?????????
        mGestureDetector.onTouchEvent(ev);
    }
    return superResult;
}

From source file:cn.kylinhuang.play.view.CommonGestures.java

public boolean onTouchEvent(MotionEvent event) {
    if (mListener == null)
        return false;

    if (null == event)
        return false;

    if (mTapGestureDetector.onTouchEvent(event))
        return true;

    if (event.getPointerCount() > 1) {
        try {//from   www. ja v a  2  s. c  o m
            if (mScaleDetector != null && mScaleDetector.onTouchEvent(event))
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (mDoubleTapGestureDetector.onTouchEvent(event))
        return true;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mListener.onGestureEnd();
        break;
    }

    return true;
}

From source file:com.android.andryyu.lifehelper.widget.RippleView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (gestureDetector.onTouchEvent(event)) {
        animateRipple(event);/*  w  w w .  j  a va2s  .  c  om*/
        sendClickEvent(false);
        rippleStatus = RIPPLE_SINGLE;
    }
    if (rippleStatus == RIPPLE_LONG_PRESS) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            rippleStatus = RIPPLE_ACTION_UP;
        } else if (Math.abs(event.getX() - lastLongPressX) >= touchSlop
                || Math.abs(event.getY() - lastLongPressY) >= touchSlop) {
            rippleStatus = RIPPLE_ACTION_MOVE;
        }
    }

    return super.onTouchEvent(event);
}

From source file:com.amazon.appstream.sampleclient.SampleClientActivity.java

/**
 * A "generic motion event" includes joystick and mouse motion
 * when the mouse button isn't down. In our simple sample, we're
 * not handling the joystick, but this is where any such code
 * would live.//  ww w. ja  v  a2  s  . c  om
 *
 * This will only ever be called in HONEYCOMB_MR1 (12) or later, so I'm marking the
 * function using \@TargetApi to allow it to call the super.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    if (event.getSource() == InputDevice.SOURCE_MOUSE) {
        event.getPointerCoords(0, mCoordHolder);
        switch (event.getAction()) {
        case MotionEvent.ACTION_HOVER_MOVE:
            AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, 0);
            break;

        default:
            return super.dispatchGenericMotionEvent(event);
        }
        return true;
    }
    return super.dispatchGenericMotionEvent(event);
}

From source file:com.nps.micro.view.TestsSectionFragment.java

private void createSequenceChooser(View rootView) {
    final String[] sequencesArray = getResources().getStringArray(R.array.sequence_array);
    selectedSequences.clear();//from  w ww. java 2 s  . c o  m
    selectedSequences.addAll(model.getSequencesAsStrings());
    runButton.setEnabled(model.getSequences().length > 0);
    selectedSequencesListView = (DynamicListView) rootView.findViewById(R.id.selectedSequencesListView);
    selectedSequencesListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    selectedSequencesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedSequences);
    selectedSequencesListView.setListItems(selectedSequences);
    selectedSequencesListView.setAdapter(selectedSequencesAdapter);
    setListViewHeightBasedOnChildren(selectedSequencesListView);
    selectedSequencesListView.setOnTouchListener(new ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            v.onTouchEvent(event);
            return true;
        }
    });

    selectSequenceButton = (Button) rootView.findViewById(R.id.selectSequenceButton);
    selectSequenceButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean[] checkedItems = new boolean[sequencesArray.length];
            for (int i = 0; i < sequencesArray.length; i++) {
                if (selectedSequences.contains(sequencesArray[i])) {
                    checkedItems[i] = true;
                } else {
                    checkedItems[i] = false;
                }
            }
            new AlertDialog.Builder(getActivity()).setTitle(R.string.arhitecture)
                    .setMultiChoiceItems(sequencesArray, checkedItems,
                            new DialogInterface.OnMultiChoiceClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                    String selectedArchitecture = sequencesArray[which];
                                    if (isChecked) {
                                        selectedSequences.add(selectedArchitecture);
                                    } else if (selectedSequences.contains(selectedArchitecture)) {
                                        selectedSequences.remove(selectedArchitecture);
                                    }
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            runButton.setEnabled(!selectedSequences.isEmpty());
                            model.setSequences(selectedSequences);
                            selectedSequencesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view,
                                    selectedSequences);
                            selectedSequencesListView.setAdapter(selectedSequencesAdapter);
                            setListViewHeightBasedOnChildren(selectedSequencesListView);
                        }
                    }).create().show();
        }
    });
}

From source file:fr.gotorennes.AbstractMapActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    boolean result = super.dispatchTouchEvent(event);
    if (event.getAction() == MotionEvent.ACTION_UP)
        onMapChange();//from w w w  . j  a va  2  s. c  om
    return result;
}