Improved show/hide keyboard

pull/198/head
M66B 4 years ago
parent ee12d06469
commit 62cc21464b

@ -89,7 +89,6 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.view.textclassifier.ConversationAction;
import android.view.textclassifier.ConversationActions;
import android.webkit.WebSettings;
@ -4725,10 +4724,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
});
pw.showAtLocation(parentFragment.getView(), Gravity.TOP | Gravity.END, 0, 0);
etSearch.requestFocus();
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Helper.showKeyboard(etSearch);
}
private int find(String query, int result) {
@ -6469,7 +6465,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final Context context = getContext();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
final Integer color = (TextUtils.isEmpty(notes)
? prefs.getInt("note_color", Color.TRANSPARENT)
@ -6483,15 +6478,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
btnColor.setColor(color);
etNotes.selectAll();
etNotes.requestFocus();
if (imm != null)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Helper.showKeyboard(etNotes);
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (imm != null)
imm.hideSoftInputFromWindow(etNotes.getWindowToken(), 0);
Helper.hideKeyboard(etNotes);
Bundle args = new Bundle();
args.putInt("color", btnColor.getColor());
@ -6649,15 +6641,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final long id = getArguments().getLong("id");
final Context context = getContext();
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
View view = LayoutInflater.from(context).inflate(R.layout.dialog_keyword_add, null);
final EditText etKeyword = view.findViewById(R.id.etKeyword);
etKeyword.setText(null);
etKeyword.requestFocus();
if (imm != null)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Helper.showKeyboard(etKeyword);
return new AlertDialog.Builder(context)
.setView(view)

@ -33,7 +33,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
@ -113,12 +112,10 @@ public class FragmentDialogSearch extends FragmentDialogBase {
final TextView tvAfter = dview.findViewById(R.id.tvAfter);
final Group grpMore = dview.findViewById(R.id.grpMore);
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
ibInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imm.hideSoftInputFromWindow(etQuery.getWindowToken(), 0);
Helper.hideKeyboard(etQuery);
Helper.viewFAQ(v.getContext(), 13);
}
});
@ -195,7 +192,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
View.OnClickListener onMore = new View.OnClickListener() {
@Override
public void onClick(View v) {
imm.hideSoftInputFromWindow(etQuery.getWindowToken(), 0);
Helper.hideKeyboard(etQuery);
if (grpMore.getVisibility() == View.VISIBLE) {
ibMore.setImageLevel(1);
@ -326,9 +323,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
cbHeaders.setVisibility(View.GONE);
cbHtml.setVisibility(View.GONE);
etQuery.requestFocus();
if (imm != null)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Helper.showKeyboard(etQuery);
final AlertDialog dialog = new AlertDialog.Builder(context)
.setView(dview)
@ -390,7 +385,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
if (before != null)
criteria.before = ((Calendar) before).getTimeInMillis();
imm.hideSoftInputFromWindow(etQuery.getWindowToken(), 0);
Helper.hideKeyboard(etQuery);
if (criteria.query != null && criteria.query.startsWith("raw:"))
new SimpleTask<EntityFolder>() {

@ -64,6 +64,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.MimeTypeMap;
import android.webkit.WebView;
import android.widget.Button;
@ -923,6 +924,43 @@ public class Helper {
return color;
}
static void showKeyboard(final View view) {
final InputMethodManager imm =
(InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null)
return;
if (view.hasFocus())
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
final View.OnFocusChangeListener listener = view.getOnFocusChangeListener();
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (listener != null)
listener.onFocusChange(v, hasFocus);
if (hasFocus)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
else
imm.toggleSoftInput(0, 0);
}
});
if (!view.hasFocus())
view.requestFocus();
}
static void hideKeyboard(final View view) {
InputMethodManager imm =
(InputMethodManager) view.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (imm == null)
return;
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
// Formatting
private static final DecimalFormat df = new DecimalFormat("@@");

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
@ -48,7 +47,6 @@ import android.util.Pair;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import androidx.appcompat.widget.PopupMenu;
@ -180,9 +178,7 @@ public class StyleHelper {
}
private boolean setColor(MenuItem item) {
InputMethodManager imm = (InputMethodManager) etBody.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (imm != null)
imm.hideSoftInputFromWindow(etBody.getWindowToken(), 0);
Helper.hideKeyboard(etBody);
Context context = etBody.getContext();
int editTextColor = Helper.resolveColor(context, android.R.attr.editTextColor);

Loading…
Cancel
Save