List of usage examples for android.view MotionEvent getRawX
public final float getRawX()
From source file:com.taobao.weex.ui.view.listview.BaseBounceView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (mGestureDetector != null) { mGestureDetector.onTouchEvent(ev); }/*from w w w . ja v a 2 s . c o m*/ switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { if (ev.getEdgeFlags() != 0) { return false; } mLastMotionX = ev.getRawX(); mLastMotionY = ev.getRawY(); mScrollValue = -getPaddingTop(); return mIsBeingDragged; } case MotionEvent.ACTION_MOVE: { if (mIsBeingDragged) { float y = ev.getRawY(); startPull(y); return true; } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { if (mIsBeingDragged) { this.mScrollValue = -getPaddingTop(); mIsBeingDragged = false; onTouchActionUp(); if (mMaxPadding > 0) { /** * 1.listview?paddingTop?0????0deltaY?paddingTop < 0 * 2.listview??PADDING????PADDINGdeltaY(-PADDING - getPaddingTop()) > 0 * bug: * listview item?2?listview??pull * fix * listview?? */ if (getPaddingTop() > 0/*|| getPaddingTop() < -mMaxPadding*/) { mScrollValue = getPaddingTop() > 0 ? 0 : -mMaxPadding; backToInitPos(getPaddingTop(), getPaddingTop() > 0 ? -getPaddingTop() : (-mMaxPadding - getPaddingTop())); } } else { backToInitPos(getScrollY(), -getScrollY()); } mMode = null; return true; } break; } } return false; }
From source file:org.smart.library.widget.SlideSwitch.java
@Override public boolean onTouchEvent(MotionEvent event) { if (slideable == false) return super.onTouchEvent(event); L.i("onTouchEvent"); getParent().requestDisallowInterceptTouchEvent(true); int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: eventStartX = (int) event.getRawX(); break;/*w w w. ja va 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; boolean toRight = (frontRect_left_begin > max_left / 2 ? true : false); if (Math.abs(wholeX) < 3) { toRight = !toRight; } moveToDest(toRight); break; default: break; } return true; }
From source file:org.lunci.dumbthing.fragment.MainDisplayFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAdapter = new DumbItemSimpleAdapter(getActivity(), R.layout.dumb_display_item_simple); mDetector = new GestureDetectorCompat(getActivity(), new GestureDetector.OnGestureListener() { private static final float ThresholdDistance = 50; private static final float ThresholdVelocity = 1000; @Override/*from www. j a va 2 s .co m*/ public boolean onDown(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e1 == null || e2 == null) return false; final float distanceX = e1.getRawX() - e2.getRawX(); if (distanceX < -ThresholdDistance && velocityX > ThresholdVelocity) { return mViewHolder.showPrevious(); } else if (distanceX > ThresholdDistance && velocityX < -ThresholdVelocity) { return mViewHolder.showNext(); } return true; } }); if (savedInstanceState != null) { savedInstanceState.setClassLoader(DumbModel.class.getClassLoader()); final ArrayList<Parcelable> list = savedInstanceState.getParcelableArrayList(EXTRA_ITEMS); for (Parcelable p : list) { mAdapter.add((DumbModel) p); } } }
From source file:com.mingle.discolor.PagerSlidingTabStrip.java
public void setViewPager(ViewPager pager) { this.pager = pager; if (colors != null) { setBackgroundColor(colors[pager.getCurrentItem()]); }//from w w w. j a va 2 s . c om if (pager.getAdapter() == null) { throw new IllegalStateException("ViewPager does not have adapter instance."); } pager.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startX = event.getRawX(); direction = ScrollDirection.SCROLL_DIRECTION_NONE; break; case MotionEvent.ACTION_MOVE: if (event.getRawX() > startX) { direction = ScrollDirection.SCROLL_DIRECTION_LEFT; } else { direction = ScrollDirection.SCROLL_DIRECTION_RIGHT; } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: break; } return false; } }); pager.setOnPageChangeListener(pageListener); notifyDataSetChanged(); }
From source file:com.fortysevendeg.android.swipelistview.SwipeListViewTouchListener.java
protected void actionUp(MotionEvent motionEvent) { if (mVelocityTracker == null || !mSwiping) { return;// w w w.j a v a2 s . c o m } float deltaX = motionEvent.getRawX() - mDownX; mVelocityTracker.addMovement(motionEvent); mVelocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(mVelocityTracker.getXVelocity()); if (!mOpened.get(mDownPosition)) { if (mSwipeMode == SwipeListView.SWIPE_MODE_LEFT && mVelocityTracker.getXVelocity() > 0) { velocityX = 0; } if (mSwipeMode == SwipeListView.SWIPE_MODE_RIGHT && mVelocityTracker.getXVelocity() < 0) { velocityX = 0; } } float velocityY = Math.abs(mVelocityTracker.getYVelocity()); boolean swap = false; boolean swapRight = false; if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX) { swapRight = mVelocityTracker.getXVelocity() > 0; swap = !(mOpened.get(mDownPosition) && mOpenedRight.get(mDownPosition) && swapRight) && !(mOpened.get(mDownPosition) && !mOpenedRight.get(mDownPosition) && !swapRight); } else if (Math.abs(deltaX) > mViewWidth / 2) { swap = true; swapRight = deltaX > 0; } generateAnimate(mFrontView, swap, swapRight, mDownPosition); mVelocityTracker.recycle(); mVelocityTracker = null; mDownX = 0; // change clickable front view if (swap) { mFrontView.setClickable(mOpened.get(mDownPosition)); mFrontView.setLongClickable(mOpened.get(mDownPosition)); } mFrontView = null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; }
From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java
/** * Manually starts the reorder process for the specified view. This should not be used if the {@link #setDragHandleId(int)} is * set and should control the reordering. * * @param view The View to start reordering * @param startMotionEvent The MotionEvent that starts the reorder *///from w w w .j av a 2 s. c om public void startReorder(View view, @Nullable MotionEvent startMotionEvent) { if (dragState == DragState.DRAGGING) { return; } if (startMotionEvent != null) { fingerOffset = new PointF(startMotionEvent.getRawX(), startMotionEvent.getRawY()); int[] rawViewLoc = new int[2]; view.getLocationOnScreen(rawViewLoc); fingerOffset.x = rawViewLoc[0] - fingerOffset.x; fingerOffset.y = rawViewLoc[1] - fingerOffset.y; } dragState = DragState.DRAGGING; dragItem = createDragBitmap(view); selectedDragItemPosition = recyclerView.getChildAdapterPosition(view); }
From source file:timer.com.maydaysdk.MayDayVideoCallFragment.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View viewInfo = inflater.inflate(R.layout.videochat, container, false); // Initialize view mLinearLayoutControls = (LinearLayout) viewInfo.findViewById(R.id.linearLayout_Controls); mLinearLayoutVideo = (LinearLayout) viewInfo.findViewById(R.id.linearLayout_video); mImageViewMute = (ImageView) viewInfo.findViewById(R.id.imageView_mute_audio); mImageViewFullScreen = (ImageView) viewInfo.findViewById(R.id.imageView_fullscreen); mImageViewAnswer = (ImageView) viewInfo.findViewById(R.id.imageView_answer); ImageView imageViewHang = (ImageView) viewInfo.findViewById(R.id.imageView_hangup); mAlertDialog = new AlertDialog.Builder(getActivity()).create(); mImageViewFullScreen.setOnClickListener(this); mImageViewMute.setOnClickListener(this); imageViewHang.setOnClickListener(this); mImageViewAnswer.setOnClickListener(this); Bundle bundle = getArguments();/*from ww w .j a v a 2 s . c o m*/ if (bundle.getString(MayDayConstant.AGENT_NAME) != null) { mAgentName = bundle.getString(MayDayConstant.AGENT_NAME); } if (bundle.getString(MayDayConstant.DOMAIN_ADDRESS) != null) { mDomainAddress = bundle.getString(MayDayConstant.DOMAIN_ADDRESS); } if (bundle.getString(MayDayConstant.VIDEO_CALL) != null) { mVideoCall = bundle.getString(MayDayConstant.VIDEO_CALL); } try { //get last device register name mDevice = RCClient.listDevices().get(0); } catch (NullPointerException e) { e.printStackTrace(); } mScalingType = VideoRendererGui.ScalingType.SCALE_ASPECT_FILL; mVideoView = (GLSurfaceView) viewInfo.findViewById(R.id.glView_call); final Intent intent = getActivity().getIntent(); if (intent.getExtras() != null) { if (intent.getAction().equals(RCDevice.OUTGOING_CALL) || intent.getAction().equals(RCDevice.INCOMING_MESSAGE)) { mImageViewAnswer.setVisibility(View.INVISIBLE); } else { mImageViewAnswer.setVisibility(View.VISIBLE); } } // Get device resolution width and height Point size = new Point(); getActivity().getWindowManager().getDefaultDisplay().getSize(size); final int windowWidth = size.x; final int windowHeight = size.y; // GLVideo resize from top to left corner mLinearLayoutVideo.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mLinearLayoutVideo .getLayoutParams(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: int x_cord = (int) event.getRawX(); int y_cord = (int) event.getRawY(); if (x_cord > windowWidth) { x_cord = windowWidth; } if (y_cord > windowHeight) { y_cord = windowHeight; } layoutParams.leftMargin = x_cord - LEFT_MARGIN; layoutParams.topMargin = y_cord - TOP_MARGIN; mLinearLayoutVideo.setLayoutParams(layoutParams); break; default: break; } return true; } }); // Setup video stuff VideoRendererGui.setView(mVideoView, new Runnable() { @Override public void run() { if (mVideoCall != null) { if (mVideoCall.equalsIgnoreCase(MayDayConstant.OUTGOING)) { callAgent(); } } else { videoContextReady(intent); } } }); // Create video renderers. mRemoteRender = VideoRendererGui.create(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIGHT, mScalingType, false); mLocalRender = VideoRendererGui.create(LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, mScalingType, true); mImageViewMute.setVisibility(View.INVISIBLE); return viewInfo; }
From source file:arun.com.chromer.webheads.ui.views.WebHead.java
private void handleTouchDown(@NonNull MotionEvent event) { dragging = false;//from www . j a va2s .com movementTracker.onDown(); initialDownX = windowParams.x; initialDownY = windowParams.y; posX = event.getRawX(); posY = event.getRawY(); if (master) { masterDownX = (int) posX; masterDownY = (int) posY; } touchDown(); cancelCoastingTask(); }
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; }/* w w w .jav a2s. c o m*/ 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.haarman.listviewanimations.itemmanipulation.SwipeDismissListViewTouchListener.java
private boolean handleDownEvent(MotionEvent motionEvent) { if (mPaused) { return false; }/*from w ww . j a va2s . co m*/ mSwipeInitiated = false; // Find the child view that was touched (perform a hit test) Rect rect = new Rect(); int childCount = mListView.getChildCount(); int[] listViewCoords = new int[2]; mListView.getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; View downView = null; for (int i = 0; i < childCount && downView == null; i++) { View child = mListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { downView = child; } } if (downView != null) { Log.d("SwipeDismissListViewTouchListener", "hit child !"); mDownX = motionEvent.getRawX(); mDownY = motionEvent.getRawY(); int downPosition = mListView.getPositionForView(downView); mCurrentDismissData = createPendingDismissData(downPosition, downView); if (mPendingDismisses.contains(mCurrentDismissData) || downPosition >= mVirtualListCount) { // Cancel, we're already processing this position mCurrentDismissData = null; return false; } else { mTouchChildTouched = !mIsParentHorizontalScrollContainer && (mResIdOfTouchChild == 0); if (mResIdOfTouchChild != 0) { mIsParentHorizontalScrollContainer = false; final View childView = downView.findViewById(mResIdOfTouchChild); if (childView != null) { final Rect childRect = getChildViewRect(mListView, childView); if (childRect.contains((int) mDownX, (int) mDownY)) { mTouchChildTouched = true; mListView.requestDisallowInterceptTouchEvent(true); } } } if (mIsParentHorizontalScrollContainer) { // Do it now and don't wait until the user moves more than // the slop factor. mTouchChildTouched = true; mListView.requestDisallowInterceptTouchEvent(true); } mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); } } return true; }