Open keyboard when we open contact selection from blocked preference.

This commit is contained in:
Alex Hart 2020-11-12 13:39:38 -04:00 committed by GitHub
parent 2dace38d43
commit 06aada20c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 1 deletions

View file

@ -65,6 +65,10 @@ public class BlockedUsersActivity extends PassphraseRequiredActivity implements
//noinspection CodeBlock2Expr //noinspection CodeBlock2Expr
getSupportFragmentManager().addOnBackStackChangedListener(() -> { getSupportFragmentManager().addOnBackStackChangedListener(() -> {
viewSwitcher.setDisplayedChild(getSupportFragmentManager().getBackStackEntryCount()); viewSwitcher.setDisplayedChild(getSupportFragmentManager().getBackStackEntryCount());
if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
contactFilterToolbar.focusAndShowKeyboard();
}
}); });
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()

View file

@ -19,6 +19,7 @@ import androidx.core.widget.TextViewCompat;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.views.DarkOverflowToolbar; import org.thoughtcrime.securesms.util.views.DarkOverflowToolbar;
public final class ContactFilterToolbar extends DarkOverflowToolbar { public final class ContactFilterToolbar extends DarkOverflowToolbar {
@ -125,6 +126,10 @@ public final class ContactFilterToolbar extends DarkOverflowToolbar {
attributes.recycle(); attributes.recycle();
} }
public void focusAndShowKeyboard() {
ViewUtil.focusAndShowKeyboard(searchText);
}
public void clear() { public void clear() {
searchText.setText(""); searchText.setText("");
notifyListener(); notifyListener();

View file

@ -27,6 +27,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewStub; import android.view.ViewStub;
import android.view.ViewTreeObserver;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -51,6 +52,32 @@ public final class ViewUtil {
private ViewUtil() { private ViewUtil() {
} }
public static void focusAndShowKeyboard(@NonNull View view) {
view.requestFocus();
if (view.hasWindowFocus()) {
showTheKeyboardNow(view);
} else {
view.getViewTreeObserver().addOnWindowFocusChangeListener(new ViewTreeObserver.OnWindowFocusChangeListener() {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
showTheKeyboardNow(view);
view.getViewTreeObserver().removeOnWindowFocusChangeListener(this);
}
}
});
}
}
private static void showTheKeyboardNow(@NonNull View view) {
if (view.isFocused()) {
view.post(() -> {
InputMethodManager inputMethodManager = ServiceUtil.getInputMethodManager(view.getContext());
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
});
}
}
public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) { public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
v.setBackground(drawable); v.setBackground(drawable);
} }

View file

@ -49,7 +49,7 @@
android:layout_marginTop="29dp" android:layout_marginTop="29dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:text="@string/BlockedUsersActivity__blocked_users" android:text="@string/BlockedUsersActivity__blocked_users"
android:textAppearance="@style/TextAppearance.Signal.Subtitle" android:textAppearance="@style/TextAppearance.Signal.Body2.Bold"
android:textColor="?colorAccent" android:textColor="?colorAccent"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"