parent
26bcb590a7
commit
0f7f458ce0
1 changed files with 28 additions and 1 deletions
|
@ -21,15 +21,19 @@ import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LinearLayout that, when a view container, will report back when it thinks a soft keyboard
|
* LinearLayout that, when a view container, will report back when it thinks a soft keyboard
|
||||||
* has been opened and what its height would be.
|
* has been opened and what its height would be.
|
||||||
|
@ -61,7 +65,7 @@ public class KeyboardAwareLinearLayout extends LinearLayout {
|
||||||
int res = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
int res = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||||
int statusBarHeight = res > 0 ? getResources().getDimensionPixelSize(res) : 0;
|
int statusBarHeight = res > 0 ? getResources().getDimensionPixelSize(res) : 0;
|
||||||
|
|
||||||
final int availableHeight = this.getRootView().getHeight() - statusBarHeight;
|
final int availableHeight = this.getRootView().getHeight() - statusBarHeight - getViewInset();
|
||||||
getWindowVisibleDisplayFrame(rect);
|
getWindowVisibleDisplayFrame(rect);
|
||||||
|
|
||||||
final int keyboardHeight = availableHeight - (rect.bottom - rect.top);
|
final int keyboardHeight = availableHeight - (rect.bottom - rect.top);
|
||||||
|
@ -73,6 +77,29 @@ public class KeyboardAwareLinearLayout extends LinearLayout {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getViewInset() {
|
||||||
|
if (Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field attachInfoField = View.class.getDeclaredField("mAttachInfo");
|
||||||
|
attachInfoField.setAccessible(true);
|
||||||
|
Object attachInfo = attachInfoField.get(this);
|
||||||
|
if (attachInfo != null) {
|
||||||
|
Field stableInsetsField = attachInfo.getClass().getDeclaredField("mStableInsets");
|
||||||
|
stableInsetsField.setAccessible(true);
|
||||||
|
Rect insets = (Rect)stableInsetsField.get(attachInfo);
|
||||||
|
return insets.bottom;
|
||||||
|
}
|
||||||
|
} catch (NoSuchFieldException nsfe) {
|
||||||
|
Log.w(TAG, "field reflection error when measuring view inset", nsfe);
|
||||||
|
} catch (IllegalAccessException iae) {
|
||||||
|
Log.w(TAG, "access reflection error when measuring view inset", iae);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
protected void onKeyboardShown(int keyboardHeight) {
|
protected void onKeyboardShown(int keyboardHeight) {
|
||||||
Log.w(TAG, "keyboard shown, height " + keyboardHeight);
|
Log.w(TAG, "keyboard shown, height " + keyboardHeight);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue