diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index da323638a..432633f31 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -179,7 +179,7 @@ android:parentActivityName=".activity.MainActivity" android:taskAffinity=".activity.DocumentActivity" android:theme="@style/AppTheme.Unified.StartupFlash" - android:windowSoftInputMode="stateAlwaysHidden|adjustResize" + android:windowSoftInputMode="stateHidden|adjustResize" tools:targetApi="lollipop"> _cu.showSoftKeyboard(activity, false, _hlEditor), 300); + _hlEditor.postDelayed(() -> _cu.showIme(activity, false, _hlEditor), 300); fadeInOut(_webView, _primaryScrollView); } else { _webViewClient.setRestoreScrollY(_webView.getScrollY()); diff --git a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java index 07401d357..4fc2985d8 100644 --- a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java +++ b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java @@ -20,6 +20,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; @@ -43,6 +44,7 @@ import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserFragment; import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserListAdapter; import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions; +import net.gsantner.opoc.util.GsContextUtils; import java.io.File; import java.io.IOException; @@ -372,19 +374,18 @@ public String getPosTitle(final int pos) { return null; } - public void onViewPagerPageSelected(int pos) { + public void onViewPagerPageSelected(final int pos) { _bottomNav.getMenu().getItem(pos).setChecked(true); if (pos == tabIdToPos(R.id.nav_notebook)) { _fab.show(); + _cu.showIme(this, false); } else { _fab.hide(); - } - setTitle(getPosTitle(pos)); - - if (pos != tabIdToPos(R.id.nav_notebook)) { restoreDefaultToolbar(); } + + setTitle(getPosTitle(pos)); } private GsFileBrowserOptions.Options _filesystemDialogOptions = null; diff --git a/app/src/main/java/net/gsantner/markor/format/todotxt/TodoTxtActionButtons.java b/app/src/main/java/net/gsantner/markor/format/todotxt/TodoTxtActionButtons.java index c6d70829d..28b8a2e60 100644 --- a/app/src/main/java/net/gsantner/markor/format/todotxt/TodoTxtActionButtons.java +++ b/app/src/main/java/net/gsantner/markor/format/todotxt/TodoTxtActionButtons.java @@ -26,6 +26,7 @@ import net.gsantner.markor.frontend.textview.TextViewUtils; import net.gsantner.markor.model.Document; import net.gsantner.opoc.util.GsCollectionUtils; +import net.gsantner.opoc.util.GsContextUtils; import net.gsantner.opoc.util.GsFileUtils; import net.gsantner.opoc.wrapper.GsCallback; @@ -204,11 +205,11 @@ public boolean onActionLongClick(final @StringRes int action) { switch (action) { case R.string.abid_todotxt_add_context: { - MarkorDialogFactory.showSttKeySearchDialog(getActivity(), _hlEditor, R.string.browse_by_context, true, true, TextViewUtils.isImeOpen(_hlEditor), TodoTxtFilter.TYPE.CONTEXT); + MarkorDialogFactory.showSttKeySearchDialog(getActivity(), _hlEditor, R.string.browse_by_context, true, true, GsContextUtils.isImeOpen(_hlEditor), TodoTxtFilter.TYPE.CONTEXT); return true; } case R.string.abid_todotxt_add_project: { - MarkorDialogFactory.showSttKeySearchDialog(getActivity(), _hlEditor, R.string.browse_by_project, true, true, TextViewUtils.isImeOpen(_hlEditor), TodoTxtFilter.TYPE.PROJECT); + MarkorDialogFactory.showSttKeySearchDialog(getActivity(), _hlEditor, R.string.browse_by_project, true, true, GsContextUtils.isImeOpen(_hlEditor), TodoTxtFilter.TYPE.PROJECT); return true; } case R.string.abid_todotxt_sort_todo: { diff --git a/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java b/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java index 5336ea8a0..09f9d65da 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java +++ b/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java @@ -14,8 +14,6 @@ import android.content.Context; import android.text.Editable; import android.view.View; -import android.view.Window; -import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; @@ -159,7 +157,7 @@ public static void showInsertImageOrLinkDialog( } }; - final Boolean restoreIme = TextViewUtils.isImeOpen(edit); + final Boolean restoreIme = GsContextUtils.isImeOpen(edit); final AlertDialog dialog = builder.setView(view) @@ -217,7 +215,7 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { dialog.setOnDismissListener(d -> { LocalBroadcastManager.getInstance(activity).unregisterReceiver(br); - edit.postDelayed(() -> GsContextUtils.instance.showSoftKeyboard(activity, restoreIme, edit), 250); + edit.postDelayed(() -> GsContextUtils.instance.showIme(activity, restoreIme, edit), 250); }); // Get picture from camera diff --git a/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java b/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java index 00c4fd514..7ecddabc8 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java +++ b/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java @@ -26,7 +26,6 @@ import android.text.TextUtils; import android.util.Pair; import android.view.Gravity; -import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; @@ -235,7 +234,7 @@ public static void showSttFilteringDialog(final Activity activity, final EditTex final DialogOptions dopt = new DialogOptions(); baseConf(activity, dopt); - final Boolean showIme = TextViewUtils.isImeOpen(text); + final Boolean showIme = GsContextUtils.isImeOpen(text); final List options = new ArrayList<>(); final List icons = new ArrayList<>(); @@ -489,11 +488,11 @@ public static void showSttSearchDialog(final Activity activity, final EditText t // Restore the keyboard when dialog closes if keyboard is open when dialog was called private static void addRestoreKeyboard(final Activity activity, final DialogOptions options, final EditText edit) { - addRestoreKeyboard(activity, options, edit, TextViewUtils.isImeOpen(edit)); + addRestoreKeyboard(activity, options, edit, GsContextUtils.isImeOpen(edit)); } private static void addRestoreKeyboard(final Activity activity, final DialogOptions options, final EditText edit, final Boolean restore) { - options.dismissCallback = (d) -> edit.postDelayed(() -> GsContextUtils.instance.showSoftKeyboard(activity, restore, edit), 250); + options.dismissCallback = (d) -> edit.postDelayed(() -> GsContextUtils.instance.showIme(activity, restore, edit), 250); } /** @@ -818,7 +817,7 @@ public static void showInsertSnippetDialog(final Activity activity, @Nullable fi baseConf(activity, dopt); final Map texts = getSnippets(as()); - final Boolean showIme = edit != null ? TextViewUtils.isImeOpen(edit) : null; + final Boolean showIme = edit != null ? GsContextUtils.isImeOpen(edit) : null; final List data = new ArrayList<>(texts.keySet()); dopt.data = data; diff --git a/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java b/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java index 0f0724eda..631ae9305 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java +++ b/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java @@ -9,10 +9,8 @@ #########################################################*/ package net.gsantner.markor.frontend.textview; -import android.animation.ObjectAnimator; import android.content.res.Resources; import android.graphics.Rect; -import android.os.Build; import android.os.Handler; import android.os.Looper; import android.text.Editable; @@ -22,7 +20,6 @@ import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.View; -import android.view.WindowInsets; import android.widget.EditText; import android.widget.TextView; @@ -725,12 +722,4 @@ public static boolean isViewVisible(final View view) { final Rect screen = new Rect(0, 0, metrics.widthPixels, metrics.heightPixels); return isGlobalVisible && Rect.intersects(actualPosition, screen); } - - // Check if keyboard open. Only available after android 11 :( - public static Boolean isImeOpen(final View view) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - return view.getRootWindowInsets().isVisible(WindowInsets.Type.ime()); - } - return null; // Uncertain - } } diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index d5bb4a393..12ac6a1ba 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -145,7 +145,7 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { _searchEdit.setTextColor(rcolor(_dopt.primaryTextColor)); _searchEdit.setHintTextColor(rcolor(_dopt.secondaryTextColor)); _searchEdit.setOnFocusChangeListener((v, isFocussed) -> { - GsContextUtils.instance.showSoftKeyboard(getActivity(), isFocussed, _searchEdit); + GsContextUtils.instance.showIme(getActivity(), isFocussed, _searchEdit); }); root.setBackgroundColor(rcolor(_dopt.backgroundColor)); @@ -210,7 +210,7 @@ public void onClicked(View view) { @Override public void onDismiss(final DialogInterface dialog) { super.onDismiss(dialog); - GsContextUtils.instance.showSoftKeyboard(getActivity(), false, _searchEdit); + GsContextUtils.instance.showIme(getActivity(), false, _searchEdit); } private void showNewDirDialog() { diff --git a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java index 354693df3..261ac970b 100644 --- a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java @@ -88,6 +88,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.Window; +import android.view.WindowInsets; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.webkit.MimeTypeMap; @@ -149,7 +150,6 @@ import java.util.Calendar; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Random; @@ -2499,7 +2499,16 @@ public void showSnackBar(final Activity context, @StringRes int stringResId, boo .show(); } - public T showSoftKeyboard(final Activity activity, final Boolean show, final View... view) { + + // Check if keyboard open. Only available after android 11 :( + public static Boolean isImeOpen(final View view) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + return view.getRootWindowInsets().isVisible(WindowInsets.Type.ime()); + } + return null; // Uncertain + } + + public T showIme(final Activity activity, final Boolean show, final View... view) { if (activity != null && show != null) { final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); final View focus = (view != null && view.length > 0) ? view[0] : activity.getCurrentFocus();