Skip to content

Commit

Permalink
fix issues #17
Browse files Browse the repository at this point in the history
that the activity uses android:configChanges="orientation|keyboardHidden|screenSize"
  • Loading branch information
w446108264 committed Jun 2, 2016
1 parent 0dbf4f6 commit 7be0d2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package sj.keyboard.widget;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,9 +16,10 @@ public abstract class AutoHeightLayout extends SoftKeyboardSizeWatchLayout imple

private static final int ID_CHILD = R.id.id_autolayout;

protected int mSoftKeyboardHeight;
protected int mMaxParentHeight;
protected Context mContext;
protected int mMaxParentHeight;
protected int mSoftKeyboardHeight;
protected boolean mConfigurationChangedFlag = false;

public AutoHeightLayout(Context context, AttributeSet attrs) {
super(context, attrs);
Expand Down Expand Up @@ -65,8 +69,26 @@ public void updateMaxParentHeight(int maxParentHeight) {
}
}

@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mConfigurationChangedFlag = true;
mScreenHeight = 0;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if(mConfigurationChangedFlag){
mConfigurationChangedFlag = false;
Rect r = new Rect();
((Activity) mContext).getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
if (mScreenHeight == 0) {
mScreenHeight = r.bottom;
}
int mNowh = mScreenHeight - r.bottom;
mMaxParentHeight = mNowh;
}

if (mMaxParentHeight != 0) {
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int expandSpec = MeasureSpec.makeMeasureSpec(mMaxParentHeight, heightMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
public class SoftKeyboardSizeWatchLayout extends RelativeLayout {

private Context mContext;
private boolean mIsSoftKeyboardPop = false;
private int mScreenHeight = 0;
private int mOldh = -1;
private int mNowh = -1;
protected int mScreenHeight = 0;
protected boolean mIsSoftKeyboardPop = false;

public SoftKeyboardSizeWatchLayout(Context context, AttributeSet attrs) {
super(context, attrs);
Expand Down

0 comments on commit 7be0d2f

Please sign in to comment.