From 77da0c6b5d3d6925c8018c1eb57fb26d102a937d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 21 Apr 2014 19:51:03 +0200 Subject: allow images to be opened with gallary app --- .../conversations/services/ImageProvider.java | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/eu/siacs/conversations/services/ImageProvider.java (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/ImageProvider.java b/src/eu/siacs/conversations/services/ImageProvider.java new file mode 100644 index 000000000..c1bae661e --- /dev/null +++ b/src/eu/siacs/conversations/services/ImageProvider.java @@ -0,0 +1,97 @@ +package eu.siacs.conversations.services; + +import java.io.File; +import java.io.FileNotFoundException; + +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.persistance.DatabaseBackend; +import eu.siacs.conversations.persistance.FileBackend; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.ParcelFileDescriptor; +import android.util.Log; + +public class ImageProvider extends ContentProvider { + + @Override + public ParcelFileDescriptor openFile(Uri uri, String mode) + throws FileNotFoundException { + DatabaseBackend databaseBackend = DatabaseBackend + .getInstance(getContext()); + FileBackend fileBackend = new FileBackend(getContext()); + String uuids = uri.getPath(); + Log.d("xmppService", "uuids = " + uuids); + if (uuids == null) { + throw new FileNotFoundException(); + } + String[] uuidsSplited = uuids.split("/"); + if (uuidsSplited.length != 3) { + throw new FileNotFoundException(); + } + String conversationUuid = uuidsSplited[1]; + String messageUuid = uuidsSplited[2]; + + Conversation conversation = databaseBackend + .findConversationByUuid(conversationUuid); + if (conversation == null) { + throw new FileNotFoundException("conversation " + conversationUuid + + " could not be found"); + } + Message message = databaseBackend.findMessageByUuid(messageUuid); + if (message == null) { + throw new FileNotFoundException("message " + messageUuid + + " could not be found"); + } + + Account account = databaseBackend.findAccountByUuid(conversation + .getAccountUuid()); + if (account == null) { + throw new FileNotFoundException("account " + + conversation.getAccountUuid() + " cound not be found"); + } + message.setConversation(conversation); + conversation.setAccount(account); + + File file = fileBackend.getJingleFile(message); + ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, + ParcelFileDescriptor.MODE_READ_ONLY); + return pfd; + } + + @Override + public int delete(Uri arg0, String arg1, String[] arg2) { + return 0; + } + + @Override + public String getType(Uri arg0) { + return null; + } + + @Override + public Uri insert(Uri arg0, ContentValues arg1) { + return null; + } + + @Override + public boolean onCreate() { + return false; + } + + @Override + public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, + String arg4) { + return null; + } + + @Override + public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) { + return 0; + } + +} -- cgit v1.2.3