List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
/** * compute finish duration./*from www . j a va2 s. c o m*/ * * @param ev up event. * @param velocity velocity x. * @return finish duration. */ private int getSwipeDuration(MotionEvent ev, int velocity) { int sx = getScrollX(); int dx = (int) (ev.getX() - sx); final int width = mSwipeCurrentHorizontal.getMenuWidth(); final int halfWidth = width / 2; final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / width); final float distance = halfWidth + halfWidth * distanceInfluenceForSnapDuration(distanceRatio); int duration; if (velocity > 0) { duration = 4 * Math.round(1000 * Math.abs(distance / velocity)); } else { final float pageDelta = (float) Math.abs(dx) / width; duration = (int) ((pageDelta + 1) * 100); } duration = Math.min(duration, mScrollerDuration); return duration; }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent me) { if (mGestureDetector.onTouchEvent(me)) { return true; }// ww w . ja v a 2 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.jest.phone.PhoneActivity.java
@Override public boolean onTouch(View arg0, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: // Start gesture firstFinger = new PointF(event.getX(), event.getY()); mode = ONE_FINGER_DRAG;// w w w . j a v a2 s . c om stopThread = true; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_POINTER_DOWN: // second finger distBetweenFingers = spacing(event); // the distance check is done to avoid false alarms if (distBetweenFingers > 5f) { mode = TWO_FINGERS_DRAG; } break; case MotionEvent.ACTION_MOVE: if (mode == ONE_FINGER_DRAG) { PointF oldFirstFinger = firstFinger; firstFinger = new PointF(event.getX(), event.getY()); scroll(oldFirstFinger.x - firstFinger.x); sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED); sensorHistoryPlot.redraw(); } else if (mode == TWO_FINGERS_DRAG) { float oldDist = distBetweenFingers; distBetweenFingers = spacing(event); zoom(oldDist / distBetweenFingers); sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED); sensorHistoryPlot.redraw(); } break; } return true; }
From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_DOWN: mDownX = event.getX(); mDisallowedParentIntercept = false; case MotionEvent.ACTION_MOVE: int x = (int) event.getX(); if (!mDisallowedParentIntercept && Math.abs(x - mDownX) > mScaledTouchSlop) { getParent().requestDisallowInterceptTouchEvent(true); mDisallowedParentIntercept = true; }/*from w w w.jav a2s. c om*/ Item item = findItemByPoint(x, (int) event.getY()); if (mTargetItem != item) { mTargetItem = item; if (item != null) { item.setSelected(!item.isSelected()); ItemState state = new ItemState(); state.item = item; state.isSelected = item.isSelected(); if (mItemState == null) { mItemState = state; } else { state.next = mItemState; mItemState = state; } } } break; case MotionEvent.ACTION_CANCEL: if (mItemState != null) { ItemState state = mItemState; while (state != null) { state.item.setSelected(!state.isSelected); state = state.next; } } case MotionEvent.ACTION_UP: requestLayout(); invalidate(); mTargetItem = null; if (mDisallowedParentIntercept) { getParent().requestDisallowInterceptTouchEvent(false); } mItemState = null; break; } return true; }
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);// w w w . j av a2s . co m } } 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 *//* ww w.ja va 2 s . com*/ 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.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;//from w ww . j av a2 s . c o 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:android.support.v7.widget.TooltipCompatHandler.java
@Override public boolean onHover(View v, MotionEvent event) { if (mPopup != null && mFromTouch) { return false; }/* w w w. java 2 s . c o m*/ 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; }
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 ww.ja v a 2 s . c om*/ 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:co.taqat.call.CallIncomingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getBoolean(R.bool.orientation_portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }//from www . j a v a 2 s . co m getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.call_incoming); name = (TextView) findViewById(R.id.contact_name); number = (TextView) findViewById(R.id.contact_number); contactPicture = (ImageView) findViewById(R.id.contact_picture); // set this flag so this activity will stay in front of the keyguard int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; getWindow().addFlags(flags); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); final int screenWidth = getResources().getDisplayMetrics().widthPixels; acceptUnlock = (LinearLayout) findViewById(R.id.acceptUnlock); declineUnlock = (LinearLayout) findViewById(R.id.declineUnlock); accept = (ImageView) findViewById(R.id.accept); decline = (ImageView) findViewById(R.id.decline); accept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { decline.setVisibility(View.GONE); acceptUnlock.setVisibility(View.VISIBLE); } }); accept.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { float curX; switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: acceptUnlock.setVisibility(View.VISIBLE); decline.setVisibility(View.GONE); answerX = motionEvent.getX(); break; case MotionEvent.ACTION_MOVE: curX = motionEvent.getX(); if ((answerX - curX) >= 0) view.scrollBy((int) (answerX - curX), view.getScrollY()); answerX = curX; if (curX < screenWidth / 4) { answer(); return true; } break; case MotionEvent.ACTION_UP: view.scrollTo(0, view.getScrollY()); decline.setVisibility(View.VISIBLE); acceptUnlock.setVisibility(View.GONE); break; } return true; } }); decline.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { float curX; switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: declineUnlock.setVisibility(View.VISIBLE); accept.setVisibility(View.GONE); declineX = motionEvent.getX(); break; case MotionEvent.ACTION_MOVE: curX = motionEvent.getX(); view.scrollBy((int) (declineX - curX), view.getScrollY()); declineX = curX; Log.w(curX); if (curX > (screenWidth / 2)) { decline(); return true; } break; case MotionEvent.ACTION_UP: view.scrollTo(0, view.getScrollY()); accept.setVisibility(View.VISIBLE); declineUnlock.setVisibility(View.GONE); break; } return true; } }); decline.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { accept.setVisibility(View.GONE); acceptUnlock.setVisibility(View.VISIBLE); } }); mListener = new LinphoneCoreListenerBase() { @Override public void callState(LinphoneCore lc, LinphoneCall call, State state, String message) { if (call == mCall && State.CallEnd == state) { finish(); } if (state == State.StreamsRunning) { // The following should not be needed except some devices need it (e.g. Galaxy S). LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled()); } } }; super.onCreate(savedInstanceState); instance = this; }