mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-10 11:15:03 -05:00
takeing pictures over intent
This commit is contained in:
parent
a8010e7133
commit
9492e28902
@ -1,6 +1,7 @@
|
|||||||
package eu.siacs.conversations.persistance;
|
package eu.siacs.conversations.persistance;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -17,7 +18,6 @@ import android.util.LruCache;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
@ -89,15 +89,25 @@ public class FileBackend {
|
|||||||
|
|
||||||
public JingleFile copyImageToPrivateStorage(Message message, Uri image) {
|
public JingleFile copyImageToPrivateStorage(Message message, Uri image) {
|
||||||
try {
|
try {
|
||||||
|
InputStream is;
|
||||||
|
if (image!=null) {
|
||||||
Log.d("xmppService","copying file: "+image.toString()+ " to internal storage");
|
Log.d("xmppService","copying file: "+image.toString()+ " to internal storage");
|
||||||
InputStream is = context.getContentResolver()
|
is = context.getContentResolver()
|
||||||
.openInputStream(image);
|
.openInputStream(image);
|
||||||
|
} else {
|
||||||
|
Log.d("xmppService","copying file from incoming to internal storage");
|
||||||
|
is = new FileInputStream(getIncomingFile());
|
||||||
|
}
|
||||||
JingleFile file = getJingleFile(message);
|
JingleFile file = getJingleFile(message);
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
OutputStream os = new FileOutputStream(file);
|
OutputStream os = new FileOutputStream(file);
|
||||||
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
|
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
|
||||||
is.close();
|
is.close();
|
||||||
|
if (image==null) {
|
||||||
|
Log.d("xmppService","delete incoming file");
|
||||||
|
getIncomingFile().delete();
|
||||||
|
}
|
||||||
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
|
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
|
||||||
boolean success = scalledBitmap.compress(
|
boolean success = scalledBitmap.compress(
|
||||||
Bitmap.CompressFormat.WEBP, 75, os);
|
Bitmap.CompressFormat.WEBP, 75, os);
|
||||||
@ -160,4 +170,8 @@ public class FileBackend {
|
|||||||
}
|
}
|
||||||
f.delete();
|
f.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getIncomingFile() {
|
||||||
|
return new File(context.getFilesDir().getAbsolutePath()+"/incoming");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package eu.siacs.conversations.services;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.persistance.DatabaseBackend;
|
import eu.siacs.conversations.persistance.DatabaseBackend;
|
||||||
import eu.siacs.conversations.persistance.FileBackend;
|
import eu.siacs.conversations.persistance.FileBackend;
|
||||||
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@ -21,11 +21,13 @@ public class ImageProvider extends ContentProvider {
|
|||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode)
|
public ParcelFileDescriptor openFile(Uri uri, String mode)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
|
ParcelFileDescriptor pfd;
|
||||||
|
FileBackend fileBackend = new FileBackend(getContext());
|
||||||
|
if ("r".equals(mode)) {
|
||||||
DatabaseBackend databaseBackend = DatabaseBackend
|
DatabaseBackend databaseBackend = DatabaseBackend
|
||||||
.getInstance(getContext());
|
.getInstance(getContext());
|
||||||
FileBackend fileBackend = new FileBackend(getContext());
|
|
||||||
String uuids = uri.getPath();
|
String uuids = uri.getPath();
|
||||||
Log.d("xmppService", "uuids = " + uuids);
|
Log.d("xmppService", "uuids = " + uuids+" mode="+mode);
|
||||||
if (uuids == null) {
|
if (uuids == null) {
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
@ -58,9 +60,21 @@ public class ImageProvider extends ContentProvider {
|
|||||||
conversation.setAccount(account);
|
conversation.setAccount(account);
|
||||||
|
|
||||||
File file = fileBackend.getJingleFile(message);
|
File file = fileBackend.getJingleFile(message);
|
||||||
ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file,
|
pfd = ParcelFileDescriptor.open(file,
|
||||||
ParcelFileDescriptor.MODE_READ_ONLY);
|
ParcelFileDescriptor.MODE_READ_ONLY);
|
||||||
return pfd;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -102,4 +116,7 @@ public class ImageProvider extends ContentProvider {
|
|||||||
+ message.getUuid());
|
+ message.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Uri getIncomingContentUri() {
|
||||||
|
return Uri.parse("content://eu.siacs.conversations.images/incoming");
|
||||||
|
}
|
||||||
}
|
}
|
@ -13,6 +13,7 @@ import eu.siacs.conversations.entities.Account;
|
|||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
import eu.siacs.conversations.services.ImageProvider;
|
||||||
import eu.siacs.conversations.utils.ExceptionHelper;
|
import eu.siacs.conversations.utils.ExceptionHelper;
|
||||||
import eu.siacs.conversations.utils.UIHelper;
|
import eu.siacs.conversations.utils.UIHelper;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -352,6 +353,7 @@ public class ConversationActivity extends XmppActivity {
|
|||||||
|
|
||||||
private void takePicture() {
|
private void takePicture() {
|
||||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, ImageProvider.getIncomingContentUri());
|
||||||
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
|
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
|
||||||
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
||||||
}
|
}
|
||||||
@ -732,6 +734,26 @@ public class ConversationActivity extends XmppActivity {
|
|||||||
announcePgp(getSelectedConversation().getAccount(),getSelectedConversation());
|
announcePgp(getSelectedConversation().getAccount(),getSelectedConversation());
|
||||||
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
|
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
|
||||||
encryptTextMessage();
|
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 {
|
} else {
|
||||||
Log.d(LOGTAG,"unknown result code:"+requestCode);
|
Log.d(LOGTAG,"unknown result code:"+requestCode);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user