diff options
author | Yorke Lee <yorkelee@google.com> | 2015-10-06 14:21:53 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2015-10-06 15:19:20 -0700 |
commit | e9c8233a77d6daa5374e146e1c871e000d7657e4 (patch) | |
tree | 8b595cf5c3ed94cfb308c3c703586dc1e3240461 /src/com/android/dialer/list | |
parent | 9fd3d0a81031baa83d1a141837c76afba79f3a02 (diff) |
Show prompt to request for location permission
Clicking on TURN ON currently only asks for the location
permission. Showing the dialog that toggles location sources
is planned for a follow up CL.
Bug: 24172011
Change-Id: Ieb6bd58a60aacbda76f9c754efeebfdd9e89aa86
Diffstat (limited to 'src/com/android/dialer/list')
-rw-r--r-- | src/com/android/dialer/list/RegularSearchFragment.java | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/src/com/android/dialer/list/RegularSearchFragment.java b/src/com/android/dialer/list/RegularSearchFragment.java index ec771e8ef..0b8703399 100644 --- a/src/com/android/dialer/list/RegularSearchFragment.java +++ b/src/com/android/dialer/list/RegularSearchFragment.java @@ -16,6 +16,7 @@ package com.android.dialer.list; import static android.Manifest.permission.READ_CONTACTS; +import static android.Manifest.permission.ACCESS_FINE_LOCATION; import android.app.Activity; import android.content.pm.PackageManager; @@ -36,13 +37,19 @@ import com.android.dialer.widget.EmptyContentView.OnEmptyViewActionButtonClicked public class RegularSearchFragment extends SearchFragment implements OnEmptyViewActionButtonClickedListener { - private static final int READ_CONTACTS_PERMISSION_REQUEST_CODE = 1; + private static final int PERMISSION_REQUEST_CODE = 1; private static final int SEARCH_DIRECTORY_RESULT_LIMIT = 5; private static final CachedNumberLookupService mCachedNumberLookupService = ObjectFactory.newCachedNumberLookupService(); + public interface HostInterface { + public boolean isNearbyPlacesSearchEnabled(); + } + + private String mPermissionToRequest; + public RegularSearchFragment() { configureDirectorySearch(); } @@ -64,6 +71,7 @@ public class RegularSearchFragment extends SearchFragment ((PinnedHeaderListView) getListView()).setScrollToSectionOnHeaderTouch(true); } + @Override protected ContactEntryListAdapter createListAdapter() { RegularSearchListAdapter adapter = new RegularSearchListAdapter(getActivity()); adapter.setDisplayPhotos(true); @@ -84,15 +92,36 @@ public class RegularSearchFragment extends SearchFragment @Override protected void setupEmptyView() { if (mEmptyView != null && getActivity() != null) { + final int imageResource; + final int actionLabelResource; + final int descriptionResource; + final OnEmptyViewActionButtonClickedListener listener; if (!PermissionsUtil.hasPermission(getActivity(), READ_CONTACTS)) { - mEmptyView.setImage(R.drawable.empty_contacts); - mEmptyView.setActionLabel(R.string.permission_single_turn_on); - mEmptyView.setDescription(R.string.permission_no_search); - mEmptyView.setActionClickedListener(this); + imageResource = R.drawable.empty_contacts; + actionLabelResource = R.string.permission_single_turn_on; + descriptionResource = R.string.permission_no_search; + listener = this; + mPermissionToRequest = READ_CONTACTS; + } else if (((HostInterface) getActivity()).isNearbyPlacesSearchEnabled() + && !PermissionsUtil.hasPermission(getActivity(), ACCESS_FINE_LOCATION)) { + imageResource = R.drawable.empty_contacts; + actionLabelResource = R.string.permission_single_turn_on; + descriptionResource = R.string.permission_no_location_for_search; + listener = this; + mPermissionToRequest = ACCESS_FINE_LOCATION; } else { - mEmptyView.setImage(EmptyContentView.NO_IMAGE); - mEmptyView.setActionLabel(EmptyContentView.NO_LABEL); - mEmptyView.setDescription(EmptyContentView.NO_LABEL); + imageResource = EmptyContentView.NO_IMAGE; + actionLabelResource = EmptyContentView.NO_LABEL; + descriptionResource = EmptyContentView.NO_LABEL; + listener = null; + mPermissionToRequest = null; + } + + mEmptyView.setImage(imageResource); + mEmptyView.setActionLabel(actionLabelResource); + mEmptyView.setDescription(descriptionResource); + if (listener != null) { + mEmptyView.setActionClickedListener(listener); } } } @@ -104,17 +133,20 @@ public class RegularSearchFragment extends SearchFragment return; } - requestPermissions(new String[] {READ_CONTACTS}, READ_CONTACTS_PERMISSION_REQUEST_CODE); + if (READ_CONTACTS.equals(mPermissionToRequest) + || ACCESS_FINE_LOCATION.equals(mPermissionToRequest)) { + requestPermissions(new String[] {mPermissionToRequest}, PERMISSION_REQUEST_CODE); + } } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == READ_CONTACTS_PERMISSION_REQUEST_CODE) { + if (requestCode == PERMISSION_REQUEST_CODE) { setupEmptyView(); if (grantResults != null && grantResults.length == 1 && PackageManager.PERMISSION_GRANTED == grantResults[0]) { - PermissionsUtil.notifyPermissionGranted(getActivity(), READ_CONTACTS); + PermissionsUtil.notifyPermissionGranted(getActivity(), mPermissionToRequest); } } } |