List of usage examples for android.view MotionEvent ACTION_MOVE
int ACTION_MOVE
To view the source code for android.view MotionEvent ACTION_MOVE.
Click Source Link
From source file:com.artemchep.horario.ui.widgets.SwipeBackLayout.java
private void chkDragable() { setOnTouchListener(new View.OnTouchListener() { @Override/* w w w . jav a 2 s .c o m*/ public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { lastY = motionEvent.getRawY(); lastX = motionEvent.getRawX(); } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) { newY = motionEvent.getRawY(); lastX = motionEvent.getRawX(); offsetY = Math.abs(newY - lastY); lastY = newY; offsetX = Math.abs(newX - lastX); lastX = newX; switch (dragEdge) { case TOP: case BOTTOM: setEnablePullToBack(offsetY > offsetX); case LEFT: case RIGHT: setEnablePullToBack(offsetY < offsetX); break; } } return false; } }); }
From source file:android.support.v13.view.DragStartHelper.java
/** * Handle a touch event.//from w w w.j a va 2 s.c o m * @param v The view the touch event has been dispatched to. * @param event The MotionEvent object containing full information about * the event. * @return True if the listener has consumed the event, false otherwise. */ public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { mLastTouchX = (int) event.getX(); mLastTouchY = (int) event.getY(); } if (event.getAction() == MotionEvent.ACTION_MOVE && MotionEventCompat.isFromSource(event, InputDeviceCompat.SOURCE_MOUSE) && (MotionEventCompat.getButtonState(event) & MotionEventCompat.BUTTON_PRIMARY) != 0) { return mListener.onDragStart(v, this); } return false; }
From source file:ch.fhnw.comgr.GLES3Activity.java
@Override public boolean onTouch(View v, final MotionEvent event) { if (event == null) { Log.i(TAG, "onTouch: null event"); return false; }/*w ww. j av a 2 s . c o m*/ int action = event.getAction(); int actionCode = action & MotionEvent.ACTION_MASK; try { if (actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN) return handleTouchDown(event); else if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP) return handleTouchUp(event); else if (actionCode == MotionEvent.ACTION_MOVE) return handleTouchMove(event); else Log.i(TAG, "Unhandeled Event: " + actionCode); } catch (Exception ex) { Log.i(TAG, "onTouch (Exception: " + actionCode); } return false; }
From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { mTickersContainer = (FixedGridView) getView().findViewById(R.id.tickersContainer); mTickersContainer.setExpanded(true); final int dashboardSpacing = getResources().getDimensionPixelSize(R.dimen.dashboard_spacing); final int dashboardItemSize = getResources().getDimensionPixelSize(R.dimen.dashboard_item_size); mTickersContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override/* www. j a va 2s. c o m*/ public void onGlobalLayout() { if (mTickersDashboardAdapter.getNumColumns() == 0) { final int numColumns = (int) Math .floor(mTickersContainer.getWidth() / (dashboardSpacing + dashboardItemSize)); if (numColumns > 0) { mTickersDashboardAdapter.setNumColumns(numColumns); mTickersContainer.setNumColumns(numColumns); } } } }); mTickersDashboardAdapter = new TickersDashboardAdapter(getActivity(), this); updateStorageWithTickers(); mTickersDashboardAdapter.update(); mTickersContainer.setAdapter(mTickersDashboardAdapter); TextView emptyView = (TextView) getView().findViewById(R.id.emptyView); mTickersContainer.setEmptyView(emptyView); mTickersContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return event.getAction() == MotionEvent.ACTION_MOVE; } }); //Broadcast receiver initialization mGetStatsReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (isVisible()) { if (mRefreshItem != null) { mRefreshItem.collapseActionView(); mRefreshItem.setActionView(null); } mTickersDashboardAdapter.update(); } } }; LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(mGetStatsReceiver, new IntentFilter("UpdateTickers")); //Trade listener, once "Buy" or "Sell" clicked, send the order to server View.OnClickListener tradeListener = new View.OnClickListener() { @Override public void onClick(View v) { new RegisterTradeRequestTask().execute((v.getId() == R.id.BuyButton) ? "buy" : "sell"); } }; Button SellButton = (Button) getView().findViewById(R.id.SellButton); Button BuyButton = (Button) getView().findViewById(R.id.BuyButton); SellButton.setOnClickListener(tradeListener); BuyButton.setOnClickListener(tradeListener); Button UpdateAccountInfoButton = (Button) getView().findViewById(R.id.UpdateAccountInfoButton); UpdateAccountInfoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new UpdateFundsTask().execute(); } }); //start service to get new data once Dashboard is opened getActivity().sendBroadcast(new Intent(getActivity(), StartServiceReceiver.class)); }
From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java
private boolean onTouchEventTraditionalRotation(MotionEvent event) { if (!isEnabled()) { return false; }/*from www.ja va 2s . com*/ final Drawable mThumb = getThumbCompat(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: setPressed(true); if (mThumb != null) { // This may be within the padding region invalidate(mThumb.getBounds()); } onStartTrackingTouch(); trackTouchEvent(event); attemptClaimDrag(true); break; case MotionEvent.ACTION_MOVE: if (mIsDragging) { trackTouchEvent(event); } break; case MotionEvent.ACTION_UP: if (mIsDragging) { trackTouchEvent(event); onStopTrackingTouch(); setPressed(false); } else { // Touch up when we never crossed the touch slop threshold // should // be interpreted as a tap-seek to that location. onStartTrackingTouch(); trackTouchEvent(event); onStopTrackingTouch(); attemptClaimDrag(false); } // ProgressBar doesn't know to repaint the thumb drawable // in its inactive state when the touch stops (because the // value has not apparently changed) invalidate(); break; case MotionEvent.ACTION_CANCEL: if (mIsDragging) { onStopTrackingTouch(); setPressed(false); } invalidate(); // see above explanation break; } return true; }
From source file:android.support.design.widget.HeaderBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }// w ww. j a v a2 s .c om switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) { mLastMotionY = y; mActivePointerId = ev.getPointerId(0); ensureVelocityTracker(); } else { return false; } break; } case MotionEvent.ACTION_MOVE: { final int activePointerIndex = ev.findPointerIndex(mActivePointerId); if (activePointerIndex == -1) { return false; } final int y = (int) ev.getY(activePointerIndex); int dy = mLastMotionY - y; if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) { mIsBeingDragged = true; if (dy > 0) { dy -= mTouchSlop; } else { dy += mTouchSlop; } } if (mIsBeingDragged) { mLastMotionY = y; // We're being dragged so scroll the ABL scroll(parent, child, dy, getMaxDragOffset(child), 0); } break; } case MotionEvent.ACTION_UP: if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel); } // $FALLTHROUGH case MotionEvent.ACTION_CANCEL: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return true; }
From source file:com.commonsware.cwac.crossport.design.widget.HeaderBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }//from w ww . ja v a2s .c om switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) { mLastMotionY = y; mActivePointerId = ev.getPointerId(0); ensureVelocityTracker(); } else { return false; } break; } case MotionEvent.ACTION_MOVE: { final int activePointerIndex = ev.findPointerIndex(mActivePointerId); if (activePointerIndex == -1) { return false; } final int y = (int) ev.getY(activePointerIndex); int dy = mLastMotionY - y; if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) { mIsBeingDragged = true; if (dy > 0) { dy -= mTouchSlop; } else { dy += mTouchSlop; } } if (mIsBeingDragged) { mLastMotionY = y; // We're being dragged so scroll the ABL scroll(parent, child, dy, getMaxDragOffset(child), 0); } break; } case MotionEvent.ACTION_UP: if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); float yvel = mVelocityTracker.getYVelocity(mActivePointerId); fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel); } // $FALLTHROUGH case MotionEvent.ACTION_CANCEL: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return true; }
From source file:android.support.designox.widget.HeaderBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }//from www .ja v a2 s . c o m switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) { mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); ensureVelocityTracker(); } else { return false; } break; } case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (activePointerIndex == -1) { return false; } final int y = (int) MotionEventCompat.getY(ev, activePointerIndex); int dy = mLastMotionY - y; if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) { mIsBeingDragged = true; if (dy > 0) { dy -= mTouchSlop; } else { dy += mTouchSlop; } } if (mIsBeingDragged) { mLastMotionY = y; // We're being dragged so scroll the ABL scroll(parent, child, dy, getMaxDragOffset(child), 0); } break; } case MotionEvent.ACTION_UP: if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel); } // $FALLTHROUGH case MotionEvent.ACTION_CANCEL: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return true; }
From source file:com.apptentive.android.sdk.util.image.PreviewImageView.java
@Override public boolean onTouch(View v, MotionEvent event) { gestureDetector.onTouchEvent(event); scaleGestureDetector.onTouchEvent(event); float x = 0, y = 0; // Get multiple touch points final int pointerCount = event.getPointerCount(); // Calculate average x and y for (int i = 0; i < pointerCount; i++) { x += event.getX(i);//from ww w. j a va 2 s . co m y += event.getY(i); } x = x / pointerCount; y = y / pointerCount; /** * Reset lastX and lastY */ if (pointerCount != lastPointerCount) { isCanDrag = false; lastX = x; lastY = y; } lastPointerCount = pointerCount; switch (event.getAction()) { case MotionEvent.ACTION_MOVE: float dx = x - lastX; float dy = y - lastY; if (!isCanDrag) { isCanDrag = isCanDrag(dx, dy); } if (isCanDrag) { RectF rectF = getMatrixRectF(); if (getDrawable() != null) { isCheckLeftAndRight = isCheckTopAndBottom = true; // No left/right translation if image width is less than screen width if (rectF.width() < getWidth()) { dx = 0; isCheckLeftAndRight = false; } // No Up/Down translation if image height is less than screen height if (rectF.height() < getHeight()) { dy = 0; isCheckTopAndBottom = false; } scaleMatrix.postTranslate(dx, dy); checkMatrixBounds(); setImageMatrix(scaleMatrix); } } lastX = x; lastY = y; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: lastPointerCount = 0; break; } 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 w w w . j a v a2 s. c o 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; }