Example usage for android.view MotionEvent ACTION_UP

List of usage examples for android.view MotionEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

Usage

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Perform click on a key.//w  ww  .  jav a 2s  .  c o m
 *
 * @param key A key to be registered.
 */
public void performClickOn(final Key key) {
    if (DEBUG_HOVER) {
        Log.d(TAG, "performClickOn: key=" + key);
    }
    simulateTouchEvent(MotionEvent.ACTION_DOWN, key);
    simulateTouchEvent(MotionEvent.ACTION_UP, key);
}

From source file:com.android.hareime.accessibility.AccessibilityEntityProvider.java

/**
 * Simulates a key press by injecting touch events into the keyboard view.
 * This avoids the complexity of trackers and listeners within the keyboard.
 *
 * @param key The key to press./* w ww .ja v  a 2 s. com*/
 */
void simulateKeyPress(Key key) {
    final int x = key.mHitBox.centerX();
    final int y = key.mHitBox.centerY();
    final long downTime = SystemClock.uptimeMillis();
    final MotionEvent downEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
    final MotionEvent upEvent = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP,
            x, y, 0);

    mKeyboardView.onTouchEvent(downEvent);
    mKeyboardView.onTouchEvent(upEvent);
}

From source file:com.android.inputmethod.accessibility.AccessibilityEntityProvider.java

/**
 * Simulates a key press by injecting touch events into the keyboard view.
 * This avoids the complexity of trackers and listeners within the keyboard.
 *
 * @param key The key to press.// www  . j av  a 2s . co  m
 */
void simulateKeyPress(Key key) {
    final int x = key.mHitBox.centerX();
    final int y = key.mHitBox.centerY();
    final long downTime = SystemClock.uptimeMillis();
    final MotionEvent downEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
    final MotionEvent upEvent = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP,
            x, y, 0);

    mKeyboardView.onTouchEvent(downEvent);
    mKeyboardView.onTouchEvent(upEvent);

    downEvent.recycle();
    upEvent.recycle();
}

From source file:cn.com.hgh.view.SlideSwitch.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (slideable == false)
        return super.onTouchEvent(event);
    int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        eventStartX = (int) event.getRawX();
        break;/*from   w ww .j av  a  2s .c o  m*/
    case MotionEvent.ACTION_MOVE:
        //         eventLastX = (int) event.getRawX();
        //         diffX = eventLastX - eventStartX;
        //         int tempX = diffX + frontRect_left_begin;
        //         tempX = (tempX > max_left ? max_left : tempX);
        //         tempX = (tempX < min_left ? min_left : tempX);
        //         if (tempX >= min_left && tempX <= max_left) {
        //            frontRect_left = tempX;
        //            alpha = (int) (255 * (float) tempX / (float) max_left);
        //            invalidateView();
        //         }
        break;
    case MotionEvent.ACTION_UP:
        int wholeX = (int) (event.getRawX() - eventStartX);
        frontRect_left_begin = frontRect_left;
        toRight = (frontRect_left_begin > max_left / 2 ? true : false);
        if (Math.abs(wholeX) < 3) {
            toRight = !toRight;
        }
        //x??
        float eventx = event.getX();
        if (isOpen) {
            //?
            if (eventx < width / 2) {
                //            switchBusinessStatus();
                switchStatus();

            }
        } else {
            //?
            if (eventx > width / 2) {
                //               switchBusinessStatus();
                switchStatus();

            }
        }
        break;
    default:
        break;
    }
    return true;
}

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

/**
 * ??/*from  w  ww .  j  ava  2s  . c o 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:io.selendroid.server.model.AndroidWebElement.java

@Override
public void click() {
    String tagName = getTagName();
    if ((tagName != null && "OPTION".equals(tagName.toUpperCase())) || driver.isInFrame()) {
        driver.resetPageIsLoading();//from   www  . ja  v a 2  s.co  m
        driver.executeAtom(AndroidAtoms.CLICK, null, this);
        driver.waitForPageToLoad();
        if (driver.isInFrame()) {
            return;
        }
    }

    Point center = getCenterCoordinates();
    long downTime = SystemClock.uptimeMillis();
    final List<MotionEvent> events = new ArrayList<MotionEvent>();

    MotionEvent downEvent = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN,
            center.x, center.y, 0);
    events.add(downEvent);
    MotionEvent upEvent = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP,
            center.x, center.y, 0);

    events.add(upEvent);

    driver.resetPageIsLoading();
    driver.getMotionSender().send(events);

    // If the page started loading we should wait
    // until the page is done loading.
    driver.waitForPageToLoad();
}

From source file:com.android.volley.ui.PhotoView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mScaleGetureDetector == null || mGestureDetector == null) {
        // We're being destroyed; ignore any touch events
        return true;
    }//  w ww  .  ja  va  2s  .c  om

    mScaleGetureDetector.onTouchEvent(event);
    mGestureDetector.onTouchEvent(event);
    final int action = event.getAction();

    switch (action) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (!mTranslateRunnable.mRunning) {
            snap();
        }
        break;
    }

    return true;
}

From source file:app.android.datetimepicker.date.SimpleMonthView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_UP:
        final int day = getDayFromLocation(event.getX(), event.getY());
        if (day >= 0) {
            onDayClick(day);//from   www .  jav a2 s.  co m
        }
        break;
    }
    return true;
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

private void init(final Context context) {
    rootView = LayoutInflater.from(context).inflate(R.layout.car_recognise_layout, this);

    deleteLastLicensePhoto();//  w  w w. ja v a 2 s.  c o m

    mCarSettings = CarSettings.getInstance();

    licenseRecognise = new LicenseRecognise(context, AppCommon.licensePhotoPath);

    licenseImageView = (ImageView) findViewById(R.id.licenseImage);
    licenseImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            licenseRecognise.takePhoto();
        }
    });

    // 
    recogniseButton = (Button) rootView.findViewById(R.id.recognise_button);
    recogniseButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // ???
            if (!mCarSettings.getBrandString().equals("")) {
                reRecognise(R.string.reRecognise1);
            } else if (!getEditViewText(rootView, R.id.plateNumber_edit).equals("")) {
                reRecognise(R.string.reRecognise);
            } else {
                //fillInDummyData();
                if (licensePhotoExist())
                    recogniseLicense();
                else
                    Toast.makeText(context, "???", Toast.LENGTH_SHORT).show();
            }
        }
    });

    // vin
    Button vinConfirmButton = (Button) rootView.findViewById(R.id.vinConfirm_button);
    vinConfirmButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // VIN??
            if (getEditViewText(rootView, R.id.vin_edit).equals("")) {
                Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show();
            } else {
                checkVinAndGetCarSettings();
            }
        }
    });

    // ?
    Button brandSelectButton = (Button) rootView.findViewById(R.id.brand_select_button);
    brandSelectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            selectCarManually();
        }
    });

    vehicleTypeEdit = (EditText) rootView.findViewById(R.id.vehicleType_edit);
    vehicleTypeEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.vehicleType_items, R.id.vehicleType_edit);
                break;
            }
            return false;
        }
    });

    useCharacterEdit = (EditText) rootView.findViewById(R.id.useCharacter_edit);
    useCharacterEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.useCharacter_items, R.id.useCharacter_edit);
                break;
            }
            return false;
        }
    });

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };

    EditText vin_edit = (EditText) findViewById(R.id.vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps(),
            new InputFilter.LengthFilter(17) });

    EditText plateNumberEdit = (EditText) findViewById(R.id.plateNumber_edit);
    plateNumberEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    EditText licenseModelEdit = (EditText) findViewById(R.id.licenseModel_edit);
    licenseModelEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(22) });

    EditText engineSerialEdit = (EditText) findViewById(R.id.engineSerial_edit);
    engineSerialEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(17) });

    vehicleModel = MainActivity.vehicleModel;
}

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

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

    getView().requestFocus();/*w w w.  j  a v a2 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();
}