mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 10:47:46 +00:00
parent
26bcb590a7
commit
0f7f458ce0
@ -21,15 +21,19 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
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
|
||||
* 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 statusBarHeight = res > 0 ? getResources().getDimensionPixelSize(res) : 0;
|
||||
|
||||
final int availableHeight = this.getRootView().getHeight() - statusBarHeight;
|
||||
final int availableHeight = this.getRootView().getHeight() - statusBarHeight - getViewInset();
|
||||
getWindowVisibleDisplayFrame(rect);
|
||||
|
||||
final int keyboardHeight = availableHeight - (rect.bottom - rect.top);
|
||||
@ -73,6 +77,29 @@ public class KeyboardAwareLinearLayout extends LinearLayout {
|
||||
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) {
|
||||
Log.w(TAG, "keyboard shown, height " + keyboardHeight);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user