List of usage examples for android.view MotionEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view MotionEvent ACTION_DOWN.
Click Source Link
From source file:cn.edu.zafu.easemob.CoverFlowLib.VelocityViewPager.java
@Override public boolean onTouchEvent(MotionEvent event) { // give all the events to the gesture detector. I'm returning true here so the viewpager doesn't // get any events at all, I'm sure you could adjust this to make that not true. mGestureDetector.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { downX = event.getX();//from ww w . j av a 2 s .c om } else if (event.getAction() == MotionEvent.ACTION_UP) { onUp(event.getX() - downX); } return true; }
From source file:akhil.alltrans.NestedScrollingMarkDownView.java
@Override public boolean onTouchEvent(MotionEvent event) { boolean result = false; MotionEvent trackedEvent = MotionEvent.obtain(event); final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { mNestedYOffset = 0;/*from w w w . ja v a 2 s . com*/ } int y = (int) event.getY(); event.offsetLocation(0, mNestedYOffset); switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = y; startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); result = super.onTouchEvent(event); break; case MotionEvent.ACTION_MOVE: int deltaY = mLastMotionY - y; if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) { deltaY -= mScrollConsumed[1]; trackedEvent.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } int oldY = getScrollY(); mLastMotionY = y - mScrollOffset[1]; if (deltaY < 0) { int newScrollY = Math.max(0, oldY + deltaY); deltaY -= newScrollY - oldY; if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) { mLastMotionY -= mScrollOffset[1]; trackedEvent.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } } result = super.onTouchEvent(trackedEvent); trackedEvent.recycle(); break; case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: stopNestedScroll(); result = super.onTouchEvent(event); break; } return result; }
From source file:com.aohuan.dodo.dispatchevent_about.dummy_demo.view1.NestedScrollWebView.java
@Override public boolean onTouchEvent(MotionEvent event) { boolean result = false; MotionEvent trackedEvent = MotionEvent.obtain(event); final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { mNestedYOffset = 0;//from w ww .ja v a2s . c om } int y = (int) event.getY(); event.offsetLocation(0, mNestedYOffset); switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = y; startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); result = super.onTouchEvent(event); break; case MotionEvent.ACTION_MOVE: int deltaY = mLastMotionY - y; if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) { deltaY -= mScrollConsumed[1]; trackedEvent.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } int oldY = getScrollY(); mLastMotionY = y - mScrollOffset[1]; if (deltaY < 0) { int newScrollY = Math.max(0, oldY + deltaY); deltaY -= newScrollY - oldY; if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) { mLastMotionY -= mScrollOffset[1]; trackedEvent.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } } trackedEvent.recycle(); result = super.onTouchEvent(trackedEvent); break; case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: stopNestedScroll(); result = super.onTouchEvent(event); break; } return result; }
From source file:com.ppdl.microphone.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); sp.edit().remove(Constant.EXTRA_INFILE).commit(); // infile?PCM????? Button recordButton = (Button) findViewById(R.id.buttonRecord); recordButton.setOnTouchListener(new View.OnTouchListener() { @Override//from w ww .j av a 2 s . co m public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startRecording(); Toast.makeText(MainActivity.this, "Start Recording", Toast.LENGTH_SHORT).show(); break; case MotionEvent.ACTION_UP: stopRecording(); v.performClick(); Toast.makeText(MainActivity.this, "Stop Recording", Toast.LENGTH_SHORT).show(); break; default: break; } return false; } }); Button playButton = (Button) findViewById(R.id.buttonPlay); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startPlaying(); } }); Button stopButton = (Button) findViewById(R.id.buttonStop); stopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { stopPlaying(); } }); Button recognizeButton = (Button) findViewById(R.id.buttonRecognize); recognizeButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: Toast.makeText(MainActivity.this, "Start Recognizing", Toast.LENGTH_SHORT).show(); speechRecognizer.cancel(); Intent intent = new Intent(); bindParams(intent); intent.putExtra("vad", "touch"); speechRecognizer.startListening(intent); break; case MotionEvent.ACTION_UP: v.performClick(); Toast.makeText(MainActivity.this, "Stop Recognizing", Toast.LENGTH_SHORT).show(); speechRecognizer.stopListening(); break; default: break; } return false; } }); speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(mRecognitionListner); }
From source file:com.android.cts.uiautomator.TestGenericDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { View rootView = inflater.inflate(R.layout.test_results_detail_fragment, container, false); if (mItem != null) { ((TextView) rootView.findViewById(R.id.testResultsTextView)).setText(mItem.mName); }/*from w w w .j a v a2s. co m*/ // listen to touch events to verify the multiPointerGesture APIs // Since API Level 18 rootView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: // Reset any collected touch coordinate results on the primary touch down resetTouchResults(); // collect this event collectStartAction(event, v, 0); break; case MotionEvent.ACTION_POINTER_DOWN: // collect this event collectStartAction(event, v, getPointerIndex(event)); break; case MotionEvent.ACTION_POINTER_UP: // collect this event collectEndAction(event, v, getPointerIndex(event)); break; case MotionEvent.ACTION_UP: // collect this event collectEndAction(event, v, 0); // on the primary touch up display results collected for all pointers displayTouchResults(); break; } return true; } }); return rootView; }
From source file:akhil.alltrans.NestedScrollingListView.java
/** * * @see android.support.v4.widget.NestedScrollView#onTouchEvent(MotionEvent) *///from w w w .j ava2s . co m @Override public boolean onTouchEvent(MotionEvent ev) { boolean returnValue = false; MotionEvent event = MotionEvent.obtain(ev); final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { mNestedOffsetY = 0; } event.offsetLocation(0, mNestedOffsetY); int eventY = (int) event.getY(); switch (action) { case MotionEvent.ACTION_MOVE: int deltaY = mLastY - eventY; // NestedPreScroll if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) { deltaY -= mScrollConsumed[1]; mLastY = eventY - mScrollOffset[1]; event.offsetLocation(0, mScrollOffset[1]); mNestedOffsetY += mScrollOffset[1]; } returnValue = super.onTouchEvent(event); // NestedScroll if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) { event.offsetLocation(0, mScrollOffset[1]); mNestedOffsetY += mScrollOffset[1]; mLastY -= mScrollOffset[1]; } break; case MotionEvent.ACTION_DOWN: returnValue = super.onTouchEvent(event); mLastY = eventY; // start NestedScroll startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; case MotionEvent.ACTION_UP: // TODO: fling returnValue = super.onTouchEvent(event); break; case MotionEvent.ACTION_CANCEL: returnValue = super.onTouchEvent(event); // end NestedScroll stopNestedScroll(); break; } return returnValue; }
From source file:android.support.designox.widget.HeaderBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }// ww w.j av a 2 s . co m final int action = ev.getAction(); // Shortcut since we're being dragged if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) { return true; } switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { mIsBeingDragged = false; final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) { mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); ensureVelocityTracker(); } break; } case MotionEvent.ACTION_MOVE: { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { break; } final int y = (int) MotionEventCompat.getY(ev, pointerIndex); final int yDiff = Math.abs(y - mLastMotionY); if (yDiff > mTouchSlop) { mIsBeingDragged = true; mLastMotionY = y; } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return mIsBeingDragged; }
From source file:com.anysoftkeyboard.devicespecific.AskV8GestureDetector.java
@Override public boolean onTouchEvent(@NonNull MotionEvent ev) { int singleFingerEventPointerId = mSingleFingerEventPointerId; //I want to keep track on the first finger (https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300) switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: if (ev.getPointerCount() == 1) { mSingleFingerEventPointerId = ev.getPointerId(0); singleFingerEventPointerId = mSingleFingerEventPointerId; }/*from ww w.j a v a2 s . c o m*/ break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (ev.getPointerCount() == 1) mSingleFingerEventPointerId = NOT_A_POINTER_ID; } try { //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/26 mScaleGestureDetector.onTouchEvent(ev); } catch (IllegalArgumentException e) { //I have nothing I can do here. } catch (ArrayIndexOutOfBoundsException e) { //I have nothing I can do here. } //I'm going to pass the event to the super, only if it is a single touch, and the event is for the first finger //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300 if (ev.getPointerCount() == 1 && ev.getPointerId(0) == singleFingerEventPointerId) return super.onTouchEvent(ev); else return false; }
From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java
@Override public boolean onTouchEvent(MotionEvent e) { // MotionEvent reports input details from the touch screen // and other input controls. In this case, you are only // interested in events where the touch position changed. switch (e.getAction()) { case MotionEvent.ACTION_DOWN: if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else {//from ww w .j a v a 2 s . c o m mVelocityTracker.clear(); } queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasStarted(); } }); // No break is intentional case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(e); // Compute velocity in pixels per second mVelocityTracker.computeCurrentVelocity(1); final ArrayList<TouchData> touchDataList = new ArrayList<>(e.getHistorySize() + 1); Vector2 viewportPosition; Vector2 viewportVelocity = new Vector2( VelocityTrackerCompat.getXVelocity(mVelocityTracker, e.getActionIndex()), VelocityTrackerCompat.getYVelocity(mVelocityTracker, e.getActionIndex())); // Add previous touch coordinates for (int i = 0; i < e.getHistorySize(); i++) { viewportPosition = new Vector2(e.getHistoricalX(i), e.getHistoricalY(i)); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getHistoricalSize(i), e.getHistoricalPressure(i))); } // Add current touch coordinates viewportPosition = new Vector2(e.getX(), e.getY()); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getSize(), e.getPressure())); // Ensure we call switchMode() on the OpenGL thread. // queueEvent() is a method of GLSurfaceView that will do this for us. queueEvent(new Runnable() { @Override public void run() { mRenderer.addTouchData(touchDataList); } }); requestRender(); break; case MotionEvent.ACTION_UP: queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasEnded(); } }); requestRender(); break; } return true; }
From source file:android.support.design.widget.HeaderBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }//from w w w . ja v a 2s . c om final int action = ev.getAction(); // Shortcut since we're being dragged if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) { return true; } switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { mIsBeingDragged = false; final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) { mLastMotionY = y; mActivePointerId = ev.getPointerId(0); ensureVelocityTracker(); } break; } case MotionEvent.ACTION_MOVE: { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = ev.findPointerIndex(activePointerId); if (pointerIndex == -1) { break; } final int y = (int) ev.getY(pointerIndex); final int yDiff = Math.abs(y - mLastMotionY); if (yDiff > mTouchSlop) { mIsBeingDragged = true; mLastMotionY = y; } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return mIsBeingDragged; }