diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-01-19 02:32:58 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-01-19 02:32:58 +0000 |
commit | e7194f7204e0b694106fcaa3cb9d3d3171c92858 (patch) | |
tree | 2b045b00d3e609a80196b2a10b829305d6dacbeb /java/com/android/dialer/main | |
parent | 8c3420c5f10bcde9475835d8e93aa2b6cb5a9d17 (diff) | |
parent | 5d272d8c24b2719cacd4940d418efb3559a1fb09 (diff) |
Merge changes I59b5f641,If438f1b7
* changes:
Search, Dialpad, BottomBar and Toolbar now persist state through rotation.
Descrease bubble bottom text scaling factor.
Diffstat (limited to 'java/com/android/dialer/main')
5 files changed, 63 insertions, 22 deletions
diff --git a/java/com/android/dialer/main/impl/BottomNavBar.java b/java/com/android/dialer/main/impl/BottomNavBar.java index 9aaa988e8..66a57becd 100644 --- a/java/com/android/dialer/main/impl/BottomNavBar.java +++ b/java/com/android/dialer/main/impl/BottomNavBar.java @@ -48,6 +48,7 @@ final class BottomNavBar extends LinearLayout { private BottomNavItem contacts; private BottomNavItem voicemail; private OnBottomNavTabSelectedListener listener; + private @TabIndex int selectedTab; public BottomNavBar(Context context, @Nullable AttributeSet attrs) { super(context, attrs); @@ -68,21 +69,25 @@ final class BottomNavBar extends LinearLayout { speedDial.setOnClickListener( v -> { + selectedTab = TabIndex.SPEED_DIAL; setSelected(speedDial); listener.onSpeedDialSelected(); }); callLog.setOnClickListener( v -> { + selectedTab = TabIndex.HISTORY; setSelected(callLog); listener.onCallLogSelected(); }); contacts.setOnClickListener( v -> { + selectedTab = TabIndex.CONTACTS; setSelected(contacts); listener.onContactsSelected(); }); voicemail.setOnClickListener( v -> { + selectedTab = TabIndex.VOICEMAIL; setSelected(voicemail); listener.onVoicemailSelected(); }); @@ -118,6 +123,10 @@ final class BottomNavBar extends LinearLayout { this.listener = listener; } + public int getSelectedTab() { + return selectedTab; + } + /** Listener for bottom nav tab's on click events. */ public interface OnBottomNavTabSelectedListener { diff --git a/java/com/android/dialer/main/impl/MainActivity.java b/java/com/android/dialer/main/impl/MainActivity.java index 7aae8cb7d..168589f13 100644 --- a/java/com/android/dialer/main/impl/MainActivity.java +++ b/java/com/android/dialer/main/impl/MainActivity.java @@ -51,11 +51,9 @@ public final class MainActivity extends AppCompatActivity DialpadFragment.HostInterface, SearchFragmentListener { - private static final String IS_FAB_HIDDEN_KEY = "is_fab_hidden"; private static final String KEY_SAVED_LANGUAGE_CODE = "saved_language_code"; private MainSearchController searchController; - private FloatingActionButton fab; /** Language the device was in last time {@link #onSaveInstanceState(Bundle)} was called. */ private String savedLanguageCode; @@ -75,24 +73,31 @@ public final class MainActivity extends AppCompatActivity super.onCreate(savedInstanceState); LogUtil.enterBlock("MainActivity.onCreate"); setContentView(R.layout.main_activity); - initLayout(); + initLayout(savedInstanceState); SmartDialPrefix.initializeNanpSettings(this); } - private void initLayout() { - fab = findViewById(R.id.fab); + private void initLayout(Bundle savedInstanceState) { + FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(v -> searchController.showDialpad(true)); MainToolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(findViewById(R.id.toolbar)); - BottomNavBar navBar = findViewById(R.id.bottom_nav_bar); - navBar.setOnTabSelectedListener(new MainBottomNavBarBottomNavTabListener()); - // TODO(calderwoodra): Implement last tab - navBar.selectTab(BottomNavBar.TabIndex.SPEED_DIAL); + BottomNavBar bottomNav = findViewById(R.id.bottom_nav_bar); + bottomNav.setOnTabSelectedListener(new MainBottomNavBarBottomNavTabListener()); - searchController = new MainSearchController(this, navBar, fab, toolbar); + searchController = new MainSearchController(this, bottomNav, fab, toolbar); toolbar.setSearchBarListener(searchController); + + // Restore our view state if needed, else initialize as if the app opened for the first time + if (savedInstanceState != null) { + savedLanguageCode = savedInstanceState.getString(KEY_SAVED_LANGUAGE_CODE); + searchController.onRestoreInstanceState(savedInstanceState); + } else { + // TODO(calderwoodra): Implement last tab + bottomNav.selectTab(BottomNavBar.TabIndex.SPEED_DIAL); + } } @Override @@ -107,17 +112,8 @@ public final class MainActivity extends AppCompatActivity @Override protected void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(bundle); - bundle.putBoolean(IS_FAB_HIDDEN_KEY, !fab.isShown()); bundle.putString(KEY_SAVED_LANGUAGE_CODE, CompatUtils.getLocale(this).getISO3Language()); - } - - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - if (savedInstanceState.getBoolean(IS_FAB_HIDDEN_KEY, false)) { - fab.hide(); - } - savedLanguageCode = savedInstanceState.getString(KEY_SAVED_LANGUAGE_CODE); + searchController.onSaveInstanceState(bundle); } @Override diff --git a/java/com/android/dialer/main/impl/MainSearchController.java b/java/com/android/dialer/main/impl/MainSearchController.java index 76c93bb87..041e32ed7 100644 --- a/java/com/android/dialer/main/impl/MainSearchController.java +++ b/java/com/android/dialer/main/impl/MainSearchController.java @@ -17,6 +17,7 @@ package com.android.dialer.main.impl; import android.app.FragmentTransaction; +import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.text.TextUtils; @@ -52,6 +53,12 @@ import com.google.common.base.Optional; */ final class MainSearchController implements SearchBarListener { + private static final String KEY_IS_FAB_HIDDEN = "is_fab_hidden"; + private static final String KEY_CURRENT_TAB = "current_tab"; + private static final String KEY_BOTTOM_NAV_VISIBILITY = "bottom_nav_visibility"; + private static final String KEY_IS_TOOLBAR_EXPANDED = "is_toolbar_expanded"; + private static final String KEY_IS_TOOLBAR_SLIDE_UP = "is_toolbar_slide_up"; + private static final String DIALPAD_FRAGMENT_TAG = "dialpad_fragment_tag"; private static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag"; @@ -155,6 +162,7 @@ final class MainSearchController implements SearchBarListener { /** Should be called when {@link DialpadListener#onDialpadShown()} is called. */ public void onDialpadShown() { getDialpadFragment().slideUp(true); + hideBottomNav(); } /** @@ -293,4 +301,26 @@ final class MainSearchController implements SearchBarListener { @Override public void sendFeedback() {} + + public void onSaveInstanceState(Bundle bundle) { + bundle.putBoolean(KEY_IS_FAB_HIDDEN, !fab.isShown()); + bundle.putInt(KEY_CURRENT_TAB, bottomNav.getSelectedTab()); + bundle.putInt(KEY_BOTTOM_NAV_VISIBILITY, bottomNav.getVisibility()); + bundle.putBoolean(KEY_IS_TOOLBAR_EXPANDED, toolbar.isExpanded()); + bundle.putBoolean(KEY_IS_TOOLBAR_SLIDE_UP, toolbar.isSlideUp()); + } + + public void onRestoreInstanceState(Bundle savedInstanceState) { + bottomNav.selectTab(savedInstanceState.getInt(KEY_CURRENT_TAB)); + bottomNav.setVisibility(savedInstanceState.getInt(KEY_BOTTOM_NAV_VISIBILITY)); + 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)) { + toolbar.slideUp(false); + } + } } diff --git a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java index 6e38d2e64..1d7f7ce20 100644 --- a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java +++ b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java @@ -17,7 +17,6 @@ package com.android.dialer.main.impl.toolbar; import android.content.Context; -import android.support.annotation.VisibleForTesting; import android.support.v7.widget.PopupMenu.OnMenuItemClickListener; import android.support.v7.widget.Toolbar; import android.util.AttributeSet; @@ -107,11 +106,14 @@ public final class MainToolbar extends Toolbar implements OnMenuItemClickListene searchBar.expand(animate, text); } - @VisibleForTesting public boolean isSlideUp() { return isSlideUp; } + public boolean isExpanded() { + return searchBar.isExpanded(); + } + public String getQuery() { return searchBar.getQuery(); } diff --git a/java/com/android/dialer/main/impl/toolbar/SearchBarView.java b/java/com/android/dialer/main/impl/toolbar/SearchBarView.java index 6b9f39dc9..c84b8fc72 100644 --- a/java/com/android/dialer/main/impl/toolbar/SearchBarView.java +++ b/java/com/android/dialer/main/impl/toolbar/SearchBarView.java @@ -185,6 +185,10 @@ final class SearchBarView extends FrameLayout { return searchBox.getText().toString(); } + public boolean isExpanded() { + return isExpanded; + } + public void setQueryWithoutUpdate(String query) { skipLatestTextChange = true; searchBox.setText(query); |