1
1
package cn .hadcn .keyboard .view ;
2
2
3
+ import static cn .hadcn .keyboard .utils .Utils .getDisplayHeightPixels ;
3
4
import android .app .Activity ;
4
5
import android .content .Context ;
5
6
import android .graphics .Rect ;
6
7
import android .util .AttributeSet ;
7
- import android .util .DisplayMetrics ;
8
+ import android .util .Log ;
8
9
import android .view .ViewTreeObserver ;
9
- import android .view .WindowManager ;
10
10
import android .widget .RelativeLayout ;
11
11
12
12
import cn .hadcn .keyboard .utils .Utils ;
@@ -23,17 +23,15 @@ public abstract class SoftListenLayout extends RelativeLayout {
23
23
private int mKeyboardHeight = 0 ;
24
24
protected Context mContext ;
25
25
26
- public SoftListenLayout (Context context , AttributeSet attrs ) {
26
+ public SoftListenLayout (final Context context , AttributeSet attrs ) {
27
27
super (context , attrs );
28
28
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 );
32
30
//the height of layout is at least 2/3 of screen height
33
- mMinLayoutHeight = metrics . heightPixels * 2 / 3 ;
31
+ mMinLayoutHeight = displayHeight * 2 / 3 ;
34
32
35
33
// min keyboard height, for ignoring navigation bar hide or show effects
36
- mMinKeyboardHeight = metrics . heightPixels / 3 ;
34
+ mMinKeyboardHeight = displayHeight / 3 ;
37
35
38
36
mKeyboardHeight = Utils .getDefKeyboardHeight (mContext );
39
37
@@ -44,9 +42,11 @@ public void onGlobalLayout() {
44
42
Rect r = new Rect ();
45
43
((Activity ) getContext ()).getWindow ().getDecorView ()
46
44
.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 )) {
48
48
// keyboard pop
49
- mKeyboardHeight = mGlobalBottom - r . bottom ;
49
+ mKeyboardHeight = popHeight ;
50
50
OnSoftKeyboardPop (mKeyboardHeight );
51
51
} else if (mGlobalBottom != 0 && r .bottom - mGlobalBottom > mMinKeyboardHeight ) {
52
52
OnSoftKeyboardClose ();
0 commit comments