Skip to content

Commit

Permalink
fix a bunch of off by one errors. disable display toggle.
Browse files Browse the repository at this point in the history
Change-Id: Ie34a787188f7df5ab46573bba50dd593bc728514
  • Loading branch information
koush committed Jul 18, 2012
1 parent 382525c commit 9209576
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ typedef struct {
FILE* fopen_path(const char *path, const char *mode);

int ui_get_selected_item();
int ui_is_showing_back_button();

#endif // RECOVERY_COMMON_H
6 changes: 3 additions & 3 deletions default_recovery_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int device_handle_key(int key_code, int visible) {
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display() && ui_menu_level > 0) {
if (!get_allow_toggle_display() && !ui_root_menu) {
return GO_BACK;
}
break;
Expand All @@ -54,11 +54,11 @@ int device_handle_key(int key_code, int visible) {
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display() && ui_menu_level > 0) {
if (!get_allow_toggle_display() && !ui_root_menu) {
return GO_BACK;
}
case KEY_BACK:
if (ui_menu_level > 0) {
if (!ui_root_menu) {
return GO_BACK;
}
}
Expand Down
17 changes: 8 additions & 9 deletions recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static const char *LOG_FILE = "/cache/recovery/log";
static const char *LAST_LOG_FILE = "/cache/recovery/last_log";
static const char *CACHE_ROOT = "/cache";
static const char *SDCARD_ROOT = "/sdcard";
static int allow_display_toggle = 1;
static int allow_display_toggle = 0;
static int poweroff = 0;
static const char *SDCARD_PACKAGE_FILE = "/sdcard/update.zip";
static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
Expand Down Expand Up @@ -434,7 +434,6 @@ get_menu_selection(char** headers, char** items, int menu_only,
// accidentally trigger menu items.
ui_clear_key_queue();

++ui_menu_level;
int item_count = ui_start_menu(headers, items, initial_selection);
int selected = initial_selection;
int chosen_item = -1;
Expand Down Expand Up @@ -475,17 +474,15 @@ get_menu_selection(char** headers, char** items, int menu_only,
break;
case SELECT_ITEM:
chosen_item = selected;
if (ui_get_showing_back_button()) {
if (chosen_item == item_count-1) {
--ui_menu_level;
if (ui_is_showing_back_button()) {
if (chosen_item == item_count) {
chosen_item = GO_BACK;
}
}
break;
case NO_ACTION:
break;
case GO_BACK:
--ui_menu_level;
chosen_item = GO_BACK;
break;
}
Expand Down Expand Up @@ -693,6 +690,7 @@ wipe_data(int confirm) {
ui_print("Data wipe complete.\n");
}

int ui_root_menu = 0;
static void
prompt_and_wait() {
char** headers = prepend_title((const char**)MENU_HEADERS);
Expand All @@ -701,10 +699,11 @@ prompt_and_wait() {
finish_recovery(NULL);
ui_reset_progress();

ui_menu_level = -1;
allow_display_toggle = 1;
ui_root_menu = 1;
// allow_display_toggle = 1;
int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0);
allow_display_toggle = 0;
ui_root_menu = 0;
// allow_display_toggle = 0;

// device-specific code may take some action here. It may
// return one of the core actions handled in the switch
Expand Down
2 changes: 1 addition & 1 deletion recovery_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extern char* MENU_HEADERS[];
extern char* MENU_ITEMS[];

// Loosely track the depth of the current menu
int ui_menu_level;
extern int ui_root_menu;

int
get_menu_selection(char** headers, char** items, int menu_only, int initial_selection);
Expand Down
23 changes: 10 additions & 13 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ static void draw_screen_locked(void)
int total_rows = gr_fb_height() / CHAR_HEIGHT;
int i = 0;
int j = 0;
int offset = 0; // offset of separating bar under menus
int row = 0; // current row that we are drawing on
if (show_menu) {
#ifndef BOARD_TOUCH_RECOVERY
Expand Down Expand Up @@ -287,11 +286,8 @@ static void draw_screen_locked(void)
break;
}

if (menu_items <= max_menu_rows)
offset = 1;

gr_fill(0, (row-offset)*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
gr_fb_width(), (row-offset)*CHAR_HEIGHT+CHAR_HEIGHT/2+1);
gr_fill(0, row*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
gr_fb_width(), row*CHAR_HEIGHT+CHAR_HEIGHT/2+1);
#else
row = draw_touch_menu(menu, menu_items, menu_top, menu_sel, menu_show_start);
#endif
Expand Down Expand Up @@ -763,21 +759,18 @@ int ui_start_menu(char** headers, char** items, int initial_selection) {
menu[i][MENU_MAX_COLS-1] = '\0';
}

if (gShowBackButton && ui_menu_level > 0) {
if (gShowBackButton && !ui_root_menu) {
strcpy(menu[i], " - +++++Go Back+++++");
++i;
}

strcpy(menu[i], " ");
++i;

menu_items = i - menu_top;
show_menu = 1;
menu_sel = menu_show_start = initial_selection;
update_screen_locked();
}
pthread_mutex_unlock(&gUpdateMutex);
if (gShowBackButton && ui_menu_level > 0) {
if (gShowBackButton && !ui_root_menu) {
return menu_items - 1;
}
return menu_items;
Expand All @@ -790,8 +783,8 @@ int ui_menu_select(int sel) {
old_sel = menu_sel;
menu_sel = sel;

if (menu_sel < 0) menu_sel = menu_items-1 + menu_sel;
if (menu_sel >= menu_items-1) menu_sel = menu_sel - menu_items+1;
if (menu_sel < 0) menu_sel = menu_items + menu_sel;
if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;


if (menu_sel < menu_show_start && menu_show_start > 0) {
Expand Down Expand Up @@ -982,6 +975,10 @@ int ui_get_showing_back_button() {
return gShowBackButton;
}

int ui_is_showing_back_button() {
return gShowBackButton && !ui_root_menu;
}

int ui_get_selected_item() {
return menu_sel;
}
Expand Down

0 comments on commit 9209576

Please sign in to comment.