Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java index 84974d6..b6523f6 100644 import org.rockbox.Helper.MediaButtonReceiver; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.util.DisplayMetrics; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; public class RockboxFramebuffer extends View { private Bitmap btm; private ByteBuffer native_buf; private MediaButtonReceiver media_monitor; + private final DisplayMetrics metrics; + private final ViewConfiguration view_config; public RockboxFramebuffer(Context c, int lcd_width, int lcd_height, ByteBuffer native_fb) public class RockboxFramebuffer extends View media_monitor.register(); /* the service needs to know the about us */ ((RockboxService)c).set_fb(this); + + metrics = c.getResources().getDisplayMetrics(); + view_config = ViewConfiguration.get(c); } public void onDraw(Canvas c) public class RockboxFramebuffer extends View media_monitor.unregister(); } + @SuppressWarnings("unused") + private int getDpi() + { + return metrics.densityDpi; + } + + @SuppressWarnings("unused") + private int getScrollThreshold() + { + return view_config.getScaledTouchSlop(); + } + public native void set_lcd_active(int active); public native void touchHandler(boolean down, int x, int y); public native boolean buttonHandler(int keycode, boolean state); diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c index d78f005..aad3b60 100644 void _gui_synclist_stop_kinetic_scrolling(void) * otherwise it returns true even if it didn't actually scroll, * but scrolling mode shouldn't be changed **/ + + +static int scroll_begin_threshold; +static int threshold_accumulation ; static bool swipe_scroll(struct gui_synclist * gui_list, int line_height, int difference) { /* fixme */ const enum screen_type screen = screens[SCREEN_MAIN].screen_type; const int nb_lines = viewport_get_nb_lines(&list_text[screen]); + if (UNLIKELY(scroll_begin_threshold == 0)) + scroll_begin_threshold = touchscreen_get_scroll_threshold(); + /* make selecting items easier */ - if (abs(difference) < SCROLL_BEGIN_THRESHOLD && scroll_mode == SCROLL_NONE) + threshold_accumulation += abs(difference); + if (threshold_accumulation < scroll_begin_threshold && scroll_mode == SCROLL_NONE) return false; + threshold_accumulation = 0; + /* does the list even scroll? if no, return but still show * the caller that we would scroll */ if (nb_lines >= gui_list->nb_items) unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list) && !is_kinetic_over()); int icon_width = 0; int line, list_width = list_text_vp->width; + static bool wait_for_release = false; released = (button&BUTTON_REL) != 0; + if (released) + wait_for_release = false; if (button == ACTION_NONE || button == ACTION_UNKNOWN) { unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list) return ACTION_NONE; } + if (button & BUTTON_REPEAT && scroll_mode == SCROLL_NONE + && !wait_for_release) + { + /* held a single line for a while, bring up the context menu */ + gui_synclist_select_item(gui_list, list_start_item + line); + /* don't sent context repeatedly */ + wait_for_release = true; + return ACTION_STD_CONTEXT; + } if (released && !cancelled_kinetic) { /* Pen was released anywhere on the screen */ last_position = 0; if (scroll_mode == SCROLL_NONE) { + /* select current line */ gui_synclist_select_item(gui_list, list_start_item + line); - /* If BUTTON_REPEAT is set, then the pen was hold on - * the same line for some time - * -> context menu - * otherwise, - * -> select - **/ - if (button & BUTTON_REPEAT) - return ACTION_STD_CONTEXT; return ACTION_STD_OK; } else diff --git a/firmware/drivers/touchscreen.c b/firmware/drivers/touchscreen.c index 9660e0c..44d2425 100644 enum touchscreen_mode touchscreen_get_mode(void) { return current_mode; } + + +#if ((CONFIG_PLATFORM & PLATFORM_ANDROID) == 0) +/* android has an API for this */ + +#define TOUCH_SLOP 16 + +static int dpi = 0; +int touchscreen_get_scroll_threshold(void) +{ + if (!dpi) + dpi = lcd_get_dpi(); + + /* Inspired by Android calculation + * + * density: real dpi / reference dpi (=160) + * threshold = (int) (density * TOUCH_SLOP + 0.5f); (original calculation) + * + * the + 0.5f is to round up, but we have no floats. but we reorder + * the calculation so that it should be fine + */ + return (dpi*TOUCH_SLOP/160); +} + +#endif diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index 79231d1..e6e19b1 100644 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y, #endif /* HAVE_LCD_BITMAP */ + +#ifdef HAVE_TOUCHSCREEN +/* only needed for touchscreen for now, feel free to implement it for others + * once needed + */ + +/* returns the pixel density of the display */ +extern int lcd_get_dpi(void); +#endif + #endif /* __LCD_H__ */ diff --git a/firmware/export/touchscreen.h b/firmware/export/touchscreen.h index 7d1eb4a..a27e60c 100644 void touchscreen_set_mode(enum touchscreen_mode mode); enum touchscreen_mode touchscreen_get_mode(void); void touchscreen_disable_mapping(void); void touchscreen_reset_mapping(void); +int touchscreen_get_scroll_threshold(void); #endif /* __TOUCHSCREEN_INCLUDE_H_ */ diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c index 78b1f12..f4ef7b5 100644 static jmethodID java_lcd_update; static jmethodID java_lcd_update_rect; static bool display_on; +static int dpi; +static int scroll_threshold; void lcd_init_device(void) { void lcd_init_device(void) RockboxFramebuffer_class, "java_lcd_update_rect", "(IIII)V"); + + jmethodID get_dpi = e->GetMethodID(env_ptr, + RockboxFramebuffer_class, + "getDpi", "()I"); + + jmethodID get_scroll_threshold + = e->GetMethodID(env_ptr, + RockboxFramebuffer_class, + "getScrollThreshold", "()I"); + + dpi = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance, + get_dpi); + scroll_threshold = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance, + get_scroll_threshold); display_on = true; } bool lcd_active(void) return display_on; } +int lcd_get_dpi(void) +{ + return dpi; +} + +int touchscreen_get_scroll_threshold(void) +{ + return scroll_threshold; +} + /* * (un)block lcd updates. * |