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

View file

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