Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. public boolean onTouchEvent(MotionEvent event) {
  2. if (this.mSwipe2SleepActive && event.getAction() == 1 && this.mIsDown) {
  3. this.mIsDown = false;
  4. mySwipeDetector(this.mDownX, this.mDownY, this.mDownTime, event.getX(), event.getY(), System.currentTimeMillis());
  5. }
  6. if (this.mTaskSwitchHelper.onTouchEvent(event)) {
  7. return true;
  8. }
  9. if (this.mDeadZone != null && event.getAction() == 4) {
  10. this.mDeadZone.poke(event);
  11. }
  12. return super.onTouchEvent(event);
  13. }
  14.  
  15. private void mySwipeDetector(float e1X, float e1Y, long e1Time, float e2X, float e2Y, long e2Time) {
  16. float distanceX = e2X - e1X;
  17. float distanceY = e2Y - e1Y;
  18. float velocityX = (distanceX / ((float) (e2Time - e1Time))) * 1000.0f;
  19. float velocityY = (distanceY / ((float) (e2Time - e1Time))) * 1000.0f;
  20. String summary = "";
  21. if (this.mContext.getResources().getConfiguration().orientation == 1) {
  22. if (Math.abs(distanceX) > Math.abs(distanceY) && Math.abs(distanceX) > 300.0f && e2Y > -50.0f && Math.abs(velocityX) > 1000.0f) {
  23. this.mPowerManager.goToSleep(SystemClock.uptimeMillis());
  24. }
  25. } else if (Math.abs(distanceY) > Math.abs(distanceX) && Math.abs(distanceY) > 300.0f && e2X > -50.0f && Math.abs(velocityY) > 1000.0f) {
  26. this.mPowerManager.goToSleep(SystemClock.uptimeMillis());
  27. }
  28. }
  29.  
  30. public boolean onInterceptTouchEvent(MotionEvent event) {
  31. if (this.mSwipe2SleepActive && event.getAction() == 0) {
  32. this.mDownTime = System.currentTimeMillis();
  33. this.mDownX = event.getX();
  34. this.mDownY = event.getY();
  35. this.mIsDown = true;
  36. }
  37. return this.mTaskSwitchHelper.onInterceptTouchEvent(event);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement