33
33
import static com .squareup .picasso .Picasso .LoadedFrom .DISK ;
34
34
35
35
class ContactsPhotoBitmapHunter extends BitmapHunter {
36
- final Context context ;
36
+ /**
37
+ a lookup uri (e.g. content://com.android.contacts/contacts/lookup/3570i61d948d30808e537 )
38
+ */
39
+ private static final int ID_LOOKUP = 1 ;
40
+ /**
41
+ a contact thumbnail uri (e.g. content://com.android.contacts/contacts/38/photo)
42
+ */
43
+ private static final int ID_THUMBNAIL = 2 ;
44
+ /**
45
+ a contact uri (e.g. content://com.android.contacts/contacts/38)
46
+ */
47
+ private static final int ID_CONTACT = 3 ;
48
+ /**
49
+ a contact display photo (high resolution) uri
50
+ (e.g. content://com.android.contacts/display_photo/5)
51
+ */
52
+ private static final int ID_DISPLAY_PHOTO = 4 ;
53
+
37
54
static final UriMatcher matcher ;
38
55
56
+ static {
57
+ matcher = new UriMatcher (UriMatcher .NO_MATCH );
58
+ matcher .addURI (ContactsContract .AUTHORITY , "contacts/lookup/*" , ID_LOOKUP );
59
+ matcher .addURI (ContactsContract .AUTHORITY , "contacts/#/photo" , ID_THUMBNAIL );
60
+ matcher .addURI (ContactsContract .AUTHORITY , "contacts/#" , ID_CONTACT );
61
+ matcher .addURI (ContactsContract .AUTHORITY , "display_photo/#" , ID_DISPLAY_PHOTO );
62
+ }
63
+
64
+ final Context context ;
65
+
39
66
ContactsPhotoBitmapHunter (Context context , Picasso picasso , Dispatcher dispatcher , Cache cache ,
40
67
Stats stats , Action action ) {
41
68
super (picasso , dispatcher , cache , stats , action );
@@ -61,22 +88,23 @@ private InputStream getInputStream() throws IOException {
61
88
ContentResolver contentResolver = context .getContentResolver ();
62
89
Uri uri = getData ().uri ;
63
90
switch (matcher .match (uri )) {
64
- case ID_LOOKUP :
65
- uri = ContactsContract .Contacts .lookupContact (contentResolver , uri );
66
- if (null == uri ) {
67
- return null ;
68
- }
69
- case ID_CONTACT :
70
- if (SDK_INT < ICE_CREAM_SANDWICH ) {
71
- return openContactPhotoInputStream (contentResolver , uri );
72
- } else {
73
- return ContactPhotoStreamIcs .get (contentResolver , uri );
74
- }
75
- case ID_THUMBNAIL :
76
- case ID_DISPLAY_PHOTO :
77
- return contentResolver .openInputStream (uri );
78
- default :
91
+ case ID_LOOKUP :
92
+ uri = ContactsContract .Contacts .lookupContact (contentResolver , uri );
93
+ if (null == uri ) {
79
94
return null ;
95
+ }
96
+ // Resolved the uri to a contact uri, intentionally fall through to process the resolved uri
97
+ case ID_CONTACT :
98
+ if (SDK_INT < ICE_CREAM_SANDWICH ) {
99
+ return openContactPhotoInputStream (contentResolver , uri );
100
+ } else {
101
+ return ContactPhotoStreamIcs .get (contentResolver , uri );
102
+ }
103
+ case ID_THUMBNAIL :
104
+ case ID_DISPLAY_PHOTO :
105
+ return contentResolver .openInputStream (uri );
106
+ default :
107
+ throw new IllegalStateException ("Invalid uri: " + uri );
80
108
}
81
109
}
82
110
@@ -105,30 +133,4 @@ static InputStream get(ContentResolver contentResolver, Uri uri) {
105
133
return openContactPhotoInputStream (contentResolver , uri , true );
106
134
}
107
135
}
108
-
109
- /**
110
- a lookup uri (e.g. content://com.android.contacts/contacts/lookup/3570i61d948d30808e537 )
111
- */
112
- private static final int ID_LOOKUP = 1 ;
113
- /**
114
- a contact thumbnail uri (e.g. content://com.android.contacts/contacts/38/photo)
115
- */
116
- private static final int ID_THUMBNAIL = 2 ;
117
- /**
118
- a contact uri (e.g. content://com.android.contacts/contacts/38)
119
- */
120
- private static final int ID_CONTACT = 3 ;
121
- /**
122
- a contact display photo (high resolution) uri
123
- (e.g. content://com.android.contacts/display_photo/5)
124
- */
125
- private static final int ID_DISPLAY_PHOTO = 4 ;
126
-
127
- static {
128
- matcher = new UriMatcher (UriMatcher .NO_MATCH );
129
- matcher .addURI (ContactsContract .AUTHORITY , "contacts/lookup/*" , ID_LOOKUP );
130
- matcher .addURI (ContactsContract .AUTHORITY , "contacts/#/photo" , ID_THUMBNAIL );
131
- matcher .addURI (ContactsContract .AUTHORITY , "contacts/#" , ID_CONTACT );
132
- matcher .addURI (ContactsContract .AUTHORITY , "display_photo/#" , ID_DISPLAY_PHOTO );
133
- }
134
136
}
0 commit comments