@@ -133,6 +133,7 @@ public class MainActivity extends AppCompatActivity implements FileDialog.OnFile
133133 private static final int SELECT_ALL_ACTION_POPUP_ID = 8 ;
134134 private static final int COPY_AS_CODE_ACTION_POPUP_ID = 9 ;
135135 private static final int PASTE_FROM_CODE_ACTION_POPUP_ID = 10 ;
136+ private static final int OPEN_MAIN_MENU_ID = 11 ;
136137
137138 private static final int STORAGE_PERMISSION_CODE = 1 ;
138139
@@ -552,25 +553,34 @@ public boolean onQueryTextChange(String newText) {
552553 @ Override
553554 public void onCreateContextMenu (ContextMenu menu , View v , ContextMenu .ContextMenuInfo menuInfo ) {
554555 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 ));
559565 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 ));
561567 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 ));
564570 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 ));
567573 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 ));
569575 }
570576
571577 @ Override
572578 public boolean onContextItemSelected (MenuItem item ) {
573579 switch (item .getItemId ()) {
580+ case OPEN_MAIN_MENU_ID : {
581+ toolbar .showOverflowMenu ();
582+ break ;
583+ }
574584 case SELECTION_START_POPUP_ID : {
575585 SelectionRange selection = codeArea .getSelection ();
576586 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) {
13201330 editable .clear ();
13211331 if (keyEvent .getKeyCode () == KeyEvent .KEYCODE_DPAD_CENTER ) {
13221332 if (keyEvent .getEventTime () - keyEvent .getDownTime () > TimeUnit .SECONDS .toMillis (1 )) {
1323- codeArea .showContextMenu ();
1324- } else {
13251333 View keyStripeView = findViewById (R .id .button0 );
13261334 keyStripeView .requestFocus ();
1335+ } else {
1336+ codeArea .showContextMenu ();
13271337 }
13281338 } else if (keyEvent .getKeyCode () == KeyEvent .KEYCODE_BACK && isGoogleTV (codeArea .getContext ())) {
1329- toolbar .showOverflowMenu ();
1339+ releaseFile (() -> {
1340+ System .exit (0 );
1341+ });
13301342 } else {
13311343 codeArea .getCommandHandler ().keyPressed (keyEvent );
13321344 }
0 commit comments