List of usage examples for android.view MotionEvent ACTION_CANCEL
int ACTION_CANCEL
To view the source code for android.view MotionEvent ACTION_CANCEL.
Click Source Link
From source file:com.android.app.MediaPlaybackActivity.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); TextView tv = textViewForContainer(v); if (tv == null) { return false; }//ww w.ja v a 2 s . com if (action == MotionEvent.ACTION_DOWN) { v.setBackgroundColor(0xff606060); mInitialX = mLastX = (int) event.getX(); mDraggingLabel = false; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { v.setBackgroundColor(0); if (mDraggingLabel) { Message msg = mLabelScroller.obtainMessage(0, tv); mLabelScroller.sendMessageDelayed(msg, 1000); } } else if (action == MotionEvent.ACTION_MOVE) { if (mDraggingLabel) { int scrollx = tv.getScrollX(); int x = (int) event.getX(); int delta = mLastX - x; if (delta != 0) { mLastX = x; scrollx += delta; if (scrollx > mTextWidth) { // scrolled the text completely off the view to the left scrollx -= mTextWidth; scrollx -= mViewWidth; } if (scrollx < -mViewWidth) { // scrolled the text completely off the view to the right scrollx += mViewWidth; scrollx += mTextWidth; } tv.scrollTo(scrollx, 0); } return true; } int delta = mInitialX - (int) event.getX(); if (Math.abs(delta) > mTouchSlop) { // start moving mLabelScroller.removeMessages(0, tv); // Only turn ellipsizing off when it's not already off, because it // causes the scroll position to be reset to 0. if (tv.getEllipsize() != null) { tv.setEllipsize(null); } Layout ll = tv.getLayout(); // layout might be null if the text just changed, or ellipsizing // was just turned off if (ll == null) { return false; } // get the non-ellipsized line width, to determine whether scrolling // should even be allowed mTextWidth = (int) tv.getLayout().getLineWidth(0); mViewWidth = tv.getWidth(); if (mViewWidth > mTextWidth) { tv.setEllipsize(TruncateAt.END); v.cancelLongPress(); return false; } mDraggingLabel = true; tv.setHorizontalFadingEdgeEnabled(true); v.cancelLongPress(); return true; } } return false; }
From source file:com.aibinong.tantan.ui.widget.CircleNoPageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/* w w w.ja v a 2 s . c om*/ // if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { // return false; // } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; // if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { // mViewPager.fakeDragBy(deltaX); // } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mRealCountGetter.getRealCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { // mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { // mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; // if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.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); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:android.hqs.view.pager.indicator.CirclePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }// w w w .j av a 2 s . c o m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.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); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.elderly.elderly.component.ElderlyCirclePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*w w w. j a v a 2s .c o m*/ if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.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); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.curiouslybuilt.splashvideo.app.CirclePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/* w w w .j a v a2 s . c om*/ if ((mViewPager == null) || (mAdapter.getActualCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mAdapter.getActualCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.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); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.coco.slidinguppanel.SlidingUpPanel.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // This method JUST determines whether we want to intercept the motion. // If we return true, onMotionEvent will be called and we do the actual // scrolling there. final int action = MotionEventCompat.getActionMasked(ev); // Always take care of the touch gesture being complete. if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { // Release the drag. DEBUG_LOG("Intercept done!"); endDrag();/*from w w w. j a v a 2 s. co m*/ return false; } // Nothing more to do here if we have decided whether or not we are dragging. if (action != MotionEvent.ACTION_DOWN) { if (mIsBeingDragged) { DEBUG_LOG("Intercept returning true!"); return true; } if (mIsUnableToDrag) { DEBUG_LOG("Intercept returning false!"); return false; } } // Check whether the user has moved far enough from his original down touch. switch (action) { case MotionEvent.ACTION_DOWN: { onTouchDown(ev, true); DEBUG_LOG("***Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged + " mIsUnableToDrag=" + mIsUnableToDrag); break; } case MotionEvent.ACTION_MOVE: { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); final float xDiff = Math.abs(x - mInitialMotionX); final float yDiff = Math.abs(y - mInitialMotionY); DEBUG_LOG("***Moved to " + x + "," + y + " diff=" + xDiff + "," + yDiff); onTouchMove(x, y, xDiff, yDiff, true); break; } case MotionEvent.ACTION_POINTER_UP: onTouchPointerUp(ev); break; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); // The only time we want to intercept motion events is if we are in the drag mode. return mIsBeingDragged; }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
public boolean areTouchesDisabled(MotionEvent motionEvent) { if (motionEvent != null && mTouchesAreDisabledTillLastFingerIsUp) { //calculate new value for mTouchesAreDisabledTillLastFingerIsUp //when do we reset the mTouchesAreDisabledTillLastFingerIsUp flag: //Only if we have a single pointer //and:/* w w w. j a v a2 s. c o m*/ // CANCEL - the single pointer has been cancelled. So no pointers // UP - the single pointer has been lifted. So now we have no pointers down. // DOWN - this is the first action from the single pointer, so we already were in no-pointers down state. final int action = MotionEventCompat.getActionMasked(motionEvent); if (MotionEventCompat.getPointerCount(motionEvent) == 1 && (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP)) { mTouchesAreDisabledTillLastFingerIsUp = false; //If the action is UP then we will return the previous value (which is TRUE), since the motion events are disabled until AFTER //the UP event, so if this event resets the flag, this event should still be disregarded. return action == MotionEvent.ACTION_UP; } } return mTouchesAreDisabledTillLastFingerIsUp; }
From source file:sjizl.com.FileUploadTest.java
@SuppressLint("NewApi") @Override// ww w. j a v a 2s. co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.fileuploadtest2); //ac_image_grid TextView textView2_under_title; final ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext())); progressBar_hole = (ProgressBar) findViewById(R.id.progressBar_hole); progressBar_hole.setVisibility(View.INVISIBLE); right_lin = (LinearLayout) findViewById(R.id.right_lin); rand = CommonUtilities.randInt(111, 999); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); //right_lin.setBackgroundColor(Color.BLUE); right_lin = (LinearLayout) findViewById(R.id.right_lin); left_lin1 = (LinearLayout) findViewById(R.id.left_lin1); left_lin3 = (LinearLayout) findViewById(R.id.left_lin3); left_lin4 = (LinearLayout) findViewById(R.id.left_lin4); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); upload_photo_text = (LinearLayout) findViewById(R.id.upload_photo_text); textView2_under_title = (TextView) findViewById(R.id.textView2_under_title); ((LinearLayout) textView2_under_title.getParent()).removeView(textView2_under_title); textView2_under_title.setVisibility(View.GONE); ImageView imageView2_dashboard = (ImageView) findViewById(R.id.imageView2_dashboard); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } Button upload_photo0 = (Button) findViewById(R.id.upload_photo0); Button upload_photo1 = (Button) findViewById(R.id.upload_photo1); Button upload_photo2 = (Button) findViewById(R.id.upload_photo2); upload_photo0.setVisibility(View.GONE); upload_photo1.setVisibility(View.GONE); upload_photo2.setVisibility(View.GONE); upload_photo0.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CommonUtilities.custom_toast(getApplicationContext(), FileUploadTest.this, "UploadActivity! ", null, R.drawable.iconbd); Intent dashboard = new Intent(getApplicationContext(), UploadActivity.class); startActivity(dashboard); } }); upload_photo1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); upload_photo2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); final ImageView left_button; left_button = (ImageView) findViewById(R.id.imageView1_back); Button button1 = (Button) findViewById(R.id.upload_photo1); SharedPreferences sp = getApplicationContext().getSharedPreferences("loginSaved", Context.MODE_PRIVATE); naam = sp.getString("naam", null); username = sp.getString("username", null); password = sp.getString("password", null); foto = sp.getString("foto", null); foto_num = sp.getString("foto_num", null); imageLoader.displayImage("http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, imageView2_dashboard, options); Brows(); listView.setLongClickable(true); registerForContextMenu(listView); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //startImagePagerActivity(position); if (position == 0) { openGallery(SELECT_FILE1); } else { listView.showContextMenuForChild(view); // registerForContextMenu(view); // openContextMenu(view); // unregisterForContextMenu(view); } } }); left_lin1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) { left_lin1.setBackgroundColor(Color.DKGRAY); v.setBackgroundColor(Color.DKGRAY); onBackPressed(); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { left_lin1.setBackgroundColor(Color.BLACK); v.setBackgroundColor(Color.BLACK); } return false; } }); CommonUtilities u = new CommonUtilities(); u.setHeaderConrols(getApplicationContext(), this, right_lin, left_lin3, left_lin4, left_lin1, left_button); ; middle_lin.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) { middle_lin.setBackgroundColor(Color.DKGRAY); v.setBackgroundColor(Color.DKGRAY); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { middle_lin.setBackgroundColor(Color.BLACK); v.setBackgroundColor(Color.BLACK); } return false; } }); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
public void disableTouchesTillFingersAreUp() { mHandler.cancelAllMessages();/*from w w w.j a v a2 s . c om*/ mHandler.dismissPreview(0); dismissPopupKeyboard(); for (PointerTracker tracker : mPointerTrackers) { Log.d(TAG, "Canceling tracker " + tracker.getKeyIndex()); sendOnXEvent(MotionEvent.ACTION_CANCEL, 0, 0, 0, tracker); tracker.setAlreadyProcessed(); } mTouchesAreDisabledTillLastFingerIsUp = true; }
From source file:com.davis.kangpinhui.views.HorizontalListView.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: for (View view : mConflictViews) { if (view == null) { continue; }// ww w . ja v a 2 s . c om if (view instanceof ViewPager) { ((ViewPager) view).requestDisallowInterceptTouchEvent(true); } if (view instanceof SwipeRefreshLayout) { view.setEnabled(false); ((SwipeRefreshLayout) view).requestDisallowInterceptTouchEvent(true); } } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: for (View view : mConflictViews) { if (view == null) { continue; } view.setEnabled(true); } break; } return super.dispatchTouchEvent(ev); }