From 75d5b2d7d73e184ed813cc5b42b19d7e21b6bd8c Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 19 Jun 2015 16:53:54 -0700 Subject: Add extra to jump to DialtactsActivity tab. + For the voicemail notification, jump to voicemail tab. + Jump through some hoops to handle this properly when waiting for the voicemail status to be retrieved. Bug: 21120186 Change-Id: I5a82f3ecafadb45246e6637e8275a09f78cc188a --- src/com/android/dialer/DialtactsActivity.java | 7 +++++ .../dialer/calllog/DefaultVoicemailNotifier.java | 10 ++++--- src/com/android/dialer/list/ListsFragment.java | 33 +++++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index fc0f1fb24..b77e910b2 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -133,6 +133,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. */ private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; + public static final String EXTRA_SHOW_TAB = "EXTRA_SHOW_TAB"; private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; @@ -539,6 +540,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } mIsRestarting = false; } + prepareVoiceSearchButton(); mDialerDatabaseHelper.startSmartDialUpdateThread(); mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); @@ -903,6 +905,11 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mStateSaved = false; displayFragment(newIntent); + if (newIntent.hasExtra(EXTRA_SHOW_TAB)) { + mListsFragment.showTab( + getIntent().getIntExtra(EXTRA_SHOW_TAB, mListsFragment.TAB_INDEX_SPEED_DIAL)); + } + invalidateOptionsMenu(); } diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java index 3c9fa1d73..d43238a14 100644 --- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java +++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java @@ -32,8 +32,10 @@ import android.text.TextUtils; import android.util.Log; import com.android.common.io.MoreCloseables; +import com.android.dialer.DialtactsActivity; import com.android.dialer.R; import com.android.dialer.calllog.PhoneAccountUtils; +import com.android.dialer.list.ListsFragment; import com.google.common.collect.Maps; import java.util.Map; @@ -172,10 +174,10 @@ public class DefaultVoicemailNotifier { final Intent contentIntent; // Open the call log. // TODO: Send to recents tab in Dialer instead. - contentIntent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI); - contentIntent.putExtra(Calls.EXTRA_CALL_TYPE_FILTER, Calls.VOICEMAIL_TYPE); - notificationBuilder.setContentIntent( - PendingIntent.getActivity(mContext, 0, contentIntent, 0)); + contentIntent = new Intent(mContext, DialtactsActivity.class); + contentIntent.putExtra(DialtactsActivity.EXTRA_SHOW_TAB, ListsFragment.TAB_INDEX_VOICEMAIL); + notificationBuilder.setContentIntent(PendingIntent.getActivity( + mContext, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // The text to show in the ticker, describing the new event. if (callToNotify != null) { diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 0e3df5284..e45da0ce0 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -84,6 +84,8 @@ public class ListsFragment extends Fragment private SharedPreferences mPrefs; private boolean mHasActiveVoicemailProvider; + private boolean mHasFetchedVoicemailStatus; + private boolean mShowVoicemailTabAfterVoicemailStatusIsFetched; private VoicemailStatusHelper mVoicemailStatusHelper; private ArrayList mOnPageChangeListeners = @@ -167,6 +169,7 @@ public class ListsFragment extends Fragment Trace.endSection(); mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); + mHasFetchedVoicemailStatus = false; mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mHasActiveVoicemailProvider = mPrefs.getBoolean( @@ -204,7 +207,7 @@ public class ListsFragment extends Fragment mViewPager.setAdapter(mViewPagerAdapter); mViewPager.setOffscreenPageLimit(TAB_COUNT_WITH_VOICEMAIL - 1); mViewPager.setOnPageChangeListener(this); - mViewPager.setCurrentItem(getRtlPosition(TAB_INDEX_SPEED_DIAL)); + showTab(TAB_INDEX_SPEED_DIAL); mTabTitles = new String[TAB_COUNT_WITH_VOICEMAIL]; mTabTitles[TAB_INDEX_SPEED_DIAL] = getResources().getString(R.string.tab_speed_dial); @@ -237,6 +240,24 @@ public class ListsFragment extends Fragment } } + /** + * Shows the tab with the specified index. If the voicemail tab index is specified, but the + * voicemail status hasn't been fetched, it will try to show the tab after the voicemail status + * has been fetched. + */ + public void showTab(int index) { + if (index == TAB_INDEX_VOICEMAIL) { + if (mHasActiveVoicemailProvider) { + mViewPager.setCurrentItem(getRtlPosition(TAB_INDEX_VOICEMAIL)); + } else if (!mHasFetchedVoicemailStatus) { + // Try to show the voicemail tab after the voicemail status returns. + mShowVoicemailTabAfterVoicemailStatusIsFetched = true; + } + } else { + mViewPager.setCurrentItem(getRtlPosition(index)); + } + } + @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { mTabIndex = getRtlPosition(position); @@ -252,6 +273,9 @@ public class ListsFragment extends Fragment public void onPageSelected(int position) { mTabIndex = getRtlPosition(position); + // Show the tab which has been selected instead. + mShowVoicemailTabAfterVoicemailStatusIsFetched = false; + final int count = mOnPageChangeListeners.size(); for (int i = 0; i < count; i++) { mOnPageChangeListeners.get(i).onPageSelected(position); @@ -269,6 +293,8 @@ public class ListsFragment extends Fragment @Override public void onVoicemailStatusFetched(Cursor statusCursor) { + mHasFetchedVoicemailStatus = true; + if (getActivity() == null || getActivity().isFinishing()) { return; } @@ -285,6 +311,11 @@ public class ListsFragment extends Fragment .putBoolean(PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, hasActiveVoicemailProvider) .commit(); } + + if (mHasActiveVoicemailProvider && mShowVoicemailTabAfterVoicemailStatusIsFetched) { + mShowVoicemailTabAfterVoicemailStatusIsFetched = false; + showTab(TAB_INDEX_VOICEMAIL); + } } @Override -- cgit v1.2.3