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:com.roger.lineselectionwebview.LSWebView.java
/** * Creates the selection layer.//from www. ja v a 2 s.co m * * @param context */ protected void createSelectionLayer(Context context) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mSelectionDragLayer = (DragLayer) inflater.inflate(R.layout.selection_drag_layer, null); // Make sure it's filling parent mDragController = new DragController(context); mDragController.setDragListener(this); mDragController.addDropTarget(mSelectionDragLayer); mSelectionDragLayer.setDragController(mDragController); mStartSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.startHandle); mStartSelectionHandle.setTag(new Integer(SELECTION_START_HANDLE)); mEndSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.endHandle); mEndSelectionHandle.setTag(new Integer(SELECTION_END_HANDLE)); OnTouchListener handleTouchListener = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { boolean handledHere = false; final int action = event.getAction(); // Down event starts drag for handle. if (action == MotionEvent.ACTION_DOWN) { handledHere = startDrag(v); mLastTouchedSelectionHandle = (Integer) v.getTag(); } return handledHere; } }; mStartSelectionHandle.setOnTouchListener(handleTouchListener); mEndSelectionHandle.setOnTouchListener(handleTouchListener); }
From source file:com.cubic9.android.droidglove.Main.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mYPointWhenDown = event.getY();/*w w w .java2 s. c o m*/ break; case MotionEvent.ACTION_MOVE: mYDiff = event.getY() - mYPointWhenDown; if (mYDiff < 0) { mYDiff = 0; mYPointWhenDown = event.getY(); } else if (mYDiff > 100) { mYDiff = 100; mYPointWhenDown = event.getY() - 100; } break; case MotionEvent.ACTION_UP: mYDiff = 0; break; default: break; } return true; }
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*ww w . j a v a 2s . co m*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchX = ev.getX(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderX = 0; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; return true; } break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float x = MotionEventCompat.getX(ev, index); final float dx = x - mLastTouchX + mTouchRemainderX; final int deltaY = (int) dx; mTouchRemainderX = dx - deltaY; if (Math.abs(dx) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; return true; } } } return false; }
From source file:cc.solart.turbo.TurboRecyclerView.java
@Override public boolean onTouchEvent(MotionEvent e) { if (!mLoadEnabled || canScrollEnd() || mIsLoading || isEmpty()) { return super.onTouchEvent(e); }//from w ww . j a v a 2 s . com if (dispatchOnItemTouch(e)) { return true; } if (getLayoutManager() == null) { return false; } final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally(); final boolean canScrollVertically = getLayoutManager().canScrollVertically(); final int action = MotionEventCompat.getActionMasked(e); switch (action) { case MotionEvent.ACTION_DOWN: { final int index = MotionEventCompat.getActionIndex(e); mActivePointerId = MotionEventCompat.getPointerId(e, 0); mInitialMotionX = getMotionEventX(e, index); mInitialMotionY = getMotionEventY(e, index); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(e); mActivePointerId = MotionEventCompat.getPointerId(e, index); mInitialMotionX = getMotionEventX(e, index); mInitialMotionY = getMotionEventY(e, index); } break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId); if (index < 0) { Log.w(TAG, "pointer index for id " + index + " not found. return super"); return super.onTouchEvent(e); } final int x = getMotionEventX(e, index); final int y = getMotionEventY(e, index); int deltaY = y - mInitialMotionY; if (canScrollVertically && Math.abs(deltaY) > mTouchSlop && deltaY < 0) { float targetEnd = -dampAxis(deltaY); setTranslationY(targetEnd); return true; } int deltaX = x - mInitialMotionX; if (canScrollHorizontally && Math.abs(deltaX) > mTouchSlop && deltaX < 0) { float targetEnd = -dampAxis(deltaX); setTranslationX(targetEnd); return true; } } break; case MotionEventCompat.ACTION_POINTER_UP: { onPointerUp(e); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { if (canScrollHorizontally) animateOffsetToEnd("translationX", mInterpolator, 0f); if (canScrollVertically) animateOffsetToEnd("translationY", mInterpolator, 0f); final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId); if (index < 0) { Log.e(TAG, "Got ACTION_UP event but don't have an active pointer id."); return super.onTouchEvent(e); } final int y = getMotionEventY(e, index); final int x = getMotionEventX(e, index); final float overScrollBottom = (mInitialMotionY - y) * DRAG_RATE; final float overScrollRight = (mInitialMotionX - x) * DRAG_RATE; if ((canScrollVertically && overScrollBottom > mTotalDragDistance) || (canScrollHorizontally && overScrollRight > mTotalDragDistance)) { Log.i(TAG, "refreshing..."); mIsLoading = true; dispatchOnLoadingMoreListeners(); smoothScrollToPosition(mLastVisibleItemPosition + 1); mActivePointerId = INVALID_POINTER; return true; } else { mIsLoading = false; mActivePointerId = INVALID_POINTER; } } break; } return super.onTouchEvent(e); }
From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanPickRange) { return super.onTouchEvent(ev); }//from ww w . j av a2 s.co m // looks like the ViewPager wants to step in if (mCheckForLongPress != null) { removeCallbacks(mCheckForLongPress); } if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && (UP || CANCEL)"); } if (ev.getAction() == MotionEvent.ACTION_UP) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), false); mDayPickerPagerAdapter.onDateRangeSelectionEnded(mTempSelectedDate); } } mIsLongPressed = false; mInitialDownX = -1; mInitialDownY = -1; mScrollingDirection = NOT_SCROLLING; if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } //return true; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_DOWN) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && DOWN"); } mScrollingDirection = NOT_SCROLLING; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_MOVE) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && MOVE"); } int direction = resolveDirectionForScroll(ev.getX()); boolean directionChanged = mScrollingDirection != direction; if (directionChanged) { if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } } if (mScrollerRunnable == null) { mScrollerRunnable = new ScrollerRunnable(); } mScrollingDirection = direction; if (mScrollingDirection == NOT_SCROLLING) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), true); if (mTempSelectedDate != null) { mDayPickerPagerAdapter.onDateRangeSelectionUpdated(mTempSelectedDate); } } } else if (directionChanged) { // SCROLLING_LEFT || SCROLLING_RIGHT post(mScrollerRunnable); } } return mIsLongPressed || super.onTouchEvent(ev); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
public boolean areTouchesDisabled(MotionEvent motionEvent) { if (motionEvent != null && mTouchesAreDisabledTillLastFingerIsUp) { //calculate new value for mTouchesAreDisabledTillLastFingerIsUp //when do we reset the mTouchesAreDisabledTillLastFingerIsUp flag: //Only if we have a single pointer //and:/*from w ww . j a va 2 s. c om*/ // CANCEL - the single pointer has been cancelled. So no pointers // UP - the single pointer has been lifted. So now we have no pointers down. // DOWN - this is the first action from the single pointer, so we already were in no-pointers down state. final int action = MotionEventCompat.getActionMasked(motionEvent); if (MotionEventCompat.getPointerCount(motionEvent) == 1 && (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP)) { mTouchesAreDisabledTillLastFingerIsUp = false; //If the action is UP then we will return the previous value (which is TRUE), since the motion events are disabled until AFTER //the UP event, so if this event resets the flag, this event should still be disregarded. return action == MotionEvent.ACTION_UP; } } return mTouchesAreDisabledTillLastFingerIsUp; }
From source file:am.widget.tabstrip.TabStripHelper.java
boolean onTouchEvent(MotionEvent event) { if (mClickable) { final float x = event.getX(); final float y = event.getY(); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mClickPosition = PagerAdapter.POSITION_NONE; mDownX = x;/* w w w . j a v a 2s .c om*/ mDownY = y; break; case MotionEvent.ACTION_UP: mClickPosition = PagerAdapter.POSITION_NONE; if (mPager != null && getPageCount() > 0) { if (mView instanceof TabStripView) mClickPosition = ((TabStripView) mView).getClickedPosition(mDownX, mDownY, x, y); else if (mView instanceof TabStripViewGroup) mClickPosition = ((TabStripViewGroup) mView).getClickedPosition(mDownX, mDownY, x, y); } break; case MotionEvent.ACTION_CANCEL: mClickPosition = PagerAdapter.POSITION_NONE; break; } } if (mDoubleClickable) { final float x = event.getX(); final float y = event.getY(); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mFirstDownX = mSecondDownX; mFirstDownY = mSecondDownY; mSecondDownX = x; mSecondDownY = y; break; case MotionEvent.ACTION_UP: final long downTime = event.getDownTime(); if (mLastUpTime != 0 && downTime - mLastUpTime < DOUBLE_TAP_TIMEOUT) { mDoubleClicked = true; if (mView instanceof TabStripView) mFirstPosition = ((TabStripView) mView).getClickedPosition(mFirstDownX, mFirstDownY, mFirstUpX, mFirstUpY); else if (mView instanceof TabStripViewGroup) mFirstPosition = ((TabStripViewGroup) mView).getClickedPosition(mFirstDownX, mFirstDownY, mFirstUpX, mFirstUpY); if (mView instanceof TabStripView) mSecondPosition = ((TabStripView) mView).getClickedPosition(mSecondDownX, mSecondDownY, x, y); else if (mView instanceof TabStripViewGroup) mSecondPosition = ((TabStripViewGroup) mView).getClickedPosition(mSecondDownX, mSecondDownY, x, y); mLastUpTime = 0; } else { mDoubleClicked = false; mFirstPosition = PagerAdapter.POSITION_NONE; mSecondPosition = PagerAdapter.POSITION_NONE; mFirstUpX = x; mFirstUpY = y; mLastUpTime = event.getEventTime(); } break; case MotionEvent.ACTION_CANCEL: break; } } return false; }
From source file:android.support.design.widget.BottomSheetBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; }/*from ww w. j ava 2s .co m*/ int action = MotionEventCompat.getActionMasked(event); if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) { return true; } mViewDragHelper.processTouchEvent(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it // to capture the bottom sheet in case it is not captured and the touch slop is passed. if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) { if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } } return !mIgnoreEvents; }
From source file:org.cocos2dx.lib.TextInputWraper.java
public boolean onTouchEvent(final MotionEvent event) { // these data are used in ACTION_MOVE and ACTION_CANCEL final int pointerNumber = event.getPointerCount(); final int[] ids = new int[pointerNumber]; final float[] xs = new float[pointerNumber]; final float[] ys = new float[pointerNumber]; for (int i = 0; i < pointerNumber; i++) { ids[i] = event.getPointerId(i);// w w w . j a va 2s . c o m xs[i] = event.getX(i); ys[i] = event.getY(i); } switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT; final int idPointerDown = event.getPointerId(indexPointerDown); final float xPointerDown = event.getX(indexPointerDown); final float yPointerDown = event.getY(indexPointerDown); queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown); } }); break; case MotionEvent.ACTION_DOWN: // there are only one finger on the screen final int idDown = event.getPointerId(0); final float xDown = xs[0]; final float yDown = ys[0]; queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionDown(idDown, xDown, yDown); } }); break; case MotionEvent.ACTION_MOVE: queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionMove(ids, xs, ys); } }); break; case MotionEvent.ACTION_POINTER_UP: final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT; final int idPointerUp = event.getPointerId(indexPointUp); final float xPointerUp = event.getX(indexPointUp); final float yPointerUp = event.getY(indexPointUp); queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp); } }); break; case MotionEvent.ACTION_UP: // there are only one finger on the screen final int idUp = event.getPointerId(0); final float xUp = xs[0]; final float yUp = ys[0]; queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionUp(idUp, xUp, yUp); } }); break; case MotionEvent.ACTION_CANCEL: queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionCancel(ids, xs, ys); } }); break; } if (debug) { dumpEvent(event); } return true; }
From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_login); ButterKnife.inject(this); try {/* w w w. j a v a2 s .c om*/ /*message from fcm service*/ msg = getIntent().getStringExtra("MSG"); type = getIntent().getStringExtra("TYPE"); actionPath = getIntent().getStringExtra("ACTION_PATH"); headerMsg = getIntent().getStringExtra("HEADER"); clubbingFlag = getIntent().getStringExtra("CLUBBINGFLAG"); notificationTreySize = getIntent().getIntExtra("NOTIFITREYSIZE", 0); // Log.e("Loginmsg", " " + msg + " header " + headerMsg + " " +type + " "+actionPath); /*Clearing notifications ArrayList from MyFirebaseMessagingService after clicking on it*/ MyFirebaseMessagingService.notifications.clear(); // FirebaseCrash.setCrashCollectionEnabled(false); } catch (Exception e) { appController.appendLog(appController.getDateTime() + "" + "/" + "Navigation Activity" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } TextView btnLinkToForgetScreen = (TextView) findViewById(R.id.btnLinkToForgetScreen); DatabaseClass databaseClass = new DatabaseClass(getApplicationContext()); bannerClass = new BannerClass(getApplicationContext()); LastnameDatabaseClass lastnameDatabaseClass = new LastnameDatabaseClass(getApplicationContext()); dbController = SQLiteHandler.getInstance(getApplicationContext()); appController = new AppController(); if (md5 == null) { md5 = new MD5(); } //getCurrentDob(21); //getCurrentDob(10); //this will set value to run asynctask only once per login session new CallAsynOnce().setValue("1");//this set value which helps to call asyntask only once while app is running. // Progress dialog connectionDetector = new ConnectionDetector(getApplicationContext()); try { sInstance = SQLiteHandler.getInstance(getApplicationContext()); if (sqlController == null) { sqlController = new SQLController(getApplicationContext()); sqlController.open(); } // sInstance = SQLiteHandler.getInstance(getApplicationContext()); Boolean value = getFirstTimeLoginStatus(); if (value) { phoneNumber = sqlController.getPhoneNumber(); doctor_membership_number = sqlController.getDoctorMembershipIdNew(); docId = sqlController.getDoctorId(); } } catch (Exception e) { e.printStackTrace(); appController.appendLog(appController.getDateTimenew() + " " + "/ " + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } try { databaseClass.createDataBase(); bannerClass.createDataBase(); } catch (Exception ioe) { appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + ioe + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); throw new Error("Unable to create database"); } try { databaseClass.openDataBase(); bannerClass.openDataBase(); /*This AsyncTask will Insert data from Asset folder file to data 23-03-2016*/ new InsertDataLocally().execute(); } catch (Exception e) { e.printStackTrace(); appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } finally { databaseClass.close(); } try { lastnameDatabaseClass.createDataBase(); } catch (IOException e) { appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); throw new Error("Unable to create database"); } try { lastnameDatabaseClass.openDataBase(); getUsernamePasswordFromDatabase(); } catch (Exception e) { e.printStackTrace(); appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } finally { lastnameDatabaseClass.close(); } btnLogin.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { hideKeyBoard(); btnLogin.setBackground(getResources().getDrawable(R.drawable.rounded_corner_withbackground)); name = inputEmail.getText().toString().trim(); strPassword = inputPassword.getText().toString().trim(); String time = appController.getDateTimenew(); AppController.getInstance().trackEvent("Login", "Login Pressed"); //This code used for Remember Me(ie. save login id and password for future ref.) rememberMe(name, strPassword, time); //save username only //rememberMeCheckbox();//Removed remeber me check box for safety concern 04-11-16 //to authenticate user credentials //Log.e("name",""+name +" savedUserName "+savedUserName+ " phoneNumber "+phoneNumber); //if(name.equals(savedUserName) || name.equals(phoneNumber)) LoginAuthentication(); // else appController.showToastMsg(getApplicationContext(),"This username is not licensed to log into this device. Please check username"); } else if (event.getAction() == MotionEvent.ACTION_DOWN) { btnLogin.setBackground( getResources().getDrawable(R.drawable.rounded_corner_withbackground_blue)); } return false; } }); /*We are updating visit date format*/ // updateVisitDateFormat(); //Commented on 10-05-2017 addVitalsIntoInvstigation(); //Commented on 10-05-2017 /* Updateing banner stats flag to 0 build no 1.3+ */ /*Updating associate master flag from 1 to 0*/ String bannerUpdateFlag = getupdateBannerClickVisitFlag0(); if (bannerUpdateFlag == null || bannerUpdateFlag.equals("true")) { updateBannerTableDataFlag(); } // Link to Register Screen btnLinkToForgetScreen.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { boolean isInternetPresent = connectionDetector.isConnectingToInternet(); if (isInternetPresent) { showChangePassDialog(); } else { appController.showToastMsg(getApplicationContext(), "Please Connect To Internet And Try Again!"); } } }); if (checkAndRequestPermissions()) { // carry on the normal flow, as the case of permissions granted. } }