diff options
| author | 2010-08-12 18:35:28 -0700 | |
|---|---|---|
| committer | 2010-08-12 18:35:28 -0700 | |
| commit | eb7845e672b50b7b4ceeee6dee005cf71feb8951 (patch) | |
| tree | a84bea5e02077ecd9f4aab99427ec8284981c8c5 | |
| parent | c178b95c1fbd4644a088ca9739d173d5bf69939c (diff) | |
| parent | 44730c2e63dd0182263b3645f537f4c3d8b7efc2 (diff) | |
Merge "Adding query-based aggregation suggestions"
| -rw-r--r-- | core/java/android/provider/ContactsContract.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index 48d534572485..c93d9b20a127 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -32,6 +32,7 @@ import android.database.Cursor; import android.database.DatabaseUtils; import android.graphics.Rect; import android.net.Uri; +import android.net.Uri.Builder; import android.os.RemoteException; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -40,6 +41,7 @@ import android.view.View; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.ArrayList; /** * <p> @@ -1487,6 +1489,106 @@ public final class ContactsContract { * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}. */ public static final String CONTENT_DIRECTORY = "suggestions"; + + /** + * Used with {@link Builder#addParameter} to specify what kind of data is + * supplied for the suggestion query. + * + * @hide + */ + public static final String PARAMETER_MATCH_NAME = "name"; + + /** + * Used with {@link Builder#addParameter} to specify what kind of data is + * supplied for the suggestion query. + * + * @hide + */ + public static final String PARAMETER_MATCH_EMAIL = "email"; + + /** + * Used with {@link Builder#addParameter} to specify what kind of data is + * supplied for the suggestion query. + * + * @hide + */ + public static final String PARAMETER_MATCH_PHONE = "phone"; + + /** + * Used with {@link Builder#addParameter} to specify what kind of data is + * supplied for the suggestion query. + * + * @hide + */ + public static final String PARAMETER_MATCH_NICKNAME = "nickname"; + + /** + * A convenience builder for aggregation suggestion content URIs. + * + * TODO: change documentation for this class to use the builder. + * @hide + */ + public static final class Builder { + private long mContactId; + private ArrayList<String> mKinds = new ArrayList<String>(); + private ArrayList<String> mValues = new ArrayList<String>(); + private int mLimit; + + /** + * Optional existing contact ID. If it is not provided, the search + * will be based exclusively on the values supplied with {@link #addParameter}. + */ + public Builder setContactId(long contactId) { + this.mContactId = contactId; + return this; + } + + /** + * A value that can be used when searching for an aggregation + * suggestion. + * + * @param kind can be one of + * {@link AggregationSuggestions#PARAMETER_MATCH_NAME}, + * {@link AggregationSuggestions#PARAMETER_MATCH_EMAIL}, + * {@link AggregationSuggestions#PARAMETER_MATCH_NICKNAME}, + * {@link AggregationSuggestions#PARAMETER_MATCH_PHONE} + */ + public Builder addParameter(String kind, String value) { + if (!TextUtils.isEmpty(value)) { + mKinds.add(kind); + mValues.add(value); + } + return this; + } + + public Builder setLimit(int limit) { + mLimit = limit; + return this; + } + + public Uri build() { + android.net.Uri.Builder builder = Contacts.CONTENT_URI.buildUpon(); + builder.appendEncodedPath(String.valueOf(mContactId)); + builder.appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY); + if (mLimit != 0) { + builder.appendQueryParameter("limit", String.valueOf(mLimit)); + } + + int count = mKinds.size(); + for (int i = 0; i < count; i++) { + builder.appendQueryParameter("query", mKinds.get(i) + ":" + mValues.get(i)); + } + + return builder.build(); + } + } + + /** + * @hide + */ + public static final Builder builder() { + return new Builder(); + } } /** |