Skip to content

Commit

Permalink
Misc tweaks / bug fixes
Browse files Browse the repository at this point in the history
- readd "power off" to the main menu
- fix bug where stdout overflows into menu text
- remove +++++Go Back+++++ from main menu as there is nothing to go back to (detects menu depth)

Change-Id: Icb84ac86e55712412d07add0ab76955d7902f07c
  • Loading branch information
CEnnis91 authored and koush committed Jan 26, 2012
1 parent de338e5 commit 4f78176
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
10 changes: 7 additions & 3 deletions default_recovery_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ int device_handle_key(int key_code, int visible) {
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display())
if (!get_allow_toggle_display() && ui_menu_level > 0) {
return GO_BACK;
}
break;
case KEY_LEFTBRACE:
case KEY_ENTER:
Expand All @@ -53,10 +54,13 @@ int device_handle_key(int key_code, int visible) {
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display())
if (!get_allow_toggle_display() && ui_menu_level > 0) {
return GO_BACK;
}
case KEY_BACK:
return GO_BACK;
if (ui_menu_level > 0) {
return GO_BACK;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions default_recovery_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ char* MENU_ITEMS[] = { "reboot system now",
"backup and restore",
"mounts and storage",
"advanced",
"power off",
NULL };

void device_ui_init(UIParameters* ui_parameters) {
Expand Down
10 changes: 7 additions & 3 deletions recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ get_menu_selection(char** headers, char** items, int menu_only,
// throw away keys pressed previously, so user doesn't
// 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,14 +476,16 @@ get_menu_selection(char** headers, char** items, int menu_only,
case SELECT_ITEM:
chosen_item = selected;
if (ui_get_showing_back_button()) {
if (chosen_item == item_count) {
if (chosen_item == item_count-1) {
--ui_menu_level;
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,7 +696,8 @@ prompt_and_wait() {
for (;;) {
finish_recovery(NULL);
ui_reset_progress();


ui_menu_level = -1;
allow_display_toggle = 1;
int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0);
allow_display_toggle = 0;
Expand Down
3 changes: 3 additions & 0 deletions recovery_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ extern char* MENU_HEADERS[];
// Text of menu items.
extern char* MENU_ITEMS[];

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

int
get_menu_selection(char** headers, char** items, int menu_only, int initial_selection);

Expand Down
20 changes: 14 additions & 6 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ static void draw_screen_locked(void)

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) {
gr_color(MENU_TEXT_COLOR);
Expand Down Expand Up @@ -266,8 +267,12 @@ static void draw_screen_locked(void)
}
row++;
}
gr_fill(0, row*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
gr_fb_width(), row*CHAR_HEIGHT+CHAR_HEIGHT/2+1);

if (menu_items <= MAX_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_color(NORMAL_TEXT_COLOR);
Expand Down Expand Up @@ -652,18 +657,21 @@ int ui_start_menu(char** headers, char** items, int initial_selection) {
menu[i][text_cols-1] = '\0';
}

if (gShowBackButton) {
if (gShowBackButton && ui_menu_level > 0) {
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) {
if (gShowBackButton && ui_menu_level > 0) {
return menu_items - 1;
}
return menu_items;
Expand All @@ -676,8 +684,8 @@ int ui_menu_select(int sel) {
old_sel = menu_sel;
menu_sel = sel;

if (menu_sel < 0) menu_sel = menu_items + menu_sel;
if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;
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 < menu_show_start && menu_show_start > 0) {
Expand Down

0 comments on commit 4f78176

Please sign in to comment.