11package cn .hadcn .keyboard .view ;
22
3+ import static cn .hadcn .keyboard .utils .Utils .getDisplayHeightPixels ;
34import android .app .Activity ;
45import android .content .Context ;
56import android .graphics .Rect ;
67import android .util .AttributeSet ;
7- import android .util .DisplayMetrics ;
8+ import android .util .Log ;
89import android .view .ViewTreeObserver ;
9- import android .view .WindowManager ;
1010import android .widget .RelativeLayout ;
1111
1212import cn .hadcn .keyboard .utils .Utils ;
@@ -23,17 +23,15 @@ public abstract class SoftListenLayout extends RelativeLayout {
2323 private int mKeyboardHeight = 0 ;
2424 protected Context mContext ;
2525
26- public SoftListenLayout (Context context , AttributeSet attrs ) {
26+ public SoftListenLayout (final Context context , AttributeSet attrs ) {
2727 super (context , attrs );
2828 mContext = context ;
29- WindowManager manager = (WindowManager ) context .getSystemService (Context .WINDOW_SERVICE );
30- DisplayMetrics metrics = new DisplayMetrics ();
31- manager .getDefaultDisplay ().getMetrics (metrics );
29+ int displayHeight = getDisplayHeightPixels (context );
3230 //the height of layout is at least 2/3 of screen height
33- mMinLayoutHeight = metrics . heightPixels * 2 / 3 ;
31+ mMinLayoutHeight = displayHeight * 2 / 3 ;
3432
3533 // min keyboard height, for ignoring navigation bar hide or show effects
36- mMinKeyboardHeight = metrics . heightPixels / 3 ;
34+ mMinKeyboardHeight = displayHeight / 3 ;
3735
3836 mKeyboardHeight = Utils .getDefKeyboardHeight (mContext );
3937
@@ -44,9 +42,11 @@ public void onGlobalLayout() {
4442 Rect r = new Rect ();
4543 ((Activity ) getContext ()).getWindow ().getDecorView ()
4644 .getWindowVisibleDisplayFrame (r );
47- if (mGlobalBottom != 0 && mGlobalBottom - r .bottom > mMinKeyboardHeight ) {
45+ int popHeight = Utils .getDisplayHeightPixels (context ) - r .bottom ;
46+ if ((mGlobalBottom != 0 && mGlobalBottom - r .bottom > mMinKeyboardHeight )
47+ || (popHeight != 0 && mKeyboardHeight != popHeight )) {
4848 // keyboard pop
49- mKeyboardHeight = mGlobalBottom - r . bottom ;
49+ mKeyboardHeight = popHeight ;
5050 OnSoftKeyboardPop (mKeyboardHeight );
5151 } else if (mGlobalBottom != 0 && r .bottom - mGlobalBottom > mMinKeyboardHeight ) {
5252 OnSoftKeyboardClose ();
0 commit comments