From 679ac2ea21709d3a4b0e80bdebe740beceac274d Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 28 May 2016 22:17:11 +0200 Subject: integrate image- and video player --- build.gradle | 11 ++- src/main/AndroidManifest.xml | 6 ++ .../ui/ShowFullscreenMessageActivity.java | 110 +++++++++++++++++++++ .../eu/siacs/conversations/ui/XmppActivity.java | 28 +++--- .../conversations/ui/adapter/MessageAdapter.java | 72 +++++++++----- .../res/layout/activity_fullscreen_message.xml | 20 ++++ src/main/res/values/ids.xml | 2 + 7 files changed, 210 insertions(+), 39 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/ShowFullscreenMessageActivity.java create mode 100644 src/main/res/layout/activity_fullscreen_message.xml diff --git a/build.gradle b/build.gradle index 3374f3604..b380223bb 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,12 @@ repositories { mavenCentral() } +allprojects { + repositories { + maven { url "https://jitpack.io" } + } +} + configurations { playstoreCompile } @@ -25,7 +31,6 @@ dependencies { compile project(':libs:MemorizingTrustManager') compile project(':libs:audiowife') - playstoreCompile 'com.google.android.gms:play-services-gcm:9.0.0' compile 'org.sufficientlysecure:openpgp-api:10.0' compile 'com.soundcloud.android:android-crop:1.0.1@aar' @@ -48,6 +53,8 @@ dependencies { compile 'com.android.support:appcompat-v7:24.0.0-beta1' compile 'com.android.support:multidex:1.0.1' compile 'com.github.bumptech.glide:glide:3.5.2' + compile 'com.github.chrisbanes:PhotoView:1.2.6' + compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.0' compile 'com.google.android.gms:play-services-location:9.0.0' compile 'com.google.android.gms:play-services-maps:9.0.0' } @@ -66,7 +73,7 @@ android { minSdkVersion 14 targetSdkVersion 23 versionCode 144 - versionName "1.12.3" + versionName "1.12.4" archivesBaseName += "-$versionName" applicationId "eu.siacs.conversations" diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 1310816c4..a2acd1d38 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -29,6 +29,7 @@ android:label="@string/app_name" android:theme="@style/ConversationsTheme" android:name="android.support.multidex.MultiDexApplication" + android:largeHeap="true" tools:replace="android:label"> @@ -201,6 +202,11 @@ + + + glideAnimation) { + super.onResourceReady(resource, glideAnimation); + mAttacher.update(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void DisplayVideo(Uri uri) { + try { + mVideo.setVisibility(View.VISIBLE); + mVideo.setVideoURI(uri); + mFullscreenbutton.setVisibility(View.INVISIBLE); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } +} \ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index faa314752..0cefe1d2d 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -1193,18 +1193,22 @@ public abstract class XmppActivity extends Activity { return xmppConnectionService.getAvatarService(); } - public void loadBitmap(Message message, ImageView imageView) { - File bm; - bm = xmppConnectionService.getFileBackend().getFile(message, true); - Glide.with(this) - .load(bm) - .override(400, 400) - .fitCenter() - //.centerCrop() - .diskCacheStrategy(DiskCacheStrategy.RESULT) - .into(imageView); + public void loadBitmap(Message message, ImageView imageView) { + File bm; + bm = xmppConnectionService.getFileBackend().getFile(message, true); + try { + Glide.with(this) + .load(bm) + .override(400, 400) + .fitCenter() + //.centerCrop() + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .into(imageView); + } catch (Exception e) { + e.printStackTrace(); + } - } + } public void loadVideoPreview(Message message, ImageView imageView) { File vp = xmppConnectionService.getFileBackend().getFile(message, true); @@ -1214,7 +1218,7 @@ public abstract class XmppActivity extends Activity { retriever.setDataSource(this, Uri.fromFile(vp)); String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); long microSecond = Long.parseLong(time); - int duration = (int) microSecond / 2; //preview at half of video + int duration = (int) Math.ceil(microSecond / 2); //preview at half of video BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool(); VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(duration); FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 8fe1d029a..54cf97933 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -51,6 +51,7 @@ import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message.FileParams; import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.ui.ConversationActivity; +import eu.siacs.conversations.ui.ShowFullscreenMessageActivity; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.UIHelper; @@ -746,31 +747,52 @@ public class MessageAdapter extends ArrayAdapter { return view; } - public void openDownloadable(Message message) { - DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); - if (!file.exists()) { - Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show(); - return; - } - Intent openIntent = new Intent(Intent.ACTION_VIEW); - String mime = file.getMimeType(); - if (mime == null) { - mime = "*/*"; - } - openIntent.setDataAndType(Uri.fromFile(file), mime); - PackageManager manager = activity.getPackageManager(); - List infos = manager.queryIntentActivities(openIntent, 0); - if (infos.size() == 0) { - openIntent.setDataAndType(Uri.fromFile(file),"*/*"); - } - try { - getContext().startActivity(openIntent); - return; - } catch (ActivityNotFoundException e) { - //ignored - } - Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show(); - } + public void openDownloadable(Message message) { + DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); + if (!file.exists()) { + Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); + return; + } + String mime = file.getMimeType(); + + if (mime.startsWith("image/")) { + Intent intent = new Intent(getContext(), ShowFullscreenMessageActivity.class); + intent.putExtra("image", Uri.fromFile(file)); + try { + activity.startActivity(intent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + } else if (mime.startsWith("video/")) { + Intent intent = new Intent(getContext(), ShowFullscreenMessageActivity.class); + intent.putExtra("video", Uri.fromFile(file)); + try { + activity.startActivity(intent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + } + Intent openIntent = new Intent(Intent.ACTION_VIEW); + if (mime == null) { + mime = "*/*"; + } + openIntent.setDataAndType(Uri.fromFile(file), mime); + PackageManager manager = activity.getPackageManager(); + List infos = manager.queryIntentActivities(openIntent, 0); + if (infos.size() == 0) { + openIntent.setDataAndType(Uri.fromFile(file), "*/*"); + } + try { + getContext().startActivity(openIntent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + Toast.makeText(activity, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + + } public void showLocation(Message message) { for(Intent intent : GeoHelper.createGeoIntentsFromMessage(message)) { diff --git a/src/main/res/layout/activity_fullscreen_message.xml b/src/main/res/layout/activity_fullscreen_message.xml new file mode 100644 index 000000000..183513196 --- /dev/null +++ b/src/main/res/layout/activity_fullscreen_message.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/values/ids.xml b/src/main/res/values/ids.xml index 76c3940b0..75f75673b 100644 --- a/src/main/res/values/ids.xml +++ b/src/main/res/values/ids.xml @@ -1,4 +1,6 @@ + + \ No newline at end of file -- cgit v1.2.3