List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { float currentTouchY = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastDispatchY = currentTouchY;/*from w w w.ja v a 2 s .c o m*/ break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastDispatchY; mLastDispatchY = currentTouchY; if (isContentViewToTop() && isHeaderViewCompleteInvisible()) { if (differentY >= 0 && !mIsInControl) { mIsInControl = true; return resetDispatchTouchEvent(ev); } if (differentY <= 0 && mIsInControl) { mIsInControl = false; return resetDispatchTouchEvent(ev); } } break; } return super.dispatchTouchEvent(ev); }
From source file:net.oschina.app.ui.MainActivity.java
@SuppressLint("ClickableViewAccessibility") @Override// w w w . j a va2s .c om public boolean onTouch(View v, MotionEvent event) { super.onTouchEvent(event); boolean consumed = false; // use getTabHost().getCurrentTabView to decide if the current tab is // touched again if (event.getAction() == MotionEvent.ACTION_DOWN && v.equals(mTabHost.getCurrentTabView())) { // use getTabHost().getCurrentView() to get a handle to the view // which is displayed in the tab - and to get this views context Fragment currentFragment = getCurrentFragment(); if (currentFragment != null && currentFragment instanceof OnTabReselectListener) { OnTabReselectListener listener = (OnTabReselectListener) currentFragment; listener.onTabReselect(); consumed = true; } } return consumed; }
From source file:com.artemchep.horario.ui.widgets.SwipeBackLayout.java
private void chkDragable() { setOnTouchListener(new View.OnTouchListener() { @Override//from w w w.j av a2 s .c om 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:com.astuetz.viewpager.extensions.SwipeyTabsView.java
@Override public boolean onTouch(View v, MotionEvent event) { float x = event.getRawX(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDragX = x;/*w ww. ja v a 2 s .c o m*/ mPager.beginFakeDrag(); break; case MotionEvent.ACTION_MOVE: if (!mPager.isFakeDragging()) break; mPager.fakeDragBy((mDragX - x) * (-1)); mDragX = x; break; case MotionEvent.ACTION_UP: if (!mPager.isFakeDragging()) break; mPager.endFakeDrag(); break; } return v.equals(this) ? true : super.onTouchEvent(event); }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { SimpleMonthAdapter.CalendarDay calendarDay = getDayFromLocation(event.getX(), event.getY()); if (calendarDay != null) { onDayClick(calendarDay);/*from w w w . jav a 2s . c o m*/ } } return true; }
From source file:com.gizwits.framework.activity.BaseActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { // ?ViewEditText View v = getCurrentFocus(); if (isShouldHideInput(v, ev)) { hideSoftInput(v.getWindowToken()); }//from w w w . ja v a 2 s . c om } return super.dispatchTouchEvent(ev); }
From source file:com.appsimobile.appsii.SidebarHotspot.java
@Override public boolean onTouchEvent(MotionEvent e) { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: { mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(e); // remove the background to make sure it does not overlap // the sidebar mIsDragOpening = true;/* www . j a v a 2 s .co m*/ setBackgroundResource(0); float x = e.getX(); float y = e.getY(); if (mCallback != null) { mSwipeListener = mCallback.open(this, Gesture.TO_CENTER, (int) x, (int) y); mSwipeInProgress = mSwipeListener != null; mState = STATE_AWAITING_RELEASE; if (mVibrate) { vibrate(); } return true; } return false; } case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(e); float x = e.getX(); float y = e.getY(); return detectSwipe(x, y, e); case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: cancelMotionHandling(e, false); return false; } return super.onTouchEvent(e); }
From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java
/** * Creates the UI for the interactive authentication process * //from ww w . j a va2 s . c o m * @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:com.tony.casthelloworld.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent)); //Current Card Text currentCard = (TextView) findViewById(R.id.currentCard); //Remaining Cards Text remainingCards = (TextView) findViewById(R.id.cardsRemaining); //Start/Reset Game Button startGame = (Button) findViewById(R.id.startGame); startGame.setOnClickListener(new View.OnClickListener() { @Override//w ww.ja va 2 s. c o m public void onClick(View v) { initializeGame(); updateCast(); } }); //Next Card Button nextCard = (Button) findViewById(R.id.nextCard); nextCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //pop the card off //Update the current card getNextCard(); updateCast(); } }); //Show Card Button showCard = (Button) findViewById(R.id.showCard); showCard.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //Make the card visible if (deck.peek() != null) { currentCard.setText(prettyPrintCard(deck.peek())); } else { currentCard.setText("No more Cards!"); } return true; case MotionEvent.ACTION_UP: // No longer down if (deck.peek() != null) { currentCard.setText(CARD_HIDDEN_TEXT); } else { currentCard.setText("No more Cards!"); } return true; } return false; } }); // Configure Cast device discovery mMediaRouter = MediaRouter.getInstance(getApplicationContext()); mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory( CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build(); mMediaRouterCallback = new MyMediaRouterCallback(); }
From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java
@Override public boolean onTouch(final View view, final MotionEvent event) { final int action = event.getAction(); if (action == MotionEvent.ACTION_CANCEL) { showTop = false;/* w w w .j av a2s.co m*/ showBottom = false; } else if (action == MotionEvent.ACTION_UP) { if (showTop) { if (listener != null && lastUid != null) { listener.showLastItem(); } } else if (showBottom) { if (listener != null && nextUid != null) { listener.showNextItem(); } } showTop = false; showBottom = false; } return false; }