List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:com.bobomee.android.recyclerviewhelper.fastscroll.FastScroller.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: if (event.getX() < handle.getX() - ViewCompat.getPaddingStart(handle)) return false; if (currentAnimator != null) currentAnimator.cancel();// w w w . ja v a2 s . co m handle.setSelected(true); mOnScrollStateChange.onFastScrollerStateChange(true); showBubble(); case MotionEvent.ACTION_MOVE: float y = event.getY(); setBubbleAndHandlePosition(y); onScrollPosition(y); return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: handle.setSelected(false); mOnScrollStateChange.onFastScrollerStateChange(false); hideBubble(); return true; } return super.onTouchEvent(event); }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent me) { if (mGestureDetector.onTouchEvent(me)) { return true; }//ww w.j a v a2 s .co 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:com.bluetech.gallery5.ui.ImageDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { /*/* ww w. ja v a2s .c om*/ // Inflate and locate the main ImageView final View v = inflater.inflate(R.layout.image_detail_fragment, container, false); mImageView = (ImageView) v.findViewById(R.id.imageRecycView); return v; */ final View v = inflater.inflate(R.layout.image_detail_fragment, container, false); mImageView = (ImageView) v.findViewById(R.id.imageRecycView); //ImageView img = new ImageView(getActivity()); mImageView.setPadding(6, 6, 6, 6); // mImageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)) ; //ImageViewHelperURL.setUrlDrawable((ImageView) img, url, R.drawable.no_image) ; mImageView.setOnTouchListener(new View.OnTouchListener() { private static final String TAG = "SlideImageView"; // These matrices will be used to move and zoom image Matrix matrix = new Matrix(); Matrix savedMatrix = new Matrix(); // We can be in one of these 3 states static final int NONE = 0; static final int DRAG = 1; static final int ZOOM = 2; int mode = NONE; // Remember some things for zooming PointF start = new PointF(); PointF mid = new PointF(); float oldDist = 1f; @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; // Dump touch event to log dumpEvent(event); // Handle touch events here... switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: savedMatrix.set(matrix); start.set(event.getX(), event.getY()); Log.d(TAG, "mode=DRAG"); mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); Log.d(TAG, "oldDist=" + oldDist); if (oldDist > 10f) { savedMatrix.set(matrix); midPoint(mid, event); mode = ZOOM; Log.d(TAG, "mode=ZOOM"); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; Log.d(TAG, "mode=NONE"); break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { // ... matrix.set(savedMatrix); matrix.postTranslate(event.getX() - start.x, event.getY() - start.y); } else if (mode == ZOOM) { float newDist = spacing(event); Log.d(TAG, "newDist=" + newDist); if (newDist > 10f) { matrix.set(savedMatrix); float scale = newDist / oldDist; Log.d(TAG, "ZOOOOOOOM: " + scale); matrix.postScale(scale, scale, mid.x, mid.y); } } break; } view.setImageMatrix(matrix); return true; // indicate event was handled } /** Show an event in the LogCat view, for debugging */ private void dumpEvent(MotionEvent event) { String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" }; StringBuilder sb = new StringBuilder(); int action = event.getAction(); int actionCode = action & MotionEvent.ACTION_MASK; sb.append("event ACTION_").append(names[actionCode]); if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) { sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_ID_SHIFT); sb.append(")"); } sb.append("["); for (int i = 0; i < event.getPointerCount(); i++) { sb.append("#").append(i); sb.append("(pid ").append(event.getPointerId(i)); sb.append(")=").append((int) event.getX(i)); sb.append(",").append((int) event.getY(i)); if (i + 1 < event.getPointerCount()) sb.append(";"); } sb.append("]"); Log.d(TAG, sb.toString()); } /** Determine the space between the first two fingers */ private float spacing(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return (float) Math.sqrt(x * x + y * y); } /** Calculate the mid point of the first two fingers */ private void midPoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); } }); return v; }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { SimpleMonthAdapter.CalendarDay calendarDay = getDayFromLocation(event.getX(), event.getY()); if (calendarDay != null) { onDayClick(calendarDay);/*from w w w. j a va 2 s . c om*/ } } return true; }
From source file:android.widget.PinnedHeaderListView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent ev) { mHeaderTouched = false;/*from www .j a va2s . co m*/ if (super.onInterceptTouchEvent(ev)) return true; if (mScrollState == SCROLL_STATE_IDLE) { final int y = (int) ev.getY(); final int x = (int) ev.getX(); for (int i = mSize; --i >= 0;) { final PinnedHeader header = mHeaders[i]; // For RTL layouts, this also takes into account that the scrollbar is on the left // side. final int padding = getPaddingLeft(); if (header.visible && header.y <= y && header.y + header.height > y && x >= padding && padding + header.view.getWidth() >= x) { mHeaderTouched = true; if (mScrollToSectionOnHeaderTouch && ev.getAction() == MotionEvent.ACTION_DOWN) return smoothScrollToPartition(i); else return true; } } } return false; }
From source file:android.support.v7.widget.FastScroller.java
@Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent ev) { final boolean handled; if (mState == STATE_VISIBLE) { boolean insideVerticalThumb = isPointInsideVerticalThumb(ev.getX(), ev.getY()); boolean insideHorizontalThumb = isPointInsideHorizontalThumb(ev.getX(), ev.getY()); if (ev.getAction() == MotionEvent.ACTION_DOWN && (insideVerticalThumb || insideHorizontalThumb)) { if (insideHorizontalThumb) { mDragState = DRAG_X;/* w w w .j av a 2 s. co m*/ mHorizontalDragX = (int) ev.getX(); } else if (insideVerticalThumb) { mDragState = DRAG_Y; mVerticalDragY = (int) ev.getY(); } setState(STATE_DRAGGING); handled = true; } else { handled = false; } } else if (mState == STATE_DRAGGING) { handled = true; } else { handled = false; } return handled; }
From source file:com.appsimobile.appsii.SidebarHotspot.java
private boolean detectSwipe(float x, float y, MotionEvent e) { if (mState == STATE_AWAITING_RELEASE && mSwipeInProgress) { if (mCallback != null) { mSwipeListener.setSwipeLocation(this, (int) e.getX(), (int) e.getY(), (int) e.getRawX(), (int) e.getRawY()); }/*from w w w .j a v a2 s. c o m*/ return true; } if (mState != STATE_GESTURE_IN_PROGRESS) return false; float deltaX = Math.abs(x - mStartX); float deltaY = y - mStartY; Gesture action = detectAction(deltaX, deltaY, mMinimumMove); if (action != null) { mSwipeListener = mCallback.open(this, action, (int) x, (int) y); mSwipeInProgress = mSwipeListener != null; mState = STATE_AWAITING_RELEASE; return true; } return true; }
From source file:com.android.utils.ExploreByTouchHelper.java
/** * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when * the Explore by Touch feature is enabled. * <p>/*w w w . jav a 2 s. c o m*/ * This method should be called by overriding * {@link View#dispatchHoverEvent}: * * <pre> * @Override * public boolean dispatchHoverEvent(MotionEvent event) { * if (mHelper.dispatchHoverEvent(this, event) { * return true; * } * return super.dispatchHoverEvent(event); * } * </pre> * * @param event The hover event to dispatch to the virtual view hierarchy. * @return Whether the hover event was handled. */ public boolean dispatchHoverEvent(MotionEvent event) { if (!mManager.isTouchExplorationEnabled()) { return false; } int virtualViewId = getVirtualViewIdAt(event.getX(), event.getY()); if (virtualViewId == INVALID_ID) { virtualViewId = ROOT_ID; } switch (event.getAction()) { case MotionEvent.ACTION_HOVER_ENTER: case MotionEvent.ACTION_HOVER_MOVE: setHoveredVirtualViewId(virtualViewId); break; case MotionEvent.ACTION_HOVER_EXIT: setHoveredVirtualViewId(virtualViewId); break; } return true; }
From source file:com.android.andryyu.lifehelper.widget.RippleView.java
/** * Method that initializes all fields and sets listeners * * @param context Context used to create this view * @param attrs Attribute used to initialize fields */// w ww . j a v a 2 s. c o m private void init(final Context context, final AttributeSet attrs) { if (isInEditMode()) return; final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView); rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, Color.parseColor("#33626262")); rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0); hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false); isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false); rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration); frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate); rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha); ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0); canvasHandler = new Handler(); zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f); zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200); isListMode = typedArray.getBoolean(R.styleable.RippleView_rv_listMode, false); typedArray.recycle(); paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setColor(rippleColor); paint.setAlpha(rippleAlpha); this.setWillNotDraw(false); gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent event) { super.onLongPress(event); animateRipple(event); sendClickEvent(true); lastLongPressX = (int) event.getX(); lastLongPressY = (int) event.getY(); rippleStatus = RIPPLE_LONG_PRESS; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return true; } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); this.setDrawingCacheEnabled(true); this.setClickable(true); this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); }
From source file:android.support.v7.widget.TooltipCompatHandler.java
@Override public boolean onHover(View v, MotionEvent event) { if (mPopup != null && mFromTouch) { return false; }/*from w w w . j a v a 2 s. com*/ AccessibilityManager manager = (AccessibilityManager) mAnchor.getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); if (manager.isEnabled() && manager.isTouchExplorationEnabled()) { return false; } switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: if (mAnchor.isEnabled() && mPopup == null) { mAnchorX = (int) event.getX(); mAnchorY = (int) event.getY(); setPendingHandler(this); } break; case MotionEvent.ACTION_HOVER_EXIT: hide(); break; } return false; }