diff options
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 13 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationActivity.java | 61 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 10 | ||||
-rw-r--r-- | src/main/res/menu/attachment_choices.xml | 2 | ||||
-rw-r--r-- | src/main/res/values-de/strings.xml | 4 | ||||
-rw-r--r-- | src/main/res/values/arrays.xml | 2 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 4 |
7 files changed, 69 insertions, 27 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 8f8d3bc70..c0cb0a7bd 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -520,12 +520,12 @@ public class FileBackend { return frame; } - private static String getTakePhotoPath() { + private static String getTakeFromCameraPath() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/Camera/"; } public Uri getTakePhotoUri() { - File file = new File(getTakePhotoPath() + "IMG_" + this.fileDateFormat.format(new Date()) + ".jpg"); + File file = new File(getTakeFromCameraPath() + "IMG_" + this.fileDateFormat.format(new Date()) + ".jpg"); file.getParentFile().mkdirs(); return getUriForFile(mXmppConnectionService, file); } @@ -552,10 +552,17 @@ public class FileBackend { return original; } else { List<String> segments = original.getPathSegments(); - return Uri.parse("file://" + getTakePhotoPath() + segments.get(segments.size() - 1)); + return Uri.parse("file://" + getTakeFromCameraPath() + segments.get(segments.size() - 1)); } } + public Uri getTakeVideoUri() { + File file = new File(getTakeFromCameraPath() + "VID_" + this.fileDateFormat.format(new Date()) + ".mp4"); + file.getParentFile().mkdirs(); + return getUriForFile(mXmppConnectionService, file); + } + + public Avatar getPepAvatar(Uri image, int size, Bitmap.CompressFormat format) { try { Avatar avatar = new Avatar(); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 96645c1e7..e47bb31e7 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -86,6 +86,8 @@ import de.pixart.messenger.xmpp.jid.InvalidJidException; import de.pixart.messenger.xmpp.jid.Jid; import de.timroes.android.listview.EnhancedListView; +import static de.pixart.messenger.ui.ShowFullscreenMessageActivity.getMimeType; + public class ConversationActivity extends XmppActivity implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast, View.OnClickListener { @@ -103,7 +105,7 @@ public class ConversationActivity extends XmppActivity public static final int REQUEST_TRUST_KEYS_MENU = 0x0209; public static final int REQUEST_START_DOWNLOAD = 0x0210; public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; - public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; + public static final int ATTACHMENT_CHOICE_TAKE_FROM_CAMERA = 0x0302; public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; public static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304; public static final int ATTACHMENT_CHOICE_LOCATION = 0x0305; @@ -617,7 +619,7 @@ public class ConversationActivity extends XmppActivity @Override public void onPresenceSelected() { - Intent intent = new Intent(); + final Intent intent = new Intent(); boolean chooser = false; String fallbackPackageId = null; switch (attachmentChoice) { @@ -635,13 +637,36 @@ public class ConversationActivity extends XmppActivity intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setAction(Intent.ACTION_GET_CONTENT); break; - case ATTACHMENT_CHOICE_TAKE_PHOTO: - Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri(); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); - intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); - mPendingPhotoUris.clear(); - mPendingPhotoUris.add(uri); + case ATTACHMENT_CHOICE_TAKE_FROM_CAMERA: + AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this); + builder.setTitle(getString(R.string.attach_take_from_camera)); + builder.setNegativeButton(getString(R.string.action_take_photo), + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri(); + intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); + intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); + mPendingPhotoUris.clear(); + mPendingPhotoUris.add(uri); + startActivityForResult(intent, attachmentChoice); + } + }); + builder.setPositiveButton(getString(R.string.action_take_video), + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Uri uri = xmppConnectionService.getFileBackend().getTakeVideoUri(); + intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); + mPendingFileUris.clear(); + mPendingFileUris.add(uri); + startActivityForResult(intent, attachmentChoice); + } + }); + builder.create().show(); break; case ATTACHMENT_CHOICE_CHOOSE_FILE: chooser = true; @@ -712,7 +737,7 @@ public class ConversationActivity extends XmppActivity case ATTACHMENT_CHOICE_RECORD_VOICE: getPreferences().edit().putString("recently_used_quick_action", "voice").apply(); break; - case ATTACHMENT_CHOICE_TAKE_PHOTO: + case ATTACHMENT_CHOICE_TAKE_FROM_CAMERA: getPreferences().edit().putString("recently_used_quick_action", "photo").apply(); break; case ATTACHMENT_CHOICE_CHOOSE_IMAGE: @@ -949,7 +974,7 @@ public class ConversationActivity extends XmppActivity attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE); break; case R.id.attach_take_picture: - attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); + attachFile(ATTACHMENT_CHOICE_TAKE_FROM_CAMERA); break; case R.id.attach_choose_video: attachFile(ATTACHMENT_CHOICE_CHOOSE_VIDEO); @@ -1543,7 +1568,7 @@ public class ConversationActivity extends XmppActivity } @Override - protected void onActivityResult(int requestCode, int resultCode, final Intent data) { + protected void onActivityResult(final int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == REQUEST_DECRYPT_PGP) { @@ -1586,7 +1611,10 @@ public class ConversationActivity extends XmppActivity } } } - } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE || requestCode == ATTACHMENT_CHOICE_CHOOSE_VIDEO) { + } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE + || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE + || requestCode == ATTACHMENT_CHOICE_CHOOSE_VIDEO + || requestCode == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA) { final List<Uri> uris = extractUriFromIntent(data); final Conversation c = getSelectedConversation(); final OnPresenceSelected callback = new OnPresenceSelected() { @@ -1596,6 +1624,9 @@ public class ConversationActivity extends XmppActivity mPendingFileUris.addAll(uris); if (xmppConnectionServiceBound) { for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) { + if (requestCode == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA && getMimeType(i.next().toString()).contains("image")) { + return; + } Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE"); attachFileToConversation(c, i.next()); } @@ -1609,12 +1640,12 @@ public class ConversationActivity extends XmppActivity } else { selectPresence(c, callback); } - } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) { + } else if (requestCode == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA) { if (mPendingPhotoUris.size() == 1) { Uri uri = FileBackend.getIndexableTakePhotoUri(mPendingPhotoUris.get(0)); mPendingPhotoUris.set(0, uri); if (xmppConnectionServiceBound) { - Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching photo to conversations. TAKE_PHOTO"); + Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching photo to conversations. TAKE_FROM_CAMERA"); attachPhotoToConversation(getSelectedConversation(), uri); mPendingPhotoUris.clear(); } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index bfdcd41f1..d67474965 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -342,8 +342,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (tag instanceof SendButtonAction) { SendButtonAction action = (SendButtonAction) tag; switch (action) { - case TAKE_PHOTO: - activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_TAKE_PHOTO); + case TAKE_FROM_CAMERA: + activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_TAKE_FROM_CAMERA); break; case SEND_LOCATION: activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_LOCATION); @@ -1173,7 +1173,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa mSendingPgpMessage.set(false); } - enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE} + enum SendButtonAction {TEXT, TAKE_FROM_CAMERA, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE} private int getSendButtonImageResource(SendButtonAction action, Presence.Status status) { switch (action) { @@ -1190,7 +1190,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa default: return R.drawable.ic_send_text_offline; } - case TAKE_PHOTO: + case TAKE_FROM_CAMERA: switch (status) { case CHAT: case ONLINE: @@ -1287,7 +1287,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } switch (setting) { case "photo": - action = SendButtonAction.TAKE_PHOTO; + action = SendButtonAction.TAKE_FROM_CAMERA; break; case "location": action = SendButtonAction.SEND_LOCATION; diff --git a/src/main/res/menu/attachment_choices.xml b/src/main/res/menu/attachment_choices.xml index 652d27647..1f5ef9c2c 100644 --- a/src/main/res/menu/attachment_choices.xml +++ b/src/main/res/menu/attachment_choices.xml @@ -13,7 +13,7 @@ <item android:id="@+id/attach_take_picture" - android:title="@string/attach_take_picture" + android:title="@string/attach_take_from_camera" android:icon="?attr/ic_attach_camera"/> <item diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index d86318e5d..c2107d4e1 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -121,7 +121,7 @@ <string name="receive_presence_updates">Online-Status empfangen</string> <string name="ask_for_presence_updates">Online-Status anfragen</string> <string name="attach_choose_picture">Bild auswählen</string> - <string name="attach_take_picture">Bild aufnehmen</string> + <string name="attach_take_from_camera">Mit Kamera aufnehmen</string> <string name="preemptively_grant">Statusanfragen vorab erlauben</string> <string name="error_not_an_image_file">Die ausgewählte Datei ist kein Bild</string> <string name="error_compressing_image">Fehler beim Umwandeln des Bildes</string> @@ -722,5 +722,7 @@ <string name="session_failure">Sitzungsfehler</string> <string name="unpublish_pgp">Öffentlichen OpenPGP-Schlüssel verwerfen</string> <string name="unpublish_pgp_message">Bist du sicher, dass du deinen öffentlichen OpenPGP-Schlüssel aus deiner Anwesenheitsmitteilung entfernen möchtest?\\nDeine Kontakte können dir dann keine OpenPGP-verschlüsselten Nachrichten senden.</string> + <string name="action_take_photo">Foto aufnehmen</string> + <string name="action_take_video">Video aufnehmen</string> </resources> diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml index ba5218cbc..d56b12bae 100644 --- a/src/main/res/values/arrays.xml +++ b/src/main/res/values/arrays.xml @@ -43,7 +43,7 @@ <string-array name="quick_actions"> <item>@string/none</item> <item>@string/recently_used</item> - <item>@string/attach_take_picture</item> + <item>@string/attach_take_from_camera</item> <item>@string/attach_choose_picture</item> <item>@string/attach_record_voice</item> <item>@string/send_location</item> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2105ca21b..03a1a7c47 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -131,7 +131,7 @@ <string name="receive_presence_updates">Receive presence updates</string> <string name="ask_for_presence_updates">Ask for presence updates</string> <string name="attach_choose_picture">Choose picture</string> - <string name="attach_take_picture">Take picture</string> + <string name="attach_take_from_camera">Take from camera</string> <string name="preemptively_grant">Preemptively grant subscription request</string> <string name="error_not_an_image_file">The file you selected is not an image</string> <string name="error_compressing_image">Error while converting the image file</string> @@ -770,4 +770,6 @@ <string name="retry_decryption">Retry decryption</string> <string name="session_failure">Session failure</string> <string name="sasl_downgrade">Downgraded SASL mechanism</string> + <string name="action_take_photo">take photo</string> + <string name="action_take_video">record video</string> </resources> |