diff options
author | Ta-wei Yen <twyen@google.com> | 2015-11-06 23:02:42 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-11-06 23:02:42 +0000 |
commit | c97b8af94f580fea9b92673b450064a58d50c062 (patch) | |
tree | 4e10347ce075d916735d5cd6ed06961cc77c3f3b | |
parent | df473ed12a747ed50e106dc065e2703748828b2d (diff) | |
parent | a5437e6882bde69cb795ed8d929c1024a8fef16e (diff) |
Call Blocking UI/String change
am: a5437e6882
* commit 'a5437e6882bde69cb795ed8d929c1024a8fef16e':
Call Blocking UI/String change
-rw-r--r-- | res/drawable/ic_blocked_numbers_settings_add.xml | 20 | ||||
-rw-r--r-- | res/layout/blocked_number_footer.xml | 40 | ||||
-rw-r--r-- | res/layout/blocked_number_header.xml | 55 | ||||
-rw-r--r-- | res/values/colors.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 44 | ||||
-rw-r--r-- | src/com/android/dialer/CallDetailActivity.java | 1 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/CallLogListItemViewHolder.java | 1 | ||||
-rw-r--r-- | src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java | 82 | ||||
-rw-r--r-- | src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java | 5 | ||||
-rw-r--r-- | src/com/android/dialer/filterednumber/BlockedNumbersFragment.java | 86 | ||||
-rw-r--r-- | src/com/android/dialer/list/BlockedListSearchFragment.java | 3 | ||||
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 18 | ||||
-rw-r--r-- | src/com/android/dialer/voicemail/VisualVoicemailEnabledChecker.java | 98 |
13 files changed, 348 insertions, 106 deletions
diff --git a/res/drawable/ic_blocked_numbers_settings_add.xml b/res/drawable/ic_blocked_numbers_settings_add.xml deleted file mode 100644 index adcf90676..000000000 --- a/res/drawable/ic_blocked_numbers_settings_add.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?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. ---> - -<bitmap xmlns:android="http://schemas.android.com/apk/res/android" - android:src="@drawable/ic_add_24dp" - android:tint="@color/blocked_number_icon_tint" /> diff --git a/res/layout/blocked_number_footer.xml b/res/layout/blocked_number_footer.xml new file mode 100644 index 000000000..cdb3ead1b --- /dev/null +++ b/res/layout/blocked_number_footer.xml @@ -0,0 +1,40 @@ +<?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. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:card_view="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:focusable="false"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:layout_marginBottom="8dp" + android:padding="16dp" + android:background="@android:color/white" + android:focusable="true"> + + <TextView android:id="@+id/blocked_number_footer_textview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textColor="@color/blocked_number_secondary_text_color" + android:textSize="@dimen/blocked_number_primary_text_size" + android:text="@string/block_number_footer_message_vvm" /> + + </LinearLayout> +</LinearLayout> diff --git a/res/layout/blocked_number_header.xml b/res/layout/blocked_number_header.xml index 50a3dc8f2..685c4efd8 100644 --- a/res/layout/blocked_number_header.xml +++ b/res/layout/blocked_number_header.xml @@ -60,7 +60,7 @@ <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/blockList" + android:text="@string/block_list" android:textColor="@color/blocked_number_header_color" android:padding="@dimen/blocked_number_container_padding" style="@android:style/TextAppearance.Material.Subhead" /> @@ -105,21 +105,48 @@ </RelativeLayout> - <TextView android:id="@+id/add_number_textview" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:background="?android:attr/selectableItemBackground" - android:textColor="@color/blocked_number_primary_text_color" - android:textSize="@dimen/blocked_number_primary_text_size" - android:paddingTop="24dp" - android:paddingBottom="24dp" - android:paddingEnd="@dimen/blocked_number_container_padding" - android:paddingStart="24dp" - android:drawableStart="@drawable/ic_blocked_numbers_settings_add" - android:drawablePadding="24dp" - android:text="@string/addBlockedNumber" /> + <LinearLayout + android:id="@+id/add_number_linear_layout" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingStart="@dimen/blocked_number_horizontal_margin" + android:paddingTop="@dimen/blocked_number_top_margin" + android:paddingBottom="@dimen/blocked_number_bottom_margin" + android:baselineAligned="false" + android:gravity="center_vertical" + android:orientation="horizontal" + android:focusable="true" + android:clickable="true" + android:background="?android:attr/selectableItemBackground" + android:contentDescription="@string/addBlockedNumber"> + + <ImageView + android:id="@+id/add_number_icon" + android:layout_width="@dimen/contact_photo_size" + android:layout_height="@dimen/contact_photo_size" + android:importantForAccessibility="no" /> + <LinearLayout + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="vertical" + android:gravity="center_vertical" + android:layout_marginStart="@dimen/blocked_number_horizontal_margin"> + + <TextView android:id="@+id/add_number_textview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textColor="@color/blocked_number_primary_text_color" + android:textSize="@dimen/blocked_number_primary_text_size" + android:includeFontPadding="false" + android:layout_marginBottom="5dp" + android:text="@string/addBlockedNumber" /> + </LinearLayout> + + </LinearLayout> <View + android:id="@+id/blocked_number_list_divider" android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginStart="72dp" diff --git a/res/values/colors.xml b/res/values/colors.xml index 2ca697f2e..e927f740f 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -133,6 +133,7 @@ <color name="blocked_number_block_color">#F44336</color> <color name="blocked_number_header_color">@color/dialer_theme_color</color> <color name="blocked_number_disabled_emergency_header_color">#616161</color> + <color name="add_blocked_number_icon_color">#bdbdbd</color> <!-- Grey 700 --> <color name="call_detail_footer_text_color">#616161</color> diff --git a/res/values/strings.xml b/res/values/strings.xml index 4682b76cc..37b2a5cb4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -59,7 +59,7 @@ <!-- Text for snackbar to undo blocking a number. [CHAR LIMIT=64] --> <string name="snackbar_number_blocked"> - <xliff:g id="number" example="(555) 555-5555">%1$s</xliff:g> added to block list</string> + <xliff:g id="number" example="(555) 555-5555">%1$s</xliff:g> blocked</string> <!-- Label for action to unblock a number [CHAR LIMIT=48]--> <string name="action_unblock_number">Unblock number</string> @@ -67,7 +67,7 @@ <!-- Text for snackbar to undo unblocking a number. [CHAR LIMIT=64] --> <string name="snackbar_number_unblocked"> <xliff:g id="number" example="(555) 555-5555">%1$s</xliff:g> - removed from block list</string> + unblocked</string> <!-- Text for undo button in snackbar for blocking/unblocking number. [CHAR LIMIT=10] --> <string name="block_number_undo">UNDO</string> @@ -519,19 +519,31 @@ [CHAR LIMIT=30] --> <string name="call_log_voicemail_title">Voicemail</string> - <!-- Confirmation dialog for blocking a number. [CHAR LIMIT=NONE] --> - <string name="blockNumberConfirmation">Add + <!-- Confirmation dialog title for blocking a number. [CHAR LIMIT=NONE] --> + <string name="block_number_confirmation_title">Add <xliff:g id="number" example="(555) 555-5555">%1$s</xliff:g> to your block list?</string> + <!-- Confirmation dialog message for blocking a number with visual voicemail active. + [CHAR LIMIT=NONE] --> + <string name="block_number_confirmation_message_vvm"> + Future calls from this number will be blocked and voicemails will be automatically deleted. + </string> + + <!-- Confirmation dialog message for blocking a number with no visual voicemail. + [CHAR LIMIT=NONE] --> + <string name="block_number_confirmation_message_no_vvm"> + Future calls from this number will be blocked. Voicemails may still reach you. + </string> + <!-- Block number alert dialog button [CHAR LIMIT=32] --> - <string name="blockNumberOk">Block number</string> + <string name="block_number_ok">BLOCK</string> <!-- Confirmation dialog for unblocking a number. [CHAR LIMIT=NONE] --> - <string name="unblockNumberConfirmation">Remove - <xliff:g id="number" example="(555) 555-5555">%1$s</xliff:g> from your block list?</string> + <string name="unblock_number_confirmation_title">Unblock + <xliff:g id="number" example="(555) 555-5555">%1$s</xliff:g></string> <!-- Unblock number alert dialog button [CHAR LIMIT=32] --> - <string name="unblockNumberOk">Unblock number</string> + <string name="unblock_number_ok">UNBLOCK</string> <!-- Accessibility text for the tab showing recent and favorite contacts who can be called. [CHAR LIMIT=40] --> @@ -830,7 +842,7 @@ <string name="call_settings_label">Calls</string> <!-- Label for the blocked numbers settings section [CHAR LIMIT=30] --> - <string name="manage_blocked_numbers_label">Blocked numbers</string> + <string name="manage_blocked_numbers_label">Call blocking</string> <!-- Label for a section describing that call blocking is temporarily disabled because an emergency call was made. [CHAR LIMIT=50] --> @@ -877,8 +889,20 @@ <!-- Button to bring up UI to add a number to the blocked call list. [CHAR LIMIT=40] --> <string name="addBlockedNumber">Add number</string> + <!-- Footer message of number blocking screen with visual voicemail active. + [CHAR LIMIT=NONE] --> + <string name="block_number_footer_message_vvm"> + Adding a number blocks all future calls and voicemails will be automatically deleted. + </string> + + <!-- Footer message of number blocking screen with no visual voicemail. + [CHAR LIMIT=NONE] --> + <string name="block_number_footer_message_no_vvm"> + Adding a number blocks all future calls. Voicemails may still reach you. + </string> + <!-- Heading for the block list in the "Spam and blocked cal)ls" settings. [CHAR LIMIT=64] --> - <string name="blockList">Block list</string> + <string name="block_list">Blocked numbers</string> <!-- Error message shown when user tries to add invalid number to the block list. [CHAR LIMIT=64] --> diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 0d943e055..f63fcf3b0 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -358,6 +358,7 @@ public class CallDetailActivity extends AppCompatActivity switch(view.getId()) { case R.id.call_detail_action_block: BlockNumberDialogFragment.show( + this, mBlockedNumberId, mNumber, mDetails.countryIso, diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 12df6c6d3..0087506fd 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -328,6 +328,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder switch (item.getItemId()) { case R.id.context_menu_block_number: BlockNumberDialogFragment.show( + mContext, blockId, number, countryIso, diff --git a/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java b/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java index 7a94eebb5..4cbd4ddb8 100644 --- a/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java +++ b/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java @@ -23,25 +23,26 @@ import android.app.FragmentManager; import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; -import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; import android.support.design.widget.Snackbar; -import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.view.View; import android.widget.Toast; +import com.android.contacts.common.util.ContactDisplayUtils; import com.android.dialer.R; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnBlockNumberListener; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnUnblockNumberListener; +import com.android.dialer.voicemail.VisualVoicemailEnabledChecker; /** * Fragment for confirming and enacting blocking/unblocking a number. Also invokes snackbar * providing undo functionality. */ -public class BlockNumberDialogFragment extends DialogFragment { +public class BlockNumberDialogFragment extends DialogFragment + implements VisualVoicemailEnabledChecker.Callback{ /** * Use a callback interface to update UI after success/undo. Favor this approach over other @@ -69,9 +70,12 @@ public class BlockNumberDialogFragment extends DialogFragment { private FilteredNumberAsyncQueryHandler mHandler; private View mParentView; + private VisualVoicemailEnabledChecker mVoicemailEnabledChecker; private Callback mCallback; + private AlertDialog mAlertDialog; public static void show( + Context context, Integer blockId, String number, String countryIso, @@ -80,13 +84,14 @@ public class BlockNumberDialogFragment extends DialogFragment { FragmentManager fragmentManager, Callback callback) { final BlockNumberDialogFragment newFragment = BlockNumberDialogFragment.newInstance( - blockId, number, countryIso, displayNumber, parentViewId); + context, blockId, number, countryIso, displayNumber, parentViewId); newFragment.setCallback(callback); newFragment.show(fragmentManager, BlockNumberDialogFragment.BLOCK_DIALOG_FRAGMENT); } private static BlockNumberDialogFragment newInstance( + Context context, Integer blockId, String number, String countryIso, @@ -104,6 +109,8 @@ public class BlockNumberDialogFragment extends DialogFragment { args.putString(ARG_COUNTRY_ISO, countryIso); args.putString(ARG_DISPLAY_NUMBER, displayNumber); fragment.setArguments(args); + fragment.mVoicemailEnabledChecker = new VisualVoicemailEnabledChecker(context,fragment); + fragment.mVoicemailEnabledChecker.asyncUpdate(); return fragment; } @@ -123,17 +130,28 @@ public class BlockNumberDialogFragment extends DialogFragment { mHandler = new FilteredNumberAsyncQueryHandler(getContext().getContentResolver()); mParentView = getActivity().findViewById(getArguments().getInt(ARG_PARENT_VIEW_ID)); - String message; + CharSequence title; String okText; + String message; if (isBlocked) { - message = getString(R.string.unblockNumberConfirmation, mDisplayNumber); - okText = getString(R.string.unblockNumberOk); + title = getTtsSpannedPhoneNumberString(R.string.unblock_number_confirmation_title, + mDisplayNumber); + okText = getString(R.string.unblock_number_ok); + message = null; } else { - message = getString(R.string.blockNumberConfirmation, mDisplayNumber); - okText = getString(R.string.blockNumberOk); + title = getTtsSpannedPhoneNumberString(R.string.block_number_confirmation_title, + mDisplayNumber); + okText = getString(R.string.block_number_ok); + if (mVoicemailEnabledChecker.isVisualVoicemailEnabled()) { + message = getString(R.string.block_number_confirmation_message_vvm); + } else { + message = getString(R.string.block_number_confirmation_message_no_vvm); + } } + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) + .setTitle(title) .setMessage(message) .setPositiveButton(okText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -142,10 +160,16 @@ public class BlockNumberDialogFragment extends DialogFragment { } else { blockNumber(); } + mAlertDialog = null; } }) - .setNegativeButton(android.R.string.cancel, null); - return builder.create(); + .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + mAlertDialog = null; + } + }); + mAlertDialog = builder.create(); + return mAlertDialog; } @Override @@ -171,12 +195,17 @@ public class BlockNumberDialogFragment extends DialogFragment { mCallback = callback; } - private String getBlockedMessage() { - return getString(R.string.snackbar_number_blocked, mDisplayNumber); + private CharSequence getTtsSpannedPhoneNumberString(int id,String number){ + String msg = getString(id, mDisplayNumber); + return ContactDisplayUtils.getTelephoneTtsSpannable(msg,mDisplayNumber); + } + + private CharSequence getBlockedMessage() { + return getTtsSpannedPhoneNumberString(R.string.snackbar_number_blocked, mDisplayNumber); } - private String getUnblockedMessage() { - return getString(R.string.snackbar_number_unblocked, mDisplayNumber); + private CharSequence getUnblockedMessage() { + return getTtsSpannedPhoneNumberString(R.string.snackbar_number_unblocked, mDisplayNumber); } private int getActionTextColor() { @@ -184,8 +213,8 @@ public class BlockNumberDialogFragment extends DialogFragment { } private void blockNumber() { - final String message = getBlockedMessage(); - final String undoMessage = getUnblockedMessage(); + final CharSequence message = getBlockedMessage(); + final CharSequence undoMessage = getUnblockedMessage(); final Callback callback = mCallback; final int actionTextColor = getActionTextColor(); final Context context = getContext(); @@ -233,8 +262,8 @@ public class BlockNumberDialogFragment extends DialogFragment { } private void unblockNumber() { - final String message = getUnblockedMessage(); - final String undoMessage = getBlockedMessage(); + final CharSequence message = getUnblockedMessage(); + final CharSequence undoMessage = getBlockedMessage(); final Callback callback = mCallback; final int actionTextColor = getActionTextColor(); @@ -270,4 +299,19 @@ public class BlockNumberDialogFragment extends DialogFragment { } }, getArguments().getInt(ARG_BLOCK_ID)); } + + @Override + public void onVisualVoicemailEnabledStatusChanged(boolean newStatus){ + updateActiveVoicemailProvider(); + } + + private void updateActiveVoicemailProvider(){ + if(mAlertDialog != null) { + if (mVoicemailEnabledChecker.isVisualVoicemailEnabled()) { + mAlertDialog.setMessage(getString(R.string.block_number_confirmation_message_vvm)); + } else { + mAlertDialog.setMessage(getString(R.string.block_number_confirmation_message_no_vvm)); + } + } + } } diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java b/src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java index ad9e7a652..be83df723 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java +++ b/src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java @@ -16,8 +16,8 @@ package com.android.dialer.filterednumber; import android.app.FragmentManager; -import android.database.Cursor; import android.content.Context; +import android.database.Cursor; import android.view.View; import com.android.contacts.common.ContactPhotoManager; @@ -46,7 +46,7 @@ public class BlockedNumbersAdapter extends NumbersAdapter { } @Override - public void bindView(View view, Context context, Cursor cursor) { + public void bindView(View view, final Context context, Cursor cursor) { super.bindView(view, context, cursor); final Integer id = cursor.getInt(cursor.getColumnIndex(FilteredNumberColumns._ID)); final String countryIso = cursor.getString(cursor.getColumnIndex( @@ -60,6 +60,7 @@ public class BlockedNumbersAdapter extends NumbersAdapter { @Override public void onClick(View view) { BlockNumberDialogFragment.show( + context, id, number, countryIso, diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java index a2a716fe3..881ec0497 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java +++ b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java @@ -15,41 +15,40 @@ */ package com.android.dialer.filterednumber; -import android.app.Activity; import android.app.ListFragment; import android.app.LoaderManager; import android.content.Context; import android.content.CursorLoader; -import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; -import android.widget.CompoundButton; -import android.widget.Switch; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.Switch; +import android.widget.ImageView; +import android.widget.TextView; +import com.android.contacts.common.lettertiles.LetterTileDrawable; import com.android.dialer.R; import com.android.dialer.database.FilteredNumberContract; import com.android.dialer.filterednumber.FilteredNumbersUtil.CheckForSendToVoicemailContactListener; import com.android.dialer.filterednumber.FilteredNumbersUtil.ImportSendToVoicemailContactsListener; -import com.android.dialer.voicemail.VoicemailStatusHelper; -import com.android.dialer.voicemail.VoicemailStatusHelperImpl; +import com.android.dialer.voicemail.VisualVoicemailEnabledChecker; public class BlockedNumbersFragment extends ListFragment - implements LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener { + implements LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener, + VisualVoicemailEnabledChecker.Callback { + private static final char ADD_BLOCKED_NUMBER_ICON_LETTER = '+'; private BlockedNumbersAdapter mAdapter; - private VoicemailStatusHelper mVoicemailStatusHelper; + private VisualVoicemailEnabledChecker mVoicemailEnabledChecker; private View mImportSettings; private View mBlockedNumbersDisabledForEmergency; + private View mBlockedNumberListDivider; @Override public void onActivityCreated(Bundle savedInstanceState) { @@ -58,6 +57,15 @@ public class BlockedNumbersFragment extends ListFragment LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); getListView().addHeaderView(inflater.inflate(R.layout.blocked_number_header, null)); + getListView().addFooterView(inflater.inflate(R.layout.blocked_number_footer, null)); + //replace the icon for add number with LetterTileDrawable(), so it will have identical style + ImageView addNumberIcon = (ImageView) getActivity().findViewById(R.id.add_number_icon); + LetterTileDrawable drawable = new LetterTileDrawable(getResources()); + drawable.setLetter(ADD_BLOCKED_NUMBER_ICON_LETTER); + drawable.setColor(getResources().getColor(R.color.add_blocked_number_icon_color, + getActivity().getTheme())); + drawable.setIsCircular(true); + addNumberIcon.setImageDrawable(drawable); if (mAdapter == null) { mAdapter = BlockedNumbersAdapter.newBlockedNumbersAdapter( @@ -65,15 +73,17 @@ public class BlockedNumbersFragment extends ListFragment } setListAdapter(mAdapter); - mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); - - mImportSettings = getActivity().findViewById(R.id.import_settings); + mImportSettings = getListView().findViewById(R.id.import_settings); mBlockedNumbersDisabledForEmergency = - getActivity().findViewById(R.id.blocked_numbers_disabled_for_emergency); - - getActivity().findViewById(R.id.import_button).setOnClickListener(this);; - getActivity().findViewById(R.id.view_numbers_button).setOnClickListener(this); - getActivity().findViewById(R.id.add_number_textview).setOnClickListener(this); + getListView().findViewById(R.id.blocked_numbers_disabled_for_emergency); + mBlockedNumberListDivider = getActivity().findViewById(R.id.blocked_number_list_divider); + getListView().findViewById(R.id.import_button).setOnClickListener(this);; + getListView().findViewById(R.id.view_numbers_button).setOnClickListener(this); + getListView().findViewById(R.id.add_number_linear_layout).setOnClickListener(this); + + mVoicemailEnabledChecker = new VisualVoicemailEnabledChecker(getContext(),this); + mVoicemailEnabledChecker.asyncUpdate(); + updateActiveVoicemailProvider(); } @Override @@ -103,19 +113,21 @@ public class BlockedNumbersFragment extends ListFragment actionBar.setTitle(R.string.manage_blocked_numbers_label); FilteredNumbersUtil.checkForSendToVoicemailContact( - getActivity(), new CheckForSendToVoicemailContactListener() { - @Override - public void onComplete(boolean hasSendToVoicemailContact) { - final int visibility = hasSendToVoicemailContact ? View.VISIBLE : View.GONE; - mImportSettings.setVisibility(visibility); - } - }); + getActivity(), new CheckForSendToVoicemailContactListener() { + @Override + public void onComplete(boolean hasSendToVoicemailContact) { + final int visibility = hasSendToVoicemailContact ? View.VISIBLE : View.GONE; + mImportSettings.setVisibility(visibility); + } + }); if (FilteredNumbersUtil.hasRecentEmergencyCall(getContext())) { mBlockedNumbersDisabledForEmergency.setVisibility(View.VISIBLE); } else { mBlockedNumbersDisabledForEmergency.setVisibility(View.GONE); } + + mVoicemailEnabledChecker.asyncUpdate(); } @Override @@ -143,6 +155,11 @@ public class BlockedNumbersFragment extends ListFragment @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { mAdapter.swapCursor(data); + if (data.getCount() == 0) { + mBlockedNumberListDivider.setVisibility(View.INVISIBLE); + } else { + mBlockedNumberListDivider.setVisibility(View.VISIBLE); + } } @Override @@ -158,7 +175,7 @@ public class BlockedNumbersFragment extends ListFragment } switch (view.getId()) { - case R.id.add_number_textview: + case R.id.add_number_linear_layout: activity.showSearchUi(); break; case R.id.view_numbers_button: @@ -175,4 +192,21 @@ public class BlockedNumbersFragment extends ListFragment break; } } + @Override + public void onVisualVoicemailEnabledStatusChanged(boolean newStatus){ + updateActiveVoicemailProvider(); + } + + private void updateActiveVoicemailProvider(){ + if (getActivity() == null || getActivity().isFinishing()) { + return; + } + TextView footerText = (TextView) getActivity().findViewById( + R.id.blocked_number_footer_textview); + if (mVoicemailEnabledChecker.isVisualVoicemailEnabled()) { + footerText.setText(R.string.block_number_footer_message_vvm); + } else { + footerText.setText(R.string.block_number_footer_message_no_vvm); + } + } } diff --git a/src/com/android/dialer/list/BlockedListSearchFragment.java b/src/com/android/dialer/list/BlockedListSearchFragment.java index 94036ae81..7f8f12c73 100644 --- a/src/com/android/dialer/list/BlockedListSearchFragment.java +++ b/src/com/android/dialer/list/BlockedListSearchFragment.java @@ -36,7 +36,6 @@ import com.android.dialer.R; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; import com.android.dialer.filterednumber.BlockNumberDialogFragment; -import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity; import com.android.dialer.widget.SearchEditTextLayout; public class BlockedListSearchFragment extends RegularSearchFragment @@ -177,6 +176,7 @@ public class BlockedListSearchFragment extends RegularSearchFragment public void onCheckComplete(Integer id) { if (id == null) { BlockNumberDialogFragment.show( + getContext(), id, number, countryIso, @@ -224,6 +224,7 @@ public class BlockedListSearchFragment extends RegularSearchFragment } BlockNumberDialogFragment.show( + getContext(), blockId, number, GeoUtil.getCurrentCountryIso(getContext()), diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 08a23732f..4735926e8 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -15,10 +15,8 @@ */ package com.android.dialer.list; -import android.animation.LayoutTransition; import android.app.Fragment; import android.app.FragmentManager; -import android.content.Context; import android.content.SharedPreferences; import android.database.Cursor; import android.os.Bundle; @@ -30,27 +28,21 @@ import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.ListView; -import com.android.contacts.common.GeoUtil; import com.android.contacts.common.list.ViewPagerTabs; -import com.android.contacts.commonbind.analytics.AnalyticsUtil; import com.android.dialer.DialtactsActivity; import com.android.dialer.R; import com.android.dialer.calllog.CallLogFragment; import com.android.dialer.calllog.CallLogQueryHandler; -import com.android.dialer.calllog.ContactInfoHelper; import com.android.dialer.logging.Logger; import com.android.dialer.util.DialerUtils; +import com.android.dialer.voicemail.VisualVoicemailEnabledChecker; import com.android.dialer.voicemail.VoicemailStatusHelper; import com.android.dialer.voicemail.VoicemailStatusHelperImpl; import com.android.dialer.widget.ActionBarController; -import com.android.dialerbind.ObjectFactory; import java.util.ArrayList; @@ -76,9 +68,6 @@ public class ListsFragment extends Fragment public static final int TAB_COUNT_DEFAULT = 3; public static final int TAB_COUNT_WITH_VOICEMAIL = 4; - private static final String PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER = - "has_active_voicemail_provider"; - public interface HostInterface { public ActionBarController getActionBarController(); } @@ -182,7 +171,7 @@ public class ListsFragment extends Fragment mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mHasActiveVoicemailProvider = mPrefs.getBoolean( - PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, false); + VisualVoicemailEnabledChecker.PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, false); Trace.endSection(); } @@ -317,7 +306,8 @@ public class ListsFragment extends Fragment mViewPagerTabs.updateTab(TAB_INDEX_VOICEMAIL); mPrefs.edit() - .putBoolean(PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, hasActiveVoicemailProvider) + .putBoolean(VisualVoicemailEnabledChecker.PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, + hasActiveVoicemailProvider) .commit(); } diff --git a/src/com/android/dialer/voicemail/VisualVoicemailEnabledChecker.java b/src/com/android/dialer/voicemail/VisualVoicemailEnabledChecker.java new file mode 100644 index 000000000..3134b1486 --- /dev/null +++ b/src/com/android/dialer/voicemail/VisualVoicemailEnabledChecker.java @@ -0,0 +1,98 @@ +package com.android.dialer.voicemail; + + +import android.content.Context; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.preference.PreferenceManager; +import android.support.annotation.Nullable; + +import com.android.dialer.calllog.CallLogQueryHandler; + +/** + * Helper class to check whether visual voicemail is enabled. + * + * Call isVisualVoicemailEnabled() to retrieve the result. + * + * The result is cached and saved in a SharedPreferences, stored as a boolean in + * PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER. Every time a new instance is created, it will try to + * restore the cached result from the SharedPreferences. + * + * Call asyncUpdate() to make a CallLogQuery to check the actual status. This is a async call so + * isVisualVoicemailEnabled() will not be affected immediately. + * + * If the status has changed as a result of asyncUpdate(), + * Callback.onVisualVoicemailEnabledStatusChanged() will be called with the new value. + */ +public class VisualVoicemailEnabledChecker implements CallLogQueryHandler.Listener { + + public static final String PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER = + "has_active_voicemail_provider"; + private SharedPreferences mPrefs; + private boolean mHasActiveVoicemailProvider; + private CallLogQueryHandler mCallLogQueryHandler; + private VoicemailStatusHelper mVoicemailStatusHelper; + private Context mContext; + + public interface Callback { + + /** + * Callback to notify enabled status has changed to the @param newValue + */ + void onVisualVoicemailEnabledStatusChanged(boolean newValue); + } + + private Callback mCallback; + + public VisualVoicemailEnabledChecker(Context context, @Nullable Callback callback) { + mContext = context; + mCallback = callback; + mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); + mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); + mHasActiveVoicemailProvider = mPrefs.getBoolean(PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, + false); + } + + /** + * @return whether visual voicemail is enabled. Result is cached, call asyncUpdate() to + * update the result. + */ + public boolean isVisualVoicemailEnabled() { + return mHasActiveVoicemailProvider; + } + + /** + * Perform an async query into the system to check the status of visual voicemail. + * If the status has changed, Callback.onVisualVoicemailEnabledStatusChanged() will be called. + */ + public void asyncUpdate() { + mCallLogQueryHandler = + new CallLogQueryHandler(mContext, mContext.getContentResolver(), this); + mCallLogQueryHandler.fetchVoicemailStatus(); + } + + @Override + public void onVoicemailStatusFetched(Cursor statusCursor) { + boolean hasActiveVoicemailProvider = + mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor) > 0; + if (hasActiveVoicemailProvider != mHasActiveVoicemailProvider) { + mHasActiveVoicemailProvider = hasActiveVoicemailProvider; + mPrefs.edit().putBoolean(PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, + mHasActiveVoicemailProvider); + if (mCallback != null) { + mCallback.onVisualVoicemailEnabledStatusChanged(mHasActiveVoicemailProvider); + } + } + } + + @Override + public void onVoicemailUnreadCountFetched(Cursor cursor) { + // Do nothing + } + + @Override + public boolean onCallsFetched(Cursor combinedCursor) { + // Do nothing + return false; + } +} |