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: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());
            }//from   w  ww  . j av a2 s  . c  o m
            //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:de.struckmeierfliesen.ds.wochenbericht.ClearableAutoCompleteTextView.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (getCompoundDrawables()[2] != null) {
        boolean tappedX = event.getX() > (getWidth() - getPaddingRight()
                - (int) (xD.getIntrinsicWidth() * DRAWABLE_MULTIPLIER));
        if (tappedX) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                setText("");
                if (textClearListener != null) {
                    textClearListener.didClearText();
                }// w  ww  . j a v a 2  s  .  com
            }
            return true;
        }
    }
    if (l != null) {
        return l.onTouch(v, event);
    }
    return false;
}

From source file:com.anysoftkeyboard.devicespecific.AskV8GestureDetector.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    int singleFingerEventPointerId = mSingleFingerEventPointerId;

    //I want to keep track on the first finger (https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300)
    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN:
        if (ev.getPointerCount() == 1) {
            mSingleFingerEventPointerId = ev.getPointerId(0);
            singleFingerEventPointerId = mSingleFingerEventPointerId;
        }/* w  w  w  .java 2  s .  co m*/
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (ev.getPointerCount() == 1)
            mSingleFingerEventPointerId = NOT_A_POINTER_ID;
    }
    try {
        //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/26
        mScaleGestureDetector.onTouchEvent(ev);
    } catch (IllegalArgumentException e) {
        //I have nothing I can do here.
    } catch (ArrayIndexOutOfBoundsException e) {
        //I have nothing I can do here.
    }
    //I'm going to pass the event to the super, only if it is a single touch, and the event is for the first finger
    //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300
    if (ev.getPointerCount() == 1 && ev.getPointerId(0) == singleFingerEventPointerId)
        return super.onTouchEvent(ev);
    else
        return false;
}

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;/*from   ww w.j  a  v  a2 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;
}

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);
    }// w  w  w .j a  va2  s.  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:ca.uqac.florentinth.speakerauthentication.CreateActivity.java

private void initGUI() {
    view = findViewById(R.id.create_layout);
    usernameInput = (EditText) findViewById(R.id.username_input);
    passwordInput = (EditText) findViewById(R.id.password_input);
    visibilityImage = (ImageView) findViewById(R.id.visibility);
    femaleRadio = (RadioButton) findViewById(R.id.radio_female);
    maleRadio = (RadioButton) findViewById(R.id.radio_male);
    createBtn = (Button) findViewById(R.id.btn_create);

    usernameInput.setText("user" + StringUtils.getCurrentDateTime());

    visibilityImage.setOnTouchListener(new View.OnTouchListener() {
        @Override/*from  w  ww .  j av a 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;
        }
    });

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

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View rootView = inflater.inflate(R.layout.test5_detail_fragment, container, false);

    // Set the content description for the following
    Spinner spinner = (Spinner) rootView.findViewById(R.id.test_5_spinner);
    spinner.setContentDescription("Spinner");
    ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.test_5_imageButton);
    imageButton.setContentDescription("Image button");

    // Each time this view is displayed, reset the following states
    SeekBar seekBar = (SeekBar) rootView.findViewById(R.id.test_5_seekBar);
    seekBar.setProgress(50);/*from  w w  w .  jav a 2  s  .c  o m*/
    seekBar.setContentDescription("Progress is 50 %");
    CheckBox checkbox = (CheckBox) rootView.findViewById(R.id.test_5_checkBox);
    checkbox.setChecked(false);

    // Register click event handlers for the following
    Button button = (Button) rootView.findViewById(R.id.test_5_button1);
    button.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            // we want an artificial crash
            throw new RuntimeException("Artificial crash to test UiWatcher");
        }
    });

    imageButton.setOnTouchListener(new ImageButton.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                resetTouchResults();
                collectStartAction(event, v);
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                collectEndAction(event, v);
                displayTouchResults();
            }
            return false;
        }
    });

    return rootView;
}

From source file:com.baidu.android.voicedemo.ActivityTouch.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sdk2_api);/*  w  ww .j a v a 2  s. c  o  m*/
    txtResult = (TextView) findViewById(R.id.txtResult);
    txtLog = (TextView) findViewById(R.id.txtLog);
    btn = (Button) findViewById(R.id.btn);
    setting = (Button) findViewById(R.id.setting);
    setting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent("com.baidu.speech.asr.demo.setting");
            startActivity(intent);
        }
    });
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));
    speechRecognizer.setRecognitionListener(this);

    speechTips = View.inflate(this, R.layout.bd_asr_popup_speech, null);
    speechWave = speechTips.findViewById(R.id.wave);
    speechTips.setVisibility(View.GONE);
    addContentView(speechTips, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    btn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                speechTips.setVisibility(View.VISIBLE);
                speechRecognizer.cancel();
                Intent intent = new Intent();
                bindParams(intent);
                intent.putExtra("vad", "touch");
                txtResult.setText("");
                txtLog.setText("");
                speechRecognizer.startListening(intent);
                return true;
            case MotionEvent.ACTION_UP:
                speechRecognizer.stopListening();
                speechTips.setVisibility(View.GONE);
                break;
            }
            return false;
        }
    });
}

From source file:com.android.audiorecorder.gallery.widget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onInterceptTouchEvent(event);
    }//from w  ww .j  a v a2s  .  c  om

    float[] difference = handleMotionEvent(event);

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

From source file:cn.iotguard.GalleryWidget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        ///*from   ww  w .j  av  a  2 s. c  om*/
        if (GalleryFileActivity.ll_dibumenu != null
                && GalleryFileActivity.ll_dibumenu.getVisibility() == View.GONE) {
            GalleryFileActivity.ll_dibumenu.setVisibility(View.VISIBLE);
        }
        if (Show_bigpic2.ll_dibumenu != null && Show_bigpic2.ll_dibumenu.getVisibility() == View.GONE) {
            Show_bigpic2.ll_dibumenu.setVisibility(View.VISIBLE);
        }

        //
        if (GalleryFileActivity.timeCount != null) {
            GalleryFileActivity.timeCount.cancel();
        }
        GalleryFileActivity.timeCount = new TimeCount_pic_dibu(Millis.pic_dibus, 1000);
        GalleryFileActivity.timeCount.start();
        System.out.println("pic    ");
        if (Show_bigpic2.timeCount != null) {
            Show_bigpic2.timeCount.cancel();
        }
        Show_bigpic2.timeCount = new TimeCount_pic_dibu_showbigpic2(Millis.pic_dibus, 1000);
        Show_bigpic2.timeCount.start();

        break;
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}