static int menu_get_selection(Menu* thiz) { ui_clear_key_queue(); menu_update_screen(thiz); int chosen_item = -1; while (chosen_item < 0) { int key = ui_wait_key(); int action = device_handle_key(key); if (action < 0) { switch (action) { case HIGHLIGHT_UP: menu_ui_select_up(thiz); break; case HIGHLIGHT_DOWN: //LOGE("**HIGHLIGHT_DOWN"); menu_ui_select_down(thiz); break; case SELECT_ITEM: chosen_item = thiz->menu_sel; break; case NO_ACTION: break; } } } return chosen_item; }
// runs the program and redirects it's output to the screen using ui_print int graphchoice_main(int argc, char** argv) { if (argc>=2) { ui_init(); ui_print(EXPAND(RECOVERY_VERSION)" - choice app\n"); ui_set_show_text(1); ui_reset_progress(); ui_clear_key_queue(); char** headers; char** list; headers = malloc(sizeof(char*)*3); headers[0] = argv[1]; headers[1] = ""; headers[2] = NULL; list = malloc(sizeof(char*)*(argc+2)); list[0] = NULL; list[1] = NULL; int i=2; while (argv[i]) { list[i-2] = argv[i]; list[i-1] = NULL; i++; } int chosen_item = GO_BACK; while (chosen_item == GO_BACK) { chosen_item = get_menu_selection(headers,list,0,0); } gr_exit(); ev_exit(); return chosen_item; } else { printf("Usage: graphchoice question [option1] [option2] [option3] [...].\n"); return -1; } }
int apply_from_adb() { stop_adbd(); set_usb_driver(1); ui_print("\n\n电脑端刷机开始 ...\n请在电脑上使用如下命令:\n" "\"adb sideload <刷机包路径>\"从电脑刷机...\n\n"); struct sideload_waiter_data data; if ((data.child = fork()) == 0) { execl("/sbin/recovery", "recovery", "adbd", NULL); _exit(-1); } pthread_t sideload_thread; pthread_create(&sideload_thread, NULL, &adb_sideload_thread, &data); static char* headers[] = { "ADB Sideload", "", NULL }; static char* list[] = { "返回取消", NULL }; get_menu_selection(headers, list, 0, 0); set_usb_driver(0); maybe_restart_adbd(); // kill the child kill(data.child, SIGTERM); pthread_join(sideload_thread, NULL); ui_clear_key_queue(); struct stat st; if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) { if (errno == ENOENT) { ui_print("没有接收到刷机包.\n"); ui_set_background(BACKGROUND_ICON_ERROR); } else { ui_print("读取刷机包失败:\n %s\n", strerror(errno)); ui_set_background(BACKGROUND_ICON_ERROR); } return INSTALL_ERROR; } int install_status = install_package(ADB_SIDELOAD_FILENAME); ui_reset_progress(); if (install_status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("电脑端刷机失败.\n"); } remove(ADB_SIDELOAD_FILENAME); return install_status; }
/** * get_menu_selection() * */ int get_menu_selection(char** headers, char** items, int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); ui_start_menu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; while (chosen_item < 0) { #ifdef BOARD_WITH_CPCAP int level = battery_level(); if (level > 0) { if ((50 * progress_value) != level / 2) { progress_value = level / 100.0; if (level < 20) ui_print("Low battery ! %3d %%\n", level); ui_reset_progress(); ui_show_progress(progress_value, 1); ui_set_progress(1.0); } } #endif int key = ui_wait_key(); int visible = ui_text_visible(); int action = device_handle_key(key, visible); if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; break; case ACTION_CANCEL: chosen_item = GO_BACK; break; case NO_ACTION: break; } } else if (!menu_only) { chosen_item = action; } } ui_end_menu(); return chosen_item; }
int apply_from_adb() { stop_adbd(); set_usb_driver(1); ui_print("\n\nSideload started ...\nNow send the package you want to apply\n" "to the device with \"adb sideload <filename>\"...\n\n"); struct sideload_waiter_data data; if ((data.child = fork()) == 0) { execl("/sbin/recovery", "recovery", "adbd", NULL); _exit(-1); } pthread_t sideload_thread; pthread_create(&sideload_thread, NULL, &adb_sideload_thread, &data); static const char* headers[] = { "ADB Sideload", "", NULL }; static char* list[] = { "Cancel sideload", NULL }; get_menu_selection(headers, list, 0, 0); set_usb_driver(0); maybe_restart_adbd(); // kill the child kill(data.child, SIGTERM); pthread_join(sideload_thread, NULL); ui_clear_key_queue(); struct stat st; if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) { if (errno == ENOENT) { ui_print("No package received.\n"); ui_set_background(BACKGROUND_ICON_ERROR); } else { ui_print("Error reading package:\n %s\n", strerror(errno)); ui_set_background(BACKGROUND_ICON_ERROR); } return INSTALL_ERROR; } int install_status = install_package(ADB_SIDELOAD_FILENAME); ui_reset_progress(); if (install_status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } remove(ADB_SIDELOAD_FILENAME); return install_status; }
static void reset_gestures() { diff_x = 0; diff_y = 0; old_x = 0; old_y = 0; touch_x = 0; touch_y = 0; ui_clear_key_queue(); }
static void reset_touch(input_device *dev) { diff_x = 0; diff_y = 0; dev->touch_start.x = 0; dev->touch_start.y = 0; dev->touch_pos.x = 0; dev->touch_pos.y = 0; dev->slot_current = 0; dev->slide_right = 0; dev->slide_left = 0; ui_clear_key_queue(); }
static int get_menu_selection(char** headers, char** items, int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); ui_start_menu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; while (chosen_item < 0) { int key = ui_wait_key(); int visible = ui_text_visible(); if (key == -1) { // ui_wait_key() timed out if (ui_text_ever_visible()) { continue; } else { LOGI("timed out waiting for key input; rebooting.\n"); ui_end_menu(); return ITEM_REBOOT; } } int action = device_handle_key(key, visible); if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; break; case NO_ACTION: break; } } else if (!menu_only) { chosen_item = action; } } ui_end_menu(); return chosen_item; }
int get_menu_selection(char** headers, char** items, int menu_only, int selected) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); ui_start_menu(headers, items,selected); int chosen_item = -1; while (chosen_item < 0) { int key = ui_wait_key(); /* char* key_str = calloc(18,sizeof(char)); sprintf(key_str, "Key %d pressed.\n", key); ui_print(key_str);*/ if (key == KEY_BACKSPACE || key == KEY_END) { return(ITEM_BACK); } int visible = ui_text_visible(); int action = device_handle_key(key, visible); if (action < 0) { switch (action) { case ITEM_BACK: return(ITEM_BACK); break; case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; break; case NO_ACTION: break; } } else if (!menu_only) { chosen_item = action; } } ui_end_menu(); return chosen_item; }
static int wait_key(int key) { int i; int result = INSTALL_SUCCESS; evt_init(); ui_clear_key_queue(); for(i=0; i < 300; i++) { if(ui_key_pressed(key)) { result = INSTALL_ERROR; } else { usleep(5000); } } evt_exit(); return result; }
int 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_start_menu(headers, items); int selected = 0; int chosen_item = -1; while (chosen_item < 0) { int key = ui_wait_key(); int visible = ui_text_visible(); int action = device_handle_key(key, visible); if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; break; case NO_ACTION: break; } if(action == SELECT_BACK) { chosen_item = action; break; } } else if (!menu_only) { chosen_item = action; } } ui_end_menu(); return chosen_item; }
int get_menu_selection(char** headers, char** items, int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); int item_count = ui_start_menu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; // Some users with dead enter keys need a way to turn on power to select. // Jiggering across the wrapping menu is one "secret" way to enable it. // We can't rely on /cache or /sdcard since they may not be available. int wrap_count = 0; while (chosen_item < 0 && chosen_item != GO_BACK) { struct keyStruct *key; key = ui_wait_key(); int visible = ui_text_visible(); int action; if(key->code == ABS_MT_POSITION_X) action = device_handle_mouse(key, visible); else action = device_handle_key(key->code, visible); int old_selected = selected; if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; if (ui_get_showing_back_button()) { if (chosen_item == item_count) { chosen_item = GO_BACK; } } break; case NO_ACTION: break; case GO_BACK: chosen_item = GO_BACK; break; } } else if (!menu_only) { chosen_item = action; } if (abs(selected - old_selected) > 1) { wrap_count++; if (wrap_count == 3) { wrap_count = 0; if (ui_get_showing_back_button()) { ui_print("Back menu button disabled.\n"); ui_set_showing_back_button(0); } else { ui_print("Back menu button enabled.\n"); ui_set_showing_back_button(1); } } } } ui_end_menu(); ui_clear_key_queue(); return chosen_item; }
int get_menu_selection(char** headers, char** items, int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); int item_count = ui_start_menu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; // NO_ACTION int wrap_count = 0; while (chosen_item < 0 && chosen_item != GO_BACK) { int key = ui_wait_key(); int visible = ui_text_visible(); if (key == -1) { // ui_wait_key() timed out if (ui_text_ever_visible()) { continue; } else { LOGI("timed out waiting for key input; rebooting.\n"); ui_end_menu(); return ITEM_REBOOT; } } else if (key == -2) { // we are returning from ui_cancel_wait_key(): trigger a GO_BACK return GO_BACK; } int action = ui_handle_key(key, visible); int old_selected = selected; selected = ui_get_selected_item(); if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; if (ui_is_showing_back_button()) { if (chosen_item == item_count) { chosen_item = GO_BACK; } } break; case NO_ACTION: break; case GO_BACK: chosen_item = GO_BACK; break; } } else if (!menu_only) { chosen_item = action; } if (abs(selected - old_selected) > 1) { wrap_count++; if (wrap_count == 5) { wrap_count = 0; if (ui_get_rainbow_mode()) { ui_set_rainbow_mode(0); ui_print("Rainbow mode disabled\n"); } else { ui_set_rainbow_mode(1); ui_print("Rainbow mode enabled!\n"); } } } } ui_end_menu(); ui_clear_key_queue(); return chosen_item; }
int get_menu_selection(char** headers, char** items, int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); ui_start_menu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; while (chosen_item < 0) { int key = ui_wait_key(); int visible = ui_text_visible(); int action = device_handle_key(key, visible); if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case KEY_POWER: case SELECT_ITEM: chosen_item = selected; break; case UP_A_LEVEL: if (menu_loc_idx != 0) { chosen_item = menu_loc[menu_loc_idx]; } break; case HOME_MENU: if (menu_loc_idx != 0) { go_home = 1; chosen_item = menu_loc[menu_loc_idx]; } break; case MENU_MENU: if (menu_loc_idx == 0) { return 3; } else { go_home = 1; go_menu = 1; chosen_item = menu_loc[menu_loc_idx]; } break; case NO_ACTION: break; } } else if (!menu_only) { chosen_item = action; } } ui_end_menu(); return chosen_item; }
int get_menu_selection(const char** headers, char** items, int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); int item_count = ui_start_menu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; // NO_ACTION #ifdef NOT_ENOUGH_RAINBOWS int wrap_count = 0; #endif while (chosen_item < 0 && chosen_item != GO_BACK) { int key = ui_wait_key(); int visible = ui_IsTextVisible(); if (key == -1) { // ui_wait_key() timed out, always reboot to main system LOGI("timed out waiting for key input; rebooting.\n"); ui_end_menu(); reboot_main_system(ANDROID_RB_RESTART, 0, 0); sleep(5); LOGE("Failed to reboot system on timed out key input!!\n"); return GO_BACK; } else if (key == -2) { // we are returning from ui_cancel_wait_key(): trigger a GO_BACK return GO_BACK; } else if (key == -3) { // an USB device was plugged in (returning from ui_wait_key()) return REFRESH; } int action = ui_handle_key(key, visible); int old_selected = selected; selected = ui_get_selected_item(); if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; #ifdef PHILZ_TOUCH_RECOVERY case HIGHLIGHT_ON_TOUCH: selected = ui_menu_touch_select(); break; #endif case SELECT_ITEM: chosen_item = selected; if (ui_is_showing_back_button()) { if (chosen_item == item_count) { chosen_item = GO_BACK; } } break; case NO_ACTION: break; case GO_BACK: chosen_item = GO_BACK; break; #ifdef PHILZ_TOUCH_RECOVERY case GESTURE_ACTIONS: handle_gesture_actions(headers, items, initial_selection); break; #endif } } else if (!menu_only) { chosen_item = action; } #ifdef NOT_ENOUGH_RAINBOWS if (abs(selected - old_selected) > 1) { wrap_count++; if (wrap_count == 5) { wrap_count = 0; if (ui_get_rainbow_mode()) { ui_set_rainbow_mode(0); ui_print("Rainbow mode disabled\n"); } else { ui_set_rainbow_mode(1); ui_print("Rainbow mode enabled!\n"); } } } #endif } ui_end_menu(); ui_clear_key_queue(); return chosen_item; }
byte aw_calibdraw(CANVAS * c, int id,int * xpos,int * ypos,int * xtch,int * ytch){ ag_draw(agc(),c,0,0); usleep(500000); int sz = agdp()*10; if (id!=-1){ int x = xpos[id]; int y = ypos[id]; int rx = x-(sz/2); int ry = y-(sz/2); ag_roundgrad( agc(),rx,ry,sz,sz, 0xffff, ag_rgb(200,200,200), sz/2); } if (id!=-1){ char txt[128]; snprintf(txt,127,"Step %i: Tap The Circle To Calibrate",id+1); char * txt2 = "Press Back Key or Other Keys To Cancel"; int tw = ag_txtwidth(txt,0); int tw2 = ag_txtwidth(txt2,0); int tx = (agw()/2) - (tw/2); int tx2= (agw()/2) - (tw2/2); int ty = (agh()/2) + (sz*2); int ty2= (ty +ag_fontheight(0)+agdp()); ag_text(agc(),tw,tx+1,ty+1,txt,0x0000,0); ag_text(agc(),tw,tx,ty,txt,0xffff,0); ag_text(agc(),tw2,tx2+1,ty2+1,txt2,0x0000,0); ag_text(agc(),tw2,tx2,ty2,txt2,0xffff,0); } else{ char * txt = "Tap The Screen to Test Calibrated Data"; char * txt2 = "Press Back or Other Keys To Continue"; int tw = ag_txtwidth(txt,0); int tw2 = ag_txtwidth(txt2,0); int tx = (agw()/2) - (tw/2); int tx2= (agw()/2) - (tw2/2); int ty = (agh()/2) + (sz*2); int ty2= (ty +ag_fontheight(0)+agdp()); ag_text(agc(),tw,tx+1,ty+1,txt,0x0000,0); ag_text(agc(),tw,tx,ty,txt,0xffff,0); ag_text(agc(),tw2,tx2+1,ty2+1,txt2,0x0000,0); ag_text(agc(),tw2,tx2,ty2,txt2,0xffff,0); } CANVAS bg; ag_canvas(&bg,agw(),agh()); ag_draw(&bg,agc(),0,0); ag_sync(); byte res=1; byte ond=1; byte onp=0; ui_clear_key_queue(); while (ond){ ATEV atev; ui_clear_key_queue(); int action=atouch_wait_ex(&atev,1); switch (action){ case ATEV_MOUSEDN:{ onp=1; if (id==-1){ ag_draw(agc(),&bg,0,0); int vz = agdp()*40; int vx = atev.x-(vz/2); int vy = atev.y-(vz/2); ag_roundgrad(agc(),vx,vy,vz,vz,0xffff,ag_rgb(180,180,180),(vz/2)); ag_sync(); } } break; case ATEV_MOUSEMV:{ if (onp){ if (id!=-1){ xtch[id]=atev.x; ytch[id]=atev.y; } else{ ag_draw(agc(),&bg,0,0); int vz = agdp()*40; int vx = atev.x-(vz/2); int vy = atev.y-(vz/2); ag_roundgrad(agc(),vx,vy,vz,vz,0xffff,ag_rgb(180,180,180),(vz/2)); ag_sync(); } } } break; case ATEV_MOUSEUP:{ if (id!=-1){ if (onp){ if ((xtch[id]>0)&&(ytch[id]>0)){ ond=0; } onp=0; } } } break; case ATEV_SELECT: case ATEV_BACK: case ATEV_MENU:{ if (atev.d==0){ ond=0; res=0; } } break; } } ag_ccanvas(&bg); return res; }
int atouch_wait_ex(ATEV *atev, byte calibratingtouch){ atev->x = -1; atev->y = -1; // if (prev_was_key) ui_clear_key_queue(); while (1){ int key = ui_wait_key(); //-- Custom Message if (key==atouch_message_code){ atev->msg = atouch_message_value; atev->d = 0; atev->x = 0; atev->y = 0; atev->k = 0; ui_clear_key_queue(); atouch_message_value = 0; return ATEV_MESSAGE; } atev->d = ui_key_pressed(key); atev->k = key; if (key==evtouch_code){ if ((evtouch_x>0)&&(evtouch_y>0)){ //-- GENERIC TOUCH SCREEN INPUT EVENT if (((evtouch_x<=agw())&&(evtouch_y<=agh()))||(calibratingtouch)){ atev->x = evtouch_x; atev->y = evtouch_y; evtouch_locked=0; switch(evtouch_state){ case 1: return ATEV_MOUSEDN; break; case 2: return ATEV_MOUSEMV; break; default: return ATEV_MOUSEUP; break; } } //-- CAPIATIVE KEY INPUT EVENT else if(evtouch_y>(agh()+(agdp()*10))){ int capiative_btnsz = agw()/4; if (evtouch_state==0){ atev->d = 0; if (evtouch_x<capiative_btnsz){ vibrate(30); atev->k = KEY_HOME; evtouch_locked=0; return ATEV_SELECT; } else if (evtouch_x<(capiative_btnsz*2)){ vibrate(30); atev->k = KEY_MENU; evtouch_locked=0; return ATEV_MENU; } else if (evtouch_x<(capiative_btnsz*3)){ vibrate(30); atev->k = KEY_BACK; evtouch_locked=0; return ATEV_BACK; } else if (evtouch_x<(capiative_btnsz*4)){ vibrate(30); atev->k = KEY_SEARCH; evtouch_locked=0; return ATEV_MENU; } } // home,menu,back,search } } evtouch_locked=0; } else if ((key!=0)&&(key==acfg()->ckey_up)) return ATEV_UP; else if ((key!=0)&&(key==acfg()->ckey_down)) return ATEV_DOWN; else if ((key!=0)&&(key==acfg()->ckey_select)) return ATEV_SELECT; else if ((key!=0)&&(key==acfg()->ckey_back)) return ATEV_BACK; else if ((key!=0)&&(key==acfg()->ckey_menu)) return ATEV_MENU; else{ /* DEFINED KEYS */ switch (key){ /* RIGHT */ case KEY_RIGHT: return ATEV_RIGHT; break; /* LEFT */ case KEY_LEFT: return ATEV_LEFT; break; /* DOWN */ case KEY_DOWN: case KEY_CAPSLOCK: case KEY_VOLUMEDOWN: return ATEV_DOWN; break; /* UP */ case KEY_UP: case KEY_LEFTSHIFT: case KEY_VOLUMEUP: return ATEV_UP; break; /* SELECT */ case KEY_LEFTBRACE: case KEY_POWER: case KEY_HOME: case BTN_MOUSE: case KEY_ENTER: case KEY_CENTER: case KEY_CAMERA: case KEY_F21: case KEY_SEND: return ATEV_SELECT; break; /* SHOW MENU */ case KEY_SEARCH: case 229: case KEY_MENU: return ATEV_MENU; break; /* BACK */ case KEY_END: case KEY_BACKSPACE: case KEY_BACK: return ATEV_BACK; break; } } } return 0; }
static int get_menu_selection(char** headers, char** items, unsigned char* selectability, int title_length, int start_sel, int menu_only) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); //get no items int num_items = 0; while (items[num_items] != NULL) num_items++; if (start_sel >= num_items) start_sel = num_items - 1; if (start_sel < 0) start_sel = 0; ui_start_menu(headers, items, title_length, start_sel); int selected = start_sel; int chosen_item = -1; while (chosen_item < 0) { int key = ui_wait_key(); int visible = ui_text_visible(); int action = device_handle_key(key, visible); if (action < 0) { switch (action) { case HIGHLIGHT_UP: while(1) { --selected; //wrap if (selected < 0) selected = num_items - 1; if (selectability[selected]) break; } selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: while(1) { ++selected; //wrap if (selected >= num_items) selected = 0; if (selectability[selected]) break; } selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; break; case NO_ACTION: break; } } else if (!menu_only) chosen_item = action; } //check first if to hide menu (don't do on menu changes or tags), //because the flicker is annoying //that is implemented elsewhere //ui_end_menu(); return chosen_item; }
int get_menu_selection(char** headers, char** items, int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); int item_count = ui_start_menu(headers, items, initial_selection); int selected = initial_selection; int chosen_item = -1; // Some users with dead enter keys need a way to turn on power to select. // Jiggering across the wrapping menu is one "secret" way to enable it. // We can't rely on /cache or /sdcard since they may not be available. int wrap_count = 0; while (chosen_item < 0 && chosen_item != GO_BACK) { int key = ui_wait_key(); int visible = ui_text_visible(); if (key == -1) { // ui_wait_key() timed out if (ui_text_ever_visible()) { continue; } else { LOGI("timed out waiting for key input; rebooting.\n"); ui_end_menu(); return ITEM_REBOOT; } } int action = ui_handle_key(key, visible); int old_selected = selected; selected = ui_get_selected_item(); if (action < 0) { switch (action) { case HIGHLIGHT_UP: --selected; selected = ui_menu_select(selected); break; case HIGHLIGHT_DOWN: ++selected; selected = ui_menu_select(selected); break; case SELECT_ITEM: chosen_item = selected; if (ui_is_showing_back_button()) { if (chosen_item == item_count) { chosen_item = GO_BACK; } } break; case NO_ACTION: break; case GO_BACK: chosen_item = GO_BACK; break; } } else if (!menu_only) { chosen_item = action; } } ui_end_menu(); ui_clear_key_queue(); return chosen_item; }
//-- Dispatch Messages dword aw_dispatch(AWINDOWP win){ dword msg; int i; ui_clear_key_queue(); while(1){ //-- Wait For Event ATEV atev; int action =atouch_wait(&atev); //-- Reset Message Value msg = aw_msg(0,0,0,0); //-- Check an Action Value switch (action){ case ATEV_MESSAGE:{ msg = atev.msg; } break; case ATEV_BACK:{ if (!atev.d){ msg = aw_msg(5,0,0,0); } } break; case ATEV_DOWN: case ATEV_RIGHT: if (!atev.d){ if (win->focusIndex!=-1){ ACONTROLP ctl = (ACONTROLP) win->controls[win->focusIndex]; if (ctl->oninput!=NULL){ msg = ctl->oninput((void*)ctl,action,&atev); } if (aw_gl(msg)==0){ for (i=win->focusIndex+1;i<win->controln;i++){ ACONTROLP fctl = (ACONTROLP) win->controls[i]; if (fctl->onfocus!=NULL){ if (fctl->onfocus(fctl)){ win->focusIndex = i; ctl->onblur(ctl); aw_draw(win); break; } } } } } } break; case ATEV_UP: case ATEV_LEFT: if (!atev.d){ if (win->focusIndex!=-1){ ACONTROLP ctl = (ACONTROLP) win->controls[win->focusIndex]; if (ctl->oninput!=NULL){ msg = ctl->oninput((void*)ctl,action,&atev); } if (aw_gl(msg)==0){ for (i=win->focusIndex-1;i>=0;i--){ ACONTROLP fctl = (ACONTROLP) win->controls[i]; if (fctl->onfocus!=NULL){ if (fctl->onfocus(fctl)){ win->focusIndex = i; ctl->onblur(ctl); aw_draw(win); break; } } } } } } break; case ATEV_MENU: case ATEV_SEARCH: case ATEV_HOME: case ATEV_SELECT:{ if (win->focusIndex!=-1){ ACONTROLP ctl = (ACONTROLP) win->controls[win->focusIndex]; if (ctl->oninput!=NULL){ msg = ctl->oninput((void*)ctl,action,&atev); } } } break; case ATEV_MOUSEDN: { if (win->controln>0){ int i; for (i=win->controln-1;i>=0;i--){ ACONTROLP ctl = (ACONTROLP) win->controls[i]; if (aw_touchoncontrol(ctl,atev.x,atev.y)){ if (ctl->oninput!=NULL){ msg = ctl->oninput((void*)ctl,action,&atev); win->touchIndex = i; break; } } } } } break; case ATEV_MOUSEUP:{ if (win->touchIndex!=-1){ ACONTROLP ctl = (ACONTROLP) win->controls[win->touchIndex]; if (ctl->oninput!=NULL) msg = ctl->oninput((void*)ctl,action,&atev); win->touchIndex = -1; } } break; case ATEV_MOUSEMV:{ if (win->touchIndex!=-1){ ACONTROLP ctl = (ACONTROLP) win->controls[win->touchIndex]; if (ctl->oninput!=NULL) msg = ctl->oninput((void*)ctl,action,&atev); } } break; } if (aw_gd(msg)==1) aw_draw(win); if (aw_gm(msg)!=0) return msg; } return msg; }