Use ContextCompat.getDrawable

pull/209/head
M66B 2 years ago
parent 3f45339f9a
commit 4e3c9655af

@ -47,6 +47,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -294,9 +295,9 @@ public class ActivityEML extends ActivityBase {
public Drawable getDrawable(Element img) {
Drawable d;
if (TextUtils.isEmpty(img.attr("x-tracking")))
d = context.getDrawable(R.drawable.twotone_image_24);
d = ContextCompat.getDrawable(context, R.drawable.twotone_image_24);
else {
d = context.getDrawable(R.drawable.twotone_my_location_24);
d = ContextCompat.getDrawable(context, R.drawable.twotone_my_location_24);
d.setTint(Helper.resolveColor(context, R.attr.colorWarning));
}
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());

@ -56,6 +56,7 @@ import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
@ -203,7 +204,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
ivSync.setImageResource(account.synchronize ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24);
ivSync.setContentDescription(context.getString(account.synchronize ? R.string.title_legend_synchronize_on : R.string.title_legend_synchronize_off));
ivOAuth.setImageDrawable(context.getDrawable(account.auth_type == AUTH_TYPE_GMAIL
ivOAuth.setImageDrawable(ContextCompat.getDrawable(context, account.auth_type == AUTH_TYPE_GMAIL
? R.drawable.twotone_android_24 : R.drawable.twotone_security_24));
ivOAuth.setVisibility(
settings && account.auth_type != AUTH_TYPE_PASSWORD ? View.VISIBLE : View.GONE);

@ -116,6 +116,7 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.helper.widget.Flow;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.graphics.ColorUtils;
@ -2937,7 +2938,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
new DynamicDrawableSpan() {
@Override
public Drawable getDrawable() {
Drawable d = context.getDrawable(R.drawable.twotone_format_quote_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_format_quote_24);
d.setTint(colorAccent);
d.setBounds(0, 0, px, px);
return d;

@ -47,6 +47,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
@ -359,7 +360,7 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
}
});
} else if (has != 0) {
cd.setCloseIcon(context.getDrawable(icons[has - 1]));
cd.setCloseIcon(ContextCompat.getDrawable(context, icons[has - 1]));
cd.setCloseIconVisible(true);
}

@ -125,6 +125,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.core.view.MenuCompat;
import androidx.core.view.WindowInsetsCompat;
@ -3150,7 +3151,7 @@ public class FragmentCompose extends FragmentBase {
if (d == null) {
int px = Helper.dp2pixels(context, (zoom + 1) * 24);
d = context.getDrawable(R.drawable.twotone_broken_image_24);
d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
}

@ -41,6 +41,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -68,8 +69,8 @@ public class FragmentDialogAccount extends FragmentDialogBase {
final Button btnAccount = dview.findViewById(R.id.btnAccount);
final Button btnGmail = dview.findViewById(R.id.btnGmail);
final Drawable check = context.getDrawable(R.drawable.twotone_check_24);
final Drawable close = context.getDrawable(R.drawable.twotone_close_24);
final Drawable check = ContextCompat.getDrawable(context, R.drawable.twotone_check_24);
final Drawable close = ContextCompat.getDrawable(context, R.drawable.twotone_close_24);
check.setBounds(0, 0, check.getIntrinsicWidth(), check.getIntrinsicHeight());
close.setBounds(0, 0, close.getIntrinsicWidth(), close.getIntrinsicHeight());

@ -37,6 +37,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
public class FragmentDialogAsk extends FragmentDialogBase {
@ -72,7 +73,7 @@ public class FragmentDialogAsk extends FragmentDialogBase {
ibInfo.setVisibility(faq == 0 ? View.GONE : View.VISIBLE);
if (warning) {
Drawable w = context.getDrawable(R.drawable.twotone_warning_24);
Drawable w = ContextCompat.getDrawable(context, R.drawable.twotone_warning_24);
w.setBounds(0, 0, w.getIntrinsicWidth(), w.getIntrinsicHeight());
w.setTint(colorError);
tvMessage.setCompoundDrawablesRelative(w, null, null, null);

@ -69,6 +69,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.core.net.MailTo;
import androidx.core.util.PatternsCompat;
import androidx.lifecycle.Lifecycle;
@ -587,7 +588,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
}
}
Drawable android = context.getDrawable(R.drawable.android_robot);
Drawable android = ContextCompat.getDrawable(context, R.drawable.android_robot);
android.setBounds(0, 0, dp24, dp24);
pkgs.add(new Package(
android,
@ -782,10 +783,10 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
super(context, 0, pkgs);
this.context = context;
this.pkgs = pkgs;
this.external = context.getDrawable(R.drawable.twotone_open_in_new_24);
this.external = ContextCompat.getDrawable(context, R.drawable.twotone_open_in_new_24);
if (external != null)
external.setBounds(0, 0, external.getIntrinsicWidth(), external.getIntrinsicHeight());
this.browser = context.getDrawable(R.drawable.twotone_language_24);
this.browser = ContextCompat.getDrawable(context, R.drawable.twotone_language_24);
if (browser != null)
browser.setBounds(0, 0, browser.getIntrinsicWidth(), browser.getIntrinsicHeight());
}

@ -52,6 +52,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import org.jsoup.nodes.Document;
@ -156,7 +157,7 @@ public class FragmentDialogTranslate extends FragmentDialogBase {
if (language != null) {
TextView tv = view.findViewById(android.R.id.text1);
Drawable icon = context.getDrawable(language.icon);
Drawable icon = ContextCompat.getDrawable(context, language.icon);
int iconSize = context.getResources()
.getDimensionPixelSize(R.dimen.menu_item_icon_size);
icon.setBounds(0, 0, iconSize, iconSize);

@ -132,6 +132,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.core.view.MenuCompat;
import androidx.core.view.MenuItemCompat;
@ -2683,7 +2684,7 @@ public class FragmentMessages extends FragmentBase
else
icon = EntityFolder.getIcon(dX > 0 ? swipes.right_type : swipes.left_type);
Drawable d = context.getDrawable(icon).mutate();
Drawable d = ContextCompat.getDrawable(context, icon).mutate();
d.setTint(Helper.resolveColor(context, android.R.attr.textColorSecondary));
int half = rect.width() / 2;
@ -5999,7 +6000,7 @@ public class FragmentMessages extends FragmentBase
tvSelectedCount.setText(NF.format(count));
if (count > (BuildConfig.DEBUG ? 10 : MAX_MORE)) {
int ts = Math.round(tvSelectedCount.getTextSize());
Drawable w = context.getDrawable(R.drawable.twotone_warning_24);
Drawable w = ContextCompat.getDrawable(context, R.drawable.twotone_warning_24);
w.setBounds(0, 0, ts, ts);
w.setTint(tvSelectedCount.getCurrentTextColor());
tvSelectedCount.setCompoundDrawablesRelative(null, null, w, null);
@ -10443,20 +10444,20 @@ public class FragmentMessages extends FragmentBase
Drawable source = null;
if (sources.size() == 1) {
source = context.getDrawable(EntityFolder.getIcon(sources.get(0)));
source = ContextCompat.getDrawable(context, EntityFolder.getIcon(sources.get(0)));
if (source != null)
source.setBounds(0, 0, source.getIntrinsicWidth(), source.getIntrinsicHeight());
if (sourceColor == null)
sourceColor = EntityFolder.getDefaultColor(sources.get(0), context);
} else {
source = context.getDrawable(R.drawable.twotone_folders_24);
source = ContextCompat.getDrawable(context, R.drawable.twotone_folders_24);
source.setBounds(0, 0, source.getIntrinsicWidth(), source.getIntrinsicHeight());
sourceColor = null;
}
Drawable target = null;
if (targets.size() == 1) {
target = context.getDrawable(EntityFolder.getIcon(targets.get(0)));
target = ContextCompat.getDrawable(context, EntityFolder.getIcon(targets.get(0)));
if (target != null)
target.setBounds(0, 0, target.getIntrinsicWidth(), target.getIntrinsicHeight());
if (targetColor == null)

@ -53,6 +53,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceManager;
@ -197,7 +198,7 @@ public class FragmentOAuth extends FragmentBase {
final boolean dark = Helper.isDarkTheme(context);
int dp12 = Helper.dp2pixels(context, 12);
int dp24 = Helper.dp2pixels(context, 24);
Drawable g = context.getDrawable(R.drawable.google_logo);
Drawable g = ContextCompat.getDrawable(context, R.drawable.google_logo);
g.setBounds(0, 0, g.getIntrinsicWidth(), g.getIntrinsicHeight());
btnOAuth.setCompoundDrawablesRelative(g, null, null, null);
btnOAuth.setCompoundDrawablePadding(dp24);
@ -212,7 +213,7 @@ public class FragmentOAuth extends FragmentBase {
Color.LTGRAY // 0xffcccccc
}
));
btnOAuth.setBackground(context.getDrawable(dark
btnOAuth.setBackground(ContextCompat.getDrawable(context, dark
? R.drawable.google_signin_background_dark
: R.drawable.google_signin_background_light));
btnOAuth.setPaddingRelative(dp12, 0, dp12, 0);

@ -43,6 +43,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.cursoradapter.widget.CursorAdapter;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.fragment.app.Fragment;
@ -240,7 +241,7 @@ public class FragmentOptions extends FragmentBase {
final Context context = getContext();
int colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
for (int i = 0; i < tabLayout.getTabCount(); i++) {
Drawable d = context.getDrawable(PAGE_ICONS[i]);
Drawable d = ContextCompat.getDrawable(context, PAGE_ICONS[i]);
d.setColorFilter(colorAccent, PorterDuff.Mode.SRC_ATOP);
SpannableStringBuilder title = new SpannableStringBuilderEx(getString(PAGE_TITLES[i]));
if (i > 0)

@ -61,6 +61,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.core.view.MenuCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Lifecycle;
@ -1075,7 +1076,7 @@ public class FragmentSetup extends FragmentBase {
final Context context = getContext();
Drawable d = context.getDrawable(R.drawable.twotone_warning_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_warning_24);
d.mutate();
d.setTint(Helper.resolveColor(context, R.attr.colorWarning));

@ -64,6 +64,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.ColorUtils;
@ -2234,7 +2235,7 @@ public class HtmlHelper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean disconnect_images = (prefs.getBoolean("disconnect_images", false) && BuildConfig.DEBUG);
Drawable d = context.getDrawable(R.drawable.twotone_my_location_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_my_location_24);
d.setTint(Helper.resolveColor(context, R.attr.colorWarning));
Bitmap bm = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
@ -2818,7 +2819,7 @@ public class HtmlHelper {
ssb.setSpan(new StyleSpan(Typeface.BOLD), s, ssb.length(), 0);
if (blocklist && i == received.length - 1) {
Drawable d = context.getDrawable(R.drawable.twotone_flag_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_flag_24);
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size);
d.setBounds(0, 0, iconSize, iconSize);
@ -3474,7 +3475,7 @@ public class HtmlHelper {
String src = element.attr("src");
if (!TextUtils.isEmpty(src)) {
Drawable d = (imageGetter == null
? context.getDrawable(R.drawable.twotone_broken_image_24)
? ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24)
: imageGetter.getDrawable(element));
ssb.insert(start, "\uFFFC"); // Object replacement character
setSpan(ssb, new ImageSpanEx(d, element), start, start + 1);

@ -53,6 +53,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.exifinterface.media.ExifInterface;
import androidx.preference.PreferenceManager;
@ -331,7 +332,7 @@ class ImageHelper {
try {
if (TextUtils.isEmpty(source)) {
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -349,12 +350,12 @@ class ImageHelper {
EntityAttachment attachment = db.attachment().getAttachment(id, cid);
if (attachment == null) {
Log.i("Image not found CID=" + cid);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
} else if (!attachment.available) {
Log.i("Image not available CID=" + cid);
Drawable d = context.getDrawable(R.drawable.twotone_photo_library_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_photo_library_24);
d.setBounds(0, 0, px, px);
return d;
} else {
@ -370,7 +371,7 @@ class ImageHelper {
return d;
} catch (IOException ex) {
Log.w(ex);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -381,7 +382,7 @@ class ImageHelper {
scaleToPixels);
if (bm == null) {
Log.i("Image not decodable CID=" + cid);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
} else {
@ -413,7 +414,7 @@ class ImageHelper {
return d;
} catch (IllegalArgumentException ex) {
Log.i(ex);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -442,7 +443,7 @@ class ImageHelper {
} catch (Throwable ex) {
// FileNotFound, Security
Log.w(ex);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -450,7 +451,7 @@ class ImageHelper {
if (!show) {
// Show placeholder icon
int resid = (embedded || data ? R.drawable.twotone_photo_library_24 : R.drawable.twotone_image_24);
Drawable d = context.getDrawable(resid);
Drawable d = ContextCompat.getDrawable(context, resid);
d.setBounds(0, 0, px, px);
return d;
}
@ -460,7 +461,7 @@ class ImageHelper {
if (cached != null || view == null) {
if (view == null)
if (cached == null) {
Drawable d = context.getDrawable(R.drawable.twotone_hourglass_top_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_hourglass_top_24);
d.setBounds(0, 0, px, px);
return d;
} else
@ -471,7 +472,7 @@ class ImageHelper {
}
final LevelListDrawable lld = new LevelListDrawable();
Drawable wait = context.getDrawable(R.drawable.twotone_hourglass_top_24);
Drawable wait = ContextCompat.getDrawable(context, R.drawable.twotone_hourglass_top_24);
lld.addLevel(1, 1, wait);
lld.setBounds(0, 0, px, px);
lld.setLevel(1);
@ -522,7 +523,7 @@ class ImageHelper {
int resid = (ex instanceof IOException && !(ex instanceof FileNotFoundException)
? R.drawable.twotone_cloud_off_24
: R.drawable.twotone_broken_image_24);
Drawable d = context.getDrawable(resid);
Drawable d = ContextCompat.getDrawable(context, resid);
d.setBounds(0, 0, px, px);
post(d, source);
}
@ -558,7 +559,7 @@ class ImageHelper {
} catch (Throwable ex) {
Log.e(ex);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}

@ -41,6 +41,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.app.Person;
import androidx.core.content.ContextCompat;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
@ -293,7 +294,7 @@ class Shortcuts {
bm = contactInfo[0].getPhotoBitmap();
else {
int resid = R.drawable.baseline_mail_24;
Drawable d = context.getDrawable(resid);
Drawable d = ContextCompat.getDrawable(context, resid);
bm = Bitmap.createBitmap(
d.getIntrinsicWidth(),
d.getIntrinsicHeight(),
@ -326,7 +327,7 @@ class Shortcuts {
view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
int resid = EntityFolder.getIcon(folder.type);
Drawable d = context.getDrawable(resid);
Drawable d = ContextCompat.getDrawable(context, resid);
Bitmap bm = Bitmap.createBitmap(
d.getIntrinsicWidth(),
d.getIntrinsicHeight(),

Loading…
Cancel
Save