From 2da48b39b5605b174493cf4fa9c5232b63077de6 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 17 May 2016 20:52:57 +0200 Subject: try out some faster image loader * picasso * glide --- build.gradle | 7 ++++++ .../eu/siacs/conversations/ui/XmppActivity.java | 26 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 89a310282..4ca246e98 100644 --- a/build.gradle +++ b/build.gradle @@ -45,6 +45,13 @@ dependencies { compile 'com.google.android.gms:play-services:6.5.87' compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:multidex:1.0.0' + + compile 'com.squareup.picasso:picasso:2.4.0' + compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0' + + compile 'com.github.bumptech.glide:glide:3.5.2' + compile 'com.android.support:support-v4:22.0.0' + playstoreCompile 'com.google.android.gms:play-services-gcm:8.4.0' } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 478bd5f05..6bb3459c8 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -42,7 +42,6 @@ import android.preference.PreferenceManager; import android.text.InputType; import android.util.DisplayMetrics; import android.util.Log; -import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -53,12 +52,15 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; +import com.squareup.picasso.Picasso; import net.java.otr4j.session.SessionID; @@ -67,8 +69,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.RunnableFuture; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -1206,6 +1206,24 @@ public abstract class XmppActivity extends Activity { } public void loadBitmap(Message message, ImageView imageView) { + //new + /*Picasso.with(this) + .load(xmppConnectionService.getFileBackend().getFile(message, true)) + .resize(300, 300) + .centerCrop() + .into(imageView); + Log.d(Config.LOGTAG,"Load image with picasso");*/ + + Glide.with(this) + .load(xmppConnectionService.getFileBackend().getFile(message, true)) + .override(288, 288) + .fitCenter() + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .into(imageView); + //Log.d(Config.LOGTAG,"Load image with glide"); + + + /*old Bitmap bm; try { bm = xmppConnectionService.getFileBackend().getThumbnail(message, @@ -1231,7 +1249,7 @@ public abstract class XmppActivity extends Activity { ignored.printStackTrace(); } } - } + }*/ } public static boolean cancelPotentialWork(Message message, ImageView imageView) { -- cgit v1.2.3 From ea44db4c633ba5ede5044aaa089819a817060d28 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 20 May 2016 22:26:25 +0200 Subject: use glide as image loader and add a simple video preview --- build.gradle | 208 ++++++++++----------- .../eu/siacs/conversations/ui/XmppActivity.java | 151 +++------------ .../conversations/ui/adapter/MessageAdapter.java | 31 ++- 3 files changed, 159 insertions(+), 231 deletions(-) diff --git a/build.gradle b/build.gradle index 4ca246e98..c6b07a09d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,134 +1,132 @@ // Top-level build file where you can add configuration options common to all // sub-projects/modules. buildscript { - repositories { - jcenter() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' - } + repositories { + jcenter() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.1.0' + } } apply plugin: 'com.android.application' repositories { - jcenter() - mavenCentral() + jcenter() + mavenCentral() } configurations { - playstoreCompile + playstoreCompile } dependencies { - compile project(':libs:MemorizingTrustManager') - compile project(':libs:audiowife') - compile 'org.sufficientlysecure:openpgp-api:10.0' - compile 'com.soundcloud.android:android-crop:1.0.1@aar' - compile 'com.android.support:support-v13:23.2.0' - compile 'org.bouncycastle:bcprov-jdk15on:1.52' - compile 'org.bouncycastle:bcmail-jdk15on:1.52' - compile 'org.jitsi:org.otr4j:0.22' - compile 'org.gnu.inet:libidn:1.15' - compile 'com.google.zxing:core:3.2.1' - compile 'com.google.zxing:android-integration:3.2.1' - compile 'de.measite.minidns:minidns:0.1.7' - compile 'de.timroes.android:EnhancedListView:0.3.4' - compile 'me.leolin:ShortcutBadger:1.1.4@aar' - compile 'com.kyleduo.switchbutton:library:1.2.8' - compile 'org.whispersystems:axolotl-android:1.3.4' - compile 'com.makeramen:roundedimageview:2.2.0' - compile 'jetty:javax.servlet:5.1.12' - compile 'com.google.code.gson:gson:2.3.1' - compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' - compile 'com.google.android.gms:play-services:6.5.87' - compile 'com.android.support:appcompat-v7:21.0.3' + compile project(':libs:MemorizingTrustManager') + compile project(':libs:audiowife') + + + playstoreCompile 'com.google.android.gms:play-services-gcm:8.4.0' + compile 'org.sufficientlysecure:openpgp-api:10.0' + compile 'com.soundcloud.android:android-crop:1.0.1@aar' + compile 'com.android.support:support-v13:24.0.0-alpha2' + compile 'org.bouncycastle:bcprov-jdk15on:1.52' + compile 'org.bouncycastle:bcmail-jdk15on:1.52' + compile 'org.jitsi:org.otr4j:0.22' + compile 'org.gnu.inet:libidn:1.15' + compile 'com.google.zxing:core:3.2.1' + compile 'com.google.zxing:android-integration:3.2.1' + compile 'de.measite.minidns:minidns:0.1.7' + compile 'de.timroes.android:EnhancedListView:0.3.4' + compile 'me.leolin:ShortcutBadger:1.1.4@aar' + compile 'com.kyleduo.switchbutton:library:1.2.8' + compile 'org.whispersystems:axolotl-android:1.3.4' + compile 'com.makeramen:roundedimageview:2.2.0' + compile 'jetty:javax.servlet:5.1.12' + compile 'com.google.code.gson:gson:2.3.1' + compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' + compile 'com.google.android.gms:play-services:8.4.0' + compile 'com.android.support:appcompat-v7:24.0.0-alpha2' compile 'com.android.support:multidex:1.0.0' - - compile 'com.squareup.picasso:picasso:2.4.0' - compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0' - compile 'com.github.bumptech.glide:glide:3.5.2' - compile 'com.android.support:support-v4:22.0.0' - - playstoreCompile 'com.google.android.gms:play-services-gcm:8.4.0' + compile 'com.android.support:support-v4:24.0.0-alpha2' + compile 'com.google.android.gms:play-services-gcm:8.4.0' } ext { - travisBuild = System.getenv("TRAVIS") == "true" - // allows for -Dpre-dex=false to be set - preDexEnabled = "true".equals(System.getProperty("pre-dex", "true")) + travisBuild = System.getenv("TRAVIS") == "true" + // allows for -Dpre-dex=false to be set + preDexEnabled = "true".equals(System.getProperty("pre-dex", "true")) } android { - compileSdkVersion 23 - buildToolsVersion "23.0.2" + compileSdkVersion 23 + buildToolsVersion "23.0.2" - defaultConfig { - minSdkVersion 14 - targetSdkVersion 23 - versionCode 143 - versionName "1.12.2" - archivesBaseName += "-$versionName" - applicationId "eu.siacs.conversations" + defaultConfig { + minSdkVersion 14 + targetSdkVersion 23 + versionCode 143 + versionName "1.12.2" + archivesBaseName += "-$versionName" + applicationId "eu.siacs.conversations" // Enabling multidex support. multiDexEnabled true - } + } - dexOptions { - // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false. - preDexLibraries = preDexEnabled && !travisBuild + dexOptions { + // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false. + preDexLibraries = preDexEnabled && !travisBuild javaMaxHeapSize "4g" - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 - } - - productFlavors { - playstore - free - } - if (project.hasProperty('mStoreFile') && - project.hasProperty('mStorePassword') && - project.hasProperty('mKeyAlias') && - project.hasProperty('mKeyPassword')) { - signingConfigs { - release { - storeFile file(mStoreFile) - storePassword mStorePassword - keyAlias mKeyAlias - keyPassword mKeyPassword - } - } - buildTypes.release.signingConfig = signingConfigs.release - } else { - buildTypes.release.signingConfig = null - } - - lintOptions { - disable 'ExtraTranslation', 'MissingTranslation', 'InvalidPackage', 'MissingQuantity', 'AppCompatResource' - } - - subprojects { - - afterEvaluate { - if (getPlugins().hasPlugin('android') || - getPlugins().hasPlugin('android-library')) { - - configure(android.lintOptions) { - disable 'AndroidGradlePluginVersion', 'MissingTranslation' - } - } - - } - } - - packagingOptions { - exclude 'META-INF/BCKEY.DSA' - exclude 'META-INF/BCKEY.SF' - } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + productFlavors { + playstore + free + } + if (project.hasProperty('mStoreFile') && + project.hasProperty('mStorePassword') && + project.hasProperty('mKeyAlias') && + project.hasProperty('mKeyPassword')) { + signingConfigs { + release { + storeFile file(mStoreFile) + storePassword mStorePassword + keyAlias mKeyAlias + keyPassword mKeyPassword + } + } + buildTypes.release.signingConfig = signingConfigs.release + } else { + buildTypes.release.signingConfig = null + } + + lintOptions { + disable 'ExtraTranslation', 'MissingTranslation', 'InvalidPackage', 'MissingQuantity', 'AppCompatResource' + } + + subprojects { + + afterEvaluate { + if (getPlugins().hasPlugin('android') || + getPlugins().hasPlugin('android-library')) { + + configure(android.lintOptions) { + disable 'AndroidGradlePluginVersion', 'MissingTranslation' + } + } + + } + } + + packagingOptions { + exclude 'META-INF/BCKEY.DSA' + exclude 'META-INF/BCKEY.SF' + } } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 6bb3459c8..e1f563e01 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -20,18 +20,14 @@ import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Point; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; import android.nfc.NfcEvent; -import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -53,19 +49,21 @@ import android.widget.TextView; import android.widget.Toast; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.DecodeFormat; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.FileDescriptorBitmapDecoder; +import com.bumptech.glide.load.resource.bitmap.VideoBitmapDecoder; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; -import com.squareup.picasso.Picasso; import net.java.otr4j.session.SessionID; -import java.io.FileNotFoundException; -import java.lang.ref.WeakReference; +import java.io.File; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -1171,124 +1169,33 @@ public abstract class XmppActivity extends Activity { return xmppConnectionService.getAvatarService(); } - class BitmapWorkerTask extends AsyncTask { - private final WeakReference imageViewReference; - private Message message = null; - - public BitmapWorkerTask(ImageView imageView) { - imageViewReference = new WeakReference<>(imageView); - } - - @Override - protected Bitmap doInBackground(Message... params) { - if (isCancelled()) { - return null; - } - message = params[0]; - try { - return xmppConnectionService.getFileBackend().getThumbnail( - message, (int) (metrics.density * 288), false); - } catch (FileNotFoundException e) { - return null; - } - } - - @Override - protected void onPostExecute(Bitmap bitmap) { - if (bitmap != null && !isCancelled()) { - final ImageView imageView = imageViewReference.get(); - if (imageView != null) { - imageView.setImageBitmap(bitmap); - imageView.setBackgroundColor(0x00000000); - } - } - } - } - public void loadBitmap(Message message, ImageView imageView) { - //new - /*Picasso.with(this) - .load(xmppConnectionService.getFileBackend().getFile(message, true)) - .resize(300, 300) - .centerCrop() - .into(imageView); - Log.d(Config.LOGTAG,"Load image with picasso");*/ - - Glide.with(this) - .load(xmppConnectionService.getFileBackend().getFile(message, true)) + File bm; + bm = xmppConnectionService.getFileBackend().getFile(message, true); + Glide.with(this) + .load(bm) .override(288, 288) - .fitCenter() + //.fitCenter() + .centerCrop() .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(imageView); - //Log.d(Config.LOGTAG,"Load image with glide"); - - - /*old - Bitmap bm; - try { - bm = xmppConnectionService.getFileBackend().getThumbnail(message, - (int) (metrics.density * 288), true); - } catch (FileNotFoundException e) { - bm = null; - } - if (bm != null) { - cancelPotentialWork(message, imageView); - imageView.setImageBitmap(bm); - imageView.setBackgroundColor(0x00000000); - } else { - if (cancelPotentialWork(message, imageView)) { - imageView.setBackgroundColor(0xff333333); - imageView.setImageDrawable(null); - final BitmapWorkerTask task = new BitmapWorkerTask(imageView); - final AsyncDrawable asyncDrawable = new AsyncDrawable( - getResources(), null, task); - imageView.setImageDrawable(asyncDrawable); - try { - task.execute(message); - } catch (final RejectedExecutionException ignored) { - ignored.printStackTrace(); - } - } - }*/ - } - - public static boolean cancelPotentialWork(Message message, ImageView imageView) { - final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); - - if (bitmapWorkerTask != null) { - final Message oldMessage = bitmapWorkerTask.message; - if (oldMessage == null || message != oldMessage) { - bitmapWorkerTask.cancel(true); - } else { - return false; - } - } - return true; - } - - private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) { - if (imageView != null) { - final Drawable drawable = imageView.getDrawable(); - if (drawable instanceof AsyncDrawable) { - final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; - return asyncDrawable.getBitmapWorkerTask(); - } - } - return null; - } - - static class AsyncDrawable extends BitmapDrawable { - private final WeakReference bitmapWorkerTaskReference; - - public AsyncDrawable(Resources res, Bitmap bitmap, - BitmapWorkerTask bitmapWorkerTask) { - super(res, bitmap); - bitmapWorkerTaskReference = new WeakReference<>( - bitmapWorkerTask); - } - - public BitmapWorkerTask getBitmapWorkerTask() { - return bitmapWorkerTaskReference.get(); - } + //Log.d(Config.LOGTAG,"Load image with glide"); + } + + public void loadVideoPreview(Message message, ImageView imageView) { + BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool(); + int microSecond = 1000000;// 1st second of video + VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond); + FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888); + File vp = xmppConnectionService.getFileBackend().getFile(message, true); + Glide.with(getApplicationContext()) + .load(vp) + .asBitmap() + .override(288,288) + //.fitCenter() + .centerCrop() + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .videoDecoder(fileDescriptorBitmapDecoder) + .into(imageView); } } 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 b671a6f43..8fe1d029a 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -485,6 +485,25 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.image.setOnLongClickListener(openContextMenu); } + private void displayVideoMessage(ViewHolder viewHolder, + final Message message) { + viewHolder.aw_player.setVisibility(View.GONE); + if (viewHolder.download_button != null) { + viewHolder.download_button.setVisibility(View.GONE); + } + viewHolder.messageBody.setVisibility(View.GONE); + viewHolder.image.setVisibility(View.VISIBLE); + activity.loadVideoPreview(message, viewHolder.image); + viewHolder.image.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + openDownloadable(message); + } + }); + viewHolder.image.setOnLongClickListener(openContextMenu); + } + private void loadMoreMessages(Conversation conversation) { conversation.setLastClearHistory(0); conversation.setHasMessagesLeftOnServer(true); @@ -631,6 +650,7 @@ public class MessageAdapter extends ArrayAdapter { }); final Transferable transferable = message.getTransferable(); + String mimeType = message.getMimeType(); if (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING) { if (transferable.getStatus() == Transferable.STATUS_OFFER) { displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message))); @@ -645,10 +665,13 @@ public class MessageAdapter extends ArrayAdapter { if (message.getFileParams().width > 0) { displayImageMessage(viewHolder,message); } else { - String mimeType = message.getMimeType(); - if (mimeType != null) { - if (message.getMimeType().startsWith("audio/")) - displayAudioMessage(viewHolder, message, position); + if (mimeType != null) { + if (message.getMimeType().startsWith("audio/")) { + displayAudioMessage(viewHolder, message, position); + } else if (message.getMimeType().startsWith("video/")) { + displayVideoMessage(viewHolder, message); + //ToDo add overlay e.g. play button + } else displayOpenableMessage(viewHolder, message); } else displayOpenableMessage(viewHolder, message); } -- cgit v1.2.3 From 516da5145406af146ba267ce874a1c8d20059918 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 20 May 2016 22:31:16 +0200 Subject: changed colors to standard from @color and add border to images --- src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 8 ++++---- src/main/res/layout/fragment_conversation.xml | 6 +++--- src/main/res/layout/message_received.xml | 5 +++-- src/main/res/layout/message_sent.xml | 5 +++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index e1f563e01..5d249d863 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -1175,8 +1175,8 @@ public abstract class XmppActivity extends Activity { Glide.with(this) .load(bm) .override(288, 288) - //.fitCenter() - .centerCrop() + .fitCenter() + //.centerCrop() .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(imageView); //Log.d(Config.LOGTAG,"Load image with glide"); @@ -1192,8 +1192,8 @@ public abstract class XmppActivity extends Activity { .load(vp) .asBitmap() .override(288,288) - //.fitCenter() - .centerCrop() + .fitCenter() + //.centerCrop() .diskCacheStrategy(DiskCacheStrategy.RESULT) .videoDecoder(fileDescriptorBitmapDecoder) .into(imageView); diff --git a/src/main/res/layout/fragment_conversation.xml b/src/main/res/layout/fragment_conversation.xml index 88f2cbb28..a66345e17 100644 --- a/src/main/res/layout/fragment_conversation.xml +++ b/src/main/res/layout/fragment_conversation.xml @@ -13,7 +13,7 @@ android:layout_above="@+id/snackbar" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" - android:background="@color/background_floating_material_light" + android:background="@color/grey200" android:divider="@null" android:dividerHeight="0dp" android:listSelector="@android:color/transparent" @@ -30,7 +30,7 @@ android:layout_alignParentLeft="true" android:background="@color/grey200" android:clickable="true" - android:paddingTop="4dp" + android:paddingTop="2dp" android:paddingLeft="2dp" android:paddingBottom="2dp"> @@ -61,7 +61,7 @@ android:layout_height="48dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" - android:background="?android:selectableItemBackground" + android:background="@color/grey200" android:src="@drawable/ic_send_text_offline" /> diff --git a/src/main/res/layout/message_received.xml b/src/main/res/layout/message_received.xml index 77d560297..14aea096f 100644 --- a/src/main/res/layout/message_received.xml +++ b/src/main/res/layout/message_received.xml @@ -46,9 +46,10 @@ android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginBottom="4dp" - app:riv_corner_radius="5dp" android:adjustViewBounds="true" - android:background="@color/black87" + app:riv_border_width="1dp" + app:riv_border_color="@color/black12" + app:riv_corner_radius="5dp" android:scaleType="centerCrop" />