Allow to disable animated custom emoji
This commit is contained in:
parent
50204353fb
commit
411e9d2edb
|
@ -17,7 +17,9 @@ package app.fedilab.android.client.Entities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
@ -41,6 +43,8 @@ import java.util.List;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
|
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
|
||||||
|
|
||||||
|
import static app.fedilab.android.helper.Helper.drawableToBitmap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 23/04/2017.
|
* Created by Thomas on 23/04/2017.
|
||||||
*/
|
*/
|
||||||
|
@ -155,6 +159,8 @@ public class Notification implements Parcelable {
|
||||||
//SpannableString displayNameSpan = status.getDisplayNameSpan();
|
//SpannableString displayNameSpan = status.getDisplayNameSpan();
|
||||||
SpannableString contentSpan = status.getContentSpan();
|
SpannableString contentSpan = status.getContentSpan();
|
||||||
SpannableString contentSpanCW = status.getContentSpanCW();
|
SpannableString contentSpanCW = status.getContentSpanCW();
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||||
if( emojisAccounts != null)
|
if( emojisAccounts != null)
|
||||||
emojis.addAll(emojisAccounts);
|
emojis.addAll(emojisAccounts);
|
||||||
if( emojis != null && emojis.size() > 0 ) {
|
if( emojis != null && emojis.size() > 0 ) {
|
||||||
|
@ -187,9 +193,18 @@ public class Notification implements Parcelable {
|
||||||
for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||||
final int endPosition = startPosition + targetedEmoji.length();
|
final int endPosition = startPosition + targetedEmoji.length();
|
||||||
if( endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
|
if( endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
|
||||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
ImageSpan imageSpan;
|
||||||
resource.setVisible(true, true);
|
if( !disableAnimatedEmoji) {
|
||||||
ImageSpan imageSpan = new ImageSpan(resource);
|
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
imageSpan = new ImageSpan(resource);
|
||||||
|
}else{
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
Bitmap bitmap = drawableToBitmap(resource);
|
||||||
|
imageSpan = new ImageSpan(context,
|
||||||
|
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||||
|
(int) Helper.convertDpToPixel(20, context), false));
|
||||||
|
}
|
||||||
contentSpan.setSpan(
|
contentSpan.setSpan(
|
||||||
imageSpan, startPosition,
|
imageSpan, startPosition,
|
||||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
@ -216,9 +231,18 @@ public class Notification implements Parcelable {
|
||||||
for (int startPosition = -1; (startPosition = contentSpanCW.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
for (int startPosition = -1; (startPosition = contentSpanCW.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||||
final int endPosition = startPosition + targetedEmoji.length();
|
final int endPosition = startPosition + targetedEmoji.length();
|
||||||
if( endPosition <= contentSpanCW.toString().length() && endPosition >= startPosition) {
|
if( endPosition <= contentSpanCW.toString().length() && endPosition >= startPosition) {
|
||||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
ImageSpan imageSpan;
|
||||||
resource.setVisible(true, true);
|
if( !disableAnimatedEmoji) {
|
||||||
ImageSpan imageSpan = new ImageSpan(resource);
|
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
imageSpan = new ImageSpan(resource);
|
||||||
|
}else {
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
Bitmap bitmap = drawableToBitmap(resource);
|
||||||
|
imageSpan = new ImageSpan(context,
|
||||||
|
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||||
|
(int) Helper.convertDpToPixel(20, context), false));
|
||||||
|
}
|
||||||
contentSpanCW.setSpan(
|
contentSpanCW.setSpan(
|
||||||
imageSpan, startPosition,
|
imageSpan, startPosition,
|
||||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -76,6 +77,7 @@ import app.fedilab.android.interfaces.OnRetrieveImageInterface;
|
||||||
import static app.fedilab.android.helper.Helper.THEME_BLACK;
|
import static app.fedilab.android.helper.Helper.THEME_BLACK;
|
||||||
import static app.fedilab.android.helper.Helper.THEME_DARK;
|
import static app.fedilab.android.helper.Helper.THEME_DARK;
|
||||||
import static app.fedilab.android.helper.Helper.THEME_LIGHT;
|
import static app.fedilab.android.helper.Helper.THEME_LIGHT;
|
||||||
|
import static app.fedilab.android.helper.Helper.drawableToBitmap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 23/04/2017.
|
* Created by Thomas on 23/04/2017.
|
||||||
|
@ -1076,6 +1078,8 @@ public class Status implements Parcelable{
|
||||||
SpannableString displayNameSpan = status.getDisplayNameSpan();
|
SpannableString displayNameSpan = status.getDisplayNameSpan();
|
||||||
SpannableString contentSpan = status.getContentSpan();
|
SpannableString contentSpan = status.getContentSpan();
|
||||||
SpannableString contentSpanCW = status.getContentSpanCW();
|
SpannableString contentSpanCW = status.getContentSpanCW();
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||||
if( emojisAccounts != null)
|
if( emojisAccounts != null)
|
||||||
emojis.addAll(emojisAccounts);
|
emojis.addAll(emojisAccounts);
|
||||||
if( emojis != null && emojis.size() > 0 ) {
|
if( emojis != null && emojis.size() > 0 ) {
|
||||||
|
@ -1109,9 +1113,18 @@ public class Status implements Parcelable{
|
||||||
for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||||
final int endPosition = startPosition + targetedEmoji.length();
|
final int endPosition = startPosition + targetedEmoji.length();
|
||||||
if( endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
|
if( endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
|
||||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
ImageSpan imageSpan;
|
||||||
resource.setVisible(true, true);
|
if( !disableAnimatedEmoji) {
|
||||||
ImageSpan imageSpan = new ImageSpan(resource);
|
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
imageSpan = new ImageSpan(resource);
|
||||||
|
}else{
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||||
|
imageSpan = new ImageSpan(context,
|
||||||
|
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||||
|
(int) Helper.convertDpToPixel(20, context), false));
|
||||||
|
}
|
||||||
contentSpan.setSpan(
|
contentSpan.setSpan(
|
||||||
imageSpan, startPosition,
|
imageSpan, startPosition,
|
||||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
@ -1123,9 +1136,19 @@ public class Status implements Parcelable{
|
||||||
for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||||
final int endPosition = startPosition + targetedEmoji.length();
|
final int endPosition = startPosition + targetedEmoji.length();
|
||||||
if(endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition) {
|
if(endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition) {
|
||||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
|
||||||
resource.setVisible(true, true);
|
ImageSpan imageSpan;
|
||||||
ImageSpan imageSpan = new ImageSpan(resource);
|
if( !disableAnimatedEmoji) {
|
||||||
|
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
imageSpan = new ImageSpan(resource);
|
||||||
|
}else{
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||||
|
imageSpan = new ImageSpan(context,
|
||||||
|
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||||
|
(int) Helper.convertDpToPixel(20, context), false));
|
||||||
|
}
|
||||||
displayNameSpan.setSpan(
|
displayNameSpan.setSpan(
|
||||||
imageSpan, startPosition,
|
imageSpan, startPosition,
|
||||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
@ -1138,9 +1161,18 @@ public class Status implements Parcelable{
|
||||||
for (int startPosition = -1; (startPosition = contentSpanCW.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
for (int startPosition = -1; (startPosition = contentSpanCW.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||||
final int endPosition = startPosition + targetedEmoji.length();
|
final int endPosition = startPosition + targetedEmoji.length();
|
||||||
if( endPosition <= contentSpanCW.toString().length() && endPosition >= startPosition) {
|
if( endPosition <= contentSpanCW.toString().length() && endPosition >= startPosition) {
|
||||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
ImageSpan imageSpan;
|
||||||
resource.setVisible(true, true);
|
if( !disableAnimatedEmoji) {
|
||||||
ImageSpan imageSpan = new ImageSpan(resource);
|
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
imageSpan = new ImageSpan(resource);
|
||||||
|
}else{
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||||
|
imageSpan = new ImageSpan(context,
|
||||||
|
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||||
|
(int) Helper.convertDpToPixel(20, context), false));
|
||||||
|
}
|
||||||
contentSpanCW.setSpan(
|
contentSpanCW.setSpan(
|
||||||
imageSpan, startPosition,
|
imageSpan, startPosition,
|
||||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
|
|
@ -996,6 +996,18 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||||
|
final CheckBox set_disable_animated_emoji = rootView.findViewById(R.id.set_disable_animated_emoji);
|
||||||
|
set_disable_animated_emoji.setChecked(disableAnimatedEmoji);
|
||||||
|
set_disable_animated_emoji.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, set_disable_animated_emoji.isChecked());
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
boolean livenotif = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
|
boolean livenotif = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
|
||||||
final CheckBox set_live_notif = rootView.findViewById(R.id.set_live_notify);
|
final CheckBox set_live_notif = rootView.findViewById(R.id.set_live_notify);
|
||||||
set_live_notif.setChecked(livenotif);
|
set_live_notif.setChecked(livenotif);
|
||||||
|
|
|
@ -344,6 +344,7 @@ public class Helper {
|
||||||
public static final String NEWS_ACCOUNT_ID = "news_account_id";
|
public static final String NEWS_ACCOUNT_ID = "news_account_id";
|
||||||
public static final String SET_LIVE_NOTIFICATIONS = "set_live_notifications";
|
public static final String SET_LIVE_NOTIFICATIONS = "set_live_notifications";
|
||||||
public static final String SET_DISABLE_GIF = "set_disable_gif";
|
public static final String SET_DISABLE_GIF = "set_disable_gif";
|
||||||
|
public static final String SET_DISABLE_ANIMATED_EMOJI = "set_disable_animated_emoji";
|
||||||
public static final String SET_CAPITALIZE = "set_capitalize";
|
public static final String SET_CAPITALIZE = "set_capitalize";
|
||||||
public static final String SET_WYSIWYG = "set_wysiwyg";
|
public static final String SET_WYSIWYG = "set_wysiwyg";
|
||||||
public static final String SET_PICTURE_RESIZE = "set_picture_resize";
|
public static final String SET_PICTURE_RESIZE = "set_picture_resize";
|
||||||
|
@ -4406,4 +4407,27 @@ public class Helper {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Bitmap drawableToBitmap (Drawable drawable) {
|
||||||
|
Bitmap bitmap;
|
||||||
|
|
||||||
|
if (drawable instanceof BitmapDrawable) {
|
||||||
|
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
||||||
|
if(bitmapDrawable.getBitmap() != null) {
|
||||||
|
return bitmapDrawable.getBitmap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
|
||||||
|
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
|
||||||
|
} else {
|
||||||
|
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
}
|
||||||
|
|
||||||
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||||
|
drawable.draw(canvas);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,6 +305,15 @@
|
||||||
android:text="@string/set_disable_gif"
|
android:text="@string/set_disable_gif"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:id="@+id/set_disable_animated_emoji"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||||
|
android:layout_marginBottom="@dimen/settings_checkbox_margin"
|
||||||
|
android:text="@string/set_disable_animated_emoji"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/set_display_card"
|
android:id="@+id/set_display_card"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -1139,6 +1139,7 @@
|
||||||
<string name="date_range">Date range</string>
|
<string name="date_range">Date range</string>
|
||||||
<string name="action_groups">Groups</string>
|
<string name="action_groups">Groups</string>
|
||||||
<string name="no_messages">No groups!</string>
|
<string name="no_messages">No groups!</string>
|
||||||
|
<string name="set_disable_animated_emoji">Disable custom animated emojis</string>
|
||||||
<plurals name="number_of_vote">
|
<plurals name="number_of_vote">
|
||||||
<item quantity="one">%d vote</item>
|
<item quantity="one">%d vote</item>
|
||||||
<item quantity="other">%d votes</item>
|
<item quantity="other">%d votes</item>
|
||||||
|
|
Loading…
Reference in New Issue