aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-01-04 17:18:34 +0100
committerChristian Schneppe <christian@pix-art.de>2019-01-04 17:18:34 +0100
commit7685c46c5af7154c6fb59ab020a174923643bd48 (patch)
treed14edb2d89e3139ca58080c6013cc1ae3ccf24a7 /src/main/java
parent032630143a286f886c58f802d3c61c9a4ba3e99f (diff)
add preference to play gif files automatically in chat view
fixes #170 and #236
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/SettingsActivity.java1
-rw-r--r--src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java14
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java95
5 files changed, 90 insertions, 24 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java b/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java
index d8659709b..2f2dcdf97 100644
--- a/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java
@@ -391,7 +391,7 @@ public class MediaViewerActivity extends XmppActivity {
return getPreferences().getBoolean("use_auto_rotate", getResources().getBoolean(R.bool.auto_rotate));
}
- protected SharedPreferences getPreferences() {
+ public SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
}
} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java
index 6f5cd2f0d..dc41011fb 100644
--- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java
@@ -62,6 +62,7 @@ public class SettingsActivity extends XmppActivity implements
public static final String USE_MULTI_ACCOUNTS = "use_multi_accounts";
public static final String QUICK_SHARE_ATTACHMENT_CHOICE = "quick_share_attachment_choice";
public static final String NUMBER_OF_ACCOUNTS = "number_of_accounts";
+ public static final String PLAY_GIF_INSIDE = "play_gif_inside";
public static final int REQUEST_WRITE_LOGS = 0xbf8701;
Preference multiAccountPreference;
diff --git a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java
index a12d398f2..d8c565345 100644
--- a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java
@@ -103,7 +103,7 @@ public class ShowLocationActivity extends XmppActivity {
}
}
- protected SharedPreferences getPreferences() {
+ public SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
}
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 19319df18..65383c2aa 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -55,6 +55,7 @@ import android.widget.Toast;
import net.java.otr4j.session.SessionID;
+import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -87,6 +88,7 @@ import de.pixart.messenger.utils.MenuDoubleTabUtil;
import de.pixart.messenger.utils.ThemeHelper;
import de.pixart.messenger.xmpp.OnKeyStatusUpdated;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
+import pl.droidsonroids.gif.GifDrawable;
import rocks.xmpp.addr.Jid;
public abstract class XmppActivity extends ActionBarActivity {
@@ -441,7 +443,7 @@ public abstract class XmppActivity extends ActionBarActivity {
return getBooleanPreference("display_enter_key", R.bool.display_enter_key);
}
- protected SharedPreferences getPreferences() {
+ public SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
}
@@ -1083,6 +1085,16 @@ public abstract class XmppActivity extends ActionBarActivity {
return xmppConnectionService.getAvatarService();
}
+ public void loadGif(File file, ImageView imageView) {
+ GifDrawable gifDrawable = null;
+ try {
+ gifDrawable = new GifDrawable(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ imageView.setImageDrawable(gifDrawable);
+ }
+
public void loadBitmap(Message message, ImageView imageView) {
Bitmap bm;
try {
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index fd9074771..1c53f1b5d 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -27,6 +27,7 @@ import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Base64;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
@@ -44,6 +45,7 @@ import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URL;
@@ -84,6 +86,10 @@ import de.pixart.messenger.utils.GeoHelper;
import de.pixart.messenger.utils.StylingHelper;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xmpp.mam.MamReference;
+import pl.droidsonroids.gif.GifDrawable;
+import pl.droidsonroids.gif.GifImageView;
+
+import static de.pixart.messenger.ui.SettingsActivity.PLAY_GIF_INSIDE;
public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
@@ -384,6 +390,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.download_button.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(text);
if (darkBackground) {
@@ -398,6 +405,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.download_button.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (darkBackground) {
viewHolder.messageBody.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Body1_Emoji_OnDark);
@@ -441,6 +449,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
});
viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
}
@@ -515,6 +524,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground, int type) {
viewHolder.download_button.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (darkBackground) {
@@ -611,6 +621,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text) {
viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE);
viewHolder.download_button.setText(text);
@@ -621,6 +632,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
private void displayOpenableMessage(ViewHolder viewHolder, final Message message) {
viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE);
final String mimeType = message.getMimeType();
@@ -686,6 +698,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.messageBody.setVisibility(View.GONE);
String url = GeoHelper.MapPreviewUri(message);
viewHolder.image.setVisibility(View.VISIBLE);
+ viewHolder.gifImage.setVisibility(View.GONE);
double target = metrics.density * 200;
int scaledW;
int scaledH;
@@ -723,6 +736,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
private void displayAudioMessage(ViewHolder viewHolder, Message message, boolean darkBackground) {
viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.GONE);
final RelativeLayout audioPlayer = viewHolder.audioPlayer;
@@ -735,29 +749,65 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.download_button.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE);
- viewHolder.image.setVisibility(View.VISIBLE);
- FileParams params = message.getFileParams();
- double target = metrics.density * 200;
- int scaledW;
- int scaledH;
- if (Math.max(params.height, params.width) * metrics.density <= target) {
- scaledW = (int) (params.width * metrics.density);
- scaledH = (int) (params.height * metrics.density);
- } else if (Math.max(params.height, params.width) <= target) {
- scaledW = params.width;
- scaledH = params.height;
- } else if (params.width <= params.height) {
- scaledW = (int) (params.width / ((double) params.height / target));
- scaledH = (int) target;
+ 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();
+ boolean playGifInside = activity.getPreferences().getBoolean(PLAY_GIF_INSIDE, activity.getResources().getBoolean(R.bool.play_gif_inside));
+ if (mime != null && mime.equals("image/gif") && playGifInside) {
+ Log.d(Config.LOGTAG, "Gif Image file");
+ viewHolder.image.setVisibility(View.GONE);
+ viewHolder.gifImage.setVisibility(View.VISIBLE);
+ FileParams params = message.getFileParams();
+ double target = metrics.density * 200;
+ int scaledW;
+ int scaledH;
+ if (Math.max(params.height, params.width) * metrics.density <= target) {
+ scaledW = (int) (params.width * metrics.density);
+ scaledH = (int) (params.height * metrics.density);
+ } else if (Math.max(params.height, params.width) <= target) {
+ scaledW = params.width;
+ scaledH = params.height;
+ } else if (params.width <= params.height) {
+ scaledW = (int) (params.width / ((double) params.height / target));
+ scaledH = (int) target;
+ } else {
+ scaledW = (int) target;
+ scaledH = (int) (params.height / ((double) params.width / target));
+ }
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH);
+ layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
+ viewHolder.gifImage.setLayoutParams(layoutParams);
+ activity.loadGif(file, viewHolder.gifImage);
+ viewHolder.gifImage.setOnClickListener(v -> openDownloadable(message));
} else {
- scaledW = (int) target;
- scaledH = (int) (params.height / ((double) params.width / target));
+ viewHolder.image.setVisibility(View.VISIBLE);
+ viewHolder.gifImage.setVisibility(View.GONE);
+ FileParams params = message.getFileParams();
+ double target = metrics.density * 200;
+ int scaledW;
+ int scaledH;
+ if (Math.max(params.height, params.width) * metrics.density <= target) {
+ scaledW = (int) (params.width * metrics.density);
+ scaledH = (int) (params.height * metrics.density);
+ } else if (Math.max(params.height, params.width) <= target) {
+ scaledW = params.width;
+ scaledH = params.height;
+ } else if (params.width <= params.height) {
+ scaledW = (int) (params.width / ((double) params.height / target));
+ scaledH = (int) target;
+ } else {
+ scaledW = (int) target;
+ scaledH = (int) (params.height / ((double) params.width / target));
+ }
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH);
+ layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
+ viewHolder.image.setLayoutParams(layoutParams);
+ activity.loadBitmap(message, viewHolder.image);
+ viewHolder.image.setOnClickListener(v -> openDownloadable(message));
}
- LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH);
- layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
- viewHolder.image.setLayoutParams(layoutParams);
- activity.loadBitmap(message, viewHolder.image);
- viewHolder.image.setOnClickListener(v -> openDownloadable(message));
}
private void loadMoreMessages(Conversation conversation) {
@@ -805,6 +855,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.indicator = view.findViewById(R.id.security_indicator);
viewHolder.edit_indicator = view.findViewById(R.id.edit_indicator);
viewHolder.image = view.findViewById(R.id.message_image);
+ viewHolder.gifImage = view.findViewById(R.id.message_image_gif);
viewHolder.messageBody = view.findViewById(R.id.message_body);
viewHolder.time = view.findViewById(R.id.message_time);
viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received);
@@ -819,6 +870,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.indicator = view.findViewById(R.id.security_indicator);
viewHolder.edit_indicator = view.findViewById(R.id.edit_indicator);
viewHolder.image = view.findViewById(R.id.message_image);
+ viewHolder.gifImage = view.findViewById(R.id.message_image_gif);
viewHolder.messageBody = view.findViewById(R.id.message_body);
viewHolder.time = view.findViewById(R.id.message_time);
viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received);
@@ -1147,6 +1199,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
protected Button download_button;
protected Button resend_button;
protected ImageView image;
+ protected GifImageView gifImage;
protected ImageView indicator;
protected ImageView indicatorReceived;
protected ImageView indicatorRead;