@@ -133,6 +133,7 @@ public class MainActivity extends AppCompatActivity implements FileDialog.OnFile
133
133
private static final int SELECT_ALL_ACTION_POPUP_ID = 8 ;
134
134
private static final int COPY_AS_CODE_ACTION_POPUP_ID = 9 ;
135
135
private static final int PASTE_FROM_CODE_ACTION_POPUP_ID = 10 ;
136
+ private static final int OPEN_MAIN_MENU_ID = 11 ;
136
137
137
138
private static final int STORAGE_PERMISSION_CODE = 1 ;
138
139
@@ -552,25 +553,34 @@ public boolean onQueryTextChange(String newText) {
552
553
@ Override
553
554
public void onCreateContextMenu (ContextMenu menu , View v , ContextMenu .ContextMenuInfo menuInfo ) {
554
555
super .onCreateContextMenu (menu , v , menuInfo );
555
- menu .add (0 , SELECTION_START_POPUP_ID , 0 , getResources ().getString (R .string .action_selection_start ));
556
- menu .add (0 , SELECTION_END_POPUP_ID , 1 , getResources ().getString (R .string .action_selection_end ));
557
- menu .add (0 , CLEAR_SELECTION_POPUP_ID , 2 , getResources ().getString (R .string .action_clear_selection ));
558
- MenuItem cutMenuItem = menu .add (1 , CUT_ACTION_POPUP_ID , 3 , getResources ().getString (R .string .action_cut ));
556
+ int order = 0 ;
557
+ if (isGoogleTV (codeArea .getContext ())) {
558
+ menu .add (0 , OPEN_MAIN_MENU_ID , order , getResources ().getString (R .string .action_open_main_menu ));
559
+ order ++;
560
+ }
561
+ menu .add (0 , SELECTION_START_POPUP_ID , order , getResources ().getString (R .string .action_selection_start ));
562
+ menu .add (0 , SELECTION_END_POPUP_ID , order + 1 , getResources ().getString (R .string .action_selection_end ));
563
+ menu .add (0 , CLEAR_SELECTION_POPUP_ID , order + 2 , getResources ().getString (R .string .action_clear_selection ));
564
+ MenuItem cutMenuItem = menu .add (1 , CUT_ACTION_POPUP_ID , order + 3 , getResources ().getString (R .string .action_cut ));
559
565
cutMenuItem .setEnabled (codeArea .isEditable () && codeArea .hasSelection ());
560
- MenuItem copyMenuItem = menu .add (1 , COPY_ACTION_POPUP_ID , 4 , getResources ().getString (R .string .action_copy ));
566
+ MenuItem copyMenuItem = menu .add (1 , COPY_ACTION_POPUP_ID , order + 4 , getResources ().getString (R .string .action_copy ));
561
567
copyMenuItem .setEnabled (codeArea .hasSelection ());
562
- menu .add (1 , COPY_AS_CODE_ACTION_POPUP_ID , 5 , getResources ().getString (R .string .action_copy_as_code ));
563
- MenuItem pasteMenuItem = menu .add (1 , PASTE_ACTION_POPUP_ID , 6 , getResources ().getString (R .string .action_paste ));
568
+ menu .add (1 , COPY_AS_CODE_ACTION_POPUP_ID , order + 5 , getResources ().getString (R .string .action_copy_as_code ));
569
+ MenuItem pasteMenuItem = menu .add (1 , PASTE_ACTION_POPUP_ID , order + 6 , getResources ().getString (R .string .action_paste ));
564
570
pasteMenuItem .setEnabled (codeArea .isEditable () && codeArea .canPaste ());
565
- menu .add (1 , PASTE_FROM_CODE_ACTION_POPUP_ID , 5 , getResources ().getString (R .string .action_paste_from_code ));
566
- MenuItem deleteMenuItem = menu .add (1 , DELETE_ACTION_POPUP_ID , 7 , getResources ().getString (R .string .action_delete ));
571
+ menu .add (1 , PASTE_FROM_CODE_ACTION_POPUP_ID , order + 7 , getResources ().getString (R .string .action_paste_from_code ));
572
+ MenuItem deleteMenuItem = menu .add (1 , DELETE_ACTION_POPUP_ID , order + 8 , getResources ().getString (R .string .action_delete ));
567
573
deleteMenuItem .setEnabled (codeArea .isEditable () && codeArea .hasSelection ());
568
- menu .add (1 , SELECT_ALL_ACTION_POPUP_ID , 8 , getResources ().getString (R .string .action_select_all ));
574
+ menu .add (1 , SELECT_ALL_ACTION_POPUP_ID , order + 9 , getResources ().getString (R .string .action_select_all ));
569
575
}
570
576
571
577
@ Override
572
578
public boolean onContextItemSelected (MenuItem item ) {
573
579
switch (item .getItemId ()) {
580
+ case OPEN_MAIN_MENU_ID : {
581
+ toolbar .showOverflowMenu ();
582
+ break ;
583
+ }
574
584
case SELECTION_START_POPUP_ID : {
575
585
SelectionRange selection = codeArea .getSelection ();
576
586
CodeAreaCaretPosition touchCaretPosition = codeArea .mousePositionToClosestCaretPosition ((int ) codeArea .getTouchPositionX (), (int ) codeArea .getTouchPositionY (), CaretOverlapMode .PARTIAL_OVERLAP );
@@ -1320,13 +1330,15 @@ public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
1320
1330
editable .clear ();
1321
1331
if (keyEvent .getKeyCode () == KeyEvent .KEYCODE_DPAD_CENTER ) {
1322
1332
if (keyEvent .getEventTime () - keyEvent .getDownTime () > TimeUnit .SECONDS .toMillis (1 )) {
1323
- codeArea .showContextMenu ();
1324
- } else {
1325
1333
View keyStripeView = findViewById (R .id .button0 );
1326
1334
keyStripeView .requestFocus ();
1335
+ } else {
1336
+ codeArea .showContextMenu ();
1327
1337
}
1328
1338
} else if (keyEvent .getKeyCode () == KeyEvent .KEYCODE_BACK && isGoogleTV (codeArea .getContext ())) {
1329
- toolbar .showOverflowMenu ();
1339
+ releaseFile (() -> {
1340
+ System .exit (0 );
1341
+ });
1330
1342
} else {
1331
1343
codeArea .getCommandHandler ().keyPressed (keyEvent );
1332
1344
}
0 commit comments