List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();//from www .j a va 2s.com boolean handled = false; if (mReturningToStart && ev.getAction() == MotionEvent.ACTION_DOWN) { mReturningToStart = false; } if (isEnabled() && !mReturningToStart && !canChildScrollUp()) { handled = onTouchEvent(ev); } return !handled ? super.onInterceptTouchEvent(ev) : handled; }
From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java
/** * This is why you don't implement your own TextView kids; you have to handle everything! *//*from ww w . j a v a 2 s . co m*/ @Override public boolean onTouchEvent(MotionEvent event) { if (!(text instanceof Spanned)) return super.onTouchEvent(event); Spannable spannedText = (Spannable) text; boolean handled = false; if (event.getAction() == MotionEvent.ACTION_DOWN) { pressedSpan = getPressedSpan(spannedText, event); if (pressedSpan != null) { pressedSpan.setPressed(true); Selection.setSelection(spannedText, spannedText.getSpanStart(pressedSpan), spannedText.getSpanEnd(pressedSpan)); handled = true; postInvalidateOnAnimation(); } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { TouchableUrlSpan touchedSpan = getPressedSpan(spannedText, event); if (pressedSpan != null && touchedSpan != pressedSpan) { pressedSpan.setPressed(false); pressedSpan = null; Selection.removeSelection(spannedText); postInvalidateOnAnimation(); } } else if (event.getAction() == MotionEvent.ACTION_UP) { if (pressedSpan != null) { pressedSpan.setPressed(false); pressedSpan.onClick(this); handled = true; postInvalidateOnAnimation(); } pressedSpan = null; Selection.removeSelection(spannedText); } else { if (pressedSpan != null) { pressedSpan.setPressed(false); handled = true; postInvalidateOnAnimation(); } pressedSpan = null; Selection.removeSelection(spannedText); } return handled; }
From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;/*from ww w .java 2s .c o m*/ mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) {//? // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) {//?? // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } //content???? updateContentOffsetTop((int) (offsetTop * mResistance)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } else { updatePositionTimeout(); } mPrevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); final int action = ev.getAction(); if (action == MotionEvent.ACTION_DOWN && touchTarget == null && stickyWrapper != null && isStickyViewTouched(stickyWrapper.view, x, y)) { touchTarget = stickyWrapper.view; touchPt.x = x;//w ww . j a v a2s . co m touchPt.y = y; downEvent = MotionEvent.obtain(ev); } if (touchTarget != null) { if (isStickyViewTouched(touchTarget, x, y)) { // forward event to header view touchTarget.dispatchTouchEvent(ev); } if (action == MotionEvent.ACTION_UP) { super.dispatchTouchEvent(ev); clearTouchTarget(); } else if (action == MotionEvent.ACTION_CANCEL) { clearTouchTarget(); } else if (action == MotionEvent.ACTION_MOVE) { if (Math.abs(y - touchPt.y) > touchSlop) { MotionEvent event = MotionEvent.obtain(ev); event.setAction(MotionEvent.ACTION_CANCEL); touchTarget.dispatchTouchEvent(event); event.recycle(); super.dispatchTouchEvent(downEvent); super.dispatchTouchEvent(ev); clearTouchTarget(); } } return true; } return super.dispatchTouchEvent(ev); }
From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java
private boolean onTouchEventTraditionalRotation(MotionEvent event) { if (!isEnabled()) { return false; }//from w w w. j a va 2 s .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.v7.widget.TooltipCompatHandler.java
@Override public boolean onHover(View v, MotionEvent event) { if (mPopup != null && mFromTouch) { return false; }/*from w w w . java2s .co 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:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { float currentTouchY = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastTouchY = currentTouchY;/* www . j a va 2 s .c o m*/ break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastTouchY; if (Math.abs(differentY) > mTouchSlop) { if (!isHeaderViewCompleteInvisible() || (isContentViewToTop() && isHeaderViewCompleteInvisible() && mIsInControl)) { mLastTouchY = currentTouchY; return true; } } break; } return super.onInterceptTouchEvent(ev); }
From source file:com.facebook.android.friendsmash.ScoreboardFragment.java
private void populateScoreboard() { // Ensure all components are firstly removed from scoreboardContainer scoreboardContainer.removeAllViews(); // Ensure the progress spinner is hidden progressContainer.setVisibility(View.INVISIBLE); // Ensure scoreboardEntriesList is not null and not empty first if (application.getScoreboardEntriesList() == null || application.getScoreboardEntriesList().size() <= 0) { closeAndShowError(getResources().getString(R.string.error_no_scores)); } else {/*w w w . ja va 2s . c o m*/ // Iterate through scoreboardEntriesList, creating new UI elements for each entry int index = 0; Iterator<ScoreboardEntry> scoreboardEntriesIterator = application.getScoreboardEntriesList().iterator(); while (scoreboardEntriesIterator.hasNext()) { // Get the current scoreboard entry final ScoreboardEntry currentScoreboardEntry = scoreboardEntriesIterator.next(); // FrameLayout Container for the currentScoreboardEntry ... // Create and add a new FrameLayout to display the details of this entry FrameLayout frameLayout = new FrameLayout(getActivity()); scoreboardContainer.addView(frameLayout); // Set the attributes for this frameLayout int topPadding = getResources().getDimensionPixelSize(R.dimen.scoreboard_entry_top_margin); frameLayout.setPadding(0, topPadding, 0, 0); // ImageView background image ... { // Create and add an ImageView for the background image to this entry ImageView backgroundImageView = new ImageView(getActivity()); frameLayout.addView(backgroundImageView); // Set the image of the backgroundImageView String uri = "drawable/scores_stub_even"; if (index % 2 != 0) { // Odd entry uri = "drawable/scores_stub_odd"; } int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName()); Drawable image = getResources().getDrawable(imageResource); backgroundImageView.setImageDrawable(image); // Other attributes of backgroundImageView to modify FrameLayout.LayoutParams backgroundImageViewLayoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); int backgroundImageViewMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_background_imageview_margin_top); backgroundImageViewLayoutParams.setMargins(0, backgroundImageViewMarginTop, 0, 0); backgroundImageViewLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry backgroundImageViewLayoutParams.gravity = Gravity.RIGHT; } backgroundImageView.setLayoutParams(backgroundImageViewLayoutParams); } // ProfilePictureView of the current user ... { // Create and add a ProfilePictureView for the current user entry's profile picture ProfilePictureView profilePictureView = new ProfilePictureView(getActivity()); frameLayout.addView(profilePictureView); // Set the attributes of the profilePictureView int profilePictureViewWidth = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_width); FrameLayout.LayoutParams profilePictureViewLayoutParams = new FrameLayout.LayoutParams( profilePictureViewWidth, profilePictureViewWidth); int profilePictureViewMarginLeft = 0; int profilePictureViewMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_top); int profilePictureViewMarginRight = 0; int profilePictureViewMarginBottom = 0; if (index % 2 == 0) { profilePictureViewMarginLeft = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_left); } else { profilePictureViewMarginRight = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_right); } profilePictureViewLayoutParams.setMargins(profilePictureViewMarginLeft, profilePictureViewMarginTop, profilePictureViewMarginRight, profilePictureViewMarginBottom); profilePictureViewLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry profilePictureViewLayoutParams.gravity = Gravity.RIGHT; } profilePictureView.setLayoutParams(profilePictureViewLayoutParams); // Finally set the id of the user to show their profile pic profilePictureView.setProfileId(currentScoreboardEntry.getId()); } // LinearLayout to hold the text in this entry // Create and add a LinearLayout to hold the TextViews LinearLayout textViewsLinearLayout = new LinearLayout(getActivity()); frameLayout.addView(textViewsLinearLayout); // Set the attributes for this textViewsLinearLayout FrameLayout.LayoutParams textViewsLinearLayoutLayoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); int textViewsLinearLayoutMarginLeft = 0; int textViewsLinearLayoutMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_top); int textViewsLinearLayoutMarginRight = 0; int textViewsLinearLayoutMarginBottom = 0; if (index % 2 == 0) { textViewsLinearLayoutMarginLeft = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_left); } else { textViewsLinearLayoutMarginRight = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_right); } textViewsLinearLayoutLayoutParams.setMargins(textViewsLinearLayoutMarginLeft, textViewsLinearLayoutMarginTop, textViewsLinearLayoutMarginRight, textViewsLinearLayoutMarginBottom); textViewsLinearLayoutLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry textViewsLinearLayoutLayoutParams.gravity = Gravity.RIGHT; } textViewsLinearLayout.setLayoutParams(textViewsLinearLayoutLayoutParams); textViewsLinearLayout.setOrientation(LinearLayout.VERTICAL); // TextView with the position and name of the current user { // Set the text that should go in this TextView first int position = index + 1; String currentScoreboardEntryTitle = position + ". " + currentScoreboardEntry.getName(); // Create and add a TextView for the current user position and first name TextView titleTextView = new TextView(getActivity()); textViewsLinearLayout.addView(titleTextView); // Set the text and other attributes for this TextView titleTextView.setText(currentScoreboardEntryTitle); titleTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerNameFont); } // TextView with the score of the current user { // Create and add a TextView for the current user score TextView scoreTextView = new TextView(getActivity()); textViewsLinearLayout.addView(scoreTextView); // Set the text and other attributes for this TextView scoreTextView.setText("Score: " + currentScoreboardEntry.getScore()); scoreTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerScoreFont); } // Finally make this frameLayout clickable so that a game starts with the user smashing // the user represented by this frameLayout in the scoreContainer frameLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { Bundle bundle = new Bundle(); bundle.putString("user_id", currentScoreboardEntry.getId()); Intent i = new Intent(); i.putExtras(bundle); getActivity().setResult(Activity.RESULT_FIRST_USER, i); getActivity().finish(); return false; } else { return true; } } }); // Increment the index before looping back index++; } } }
From source file:android.widget.PinnedHeaderListView.java
@Override public boolean onTouchEvent(final MotionEvent ev) { if (mHeaderTouched) { if (ev.getAction() == MotionEvent.ACTION_UP) mHeaderTouched = false;// w w w .ja v a 2s . c o m return true; } return super.onTouchEvent(ev); }
From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();// ww w .j a v a2 s.com boolean handled = false; if (mReturningToStart && ev.getAction() == MotionEvent.ACTION_DOWN) { mReturningToStart = false; } // enable?||??||?View? if (isEnabled() && !mReturningToStart && !canChildScrollUp()) { handled = onTouchEvent(ev); } return !handled ? super.onInterceptTouchEvent(ev) : handled; }