List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:org.cocos2dx.lib.TextInputWraper.java
private void dumpEvent(MotionEvent event) { String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" }; StringBuilder sb = new StringBuilder(); int action = event.getAction(); int actionCode = action & MotionEvent.ACTION_MASK; sb.append("event ACTION_").append(names[actionCode]); if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) { sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_ID_SHIFT); sb.append(")"); }// ww w . j av a 2 s. co m sb.append("["); for (int i = 0; i < event.getPointerCount(); i++) { sb.append("#").append(i); sb.append("(pid ").append(event.getPointerId(i)); sb.append(")=").append((int) event.getX(i)); sb.append(",").append((int) event.getY(i)); if (i + 1 < event.getPointerCount()) sb.append(";"); } sb.append("]"); Log.d(TAG, sb.toString()); }
From source file:com.brightcove.player.samples.offlineplayback.VideoListAdapter.java
@Override public void onBindViewHolder(final ViewHolder holder, int position) { updateView(holder, position, null);//from ww w .j av a2 s .c om // Setup listeners to handle user interactions holder.videoThumbnailImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { boolean consumed = false; if (event.getAction() == MotionEvent.ACTION_DOWN) { consumed = true; } if (event.getAction() == MotionEvent.ACTION_UP) { listener.playVideo(holder.getVideo()); consumed = true; } return consumed; } }); holder.rentButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { listener.rentVideo(holder.video); } return false; } }); holder.buyButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { listener.buyVideo(holder.video); } return false; } }); holder.downloadButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { listener.downloadVideo(holder.video); } return false; } }); holder.pauseButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { listener.pauseVideoDownload(holder.video); } return false; } }); holder.resumeButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { listener.resumeVideoDownload(holder.video); } return false; } }); holder.deleteButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { holder.videoStatusText.setText("Deleting video..."); listener.deleteVideo(holder.video); } return false; } }); }
From source file:com.awt.supark.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cont = this;/*from ww w . j a v a2s . c o m*/ // Animations anim_zoom_in = AnimationUtils.loadAnimation(this, R.anim.zoom_in); anim_zoom_out = AnimationUtils.loadAnimation(this, R.anim.zoom_out); anim_fade_in = AnimationUtils.loadAnimation(this, R.anim.fade_in); anim_fade_out = AnimationUtils.loadAnimation(this, R.anim.fade_out); anim_slide_up_fade_in = AnimationUtils.loadAnimation(this, R.anim.slide_up_fade_in); anim_slide_down_fade_out = AnimationUtils.loadAnimation(this, R.anim.slide_down_fade_out); anim_center_open_up = AnimationUtils.loadAnimation(this, R.anim.center_open_up); anim_anticipate_rotate_zoom_out = AnimationUtils.loadAnimation(this, R.anim.anticipate_rotate_zoom_out); anim_anticipate_rotate_zoom_in = AnimationUtils.loadAnimation(this, R.anim.anticipate_rotate_zoom_in); anim_blink = AnimationUtils.loadAnimation(this, R.anim.blink); anim_car_enter = AnimationUtils.loadAnimation(this, R.anim.car_enter); anim_car_leave = AnimationUtils.loadAnimation(this, R.anim.car_leave); // UI elements btnPark = (ImageButton) findViewById(R.id.buttonPark); btnZone1 = (ImageButton) findViewById(R.id.buttonZone1); btnZone2 = (ImageButton) findViewById(R.id.buttonZone2); btnZone3 = (ImageButton) findViewById(R.id.buttonZone3); btnZone4 = (ImageButton) findViewById(R.id.buttonZone4); locationInfo = (TextView) findViewById(R.id.textViewLocationInfo); imageLocation = (ImageView) findViewById(R.id.imageLocation); imageCar = (ImageView) findViewById(R.id.imageCar); textParkingScreen = (TextView) findViewById(R.id.textParkingScreen); btnCars = (FloatingActionButton) findViewById(R.id.buttonCars); btnStatistics = (FloatingActionButton) findViewById(R.id.buttonStatistics); btnEtc = (FloatingActionButton) findViewById(R.id.buttonEtc); btnMap = (FloatingActionButton) findViewById(R.id.buttonMap); zonePrice = (TextView) findViewById(R.id.textViewZonePrice); licensePlate = (LinearLayout) findViewById(R.id.licensePlate); licenseCity = (TextView) findViewById(R.id.city); licenseNum = (TextView) findViewById(R.id.num); tapHereText = (LinearLayout) findViewById(R.id.tapHereText); tapHereText1 = (TextView) findViewById(R.id.tapHereText1); // Layouts backDimmer = (RelativeLayout) findViewById(R.id.back_dimmer); contentLinear = (LinearLayout) findViewById(R.id.contentLinear); tableRowTopHalf = (TableRow) findViewById(R.id.tableRowTopHalf); otherContent = (FrameLayout) findViewById(R.id.otherContent); parkingBackground = (LinearLayout) findViewById(R.id.parkingBackground); wrapper = (RelativeLayout) findViewById(R.id.wrapper); sharedprefs = PreferenceManager.getDefaultSharedPreferences(cont); autoLoc = sharedprefs.getBoolean("autoloc", true); lastLicense = sharedprefs.getBoolean("lastlicenseremember", true); showTicket = sharedprefs.getBoolean("showTicket", true); debugNumbers = sharedprefs.getBoolean("debugNumbers", true); debugsendsms = sharedprefs.getBoolean("debugsendsms", true); setLanguage(sharedprefs.getString("lang", "auto")); tapHereText1.setText(getString(R.string.tap_here2)); if (lastLicense) currentLicense = sharedprefs.getString("lastlicense", ""); fragmentManager = getSupportFragmentManager(); // Setting up the handlers parkHandler = new ParkingDataHandler(this); parkHandler.checkForUpdate(); // Checks that the local database is up to date parkHandler.throwHandler(mHandler); // Initializes the message handler smsHandler = new ParkingSmsSender(this); smsHandler.throwHandler(smsResponse); // Initializes the message handler layoutHandler = new LayoutHandler(this); CarHandler = new carHandler(this); zoneHandler = new ZoneHandler(this); btnPark.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == android.view.MotionEvent.ACTION_DOWN) { view.startAnimation(anim_zoom_out); anim_zoom_out.setFillAfter(true); } else if (motionEvent.getAction() == android.view.MotionEvent.ACTION_UP) { view.startAnimation(anim_zoom_in); anim_zoom_in.setFillAfter(true); } return false; } }); // Setting up a listener to track the click events for the parking button btnPark.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!pullUpStarted) { pullUpStarted = true; parkingInit("start"); } } }); // Turning off zone button highlight layoutHandler.activeZoneButton(0, act); // If the auto locate setting was enabled starts locating if (autoLoc) { getGPSzone(null); } else { currentZone = 0; layoutHandler.updateLocationTextButton(act); } CarHandler.updateLicense(act); setDebugNumbers(); // Starting the background service mServiceIntent = new Intent(act, ParkingTimerService.class); Log.i("Main", "OnCreate"); startTimerService(0); }
From source file:app.android.datetimepicker.date.SimpleMonthView.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: final int day = getDayFromLocation(event.getX(), event.getY()); if (day >= 0) { onDayClick(day);// ww w . j a v a2s. co m } break; } return true; }
From source file:com.benefit.buy.library.viewpagerindicator.UnderlinePageIndicator.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from w w w . java 2s . co 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.andview.refreshview.swipe.SwipeMenuLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = mLastX = (int) ev.getX(); mDownY = (int) ev.getY(); isIntercepted = false;//from w ww . j ava 2 s. c om break; case MotionEvent.ACTION_MOVE: int disX = (int) (ev.getX() - mDownX); int disY = (int) (ev.getY() - mDownY); isIntercepted = Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY); break; case MotionEvent.ACTION_UP: isIntercepted = false; if (isMenuOpen() && mSwipeCurrentHorizontal.isClickOnContentView(getWidth(), ev.getX())) { smoothCloseMenu(); isIntercepted = true; } break; case MotionEvent.ACTION_CANCEL: isIntercepted = false; if (!mScroller.isFinished()) mScroller.abortAnimation(); break; } return isIntercepted; }
From source file:com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy.java
/** * Receives hover events when touch exploration is turned on in SDK versions * ICS and higher.//w ww. ja va 2 s . co m * * @param event The hover event. * @return {@code true} if the event is handled */ public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) { final int x = (int) event.getX(); final int y = (int) event.getY(); final Key previousKey = mLastHoverKey; final Key key; if (pointInView(x, y)) { key = tracker.getKeyOn(x, y); } else { key = null; } mLastHoverKey = key; switch (event.getAction()) { case MotionEvent.ACTION_HOVER_EXIT: // Make sure we're not getting an EXIT event because the user slid // off the keyboard area, then force a key press. if (key != null) { getAccessibilityNodeProvider().simulateKeyPress(key); } //$FALL-THROUGH$ case MotionEvent.ACTION_HOVER_ENTER: return onHoverKey(key, event); case MotionEvent.ACTION_HOVER_MOVE: if (key != previousKey) { return onTransitionKey(key, previousKey, event); } else { return onHoverKey(key, event); } } return false; }
From source file:com.base.app.widget.indicatorview.UnderlinePageIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from w w w . java 2s . 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.android.yijiang.kzx.widget.betterpickers.calendardatepicker.SimpleMonthView.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: final CalendarDay day = getDayFromLocation(event.getX(), event.getY()); if (day != null) { onDayClick(day);/*from w w w .j a va2 s . c om*/ } break; } return true; }