1 package org.coolreader.crengine; 2 3 import java.util.ArrayList; 4 5 import org.coolreader.R; 6 7 public class ReaderAction { 8 final public String id; 9 final public int nameId; 10 public int iconId; 11 final public ReaderCommand cmd; 12 final public int param; 13 final public int menuItemId; 14 private boolean canRepeat = false; 15 private boolean mayAssignOnKey = true; 16 private boolean mayAssignOnTap = true; 17 private boolean activateWithLongMenuKey = false; setActivateWithLongMenuKey()18 private ReaderAction setActivateWithLongMenuKey() { this.activateWithLongMenuKey = true; return this; } setIconId(int iconId)19 public ReaderAction setIconId(int iconId) { this.iconId = iconId; return this; } setCanRepeat()20 private ReaderAction setCanRepeat() { canRepeat = true; return this; } 21 //private ReaderAction dontAssignOnKey() { mayAssignOnKey=false; return this; } dontAssignOnTap()22 private ReaderAction dontAssignOnTap() { mayAssignOnTap = false; return this; } canRepeat()23 public boolean canRepeat() { return canRepeat; } mayAssignOnKey()24 public boolean mayAssignOnKey() { return mayAssignOnKey; } mayAssignOnTap()25 public boolean mayAssignOnTap() { return mayAssignOnTap; } activateWithLongMenuKey()26 public boolean activateWithLongMenuKey() { return activateWithLongMenuKey; } 27 ReaderAction(String id, int nameId, ReaderCommand cmd, int param)28 public ReaderAction(String id, int nameId, ReaderCommand cmd, int param) { 29 super(); 30 this.id = id; 31 this.nameId = nameId; 32 this.cmd = cmd; 33 this.param = param; 34 this.menuItemId = 0; 35 this.iconId = 0; 36 } 37 ReaderAction(String id, int nameId, ReaderCommand cmd, int param, int menuItemId)38 public ReaderAction(String id, int nameId, ReaderCommand cmd, int param, int menuItemId) { 39 super(); 40 this.id = id; 41 this.nameId = nameId; 42 this.cmd = cmd; 43 this.param = param; 44 this.menuItemId = menuItemId; 45 this.iconId = 0; 46 } 47 toString()48 public String toString() { 49 return id; 50 } 51 52 public final static ReaderAction NONE = new ReaderAction("NONE", R.string.action_none, ReaderCommand.DCMD_NONE, 0 ); 53 public final static ReaderAction REPEAT = new ReaderAction("REPEAT", R.string.action_repeat, ReaderCommand.DCMD_REPEAT, 0 ); 54 public final static ReaderAction PAGE_DOWN = new ReaderAction("PAGE_DOWN", R.string.action_pagedown, ReaderCommand.DCMD_PAGEDOWN, 1 ).setCanRepeat(); 55 public final static ReaderAction PAGE_DOWN_10 = new ReaderAction("PAGE_DOWN_10", R.string.action_pagedown_10, ReaderCommand.DCMD_PAGEDOWN, 10 ).setCanRepeat(); 56 public final static ReaderAction PAGE_UP = new ReaderAction("PAGE_UP", R.string.action_pageup, ReaderCommand.DCMD_PAGEUP, 1 ).setCanRepeat(); 57 public final static ReaderAction PAGE_UP_10 = new ReaderAction("PAGE_UP_10", R.string.action_pageup_10, ReaderCommand.DCMD_PAGEUP, 10 ).setCanRepeat(); 58 public final static ReaderAction ZOOM_IN = new ReaderAction("ZOOM_IN", R.string.mi_font_size_increase, ReaderCommand.DCMD_ZOOM_IN, 1); //, R.id.cr3_mi_font_size_increase 59 public final static ReaderAction ZOOM_OUT = new ReaderAction("ZOOM_OUT", R.string.mi_font_size_decrease, ReaderCommand.DCMD_ZOOM_OUT, 1); //, R.id.cr3_mi_font_size_decrease 60 public final static ReaderAction DOCUMENT_STYLES = new ReaderAction("DOCUMENT_STYLES", R.string.action_toggle_document_styles, ReaderCommand.DCMD_TOGGLE_DOCUMENT_STYLES, 0, R.id.cr3_mi_toggle_document_styles ); 61 public final static ReaderAction TEXT_AUTOFORMAT = new ReaderAction("TEXT_AUTOFORMAT", R.string.action_toggle_text_autoformat, ReaderCommand.DCMD_TOGGLE_TEXT_AUTOFORMAT, 0, R.id.cr3_mi_toggle_text_autoformat ); 62 public final static ReaderAction BOOKMARKS = new ReaderAction("BOOKMARKS", R.string.action_bookmarks, ReaderCommand.DCMD_BOOKMARKS, 0, R.id.cr3_mi_bookmarks ).setIconId(R.drawable.cr3_button_bookmarks); 63 public final static ReaderAction ABOUT = new ReaderAction("ABOUT", R.string.dlg_about, ReaderCommand.DCMD_ABOUT, 0, R.id.cr3_mi_about ).setIconId(R.drawable.cr3_logo_button); 64 public final static ReaderAction USER_MANUAL = new ReaderAction("USER_MANUAL", R.string.mi_goto_manual, ReaderCommand.DCMD_USER_MANUAL, 0, R.id.cr3_mi_user_manual ); 65 public final static ReaderAction BOOK_INFO = new ReaderAction("BOOK_INFO", R.string.dlg_book_info, ReaderCommand.DCMD_BOOK_INFO, 0, R.id.cr3_mi_book_info ); 66 public final static ReaderAction TOC = new ReaderAction("TOC", R.string.action_toc, ReaderCommand.DCMD_TOC_DIALOG, 0, R.id.cr3_go_toc ).setIconId(R.drawable.cr3_viewer_toc); 67 public final static ReaderAction SEARCH = new ReaderAction("SEARCH", R.string.action_search, ReaderCommand.DCMD_SEARCH, 0, R.id.cr3_mi_search ).setIconId(R.drawable.cr3_viewer_find); 68 public final static ReaderAction GO_PAGE = new ReaderAction("GO_PAGE", R.string.action_go_page, ReaderCommand.DCMD_GO_PAGE_DIALOG, 0, R.id.cr3_mi_go_page ).setIconId(R.drawable.cr3_button_go_page); 69 public final static ReaderAction GO_PERCENT = new ReaderAction("GO_PERCENT", R.string.action_go_percent, ReaderCommand.DCMD_GO_PERCENT_DIALOG, 0, R.id.cr3_mi_go_percent ).setIconId(R.drawable.cr3_button_go_percent); 70 public final static ReaderAction FIRST_PAGE = new ReaderAction("FIRST_PAGE", R.string.action_go_first_page, ReaderCommand.DCMD_BEGIN, 0 ); 71 public final static ReaderAction LAST_PAGE = new ReaderAction("LAST_PAGE", R.string.action_go_last_page, ReaderCommand.DCMD_END, 0 ); 72 public final static ReaderAction OPTIONS = new ReaderAction("OPTIONS", R.string.action_options, ReaderCommand.DCMD_OPTIONS_DIALOG, 0, R.id.cr3_mi_options ).setIconId(R.drawable.cr3_viewer_settings); 73 public final static ReaderAction READER_MENU = new ReaderAction("READER_MENU", R.string.action_reader_menu, ReaderCommand.DCMD_READER_MENU, 0 ); 74 public final static ReaderAction TOGGLE_DAY_NIGHT = new ReaderAction("TOGGLE_DAY_NIGHT", R.string.action_toggle_day_night, ReaderCommand.DCMD_TOGGLE_DAY_NIGHT_MODE, 0, R.id.cr3_mi_toggle_day_night ).setIconId(R.drawable.cr3_option_night); 75 public final static ReaderAction RECENT_BOOKS = new ReaderAction("RECENT_BOOKS", R.string.action_recent_books_list, ReaderCommand.DCMD_RECENT_BOOKS_LIST, R.id.book_recent_books ).setIconId(R.drawable.cr3_browser_folder_recent); 76 public final static ReaderAction OPDS_CATALOGS = new ReaderAction("OPDS_CATALOGS", R.string.mi_book_opds_root, ReaderCommand.DCMD_OPDS_CATALOGS, 0).setIconId(R.drawable.cr3_browser_folder_opds); 77 public final static ReaderAction FILE_BROWSER_ROOT = new ReaderAction("FILE_BROWSER_ROOT", R.string.mi_book_root, ReaderCommand.DCMD_FILE_BROWSER_ROOT, 0).setIconId(R.drawable.cr3_browser_folder_root); 78 public final static ReaderAction FILE_BROWSER = new ReaderAction("FILE_BROWSER", R.string.action_file_browser, ReaderCommand.DCMD_FILE_BROWSER, 0, R.id.cr3_mi_open_file ).setIconId(R.drawable.cr3_browser_folder); 79 public final static ReaderAction FILE_BROWSER_UP = new ReaderAction("FILE_BROWSER_UP", R.string.action_go_back, ReaderCommand.DCMD_FILE_BROWSER_UP, 0).setIconId(R.drawable.cr3_button_prev); 80 public final static ReaderAction CURRENT_BOOK_DIRECTORY = new ReaderAction("DCMD_CURRENT_BOOK_DIRECTORY", R.string.mi_book_recent_goto, ReaderCommand.DCMD_CURRENT_BOOK_DIRECTORY, 0).setIconId(R.drawable.cr3_browser_folder_current_book); 81 public final static ReaderAction CURRENT_BOOK = new ReaderAction("DCMD_CURRENT_BOOK", R.string.mi_book_back_to_reading, ReaderCommand.DCMD_CURRENT_BOOK, 0).setIconId(R.drawable.cr3_button_book_open); 82 public final static ReaderAction FILE_BROWSER_SORT_ORDER = new ReaderAction("FILE_BROWSER_SORT_ORDER", R.string.mi_book_sort_order, ReaderCommand.DCMD_FILE_BROWSER_SORT_ORDER, 0); 83 public final static ReaderAction TOGGLE_DICT_ONCE = new ReaderAction("TOGGLE_DICT_ONCE", R.string.toggle_dict_once, ReaderCommand.DCMD_TOGGLE_DICT_ONCE, 0); 84 public final static ReaderAction TOGGLE_DICT = new ReaderAction("TOGGLE_DICT", R.string.toggle_dict, ReaderCommand.DCMD_TOGGLE_DICT, 0); 85 86 public final static ReaderAction FONT_PREVIOUS = new ReaderAction("FONT_PREVIOUS", R.string.mi_font_previous, ReaderCommand.DCMD_FONT_PREVIOUS, 0); //, R.id.cr3_mi_font_previous 87 public final static ReaderAction FONT_NEXT = new ReaderAction("FONT_NEXT", R.string.mi_font_next, ReaderCommand.DCMD_FONT_NEXT, 0); //, R.id.cr3_mi_font_next 88 public final static ReaderAction TOGGLE_TOUCH_SCREEN_LOCK = new ReaderAction("TOGGLE_TOUCH_SCREEN_LOCK", R.string.action_touch_screen_toggle_lock, ReaderCommand.DCMD_TOGGLE_TOUCH_SCREEN_LOCK, 0 ).dontAssignOnTap(); 89 public final static ReaderAction TOGGLE_ORIENTATION = new ReaderAction("TOGGLE_ORIENTATION", R.string.action_toggle_screen_orientation, ReaderCommand.DCMD_TOGGLE_ORIENTATION, 0 ); 90 public final static ReaderAction TOGGLE_FULLSCREEN = new ReaderAction("TOGGLE_FULLSCREEN", R.string.action_toggle_fullscreen, ReaderCommand.DCMD_TOGGLE_FULLSCREEN, 0 ); 91 public final static ReaderAction TOGGLE_SELECTION_MODE = new ReaderAction("TOGGLE_SELECTION_MODE", R.string.action_toggle_selection_mode, ReaderCommand.DCMD_TOGGLE_SELECTION_MODE, 0, R.id.cr3_mi_select_text).setIconId(R.drawable.cr3_option_touch); 92 public final static ReaderAction HOME_SCREEN = new ReaderAction("HOME_SCREEN", R.string.action_exit_home_screen, ReaderCommand.DCMD_SHOW_HOME_SCREEN, 0 ); 93 public final static ReaderAction GO_BACK = new ReaderAction("GO_BACK", R.string.action_go_back, ReaderCommand.DCMD_LINK_BACK, 0, R.id.cr3_go_back ).setIconId(R.drawable.cr3_button_prev); 94 public final static ReaderAction GO_FORWARD = new ReaderAction("GO_FORWARD", R.string.action_go_forward, ReaderCommand.DCMD_LINK_FORWARD, 0, R.id.cr3_go_forward).setIconId(R.drawable.cr3_button_next); 95 public final static ReaderAction TTS_PLAY = new ReaderAction("TTS_PLAY", R.string.mi_tts_play, ReaderCommand.DCMD_TTS_PLAY, 0, R.id.cr3_mi_tts_play ).setIconId(R.drawable.cr3_button_tts); //.setActivateWithLongMenuKey() 96 public final static ReaderAction TOGGLE_TITLEBAR = new ReaderAction("TOGGLE_TITLEBAR", R.string.action_toggle_titlebar, ReaderCommand.DCMD_TOGGLE_TITLEBAR, 0 ); 97 public final static ReaderAction SHOW_POSITION_INFO_POPUP = new ReaderAction("SHOW_POSITION_INFO_POPUP", R.string.action_show_position_info, ReaderCommand.DCMD_SHOW_POSITION_INFO_POPUP, 0 ); 98 public final static ReaderAction SHOW_DICTIONARY = new ReaderAction("SHOW_DICTIONARY", R.string.action_show_dictionary, ReaderCommand.DCMD_SHOW_DICTIONARY, 0); 99 public final static ReaderAction OPEN_PREVIOUS_BOOK = new ReaderAction("OPEN_PREVIOUS_BOOK", R.string.action_open_last_book, ReaderCommand.DCMD_OPEN_PREVIOUS_BOOK, 0, R.id.cr3_go_previous_book).setIconId(R.drawable.cr3_btn_books_swap); 100 public final static ReaderAction TOGGLE_AUTOSCROLL = new ReaderAction("TOGGLE_AUTOSCROLL", R.string.action_toggle_autoscroll, ReaderCommand.DCMD_TOGGLE_AUTOSCROLL, 0, R.id.cr3_mi_toggle_autoscroll).setIconId(R.drawable.cr3_button_scroll_go); 101 public final static ReaderAction AUTOSCROLL_SPEED_INCREASE = new ReaderAction("AUTOSCROLL_SPEED_INCREASE", R.string.action_autoscroll_speed_increase, ReaderCommand.DCMD_AUTOSCROLL_SPEED_INCREASE, 0); 102 public final static ReaderAction AUTOSCROLL_SPEED_DECREASE = new ReaderAction("AUTOSCROLL_SPEED_DECREASE", R.string.action_autoscroll_speed_decrease, ReaderCommand.DCMD_AUTOSCROLL_SPEED_DECREASE, 0); 103 public final static ReaderAction START_SELECTION = new ReaderAction("START_SELECTION", R.string.action_toggle_selection_mode, ReaderCommand.DCMD_START_SELECTION, 0); 104 public final static ReaderAction SWITCH_PROFILE = new ReaderAction("SWITCH_PROFILE", R.string.action_switch_settings_profile, ReaderCommand.DCMD_SWITCH_PROFILE, 0); 105 public final static ReaderAction SCAN_DIRECTORY_RECURSIVE = new ReaderAction("SCAN_DIRECTORY_RECURSIVE", R.string.mi_book_scan_recursive, ReaderCommand.DCMD_SCAN_DIRECTORY_RECURSIVE, 0); 106 public final static ReaderAction NEXT_CHAPTER = new ReaderAction("NEXT_CHAPTER", R.string.action_chapter_next, ReaderCommand.DCMD_MOVE_BY_CHAPTER, 1); 107 public final static ReaderAction PREV_CHAPTER = new ReaderAction("PREV_CHAPTER", R.string.action_chapter_prev, ReaderCommand.DCMD_MOVE_BY_CHAPTER, -1); 108 public final static ReaderAction SAVE_LOGCAT = new ReaderAction("SAVE_LOGCAT", R.string.action_logcat, ReaderCommand.DCMD_SAVE_LOGCAT, 0).setIconId(R.drawable.cr3_button_log); 109 public final static ReaderAction EXIT = new ReaderAction("EXIT", R.string.action_exit, ReaderCommand.DCMD_EXIT, 0, R.id.cr3_mi_exit ).setIconId(R.drawable.cr3_viewer_exit); 110 111 public final static ReaderAction BACKLIGHT_SET_DEFAULT = new ReaderAction("BACKLIGHT_SET_DEFAULT", R.string.action_backlight_set_default, ReaderCommand.DCMD_BACKLIGHT_SET_DEFAULT, -1); 112 public final static ReaderAction SHOW_SYSTEM_BACKLIGHT_DIALOG = new ReaderAction("SHOW_SYSTEM_BACKLIGHT_DIALOG", R.string.action_show_onyx_backlight_system_dialog, ReaderCommand.DCMD_SHOW_SYSTEM_BACKLIGHT_DIALOG, -1); 113 114 public final static ReaderAction GDRIVE_SYNCTO = new ReaderAction("GDRIVE_SYNCTO", R.string.googledrive_sync_to, ReaderCommand.DCMD_GOOGLEDRIVE_SYNC, 0).setIconId(R.drawable.google_drive); 115 public final static ReaderAction GDRIVE_SYNCFROM = new ReaderAction("GDRIVE_SYNCFROM", R.string.googledrive_sync_from, ReaderCommand.DCMD_GOOGLEDRIVE_SYNC, 1).setIconId(R.drawable.google_drive); 116 117 public final static ReaderAction[] AVAILABLE_ACTIONS; 118 isNone()119 public boolean isNone() { 120 return cmd == NONE.cmd; 121 } 122 isRepeat()123 public boolean isRepeat() { 124 return cmd == REPEAT.cmd; 125 } 126 findById( String id )127 public static ReaderAction findById( String id ) { 128 if ( id==null ) 129 return NONE; 130 for ( ReaderAction a : AVAILABLE_ACTIONS ) { 131 if ( id.equals(a.id) ) 132 return a; 133 } 134 if ( id.equals(REPEAT.id) ) 135 return REPEAT; 136 return NONE; 137 } findByMenuId( int id )138 public static ReaderAction findByMenuId( int id ) { 139 if ( id==0 ) 140 return NONE; 141 for ( ReaderAction a : AVAILABLE_ACTIONS ) { 142 if ( id == a.menuItemId ) 143 return a; 144 } 145 return NONE; 146 } 147 public final static String NORMAL_PROP = "."; 148 public final static String LONG_PROP = ".long."; 149 public final static String DOUBLECLICK_PROP = ".dbl."; 150 151 public final static int NORMAL = 0; 152 public final static int LONG = 1; 153 public final static int DOUBLE = 2; 154 public final static String[] TYPE_PROP_SUBPATH = new String[] {NORMAL_PROP, LONG_PROP, DOUBLECLICK_PROP}; 155 getTypeString( int type )156 public static String getTypeString( int type ) { 157 return TYPE_PROP_SUBPATH[type]; 158 } 159 getTapZoneProp( int tapZoneNumber, int type )160 public static String getTapZoneProp( int tapZoneNumber, int type ) { 161 return ReaderView.PROP_APP_TAP_ZONE_ACTIONS_TAP + getTypeString(type) + tapZoneNumber; 162 } getKeyProp( int keyCode, int type )163 public static String getKeyProp( int keyCode, int type ) { 164 return ReaderView.PROP_APP_KEY_ACTIONS_PRESS + getTypeString(type) + keyCode; 165 } findForTap( int tapZoneNumber, Properties settings )166 public static ReaderAction findForTap( int tapZoneNumber, Properties settings ) { 167 String id = settings.getProperty( getTapZoneProp( tapZoneNumber, NORMAL ) ); 168 return findById(id); 169 } findForLongTap( int tapZoneNumber, Properties settings )170 public static ReaderAction findForLongTap( int tapZoneNumber, Properties settings ) { 171 String id = settings.getProperty( getTapZoneProp( tapZoneNumber, LONG ) ); 172 return findById(id); 173 } findForDoubleTap( int tapZoneNumber, Properties settings )174 public static ReaderAction findForDoubleTap( int tapZoneNumber, Properties settings ) { 175 String id = settings.getProperty( getTapZoneProp( tapZoneNumber, DOUBLE ) ); 176 return findById(id); 177 } findForKey( int keyCode, Properties settings )178 public static ReaderAction findForKey( int keyCode, Properties settings ) { 179 String id = settings.getProperty( getKeyProp( keyCode, NORMAL ) ); 180 return findById(id); 181 } findForLongKey( int keyCode, Properties settings )182 public static ReaderAction findForLongKey( int keyCode, Properties settings ) { 183 String id = settings.getProperty( getKeyProp( keyCode, LONG ) ); 184 return findById(id); 185 } findForDoubleKey( int keyCode, Properties settings )186 public static ReaderAction findForDoubleKey( int keyCode, Properties settings ) { 187 String id = settings.getProperty( getKeyProp( keyCode, DOUBLE ) ); 188 return findById(id); 189 } 190 createList(ReaderAction .... actions)191 public static ArrayList<ReaderAction> createList(ReaderAction ... actions) { 192 ArrayList<ReaderAction> list = new ArrayList<ReaderAction>(actions.length); 193 for (ReaderAction item : actions) 194 list.add(item); 195 return list; 196 } 197 198 static { 199 ReaderAction[] BASE_ACTIONS = new ReaderAction[]{ 200 NONE, 201 PAGE_DOWN, 202 PAGE_UP, 203 PAGE_DOWN_10, 204 PAGE_UP_10, 205 FIRST_PAGE, 206 LAST_PAGE, 207 NEXT_CHAPTER, 208 PREV_CHAPTER, 209 TOC, 210 GO_PAGE, 211 GO_PERCENT, 212 BOOKMARKS, 213 SEARCH, 214 OPTIONS, 215 EXIT, 216 TOGGLE_DAY_NIGHT, 217 RECENT_BOOKS, 218 FILE_BROWSER, 219 FILE_BROWSER_ROOT, 220 CURRENT_BOOK_DIRECTORY, 221 READER_MENU, 222 TOGGLE_TOUCH_SCREEN_LOCK, 223 TOGGLE_SELECTION_MODE, 224 TOGGLE_ORIENTATION, 225 TOGGLE_FULLSCREEN, 226 GO_BACK, 227 GO_FORWARD, 228 HOME_SCREEN, 229 ZOOM_IN, 230 ZOOM_OUT, 231 FONT_PREVIOUS, 232 FONT_NEXT, 233 DOCUMENT_STYLES, 234 ABOUT, 235 BOOK_INFO, 236 TTS_PLAY, 237 TOGGLE_TITLEBAR, 238 SHOW_POSITION_INFO_POPUP, 239 SHOW_DICTIONARY, 240 OPEN_PREVIOUS_BOOK, 241 TOGGLE_AUTOSCROLL, 242 SWITCH_PROFILE, 243 TEXT_AUTOFORMAT, 244 USER_MANUAL, 245 // AUTOSCROLL_SPEED_INCREASE, 246 // AUTOSCROLL_SPEED_DECREASE, 247 TOGGLE_DICT_ONCE, 248 TOGGLE_DICT, 249 BACKLIGHT_SET_DEFAULT, 250 GDRIVE_SYNCTO, 251 GDRIVE_SYNCFROM, 252 SAVE_LOGCAT 253 }; 254 if (DeviceInfo.EINK_HAVE_FRONTLIGHT) { 255 // TODO: and may be other eink devices with frontlight... 256 if (DeviceInfo.EINK_ONYX && DeviceInfo.ONYX_HAVE_BRIGHTNESS_SYSTEM_DIALOG) { 257 int count = BASE_ACTIONS.length; 258 ReaderAction[] new_array = new ReaderAction[count + 1]; System.arraycopy(BASE_ACTIONS, 0, new_array, 0, count)259 System.arraycopy(BASE_ACTIONS, 0, new_array, 0, count); 260 new_array[count] = SHOW_SYSTEM_BACKLIGHT_DIALOG; 261 BASE_ACTIONS = new_array; 262 } 263 } 264 AVAILABLE_ACTIONS = BASE_ACTIONS; 265 } 266 } 267