11package com .d4rk .androidtutorials .java .ui .screens .android .lessons .basics .shortcuts .tabs ;
22
33import android .os .Bundle ;
4+ import android .view .LayoutInflater ;
5+ import android .view .View ;
6+ import android .view .ViewGroup ;
7+ import android .widget .TextView ;
48
9+ import androidx .annotation .NonNull ;
10+ import androidx .recyclerview .widget .LinearLayoutManager ;
11+ import androidx .recyclerview .widget .RecyclerView ;
12+
13+ import com .d4rk .androidtutorials .java .R ;
514import com .d4rk .androidtutorials .java .databinding .ActivityShortcutsNavigationAndSearchingBinding ;
615import com .d4rk .androidtutorials .java .ui .components .navigation .UpNavigationActivity ;
716import com .d4rk .androidtutorials .java .utils .EdgeToEdgeDelegate ;
817import com .google .android .gms .ads .AdRequest ;
918import com .google .android .gms .ads .MobileAds ;
1019
20+ import java .util .List ;
21+
1122import me .zhanghai .android .fastscroll .FastScrollerBuilder ;
1223
1324public class NavigationAndSearchingShortcutsActivity extends UpNavigationActivity {
1425 @ Override
1526 protected void onCreate (Bundle savedInstanceState ) {
1627 super .onCreate (savedInstanceState );
17- com . d4rk . androidtutorials . java . databinding . ActivityShortcutsNavigationAndSearchingBinding binding = ActivityShortcutsNavigationAndSearchingBinding .inflate (getLayoutInflater ());
28+ ActivityShortcutsNavigationAndSearchingBinding binding = ActivityShortcutsNavigationAndSearchingBinding .inflate (getLayoutInflater ());
1829 setContentView (binding .getRoot ());
1930 MobileAds .initialize (this );
2031
2132 EdgeToEdgeDelegate edgeToEdgeDelegate = new EdgeToEdgeDelegate (this );
22- edgeToEdgeDelegate .applyEdgeToEdge (binding .scrollView );
33+ edgeToEdgeDelegate .applyEdgeToEdge (binding .shortcutList );
2334
2435 binding .adView .loadAd (new AdRequest .Builder ().build ());
25- new FastScrollerBuilder (binding .scrollView ).useMd2Style ().build ();
36+ new FastScrollerBuilder (binding .shortcutList ).useMd2Style ().build ();
37+
38+ List <Shortcut > shortcuts = List .of (
39+ new Shortcut (getString (R .string .press_shift_twice ), getString (R .string .search_everything )),
40+ new Shortcut ("Ctrl + F" , getString (R .string .find )),
41+ new Shortcut ("F3" , getString (R .string .find_next )),
42+ new Shortcut ("Shift + F3" , getString (R .string .find_previous )),
43+ new Shortcut ("Ctrl + R" , getString (R .string .replace )),
44+ new Shortcut ("Ctrl + Shift + A" , getString (R .string .find_action )),
45+ new Shortcut ("Ctrl + Alt + Shift + N" , getString (R .string .search_by_symbol_name )),
46+ new Shortcut ("Ctrl + N" , getString (R .string .find_class )),
47+ new Shortcut ("Ctrl + Shift + N" , getString (R .string .find_file )),
48+ new Shortcut ("Ctrl + Shift + F" , getString (R .string .find_path )),
49+ new Shortcut ("Ctrl + F12" , getString (R .string .open_file_structure )),
50+ new Shortcut ("Alt + Right/Left Arrow" , getString (R .string .navigate_between_open_tabs )),
51+ new Shortcut ("F4/Ctrl +Enter" , getString (R .string .jump_to_source )),
52+ new Shortcut ("Shift + F4" , getString (R .string .open_current_editor_tab_in_new_window )),
53+ new Shortcut ("Ctrl + E" , getString (R .string .recently_opened_files )),
54+ new Shortcut ("Ctrl + Shift + E" , getString (R .string .recently_edited_files )),
55+ new Shortcut ("Ctrl + Shift + Backspace" , getString (R .string .go_to_last_edit_location )),
56+ new Shortcut ("Ctrl + F4" , getString (R .string .close_active_editor_tabs )),
57+ new Shortcut ("Esc" , getString (R .string .return_to_editor_window )),
58+ new Shortcut ("Shift + Esc" , getString (R .string .hide_active_window )),
59+ new Shortcut ("Ctrl + G" , getString (R .string .go_to_line )),
60+ new Shortcut ("Ctrl + H" , getString (R .string .open_type_hierarchy )),
61+ new Shortcut ("Ctrl + Shift + H" , getString (R .string .open_v_hierarchy )),
62+ new Shortcut ("Ctrl + Alt + H" , getString (R .string .open_call_hierarchy ))
63+ );
64+
65+ binding .shortcutList .setLayoutManager (new LinearLayoutManager (this ));
66+ binding .shortcutList .setAdapter (new ShortcutsAdapter (shortcuts ));
2667 }
68+
69+ private static class ShortcutsAdapter extends RecyclerView .Adapter <ShortcutsAdapter .ShortcutHolder > {
70+ private final List <Shortcut > items ;
71+
72+ ShortcutsAdapter (List <Shortcut > items ) {
73+ this .items = items ;
74+ }
75+
76+ @ NonNull
77+ @ Override
78+ public ShortcutHolder onCreateViewHolder (@ NonNull ViewGroup parent , int viewType ) {
79+ View view = LayoutInflater .from (parent .getContext ()).inflate (R .layout .item_shortcut , parent , false );
80+ return new ShortcutHolder (view );
81+ }
82+
83+ @ Override
84+ public void onBindViewHolder (@ NonNull ShortcutHolder holder , int position ) {
85+ Shortcut item = items .get (position );
86+ holder .key .setText (item .key );
87+ holder .description .setText (item .description );
88+ }
89+
90+ @ Override
91+ public int getItemCount () {
92+ return items .size ();
93+ }
94+
95+ static class ShortcutHolder extends RecyclerView .ViewHolder {
96+ final TextView key ;
97+ final TextView description ;
98+
99+ ShortcutHolder (@ NonNull View itemView ) {
100+ super (itemView );
101+ key = itemView .findViewById (R .id .shortcut_key );
102+ description = itemView .findViewById (R .id .shortcut_description );
103+ }
104+ }
105+ }
106+
107+ private record Shortcut (String key , String description ) { }
27108}
0 commit comments