diff options
author | Danny Baumann <dannybaumann@web.de> | 2016-04-14 10:16:31 +0200 |
---|---|---|
committer | Rohit Yengisetty <rohit@cyngn.com> | 2016-04-20 14:29:06 -0700 |
commit | 93b791a4f84e15d89ffa84f855d1582f729a5b76 (patch) | |
tree | 35e961979b929a3c8e956605325671380ae53b6e | |
parent | 5d89d627870b563ea2d7abc67dbcbf1c75aa6dea (diff) | |
download | android_packages_apps_Dialer-93b791a4f84e15d89ffa84f855d1582f729a5b76.tar.gz android_packages_apps_Dialer-93b791a4f84e15d89ffa84f855d1582f729a5b76.tar.bz2 android_packages_apps_Dialer-93b791a4f84e15d89ffa84f855d1582f729a5b76.zip |
Convert call log and call stats details to new contact blocking code.
Change-Id: I78b974810b2d81175a3f71146130f22479a0c595
-rw-r--r-- | res/menu/call_details_options.xml | 4 | ||||
-rw-r--r-- | res/menu/call_stats_details_options.xml | 6 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 3 | ||||
-rw-r--r-- | src/com/android/dialer/CallDetailActivity.java | 42 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/BlockContactPresenter.java | 5 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/CallLogListItemViewHolder.java | 2 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/ContactInfoHelper.java | 47 | ||||
-rw-r--r-- | src/com/android/dialer/callstats/CallStatsDetailActivity.java | 56 |
8 files changed, 87 insertions, 78 deletions
diff --git a/res/menu/call_details_options.xml b/res/menu/call_details_options.xml index 6edeb95db..cf7abac31 100644 --- a/res/menu/call_details_options.xml +++ b/res/menu/call_details_options.xml @@ -31,6 +31,6 @@ <item android:id="@+id/menu_report" android:title="@string/call_detail_menu_report" /> - <item android:id="@+id/menu_add_to_blacklist" - android:title="@string/menu_add_to_blacklist" /> + <item android:id="@+id/menu_block_contact" + android:title="@string/menu_block_contact" /> </menu> diff --git a/res/menu/call_stats_details_options.xml b/res/menu/call_stats_details_options.xml index c16db3315..32898c2b1 100644 --- a/res/menu/call_stats_details_options.xml +++ b/res/menu/call_stats_details_options.xml @@ -17,11 +17,9 @@ <item android:id="@+id/menu_edit_number_before_call" android:title="@string/recentCalls_editNumberBeforeCall" - android:onClick="onMenuEditNumberBeforeCall" /> <item - android:id="@+id/menu_add_to_blacklist" - android:title="@string/menu_add_to_blacklist" - android:onClick="onMenuAddToBlacklist" + android:id="@+id/menu_block_contact" + android:title="@string/menu_block_contact" /> </menu> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 26e6d1cb9..be32f45d6 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -44,9 +44,6 @@ <!-- Description for incoming calls that were blacklisted --> <string name="type_blacklist">Blacklisted call</string> - <string name="menu_add_to_blacklist">Add to blocked caller list</string> - <string name="toast_added_to_blacklist">%s added to blocked caller list.</string> - <string name="toast_removed_from_blacklist">%s removed from blocked caller list.</string> <string name="call_log_action_block">Block caller</string> <string name="call_log_action_unblock">Caller blocked</string> diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 48854bec6..8a4cd7590 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -17,6 +17,7 @@ package com.android.dialer; import android.app.Activity; +import android.app.DialogFragment; import android.content.ContentResolver; import android.content.ComponentName; import android.content.ContentUris; @@ -51,6 +52,8 @@ import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.util.PermissionsUtil; import com.android.contacts.common.GeoUtil; import com.android.contacts.common.CallUtil; +import com.android.contacts.common.activity.fragment.BlockContactDialogFragment; +import com.android.contacts.common.util.BlockContactHelper; import com.android.contacts.common.util.UriUtils; import com.android.dialer.calllog.CallDetailHistoryAdapter; import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener; @@ -70,6 +73,7 @@ import com.android.phone.common.incall.CallMethodHelper; import com.android.phone.common.incall.CallMethodInfo; import com.cyanogen.ambient.incall.extension.OriginCodes; +import com.cyanogen.lookup.phonenumber.provider.LookupProviderImpl; import java.util.List; @@ -80,7 +84,7 @@ import java.util.List; * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. */ public class CallDetailActivity extends Activity - implements MenuItem.OnMenuItemClickListener { + implements MenuItem.OnMenuItemClickListener, BlockContactDialogFragment.Callbacks { private static final String TAG = "CallDetail"; private static final boolean DEBUG = false; @@ -190,6 +194,7 @@ public class CallDetailActivity extends Activity nameForDefaultImage = firstDetails.name.toString(); } + mBlockContactHelper.setContactInfo(mNumber); loadContactPhotos(contactUri, photoUri, nameForDefaultImage, lookupKey, contactType, photoId, mInCallComponentName); findViewById(R.id.call_detail).setVisibility(View.VISIBLE); @@ -220,6 +225,7 @@ public class CallDetailActivity extends Activity private TextView mAccountLabel; private View mCallButton; private ContactInfoHelper mContactInfoHelper; + private BlockContactHelper mBlockContactHelper; protected String mNumber; private ComponentName mInCallComponentName; @@ -281,6 +287,7 @@ public class CallDetailActivity extends Activity }); mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); + mBlockContactHelper = new BlockContactHelper(this, new LookupProviderImpl(this)); getActionBar().setDisplayHomeAsUpEnabled(true); if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { @@ -291,6 +298,7 @@ public class CallDetailActivity extends Activity @Override protected void onDestroy() { super.onDestroy(); + mBlockContactHelper.destroy(); mCallRecordingDataStore.close(); } @@ -369,6 +377,16 @@ public class CallDetailActivity extends Activity } @Override + public void onBlockSelected(boolean notifyLookupProvider) { + mBlockContactHelper.blockContactAsync(notifyLookupProvider); + } + + @Override + public void onUnblockSelected(boolean notifyLookupProvider) { + mBlockContactHelper.unblockContactAsync(notifyLookupProvider); + } + + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.call_details_options, menu); return super.onCreateOptionsMenu(menu); @@ -390,9 +408,14 @@ public class CallDetailActivity extends Activity menu.findItem(R.id.menu_report) .setVisible(mHasReportMenuOption) .setOnMenuItemClickListener(this); - menu.findItem(R.id.menu_add_to_blacklist) - .setVisible(mInCallComponentName == null) + + boolean canBlock = mBlockContactHelper.canBlockContact(this); + menu.findItem(R.id.menu_block_contact) + .setVisible(canBlock) + .setTitle(canBlock && mBlockContactHelper.isContactBlacklisted() + ? R.string.menu_unblock_contact : R.string.menu_block_contact) .setOnMenuItemClickListener(this); + return super.onPrepareOptionsMenu(menu); } @@ -417,9 +440,16 @@ public class CallDetailActivity extends Activity CallLogAsyncTaskUtil.deleteVoicemail( this, mVoicemailUri, mCallLogAsyncTaskListener); break; - case R.id.menu_add_to_blacklist: - mContactInfoHelper.addNumberToBlacklist(mNumber); - break; + case R.id.menu_block_contact: { + // block contact dialog fragment + DialogFragment f = mBlockContactHelper.getBlockContactDialog( + mBlockContactHelper.isContactBlacklisted() ? + BlockContactHelper.BlockOperation.UNBLOCK : + BlockContactHelper.BlockOperation.BLOCK + ); + f.show(getFragmentManager(), "block_contact"); + return true; + } } return true; } diff --git a/src/com/android/dialer/calllog/BlockContactPresenter.java b/src/com/android/dialer/calllog/BlockContactPresenter.java index 9a94d4c43..47810dca9 100644 --- a/src/com/android/dialer/calllog/BlockContactPresenter.java +++ b/src/com/android/dialer/calllog/BlockContactPresenter.java @@ -26,6 +26,7 @@ import android.widget.TextView; import com.android.contacts.common.util.BlockContactHelper; import com.android.dialer.R; +import com.android.internal.telephony.util.BlacklistUtils; import com.cyanogen.lookup.phonenumber.provider.LookupProviderImpl; /** @@ -95,6 +96,10 @@ public class BlockContactPresenter implements View.OnClickListener, } } + public boolean canBlock() { + return BlacklistUtils.isBlacklistEnabled(mActivity); + } + public void onBlockSelected(boolean notifyProvider) { mBlockContactHelper.blockContactAsync(notifyProvider); } diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 7c50cf645..972addc32 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -456,7 +456,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder supportsCallSubject && !isVoicemailNumber ? View.VISIBLE : View.GONE); // Remove block caller item if blacklist is disabled - if (mContactInfoHelper.canBlacklistCalls() && (cmi == null || !cmi.mIsInCallProvider)) { + if (mBlockContactPresenter.canBlock() && (cmi == null || !cmi.mIsInCallProvider)) { mBlockContactPresenter.setControlView(blockCallerButtonView, number); blockCallerButtonView.setVisibility(View.VISIBLE); } else { diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index af46127e8..0bfe92bca 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -25,12 +25,9 @@ import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.DisplayNameSources; import android.provider.ContactsContract.PhoneLookup; -import android.provider.Settings; -import android.provider.Telephony; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.util.Log; -import android.widget.Toast; import com.android.contacts.common.util.Constants; import com.android.contacts.common.util.PermissionsUtil; @@ -512,50 +509,6 @@ public class ContactInfoHelper { && mCachedNumberLookupService.canReportAsInvalid(sourceType, objectId); } - /** - * Checks whether calls can be blacklisted; that is, whether the - * phone blacklist is enabled - */ - public boolean canBlacklistCalls() { - return Settings.System.getInt(mContext.getContentResolver(), - Settings.System.PHONE_BLACKLIST_ENABLED, 1) != 0; - } - - /** - * Requests the given number to be added to the phone blacklist - * - * @param number the number to be blacklisted - */ - public void addNumberToBlacklist(String number) { - ContentValues cv = new ContentValues(); - cv.put(Telephony.Blacklist.PHONE_MODE, 1); - - Uri uri = Uri.withAppendedPath(Telephony.Blacklist.CONTENT_FILTER_BYNUMBER_URI, number); - int count = mContext.getContentResolver().update(uri, cv, null, null); - - if (count != 0) { - // Give the user some feedback - String message = mContext.getString(R.string.toast_added_to_blacklist, number); - Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); - } - } - - /** - * Requests the given number to be removed from phone blacklist - * - * @param number the number to be removed from blacklist - */ - public void removeNumberFromBlacklist(String number) { - Uri uri = Uri.withAppendedPath(Telephony.Blacklist.CONTENT_FILTER_BYNUMBER_URI, number); - int count = mContext.getContentResolver().delete(uri, null, null); - - if (count != 0) { - // Give the user some feedback - String message = mContext.getString(R.string.toast_removed_from_blacklist, number); - Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); - } - } - private void logSuccessfulFetch() { MetricsHelper.Field field = new MetricsHelper.Field( MetricsHelper.Fields.PROVIDER_PACKAGE_NAME, diff --git a/src/com/android/dialer/callstats/CallStatsDetailActivity.java b/src/com/android/dialer/callstats/CallStatsDetailActivity.java index 3f4d6c98a..35eb9fcd0 100644 --- a/src/com/android/dialer/callstats/CallStatsDetailActivity.java +++ b/src/com/android/dialer/callstats/CallStatsDetailActivity.java @@ -19,6 +19,7 @@ package com.android.dialer.callstats; import android.app.ActionBar; import android.app.Activity; +import android.app.DialogFragment; import android.content.Intent; import android.content.res.Resources; import android.net.Uri; @@ -37,6 +38,8 @@ import android.widget.TextView; import com.android.contacts.common.CallUtil; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.GeoUtil; +import com.android.contacts.common.activity.fragment.BlockContactDialogFragment; +import com.android.contacts.common.util.BlockContactHelper; import com.android.contacts.common.util.UriUtils; import com.android.dialer.R; import com.android.dialer.calllog.CallTypeIconsView; @@ -45,11 +48,13 @@ import com.android.dialer.calllog.ContactInfoHelper; import com.android.dialer.util.IntentUtil; import com.android.dialer.util.PhoneNumberUtil; import com.android.dialer.widget.LinearColorBar; +import com.cyanogen.lookup.phonenumber.provider.LookupProviderImpl; /** * Activity to display detailed information about a callstat item */ -public class CallStatsDetailActivity extends Activity { +public class CallStatsDetailActivity extends Activity implements + BlockContactDialogFragment.Callbacks { private static final String TAG = "CallStatsDetailActivity"; public static final String EXTRA_DETAILS = "details"; @@ -58,6 +63,7 @@ public class CallStatsDetailActivity extends Activity { public static final String EXTRA_TO = "to"; private ContactInfoHelper mContactInfoHelper; + private BlockContactHelper mBlockContactHelper; private Resources mResources; private QuickContactBadge mQuickContactBadge; @@ -103,6 +109,7 @@ public class CallStatsDetailActivity extends Activity { mResources = getResources(); mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); + mBlockContactHelper = new BlockContactHelper(this, new LookupProviderImpl(this)); mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); mQuickContactBadge.setOverlay(null); @@ -172,6 +179,16 @@ public class CallStatsDetailActivity extends Activity { new UpdateContactTask().execute(mData.number.toString(), mData.countryIso); } + @Override + public void onBlockSelected(boolean notifyLookupProvider) { + mBlockContactHelper.blockContactAsync(notifyLookupProvider); + } + + @Override + public void onUnblockSelected(boolean notifyLookupProvider) { + mBlockContactHelper.unblockContactAsync(notifyLookupProvider); + } + private void updateData() { mNumber = mData.number.toString(); @@ -183,6 +200,7 @@ public class CallStatsDetailActivity extends Activity { : mData.geocode; mData.updateDisplayPropertiesIfNeeded(this); + mBlockContactHelper.setContactInfo(mNumber); final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); mHasEditNumberBeforeCallOption = @@ -280,30 +298,38 @@ public class CallStatsDetailActivity extends Activity { @Override public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_edit_number_before_call).setVisible( - mHasEditNumberBeforeCallOption); + menu.findItem(R.id.menu_edit_number_before_call) + .setVisible(mHasEditNumberBeforeCallOption); + + boolean canBlock = mBlockContactHelper.canBlockContact(this); + menu.findItem(R.id.menu_block_contact) + .setVisible(canBlock) + .setTitle(canBlock && mBlockContactHelper.isContactBlacklisted() + ? R.string.menu_unblock_contact : R.string.menu_block_contact); + return super.onPrepareOptionsMenu(menu); } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { - case android.R.id.home: { + case android.R.id.home: onHomeSelected(); return true; + case R.id.menu_edit_number_before_call: + startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); + return true; + case R.id.menu_block_contact: { + DialogFragment f = mBlockContactHelper.getBlockContactDialog( + mBlockContactHelper.isContactBlacklisted() ? + BlockContactHelper.BlockOperation.UNBLOCK : + BlockContactHelper.BlockOperation.BLOCK + ); + f.show(getFragmentManager(), "block_contact"); + return true; } - // All the options menu items are handled by onMenu... methods. - default: - throw new IllegalArgumentException(); } - } - - public void onMenuEditNumberBeforeCall(MenuItem menuItem) { - startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); - } - - public void onMenuAddToBlacklist(MenuItem menuItem) { - mContactInfoHelper.addNumberToBlacklist(mNumber); + return false; } private void onHomeSelected() { |