List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:Main.java
public static int getActionMasked(MotionEvent paramMotionEvent) { return 0xFF & paramMotionEvent.getAction(); }
From source file:Main.java
public static void handleTouches(ImageView button) { button.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent m) { if (m.getAction() == MotionEvent.ACTION_DOWN) { darkenImage((ImageView) v); } else if (m.getAction() == MotionEvent.ACTION_UP) { ((ImageView) v).setColorFilter(null); }//from w ww . j a v a2 s . co m return false; } }); }
From source file:Main.java
public static String eventToString(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: return "DOWN"; case MotionEvent.ACTION_MOVE: return "MOVE"; case MotionEvent.ACTION_UP: return "UP"; case MotionEvent.ACTION_CANCEL: return "CANCEL"; case MotionEvent.ACTION_OUTSIDE: return "OUTSIDE"; case MotionEvent.ACTION_POINTER_DOWN: return "POINTER DOWN"; case MotionEvent.ACTION_POINTER_UP: return "POINTER UP"; }// w ww. ja va2 s .co m return "UNKNOWN"; }
From source file:Main.java
public static void setViewTouchHightlighted(final View view) { if (view == null) { return;//from w ww .j a v a 2s.c om } view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { view.setBackgroundColor(Color.rgb(1, 175, 244)); } else if (event.getAction() == MotionEvent.ACTION_UP) { view.setBackgroundColor(Color.rgb(255, 255, 255)); } return false; } }); }
From source file:Main.java
/** * Returns {@true} if the provided event is a touch exploration (e.g. hover) * event. This is used to determine whether the event should be processed by * the touch exploration code within the keyboard. * * @param event The event to check./*from ww w. j a va2 s. c om*/ * @return {@true} is the event is a touch exploration event */ public static boolean isTouchExplorationEvent(final MotionEvent event) { final int action = event.getAction(); return action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_EXIT || action == MotionEvent.ACTION_HOVER_MOVE; }
From source file:Main.java
public static void addTouchFeedback(final ImageView view) { view.setOnTouchListener(new View.OnTouchListener() { private Rect rect; @Override/*ww w . j a va 2 s.c om*/ public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { view.setColorFilter(Color.argb(50, 0, 0, 0)); rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); } if (event.getAction() == MotionEvent.ACTION_UP) { view.setColorFilter(Color.argb(0, 0, 0, 0)); } if (event.getAction() == MotionEvent.ACTION_MOVE) { if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())) { view.setColorFilter(Color.argb(0, 0, 0, 0)); } } return false; } }); }
From source file:Main.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return;// ww w. j av a 2 s. com int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { view = listAdapter.getView(i, view, listView); if (i == 0) view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += view.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); listView.setOnTouchListener(new View.OnTouchListener() { // Setting on Touch Listener for handling the touch inside ScrollView @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_MOVE) { return true; // Indicates that this has been handled by you and will not be forwarded further. } return false; } }); }
From source file:Main.java
public static void setOnTouchScaleAnimation(View targetView, final float scaleX, final float scaleY) { targetView.setOnTouchListener(new View.OnTouchListener() { @Override/*www . j a v a2 s . c om*/ public boolean onTouch(View v, MotionEvent event) { final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: { ScaleAnimation anim = new ScaleAnimation(1.0f, scaleX, 1.0f, scaleY, v.getWidth() / 2, v.getHeight() / 2); anim.setDuration(60); anim.setFillEnabled(true); anim.setFillAfter(true); v.startAnimation(anim); break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { ScaleAnimation anim = new ScaleAnimation(scaleX, 1.0f, scaleY, 1.0f, v.getWidth() / 2, v.getHeight() / 2); anim.setDuration(100); v.startAnimation(anim); break; } } return false; } }); }
From source file:Main.java
public static void makeListViewWorkableInScollView(ListView lv) { lv.setOnTouchListener(new ListView.OnTouchListener() { @Override//from ww w. j a v a2 s . c o m public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: // Disallow ScrollView to intercept touch events. v.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: // Allow ScrollView to intercept touch events. v.getParent().requestDisallowInterceptTouchEvent(false); break; } // Handle ListView touch events. v.onTouchEvent(event); return true; } }); }
From source file:Main.java
/** * inject a image touch overley/*from w ww .java 2 s. c om*/ * @param v * @param event */ public static boolean imageOverlay(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // overlay is black with transparency of 0x77 (119) view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP); view.invalidate(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { // clear the overlay view.getDrawable().clearColorFilter(); view.invalidate(); break; } } return false; }