summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-10-13 01:00:15 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-10-13 01:00:15 +0000
commit2176206d87eb07d77279ae6080f1cda94496e56d (patch)
tree3214718c8d52f3c083e0fb8b367376b63a1bb8ca
parent01b435b5efd591a615378251c672d44840c808be (diff)
parent975d2d46ac7148a86065ebf5987bc9aa2365d251 (diff)
am 975d2d46: Merge "Implement behavior for import settings visibility." into ub-contactsdialer-a-dev
* commit '975d2d46ac7148a86065ebf5987bc9aa2365d251': Implement behavior for import settings visibility.
-rw-r--r--src/com/android/dialer/filterednumber/BlockedNumberFragment.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java
index e12fd6b38..5740305f7 100644
--- a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java
+++ b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java
@@ -21,7 +21,9 @@ import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
+import android.os.AsyncTask;
import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -32,7 +34,16 @@ import com.android.dialer.database.FilteredNumberContract;
public class BlockedNumberFragment extends ListFragment implements
LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener {
+ private static class SendToVoicemailContactQuery {
+ static final String[] PROJECTION = {
+ Contacts._ID
+ };
+
+ static final String SELECT_SEND_TO_VOICEMAIL_TRUE = Contacts.SEND_TO_VOICEMAIL + "=1";
+ }
+
private BlockedNumberAdapter mAdapter;
+ private View mImportSettings;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
@@ -47,6 +58,8 @@ public class BlockedNumberFragment extends ListFragment implements
getActivity().findViewById(R.id.add_number_button).setOnClickListener(this);
getListView().getEmptyView().findViewById(R.id.add_number_button).setOnClickListener(this);
+
+ mImportSettings = getActivity().findViewById(R.id.importsettings);
}
@Override
@@ -62,6 +75,12 @@ public class BlockedNumberFragment extends ListFragment implements
}
@Override
+ public void onResume() {
+ super.onResume();
+ checkForSendToVoicemailContact();
+ }
+
+ @Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.blocked_number_fragment, container, false);
@@ -102,4 +121,44 @@ public class BlockedNumberFragment extends ListFragment implements
manageBlockedNumbersActivity.enterSearchUi();
}
}
+
+ /**
+ * Checks if there exists a contact with {@code Contacts.SEND_TO_VOICEMAIL} set to true,
+ * and updates the visibility of the import settings buttons accordingly.
+ */
+ private void checkForSendToVoicemailContact() {
+ final AsyncTask task = new AsyncTask<Object, Void, Boolean>() {
+ @Override
+ public Boolean doInBackground(Object[] params) {
+ if (getActivity() == null) {
+ return false;
+ }
+
+ final Cursor cursor = getActivity().getContentResolver().query(
+ Contacts.CONTENT_URI,
+ SendToVoicemailContactQuery.PROJECTION,
+ SendToVoicemailContactQuery.SELECT_SEND_TO_VOICEMAIL_TRUE,
+ null,
+ null);
+
+ boolean hasSendToVoicemailContacts = false;
+ if (cursor != null) {
+ try {
+ hasSendToVoicemailContacts = cursor.getCount() > 0;
+ } finally {
+ cursor.close();
+ }
+ }
+
+ return hasSendToVoicemailContacts;
+ }
+
+ @Override
+ public void onPostExecute(Boolean hasSendToVoicemailContact) {
+ final int visibility = hasSendToVoicemailContact ? View.VISIBLE : View.GONE;
+ mImportSettings.setVisibility(visibility);
+ }
+ };
+ task.execute();
+ }
}