From 23ef36ff6dfd2fdb47f6ec8bb6928e4e40e11fa5 Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Fri, 6 Apr 2018 12:29:17 -0700 Subject: Only request focus on search edit text when it's slide down. Bug: 77586391 Test: manual PiperOrigin-RevId: 191924178 Change-Id: I792a6f0308f0dde9b4ae82227aa6a8327208a192 --- .../android/dialer/main/impl/MainSearchController.java | 15 +++++++++------ .../android/dialer/main/impl/toolbar/MainToolbar.java | 6 +++--- .../android/dialer/main/impl/toolbar/SearchBarView.java | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 13 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/main/impl/MainSearchController.java b/java/com/android/dialer/main/impl/MainSearchController.java index b04e7b11b..dbeed0d69 100644 --- a/java/com/android/dialer/main/impl/MainSearchController.java +++ b/java/com/android/dialer/main/impl/MainSearchController.java @@ -140,7 +140,7 @@ public class MainSearchController implements SearchBarListener { fab.hide(); toolbar.slideUp(animate, fragmentContainer); - toolbar.expand(animate, Optional.absent()); + toolbar.expand(animate, Optional.absent(), /* requestFocus */ false); toolbarShadow.setVisibility(View.VISIBLE); activity.setTitle(R.string.dialpad_activity_title); @@ -390,7 +390,7 @@ public class MainSearchController implements SearchBarListener { Logger.get(activity).logScreenView(ScreenEvent.Type.MAIN_SEARCH, activity); fab.hide(); - toolbar.expand(/* animate=*/ true, query); + toolbar.expand(/* animate=*/ true, query, /* requestFocus */ true); toolbar.showKeyboard(); toolbarShadow.setVisibility(View.VISIBLE); hideBottomNav(); @@ -528,12 +528,15 @@ public class MainSearchController implements SearchBarListener { if (savedInstanceState.getBoolean(KEY_IS_FAB_HIDDEN, false)) { fab.hide(); } - if (savedInstanceState.getBoolean(KEY_IS_TOOLBAR_EXPANDED, false)) { - toolbar.expand(false, Optional.absent()); - } - if (savedInstanceState.getBoolean(KEY_IS_TOOLBAR_SLIDE_UP, false)) { + boolean isSlideUp = savedInstanceState.getBoolean(KEY_IS_TOOLBAR_SLIDE_UP, false); + if (isSlideUp) { toolbar.slideUp(false, fragmentContainer); } + if (savedInstanceState.getBoolean(KEY_IS_TOOLBAR_EXPANDED, false)) { + // If the toolbar is slide up, that means the dialpad is showing. Thus we don't want to + // request focus or we'll break physical/bluetooth keyboards typing. + toolbar.expand(/* animate */ false, Optional.absent(), /* requestFocus */ !isSlideUp); + } } public void addOnSearchShowListener(OnSearchShowListener listener) { diff --git a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java index 68876dde5..5e5db2c8c 100644 --- a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java +++ b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java @@ -113,9 +113,9 @@ public final class MainToolbar extends Toolbar implements PopupMenu.OnMenuItemCl searchBar.collapse(animate); } - /** @see SearchBarView#collapse(boolean) */ - public void expand(boolean animate, Optional text) { - searchBar.expand(animate, text); + /** @see SearchBarView#expand(boolean, Optional, boolean) */ + public void expand(boolean animate, Optional text, boolean requestFocus) { + searchBar.expand(animate, text, requestFocus); } public boolean isSlideUp() { diff --git a/java/com/android/dialer/main/impl/toolbar/SearchBarView.java b/java/com/android/dialer/main/impl/toolbar/SearchBarView.java index 0cc76598c..8ea94299e 100644 --- a/java/com/android/dialer/main/impl/toolbar/SearchBarView.java +++ b/java/com/android/dialer/main/impl/toolbar/SearchBarView.java @@ -101,13 +101,17 @@ final class SearchBarView extends FrameLayout { listener.onVoiceButtonClicked( result -> { if (!TextUtils.isEmpty(result)) { - expand(true, Optional.of(result)); + expand(/* animate */ true, Optional.of(result), /* requestFocus */ true); } }); } - /** Expand the search bar and populate it with text if any exists. */ - /* package-private */ void expand(boolean animate, Optional text) { + /** + * Expand the search bar and populate it with text if any exists. + * + * @param requestFocus should be false if showing the dialpad + */ + /* package-private */ void expand(boolean animate, Optional text, boolean requestFocus) { if (isExpanded) { return; } @@ -133,7 +137,11 @@ final class SearchBarView extends FrameLayout { if (text.isPresent()) { searchBox.setText(text.get()); } - searchBox.requestFocus(); + // Don't request focus unless we're actually showing the search box, otherwise + // physical/bluetooth keyboards will type into this box when the dialpad is open. + if (requestFocus) { + searchBox.requestFocus(); + } setBackgroundResource(R.drawable.search_bar_background); } }); -- cgit v1.2.3