CustomScrollView.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.ivalentin.gm;
  2. import android.annotation.SuppressLint;
  3. import android.content.Context;
  4. import android.util.AttributeSet;
  5. import android.view.MotionEvent;
  6. import android.widget.ScrollView;
  7. /**
  8. * An extended ScrollView.
  9. * It allows to be swept from the left to open the application menu.
  10. *
  11. * @author Iñigo Valentin
  12. *
  13. * @see ScrollView
  14. *
  15. */
  16. public class CustomScrollView extends ScrollView{
  17. /**
  18. * Constructor.
  19. *
  20. * @param context The context of the app or Activity.
  21. */
  22. public CustomScrollView(Context context) {
  23. super(context);
  24. }
  25. /**
  26. * Constructor.
  27. *
  28. * @param context The context of the app or Activity.
  29. * @param attrs Attributes.
  30. */
  31. public CustomScrollView(Context context, AttributeSet attrs) {
  32. super(context, attrs);
  33. }
  34. /**
  35. * Constructor.
  36. *
  37. * @param context The context of the app or Activity.
  38. * @param attrs Attributes.
  39. * @param defStyle Default style.
  40. */
  41. public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
  42. super(context, attrs, defStyle);
  43. }
  44. /**
  45. * Overrides the default onTouchListener.
  46. *
  47. * If the motion is in the leftmost part of the screen, the event is not
  48. * passed along and the menu is shown.
  49. *
  50. * @see android.widget.ScrollView#onTouchEvent(android.view.MotionEvent)
  51. *
  52. * @param ev The MotionEvent triggering the action
  53. *
  54. * @return True if the app handles the motion (i.e. to slide), false otherwise (normal event)
  55. */
  56. @SuppressLint("ClickableViewAccessibility") //Disturbs the sliding process
  57. @Override
  58. public boolean onTouchEvent(MotionEvent ev) {
  59. int width = this.getWidth();
  60. super.onTouchEvent(ev);
  61. if (ev.getX() < (float) width / 10){
  62. return false;
  63. }
  64. else{
  65. return true;
  66. }
  67. }
  68. }