75 lines
2.6 KiB
Java
75 lines
2.6 KiB
Java
package com.squareup.picasso;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.UriMatcher;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.provider.ContactsContract;
|
|
import com.squareup.picasso.Picasso;
|
|
import com.squareup.picasso.RequestHandler;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
/* loaded from: classes.dex */
|
|
class ContactsPhotoRequestHandler extends RequestHandler {
|
|
private static final UriMatcher b = new UriMatcher(-1);
|
|
private final Context a;
|
|
|
|
@TargetApi(14)
|
|
private static class ContactPhotoStreamIcs {
|
|
static InputStream a(ContentResolver contentResolver, Uri uri) {
|
|
return ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, uri, true);
|
|
}
|
|
}
|
|
|
|
static {
|
|
b.addURI("com.android.contacts", "contacts/lookup/*/#", 1);
|
|
b.addURI("com.android.contacts", "contacts/lookup/*", 1);
|
|
b.addURI("com.android.contacts", "contacts/#/photo", 2);
|
|
b.addURI("com.android.contacts", "contacts/#", 3);
|
|
b.addURI("com.android.contacts", "display_photo/#", 4);
|
|
}
|
|
|
|
ContactsPhotoRequestHandler(Context context) {
|
|
this.a = context;
|
|
}
|
|
|
|
private InputStream c(Request request) throws IOException {
|
|
ContentResolver contentResolver = this.a.getContentResolver();
|
|
Uri uri = request.d;
|
|
int match = b.match(uri);
|
|
if (match != 1) {
|
|
if (match != 2) {
|
|
if (match != 3) {
|
|
if (match != 4) {
|
|
throw new IllegalStateException("Invalid uri: " + uri);
|
|
}
|
|
}
|
|
}
|
|
return contentResolver.openInputStream(uri);
|
|
}
|
|
uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);
|
|
if (uri == null) {
|
|
return null;
|
|
}
|
|
return Build.VERSION.SDK_INT < 14 ? ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, uri) : ContactPhotoStreamIcs.a(contentResolver, uri);
|
|
}
|
|
|
|
@Override // com.squareup.picasso.RequestHandler
|
|
public boolean a(Request request) {
|
|
Uri uri = request.d;
|
|
return "content".equals(uri.getScheme()) && ContactsContract.Contacts.CONTENT_URI.getHost().equals(uri.getHost()) && b.match(request.d) != -1;
|
|
}
|
|
|
|
@Override // com.squareup.picasso.RequestHandler
|
|
public RequestHandler.Result a(Request request, int i) throws IOException {
|
|
InputStream c = c(request);
|
|
if (c != null) {
|
|
return new RequestHandler.Result(c, Picasso.LoadedFrom.DISK);
|
|
}
|
|
return null;
|
|
}
|
|
}
|