Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrhaal <drhaal@protonmail.com>2021-06-10 21:46:56 +0300
committerdrhaal <drhaal@protonmail.com>2021-06-10 21:47:07 +0300
commit7a59c808a34b7fe472cc681065154bba2098ae2d (patch)
tree50c99e7d642c8a9d50768049bbec751cb5a8cdfa /app/src/main/java/it/niedermann
parent988ce872ccbfb5f96825d90eea811e5e1a713cfc (diff)
check for nulls + use proper keyboard detection on API 30+
Diffstat (limited to 'app/src/main/java/it/niedermann')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java9
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java16
2 files changed, 21 insertions, 4 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java
index 6ba09432..11e1ec4f 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java
@@ -16,6 +16,7 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewParent;
import android.view.inputmethod.InputMethodManager;
import android.widget.ScrollView;
@@ -183,8 +184,12 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
binding.editContent.removeTextChangedListener(textWatcher);
cancelTimers();
- final View parentView = ((ViewGroup) requireActivity().findViewById(android.R.id.content)).getChildAt(0);
- keyboardShown = DisplayUtils.isSoftKeyboardVisible(parentView);
+ final ViewGroup parentView = requireActivity().findViewById(android.R.id.content);
+ if(parentView != null && parentView.getChildCount() > 0){
+ keyboardShown = DisplayUtils.isSoftKeyboardVisible(parentView.getChildAt(0));
+ }else {
+ keyboardShown = false;
+ }
}
private void cancelTimers() {
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java
index 297c843c..ffea98b1 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java
@@ -11,11 +11,14 @@ import android.text.TextUtils;
import android.text.style.MetricAffectingSpan;
import android.util.TypedValue;
import android.view.View;
+import android.view.WindowInsets;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
import java.util.Collection;
import java.util.List;
@@ -58,12 +61,21 @@ public class DisplayUtils {
}
/**
- * Android does not provide a way to get keyboard visibility prior to API 30 so we use a workaround
+ * Detect if the soft keyboard is open.
+ * On API prior to 30 we fall back to workaround which might be less reliable
*
* @param parentView View
* @return keyboardVisibility Boolean
*/
- public static boolean isSoftKeyboardVisible(View parentView) {
+ public static boolean isSoftKeyboardVisible(@NonNull View parentView) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(parentView);
+ if(insets != null){
+ return insets.isVisible(WindowInsets.Type.ime());
+ }
+ }
+ //Fall Back to workaround
+
//Arbitrary keyboard height
final int defaultKeyboardHeightDP = 100;
final int EstimatedKeyboardDP = defaultKeyboardHeightDP + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? 48 : 0);