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:
authorStefan Niedermann <info@niedermann.it>2021-06-17 17:20:21 +0300
committerStefan Niedermann <info@niedermann.it>2021-06-17 17:20:21 +0300
commitf95175e8fa84830c4b6c4c665c83da3e1ac26282 (patch)
treec6fd3ea92a4a937af8e7fee34be6c2a06929a1ec /app/src/main/java/it/niedermann/owncloud/notes/shared
parentbb92c9aeda9d8590888a9fa31367e1a10bdecae8 (diff)
parent7a59c808a34b7fe472cc681065154bba2098ae2d (diff)
Merge branch 'keyboardReopen' of https://github.com/Drhaal/nextcloud-notes into Drhaal-keyboardReopen
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/shared')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java34
1 files changed, 34 insertions, 0 deletions
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 b0adc011..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
@@ -3,15 +3,22 @@ package it.niedermann.owncloud.notes.shared.util;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
+import android.graphics.Rect;
+import android.os.Build;
import android.text.Spannable;
import android.text.TextPaint;
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;
@@ -52,4 +59,31 @@ public class DisplayUtils {
}
return new NavigationItem.CategoryNavigationItem("category:" + counter.getCategory(), counter.getCategory(), counter.getTotalNotes(), icon, counter.getAccountId(), counter.getCategory());
}
+
+ /**
+ * 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(@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);
+ final Rect rect = new Rect();
+
+ int estimatedKeyboardHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, EstimatedKeyboardDP, parentView.getResources().getDisplayMetrics());
+ parentView.getWindowVisibleDisplayFrame(rect);
+ int heightDiff = parentView.getRootView().getHeight() - (rect.bottom - rect.top);
+ return heightDiff >= estimatedKeyboardHeight;
+ }
}