From 90a99d49943fc240b741893e75677a3431ffaa25 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Sat, 22 May 2021 02:19:24 +0200 Subject: [PATCH] fix design when keyboard is shown - set windowSoftInputMode to adjustResize - comment out everything related to KeyboardUtils this fixes the design when keyboard is shown. At least this breaks the BottomSheet which will be hidden by the keyboard. Signed-off-by: Marcel Hibbe --- app/src/main/AndroidManifest.xml | 2 +- .../talk/controllers/ChatController.kt | 5 - .../talk/controllers/ContactsController.java | 5 +- .../ConversationsListController.java | 3 +- .../nextcloud/talk/utils/KeyboardUtils.java | 92 ------------------- 5 files changed, 3 insertions(+), 104 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d6c2e86bc..cda833251 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -97,7 +97,7 @@ + android:windowSoftInputMode="adjustResize"> diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index b47f38cbe..4c99a1ddf 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -149,7 +149,6 @@ import com.nextcloud.talk.utils.ContactUtils import com.nextcloud.talk.utils.DateUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.ImageEmojiEditText -import com.nextcloud.talk.utils.KeyboardUtils import com.nextcloud.talk.utils.MagicCharPolicy import com.nextcloud.talk.utils.NotificationUtils import com.nextcloud.talk.utils.UriUtils @@ -1541,10 +1540,6 @@ class ChatController(args: Bundle) : cancelReply() } - if (activity != null) { - KeyboardUtils(activity, getView(), false) - } - cancelNotificationsForCurrentConversation() if (inConversation) { diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java index c9dbaf36a..5a5491f20 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -64,7 +64,6 @@ import com.nextcloud.talk.models.json.converters.EnumActorTypeConverter; import com.nextcloud.talk.models.json.participants.Participant; import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ConductorRemapping; -import com.nextcloud.talk.utils.KeyboardUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.preferences.AppPreferences; @@ -801,8 +800,6 @@ public class ContactsController extends BaseController implements SearchView.OnQ } } - - private void prepareAndShowBottomSheetWithBundle(Bundle bundle, boolean showEntrySheet) { if (view == null) { view = getActivity().getLayoutInflater().inflate(R.layout.bottom_sheet, null, false); @@ -826,7 +823,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ bottomSheet.setOnShowListener(dialog -> { if (showEntrySheet) { - new KeyboardUtils(getActivity(), bottomSheet.getLayout(), true); +// new KeyboardUtils(getActivity(), bottomSheet.getLayout(), true); } else { eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java index 40c3cdf49..cd761b552 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java @@ -89,7 +89,6 @@ import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ClosedInterfaceImpl; import com.nextcloud.talk.utils.ConductorRemapping; import com.nextcloud.talk.utils.DisplayUtils; -import com.nextcloud.talk.utils.KeyboardUtils; import com.nextcloud.talk.utils.UriUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.user.UserUtils; @@ -860,7 +859,7 @@ public class ConversationsListController extends BaseController implements Searc bottomSheet = new BottomSheet.Builder(getActivity()).setView(view).create(); } - bottomSheet.setOnShowListener(dialog -> new KeyboardUtils(getActivity(), bottomSheet.getLayout(), true)); +// bottomSheet.setOnShowListener(dialog -> new KeyboardUtils(getActivity(), bottomSheet.getLayout(), true)); bottomSheet.setOnDismissListener(dialog -> showSearchOrToolbar()); bottomSheet.show(); } diff --git a/app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java b/app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java deleted file mode 100644 index 5ab0b0138..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.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; - private boolean isUsedInBottomSheet; - //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; - - boolean shouldSetBottomPadding = (isUsedInBottomSheet && diff != 0) || (diff > 0); - - if (shouldSetBottomPadding) { - 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 != initialBottomPadding (if yes reset the padding) - if (contentView.getPaddingBottom() != 0) { - //reset the padding of the contentView - contentView.setPadding(0, 0, 0, 0); - } - } - } - }; - - public KeyboardUtils(Activity act, View contentView, boolean isUsedInBottomSheet) { - this.decorView = act.getWindow().getDecorView(); - this.contentView = contentView; - this.isUsedInBottomSheet = isUsedInBottomSheet; - - decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); - } - - /** - * 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); - } - } - - public void enable() { - decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); - } - - public void disable() { - decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener); - } -}