diff options
author | calderwoodra <calderwoodra@google.com> | 2018-03-21 16:57:10 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-26 22:14:35 -0700 |
commit | 58d0b2a7cdd4b988f527f03a7cb4ba2a4b7cd145 (patch) | |
tree | 9f345f599109739aa93fe700981fc289dab0e66a /java/com/android/dialer/app/list | |
parent | 2213f8e4a91bf5bd39e8f55554f7020f0e6b5792 (diff) |
Delete old search, old contacts, p13n logger, filtered numbers add number search.
These components are safe to delete because:
- New Contacts has been in prod for several releases.
- New Search has been in in prod for 2 releases.
- p13n logger was based on old search and is no longer being implemented in
Dialer.
- Filtered Number Settings contact search since we no longer support M.
Bug: 37208802,73902692
Test: tap
PiperOrigin-RevId: 189992017
Change-Id: I2720a252ababd164b5d0fb1011753a3c96a704d1
Diffstat (limited to 'java/com/android/dialer/app/list')
10 files changed, 3 insertions, 1824 deletions
diff --git a/java/com/android/dialer/app/list/AllContactsFragment.java b/java/com/android/dialer/app/list/AllContactsFragment.java deleted file mode 100644 index 5076fd9cf..000000000 --- a/java/com/android/dialer/app/list/AllContactsFragment.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) 2013 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.app.list; - -import static android.Manifest.permission.READ_CONTACTS; - -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.Loader; -import android.content.pm.PackageManager; -import android.database.Cursor; -import android.net.Uri; -import android.provider.ContactsContract.CommonDataKinds.Phone; -import android.provider.ContactsContract.QuickContact; -import android.support.v13.app.FragmentCompat; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import com.android.contacts.common.list.ContactEntryListAdapter; -import com.android.contacts.common.list.ContactEntryListFragment; -import com.android.contacts.common.list.ContactListFilter; -import com.android.contacts.common.list.DefaultContactListAdapter; -import com.android.dialer.app.R; -import com.android.dialer.common.LogUtil; -import com.android.dialer.compat.CompatUtils; -import com.android.dialer.logging.InteractionEvent; -import com.android.dialer.logging.Logger; -import com.android.dialer.util.DialerUtils; -import com.android.dialer.util.IntentUtil; -import com.android.dialer.util.PermissionsUtil; -import com.android.dialer.widget.EmptyContentView; -import com.android.dialer.widget.EmptyContentView.OnEmptyViewActionButtonClickedListener; -import java.util.Arrays; - -/** Fragments to show all contacts with phone numbers. */ -public class AllContactsFragment extends ContactEntryListFragment<ContactEntryListAdapter> - implements OnEmptyViewActionButtonClickedListener, - FragmentCompat.OnRequestPermissionsResultCallback { - - private static final int READ_CONTACTS_PERMISSION_REQUEST_CODE = 1; - - private EmptyContentView emptyListView; - - /** - * Listen to broadcast events about permissions in order to be notified if the READ_CONTACTS - * permission is granted via the UI in another fragment. - */ - private BroadcastReceiver readContactsPermissionGrantedReceiver = - new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - reloadData(); - } - }; - - public AllContactsFragment() { - setQuickContactEnabled(false); - setAdjustSelectionBoundsEnabled(true); - setPhotoLoaderEnabled(true); - setSectionHeaderDisplayEnabled(true); - setDarkTheme(false); - setVisibleScrollbarEnabled(true); - } - - @Override - public void onViewCreated(View view, android.os.Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - emptyListView = (EmptyContentView) view.findViewById(R.id.empty_list_view); - emptyListView.setImage(R.drawable.empty_contacts); - emptyListView.setDescription(R.string.all_contacts_empty); - emptyListView.setActionClickedListener(this); - getListView().setEmptyView(emptyListView); - emptyListView.setVisibility(View.GONE); - } - - @Override - public void onStart() { - super.onStart(); - PermissionsUtil.registerPermissionReceiver( - getActivity(), readContactsPermissionGrantedReceiver, READ_CONTACTS); - } - - @Override - public void onStop() { - PermissionsUtil.unregisterPermissionReceiver( - getActivity(), readContactsPermissionGrantedReceiver); - super.onStop(); - } - - @Override - protected void startLoading() { - if (PermissionsUtil.hasPermission(getActivity(), READ_CONTACTS)) { - super.startLoading(); - emptyListView.setDescription(R.string.all_contacts_empty); - emptyListView.setActionLabel(R.string.all_contacts_empty_add_contact_action); - } else { - emptyListView.setDescription(R.string.permission_no_contacts); - emptyListView.setActionLabel(R.string.permission_single_turn_on); - emptyListView.setVisibility(View.VISIBLE); - } - } - - @Override - public void onLoadFinished(Loader<Cursor> loader, Cursor data) { - super.onLoadFinished(loader, data); - - if (data == null || data.getCount() == 0) { - emptyListView.setVisibility(View.VISIBLE); - } - } - - @Override - protected ContactEntryListAdapter createListAdapter() { - final DefaultContactListAdapter adapter = - new DefaultContactListAdapter(getActivity()) { - @Override - protected void bindView(View itemView, int partition, Cursor cursor, int position) { - super.bindView(itemView, partition, cursor, position); - itemView.setTag(this.getContactUri(partition, cursor)); - } - }; - adapter.setDisplayPhotos(true); - adapter.setFilter( - ContactListFilter.createFilterWithType(ContactListFilter.FILTER_TYPE_DEFAULT)); - adapter.setSectionHeaderDisplayEnabled(isSectionHeaderDisplayEnabled()); - return adapter; - } - - @Override - protected View inflateView(LayoutInflater inflater, ViewGroup container) { - return inflater.inflate(R.layout.all_contacts_fragment, null); - } - - @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - final Uri uri = (Uri) view.getTag(); - if (uri != null) { - Logger.get(getContext()) - .logInteraction(InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_ALL_CONTACTS_GENERAL); - if (CompatUtils.hasPrioritizedMimeType()) { - QuickContact.showQuickContact(getContext(), view, uri, null, Phone.CONTENT_ITEM_TYPE); - } else { - QuickContact.showQuickContact(getActivity(), view, uri, QuickContact.MODE_LARGE, null); - } - } - } - - @Override - protected void onItemClick(int position, long id) { - // Do nothing. Implemented to satisfy ContactEntryListFragment. - } - - @Override - public void onEmptyViewActionButtonClicked() { - final Activity activity = getActivity(); - if (activity == null) { - return; - } - - String[] deniedPermissions = - PermissionsUtil.getPermissionsCurrentlyDenied( - getContext(), PermissionsUtil.allContactsGroupPermissionsUsedInDialer); - if (deniedPermissions.length > 0) { - LogUtil.i( - "AllContactsFragment.onEmptyViewActionButtonClicked", - "Requesting permissions: " + Arrays.toString(deniedPermissions)); - FragmentCompat.requestPermissions( - this, deniedPermissions, READ_CONTACTS_PERMISSION_REQUEST_CODE); - } else { - // Add new contact - DialerUtils.startActivityWithErrorToast( - activity, IntentUtil.getNewContactIntent(), R.string.add_contact_not_available); - } - } - - @Override - public void onRequestPermissionsResult( - int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == READ_CONTACTS_PERMISSION_REQUEST_CODE) { - if (grantResults.length >= 1 && PackageManager.PERMISSION_GRANTED == grantResults[0]) { - // Force a refresh of the data since we were missing the permission before this. - reloadData(); - } - } - } -} diff --git a/java/com/android/dialer/app/list/BlockedListSearchAdapter.java b/java/com/android/dialer/app/list/BlockedListSearchAdapter.java deleted file mode 100644 index 575d6e63f..000000000 --- a/java/com/android/dialer/app/list/BlockedListSearchAdapter.java +++ /dev/null @@ -1,84 +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.app.list; - -import android.content.Context; -import android.content.res.Resources; -import android.database.Cursor; -import android.view.View; -import com.android.contacts.common.list.ContactListItemView; -import com.android.dialer.app.R; -import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; -import com.android.dialer.location.GeoUtil; - -/** List adapter to display search results for adding a blocked number. */ -public class BlockedListSearchAdapter extends RegularSearchListAdapter { - - private Resources resources; - private FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler; - - public BlockedListSearchAdapter(Context context) { - super(context); - resources = context.getResources(); - disableAllShortcuts(); - setShortcutEnabled(SHORTCUT_BLOCK_NUMBER, true); - - filteredNumberAsyncQueryHandler = new FilteredNumberAsyncQueryHandler(context); - } - - @Override - protected boolean isChanged(boolean showNumberShortcuts) { - return setShortcutEnabled(SHORTCUT_BLOCK_NUMBER, showNumberShortcuts || isQuerySipAddress); - } - - public void setViewBlocked(ContactListItemView view, Integer id) { - view.setTag(R.id.block_id, id); - final int textColor = resources.getColor(R.color.blocked_number_block_color); - view.getDataView().setTextColor(textColor); - view.getLabelView().setTextColor(textColor); - //TODO: Add icon - } - - public void setViewUnblocked(ContactListItemView view) { - view.setTag(R.id.block_id, null); - final int textColor = resources.getColor(R.color.dialer_secondary_text_color); - view.getDataView().setTextColor(textColor); - view.getLabelView().setTextColor(textColor); - //TODO: Remove icon - } - - @Override - protected void bindView(View itemView, int partition, Cursor cursor, int position) { - super.bindView(itemView, partition, cursor, position); - - final ContactListItemView view = (ContactListItemView) itemView; - // Reset view state to unblocked. - setViewUnblocked(view); - - final String number = getPhoneNumber(position); - final String countryIso = GeoUtil.getCurrentCountryIso(mContext); - final FilteredNumberAsyncQueryHandler.OnCheckBlockedListener onCheckListener = - new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() { - @Override - public void onCheckComplete(Integer id) { - if (id != null && id != FilteredNumberAsyncQueryHandler.INVALID_ID) { - setViewBlocked(view, id); - } - } - }; - filteredNumberAsyncQueryHandler.isBlockedNumber(onCheckListener, number, countryIso); - } -} diff --git a/java/com/android/dialer/app/list/BlockedListSearchFragment.java b/java/com/android/dialer/app/list/BlockedListSearchFragment.java deleted file mode 100644 index ce812af6e..000000000 --- a/java/com/android/dialer/app/list/BlockedListSearchFragment.java +++ /dev/null @@ -1,248 +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.app.list; - -import android.app.Activity; -import android.os.Bundle; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.text.Editable; -import android.text.TextUtils; -import android.text.TextWatcher; -import android.util.TypedValue; -import android.view.View; -import android.widget.AdapterView; -import android.widget.EditText; -import android.widget.Toast; -import com.android.contacts.common.list.ContactEntryListAdapter; -import com.android.contacts.common.util.ContactDisplayUtils; -import com.android.dialer.app.R; -import com.android.dialer.app.widget.SearchEditTextLayout; -import com.android.dialer.blocking.BlockNumberDialogFragment; -import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; -import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; -import com.android.dialer.common.LogUtil; -import com.android.dialer.location.GeoUtil; -import com.android.dialer.logging.InteractionEvent; -import com.android.dialer.logging.Logger; -import com.android.dialer.phonenumberutil.PhoneNumberHelper; - -/** TODO(calderwoodra): documentation */ -public class BlockedListSearchFragment extends RegularSearchFragment - implements BlockNumberDialogFragment.Callback { - - private final TextWatcher phoneSearchQueryTextListener = - new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - setQueryString(s.toString()); - } - - @Override - public void afterTextChanged(Editable s) {} - }; - private final SearchEditTextLayout.Callback searchLayoutCallback = - new SearchEditTextLayout.Callback() { - @Override - public void onBackButtonClicked() { - getActivity().onBackPressed(); - } - - @Override - public void onSearchViewClicked() {} - }; - private FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler; - private EditText searchView; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setShowEmptyListForNullQuery(true); - /* - * Pass in the empty string here so ContactEntryListFragment#setQueryString interprets it as - * an empty search query, rather than as an uninitalized value. In the latter case, the - * adapter returned by #createListAdapter is used, which populates the view with contacts. - * Passing in the empty string forces ContactEntryListFragment to interpret it as an empty - * query, which results in showing an empty view - */ - setQueryString(getQueryString() == null ? "" : getQueryString()); - filteredNumberAsyncQueryHandler = new FilteredNumberAsyncQueryHandler(getContext()); - } - - @Override - public void onResume() { - super.onResume(); - - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - actionBar.setCustomView(R.layout.search_edittext); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setDisplayHomeAsUpEnabled(false); - actionBar.setDisplayShowHomeEnabled(false); - - final SearchEditTextLayout searchEditTextLayout = - (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container); - searchEditTextLayout.expand(false, true); - searchEditTextLayout.setCallback(searchLayoutCallback); - searchEditTextLayout.setBackgroundDrawable(null); - - searchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view); - searchView.addTextChangedListener(phoneSearchQueryTextListener); - searchView.setHint(R.string.block_number_search_hint); - - searchEditTextLayout - .findViewById(R.id.search_box_expanded) - .setBackgroundColor(getContext().getResources().getColor(android.R.color.white)); - - if (!TextUtils.isEmpty(getQueryString())) { - searchView.setText(getQueryString()); - } - - // TODO: Don't set custom text size; use default search text size. - searchView.setTextSize( - TypedValue.COMPLEX_UNIT_PX, - getResources().getDimension(R.dimen.blocked_number_search_text_size)); - } - - @Override - protected ContactEntryListAdapter createListAdapter() { - BlockedListSearchAdapter adapter = new BlockedListSearchAdapter(getActivity()); - adapter.setDisplayPhotos(true); - // Don't show SIP addresses. - adapter.setUseCallableUri(false); - // Keep in sync with the queryString set in #onCreate - adapter.setQueryString(getQueryString() == null ? "" : getQueryString()); - return adapter; - } - - @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - super.onItemClick(parent, view, position, id); - final int adapterPosition = position - getListView().getHeaderViewsCount(); - final BlockedListSearchAdapter adapter = (BlockedListSearchAdapter) getAdapter(); - final int shortcutType = adapter.getShortcutTypeFromPosition(adapterPosition); - final Integer blockId = (Integer) view.getTag(R.id.block_id); - final String number; - switch (shortcutType) { - case DialerPhoneNumberListAdapter.SHORTCUT_INVALID: - // Handles click on a search result, either contact or nearby places result. - number = adapter.getPhoneNumber(adapterPosition); - blockContactNumber(number, blockId); - break; - case DialerPhoneNumberListAdapter.SHORTCUT_BLOCK_NUMBER: - // Handles click on 'Block number' shortcut to add the user query as a number. - number = adapter.getQueryString(); - blockNumber(number); - break; - default: - LogUtil.w( - "BlockedListSearchFragment.onItemClick", - "ignoring unsupported shortcut type: " + shortcutType); - break; - } - } - - @Override - protected void onItemClick(int position, long id) { - // Prevent SearchFragment.onItemClicked from being called. - } - - private void blockNumber(final String number) { - final String countryIso = GeoUtil.getCurrentCountryIso(getContext()); - final OnCheckBlockedListener onCheckListener = - new OnCheckBlockedListener() { - @Override - public void onCheckComplete(Integer id) { - if (id == null) { - BlockNumberDialogFragment.show( - id, - number, - countryIso, - PhoneNumberHelper.formatNumber(getContext(), number, countryIso), - R.id.blocked_numbers_activity_container, - getFragmentManager(), - BlockedListSearchFragment.this); - } else if (id == FilteredNumberAsyncQueryHandler.INVALID_ID) { - Toast.makeText( - getContext(), - ContactDisplayUtils.getTtsSpannedPhoneNumber( - getResources(), R.string.invalidNumber, number), - Toast.LENGTH_SHORT) - .show(); - } else { - Toast.makeText( - getContext(), - ContactDisplayUtils.getTtsSpannedPhoneNumber( - getResources(), R.string.alreadyBlocked, number), - Toast.LENGTH_SHORT) - .show(); - } - } - }; - filteredNumberAsyncQueryHandler.isBlockedNumber(onCheckListener, number, countryIso); - } - - @Override - public void onFilterNumberSuccess() { - Logger.get(getContext()).logInteraction(InteractionEvent.Type.BLOCK_NUMBER_MANAGEMENT_SCREEN); - goBack(); - } - - @Override - public void onUnfilterNumberSuccess() { - LogUtil.e( - "BlockedListSearchFragment.onUnfilterNumberSuccess", - "unblocked a number from the BlockedListSearchFragment"); - goBack(); - } - - private void goBack() { - Activity activity = getActivity(); - if (activity == null) { - return; - } - activity.onBackPressed(); - } - - @Override - public void onChangeFilteredNumberUndo() { - getAdapter().notifyDataSetChanged(); - } - - private void blockContactNumber(final String number, final Integer blockId) { - if (blockId != null) { - Toast.makeText( - getContext(), - ContactDisplayUtils.getTtsSpannedPhoneNumber( - getResources(), R.string.alreadyBlocked, number), - Toast.LENGTH_SHORT) - .show(); - return; - } - - BlockNumberDialogFragment.show( - blockId, - number, - GeoUtil.getCurrentCountryIso(getContext()), - number, - R.id.blocked_numbers_activity_container, - getFragmentManager(), - this); - } -} diff --git a/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java b/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java deleted file mode 100644 index d5609b856..000000000 --- a/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (C) 2016 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.app.list; - -import android.content.Context; -import android.content.res.Resources; -import android.database.Cursor; -import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; -import android.telephony.PhoneNumberUtils; -import android.text.BidiFormatter; -import android.text.TextDirectionHeuristics; -import android.view.View; -import android.view.ViewGroup; -import com.android.contacts.common.list.ContactListItemView; -import com.android.contacts.common.list.PhoneNumberListAdapter; -import com.android.contacts.common.util.ContactDisplayUtils; -import com.android.dialer.app.R; -import com.android.dialer.location.GeoUtil; -import com.android.dialer.phonenumberutil.PhoneNumberHelper; - -/** - * {@link PhoneNumberListAdapter} with the following added shortcuts, that are displayed as list - * items: 1) Directly calling the phone number query 2) Adding the phone number query to a contact - * - * <p>These shortcuts can be enabled or disabled to toggle whether or not they show up in the list. - */ -public class DialerPhoneNumberListAdapter extends PhoneNumberListAdapter { - - public static final int SHORTCUT_INVALID = -1; - public static final int SHORTCUT_DIRECT_CALL = 0; - public static final int SHORTCUT_CREATE_NEW_CONTACT = 1; - public static final int SHORTCUT_ADD_TO_EXISTING_CONTACT = 2; - public static final int SHORTCUT_SEND_SMS_MESSAGE = 3; - public static final int SHORTCUT_MAKE_VIDEO_CALL = 4; - public static final int SHORTCUT_BLOCK_NUMBER = 5; - public static final int SHORTCUT_COUNT = 6; - - private final boolean[] shortcutEnabled = new boolean[SHORTCUT_COUNT]; - private final BidiFormatter bidiFormatter = BidiFormatter.getInstance(); - private final String countryIso; - - private String formattedQueryString; - - public DialerPhoneNumberListAdapter(Context context) { - super(context); - - countryIso = GeoUtil.getCurrentCountryIso(context); - } - - @Override - public int getCount() { - return super.getCount() + getShortcutCount(); - } - - /** @return The number of enabled shortcuts. Ranges from 0 to a maximum of SHORTCUT_COUNT */ - public int getShortcutCount() { - int count = 0; - for (int i = 0; i < shortcutEnabled.length; i++) { - if (shortcutEnabled[i]) { - count++; - } - } - return count; - } - - public void disableAllShortcuts() { - for (int i = 0; i < shortcutEnabled.length; i++) { - shortcutEnabled[i] = false; - } - } - - @Override - public int getItemViewType(int position) { - final int shortcut = getShortcutTypeFromPosition(position); - if (shortcut >= 0) { - // shortcutPos should always range from 1 to SHORTCUT_COUNT - return super.getViewTypeCount() + shortcut; - } else { - return super.getItemViewType(position); - } - } - - @Override - public int getViewTypeCount() { - // Number of item view types in the super implementation + 2 for the 2 new shortcuts - return super.getViewTypeCount() + SHORTCUT_COUNT; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final int shortcutType = getShortcutTypeFromPosition(position); - if (shortcutType >= 0) { - if (convertView != null) { - assignShortcutToView((ContactListItemView) convertView, shortcutType); - return convertView; - } else { - final ContactListItemView v = - new ContactListItemView(getContext(), null, mIsImsVideoEnabled); - assignShortcutToView(v, shortcutType); - return v; - } - } else { - return super.getView(position, convertView, parent); - } - } - - @Override - protected ContactListItemView newView( - Context context, int partition, Cursor cursor, int position, ViewGroup parent) { - final ContactListItemView view = super.newView(context, partition, cursor, position, parent); - - view.setSupportVideoCallIcon(mIsImsVideoEnabled); - return view; - } - - /** - * @param position The position of the item - * @return The enabled shortcut type matching the given position if the item is a shortcut, -1 - * otherwise - */ - public int getShortcutTypeFromPosition(int position) { - int shortcutCount = position - super.getCount(); - if (shortcutCount >= 0) { - // Iterate through the array of shortcuts, looking only for shortcuts where - // mShortcutEnabled[i] is true - for (int i = 0; shortcutCount >= 0 && i < shortcutEnabled.length; i++) { - if (shortcutEnabled[i]) { - shortcutCount--; - if (shortcutCount < 0) { - return i; - } - } - } - throw new IllegalArgumentException( - "Invalid position - greater than cursor count " + " but not a shortcut."); - } - return SHORTCUT_INVALID; - } - - @Override - public boolean isEmpty() { - return getShortcutCount() == 0 && super.isEmpty(); - } - - @Override - public boolean isEnabled(int position) { - final int shortcutType = getShortcutTypeFromPosition(position); - if (shortcutType >= 0) { - return true; - } else { - return super.isEnabled(position); - } - } - - private void assignShortcutToView(ContactListItemView v, int shortcutType) { - final CharSequence text; - final Drawable drawable; - final Resources resources = getContext().getResources(); - final String number = getFormattedQueryString(); - switch (shortcutType) { - case SHORTCUT_DIRECT_CALL: - text = - ContactDisplayUtils.getTtsSpannedPhoneNumber( - resources, - R.string.search_shortcut_call_number, - bidiFormatter.unicodeWrap(number, TextDirectionHeuristics.LTR)); - drawable = ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_call_vd_theme_24); - break; - case SHORTCUT_CREATE_NEW_CONTACT: - text = resources.getString(R.string.search_shortcut_create_new_contact); - drawable = - ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_person_add_vd_theme_24); - drawable.setAutoMirrored(true); - break; - case SHORTCUT_ADD_TO_EXISTING_CONTACT: - text = resources.getString(R.string.search_shortcut_add_to_contact); - drawable = - ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_person_add_vd_theme_24); - break; - case SHORTCUT_SEND_SMS_MESSAGE: - text = resources.getString(R.string.search_shortcut_send_sms_message); - drawable = - ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_message_vd_theme_24); - break; - case SHORTCUT_MAKE_VIDEO_CALL: - text = resources.getString(R.string.search_shortcut_make_video_call); - drawable = - ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_videocam_vd_theme_24); - break; - case SHORTCUT_BLOCK_NUMBER: - text = resources.getString(R.string.search_shortcut_block_number); - drawable = - ContextCompat.getDrawable(getContext(), R.drawable.ic_not_interested_googblue_24dp); - break; - default: - throw new IllegalArgumentException("Invalid shortcut type"); - } - v.setDrawable(drawable); - v.setDisplayName(text); - v.setAdjustSelectionBoundsEnabled(false); - } - - /** @return True if the shortcut state (disabled vs enabled) was changed by this operation */ - public boolean setShortcutEnabled(int shortcutType, boolean visible) { - final boolean changed = shortcutEnabled[shortcutType] != visible; - shortcutEnabled[shortcutType] = visible; - return changed; - } - - public String getFormattedQueryString() { - return formattedQueryString; - } - - @Override - public void setQueryString(String queryString) { - formattedQueryString = - PhoneNumberHelper.formatNumber( - getContext(), PhoneNumberUtils.normalizeNumber(queryString), countryIso); - super.setQueryString(queryString); - } -} diff --git a/java/com/android/dialer/app/list/DialtactsPagerAdapter.java b/java/com/android/dialer/app/list/DialtactsPagerAdapter.java index d27293244..364ae6fad 100644 --- a/java/com/android/dialer/app/list/DialtactsPagerAdapter.java +++ b/java/com/android/dialer/app/list/DialtactsPagerAdapter.java @@ -56,11 +56,9 @@ public class DialtactsPagerAdapter extends FragmentPagerAdapter { private final List<Fragment> fragments = new ArrayList<>(); private final String[] tabTitles; private final boolean useNewSpeedDialTab; - private final boolean useNewContactsTab; private OldSpeedDialFragment oldSpeedDialFragment; private SpeedDialFragment speedDialFragment; private CallLogFragment callLogFragment; - private AllContactsFragment oldContactsFragment; private ContactsFragment contactsFragment; private CallLogFragment voicemailFragment; @@ -71,8 +69,6 @@ public class DialtactsPagerAdapter extends FragmentPagerAdapter { super(fm); useNewSpeedDialTab = ConfigProviderBindings.get(context).getBoolean("enable_new_favorites_tab", false); - useNewContactsTab = - ConfigProviderBindings.get(context).getBoolean("enable_new_contacts_tab", true); this.tabTitles = tabTitles; hasActiveVoicemailProvider = hasVoicemailProvider; fragments.addAll(Collections.nCopies(TAB_COUNT_WITH_VOICEMAIL, null)); @@ -105,17 +101,10 @@ public class DialtactsPagerAdapter extends FragmentPagerAdapter { } return callLogFragment; case TAB_INDEX_ALL_CONTACTS: - if (useNewContactsTab) { - if (contactsFragment == null) { - contactsFragment = ContactsFragment.newInstance(Header.ADD_CONTACT); - } - return contactsFragment; - } else { - if (oldContactsFragment == null) { - oldContactsFragment = new AllContactsFragment(); - } - return oldContactsFragment; + if (contactsFragment == null) { + contactsFragment = ContactsFragment.newInstance(Header.ADD_CONTACT); } + return contactsFragment; case TAB_INDEX_VOICEMAIL: if (voicemailFragment == null) { voicemailFragment = new VisualVoicemailCallLogFragment(); @@ -145,8 +134,6 @@ public class DialtactsPagerAdapter extends FragmentPagerAdapter { callLogFragment = (CallLogFragment) fragment; } else if (fragment instanceof ContactsFragment) { contactsFragment = (ContactsFragment) fragment; - } else if (fragment instanceof AllContactsFragment) { - oldContactsFragment = (AllContactsFragment) fragment; } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_VOICEMAIL) { voicemailFragment = (CallLogFragment) fragment; LogUtil.v("ViewPagerAdapter.instantiateItem", voicemailFragment.toString()); diff --git a/java/com/android/dialer/app/list/RegularSearchFragment.java b/java/com/android/dialer/app/list/RegularSearchFragment.java deleted file mode 100644 index d1927f08a..000000000 --- a/java/com/android/dialer/app/list/RegularSearchFragment.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2013 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.app.list; - -import static android.Manifest.permission.READ_CONTACTS; - -import android.app.Activity; -import android.content.Context; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v13.app.FragmentCompat; -import android.view.LayoutInflater; -import android.view.ViewGroup; -import com.android.contacts.common.list.ContactEntryListAdapter; -import com.android.contacts.common.list.PinnedHeaderListView; -import com.android.dialer.app.R; -import com.android.dialer.callintent.CallInitiationType; -import com.android.dialer.common.LogUtil; -import com.android.dialer.common.concurrent.DialerExecutor; -import com.android.dialer.common.concurrent.DialerExecutor.Worker; -import com.android.dialer.common.concurrent.DialerExecutorComponent; -import com.android.dialer.phonenumbercache.CachedNumberLookupService; -import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo; -import com.android.dialer.phonenumbercache.PhoneNumberCache; -import com.android.dialer.util.PermissionsUtil; -import com.android.dialer.widget.EmptyContentView; -import com.android.dialer.widget.EmptyContentView.OnEmptyViewActionButtonClickedListener; -import java.util.Arrays; - -public class RegularSearchFragment extends SearchFragment - implements OnEmptyViewActionButtonClickedListener, - FragmentCompat.OnRequestPermissionsResultCallback { - - public static final int PERMISSION_REQUEST_CODE = 1; - - private static final int SEARCH_DIRECTORY_RESULT_LIMIT = 5; - protected String permissionToRequest; - - private DialerExecutor<CachedContactInfo> addContactTask; - - public RegularSearchFragment() { - configureDirectorySearch(); - } - - public void configureDirectorySearch() { - setDirectorySearchEnabled(true); - setDirectoryResultLimit(SEARCH_DIRECTORY_RESULT_LIMIT); - } - - @Override - public void onCreate(Bundle savedState) { - super.onCreate(savedState); - - addContactTask = - DialerExecutorComponent.get(getContext()) - .dialerExecutorFactory() - .createUiTaskBuilder( - getFragmentManager(), - "RegularSearchFragment.addContact", - new AddContactWorker(getContext().getApplicationContext())) - .build(); - } - - @Override - protected void onCreateView(LayoutInflater inflater, ViewGroup container) { - super.onCreateView(inflater, container); - ((PinnedHeaderListView) getListView()).setScrollToSectionOnHeaderTouch(true); - } - - @Override - protected ContactEntryListAdapter createListAdapter() { - RegularSearchListAdapter adapter = new RegularSearchListAdapter(getActivity()); - adapter.setDisplayPhotos(true); - adapter.setUseCallableUri(usesCallableUri()); - adapter.setListener(this); - return adapter; - } - - @Override - protected void cacheContactInfo(int position) { - CachedNumberLookupService cachedNumberLookupService = - PhoneNumberCache.get(getContext()).getCachedNumberLookupService(); - if (cachedNumberLookupService != null) { - final RegularSearchListAdapter adapter = (RegularSearchListAdapter) getAdapter(); - CachedContactInfo cachedContactInfo = - adapter.getContactInfo(cachedNumberLookupService, position); - addContactTask.executeSerial(cachedContactInfo); - } - } - - @Override - protected void setupEmptyView() { - if (emptyView != null && getActivity() != null) { - final int imageResource; - final int actionLabelResource; - final int descriptionResource; - final OnEmptyViewActionButtonClickedListener listener; - if (!PermissionsUtil.hasPermission(getActivity(), READ_CONTACTS)) { - imageResource = R.drawable.empty_contacts; - actionLabelResource = R.string.permission_single_turn_on; - descriptionResource = R.string.permission_no_search; - listener = this; - permissionToRequest = READ_CONTACTS; - } else { - imageResource = EmptyContentView.NO_IMAGE; - actionLabelResource = EmptyContentView.NO_LABEL; - descriptionResource = EmptyContentView.NO_LABEL; - listener = null; - permissionToRequest = null; - } - - emptyView.setImage(imageResource); - emptyView.setActionLabel(actionLabelResource); - emptyView.setDescription(descriptionResource); - if (listener != null) { - emptyView.setActionClickedListener(listener); - } - } - } - - @Override - public void onEmptyViewActionButtonClicked() { - final Activity activity = getActivity(); - if (activity == null) { - return; - } - - if (READ_CONTACTS.equals(permissionToRequest)) { - String[] deniedPermissions = - PermissionsUtil.getPermissionsCurrentlyDenied( - getContext(), PermissionsUtil.allContactsGroupPermissionsUsedInDialer); - if (deniedPermissions.length > 0) { - LogUtil.i( - "RegularSearchFragment.onEmptyViewActionButtonClicked", - "Requesting permissions: " + Arrays.toString(deniedPermissions)); - FragmentCompat.requestPermissions(this, deniedPermissions, PERMISSION_REQUEST_CODE); - } - } - } - - @Override - public void onRequestPermissionsResult( - int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == PERMISSION_REQUEST_CODE) { - setupEmptyView(); - if (grantResults != null - && grantResults.length == 1 - && PackageManager.PERMISSION_GRANTED == grantResults[0]) { - PermissionsUtil.notifyPermissionGranted(getActivity(), permissions[0]); - } - } - } - - @Override - protected CallInitiationType.Type getCallInitiationType(boolean isRemoteDirectory) { - return isRemoteDirectory - ? CallInitiationType.Type.REMOTE_DIRECTORY - : CallInitiationType.Type.REGULAR_SEARCH; - } - - public interface CapabilityChecker { - - boolean isNearbyPlacesSearchEnabled(); - } - - private static class AddContactWorker implements Worker<CachedContactInfo, Void> { - - private final Context appContext; - - private AddContactWorker(Context appContext) { - this.appContext = appContext; - } - - @Nullable - @Override - public Void doInBackground(@Nullable CachedContactInfo contactInfo) throws Throwable { - CachedNumberLookupService cachedNumberLookupService = - PhoneNumberCache.get(appContext).getCachedNumberLookupService(); - if (cachedNumberLookupService != null) { - cachedNumberLookupService.addContact(appContext, contactInfo); - } - return null; - } - } -} diff --git a/java/com/android/dialer/app/list/RegularSearchListAdapter.java b/java/com/android/dialer/app/list/RegularSearchListAdapter.java deleted file mode 100644 index c92f48c8b..000000000 --- a/java/com/android/dialer/app/list/RegularSearchListAdapter.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2013 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.app.list; - -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.text.TextUtils; -import com.android.contacts.common.ContactsUtils; -import com.android.contacts.common.list.DirectoryPartition; -import com.android.dialer.common.cp2.DirectoryCompat; -import com.android.dialer.phonenumbercache.CachedNumberLookupService; -import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo; -import com.android.dialer.phonenumbercache.ContactInfo; -import com.android.dialer.phonenumberutil.PhoneNumberHelper; -import com.android.dialer.util.CallUtil; - -/** List adapter to display regular search results. */ -public class RegularSearchListAdapter extends DialerPhoneNumberListAdapter { - - protected boolean isQuerySipAddress; - - public RegularSearchListAdapter(Context context) { - super(context); - setShortcutEnabled(SHORTCUT_CREATE_NEW_CONTACT, false); - setShortcutEnabled(SHORTCUT_ADD_TO_EXISTING_CONTACT, false); - } - - public CachedContactInfo getContactInfo(CachedNumberLookupService lookupService, int position) { - ContactInfo info = new ContactInfo(); - CachedContactInfo cacheInfo = lookupService.buildCachedContactInfo(info); - final Cursor item = (Cursor) getItem(position); - if (item != null) { - final DirectoryPartition partition = - (DirectoryPartition) getPartition(getPartitionForPosition(position)); - final long directoryId = partition.getDirectoryId(); - final boolean isExtendedDirectory = isExtendedDirectory(directoryId); - - info.name = item.getString(PhoneQuery.DISPLAY_NAME); - info.type = item.getInt(PhoneQuery.PHONE_TYPE); - info.label = item.getString(PhoneQuery.PHONE_LABEL); - info.number = item.getString(PhoneQuery.PHONE_NUMBER); - final String photoUriStr = item.getString(PhoneQuery.PHOTO_URI); - info.photoUri = photoUriStr == null ? null : Uri.parse(photoUriStr); - /* - * An extended directory is custom directory in the app, but not a directory provided by - * framework. So it can't be USER_TYPE_WORK. - * - * When a search result is selected, RegularSearchFragment calls getContactInfo and - * cache the resulting @{link ContactInfo} into local db. Set usertype to USER_TYPE_WORK - * only if it's NOT extended directory id and is enterprise directory. - */ - info.userType = - !isExtendedDirectory && DirectoryCompat.isEnterpriseDirectoryId(directoryId) - ? ContactsUtils.USER_TYPE_WORK - : ContactsUtils.USER_TYPE_CURRENT; - - cacheInfo.setLookupKey(item.getString(PhoneQuery.LOOKUP_KEY)); - - final String sourceName = partition.getLabel(); - if (isExtendedDirectory) { - cacheInfo.setExtendedSource(sourceName, directoryId); - } else { - cacheInfo.setDirectorySource(sourceName, directoryId); - } - } - return cacheInfo; - } - - @Override - public String getFormattedQueryString() { - if (isQuerySipAddress) { - // Return unnormalized SIP address - return getQueryString(); - } - return super.getFormattedQueryString(); - } - - @Override - public void setQueryString(String queryString) { - // Don't show actions if the query string contains a letter. - final boolean showNumberShortcuts = - !TextUtils.isEmpty(getFormattedQueryString()) && hasDigitsInQueryString(); - isQuerySipAddress = PhoneNumberHelper.isUriNumber(queryString); - - if (isChanged(showNumberShortcuts)) { - notifyDataSetChanged(); - } - super.setQueryString(queryString); - } - - protected boolean isChanged(boolean showNumberShortcuts) { - boolean changed = false; - changed |= setShortcutEnabled(SHORTCUT_DIRECT_CALL, showNumberShortcuts || isQuerySipAddress); - changed |= setShortcutEnabled(SHORTCUT_SEND_SMS_MESSAGE, showNumberShortcuts); - changed |= - setShortcutEnabled( - SHORTCUT_MAKE_VIDEO_CALL, showNumberShortcuts && CallUtil.isVideoEnabled(getContext())); - return changed; - } - - /** Whether there is at least one digit in the query string. */ - private boolean hasDigitsInQueryString() { - String queryString = getQueryString(); - int length = queryString.length(); - for (int i = 0; i < length; i++) { - if (Character.isDigit(queryString.charAt(i))) { - return true; - } - } - return false; - } -} diff --git a/java/com/android/dialer/app/list/SearchFragment.java b/java/com/android/dialer/app/list/SearchFragment.java deleted file mode 100644 index afb678969..000000000 --- a/java/com/android/dialer/app/list/SearchFragment.java +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (C) 2013 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.app.list; - -import android.animation.Animator; -import android.animation.AnimatorInflater; -import android.animation.AnimatorListenerAdapter; -import android.app.Activity; -import android.app.DialogFragment; -import android.content.Intent; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Interpolator; -import android.widget.AbsListView; -import android.widget.AbsListView.OnScrollListener; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.Space; -import com.android.contacts.common.list.ContactEntryListAdapter; -import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; -import com.android.contacts.common.list.PhoneNumberPickerFragment; -import com.android.dialer.animation.AnimUtils; -import com.android.dialer.app.R; -import com.android.dialer.app.widget.DialpadSearchEmptyContentView; -import com.android.dialer.callintent.CallSpecificAppData; -import com.android.dialer.common.LogUtil; -import com.android.dialer.dialpadview.DialpadFragment.ErrorDialogFragment; -import com.android.dialer.logging.DialerImpression; -import com.android.dialer.logging.Logger; -import com.android.dialer.util.DialerUtils; -import com.android.dialer.util.IntentUtil; -import com.android.dialer.util.PermissionsUtil; -import com.android.dialer.widget.EmptyContentView; - -public class SearchFragment extends PhoneNumberPickerFragment { - - protected EmptyContentView emptyView; - private OnListFragmentScrolledListener activityScrollListener; - private View.OnTouchListener activityOnTouchListener; - /* - * Stores the untouched user-entered string that is used to populate the add to contacts - * intent. - */ - private String addToContactNumber; - private int actionBarHeight; - private int shadowHeight; - private int paddingTop; - private int showDialpadDuration; - private int hideDialpadDuration; - /** - * Used to resize the list view containing search results so that it fits the available space - * above the dialpad. Does not have a user-visible effect in regular touch usage (since the - * dialpad hides that portion of the ListView anyway), but improves usability in accessibility - * mode. - */ - private Space spacer; - - private HostInterface activity; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - setQuickContactEnabled(true); - setAdjustSelectionBoundsEnabled(false); - setDarkTheme(false); - setUseCallableUri(true); - - try { - activityScrollListener = (OnListFragmentScrolledListener) activity; - } catch (ClassCastException e) { - LogUtil.v( - "SearchFragment.onAttach", - activity.toString() - + " doesn't implement OnListFragmentScrolledListener. " - + "Ignoring."); - } - } - - @Override - public void onStart() { - LogUtil.d("SearchFragment.onStart", ""); - super.onStart(); - - activity = (HostInterface) getActivity(); - - final Resources res = getResources(); - actionBarHeight = activity.getActionBarHeight(); - shadowHeight = res.getDrawable(R.drawable.search_shadow).getIntrinsicHeight(); - paddingTop = res.getDimensionPixelSize(R.dimen.search_list_padding_top); - showDialpadDuration = res.getInteger(R.integer.dialpad_slide_in_duration); - hideDialpadDuration = res.getInteger(R.integer.dialpad_slide_out_duration); - - final ListView listView = getListView(); - - if (emptyView == null) { - if (this instanceof SmartDialSearchFragment) { - emptyView = new DialpadSearchEmptyContentView(getActivity()); - } else { - emptyView = new EmptyContentView(getActivity()); - } - ((ViewGroup) getListView().getParent()).addView(emptyView); - getListView().setEmptyView(emptyView); - setupEmptyView(); - } - - listView.setBackgroundColor(res.getColor(R.color.background_dialer_results)); - listView.setClipToPadding(false); - setVisibleScrollbarEnabled(false); - - //Turn of accessibility live region as the list constantly update itself and spam messages. - listView.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_NONE); - ContentChangedFilter.addToParent(listView); - - listView.setOnScrollListener( - new OnScrollListener() { - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - if (activityScrollListener != null) { - activityScrollListener.onListFragmentScrollStateChange(scrollState); - } - } - - @Override - public void onScroll( - AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {} - }); - if (activityOnTouchListener != null) { - listView.setOnTouchListener(activityOnTouchListener); - } - - updatePosition(false /* animate */); - } - - @Override - public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { - Animator animator = null; - if (nextAnim != 0) { - animator = AnimatorInflater.loadAnimator(getActivity(), nextAnim); - } - if (animator != null) { - final View view = getView(); - final int oldLayerType = view.getLayerType(); - animator.addListener( - new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - view.setLayerType(oldLayerType, null); - } - }); - } - return animator; - } - - public void setAddToContactNumber(String addToContactNumber) { - this.addToContactNumber = addToContactNumber; - } - - /** - * Return true if phone number is prohibited by a value - - * (R.string.config_prohibited_phone_number_regexp) in the config files. False otherwise. - */ - public boolean checkForProhibitedPhoneNumber(String number) { - // Regular expression prohibiting manual phone call. Can be empty i.e. "no rule". - String prohibitedPhoneNumberRegexp = - getResources().getString(R.string.config_prohibited_phone_number_regexp); - - // "persist.radio.otaspdial" is a temporary hack needed for one carrier's automated - // test equipment. - if (number != null - && !TextUtils.isEmpty(prohibitedPhoneNumberRegexp) - && number.matches(prohibitedPhoneNumberRegexp)) { - LogUtil.i( - "SearchFragment.checkForProhibitedPhoneNumber", - "the phone number is prohibited explicitly by a rule"); - if (getActivity() != null) { - DialogFragment dialogFragment = - ErrorDialogFragment.newInstance(R.string.dialog_phone_call_prohibited_message); - dialogFragment.show(getFragmentManager(), "phone_prohibited_dialog"); - } - - return true; - } - return false; - } - - @Override - protected ContactEntryListAdapter createListAdapter() { - DialerPhoneNumberListAdapter adapter = new DialerPhoneNumberListAdapter(getActivity()); - adapter.setDisplayPhotos(true); - adapter.setUseCallableUri(super.usesCallableUri()); - adapter.setListener(this); - return adapter; - } - - @Override - protected void onItemClick(int position, long id) { - final DialerPhoneNumberListAdapter adapter = (DialerPhoneNumberListAdapter) getAdapter(); - final int shortcutType = adapter.getShortcutTypeFromPosition(position); - final OnPhoneNumberPickerActionListener listener; - final Intent intent; - final String number; - - LogUtil.i("SearchFragment.onItemClick", "shortcutType: " + shortcutType); - - switch (shortcutType) { - case DialerPhoneNumberListAdapter.SHORTCUT_DIRECT_CALL: - number = adapter.getQueryString(); - listener = getOnPhoneNumberPickerListener(); - if (listener != null && !checkForProhibitedPhoneNumber(number)) { - CallSpecificAppData callSpecificAppData = - CallSpecificAppData.newBuilder() - .setCallInitiationType(getCallInitiationType(false /* isRemoteDirectory */)) - .setPositionOfSelectedSearchResult(position) - .setCharactersInSearchString( - getQueryString() == null ? 0 : getQueryString().length()) - .build(); - listener.onPickPhoneNumber(number, false /* isVideoCall */, callSpecificAppData); - } - break; - case DialerPhoneNumberListAdapter.SHORTCUT_CREATE_NEW_CONTACT: - if (this instanceof SmartDialSearchFragment) { - Logger.get(getContext()) - .logImpression(DialerImpression.Type.CREATE_NEW_CONTACT_FROM_DIALPAD); - } - number = - TextUtils.isEmpty(addToContactNumber) - ? adapter.getFormattedQueryString() - : addToContactNumber; - intent = IntentUtil.getNewContactIntent(number); - DialerUtils.startActivityWithErrorToast(getActivity(), intent); - break; - case DialerPhoneNumberListAdapter.SHORTCUT_ADD_TO_EXISTING_CONTACT: - if (this instanceof SmartDialSearchFragment) { - Logger.get(getContext()) - .logImpression(DialerImpression.Type.ADD_TO_A_CONTACT_FROM_DIALPAD); - } - number = - TextUtils.isEmpty(addToContactNumber) - ? adapter.getFormattedQueryString() - : addToContactNumber; - intent = IntentUtil.getAddToExistingContactIntent(number); - DialerUtils.startActivityWithErrorToast( - getActivity(), intent, R.string.add_contact_not_available); - break; - case DialerPhoneNumberListAdapter.SHORTCUT_SEND_SMS_MESSAGE: - number = - TextUtils.isEmpty(addToContactNumber) - ? adapter.getFormattedQueryString() - : addToContactNumber; - intent = IntentUtil.getSendSmsIntent(number); - DialerUtils.startActivityWithErrorToast(getActivity(), intent); - break; - case DialerPhoneNumberListAdapter.SHORTCUT_MAKE_VIDEO_CALL: - number = - TextUtils.isEmpty(addToContactNumber) ? adapter.getQueryString() : addToContactNumber; - listener = getOnPhoneNumberPickerListener(); - if (listener != null && !checkForProhibitedPhoneNumber(number)) { - CallSpecificAppData callSpecificAppData = - CallSpecificAppData.newBuilder() - .setCallInitiationType(getCallInitiationType(false /* isRemoteDirectory */)) - .setPositionOfSelectedSearchResult(position) - .setCharactersInSearchString( - getQueryString() == null ? 0 : getQueryString().length()) - .build(); - listener.onPickPhoneNumber(number, true /* isVideoCall */, callSpecificAppData); - } - break; - case DialerPhoneNumberListAdapter.SHORTCUT_INVALID: - default: - super.onItemClick(position, id); - break; - } - } - - /** - * Updates the position and padding of the search fragment, depending on whether the dialpad is - * shown. This can be optionally animated. - */ - public void updatePosition(boolean animate) { - LogUtil.d("SearchFragment.updatePosition", "animate: %b", animate); - if (activity == null) { - // Activity will be set in onStart, and this method will be called again - return; - } - - // Use negative shadow height instead of 0 to account for the 9-patch's shadow. - int startTranslationValue = - activity.isDialpadShown() ? actionBarHeight - shadowHeight : -shadowHeight; - int endTranslationValue = 0; - // Prevents ListView from being translated down after a rotation when the ActionBar is up. - if (animate || activity.isActionBarShowing()) { - endTranslationValue = activity.isDialpadShown() ? 0 : actionBarHeight - shadowHeight; - } - if (animate) { - // If the dialpad will be shown, then this animation involves sliding the list up. - final boolean slideUp = activity.isDialpadShown(); - - Interpolator interpolator = slideUp ? AnimUtils.EASE_IN : AnimUtils.EASE_OUT; - int duration = slideUp ? showDialpadDuration : hideDialpadDuration; - getView().setTranslationY(startTranslationValue); - getView() - .animate() - .translationY(endTranslationValue) - .setInterpolator(interpolator) - .setDuration(duration) - .setListener( - new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animation) { - if (!slideUp) { - resizeListView(); - } - } - - @Override - public void onAnimationEnd(Animator animation) { - if (slideUp) { - resizeListView(); - } - } - }); - - } else { - getView().setTranslationY(endTranslationValue); - resizeListView(); - } - - // There is padding which should only be applied when the dialpad is not shown. - int paddingTop = activity.isDialpadShown() ? 0 : this.paddingTop; - final ListView listView = getListView(); - listView.setPaddingRelative( - listView.getPaddingStart(), - paddingTop, - listView.getPaddingEnd(), - listView.getPaddingBottom()); - } - - public void resizeListView() { - if (spacer == null) { - return; - } - int spacerHeight = activity.isDialpadShown() ? activity.getDialpadHeight() : 0; - LogUtil.d( - "SearchFragment.resizeListView", - "spacerHeight: %d -> %d, isDialpadShown: %b, dialpad height: %d", - spacer.getHeight(), - spacerHeight, - activity.isDialpadShown(), - activity.getDialpadHeight()); - if (spacerHeight != spacer.getHeight()) { - final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) spacer.getLayoutParams(); - lp.height = spacerHeight; - spacer.setLayoutParams(lp); - } - } - - @Override - protected void startLoading() { - if (getActivity() == null) { - return; - } - - if (PermissionsUtil.hasContactsReadPermissions(getActivity())) { - super.startLoading(); - } else if (TextUtils.isEmpty(getQueryString())) { - // Clear out any existing call shortcuts. - final DialerPhoneNumberListAdapter adapter = (DialerPhoneNumberListAdapter) getAdapter(); - adapter.disableAllShortcuts(); - } else { - // The contact list is not going to change (we have no results since permissions are - // denied), but the shortcuts might because of the different query, so update the - // list. - getAdapter().notifyDataSetChanged(); - } - - setupEmptyView(); - } - - public void setOnTouchListener(View.OnTouchListener onTouchListener) { - activityOnTouchListener = onTouchListener; - } - - @Override - protected View inflateView(LayoutInflater inflater, ViewGroup container) { - final LinearLayout parent = (LinearLayout) super.inflateView(inflater, container); - final int orientation = getResources().getConfiguration().orientation; - if (orientation == Configuration.ORIENTATION_PORTRAIT) { - spacer = new Space(getActivity()); - parent.addView( - spacer, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0)); - } - return parent; - } - - protected void setupEmptyView() {} - - public interface HostInterface { - - boolean isActionBarShowing(); - - boolean isDialpadShown(); - - int getDialpadHeight(); - - int getActionBarHeight(); - } -} diff --git a/java/com/android/dialer/app/list/SmartDialNumberListAdapter.java b/java/com/android/dialer/app/list/SmartDialNumberListAdapter.java deleted file mode 100644 index c84bff7fc..000000000 --- a/java/com/android/dialer/app/list/SmartDialNumberListAdapter.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2013 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.app.list; - -import android.content.Context; -import android.database.Cursor; -import android.support.annotation.NonNull; -import android.telephony.PhoneNumberUtils; -import android.text.TextUtils; -import com.android.contacts.common.list.ContactListItemView; -import com.android.dialer.common.LogUtil; -import com.android.dialer.smartdial.SmartDialCursorLoader; -import com.android.dialer.smartdial.util.SmartDialMatchPosition; -import com.android.dialer.smartdial.util.SmartDialNameMatcher; -import com.android.dialer.util.CallUtil; -import java.util.ArrayList; - -/** List adapter to display the SmartDial search results. */ -public class SmartDialNumberListAdapter extends DialerPhoneNumberListAdapter { - - private static final String TAG = SmartDialNumberListAdapter.class.getSimpleName(); - private static final boolean DEBUG = false; - - private final Context context; - @NonNull private final SmartDialNameMatcher nameMatcher; - - public SmartDialNumberListAdapter(Context context) { - super(context); - this.context = context; - nameMatcher = new SmartDialNameMatcher(""); - setShortcutEnabled(SmartDialNumberListAdapter.SHORTCUT_DIRECT_CALL, false); - - if (DEBUG) { - LogUtil.v(TAG, "Constructing List Adapter"); - } - } - - /** Sets query for the SmartDialCursorLoader. */ - public void configureLoader(SmartDialCursorLoader loader) { - if (DEBUG) { - LogUtil.v(TAG, "Configure Loader with query" + getQueryString()); - } - - if (getQueryString() == null) { - loader.configureQuery(""); - nameMatcher.setQuery(""); - } else { - loader.configureQuery(getQueryString()); - nameMatcher.setQuery(PhoneNumberUtils.normalizeNumber(getQueryString())); - } - } - - /** - * Sets highlight options for a List item in the SmartDial search results. - * - * @param view ContactListItemView where the result will be displayed. - * @param cursor Object containing information of the associated List item. - */ - @Override - protected void setHighlight(ContactListItemView view, Cursor cursor) { - view.clearHighlightSequences(); - - if (nameMatcher.matches(context, cursor.getString(PhoneQuery.DISPLAY_NAME))) { - final ArrayList<SmartDialMatchPosition> nameMatches = nameMatcher.getMatchPositions(); - for (SmartDialMatchPosition match : nameMatches) { - view.addNameHighlightSequence(match.start, match.end); - if (DEBUG) { - LogUtil.v( - TAG, - cursor.getString(PhoneQuery.DISPLAY_NAME) - + " " - + nameMatcher.getQuery() - + " " - + String.valueOf(match.start)); - } - } - } - - final SmartDialMatchPosition numberMatch = - nameMatcher.matchesNumber(context, cursor.getString(PhoneQuery.PHONE_NUMBER)); - if (numberMatch != null) { - view.addNumberHighlightSequence(numberMatch.start, numberMatch.end); - } - } - - @Override - public void setQueryString(String queryString) { - final boolean showNumberShortcuts = !TextUtils.isEmpty(getFormattedQueryString()); - boolean changed = false; - changed |= setShortcutEnabled(SHORTCUT_CREATE_NEW_CONTACT, showNumberShortcuts); - changed |= setShortcutEnabled(SHORTCUT_ADD_TO_EXISTING_CONTACT, showNumberShortcuts); - changed |= setShortcutEnabled(SHORTCUT_SEND_SMS_MESSAGE, showNumberShortcuts); - changed |= - setShortcutEnabled( - SHORTCUT_MAKE_VIDEO_CALL, showNumberShortcuts && CallUtil.isVideoEnabled(getContext())); - if (changed) { - notifyDataSetChanged(); - } - super.setQueryString(queryString); - } - - public void setShowEmptyListForNullQuery(boolean show) { - nameMatcher.setShouldMatchEmptyQuery(!show); - } -} diff --git a/java/com/android/dialer/app/list/SmartDialSearchFragment.java b/java/com/android/dialer/app/list/SmartDialSearchFragment.java deleted file mode 100644 index fdf0b5a56..000000000 --- a/java/com/android/dialer/app/list/SmartDialSearchFragment.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2013 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.app.list; - -import static android.Manifest.permission.CALL_PHONE; - -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.Loader; -import android.database.Cursor; -import android.os.Bundle; -import android.support.v13.app.FragmentCompat; -import com.android.contacts.common.list.ContactEntryListAdapter; -import com.android.dialer.app.R; -import com.android.dialer.callintent.CallInitiationType; -import com.android.dialer.common.LogUtil; -import com.android.dialer.database.DialerDatabaseHelper; -import com.android.dialer.smartdial.SmartDialCursorLoader; -import com.android.dialer.util.PermissionsUtil; -import com.android.dialer.widget.EmptyContentView; -import java.util.Arrays; - -/** Implements a fragment to load and display SmartDial search results. */ -public class SmartDialSearchFragment extends SearchFragment - implements EmptyContentView.OnEmptyViewActionButtonClickedListener, - FragmentCompat.OnRequestPermissionsResultCallback { - - private static final int CALL_PHONE_PERMISSION_REQUEST_CODE = 1; - - private final BroadcastReceiver smartDialUpdatedReceiver = - new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - LogUtil.i("SmartDialSearchFragment.onReceive", "smart dial update broadcast received"); - reloadData(); - } - }; - - /** Creates a SmartDialListAdapter to display and operate on search results. */ - @Override - protected ContactEntryListAdapter createListAdapter() { - SmartDialNumberListAdapter adapter = new SmartDialNumberListAdapter(getActivity()); - adapter.setUseCallableUri(super.usesCallableUri()); - adapter.setQuickContactEnabled(true); - adapter.setShowEmptyListForNullQuery(getShowEmptyListForNullQuery()); - // Set adapter's query string to restore previous instance state. - adapter.setQueryString(getQueryString()); - adapter.setListener(this); - return adapter; - } - - /** Creates a SmartDialCursorLoader object to load query results. */ - @Override - public Loader<Cursor> onCreateLoader(int id, Bundle args) { - // Smart dialing does not support Directory Load, falls back to normal search instead. - if (id == getDirectoryLoaderId()) { - return super.onCreateLoader(id, args); - } else { - final SmartDialNumberListAdapter adapter = (SmartDialNumberListAdapter) getAdapter(); - SmartDialCursorLoader loader = new SmartDialCursorLoader(super.getContext()); - loader.setShowEmptyListForNullQuery(getShowEmptyListForNullQuery()); - adapter.configureLoader(loader); - return loader; - } - } - - @Override - public boolean getShowEmptyListForNullQuery() { - return true; - } - - @Override - protected void setupEmptyView() { - if (emptyView != null && getActivity() != null) { - if (!PermissionsUtil.hasPermission(getActivity(), CALL_PHONE)) { - emptyView.setImage(R.drawable.empty_contacts); - emptyView.setActionLabel(R.string.permission_single_turn_on); - emptyView.setDescription(R.string.permission_place_call); - emptyView.setActionClickedListener(this); - } else { - emptyView.setImage(EmptyContentView.NO_IMAGE); - emptyView.setActionLabel(EmptyContentView.NO_LABEL); - emptyView.setDescription(EmptyContentView.NO_LABEL); - } - } - } - - @Override - public void onStart() { - super.onStart(); - - LogUtil.i("SmartDialSearchFragment.onStart", "registering smart dial update receiver"); - - getActivity() - .registerReceiver( - smartDialUpdatedReceiver, - new IntentFilter(DialerDatabaseHelper.ACTION_SMART_DIAL_UPDATED)); - } - - @Override - public void onStop() { - super.onStop(); - - LogUtil.i("SmartDialSearchFragment.onStop", "unregistering smart dial update receiver"); - - getActivity().unregisterReceiver(smartDialUpdatedReceiver); - } - - @Override - public void onEmptyViewActionButtonClicked() { - final Activity activity = getActivity(); - if (activity == null) { - return; - } - - String[] deniedPermissions = - PermissionsUtil.getPermissionsCurrentlyDenied( - getContext(), PermissionsUtil.allPhoneGroupPermissionsUsedInDialer); - if (deniedPermissions.length > 0) { - LogUtil.i( - "SmartDialSearchFragment.onEmptyViewActionButtonClicked", - "Requesting permissions: " + Arrays.toString(deniedPermissions)); - FragmentCompat.requestPermissions( - this, deniedPermissions, CALL_PHONE_PERMISSION_REQUEST_CODE); - } - } - - @Override - public void onRequestPermissionsResult( - int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == CALL_PHONE_PERMISSION_REQUEST_CODE) { - setupEmptyView(); - } - } - - @Override - protected CallInitiationType.Type getCallInitiationType(boolean isRemoteDirectory) { - return CallInitiationType.Type.SMART_DIAL; - } - - public boolean isShowingPermissionRequest() { - return emptyView != null && emptyView.isShowingContent(); - } - - @Override - public void setShowEmptyListForNullQuery(boolean show) { - if (getAdapter() != null) { - ((SmartDialNumberListAdapter) getAdapter()).setShowEmptyListForNullQuery(show); - } - super.setShowEmptyListForNullQuery(show); - } -} |