parent
1641fd91cf
commit
0c9d9e8dcf
@ -0,0 +1,52 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.data.StreamLocalUriFetcher;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.api.crypto.AttachmentCipherInputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AttachmentStreamLocalUriFetcher implements DataFetcher<InputStream> {
|
||||
private static final String TAG = AttachmentStreamLocalUriFetcher.class.getSimpleName();
|
||||
private File attachment;
|
||||
private byte[] key;
|
||||
private InputStream is;
|
||||
|
||||
public AttachmentStreamLocalUriFetcher(File attachment, byte[] key) {
|
||||
this.attachment = attachment;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override public InputStream loadData(Priority priority) throws Exception {
|
||||
is = new AttachmentCipherInputStream(attachment, key);
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override public void cleanup() {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
is = null;
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, "ioe");
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return AttachmentStreamLocalUriFetcher.class.getCanonicalName() + "::" + attachment.getAbsolutePath();
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.GenericLoaderFactory;
|
||||
import com.bumptech.glide.load.model.ModelLoader;
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentStreamUriLoader.AttachmentModel;
|
||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* A {@link ModelLoader} for translating uri models into {@link InputStream} data. Capable of handling 'http',
|
||||
* 'https', 'android.resource', 'content', and 'file' schemes. Unsupported schemes will throw an exception in
|
||||
* {@link #getResourceFetcher(Uri, int, int)}.
|
||||
*/
|
||||
public class AttachmentStreamUriLoader implements StreamModelLoader<AttachmentModel> {
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* THe default factory for {@link com.bumptech.glide.load.model.stream.StreamUriLoader}s.
|
||||
*/
|
||||
public static class Factory implements ModelLoaderFactory<AttachmentModel, InputStream> {
|
||||
|
||||
@Override
|
||||
public StreamModelLoader<AttachmentModel> build(Context context, GenericLoaderFactory factories) {
|
||||
return new AttachmentStreamUriLoader(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teardown() {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
public AttachmentStreamUriLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(AttachmentModel model, int width, int height) {
|
||||
return new AttachmentStreamLocalUriFetcher(model.attachment, model.key);
|
||||
}
|
||||
|
||||
public static class AttachmentModel {
|
||||
public File attachment;
|
||||
public byte[] key;
|
||||
|
||||
public AttachmentModel(File attachment, byte[] key) {
|
||||
this.attachment = attachment;
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.provider.ContactsContract;
|
||||
|
||||
import com.bumptech.glide.load.data.StreamLocalUriFetcher;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ContactPhotoLocalUriFetcher extends StreamLocalUriFetcher {
|
||||
private static final String TAG = ContactPhotoLocalUriFetcher.class.getSimpleName();
|
||||
|
||||
public ContactPhotoLocalUriFetcher(Context context, Uri uri) {
|
||||
super(context, uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream loadResource(Uri uri, ContentResolver contentResolver)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
return ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, uri, true);
|
||||
} else {
|
||||
return ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, uri);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.GenericLoaderFactory;
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||
|
||||
import org.thoughtcrime.securesms.mms.ContactPhotoUriLoader.ContactPhotoUri;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ContactPhotoUriLoader implements StreamModelLoader<ContactPhotoUri> {
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* THe default factory for {@link com.bumptech.glide.load.model.stream.StreamUriLoader}s.
|
||||
*/
|
||||
public static class Factory implements ModelLoaderFactory<ContactPhotoUri, InputStream> {
|
||||
|
||||
@Override
|
||||
public StreamModelLoader<ContactPhotoUri> build(Context context, GenericLoaderFactory factories) {
|
||||
return new ContactPhotoUriLoader(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teardown() {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
public ContactPhotoUriLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(ContactPhotoUri model, int width, int height) {
|
||||
return new ContactPhotoLocalUriFetcher(context, model.uri);
|
||||
}
|
||||
|
||||
public static class ContactPhotoUri {
|
||||
public Uri uri;
|
||||
|
||||
public ContactPhotoUri(Uri uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue