2323import android .content .SharedPreferences ;
2424import android .content .pm .ActivityInfo ;
2525import android .content .pm .PackageManager ;
26+ import android .graphics .Rect ;
2627import android .graphics .drawable .Drawable ;
2728import android .net .Uri ;
2829import android .os .Build ;
4647import android .view .MenuItem ;
4748import android .view .SubMenu ;
4849import android .view .View ;
50+ import android .view .ViewTreeObserver ;
4951import android .widget .TextView ;
5052
5153import com .duy .common .StoreUtil ;
8183import com .jecelyin .editor .v2 .widget .menu .MenuFactory ;
8284import com .jecelyin .editor .v2 .widget .menu .MenuGroup ;
8385import com .jecelyin .editor .v2 .widget .menu .MenuItemInfo ;
86+ import com .ogaclejapan .smarttablayout .SmartTabLayout ;
8487import com .sothree .slidinguppanel .SlidingUpPanelLayout ;
8588
8689import org .gjt .sp .jedit .Catalog ;
@@ -104,16 +107,20 @@ public abstract class IdeActivity extends ThemeSupportActivity implements MenuIt
104107
105108 //Handle create on MainThread, use for update UI
106109 private final Handler mHandler = new Handler ();
107-
108110 public SlidingUpPanelLayout mSlidingUpPanelLayout ;
109- public Toolbar mToolbar ;
110111 public ViewPager mEditorPager ;
111- public DrawerLayout mDrawerLayout ;
112+
112113 protected TabManager mTabManager ;
113114 protected DiagnosticPresenter mDiagnosticPresenter ;
115+
114116 private SymbolBarLayout mSymbolBarLayout ;
117+ private Toolbar mToolbar ;
118+ private DrawerLayout mDrawerLayout ;
119+ private SmartTabLayout mTabLayout ;
120+
115121 private Preferences mPreferences ;
116122 private long mExitTime ;
123+ private KeyBoardEventListener mKeyBoardListener ;
117124
118125 @ Override
119126 protected void onCreate (Bundle savedInstanceState ) {
@@ -125,6 +132,7 @@ protected void onCreate(Bundle savedInstanceState) {
125132 MenuManager .init (this );
126133 mPreferences = Preferences .getInstance (this );
127134
135+ mTabLayout = findViewById (R .id .tab_layout );
128136 mEditorPager = findViewById (R .id .editor_view_pager );
129137 mDrawerLayout = findViewById (R .id .drawer_layout );
130138 mDrawerLayout .setKeepScreenOn (mPreferences .isKeepScreenOn ());
@@ -141,10 +149,6 @@ public void onDrawerOpened(View drawerView) {
141149 mDrawerLayout .addDrawerListener (actionBarDrawerToggle );
142150 actionBarDrawerToggle .syncState ();
143151
144- //keyboard hide/show listener
145- setRootLayout (mDrawerLayout );
146- attachKeyboardListeners ();
147-
148152 mSymbolBarLayout = findViewById (R .id .symbolBarLayout );
149153 mSymbolBarLayout .setOnSymbolCharClickListener (new SymbolBarLayout .OnSymbolCharClickListener () {
150154 @ Override
@@ -165,6 +169,10 @@ public void onClick(View v, String text) {
165169 processIntent ();
166170
167171 mPreferences .registerOnSharedPreferenceChangeListener (this );
172+
173+ //attach listener hide/show keyboard
174+ mKeyBoardListener = new KeyBoardEventListener (this );
175+ mDrawerLayout .getViewTreeObserver ().addOnGlobalLayoutListener (mKeyBoardListener );
168176 }
169177
170178 private void intiDiagnosticView () {
@@ -731,4 +739,44 @@ public String getCurrentLang() {
731739 public void onEditorViewCreated (IEditorDelegate editorDelegate ) {
732740
733741 }
742+
743+ protected void onShowKeyboard () {
744+ mTabLayout .setVisibility (View .GONE );
745+ }
746+
747+ protected void onHideKeyboard () {
748+ mTabLayout .setVisibility (View .VISIBLE );
749+ }
750+
751+ @ Override
752+ protected void onDestroy () {
753+ mDrawerLayout .getViewTreeObserver ()
754+ .removeGlobalOnLayoutListener (mKeyBoardListener );
755+ super .onDestroy ();
756+ }
757+
758+ private class KeyBoardEventListener implements ViewTreeObserver .OnGlobalLayoutListener {
759+ IdeActivity activity ;
760+
761+ KeyBoardEventListener (IdeActivity activityIde ) {
762+ this .activity = activityIde ;
763+ }
764+
765+ public void onGlobalLayout () {
766+ int i = 0 ;
767+ int navHeight = this .activity .getResources ().getIdentifier ("navigation_bar_height" , "dimen" , "android" );
768+ navHeight = navHeight > 0 ? this .activity .getResources ().getDimensionPixelSize (navHeight ) : 0 ;
769+ int statusBarHeight = this .activity .getResources ().getIdentifier ("status_bar_height" , "dimen" , "android" );
770+ if (statusBarHeight > 0 ) {
771+ i = this .activity .getResources ().getDimensionPixelSize (statusBarHeight );
772+ }
773+ Rect rect = new Rect ();
774+ activity .getWindow ().getDecorView ().getWindowVisibleDisplayFrame (rect );
775+ if (activity .mDrawerLayout .getRootView ().getHeight () - ((navHeight + i ) + rect .height ()) <= 0 ) {
776+ activity .onHideKeyboard ();
777+ } else {
778+ activity .onShowKeyboard ();
779+ }
780+ }
781+ }
734782}
0 commit comments