浏览代码

Fix #112 and #107

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 年之前
父节点
当前提交
84a8b8a745

+ 2 - 3
app/src/main/java/com/nextcloud/talk/controllers/CallsListController.java

@@ -42,7 +42,6 @@ import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
-import android.view.WindowManager;
 import android.view.inputmethod.EditorInfo;
 
 import com.bluelinelabs.conductor.RouterTransaction;
@@ -64,6 +63,7 @@ import com.nextcloud.talk.models.database.UserEntity;
 import com.nextcloud.talk.models.json.participants.Participant;
 import com.nextcloud.talk.models.json.rooms.Room;
 import com.nextcloud.talk.utils.ApiUtils;
+import com.nextcloud.talk.utils.KeyboardUtils;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 
@@ -467,8 +467,7 @@ public class CallsListController extends BaseController implements SearchView.On
             bottomSheet = new BottomSheet.Builder(getActivity()).setView(view).create();
         }
 
-        bottomSheet.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
-
+        bottomSheet.setOnShowListener(dialog -> new KeyboardUtils(getActivity(), bottomSheet.getLayout()));
         bottomSheet.show();
     }
 

+ 3 - 3
app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java

@@ -43,7 +43,6 @@ import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
-import android.view.WindowManager;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Button;
@@ -72,6 +71,7 @@ import com.nextcloud.talk.models.json.rooms.RoomOverall;
 import com.nextcloud.talk.models.json.sharees.Sharee;
 import com.nextcloud.talk.models.json.sharees.ShareesOverall;
 import com.nextcloud.talk.utils.ApiUtils;
+import com.nextcloud.talk.utils.KeyboardUtils;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 
@@ -736,14 +736,14 @@ public class ContactsController extends BaseController implements SearchView.OnQ
             bottomSheet = new BottomSheet.Builder(getActivity()).setView(view).create();
         }
 
-        bottomSheet.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
-
         bottomSheet.setOnCancelListener(dialog -> {
             if (getActionBar() != null) {
                 getActionBar().setDisplayHomeAsUpEnabled(true);
             }
         });
 
+        bottomSheet.setOnShowListener(dialog -> new KeyboardUtils(getActivity(), bottomSheet.getLayout()));
+
         bottomSheet.show();
     }
 

+ 101 - 0
app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java

@@ -0,0 +1,101 @@
+/*
+ * Copyright 2015 Mike Penz All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.nextcloud.talk.utils;
+
+import android.app.Activity;
+import android.graphics.Rect;
+import android.os.Build;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.view.inputmethod.InputMethodManager;
+
+/**
+ * Created by mikepenz on 14.03.15.
+ * This class implements a hack to change the layout padding on bottom if the keyboard is shown
+ * to allow long lists with editTextViews
+ * Basic idea for this solution found here: http://stackoverflow.com/a/9108219/325479
+ */
+public class KeyboardUtils {
+    private View decorView;
+    private View contentView;
+
+    public KeyboardUtils(Activity act, View contentView) {
+        this.decorView = act.getWindow().getDecorView();
+        this.contentView = contentView;
+
+        //only required on newer android versions. it was working on API level 19
+        if (Build.VERSION.SDK_INT >= 19) {
+            decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
+        }
+    }
+
+    public void enable() {
+        if (Build.VERSION.SDK_INT >= 19) {
+            decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
+        }
+    }
+
+    public void disable() {
+        if (Build.VERSION.SDK_INT >= 19) {
+            decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
+        }
+    }
+
+
+    //a small helper to allow showing the editText focus
+    ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
+        @Override
+        public void onGlobalLayout() {
+            Rect r = new Rect();
+            //r will be populated with the coordinates of your view that area still visible.
+            decorView.getWindowVisibleDisplayFrame(r);
+
+            //get screen height and calculate the difference with the useable area from the r
+            int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels;
+            int diff = height - r.bottom;
+
+            //if it could be a keyboard add the padding to the view
+            if (diff != 0) {
+                // if the use-able screen height differs from the total screen height we assume that it shows a keyboard now
+                //check if the padding is 0 (if yes set the padding for the keyboard)
+                if (contentView.getPaddingBottom() != diff) {
+                    //set the padding of the contentView for the keyboard
+                    contentView.setPadding(0, 0, 0, diff);
+                }
+            } else {
+                //check if the padding is != 0 (if yes reset the padding)
+                if (contentView.getPaddingBottom() != 0) {
+                    //reset the padding of the contentView
+                    contentView.setPadding(0, 0, 0, 0);
+                }
+            }
+        }
+    };
+
+
+    /**
+     * Helper to hide the keyboard
+     *
+     * @param act
+     */
+    public static void hideKeyboard(Activity act) {
+        if (act != null && act.getCurrentFocus() != null) {
+            InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE);
+            inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);
+        }
+    }
+}