aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java20
-rw-r--r--src/eu/siacs/conversations/services/ImageProvider.java95
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java66
3 files changed, 138 insertions, 43 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index becb1ee3..0b26049e 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -1,6 +1,7 @@
package eu.siacs.conversations.persistance;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -17,7 +18,6 @@ import android.util.LruCache;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
-
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
@@ -89,15 +89,25 @@ public class FileBackend {
public JingleFile copyImageToPrivateStorage(Message message, Uri image) {
try {
- Log.d("xmppService","copying file: "+image.toString()+ " to internal storage");
- InputStream is = context.getContentResolver()
+ InputStream is;
+ if (image!=null) {
+ Log.d("xmppService","copying file: "+image.toString()+ " to internal storage");
+ is = context.getContentResolver()
.openInputStream(image);
+ } else {
+ Log.d("xmppService","copying file from incoming to internal storage");
+ is = new FileInputStream(getIncomingFile());
+ }
JingleFile file = getJingleFile(message);
file.getParentFile().mkdirs();
file.createNewFile();
OutputStream os = new FileOutputStream(file);
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
is.close();
+ if (image==null) {
+ Log.d("xmppService","delete incoming file");
+ getIncomingFile().delete();
+ }
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
boolean success = scalledBitmap.compress(
Bitmap.CompressFormat.WEBP, 75, os);
@@ -160,4 +170,8 @@ public class FileBackend {
}
f.delete();
}
+
+ public File getIncomingFile() {
+ return new File(context.getFilesDir().getAbsolutePath()+"/incoming");
+ }
}
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
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index c650240f..16efdade 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -11,12 +11,14 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.services.ImageProvider;
import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.UIHelper;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.provider.MediaStore;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.app.PendingIntent;
@@ -63,6 +65,7 @@ public class ConversationActivity extends XmppActivity {
public static final int REQUEST_SEND_MESSAGE = 0x75441;
public static final int REQUEST_DECRYPT_PGP = 0x76783;
private static final int REQUEST_ATTACH_FILE_DIALOG = 0x48502;
+ private static final int REQUEST_IMAGE_CAPTURE = 0x33788;
private static final int REQUEST_SEND_PGP_IMAGE = 0x53883;
private static final int REQUEST_ATTACH_FILE = 0x73824;
public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018;
@@ -349,6 +352,29 @@ public class ConversationActivity extends XmppActivity {
}
},"file");
}
+
+ private void takePicture() {
+ selectPresence(getSelectedConversation(), new OnPresenceSelected() {
+
+ @Override
+ public void onPresenceSelected(boolean success, String presence) {
+ if (success) {
+ Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+ takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, ImageProvider.getIncomingContentUri());
+ if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
+ startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
+ }
+ }
+ }
+
+ @Override
+ public void onSendPlainTextInstead() {
+ // TODO Auto-generated method stub
+
+ }
+ },"file");
+
+ }
private void attachFile() {
final Conversation conversation = getSelectedConversation();
@@ -425,7 +451,25 @@ public class ConversationActivity extends XmppActivity {
spl.openPane();
break;
case R.id.action_attach_file:
- attachFile();
+ View menuAttachFile = findViewById(R.id.action_attach_file);
+ PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
+ attachFilePopup.inflate(R.menu.attachment_choices);
+ attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.attach_choose_picture:
+ attachFile();
+ break;
+ case R.id.attach_take_picture:
+ takePicture();
+ break;
+ }
+ return false;
+ }
+ });
+ attachFilePopup.show();
break;
case R.id.action_add:
startActivity(new Intent(this, ContactsActivity.class));
@@ -706,6 +750,26 @@ public class ConversationActivity extends XmppActivity {
announcePgp(getSelectedConversation().getAccount(),getSelectedConversation());
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
encryptTextMessage();
+ } else if (requestCode == REQUEST_IMAGE_CAPTURE) {
+ this.pendingMessage = xmppConnectionService.attachImageToConversation(getSelectedConversation(), null, new UiCallback() {
+
+ @Override
+ public void userInputRequried(PendingIntent pi) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void success() {
+ sendPendingImageMessage();
+ }
+
+ @Override
+ public void error(int errorCode) {
+ // TODO Auto-generated method stub
+
+ }
+ });
} else {
Log.d(LOGTAG,"unknown result code:"+requestCode);
}