@@ -211,12 +211,14 @@ private void intiDiagnosticView() {
211211
212212 final View toggleView = findViewById (R .id .btn_toggle_panel );
213213 mSlidingUpPanelLayout = findViewById (R .id .diagnostic_panel );
214- mSlidingUpPanelLayout .addPanelSlideListener (new SlidingUpPanelLayout .SimplePanelSlideListener () {
215- @ Override
216- public void onPanelSlide (View panel , float slideOffset ) {
217- toggleView .animate ().rotation (180 * slideOffset ).start ();
218- }
219- });
214+ //animation
215+ mSlidingUpPanelLayout .addPanelSlideListener (
216+ new SlidingUpPanelLayout .SimplePanelSlideListener () {
217+ @ Override
218+ public void onPanelSlide (View panel , float slideOffset ) {
219+ toggleView .animate ().rotation (180 * slideOffset ).start ();
220+ }
221+ });
220222
221223 FragmentManager fm = getSupportFragmentManager ();
222224 String tag = DiagnosticFragment .class .getSimpleName ();
@@ -243,6 +245,21 @@ public void onPanelSlide(View panel, float slideOffset) {
243245 @ LayoutRes
244246 protected abstract int getRootLayoutId ();
245247
248+ /**
249+ * You should override this method to init editor fragment
250+ */
251+ @ Override
252+ @ CallSuper
253+ public void onEditorViewCreated (IEditorDelegate editorDelegate ) {
254+ editorDelegate .setCodeFormatProvider (getCodeFormatProvider ());
255+ }
256+
257+ @ Nullable
258+ protected CodeFormatProvider getCodeFormatProvider () {
259+ return new CodeFormatProviderImpl (this );
260+ }
261+
262+
246263 @ Override
247264 public void onSharedPreferenceChanged (SharedPreferences sharedPreferences , String key ) {
248265 super .onSharedPreferenceChanged (sharedPreferences , key );
@@ -441,15 +458,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
441458
442459 @ Override
443460 public boolean onMenuItemClick (MenuItem item ) {
444- onMenuClick (item .getItemId ());
445- return true ;
446- }
447-
448- private void onMenuClick (int id ) {
449461 Command .CommandEnum commandEnum ;
450-
451- closeMenu ();
452-
462+ closeDrawers ();
463+ int id = item .getItemId ();
453464 if (id == R .id .action_new_file ) {
454465 createNewFile ();
455466
@@ -511,12 +522,18 @@ public void run() {
511522 StoreUtil .gotoPlayStore (this , getPackageName ());
512523 } else {
513524 commandEnum = MenuFactory .getInstance (this ).idToCommandEnum (id );
514- if (commandEnum != Command .CommandEnum .NONE )
525+ if (commandEnum != Command .CommandEnum .NONE ) {
515526 doCommand (new Command (commandEnum ));
527+ }
516528 }
529+ return true ;
517530 }
518531
519- private void openFileExplorer () {
532+
533+ /**
534+ * Called when user click open file expoler menu
535+ */
536+ public void openFileExplorer () {
520537 EditorDelegate editorDelegate = getCurrentEditorDelegate ();
521538 String sourceDir ;
522539 String homeDir = Environment .getExternalStorageDirectory ().getAbsolutePath ();
@@ -531,11 +548,15 @@ private void openFileExplorer() {
531548 FileExplorerActivity .startPickFileActivity (this , sourceDir , homeDir , RC_OPEN_FILE );
532549 }
533550
551+ /**
552+ * Called when user click create new file button, should override if you need more feature
553+ */
534554 public void createNewFile () {
535555 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
536556 if (ActivityCompat .checkSelfPermission (this , Manifest .permission .WRITE_EXTERNAL_STORAGE )
537557 != PackageManager .PERMISSION_GRANTED ) {
538- requestPermissions (new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE }, RC_PERMISSION_WRITE_STORAGE );
558+ requestPermissions (new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE },
559+ RC_PERMISSION_WRITE_STORAGE );
539560 return ;
540561 }
541562 }
@@ -586,20 +607,14 @@ public void onSaveFailed(Exception e) {
586607 saveAllTask .execute ();
587608 }
588609
610+ /**
611+ * Called when save all files completed
612+ */
589613 protected void onSaveComplete (int requestCode ) {
590614
591615 }
592616
593- public void closeMenu () {
594- if (mDrawerLayout .isDrawerOpen (GravityCompat .START )) {
595- mDrawerLayout .closeDrawer (GravityCompat .START );
596- }
597- if (mDrawerLayout .isDrawerOpen (GravityCompat .END )) {
598- mDrawerLayout .closeDrawer (GravityCompat .END );
599- }
600- }
601-
602- private void hideSoftInput () {
617+ protected void hideSoftInput () {
603618 doCommand (new Command (Command .CommandEnum .HIDE_SOFT_INPUT ));
604619 }
605620
@@ -622,8 +637,9 @@ public void doCommand(Command command) {
622637 }
623638
624639 protected EditorDelegate getCurrentEditorDelegate () {
625- if (mTabManager == null || mTabManager .getEditorPagerAdapter () == null )
640+ if (mTabManager == null || mTabManager .getEditorPagerAdapter () == null ) {
626641 return null ;
642+ }
627643 return mTabManager .getEditorPagerAdapter ().getCurrentEditorDelegate ();
628644 }
629645
@@ -641,10 +657,12 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
641657 }
642658
643659 @ Override
660+ @ CallSuper
644661 protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
645662 super .onActivityResult (requestCode , resultCode , data );
646- if (resultCode != RESULT_OK )
663+ if (resultCode != RESULT_OK ) {
647664 return ;
665+ }
648666
649667 switch (requestCode ) {
650668 case RC_OPEN_FILE :
@@ -666,25 +684,28 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
666684 }
667685 break ;
668686 case RC_SETTINGS :
687+ // TODO: 09-Jun-18 need update themes
669688 break ;
670689 }
671690 }
672691
673692 private void openText (CharSequence content ) {
674- if (TextUtils .isEmpty (content ))
693+ if (TextUtils .isEmpty (content )) {
675694 return ;
695+ }
676696 FileManager fileManager = new FileManager (this );
677- File newFile = fileManager .createNewFile ("_" + System .currentTimeMillis () + ".txt" );
697+ File newFile = fileManager .createNewFile (
698+ "untitled_" + System .currentTimeMillis () + ".txt" );
678699 if (IOUtils .writeFile (newFile , content .toString ())) {
679700 mTabManager .newTab (newFile );
680701 }
681702 }
682703
683- private void openFile (String file ) {
704+ protected void openFile (String file ) {
684705 openFile (file , null , 0 );
685706 }
686707
687- public void openFile (final String filePath , final String encoding , final int offset ) {
708+ protected void openFile (final String filePath , final String encoding , final int offset ) {
688709 //ensure file exist, can read/write
689710 if (TextUtils .isEmpty (filePath )) {
690711 return ;
@@ -741,6 +762,7 @@ public TabManager getTabManager() {
741762 }
742763
743764 @ Override
765+ @ CallSuper
744766 public void onBackPressed () {
745767 if (closeDrawers ()) {
746768 return ;
@@ -777,10 +799,6 @@ public String getCurrentLang() {
777799 return editorDelegate .getLang ();
778800 }
779801
780- @ Override
781- public void onEditorViewCreated (IEditorDelegate editorDelegate ) {
782- editorDelegate .setCodeFormatProvider (getCodeFormatProvider ());
783- }
784802
785803 protected void onShowKeyboard () {
786804 if (mTabLayout != null ) {
@@ -802,15 +820,10 @@ protected void onHideKeyboard() {
802820
803821 @ Override
804822 protected void onDestroy () {
805- mDrawerLayout .getViewTreeObserver ()
806- .removeGlobalOnLayoutListener (mKeyBoardListener );
823+ mDrawerLayout .getViewTreeObserver ().removeGlobalOnLayoutListener (mKeyBoardListener );
807824 super .onDestroy ();
808825 }
809826
810- @ Nullable
811- protected CodeFormatProvider getCodeFormatProvider () {
812- return new CodeFormatProviderImpl (this );
813- }
814827
815828 private class KeyBoardEventListener implements ViewTreeObserver .OnGlobalLayoutListener {
816829 IdeActivity activity ;
0 commit comments