save newly taken photos in DCIM dir

This commit is contained in:
iNPUTmice 2014-08-21 09:19:18 +02:00
parent 7808e5b77f
commit 301477c764
3 changed files with 42 additions and 33 deletions

View file

@ -2,7 +2,6 @@ package eu.siacs.conversations.persistance;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
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;
@ -11,6 +10,9 @@ import java.io.OutputStream;
import java.security.DigestOutputStream; import java.security.DigestOutputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
@ -42,6 +44,8 @@ public class FileBackend {
private Context context; private Context context;
private LruCache<String, Bitmap> thumbnailCache; private LruCache<String, Bitmap> thumbnailCache;
private SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS",Locale.US);
public FileBackend(Context context) { public FileBackend(Context context) {
this.context = context; this.context = context;
@ -140,13 +144,7 @@ public class FileBackend {
private JingleFile copyImageToPrivateStorage(Message message, Uri image, private JingleFile copyImageToPrivateStorage(Message message, Uri image,
int sampleSize) throws ImageCopyException { int sampleSize) throws ImageCopyException {
try { try {
InputStream is; InputStream is = context.getContentResolver().openInputStream(image);
if (image != null) {
is = context.getContentResolver().openInputStream(image);
} else {
is = new FileInputStream(getIncomingFile());
image = getIncomingUri();
}
JingleFile file = getJingleFile(message); JingleFile file = getJingleFile(message);
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
file.createNewFile(); file.createNewFile();
@ -273,12 +271,17 @@ public class FileBackend {
f.delete(); f.delete();
} }
public File getIncomingFile() { public Uri getTakePhotoUri() {
return new File(context.getFilesDir().getAbsolutePath() + "/incoming"); StringBuilder pathBuilder = new StringBuilder();
} pathBuilder.append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
pathBuilder.append('/');
public Uri getIncomingUri() { pathBuilder.append("Camera");
return Uri.parse(context.getFilesDir().getAbsolutePath() + "/incoming"); pathBuilder.append('/');
pathBuilder.append("IMG_"+this.imageDateFormat.format(new Date())+".jpg");
Uri uri = Uri.parse("file://"+pathBuilder.toString());
File file = new File(uri.toString());
file.getParentFile().mkdirs();
return uri;
} }
public Avatar getPepAvatar(Uri image, int size, Bitmap.CompressFormat format) { public Avatar getPepAvatar(Uri image, int size, Bitmap.CompressFormat format) {

View file

@ -65,15 +65,6 @@ public class ImageProvider extends ContentProvider {
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 { } else {
throw new FileNotFoundException(); throw new FileNotFoundException();
} }
@ -118,8 +109,4 @@ public class ImageProvider extends ContentProvider {
+ message.getUuid() + message.getUuid()
+ ".webp"); + ".webp");
} }
public static Uri getIncomingContentUri() {
return Uri.parse("content://eu.siacs.conversations.images/incoming");
}
} }

View file

@ -10,7 +10,6 @@ import eu.siacs.conversations.R;
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.services.XmppConnectionService.OnConversationUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
@ -36,6 +35,7 @@ import android.graphics.drawable.Drawable;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -111,6 +111,8 @@ public class ConversationActivity extends XmppActivity {
protected ConversationActivity activity = this; protected ConversationActivity activity = this;
private DisplayMetrics metrics; private DisplayMetrics metrics;
private Toast prepareImageToast; private Toast prepareImageToast;
private Uri pendingImageUri = null;
public List<Conversation> getConversationList() { public List<Conversation> getConversationList() {
return this.conversationList; return this.conversationList;
@ -265,10 +267,11 @@ public class ConversationActivity extends XmppActivity {
@Override @Override
public void onPresenceSelected() { public void onPresenceSelected() {
if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) { if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) {
pendingImageUri = xmppConnectionService.getFileBackend().getTakePhotoUri();
Log.d("xmppService",pendingImageUri.toString());
Intent takePictureIntent = new Intent( Intent takePictureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE); MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,pendingImageUri);
ImageProvider.getIncomingContentUri());
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, startActivityForResult(takePictureIntent,
REQUEST_IMAGE_CAPTURE); REQUEST_IMAGE_CAPTURE);
@ -597,6 +600,13 @@ public class ConversationActivity extends XmppActivity {
if (conversationList.size() == 0) { if (conversationList.size() == 0) {
updateConversationList(); updateConversationList();
} }
if (getSelectedConversation()!=null && pendingImageUri !=null) {
attachImageToConversation(getSelectedConversation(), pendingImageUri);
pendingImageUri = null;
} else {
pendingImageUri = null;
}
if ((getIntent().getAction() != null) if ((getIntent().getAction() != null)
&& (getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) { && (getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) {
@ -659,8 +669,11 @@ public class ConversationActivity extends XmppActivity {
selectedFragment.hideSnackbar(); selectedFragment.hideSnackbar();
} }
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
attachImageToConversation(getSelectedConversation(), pendingImageUri = data.getData();
data.getData()); if (xmppConnectionServiceBound) {
attachImageToConversation(getSelectedConversation(),pendingImageUri);
pendingImageUri = null;
}
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) { } else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) { } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
@ -673,7 +686,13 @@ public class ConversationActivity extends XmppActivity {
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) { } else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
// encryptTextMessage(); // encryptTextMessage();
} else if (requestCode == REQUEST_IMAGE_CAPTURE) { } else if (requestCode == REQUEST_IMAGE_CAPTURE) {
attachImageToConversation(getSelectedConversation(), null); if (xmppConnectionServiceBound) {
attachImageToConversation(getSelectedConversation(), pendingImageUri);
pendingImageUri = null;
}
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(pendingImageUri);
sendBroadcast(intent);
} else if (requestCode == REQUEST_RECORD_AUDIO) { } else if (requestCode == REQUEST_RECORD_AUDIO) {
attachAudioToConversation(getSelectedConversation(), attachAudioToConversation(getSelectedConversation(),
data.getData()); data.getData());