diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/InputAwareLayout.java b/app/src/main/java/org/thoughtcrime/securesms/components/InputAwareLayout.java index dae12efa93..d4154c0a51 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/InputAwareLayout.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/InputAwareLayout.java @@ -1,6 +1,8 @@ package org.thoughtcrime.securesms.components; import android.content.Context; +import android.os.Build; +import android.text.InputType; import android.util.AttributeSet; import android.widget.EditText; @@ -12,6 +14,7 @@ import org.thoughtcrime.securesms.util.ServiceUtil; public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKeyboardShownListener { private InputView current; + private int previousInputType = InputType.TYPE_NULL; public InputAwareLayout(Context context) { this(context, null); @@ -44,6 +47,8 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey input.show(getKeyboardHeight(), current != null); current = input; } + + setShowSoftInputOnFocusCompat(imeTarget, false); } public InputView getCurrentInput() { @@ -53,6 +58,8 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey public void hideCurrentInput(EditText imeTarget) { if (isKeyboardOpen()) hideSoftkey(imeTarget, null); else hideAttachedInput(false); + + setShowSoftInputOnFocusCompat(imeTarget, true); } public void hideAttachedInput(boolean instant) { @@ -65,6 +72,13 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey } public void showSoftkey(final EditText inputTarget) { + showSoftkey(inputTarget, false); + } + + public void showSoftkey(final EditText inputTarget, boolean force) { + if (!force && isInputOpen()) return; + + setShowSoftInputOnFocusCompat(inputTarget, true); postOnKeyboardOpen(new Runnable() { @Override public void run() { hideAttachedInput(true); @@ -85,6 +99,20 @@ public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKey .hideSoftInputFromWindow(inputTarget.getWindowToken(), 0); } + private void setShowSoftInputOnFocusCompat(EditText imeTarget, boolean show) { + if (Build.VERSION.SDK_INT >= 21) { + imeTarget.setShowSoftInputOnFocus(show); + } else if (show) { + if (previousInputType != InputType.TYPE_NULL) { + imeTarget.setInputType(previousInputType); + } + } else { + previousInputType = imeTarget.getInputType(); + imeTarget.setRawInputType(InputType.TYPE_CLASS_TEXT); + imeTarget.setTextIsSelectable(true); + } + } + public interface InputView { void show(int height, boolean immediate); void hide(boolean immediate); diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationParentFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationParentFragment.java index 148b6b1f4c..1b571989e8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationParentFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationParentFragment.java @@ -3273,7 +3273,7 @@ public class ConversationParentFragment extends Fragment emojiDrawerStub.get().setFragmentManager(getChildFragmentManager()); if (container.getCurrentInput() == emojiDrawerStub.get()) { - container.showSoftkey(composeText); + container.showSoftkey(composeText, true); } else { container.show(composeText, emojiDrawerStub.get()); }