Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 4th, 2010  |  syntax: None  |  size: 4.59 KB  |  hits: 109  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
  2. index ca11de0..cb8b83f 100644
  3. --- a/android/src/org/rockbox/RockboxFramebuffer.java
  4. +++ b/android/src/org/rockbox/RockboxFramebuffer.java
  5. @@ -73,6 +73,21 @@ public class RockboxFramebuffer extends View
  6.                 Log.d("RockboxBootloader", (String) text);
  7.         }
  8.  
  9. +       public boolean onTrackBallEvent(MotionEvent me)
  10. +       {
  11. +               LOG("onTrackBallEvent");
  12. +               switch (me.getAction())
  13. +               {
  14. +               case MotionEvent.ACTION_MOVE:
  15. +                       buttonHandler(0, (int)me.getX(), (int)me.getY());
  16. +                       break;
  17. +               case MotionEvent.ACTION_DOWN:
  18. +                       buttonHandler(1, 0, 0);
  19. +                       break;
  20. +               }
  21. +               return true;
  22. +       }
  23. +      
  24.         public boolean onTouchEvent(MotionEvent me)
  25.         {
  26.                 LOG("onTouchEvent");
  27. @@ -106,4 +121,5 @@ public class RockboxFramebuffer extends View
  28.         public native void set_lcd_active(int active);
  29.         public native void pixelHandler(int x, int y);
  30.         public native void touchHandler(int down);
  31. +       public native void buttonHandler(int press, int relative_x, int relative_y);
  32.  }
  33. diff --git a/firmware/target/hosted/android/app/button-target.h b/firmware/target/hosted/android/app/button-target.h
  34. index 329ed65..73149a0 100644
  35. --- a/firmware/target/hosted/android/app/button-target.h
  36. +++ b/firmware/target/hosted/android/app/button-target.h
  37. @@ -30,27 +30,22 @@ void button_init_device(void);
  38.  int button_read_device(int *data);
  39.  
  40.  /* Main unit's buttons */
  41. -#define BUTTON_POWER      0x00000001
  42. -#define BUTTON_PLUS       0x00000002
  43. -#define BUTTON_MINUS      0x00000004
  44. -#define BUTTON_MENU       0x00000008
  45. -
  46. -/* Compatibility hacks for flipping. Needs a somewhat better fix. */
  47. -#define BUTTON_LEFT  BUTTON_MIDLEFT
  48. -#define BUTTON_RIGHT BUTTON_MIDRIGHT
  49. -#define BUTTON_UP    BUTTON_TOPMIDDLE
  50. -#define BUTTON_DOWN  BUTTON_BOTTOMMIDDLE
  51. +#define BUTTON_UP       0x00000001
  52. +#define BUTTON_DOWN     0x00000002
  53. +#define BUTTON_LEFT     0x00000004
  54. +#define BUTTON_RIGHT    0x00000008
  55. +#define BUTTON_SELECT   0x00000010
  56.  
  57.  /* Touch Screen Area Buttons */
  58. -#define BUTTON_TOPLEFT      0x00000010
  59. -#define BUTTON_TOPMIDDLE    0x00000020
  60. -#define BUTTON_TOPRIGHT     0x00000040
  61. -#define BUTTON_MIDLEFT      0x00000080
  62. -#define BUTTON_CENTER       0x00000100
  63. -#define BUTTON_MIDRIGHT     0x00000200
  64. -#define BUTTON_BOTTOMLEFT   0x00000400
  65. -#define BUTTON_BOTTOMMIDDLE 0x00000800
  66. -#define BUTTON_BOTTOMRIGHT  0x00001000
  67. +#define BUTTON_TOPLEFT      0x00000100
  68. +#define BUTTON_TOPMIDDLE    0x00000200
  69. +#define BUTTON_TOPRIGHT     0x00000400
  70. +#define BUTTON_MIDLEFT      0x00000800
  71. +#define BUTTON_CENTER       0x00001000
  72. +#define BUTTON_MIDRIGHT     0x00002000
  73. +#define BUTTON_BOTTOMLEFT   0x00004000
  74. +#define BUTTON_BOTTOMMIDDLE 0x00008000
  75. +#define BUTTON_BOTTOMRIGHT  0x00010000
  76.  
  77.  #define BUTTON_MAIN 0x1FFF
  78.  
  79. diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c
  80. index 1172880..2a5b653 100644
  81. --- a/firmware/target/hosted/android/button-android.c
  82. +++ b/firmware/target/hosted/android/button-android.c
  83. @@ -28,6 +28,7 @@
  84.  #include "touchscreen.h"
  85.  
  86.  static int last_y, last_x;
  87. +static int last_button;
  88.  
  89.  static enum {
  90.      STATE_UNKNOWN,
  91. @@ -64,13 +65,42 @@ Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this,
  92.          last_state = STATE_UP;
  93.  }
  94.  
  95. +/*
  96. + * this notifies us in an interrupt-like fashion when a hardware button is pressed */
  97. +JNIEXPORT void JNICALL
  98. +Java_org_rockbox_RockboxFramebuffer_butttonHandler(JNIEnv*env, jobject this,
  99. +                                                   int press, int relative_x, int relative_y)
  100. +{
  101. +    if (press)
  102. +        last_button = BUTTON_SELECT;
  103. +    else if (relative_y > 0)
  104. +        last_button = BUTTON_UP;
  105. +    else if (relative_y < 0)
  106. +        last_button = BUTTON_DOWN;
  107. +    else if (relative_x > 0)
  108. +        last_button = BUTTON_RIGHT;
  109. +    else if (relative_x < 0)
  110. +        last_button = BUTTON_LEFT;
  111. +}
  112. +
  113.  void button_init_device(void)
  114.  {
  115. +    last_button = BUTTON_NONE;
  116.  }
  117.  
  118.  int button_read_device(int *data)
  119.  {
  120. -    /* get grid button/coordinates based on the current touchscreen mode */
  121. -    int btn = touchscreen_to_pixels(last_x, last_y, data);
  122. -    return (last_state == STATE_DOWN ? btn : 0);
  123. +    int btn;
  124. +    if (last_button == BUTTON_NONE)
  125. +    {
  126. +        /* get grid button/coordinates based on the current touchscreen mode */
  127. +        btn = touchscreen_to_pixels(last_x, last_y, data);
  128. +        return (last_state == STATE_DOWN ? btn : 0);
  129. +    }
  130. +    else
  131. +    {
  132. +        btn = last_button;
  133. +        last_button = BUTTON_NONE;
  134. +        return btn;
  135. +    }
  136.  }