From 690e1b5cc87003f939f57f80511e473458d17ac2 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 28 Oct 2015 18:04:59 -0700 Subject: Rename adapters to a more consistent plurality. ... really, this was just bugging me. I'm not trying to just pad my CL count. ;) Bug: 25343277 Change-Id: Ifa0e894415d64f373fc23b01eb6169b5fffd98ce --- .../filterednumber/BlockedNumberAdapter.java | 82 ------------- .../filterednumber/BlockedNumbersAdapter.java | 82 +++++++++++++ .../filterednumber/BlockedNumbersFragment.java | 4 +- .../dialer/filterednumber/NumberAdapter.java | 133 --------------------- .../dialer/filterednumber/NumbersAdapter.java | 133 +++++++++++++++++++++ .../filterednumber/ViewNumbersToImportAdapter.java | 2 +- 6 files changed, 218 insertions(+), 218 deletions(-) delete mode 100644 src/com/android/dialer/filterednumber/BlockedNumberAdapter.java create mode 100644 src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java delete mode 100644 src/com/android/dialer/filterednumber/NumberAdapter.java create mode 100644 src/com/android/dialer/filterednumber/NumbersAdapter.java diff --git a/src/com/android/dialer/filterednumber/BlockedNumberAdapter.java b/src/com/android/dialer/filterednumber/BlockedNumberAdapter.java deleted file mode 100644 index 76fc74320..000000000 --- a/src/com/android/dialer/filterednumber/BlockedNumberAdapter.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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. - */ -package com.android.dialer.filterednumber; - -import android.app.FragmentManager; -import android.database.Cursor; -import android.content.Context; -import android.view.View; - -import com.android.contacts.common.ContactPhotoManager; -import com.android.contacts.common.GeoUtil; -import com.android.dialer.R; -import com.android.dialer.calllog.ContactInfoHelper; -import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; - -public class BlockedNumberAdapter extends NumberAdapter { - - private BlockedNumberAdapter( - Context context, - FragmentManager fragmentManager, - ContactInfoHelper contactInfoHelper, - ContactPhotoManager contactPhotoManager) { - super(context, fragmentManager, contactInfoHelper, contactPhotoManager); - } - - public static BlockedNumberAdapter newBlockedNumberAdapter( - Context context, FragmentManager fragmentManager) { - return new BlockedNumberAdapter( - context, - fragmentManager, - new ContactInfoHelper(context, GeoUtil.getCurrentCountryIso(context)), - ContactPhotoManager.getInstance(context)); - } - - @Override - public void bindView(View view, 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( - FilteredNumberColumns.COUNTRY_ISO)); - final String number = cursor.getString(cursor.getColumnIndex(FilteredNumberColumns.NUMBER)); - final String normalizedNumber = cursor.getString(cursor.getColumnIndex( - FilteredNumberColumns.NORMALIZED_NUMBER)); - - final View deleteButton = view.findViewById(R.id.delete_button); - deleteButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - BlockNumberDialogFragment.show( - id, - normalizedNumber, - number, - countryIso, - number, - R.id.blocked_number_fragment, - getFragmentManager(), - null /* callback */); - } - }); - - updateView(view, number, countryIso); - } - - @Override - public boolean isEmpty() { - // Always return false, so that the header with blocking-related options always shows. - return false; - } -} diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java b/src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java new file mode 100644 index 000000000..71a054721 --- /dev/null +++ b/src/com/android/dialer/filterednumber/BlockedNumbersAdapter.java @@ -0,0 +1,82 @@ +/* + * 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. + */ +package com.android.dialer.filterednumber; + +import android.app.FragmentManager; +import android.database.Cursor; +import android.content.Context; +import android.view.View; + +import com.android.contacts.common.ContactPhotoManager; +import com.android.contacts.common.GeoUtil; +import com.android.dialer.R; +import com.android.dialer.calllog.ContactInfoHelper; +import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; + +public class BlockedNumbersAdapter extends NumbersAdapter { + + private BlockedNumbersAdapter( + Context context, + FragmentManager fragmentManager, + ContactInfoHelper contactInfoHelper, + ContactPhotoManager contactPhotoManager) { + super(context, fragmentManager, contactInfoHelper, contactPhotoManager); + } + + public static BlockedNumbersAdapter newBlockedNumbersAdapter( + Context context, FragmentManager fragmentManager) { + return new BlockedNumbersAdapter( + context, + fragmentManager, + new ContactInfoHelper(context, GeoUtil.getCurrentCountryIso(context)), + ContactPhotoManager.getInstance(context)); + } + + @Override + public void bindView(View view, 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( + FilteredNumberColumns.COUNTRY_ISO)); + final String number = cursor.getString(cursor.getColumnIndex(FilteredNumberColumns.NUMBER)); + final String normalizedNumber = cursor.getString(cursor.getColumnIndex( + FilteredNumberColumns.NORMALIZED_NUMBER)); + + final View deleteButton = view.findViewById(R.id.delete_button); + deleteButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + BlockNumberDialogFragment.show( + id, + normalizedNumber, + number, + countryIso, + number, + R.id.blocked_number_fragment, + getFragmentManager(), + null /* callback */); + } + }); + + updateView(view, number, countryIso); + } + + @Override + public boolean isEmpty() { + // Always return false, so that the header with blocking-related options always shows. + return false; + } +} diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java index 571c94ba2..36978885a 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java +++ b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java @@ -47,7 +47,7 @@ public class BlockedNumbersFragment extends ListFragment implements LoaderManager.LoaderCallbacks, View.OnClickListener, CallLogQueryHandler.Listener { - private BlockedNumberAdapter mAdapter; + private BlockedNumbersAdapter mAdapter; private CallLogQueryHandler mCallLogQueryHandler; private VoicemailStatusHelper mVoicemailStatusHelper; @@ -64,7 +64,7 @@ public class BlockedNumbersFragment extends ListFragment getListView().addHeaderView(inflater.inflate(R.layout.blocked_number_header, null)); if (mAdapter == null) { - mAdapter = BlockedNumberAdapter.newBlockedNumberAdapter( + mAdapter = BlockedNumbersAdapter.newBlockedNumbersAdapter( getContext(), getActivity().getFragmentManager()); } setListAdapter(mAdapter); diff --git a/src/com/android/dialer/filterednumber/NumberAdapter.java b/src/com/android/dialer/filterednumber/NumberAdapter.java deleted file mode 100644 index b212fa3e2..000000000 --- a/src/com/android/dialer/filterednumber/NumberAdapter.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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. - */ -package com.android.dialer.filterednumber; - -import android.app.Activity; -import android.app.FragmentManager; -import android.content.Context; -import android.content.res.Resources; -import android.provider.ContactsContract; -import android.text.BidiFormatter; -import android.text.TextDirectionHeuristics; -import android.text.TextUtils; -import android.view.View; -import android.widget.QuickContactBadge; -import android.widget.SimpleCursorAdapter; -import android.widget.TextView; - -import com.android.contacts.common.ContactPhotoManager; -import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; -import com.android.contacts.common.util.UriUtils; -import com.android.dialer.R; -import com.android.dialer.calllog.ContactInfo; -import com.android.dialer.calllog.ContactInfoHelper; -import com.android.dialer.util.PhoneNumberUtil; - -public class NumberAdapter extends SimpleCursorAdapter { - - private Context mContext; - private FragmentManager mFragmentManager; - private ContactInfoHelper mContactInfoHelper; - private Resources mResources; - private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); - private ContactPhotoManager mContactPhotoManager; - - public NumberAdapter( - Context context, - FragmentManager fragmentManager, - ContactInfoHelper contactInfoHelper, - ContactPhotoManager contactPhotoManager) { - super(context, R.layout.blocked_number_item, null, new String[]{}, new int[]{}, 0); - mContext = context; - mFragmentManager = fragmentManager; - mContactInfoHelper = contactInfoHelper; - mContactPhotoManager = contactPhotoManager; - } - - public void updateView(View view, String number, String countryIso) { - final TextView callerName = (TextView) view.findViewById(R.id.caller_name); - final TextView callerNumber = (TextView) view.findViewById(R.id.caller_number); - final QuickContactBadge quickContactBadge = - (QuickContactBadge) view.findViewById(R.id.quick_contact_photo); - quickContactBadge.setOverlay(null); - quickContactBadge.setPrioritizedMimeType( - ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); - - final ContactInfo info = mContactInfoHelper.lookupNumber(number, countryIso); - final CharSequence locationOrType = getNumberTypeOrLocation(info); - final String displayNumber = getDisplayNumber(info); - final String displayNumberStr = mBidiFormatter.unicodeWrap( - displayNumber.toString(), TextDirectionHeuristics.LTR); - - String nameForDefaultImage; - if (!TextUtils.isEmpty(info.name)) { - nameForDefaultImage = info.name; - callerName.setText(info.name); - callerNumber.setText(locationOrType + " " + displayNumberStr); - } else { - nameForDefaultImage = displayNumber; - callerName.setText(displayNumberStr); - if (!TextUtils.isEmpty(locationOrType)) { - callerNumber.setText(locationOrType); - callerNumber.setVisibility(View.VISIBLE); - } else { - callerNumber.setVisibility(View.GONE); - } - } - loadContactPhoto(info, nameForDefaultImage, quickContactBadge); - } - - private void loadContactPhoto(ContactInfo info, String displayName, QuickContactBadge badge) { - final String lookupKey = info.lookupUri == null - ? null : UriUtils.getLookupKeyFromUri(info.lookupUri); - final int contactType = mContactInfoHelper.isBusiness(info.sourceType) - ? ContactPhotoManager.TYPE_BUSINESS : ContactPhotoManager.TYPE_DEFAULT; - final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, - contactType, true /* isCircular */); - badge.assignContactUri(info.lookupUri); - badge.setContentDescription( - mContext.getResources().getString(R.string.description_contact_details, displayName)); - mContactPhotoManager.loadDirectoryPhoto(badge, info.photoUri, - false /* darkTheme */, true /* isCircular */, request); - } - - private String getDisplayNumber(ContactInfo info) { - if (!TextUtils.isEmpty(info.formattedNumber)) { - return info.formattedNumber; - } else if (!TextUtils.isEmpty(info.number)) { - return info.number; - } else { - return ""; - } - } - - private CharSequence getNumberTypeOrLocation(ContactInfo info) { - if (!TextUtils.isEmpty(info.name)) { - return ContactsContract.CommonDataKinds.Phone.getTypeLabel( - mContext.getResources(), info.type, info.label); - } else { - return PhoneNumberUtil.getGeoDescription(mContext, info.number); - } - } - - protected Context getContext() { - return mContext; - } - - protected FragmentManager getFragmentManager() { - return mFragmentManager; - } -} diff --git a/src/com/android/dialer/filterednumber/NumbersAdapter.java b/src/com/android/dialer/filterednumber/NumbersAdapter.java new file mode 100644 index 000000000..170610712 --- /dev/null +++ b/src/com/android/dialer/filterednumber/NumbersAdapter.java @@ -0,0 +1,133 @@ +/* + * 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. + */ +package com.android.dialer.filterednumber; + +import android.app.Activity; +import android.app.FragmentManager; +import android.content.Context; +import android.content.res.Resources; +import android.provider.ContactsContract; +import android.text.BidiFormatter; +import android.text.TextDirectionHeuristics; +import android.text.TextUtils; +import android.view.View; +import android.widget.QuickContactBadge; +import android.widget.SimpleCursorAdapter; +import android.widget.TextView; + +import com.android.contacts.common.ContactPhotoManager; +import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; +import com.android.contacts.common.util.UriUtils; +import com.android.dialer.R; +import com.android.dialer.calllog.ContactInfo; +import com.android.dialer.calllog.ContactInfoHelper; +import com.android.dialer.util.PhoneNumberUtil; + +public class NumbersAdapter extends SimpleCursorAdapter { + + private Context mContext; + private FragmentManager mFragmentManager; + private ContactInfoHelper mContactInfoHelper; + private Resources mResources; + private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); + private ContactPhotoManager mContactPhotoManager; + + public NumbersAdapter( + Context context, + FragmentManager fragmentManager, + ContactInfoHelper contactInfoHelper, + ContactPhotoManager contactPhotoManager) { + super(context, R.layout.blocked_number_item, null, new String[]{}, new int[]{}, 0); + mContext = context; + mFragmentManager = fragmentManager; + mContactInfoHelper = contactInfoHelper; + mContactPhotoManager = contactPhotoManager; + } + + public void updateView(View view, String number, String countryIso) { + final TextView callerName = (TextView) view.findViewById(R.id.caller_name); + final TextView callerNumber = (TextView) view.findViewById(R.id.caller_number); + final QuickContactBadge quickContactBadge = + (QuickContactBadge) view.findViewById(R.id.quick_contact_photo); + quickContactBadge.setOverlay(null); + quickContactBadge.setPrioritizedMimeType( + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); + + final ContactInfo info = mContactInfoHelper.lookupNumber(number, countryIso); + final CharSequence locationOrType = getNumberTypeOrLocation(info); + final String displayNumber = getDisplayNumber(info); + final String displayNumberStr = mBidiFormatter.unicodeWrap( + displayNumber.toString(), TextDirectionHeuristics.LTR); + + String nameForDefaultImage; + if (!TextUtils.isEmpty(info.name)) { + nameForDefaultImage = info.name; + callerName.setText(info.name); + callerNumber.setText(locationOrType + " " + displayNumberStr); + } else { + nameForDefaultImage = displayNumber; + callerName.setText(displayNumberStr); + if (!TextUtils.isEmpty(locationOrType)) { + callerNumber.setText(locationOrType); + callerNumber.setVisibility(View.VISIBLE); + } else { + callerNumber.setVisibility(View.GONE); + } + } + loadContactPhoto(info, nameForDefaultImage, quickContactBadge); + } + + private void loadContactPhoto(ContactInfo info, String displayName, QuickContactBadge badge) { + final String lookupKey = info.lookupUri == null + ? null : UriUtils.getLookupKeyFromUri(info.lookupUri); + final int contactType = mContactInfoHelper.isBusiness(info.sourceType) + ? ContactPhotoManager.TYPE_BUSINESS : ContactPhotoManager.TYPE_DEFAULT; + final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, + contactType, true /* isCircular */); + badge.assignContactUri(info.lookupUri); + badge.setContentDescription( + mContext.getResources().getString(R.string.description_contact_details, displayName)); + mContactPhotoManager.loadDirectoryPhoto(badge, info.photoUri, + false /* darkTheme */, true /* isCircular */, request); + } + + private String getDisplayNumber(ContactInfo info) { + if (!TextUtils.isEmpty(info.formattedNumber)) { + return info.formattedNumber; + } else if (!TextUtils.isEmpty(info.number)) { + return info.number; + } else { + return ""; + } + } + + private CharSequence getNumberTypeOrLocation(ContactInfo info) { + if (!TextUtils.isEmpty(info.name)) { + return ContactsContract.CommonDataKinds.Phone.getTypeLabel( + mContext.getResources(), info.type, info.label); + } else { + return PhoneNumberUtil.getGeoDescription(mContext, info.number); + } + } + + protected Context getContext() { + return mContext; + } + + protected FragmentManager getFragmentManager() { + return mFragmentManager; + } +} diff --git a/src/com/android/dialer/filterednumber/ViewNumbersToImportAdapter.java b/src/com/android/dialer/filterednumber/ViewNumbersToImportAdapter.java index 40b81c7b4..58fe1d46c 100644 --- a/src/com/android/dialer/filterednumber/ViewNumbersToImportAdapter.java +++ b/src/com/android/dialer/filterednumber/ViewNumbersToImportAdapter.java @@ -25,7 +25,7 @@ import com.android.contacts.common.GeoUtil; import com.android.dialer.R; import com.android.dialer.calllog.ContactInfoHelper; -public class ViewNumbersToImportAdapter extends NumberAdapter { +public class ViewNumbersToImportAdapter extends NumbersAdapter { private ViewNumbersToImportAdapter( Context context, -- cgit v1.2.3