mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-25 22:36:17 +03:00
Minor code improvements
Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
parent
f95175e8fa
commit
35605e4a0a
2 changed files with 7 additions and 23 deletions
|
@ -16,7 +16,6 @@ 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;
|
||||
|
||||
|
@ -184,10 +183,10 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
|
|||
binding.editContent.removeTextChangedListener(textWatcher);
|
||||
cancelTimers();
|
||||
|
||||
final ViewGroup parentView = requireActivity().findViewById(android.R.id.content);
|
||||
if(parentView != null && parentView.getChildCount() > 0){
|
||||
final ViewGroup parentView = requireActivity().findViewById(android.R.id.content);
|
||||
if (parentView != null && parentView.getChildCount() > 0) {
|
||||
keyboardShown = DisplayUtils.isSoftKeyboardVisible(parentView.getChildAt(0));
|
||||
}else {
|
||||
} else {
|
||||
keyboardShown = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,34 +2,21 @@ 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;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import it.niedermann.android.util.ColorUtil;
|
||||
import it.niedermann.owncloud.notes.NotesApplication;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.branding.BrandingUtil;
|
||||
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
|
||||
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
|
||||
import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount;
|
||||
|
@ -69,21 +56,19 @@ public class DisplayUtils {
|
|||
*/
|
||||
public static boolean isSoftKeyboardVisible(@NonNull View parentView) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(parentView);
|
||||
if(insets != null){
|
||||
final 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());
|
||||
final 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);
|
||||
final int heightDiff = parentView.getRootView().getHeight() - (rect.bottom - rect.top);
|
||||
return heightDiff >= estimatedKeyboardHeight;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue