|
|
@@ -0,0 +1,62 @@
|
|
|
+package kr.co.zumo.app.lifeplus.view.custom;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.graphics.Rect;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewTreeObserver;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+
|
|
|
+/**
|
|
|
+ * AndroidBug5497Workaround
|
|
|
+ * <pre>
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @author 하세미
|
|
|
+ * @version 1.0
|
|
|
+ * @history 하세미 [2018-12-05] [최초 작성]
|
|
|
+ * @since 2018-12-05
|
|
|
+ */
|
|
|
+public class AndroidBug5497Workaround {
|
|
|
+
|
|
|
+ public static void assistActivity(Activity activity) {
|
|
|
+ new AndroidBug5497Workaround(activity);
|
|
|
+ }
|
|
|
+
|
|
|
+ private View mChildOfContent;
|
|
|
+ private int usableHeightPrevious;
|
|
|
+ private FrameLayout.LayoutParams frameLayoutParams;
|
|
|
+
|
|
|
+ private AndroidBug5497Workaround(Activity activity) {
|
|
|
+ FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
|
|
|
+ mChildOfContent = content.getChildAt(0);
|
|
|
+ mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
+ public void onGlobalLayout() { possiblyResizeChildOfContent(); }
|
|
|
+ });
|
|
|
+ frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void possiblyResizeChildOfContent() {
|
|
|
+ int usableHeightNow = computeUsableHeight();
|
|
|
+ if (usableHeightNow != usableHeightPrevious) {
|
|
|
+ int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
|
|
|
+ int heightDifference = usableHeightSansKeyboard - usableHeightNow;
|
|
|
+ if (heightDifference > (usableHeightSansKeyboard / 4)) {
|
|
|
+ // keyboard probably just became visible
|
|
|
+ frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // keyboard probably just became hidden
|
|
|
+ frameLayoutParams.height = usableHeightSansKeyboard;
|
|
|
+ }
|
|
|
+ mChildOfContent.requestLayout();
|
|
|
+ usableHeightPrevious = usableHeightNow;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int computeUsableHeight() {
|
|
|
+ Rect r = new Rect();
|
|
|
+ mChildOfContent.getWindowVisibleDisplayFrame(r);
|
|
|
+ return (r.bottom - r.top);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|