summaryrefslogtreecommitdiffstats
path: root/chips/src/com/android/ex/chips/Queries.java
blob: ab548a6eccffe353c753cde7c9a7f4deb6ce016a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) 2012 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.ex.chips;

import android.content.res.Resources;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;

/**
 * Phone and Email queries for supporting Chips UI.
 */
/* package */ class Queries {

    public static final Query PHONE = new Query(new String[] {
            Contacts.DISPLAY_NAME,       // 0
            Phone.NUMBER,                // 1
            Phone.TYPE,                  // 2
            Phone.LABEL,                 // 3
            Phone.CONTACT_ID,            // 4
            Phone._ID,                   // 5
            Contacts.PHOTO_THUMBNAIL_URI,// 6
            Contacts.DISPLAY_NAME_SOURCE // 7
        }, Phone.CONTENT_FILTER_URI, Phone.CONTENT_URI, Phone.NORMALIZED_NUMBER) {

            @Override
            public CharSequence getTypeLabel(Resources res, int type, CharSequence label) {
                return Phone.getTypeLabel(res, type, label);
            }

    };

    public static final Query EMAIL = new Query(new String[]{
            Contacts.DISPLAY_NAME,       // 0
            Email.DATA,                  // 1
            Email.TYPE,                  // 2
            Email.LABEL,                 // 3
            Email.CONTACT_ID,            // 4
            Email._ID,                   // 5
            Contacts.PHOTO_THUMBNAIL_URI,// 6
            Contacts.DISPLAY_NAME_SOURCE // 7
        }, Email.CONTENT_FILTER_URI, Email.CONTENT_URI, Email.DATA) {

            @Override
            public CharSequence getTypeLabel(Resources res, int type, CharSequence label) {
                return Email.getTypeLabel(res, type, label);
            }

    };

    static abstract class Query {
        private final String[] mProjection;
        private final Uri mContentFilterUri;
        private final Uri mContentUri;
        private final String mSelectionColumn;

        public static final int NAME = 0;                // String
        public static final int DESTINATION = 1;         // String
        public static final int DESTINATION_TYPE = 2;    // int
        public static final int DESTINATION_LABEL = 3;   // String
        public static final int CONTACT_ID = 4;          // long
        public static final int DATA_ID = 5;             // long
        public static final int PHOTO_THUMBNAIL_URI = 6; // String
        public static final int DISPLAY_NAME_SOURCE = 7; // int

        public Query (String[] projection, Uri contentFilter,
                Uri content, String selectionColumn) {
            mProjection = projection;
            mContentFilterUri = contentFilter;
            mContentUri = content;
            mSelectionColumn = selectionColumn;
        }

        public String[] getProjection() {
            return mProjection;
        }

        public Uri getContentFilterUri() {
            return mContentFilterUri;
        }

        public Uri getContentUri() {
            return mContentUri;
        }

        public String getSelectionColumn() {
            return mSelectionColumn;
        }

        public abstract CharSequence getTypeLabel(Resources res, int type, CharSequence label);
    }
}