diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-01-12 22:14:02 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-01-12 22:14:02 +0000 |
commit | f8eb6798d116165971702a698b3e3e6c495abec6 (patch) | |
tree | c25ff019bf3b4ce6eb7b37483bde4bc6c63876a5 /java/com/android/dialer/main/impl/MainActivity.java | |
parent | 7a8b1fce120c8b85c2acf07bf4e5decbc25617e6 (diff) | |
parent | 4d881e4b22e61913bd2439fba6901bf6cc0e98c5 (diff) |
Merge "Added Dialpad to NUI."
Diffstat (limited to 'java/com/android/dialer/main/impl/MainActivity.java')
-rw-r--r-- | java/com/android/dialer/main/impl/MainActivity.java | 172 |
1 files changed, 161 insertions, 11 deletions
diff --git a/java/com/android/dialer/main/impl/MainActivity.java b/java/com/android/dialer/main/impl/MainActivity.java index fc7e670b0..8bdb295c7 100644 --- a/java/com/android/dialer/main/impl/MainActivity.java +++ b/java/com/android/dialer/main/impl/MainActivity.java @@ -21,24 +21,35 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract.QuickContact; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; -import android.view.View; +import android.text.TextUtils; +import android.view.animation.Animation; +import android.view.animation.Animation.AnimationListener; import android.widget.ImageView; import com.android.dialer.calllog.ui.NewCallLogFragment; +import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.contactsfragment.ContactsFragment; import com.android.dialer.contactsfragment.ContactsFragment.Header; import com.android.dialer.contactsfragment.ContactsFragment.OnContactSelectedListener; +import com.android.dialer.dialpadview.DialpadFragment; +import com.android.dialer.dialpadview.DialpadFragment.DialpadListener; +import com.android.dialer.dialpadview.DialpadFragment.LastOutgoingCallCallback; +import com.android.dialer.dialpadview.DialpadFragment.OnDialpadQueryChangedListener; import com.android.dialer.main.impl.BottomNavBar.OnBottomNavTabSelectedListener; import com.android.dialer.main.impl.toolbar.MainToolbar; import com.android.dialer.main.impl.toolbar.SearchBarListener; +import com.android.dialer.searchfragment.list.NewSearchFragment; import com.android.dialer.speeddial.SpeedDialFragment; import com.android.dialer.voicemail.listui.NewVoicemailFragment; /** This is the main activity for dialer. It hosts favorites, call log, search, dialpad, etc... */ public final class MainActivity extends AppCompatActivity - implements View.OnClickListener, OnContactSelectedListener { + implements OnContactSelectedListener, OnDialpadQueryChangedListener, DialpadListener { + + private SearchController searchController; /** * @param context Context of the application package implementing MainActivity class. @@ -59,29 +70,168 @@ public final class MainActivity extends AppCompatActivity } private void initLayout() { - findViewById(R.id.fab).setOnClickListener(this); + FloatingActionButton fab = findViewById(R.id.fab); + fab.setOnClickListener(v -> searchController.showDialpad(true)); + MainToolbar toolbar = findViewById(R.id.toolbar); toolbar.setSearchBarListener(new MainSearchBarListener()); - setSupportActionBar(toolbar); + searchController = new SearchController(fab, 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); } @Override - public void onClick(View v) { - if (v.getId() == R.id.fab) { - // open dialpad search - } - } - - @Override public void onContactSelected(ImageView photo, Uri contactUri, long contactId) { // TODO(calderwoodra): Add impression logging QuickContact.showQuickContact( this, photo, contactUri, QuickContact.MODE_LARGE, null /* excludeMimes */); } + @Override // OnDialpadQueryChangedListener + public void onDialpadQueryChanged(String query) { + // TODO(calderwoodra): update search fragment + } + + @Override // DialpadListener + public void getLastOutgoingCall(LastOutgoingCallCallback callback) { + // TODO(calderwoodra): migrate CallLogAsync class outside of dialer/app and call it here. + } + + @Override // DialpadListener + public void onDialpadShown() { + searchController.getDialpadFragment().slideUp(true); + } + + @Override // DialpadListener + public void onCallPlacedFromDialpad() { + // TODO(calderwoodra): logging + } + + @Override + public void onBackPressed() { + if (searchController.onBackPressed()) { + return; + } + super.onBackPressed(); + } + + /** Search controller for handling all the logic related to hiding/showing search and dialpad. */ + private final class SearchController { + + private static final String DIALPAD_FRAGMENT_TAG = "dialpad_fragment_tag"; + private static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag"; + + private final FloatingActionButton fab; + private final MainToolbar toolbar; + + private boolean isDialpadVisible; + private boolean isSearchVisible; + + private SearchController(FloatingActionButton fab, MainToolbar toolbar) { + this.fab = fab; + this.toolbar = toolbar; + } + + /** Shows the dialpad, hides the FAB and slides the toolbar off screen. */ + public void showDialpad(boolean animate) { + Assert.checkArgument(!isDialpadVisible); + isDialpadVisible = true; + isSearchVisible = true; + + fab.hide(); + toolbar.slideUp(animate); + setTitle(R.string.dialpad_activity_title); + + android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction(); + + // Show Search + if (getSearchFragment() == null) { + NewSearchFragment searchFragment = NewSearchFragment.newInstance(false); + transaction.add(R.id.search_fragment_container, searchFragment, SEARCH_FRAGMENT_TAG); + } else if (!isSearchVisible) { + transaction.show(getSearchFragment()); + } + + // Show Dialpad + if (getDialpadFragment() == null) { + DialpadFragment dialpadFragment = new DialpadFragment(); + transaction.add(R.id.search_fragment_container, dialpadFragment, DIALPAD_FRAGMENT_TAG); + } else { + DialpadFragment dialpadFragment = getDialpadFragment(); + transaction.show(dialpadFragment); + } + transaction.commit(); + } + + /** Hides the dialpad, reveals the FAB and slides the toolbar back onto the screen. */ + public void hideDialpad(boolean animate) { + Assert.checkArgument(isDialpadVisible); + isDialpadVisible = false; + + fab.show(); + toolbar.slideDown(animate); + setTitle(R.string.main_activity_label); + + DialpadFragment dialpadFragment = getDialpadFragment(); + dialpadFragment.setAnimate(animate); + dialpadFragment.slideDown( + animate, + new AnimationListener() { + @Override + public void onAnimationStart(Animation animation) {} + + @Override + public void onAnimationEnd(Animation animation) { + if (!(isFinishing() || isDestroyed())) { + getFragmentManager().beginTransaction().remove(dialpadFragment).commit(); + } + } + + @Override + public void onAnimationRepeat(Animation animation) {} + }); + } + + /** + * Should be called when the user presses the back button. + * + * @return true if {@link #onBackPressed()} handled to action. + */ + public boolean onBackPressed() { + if (isDialpadVisible && !TextUtils.isEmpty(getDialpadFragment().getQuery())) { + hideDialpad(true); + return true; + } else if (isSearchVisible) { + closeSearch(true); + return true; + } else { + return false; + } + } + + /** Calls {@link #hideDialpad(boolean)} and removes the search fragment. */ + private void closeSearch(boolean animate) { + Assert.checkArgument(isSearchVisible); + if (isDialpadVisible) { + hideDialpad(animate); + } + getFragmentManager().beginTransaction().remove(getSearchFragment()).commit(); + isSearchVisible = false; + } + + private DialpadFragment getDialpadFragment() { + return (DialpadFragment) getFragmentManager().findFragmentByTag(DIALPAD_FRAGMENT_TAG); + } + + private NewSearchFragment getSearchFragment() { + return (NewSearchFragment) getFragmentManager().findFragmentByTag(SEARCH_FRAGMENT_TAG); + } + } + /** * Implementation of {@link SearchBarListener} that holds the logic for how to handle search bar * events. |