|
| 1 | +package com.d4rk.androidtutorials.java.ui.screens.android.lessons.basics.shortcuts; |
| 2 | + |
| 3 | +import android.util.SparseArray; |
| 4 | + |
| 5 | +import androidx.annotation.LayoutRes; |
| 6 | + |
| 7 | +import com.d4rk.androidtutorials.java.R; |
| 8 | + |
| 9 | +import java.util.Collections; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +public final class ShortcutsRepository { |
| 13 | + |
| 14 | + private ShortcutsRepository() { /* Utility class. */ } |
| 15 | + |
| 16 | + // --- Public API ---------------------------------------------------------- |
| 17 | + public static List<ShortcutItem> getShortcuts(@LayoutRes int layoutResId) { |
| 18 | + List<ShortcutItem> list = SHORTCUTS_BY_LAYOUT.get(layoutResId); |
| 19 | + return list != null ? list : Collections.emptyList(); |
| 20 | + } |
| 21 | + |
| 22 | + // --- Implementation details --------------------------------------------- |
| 23 | + private static final SparseArray<List<ShortcutItem>> SHORTCUTS_BY_LAYOUT = new SparseArray<>(); |
| 24 | + |
| 25 | + private static final List<ShortcutItem> GENERAL_SHORTCUTS = List.of( |
| 26 | + new ShortcutItem("Ctrl + S", R.string.save_all), |
| 27 | + new ShortcutItem("Ctrl + ALT + Y", R.string.synchronize), |
| 28 | + new ShortcutItem("Ctrl + Shift + F12", R.string.maximize), |
| 29 | + new ShortcutItem("Ctrl + Shift + F", R.string.add_to_favorites), |
| 30 | + new ShortcutItem("Ctrl + Shift + I", R.string.file_inspect), |
| 31 | + new ShortcutItem("Ctrl + `", R.string.quick_switch_theme), |
| 32 | + new ShortcutItem("Ctrl + Alt + S", R.string.open_settings), |
| 33 | + new ShortcutItem("Ctrl + Alt + Shift + S", R.string.open_project), |
| 34 | + new ShortcutItem("Ctrl + Tab", R.string.switch_tabs) |
| 35 | + ); |
| 36 | + |
| 37 | + private static final List<ShortcutItem> BUILD_SHORTCUTS = List.of( |
| 38 | + new ShortcutItem("Ctrl + F9", R.string.build), |
| 39 | + new ShortcutItem("Shift + F10", R.string.build_and_run), |
| 40 | + new ShortcutItem("Ctrl + F10", R.string.apply_changes) |
| 41 | + ); |
| 42 | + |
| 43 | + private static final List<ShortcutItem> DEBUGGING_SHORTCUTS = List.of( |
| 44 | + new ShortcutItem("Shift + F9", R.string.debug), |
| 45 | + new ShortcutItem("F8", R.string.step_over), |
| 46 | + new ShortcutItem("F7", R.string.step_into), |
| 47 | + new ShortcutItem("Shift + F7", R.string.smart_step_into), |
| 48 | + new ShortcutItem("Shift + F8", R.string.step_out), |
| 49 | + new ShortcutItem("Alt + F9", R.string.run_to_cursor), |
| 50 | + new ShortcutItem("Alt + F8", R.string.evaluate_expression), |
| 51 | + new ShortcutItem("F9", R.string.resume_program), |
| 52 | + new ShortcutItem("Ctrl + F8", R.string.toggle_breakpoint), |
| 53 | + new ShortcutItem("Ctrl + Shift + F8", R.string.view_breakpoints) |
| 54 | + ); |
| 55 | + |
| 56 | + private static final List<ShortcutItem> CODE_SHORTCUTS = List.of( |
| 57 | + new ShortcutItem("Alt + Insert", R.string.generate_code), |
| 58 | + new ShortcutItem("Ctrl + O", R.string.override_methods), |
| 59 | + new ShortcutItem("Ctrl + I", R.string.implement_methods), |
| 60 | + new ShortcutItem("Ctrl + Alt + T", R.string.surround), |
| 61 | + new ShortcutItem("Ctrl + Y", R.string.delete_line), |
| 62 | + new ShortcutItem("Ctrl +", R.string.collapse_and_expand_code_block), |
| 63 | + new ShortcutItem("-/+", R.string.collapse_and_expand_all_code_block), |
| 64 | + new ShortcutItem("Ctrl + Shift +", R.string.duplicate_current_line), |
| 65 | + new ShortcutItem("-/+", R.string.basic_code_completion), |
| 66 | + new ShortcutItem("Ctrl + D", R.string.smart_code_completion) |
| 67 | + ); |
| 68 | + |
| 69 | + private static final List<ShortcutItem> REFACTORING_SHORTCUTS = List.of( |
| 70 | + new ShortcutItem("F5", android.R.string.copy), |
| 71 | + new ShortcutItem("F6", R.string.move), |
| 72 | + new ShortcutItem("Alt + Delete", R.string.safe_delete), |
| 73 | + new ShortcutItem("Shift + F6", R.string.rename), |
| 74 | + new ShortcutItem("Ctrl + F6", R.string.change_signature), |
| 75 | + new ShortcutItem("Ctrl + Alt + N", R.string.inline), |
| 76 | + new ShortcutItem("Ctrl + Alt + M", R.string.extract_method), |
| 77 | + new ShortcutItem("Ctrl + Alt + V", R.string.extract_variable), |
| 78 | + new ShortcutItem("Ctrl + Alt + F", R.string.extract_field), |
| 79 | + new ShortcutItem("Ctrl + Alt + C", R.string.extract_constant) |
| 80 | + ); |
| 81 | + |
| 82 | + private static final List<ShortcutItem> VERSION_CONTROL_SHORTCUTS = List.of( |
| 83 | + new ShortcutItem("Ctrl + K", R.string.commit_project), |
| 84 | + new ShortcutItem("Ctrl + T", R.string.update_project), |
| 85 | + new ShortcutItem("Alt + Shift + C", R.string.view_recent_changes), |
| 86 | + new ShortcutItem("Alt + `", R.string.open_vcs_popup) |
| 87 | + ); |
| 88 | + |
| 89 | + private static final List<ShortcutItem> NAVIGATION_SHORTCUTS = List.of( |
| 90 | + new ShortcutItem("Press Shift twice", R.string.search_everything), |
| 91 | + new ShortcutItem("Ctrl + F", R.string.find), |
| 92 | + new ShortcutItem("F3", R.string.find_next), |
| 93 | + new ShortcutItem("Shift + F3", R.string.find_previous), |
| 94 | + new ShortcutItem("Ctrl + R", R.string.replace), |
| 95 | + new ShortcutItem("Ctrl + Shift + A", R.string.find_action), |
| 96 | + new ShortcutItem("Ctrl + Alt + Shift + N", R.string.search_by_symbol_name), |
| 97 | + new ShortcutItem("Ctrl + N", R.string.find_class), |
| 98 | + new ShortcutItem("Ctrl + Shift + N", R.string.find_file), |
| 99 | + new ShortcutItem("Ctrl + Shift + Alt + N", R.string.find_path), |
| 100 | + new ShortcutItem("Ctrl + F12", R.string.open_file_structure), |
| 101 | + new ShortcutItem("Ctrl + Tab", R.string.navigate_between_open_tabs), |
| 102 | + new ShortcutItem("F4", R.string.jump_to_source), |
| 103 | + new ShortcutItem("Shift + F4", R.string.open_current_editor_tab_in_new_window), |
| 104 | + new ShortcutItem("Ctrl + E", R.string.recently_opened_files), |
| 105 | + new ShortcutItem("Ctrl + Shift + E", R.string.recently_edited_files), |
| 106 | + new ShortcutItem("Ctrl + Shift + Backspace", R.string.go_to_last_edit_location), |
| 107 | + new ShortcutItem("Ctrl + F4", R.string.close_active_editor_tabs), |
| 108 | + new ShortcutItem("Esc", R.string.return_to_editor_window), |
| 109 | + new ShortcutItem("Shift + Esc", R.string.hide_active_window), |
| 110 | + new ShortcutItem("Ctrl + G", R.string.go_to_line), |
| 111 | + new ShortcutItem("Ctrl + H", R.string.open_type_hierarchy), |
| 112 | + new ShortcutItem("Ctrl + Shift + H", R.string.open_v_hierarchy), |
| 113 | + new ShortcutItem("Ctrl + Alt + H", R.string.open_call_hierarchy) |
| 114 | + ); |
| 115 | + |
| 116 | + static { |
| 117 | + SHORTCUTS_BY_LAYOUT.put(R.layout.activity_shortcuts_general, GENERAL_SHORTCUTS); |
| 118 | + SHORTCUTS_BY_LAYOUT.put(R.layout.activity_shortcuts_build, BUILD_SHORTCUTS); |
| 119 | + SHORTCUTS_BY_LAYOUT.put(R.layout.activity_shortcuts_debugging, DEBUGGING_SHORTCUTS); |
| 120 | + SHORTCUTS_BY_LAYOUT.put(R.layout.activity_shortcuts_code, CODE_SHORTCUTS); |
| 121 | + SHORTCUTS_BY_LAYOUT.put(R.layout.activity_shortcuts_refractoring, REFACTORING_SHORTCUTS); |
| 122 | + SHORTCUTS_BY_LAYOUT.put(R.layout.activity_shortcuts_version_control, VERSION_CONTROL_SHORTCUTS); |
| 123 | + SHORTCUTS_BY_LAYOUT.put(R.layout.activity_shortcuts_navigation_and_searching, NAVIGATION_SHORTCUTS); |
| 124 | + } |
| 125 | +} |
0 commit comments