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
|
/*
* Copyright (C) 2017 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.speeddial;
import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import com.android.dialer.speeddial.room.SpeedDialDatabaseComponent;
import com.android.dialer.speeddial.room.SpeedDialEntry;
import java.util.List;
/** Cursor Loader for strequent contacts. */
public final class StrequentContactsCursorLoader extends CursorLoader {
public static final int PHONE_ID = 0;
public static final int PHONE_DISPLAY_NAME = 1;
public static final int PHONE_STARRED = 2;
public static final int PHONE_PHOTO_URI = 3;
public static final int PHONE_LOOKUP_KEY = 4;
public static final int PHONE_PHOTO_ID = 5;
public static final int PHONE_NUMBER = 6;
public static final int PHONE_TYPE = 7;
public static final int PHONE_LABEL = 8;
public static final int PHONE_IS_SUPER_PRIMARY = 9;
public static final int PHONE_PINNED = 10;
public static final int PHONE_CONTACT_ID = 11;
public static final String[] PHONE_PROJECTION =
new String[] {
Phone._ID, // 0
Phone.DISPLAY_NAME, // 1
Phone.STARRED, // 2
Phone.PHOTO_URI, // 3
Phone.LOOKUP_KEY, // 4
Phone.PHOTO_ID, // 5
Phone.NUMBER, // 6
Phone.TYPE, // 7
Phone.LABEL, // 8
Phone.IS_SUPER_PRIMARY, // 9
Phone.PINNED, // 10
Phone.CONTACT_ID, // 11
};
StrequentContactsCursorLoader(Context context) {
super(
context,
buildUri(),
PHONE_PROJECTION,
null /* selection */,
null /* selectionArgs */,
null /* sortOrder */);
// TODO(calderwoodra): implement alternative display names
}
static void addToCursor(MatrixCursor dest, Cursor source) {
dest.newRow()
.add(PHONE_PROJECTION[PHONE_ID], source.getLong(PHONE_ID))
.add(PHONE_PROJECTION[PHONE_DISPLAY_NAME], source.getString(PHONE_DISPLAY_NAME))
.add(PHONE_PROJECTION[PHONE_STARRED], source.getInt(PHONE_STARRED))
.add(PHONE_PROJECTION[PHONE_PHOTO_URI], source.getString(PHONE_PHOTO_URI))
.add(PHONE_PROJECTION[PHONE_LOOKUP_KEY], source.getString(PHONE_LOOKUP_KEY))
.add(PHONE_PROJECTION[PHONE_NUMBER], source.getString(PHONE_NUMBER))
.add(PHONE_PROJECTION[PHONE_TYPE], source.getInt(PHONE_TYPE))
.add(PHONE_PROJECTION[PHONE_LABEL], source.getString(PHONE_LABEL))
.add(PHONE_PROJECTION[PHONE_IS_SUPER_PRIMARY], source.getInt(PHONE_IS_SUPER_PRIMARY))
.add(PHONE_PROJECTION[PHONE_PINNED], source.getInt(PHONE_PINNED))
.add(PHONE_PROJECTION[PHONE_CONTACT_ID], source.getLong(PHONE_CONTACT_ID));
}
private static Uri buildUri() {
return Contacts.CONTENT_STREQUENT_URI
.buildUpon()
.appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true")
.build();
}
@Override
public Cursor loadInBackground() {
Cursor strequentCursor = super.loadInBackground();
List<SpeedDialEntry> entries =
SpeedDialDatabaseComponent.get(getContext().getApplicationContext())
.speedDialDatabase()
.getSpeedDialEntryDao()
.getAllEntries();
return SpeedDialCursor.newInstance(strequentCursor, entries);
}
}
|