aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/services/ImageProvider.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-05-13 16:48:39 +0200
committerDaniel Gultsch <daniel@gultsch.de>2014-05-13 16:48:39 +0200
commit9492e2890208ed8527504d692cfdb07d36d2fa30 (patch)
tree3638889168dc1bffdba605dcce01f1689f5fc773 /src/eu/siacs/conversations/services/ImageProvider.java
parenta8010e71335daab3dfc3d6d523fd51755c9d6427 (diff)
takeing pictures over intent
Diffstat (limited to 'src/eu/siacs/conversations/services/ImageProvider.java')
-rw-r--r--src/eu/siacs/conversations/services/ImageProvider.java95
1 files changed, 56 insertions, 39 deletions
diff --git a/src/eu/siacs/conversations/services/ImageProvider.java b/src/eu/siacs/conversations/services/ImageProvider.java
index 7ca57032..798a4e25 100644
--- a/src/eu/siacs/conversations/services/ImageProvider.java
+++ b/src/eu/siacs/conversations/services/ImageProvider.java
@@ -2,13 +2,13 @@ package eu.siacs.conversations.services;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
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;
@@ -21,46 +21,60 @@ public class ImageProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
throws FileNotFoundException {
- DatabaseBackend databaseBackend = DatabaseBackend
- .getInstance(getContext());
+ ParcelFileDescriptor pfd;
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) {
+ if ("r".equals(mode)) {
+ DatabaseBackend databaseBackend = DatabaseBackend
+ .getInstance(getContext());
+ String uuids = uri.getPath();
+ Log.d("xmppService", "uuids = " + uuids+" mode="+mode);
+ 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);
+ pfd = ParcelFileDescriptor.open(file,
+ ParcelFileDescriptor.MODE_READ_ONLY);
+ return pfd;
+ } else if ("w".equals(mode)){
+ File file = fileBackend.getIncomingFile();
+ try {
+ file.createNewFile();
+ } catch (IOException e) {
+ throw new FileNotFoundException();
+ }
+ pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);
+ return pfd;
+ } else {
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
@@ -102,4 +116,7 @@ public class ImageProvider extends ContentProvider {
+ message.getUuid());
}
-}
+ public static Uri getIncomingContentUri() {
+ return Uri.parse("content://eu.siacs.conversations.images/incoming");
+ }
+} \ No newline at end of file