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:cl.ipp.katbag.fragment.Player.java
public void setSensing(String[] line, int lineNumber) { switch (Integer.parseInt(line[3])) { case 0://from w w w . j a v a 2 s . c o m boolean ex = false; for (int z = 0; z < touchEventId.size(); z++) { if (line[0].contentEquals(String.valueOf(touchEventId.get(z)))) { ex = true; break; } } if (!ex) { int last = -1; for (int i = lineNumber + 1; i < develop.size(); i++) { String[] it = develop.get(i).split("&&"); last = i; if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) { last--; break; } } if ((lineNumber + 1) <= last) { touchEventId.add(Integer.valueOf(line[0])); touchEventDrawing.add(Integer.valueOf(line[4])); // drawing touchEventBgn.add(lineNumber + 1); // begin in touchEventLst.add(last); // ends final KatbagDrawing drawing = (KatbagDrawing) v.findViewById(Integer.valueOf(line[4])); if (drawing != null) { drawing.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: for (int i = 0; i < touchEventDrawing.size(); i++) { if (touchEventDrawing.get(i) == drawing.getId()) { setBranchTreeCondition(touchEventId.get(i), 1); if (checkTreeCondition(touchEventId.get(i))) { Log.d("ply", "touchEventDrawing - ini:" + touchEventBgn.get(i) + ", last:" + touchEventLst.get(i)); play(touchEventBgn.get(i), touchEventLst.get(i) + 1); break; } } } break; case MotionEvent.ACTION_UP: for (int i = 0; i < touchEventDrawing.size(); i++) { if (touchEventDrawing.get(i) == drawing.getId()) { setBranchTreeCondition(touchEventId.get(i), 0); break; } } break; } return true; } }); Log.d("ply", "setSensing - touchEvent add! count:" + touchEventId.size() + ", drawing:" + touchEventDrawing.get(touchEventDrawing.size() - 1) + " ini:" + touchEventBgn.get(touchEventBgn.size() - 1) + " last:" + touchEventLst.get(touchEventLst.size() - 1)); } } if (last > -1) if ((last + 1) < develop.size()) play((last + 1), develop.size()); } break; case 1: boolean ex1 = false; for (int z = 0; z < shakeId.size(); z++) { if (line[0].contentEquals(String.valueOf(shakeId.get(z)))) { ex1 = true; break; } } if (!ex1) { int last1 = -1; for (int i = lineNumber + 1; i < develop.size(); i++) { String[] it = develop.get(i).split("&&"); last1 = i; if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) { last1--; break; } } if ((lineNumber + 1) <= last1) { shakeId.add(Integer.valueOf(line[0])); shakeBgn.add(lineNumber + 1); // begin in shakeLst.add(last1); // ends sensorManager = (SensorManager) mainActivity.context.getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_FASTEST); useAccelerometer = true; Log.d("ply", "setSensing - shake add! count:" + shakeId.size() + ", ini:" + shakeBgn.get(shakeBgn.size() - 1) + " last:" + shakeLst.get(shakeLst.size() - 1)); } if (last1 > -1) if ((last1 + 1) < develop.size()) play((last1 + 1), develop.size()); } break; } }
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*from ww w . j av a2 s .com*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchX = ev.getX(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderX = 0; break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float x = MotionEventCompat.getX(ev, index); final float dx = x - mLastTouchX + mTouchRemainderX; final int deltaX = (int) dx; mTouchRemainderX = dx - deltaX; if (Math.abs(dx) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchX = x; if (!trackMotionScroll(deltaX, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } } break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId); if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, (int) velocity, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); mLastTouchX = 0; ViewCompat.postInvalidateOnAnimation(this); } else { mTouchMode = TOUCH_MODE_IDLE; } } break; } return true; }
From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) { return false; }/*from ww w .j a v a 2 s . c o m*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsDragging = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsDragging) { return true; } else if (mIsUnableToDrag) { return false; } } switch (action) { case MotionEvent.ACTION_MOVE: final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastY; final float yDiff = Math.abs(y - mLastY); if (mOnInteractListener != null) { boolean isControlled = mOnInteractListener.onInterceptActionMove(x, y); if (isControlled) { break; } } if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) { mIsDragging = true; mLastX = x; setDrawingCacheEnabled(true); } else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) { mIsDragging = true; mLastY = y; setDrawingCacheEnabled(true); } break; case MotionEvent.ACTION_DOWN: mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK : MotionEventCompat.ACTION_POINTER_INDEX_MASK); mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId); mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId); if (allowSlidingFromHereX(ev, mInitialX)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else if (allowSlidingFromHereY(ev, mInitialY)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsDragging) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsDragging; }
From source file:com.aiga.events.android.views.NoScrollSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;//from ww w.jav a2 s.c o m mDownEvent = MotionEvent.obtain(event); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart && !mRefreshing && !mUserInteracting) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh mUserInteracting = true; startRefresh(); handled = true; break; } // Just track the user's movement setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); updatePositionTimeout(); handled = true; } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mUserInteracting = false; if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:cn.colink.commumication.swipelistview.SwipeListView.java
/** * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent) *///from w w w .j a va2s .co m @Override public boolean onInterceptTouchEvent(MotionEvent ev) { int action = MotionEventCompat.getActionMasked(ev); final float x = ev.getX(); final float y = ev.getY(); if (touchState == TOUCH_STATE_SCROLLING_X) { return touchListener.onTouch(this, ev); } switch (action) { case MotionEvent.ACTION_MOVE: checkInMoving(x, y); return touchState == TOUCH_STATE_SCROLLING_Y; case MotionEvent.ACTION_DOWN: touchListener.onTouch(this, ev); touchState = TOUCH_STATE_REST; lastMotionX = x; lastMotionY = y; return false; case MotionEvent.ACTION_CANCEL: touchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_UP: touchListener.onTouch(this, ev); return touchState == TOUCH_STATE_SCROLLING_Y; default: break; } return super.onInterceptTouchEvent(ev); }
From source file:com.astuetz.viewpager.extensions.SwipeyTabsView.java
@Override public boolean onTouch(View v, MotionEvent event) { float x = event.getRawX(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDragX = x;/*ww w . j a v a 2 s .c om*/ mPager.beginFakeDrag(); break; case MotionEvent.ACTION_MOVE: if (!mPager.isFakeDragging()) break; mPager.fakeDragBy((mDragX - x) * (-1)); mDragX = x; break; case MotionEvent.ACTION_UP: if (!mPager.isFakeDragging()) break; mPager.endFakeDrag(); break; } return v.equals(this) ? true : super.onTouchEvent(event); }
From source file:com.android.deskclock.alarms.AlarmActivity.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { if (mAlarmHandled) { LogUtils.v(LOGTAG, "onTouch ignored: %s", motionEvent); return false; }/*ww w . j a v a 2 s . com*/ final int[] contentLocation = { 0, 0 }; mContentView.getLocationOnScreen(contentLocation); final float x = motionEvent.getRawX() - contentLocation[0]; final float y = motionEvent.getRawY() - contentLocation[1]; final int alarmLeft = mAlarmButton.getLeft() + mAlarmButton.getPaddingLeft(); final int alarmRight = mAlarmButton.getRight() - mAlarmButton.getPaddingRight(); final float snoozeFraction, dismissFraction; if (mContentView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x); dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x); } else { snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x); dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x); } setAnimatedFractions(snoozeFraction, dismissFraction); switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: LogUtils.v(LOGTAG, "onTouch started: %s", motionEvent); // Stop the pulse, allowing the last pulse to finish. mPulseAnimator.setRepeatCount(0); break; case MotionEvent.ACTION_UP: LogUtils.v(LOGTAG, "onTouch ended: %s", motionEvent); if (snoozeFraction == 1.0f) { snooze(); } else if (dismissFraction == 1.0f) { dismiss(); } else { if (snoozeFraction > 0.0f || dismissFraction > 0.0f) { // Animate back to the initial state. AnimatorUtils.reverse(mAlarmAnimator, mSnoozeAnimator, mDismissAnimator); } else if (mAlarmButton.getTop() <= y && y <= mAlarmButton.getBottom()) { // User touched the alarm button, hint the dismiss action hintDismiss(); } // Restart the pulse. mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE); if (!mPulseAnimator.isStarted()) { mPulseAnimator.start(); } } break; case MotionEvent.ACTION_CANCEL: resetAnimations(); break; default: break; } return true; }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent me) { if (mGestureDetector.onTouchEvent(me)) { return true; }/*from w w w .j a v a 2 s . c o m*/ int action = me.getAction(); final int x = (int) me.getX(); final int y = (int) me.getY(); mTouchX = x; switch (action) { case MotionEvent.ACTION_DOWN: invalidate(); break; case MotionEvent.ACTION_MOVE: if (y <= 0) { // Fling up!? //Fling up should be a hacker's way to delete words (user dictionary words) if (mSelectedString != null) { Logger.d(TAG, "Fling up from candidates view. Deleting word at index %d, which is %s", mSelectedIndex, mSelectedString); mService.removeFromUserDictionary(mSelectedString.toString()); clear(); } } break; case MotionEvent.ACTION_UP: if (!mScrolled) { if (mSelectedString != null) { if (mShowingAddToDictionary) { final CharSequence word = mSuggestions.get(0); if (word.length() >= 2 && !mNoticing) { Logger.d(TAG, "User wants to add the word '%s' to the user-dictionary.", word); boolean added = mService.addWordToDictionary(word.toString()); if (!added) { Logger.w(TAG, "Failed to add word to user-dictionary!"); } } } else if (!mNoticing) { mService.pickSuggestionManually(mSelectedIndex, mSelectedString); } else if (mSelectedIndex == 1 && !TextUtils.isEmpty(mJustAddedWord)) { // 1 is the index of "Remove?" Logger.d(TAG, "User wants to remove an added word '%s'", mJustAddedWord); mService.removeFromUserDictionary(mJustAddedWord.toString()); } } } invalidate(); break; } return true; }
From source file:android.widget.PinnedHeaderListView.java
@Override public boolean onTouchEvent(final MotionEvent ev) { if (mHeaderTouched) { if (ev.getAction() == MotionEvent.ACTION_UP) mHeaderTouched = false;// w ww. j a v a 2s .c om return true; } return super.onTouchEvent(ev); }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
@Override public boolean onTouchEvent(MotionEvent event) { final int x = (int) (event.getX() + 0.5f); final int y = (int) (event.getY() + 0.5f); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = x;//from w w w. ja va 2 s . com mDownY = y; mInitialTarget = getDayAtLocation(mDownX, mDownY); if (mInitialTarget < 0) { return false; } if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); break; case MotionEvent.ACTION_MOVE: if (!isStillAClick(x, y)) { if (mPendingCheckForTap != null) { removeCallbacks(mPendingCheckForTap); } mInitialTarget = -1; if (mTouchedItem >= 0) { mTouchedItem = -1; invalidate(); } } break; case MotionEvent.ACTION_UP: onDayClicked(mInitialTarget); // Fall through. case MotionEvent.ACTION_CANCEL: if (mPendingCheckForTap != null) { removeCallbacks(mPendingCheckForTap); } // Reset touched day on stream end. mTouchedItem = -1; mInitialTarget = -1; invalidate(); break; } return true; }