aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/XmppActivity.java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java172
1 files changed, 60 insertions, 112 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index 5dfa50832..0cefe1d2d 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -20,18 +20,15 @@ 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.media.MediaMetadataRetriever;
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;
@@ -52,6 +49,12 @@ import android.widget.LinearLayout;
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;
@@ -61,12 +64,10 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
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;
-import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
@@ -361,8 +362,15 @@ public abstract class XmppActivity extends Activity {
case R.id.action_settings:
startActivity(new Intent(this, SettingsActivity.class));
break;
+ case R.id.action_check_updates:
+ startActivity(new Intent(this, UpdaterActivity.class));
+ break;
case R.id.action_accounts:
- startActivity(new Intent(this, ManageAccountActivity.class));
+ final Intent intent = new Intent(getApplicationContext(), EditAccountActivity.class);
+ Account mAccount = xmppConnectionService.getAccounts().get(0);
+ intent.putExtra("jid", mAccount.getJid().toBareJid().toString());
+ intent.putExtra("init", false);
+ startActivity(intent);
break;
case android.R.id.home:
finish();
@@ -384,7 +392,7 @@ public abstract class XmppActivity extends Activity {
mTertiaryTextColor = getResources().getColor(R.color.black12);
mColorRed = getResources().getColor(R.color.red800);
mColorOrange = getResources().getColor(R.color.orange500);
- mColorGreen = getResources().getColor(R.color.green500);
+ mColorGreen = getResources().getColor(R.color.realgreen);
mPrimaryColor = getResources().getColor(R.color.primary);
mPrimaryBackgroundColor = getResources().getColor(R.color.grey50);
mSecondaryBackgroundColor = getResources().getColor(R.color.grey200);
@@ -1054,7 +1062,7 @@ public abstract class XmppActivity extends Activity {
}
protected boolean manuallyChangePresence() {
- return getPreferences().getBoolean("manually_change_presence", false);
+ return getPreferences().getBoolean("manually_change_presence", true);
}
protected void unregisterNdefPushMessageCallback() {
@@ -1185,106 +1193,46 @@ public abstract class XmppActivity extends Activity {
return xmppConnectionService.getAvatarService();
}
- class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
- private final WeakReference<ImageView> 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) {
- 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<BitmapWorkerTask> bitmapWorkerTaskReference;
-
- public AsyncDrawable(Resources res, Bitmap bitmap,
- BitmapWorkerTask bitmapWorkerTask) {
- super(res, bitmap);
- bitmapWorkerTaskReference = new WeakReference<>(
- bitmapWorkerTask);
- }
-
- public BitmapWorkerTask getBitmapWorkerTask() {
- return bitmapWorkerTaskReference.get();
- }
- }
+ 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);
+ try {
+ MediaMetadataRetriever retriever = new MediaMetadataRetriever();
+ //use one of overloaded setDataSource() functions to set your data source
+ retriever.setDataSource(this, Uri.fromFile(vp));
+ String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
+ long microSecond = Long.parseLong(time);
+ 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);
+ Glide.with(getApplicationContext())
+ .load(vp)
+ .asBitmap()
+ .override(400, 400)
+ .fitCenter()
+ //.centerCrop()
+ .diskCacheStrategy(DiskCacheStrategy.RESULT)
+ .videoDecoder(fileDescriptorBitmapDecoder)
+ .into(imageView);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}