List of usage examples for android.view MotionEvent ACTION_UP
int ACTION_UP
To view the source code for android.view MotionEvent ACTION_UP.
Click Source Link
From source file:com.amazon.appstream.fireclient.FireClientActivity.java
/** * A "touch event" includes mouse motion when the mouse button * is down./*from ww w . j a v a 2 s . c om*/ */ @Override public boolean dispatchTouchEvent(MotionEvent event) { if (mKeyboardActive) { if (mGestureDetector.onTouchEvent(event)) { return true; } } if (super.dispatchTouchEvent(event)) return true; int flags = 0; if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN) { flags = AppStreamInterface.CET_TOUCH_FLAG; } event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_MOVE: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, flags); break; case MotionEvent.ACTION_DOWN: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_DOWN | flags); break; case MotionEvent.ACTION_UP: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_UP | flags); break; } return true; }
From source file:com.andlu6.teacup.viewpagerindicator.CirclePageIndicator.java
@SuppressLint("ClickableViewAccessibility") public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from www. j av a 2 s .com 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.android.app.MediaPlaybackActivity.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); TextView tv = textViewForContainer(v); if (tv == null) { return false; }/*w w w. ja v a 2s . co m*/ 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:io.selendroid.server.model.AndroidNativeElement.java
private void clickOnScreen(float x, float y) { SelendroidLogger.debug(String.format("Clicking at position [%f, %f]", x, y)); final ServerInstrumentation inst = ServerInstrumentation.getInstance(); long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis(); final MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0); final MotionEvent event2 = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0); try {//from w ww. ja v a 2 s. c om inst.sendPointerSync(event); inst.sendPointerSync(event2); try { Thread.sleep(300); } catch (InterruptedException ignored) { } } catch (SecurityException e) { SelendroidLogger.error("error while clicking element", e); } }
From source file:cl.monsoon.s1next.widget.PhotoView.java
@Override public boolean onDoubleTapEvent(MotionEvent e) { final int action = e.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: if (mQuickScaleEnabled) { mDownFocusX = e.getX();// w ww . j a v a 2s.c o m mDownFocusY = e.getY(); } break; case MotionEvent.ACTION_UP: if (mQuickScaleEnabled) { handled = scale(e); } break; case MotionEvent.ACTION_MOVE: if (mQuickScaleEnabled && mDoubleTapOccurred) { final int deltaX = (int) (e.getX() - mDownFocusX); final int deltaY = (int) (e.getY() - mDownFocusY); int distance = (deltaX * deltaX) + (deltaY * deltaY); if (distance > sTouchSlopSquare) { mDoubleTapOccurred = false; } } break; } return handled; }
From source file:com.aibinong.tantan.ui.widget.CircleNoPageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from w w w. j a v a2 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 a v a2 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:sjizl.com.FileUploadTest.java
@SuppressLint("NewApi") @Override// ww w .ja v a 2s . c o 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.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 av a2 s .com // 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:am.widget.tabstrip.TabStripHelper.java
boolean onTouchEvent(MotionEvent event) { if (mClickable) { final float x = event.getX(); final float y = event.getY(); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mClickPosition = PagerAdapter.POSITION_NONE; mDownX = x;/* ww w . ja va2 s. c om*/ mDownY = y; break; case MotionEvent.ACTION_UP: mClickPosition = PagerAdapter.POSITION_NONE; if (mPager != null && getPageCount() > 0) { if (mView instanceof TabStripView) mClickPosition = ((TabStripView) mView).getClickedPosition(mDownX, mDownY, x, y); else if (mView instanceof TabStripViewGroup) mClickPosition = ((TabStripViewGroup) mView).getClickedPosition(mDownX, mDownY, x, y); } break; case MotionEvent.ACTION_CANCEL: mClickPosition = PagerAdapter.POSITION_NONE; break; } } if (mDoubleClickable) { final float x = event.getX(); final float y = event.getY(); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mFirstDownX = mSecondDownX; mFirstDownY = mSecondDownY; mSecondDownX = x; mSecondDownY = y; break; case MotionEvent.ACTION_UP: final long downTime = event.getDownTime(); if (mLastUpTime != 0 && downTime - mLastUpTime < DOUBLE_TAP_TIMEOUT) { mDoubleClicked = true; if (mView instanceof TabStripView) mFirstPosition = ((TabStripView) mView).getClickedPosition(mFirstDownX, mFirstDownY, mFirstUpX, mFirstUpY); else if (mView instanceof TabStripViewGroup) mFirstPosition = ((TabStripViewGroup) mView).getClickedPosition(mFirstDownX, mFirstDownY, mFirstUpX, mFirstUpY); if (mView instanceof TabStripView) mSecondPosition = ((TabStripView) mView).getClickedPosition(mSecondDownX, mSecondDownY, x, y); else if (mView instanceof TabStripViewGroup) mSecondPosition = ((TabStripViewGroup) mView).getClickedPosition(mSecondDownX, mSecondDownY, x, y); mLastUpTime = 0; } else { mDoubleClicked = false; mFirstPosition = PagerAdapter.POSITION_NONE; mSecondPosition = PagerAdapter.POSITION_NONE; mFirstUpX = x; mFirstUpY = y; mLastUpTime = event.getEventTime(); } break; case MotionEvent.ACTION_CANCEL: break; } } return false; }