diff options
author | Andrew Lee <anwlee@google.com> | 2015-05-21 18:41:33 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-21 18:41:34 +0000 |
commit | 2b00f73c9d9827d38c425942c8683e3c065848eb (patch) | |
tree | 3b357b487928e2a46fd10f600dcc5340658a8f3c | |
parent | 5a194cd1f573d6c94a6b0e3e14cfabd69e42b856 (diff) | |
parent | 50dfa5e6b49c72ca3a10b38207d04f233ec1a2e3 (diff) |
Merge "Add voicemail tab if there are active providers." into mnc-dev
-rw-r--r-- | res/drawable/tab_voicemail.xml | 30 | ||||
-rw-r--r-- | res/values/strings.xml | 7 | ||||
-rw-r--r-- | src/com/android/dialer/CallDetailActivity.java | 3 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/CallLogActivity.java | 7 | ||||
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 66 |
5 files changed, 98 insertions, 15 deletions
diff --git a/res/drawable/tab_voicemail.xml b/res/drawable/tab_voicemail.xml new file mode 100644 index 000000000..568891b01 --- /dev/null +++ b/res/drawable/tab_voicemail.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="@color/tab_ripple_color"> + + <item> + <bitmap android:src="@drawable/ic_voicemail_24dp" + android:gravity="center" /> + </item> + + <item android:id="@android:id/mask"> + <color android:color="@android:color/white" /> + </item> + +</ripple> diff --git a/res/values/strings.xml b/res/values/strings.xml index e3b268247..21cd8909f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -471,12 +471,19 @@ [CHAR LIMIT=30] --> <string name="call_log_voicemail_title">Voicemail</string> + <!-- Accessibility text for the tab showing recent and favorite contacts who can be called. + [CHAR LIMIT=40] --> <string name="tab_speed_dial">Speed dial</string> + <!-- Accessibility text for the tab showing the call log of recent calls. [CHAR LIMIT=40] --> <string name="tab_recents">Recents</string> + <!-- Accessibility text for the tab showing the user's contacts. [CHAR LIMIT=40] --> <string name="tab_all_contacts">Contacts</string> + <!-- Accessibility text for the tab showing the user's voicemails. [CHAR LIMIT=40] --> + <string name="tab_voicemail">Voicemail</string> + <!-- Text displayed when user swipes out a favorite contact --> <string name="favorite_hidden">Removed from favorites</string> <!-- Text displayed for the undo button to undo removing a favorite contact --> diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index db247ba11..1c684a510 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -62,9 +62,6 @@ import com.android.dialer.util.IntentUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.TelecomUtil; import com.android.dialer.voicemail.VoicemailPlaybackFragment; -import com.android.dialer.voicemail.VoicemailStatusHelper; -import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; -import com.android.dialer.voicemail.VoicemailStatusHelperImpl; import java.util.List; diff --git a/src/com/android/dialer/calllog/CallLogActivity.java b/src/com/android/dialer/calllog/CallLogActivity.java index 8a0cc1364..00e5e6b5e 100644 --- a/src/com/android/dialer/calllog/CallLogActivity.java +++ b/src/com/android/dialer/calllog/CallLogActivity.java @@ -245,9 +245,10 @@ public class CallLogActivity extends Activity implements CallLogQueryHandler.Lis mHandler.removeCallbacks(mWaitForVoicemailTimeoutRunnable); // Update mHasActiveVoicemailProvider, which controls the number of tabs displayed. - int activeSources = mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor); - if (activeSources > 0 != mHasActiveVoicemailProvider) { - mHasActiveVoicemailProvider = activeSources > 0; + boolean hasActiveVoicemailProvider = + mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor) > 0; + if (hasActiveVoicemailProvider != mHasActiveVoicemailProvider) { + mHasActiveVoicemailProvider = hasActiveVoicemailProvider; mViewPagerAdapter.notifyDataSetChanged(); mViewPagerTabs.setViewPager(mViewPager); if (mSwitchToVoicemailTab) { diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 6e30af299..0ac6b1ac0 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -9,6 +9,7 @@ import android.content.SharedPreferences; import android.database.Cursor; import android.os.Bundle; import android.os.Trace; +import android.provider.CallLog.Calls; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; @@ -28,6 +29,8 @@ import com.android.dialer.calllog.CallLogFragment; import com.android.dialer.calllog.CallLogQueryHandler; import com.android.dialer.calllog.ContactInfoHelper; import com.android.dialer.util.DialerUtils; +import com.android.dialer.voicemail.VoicemailStatusHelper; +import com.android.dialer.voicemail.VoicemailStatusHelperImpl; import com.android.dialer.widget.ActionBarController; import com.android.dialerbind.ObjectFactory; @@ -41,7 +44,8 @@ import java.util.ArrayList; * ViewPager containing the lists up above the search bar and pin it against the top of the * screen. */ -public class ListsFragment extends Fragment implements ViewPager.OnPageChangeListener { +public class ListsFragment extends Fragment + implements ViewPager.OnPageChangeListener, CallLogQueryHandler.Listener { private static final boolean DEBUG = DialtactsActivity.DEBUG; private static final String TAG = "ListsFragment"; @@ -49,8 +53,10 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis public static final int TAB_INDEX_SPEED_DIAL = 0; public static final int TAB_INDEX_RECENTS = 1; public static final int TAB_INDEX_ALL_CONTACTS = 2; + public static final int TAB_INDEX_VOICEMAIL = 3; - public static final int TAB_INDEX_COUNT = 3; + public static final int TAB_COUNT_DEFAULT = 3; + public static final int TAB_COUNT_WITH_VOICEMAIL = 4; private static final int MAX_RECENTS_ENTRIES = 20; // Oldest recents entry to display is 2 weeks old. @@ -69,9 +75,14 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis private ViewPagerAdapter mViewPagerAdapter; private RemoveView mRemoveView; private View mRemoveViewContent; + private SpeedDialFragment mSpeedDialFragment; private CallLogFragment mRecentsFragment; private AllContactsFragment mAllContactsFragment; + private CallLogFragment mVoicemailFragment; + + private boolean mHasActiveVoicemailProvider; + private VoicemailStatusHelper mVoicemailStatusHelper; private ArrayList<OnPageChangeListener> mOnPageChangeListeners = new ArrayList<OnPageChangeListener>(); @@ -117,6 +128,9 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis case TAB_INDEX_ALL_CONTACTS: mAllContactsFragment = new AllContactsFragment(); return mAllContactsFragment; + case TAB_INDEX_VOICEMAIL: + mVoicemailFragment = new CallLogFragment(Calls.VOICEMAIL_TYPE); + return mVoicemailFragment; } throw new IllegalStateException("No fragment at position " + position); } @@ -130,17 +144,19 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis (Fragment) super.instantiateItem(container, position); if (fragment instanceof SpeedDialFragment) { mSpeedDialFragment = (SpeedDialFragment) fragment; - } else if (fragment instanceof CallLogFragment) { + } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_RECENTS) { mRecentsFragment = (CallLogFragment) fragment; } else if (fragment instanceof AllContactsFragment) { mAllContactsFragment = (AllContactsFragment) fragment; + } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_VOICEMAIL) { + mVoicemailFragment = (CallLogFragment) fragment; } return fragment; } @Override public int getCount() { - return TAB_INDEX_COUNT; + return mHasActiveVoicemailProvider ? TAB_COUNT_WITH_VOICEMAIL : TAB_COUNT_DEFAULT; } @Override @@ -158,6 +174,7 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis final String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); Trace.endSection(); + mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); Trace.endSection(); } @@ -172,6 +189,11 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis if (getUserVisibleHint()) { sendScreenViewForPosition(mViewPager.getCurrentItem()); } + + // Fetch voicemail status to determine if we should show the voicemail tab. + CallLogQueryHandler callLogQueryHandler = + new CallLogQueryHandler(getActivity(), getActivity().getContentResolver(), this); + callLogQueryHandler.fetchVoicemailStatus(); Trace.endSection(); } @@ -186,19 +208,21 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis mViewPager = (ViewPager) parentView.findViewById(R.id.lists_pager); mViewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager()); mViewPager.setAdapter(mViewPagerAdapter); - mViewPager.setOffscreenPageLimit(2); + mViewPager.setOffscreenPageLimit(TAB_COUNT_DEFAULT - 1); mViewPager.setOnPageChangeListener(this); mViewPager.setCurrentItem(getRtlPosition(TAB_INDEX_SPEED_DIAL)); - mTabTitles = new String[TAB_INDEX_COUNT]; + mTabTitles = new String[TAB_COUNT_WITH_VOICEMAIL]; mTabTitles[TAB_INDEX_SPEED_DIAL] = getResources().getString(R.string.tab_speed_dial); mTabTitles[TAB_INDEX_RECENTS] = getResources().getString(R.string.tab_recents); mTabTitles[TAB_INDEX_ALL_CONTACTS] = getResources().getString(R.string.tab_all_contacts); + mTabTitles[TAB_INDEX_VOICEMAIL] = getResources().getString(R.string.tab_voicemail); - mTabIcons = new int[TAB_INDEX_COUNT]; + mTabIcons = new int[TAB_COUNT_WITH_VOICEMAIL]; mTabIcons[TAB_INDEX_SPEED_DIAL] = R.drawable.tab_speed_dial; mTabIcons[TAB_INDEX_RECENTS] = R.drawable.tab_recents; mTabIcons[TAB_INDEX_ALL_CONTACTS] = R.drawable.tab_contacts; + mTabIcons[TAB_INDEX_VOICEMAIL] = R.drawable.tab_voicemail; mViewPagerTabs = (ViewPagerTabs) parentView.findViewById(R.id.lists_pager_header); mViewPagerTabs.setTabIcons(mTabIcons); @@ -247,6 +271,28 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis } } + @Override + public void onVoicemailStatusFetched(Cursor statusCursor) { + if (getActivity() == null || getActivity().isFinishing()) { + return; + } + + // Update mHasActiveVoicemailProvider, which controls the number of tabs displayed. + boolean hasActiveVoicemailProvider = + mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor) > 0; + if (hasActiveVoicemailProvider != mHasActiveVoicemailProvider) { + mHasActiveVoicemailProvider = hasActiveVoicemailProvider; + mViewPagerAdapter.notifyDataSetChanged(); + mViewPagerTabs.setViewPager(mViewPager); + } + } + + @Override + public boolean onCallsFetched(Cursor statusCursor) { + // Return false; did not take ownership of cursor + return false; + } + public int getTabPosition() { return mTabPosition; } @@ -272,7 +318,7 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis public int getRtlPosition(int position) { if (DialerUtils.isRtl()) { - return TAB_INDEX_COUNT - 1 - position; + return mViewPagerAdapter.getCount() - 1 - position; } return position; } @@ -291,11 +337,13 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis fragmentName = SpeedDialFragment.class.getSimpleName(); break; case TAB_INDEX_RECENTS: - fragmentName = CallLogFragment.class.getSimpleName(); + fragmentName = CallLogFragment.class.getSimpleName() + "#Recents"; break; case TAB_INDEX_ALL_CONTACTS: fragmentName = AllContactsFragment.class.getSimpleName(); break; + case TAB_INDEX_VOICEMAIL: + fragmentName = CallLogFragment.class.getSimpleName() + "#Voicemail"; default: return; } |