From 66457c9f2ec61953d831b132206e8e06e14313bd Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 24 Jan 2017 20:17:36 +0100 Subject: transcode videos before sharing. change storage location --- src/main/AndroidManifest.xml | 2 + .../conversations/persistance/FileBackend.java | 32 ++++----- .../services/XmppConnectionService.java | 79 +++++++++++++++++++++- .../conversations/ui/ConversationActivity.java | 19 +++++- .../siacs/conversations/ui/ShareWithActivity.java | 15 +++- .../conversations/ui/UiInformableCallback.java | 5 ++ src/main/res/values/strings.xml | 1 + src/main/res/xml/file_paths.xml | 5 +- 8 files changed, 130 insertions(+), 28 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/UiInformableCallback.java (limited to 'src/main') diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index d6991f88..c43c0429 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -19,6 +19,8 @@ android:name="android.permission.READ_PHONE_STATE" tools:node="remove" /> + + progressTracker = new ArrayList<>(); + final UiInformableCallback informableCallback; + if (callback instanceof UiInformableCallback) { + informableCallback = (UiInformableCallback) callback; + } else { + informableCallback = null; + } + MediaTranscoder.Listener listener = new MediaTranscoder.Listener() { + @Override + public void onTranscodeProgress(double progress) { + int p = ((int) Math.round(progress * 100) / 20) * 20; + if (!progressTracker.contains(p) && p != 100 && p != 0) { + progressTracker.add(p); + if (informableCallback != null) { + + informableCallback.inform(getString(R.string.transcoding_video_progress, p)); + } + } + } + + @Override + public void onTranscodeCompleted() { + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + getPgpEngine().encrypt(message, callback); + } else { + callback.success(message); + } + } + + @Override + public void onTranscodeCanceled() { + processAsFile(); + } + + @Override + public void onTranscodeFailed(Exception e) { + Log.d(Config.LOGTAG,"video transcoding failed "+e.getMessage()); + processAsFile(); + } + }; + MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(), + MediaFormatStrategyPresets.createAndroid720pStrategy(), listener); + } + + @Override + public void run() { + final String mimeType = MimeUtils.guessMimeTypeFromUri(XmppConnectionService.this, uri); + if (mimeType != null && mimeType.startsWith("video/") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + try { + processAsVideo(); + } catch (Throwable e) { + processAsFile(); + } + } else { + processAsFile(); + } + + } }); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 8a7a2785..65b81732 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1543,9 +1543,26 @@ public class ConversationActivity extends XmppActivity } final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG); prepareFileToast.show(); - xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback() { + xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback() { + @Override + public void inform(final String text) { + hidePrepareFileToast(prepareFileToast); + runOnUiThread(new Runnable() { + @Override + public void run() { + replaceToast(text); + } + }); + } + @Override public void success(Message message) { + runOnUiThread(new Runnable() { + @Override + public void run() { + hideToast(); + } + }); hidePrepareFileToast(prepareFileToast); xmppConnectionService.sendMessage(message); } diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index f5724fc6..9cb7c87e 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -59,7 +59,17 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer private Toast mToast; private AtomicInteger attachmentCounter = new AtomicInteger(0); - private UiCallback attachFileCallback = new UiCallback() { + private UiInformableCallback attachFileCallback = new UiInformableCallback() { + + @Override + public void inform(final String text) { + runOnUiThread(new Runnable() { + @Override + public void run() { + replaceToast(text); + } + }); + } @Override public void userInputRequried(PendingIntent pi, Message object) { @@ -293,8 +303,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } else { replaceToast(getString(R.string.preparing_file)); ShareWithActivity.this.xmppConnectionService - .attachFileToConversation(conversation, share.uris.get(0), - attachFileCallback); + .attachFileToConversation(conversation, share.uris.get(0), attachFileCallback); } } }; diff --git a/src/main/java/eu/siacs/conversations/ui/UiInformableCallback.java b/src/main/java/eu/siacs/conversations/ui/UiInformableCallback.java new file mode 100644 index 00000000..9021f988 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/UiInformableCallback.java @@ -0,0 +1,5 @@ +package eu.siacs.conversations.ui; + +public interface UiInformableCallback extends UiCallback { + void inform(String text); +} diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index b56ec72c..68e08ba4 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -732,4 +732,5 @@ Automatically delete messages from this device that are older than the configured time frame. Encrypting message Overstepping local retention period. + Compressing video (%s%% completed) diff --git a/src/main/res/xml/file_paths.xml b/src/main/res/xml/file_paths.xml index 6a5e2609..4147940e 100644 --- a/src/main/res/xml/file_paths.xml +++ b/src/main/res/xml/file_paths.xml @@ -1,7 +1,8 @@ - + + - + \ No newline at end of file -- cgit v1.2.3