|
|
|
|
@ -23,11 +23,13 @@ import android.appwidget.AppWidgetManager;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
|
import android.content.res.ColorStateList;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
|
import android.graphics.drawable.Icon;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.text.SpannableString;
|
|
|
|
|
import android.text.Spanned;
|
|
|
|
|
@ -43,6 +45,11 @@ import androidx.core.content.ContextCompat;
|
|
|
|
|
import androidx.core.graphics.ColorUtils;
|
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@ -173,13 +180,39 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File dir = new File(Helper.getExternalFilesDir(context), "avatars");
|
|
|
|
|
dir.mkdirs();
|
|
|
|
|
|
|
|
|
|
hasColor = false;
|
|
|
|
|
allColors = (account_color > 0);
|
|
|
|
|
for (TupleMessageWidget message : messages)
|
|
|
|
|
for (TupleMessageWidget message : messages) {
|
|
|
|
|
if (message.accountColor == null)
|
|
|
|
|
allColors = false;
|
|
|
|
|
else
|
|
|
|
|
hasColor = true;
|
|
|
|
|
|
|
|
|
|
File file = new File(dir, message.id + ".png");
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
ContactInfo[] info = ContactInfo.get(context,
|
|
|
|
|
message.account, null,
|
|
|
|
|
message.bimi_selector, Boolean.TRUE.equals(message.dmarc),
|
|
|
|
|
message.isForwarder() ? message.submitter : message.from);
|
|
|
|
|
Bitmap bm = (info.length == 0 ? null : info[0].getPhotoBitmap());
|
|
|
|
|
if (bm != null) {
|
|
|
|
|
int dp36 = Helper.dp2pixels(context, 36);
|
|
|
|
|
bm = Bitmap.createScaledBitmap(bm, dp36, bm.getHeight() * dp36 / bm.getWidth(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bm != null) {
|
|
|
|
|
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
|
|
|
|
|
bm.compress(Bitmap.CompressFormat.PNG, ImageHelper.DEFAULT_PNG_COMPRESSION, os);
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -249,21 +282,18 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
|
|
|
|
|
views.setViewVisibility(R.id.stripe, hasColor && account_color == 1 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
|
|
if (avatars) {
|
|
|
|
|
ContactInfo[] info = ContactInfo.get(context,
|
|
|
|
|
message.account, null,
|
|
|
|
|
message.bimi_selector, Boolean.TRUE.equals(message.dmarc),
|
|
|
|
|
message.isForwarder() ? message.submitter : message.from);
|
|
|
|
|
Bitmap bm = (info.length == 0 ? null : info[0].getPhotoBitmap());
|
|
|
|
|
if (bm != null) {
|
|
|
|
|
int w = bm.getWidth();
|
|
|
|
|
int h = bm.getHeight();
|
|
|
|
|
int dp36 = Helper.dp2pixels(context, 36);
|
|
|
|
|
bm = Bitmap.createScaledBitmap(bm, dp36, bm.getHeight() * dp36 / bm.getWidth(), true);
|
|
|
|
|
}
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.BAKLAVA)
|
|
|
|
|
views.setImageViewBitmap(R.id.avatar, bm);
|
|
|
|
|
else
|
|
|
|
|
views.setImageViewIcon(R.id.avatar, bm == null ? null : Icon.createWithBitmap(bm));
|
|
|
|
|
File dir = new File(Helper.getExternalFilesDir(context), "avatars");
|
|
|
|
|
File file = new File(dir, message.id + ".png");
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
Uri uri = FileProviderEx.getUri(context, BuildConfig.APPLICATION_ID, file);
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
|
|
|
intent.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
|
|
|
for (ResolveInfo resolveInfo : resInfoList)
|
|
|
|
|
context.grantUriPermission(resolveInfo.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
|
views.setImageViewUri(R.id.avatar, uri);
|
|
|
|
|
} else
|
|
|
|
|
views.setImageViewBitmap(R.id.avatar, null);
|
|
|
|
|
}
|
|
|
|
|
views.setViewVisibility(R.id.avatar, avatars ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
|
|
|