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.app.blockydemo.ui.fragment.FormulaEditorFragment.java
@Override public void onStart() { formulaEditorKeyboard.setClickable(true); formularEditorFieldDeleteButton.setClickable(true); getView().requestFocus();// w ww.j a va2 s . c om View.OnTouchListener touchListener = new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { Log.i("info", "viewId: " + view.getId()); if (event.getAction() == MotionEvent.ACTION_UP) { updateButtonViewOnKeyboard(); view.setPressed(false); return true; } if (event.getAction() == MotionEvent.ACTION_DOWN) { view.setPressed(true); switch (view.getId()) { case R.id.formula_editor_keyboard_compute: InternFormulaParser internFormulaParser = formulaEditorEditText.getFormulaParser(); FormulaElement formulaElement = internFormulaParser.parseFormula(); if (formulaElement == null) { if (internFormulaParser.getErrorTokenIndex() >= 0) { formulaEditorEditText.setParseErrorCursorAndSelection(); } return false; } Formula formulaToCompute = new Formula(formulaElement); FormulaEditorComputeDialog computeDialog = new FormulaEditorComputeDialog(context); computeDialog.setFormula(formulaToCompute); computeDialog.show(); return true; case R.id.formula_editor_keyboard_undo: formulaEditorEditText.undo(); return true; case R.id.formula_editor_keyboard_redo: formulaEditorEditText.redo(); return true; case R.id.formula_editor_keyboard_math: showFormulaEditorListFragment(FormulaEditorListFragment.MATH_TAG, R.string.formula_editor_math); return true; case R.id.formula_editor_keyboard_logic: showFormulaEditorListFragment(FormulaEditorListFragment.LOGIC_TAG, R.string.formula_editor_logic); return true; case R.id.formula_editor_keyboard_object: showFormulaEditorListFragment(FormulaEditorListFragment.OBJECT_TAG, R.string.formula_editor_choose_object_variable); return true; case R.id.formula_editor_keyboard_scripts: showFormulaEditorScriptListFragment(FormulaEditorScriptListFragment.SCRIPT_TAG, R.string.formula_editor_scripts); return true; case R.id.formula_editor_keyboard_variables: showFormulaEditorVariableListFragment(FormulaEditorVariableListFragment.VARIABLE_TAG, R.string.formula_editor_variables); return true; case R.id.formula_editor_keyboard_ok: endFormulaEditor(); return true; default: formulaEditorEditText.handleKeyEvent(view.getId(), ""); return true; } } return false; } }; for (int index = 0; index < formulaEditorKeyboard.getChildCount(); index++) { LinearLayout child = (LinearLayout) formulaEditorKeyboard.getChildAt(index); for (int nestedIndex = 0; nestedIndex < child.getChildCount(); nestedIndex++) { View view = child.getChildAt(nestedIndex); view.setOnTouchListener(touchListener); } } formularEditorFieldDeleteButton.setOnTouchListener(touchListener); updateButtonViewOnKeyboard(); super.onStart(); }
From source file:heartware.com.heartware_master.FriendsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View view = inflater.inflate(R.layout.fragment_friends, container, false); mMeetupDialog = new MeetupDialogFragment(); profilePictureView = (ProfilePictureView) view.findViewById(R.id.selection_profile_pic); profilePictureView.setCropped(true); bLoginButton = (LoginButton) view.findViewById(R.id.login_button); bLoginButton.setReadPermissions("user_friends"); bLoginButton.setFragment(this); bLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override/*from w ww .j a v a2 s . co m*/ public void onSuccess(LoginResult loginResult) { Toast.makeText(getActivity(), "Login successful", Toast.LENGTH_SHORT).show(); } @Override public void onCancel() { Toast.makeText(getActivity(), "Login canceled", Toast.LENGTH_SHORT).show(); } @Override public void onError(FacebookException e) { Toast.makeText(getActivity(), "Login error", Toast.LENGTH_SHORT).show(); } }); bMeetup = (ImageButton) view.findViewById(R.id.create_meetup); bMeetup.getBackground().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY); shareButton = (ShareButton) view.findViewById(R.id.share_button); listView = (ListView) view.findViewById(R.id.selection_list); photoThumbnail = (ImageView) view.findViewById(R.id.selected_image); bMeetup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); bMeetup.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // show interest in events resulting from ACTION_DOWN if (event.getAction() == MotionEvent.ACTION_DOWN) { bMeetup.setSelected(true); createMeetup(); return true; } // don't handle event unless its ACTION_UP so "doSomething()" only runs once. if (event.getAction() != MotionEvent.ACTION_UP) { bMeetup.setSelected(false); return false; } return true; } }); shareButton.registerCallback(callbackManager, shareCallback); shareButton.setFragment(this); init(savedInstanceState); updateWithToken(AccessToken.getCurrentAccessToken()); return view; }
From source file:adapters.CirclePageIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/* w w w .j a v a 2 s. com*/ if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.android.volley.ui.PhotoView.java
@Override public boolean onDoubleTapEvent(MotionEvent e) { final int action = e.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: if (mQuickScaleEnabled) { mDownFocusX = e.getX();//from www . j a va 2 s.c om mDownFocusY = e.getY(); } break; case MotionEvent.ACTION_UP: if (mQuickScaleEnabled) { handled = scale(e); } break; case MotionEvent.ACTION_MOVE: if (mQuickScaleEnabled && mDoubleTapOccurred) { final int deltaX = (int) (e.getX() - mDownFocusX); final int deltaY = (int) (e.getY() - mDownFocusY); int distance = (deltaX * deltaX) + (deltaY * deltaY); if (distance > sTouchSlopSquare) { mDoubleTapOccurred = false; } } break; } return handled; }
From source file:com.codeim.coxin.LoginActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { View v = getCurrentFocus(); if (isShouldHideInput(v, ev)) { hideSoftInput(v.getWindowToken()); }/* w ww.j a v a2 s. c o m*/ } return super.dispatchTouchEvent(ev); }
From source file:com.alibaba.akita.widget.CirclePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from w ww .j a v a2s. c o m*/ if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { if (!mViewPager.isFakeDragging()) { mViewPager.beginFakeDrag(); } mLastMotionX = x; mViewPager.fakeDragBy(deltaX); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:cn.panorama.slook.view.CirclePageIndicator.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }// ww w . ja v a2s .c o m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java
/** * Creates the UI for the interactive authentication process * /*from w w w . j av a2 s. c om*/ * @param provider * The provider used for the authentication process * @param startUrl * The initial URL for the authentication process * @param endUrl * The final URL for the authentication process * @param context * The context used to create the authentication dialog * @param callback * Callback to invoke when the authentication process finishes */ private void showLoginUI(final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); wv.getSettings().setJavaScriptEnabled(true); DisplayMetrics displaymetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int webViewHeight = displaymetrics.heightPixels; wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight)); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }
From source file:android.support.design.widget.SheetBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; }//from ww w .j a v a 2 s.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) { if (mSlideHelper.canScrollHorizontally() != 0 && Math.abs(mInitialY - event.getX()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } else if (mSlideHelper.canScrollVertically() != 0 && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } } return true; }
From source file:asywalul.minang.wisatasumbar.ui.introtutorial.view.CirclePageIndicator.java
public boolean onTouchEvent(@NonNull MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//ww w . j a v a 2 s . c o m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }