Simplification

This commit is contained in:
M66B 2021-01-23 09:28:51 +01:00
parent fb4d4d51f7
commit eba5b0f839
6 changed files with 20 additions and 22 deletions

View File

@ -61,7 +61,7 @@ public class FragmentDialogAsk extends FragmentDialogBase {
cbNotAgain.setVisibility(notagain == null ? View.GONE : View.VISIBLE);
if (warning) {
Drawable w = context.getResources().getDrawable(R.drawable.twotone_warning_24, context.getTheme());
Drawable w = context.getDrawable(R.drawable.twotone_warning_24);
w.setBounds(0, 0, w.getIntrinsicWidth(), w.getIntrinsicHeight());
w.setTint(colorError);
tvMessage.setCompoundDrawablesRelative(w, null, null, null);

View File

@ -2003,7 +2003,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
else
icon = EntityFolder.getIcon(dX > 0 ? swipes.right_type : swipes.left_type);
Drawable d = getResources().getDrawable(icon, context.getTheme()).mutate();
Drawable d = context.getDrawable(icon).mutate();
d.setTint(Helper.resolveColor(context, android.R.attr.textColorSecondary));
if (dX > 0) {
@ -4512,7 +4512,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
tvSelectedCount.setText(NF.format(count));
if (count > (BuildConfig.DEBUG ? 10 : MAX_MORE)) {
int ts = Math.round(tvSelectedCount.getTextSize());
Drawable w = context.getResources().getDrawable(R.drawable.twotone_warning_24, context.getTheme());
Drawable w = context.getDrawable(R.drawable.twotone_warning_24);
w.setBounds(0, 0, ts, ts);
w.setTint(tvSelectedCount.getCurrentTextColor());
tvSelectedCount.setCompoundDrawablesRelative(null, null, w, null);
@ -7999,7 +7999,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Drawable source = null;
if (sources.size() == 1) {
source = getResources().getDrawable(EntityFolder.getIcon(sources.get(0)), null);
source = getContext().getDrawable(EntityFolder.getIcon(sources.get(0)));
if (source != null)
source.setBounds(0, 0, source.getIntrinsicWidth(), source.getIntrinsicHeight());
if (sourceColor == null)
@ -8009,7 +8009,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Drawable target = null;
if (targets.size() == 1) {
target = getResources().getDrawable(EntityFolder.getIcon(targets.get(0)), null);
target = getContext().getDrawable(EntityFolder.getIcon(targets.get(0)));
if (target != null)
target.setBounds(0, 0, target.getIntrinsicWidth(), target.getIntrinsicHeight());
if (targetColor == null)

View File

@ -99,7 +99,7 @@ public class FragmentSetup extends FragmentBase {
textColorPrimary = Helper.resolveColor(getContext(), android.R.attr.textColorPrimary);
colorWarning = Helper.resolveColor(getContext(), R.attr.colorWarning);
check = getResources().getDrawable(R.drawable.twotone_check_24, getContext().getTheme());
check = getContext().getDrawable(R.drawable.twotone_check_24);
view = (ViewGroup) inflater.inflate(R.layout.fragment_setup, container, false);

View File

@ -59,7 +59,6 @@ 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;
@ -1564,7 +1563,7 @@ public class HtmlHelper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean disconnect_images = prefs.getBoolean("disconnect_images", false);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_my_location_24);
Drawable d = context.getDrawable(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);

View File

@ -233,14 +233,13 @@ class ImageHelper {
boolean inline = prefs.getBoolean("inline_images", false);
final int px = Helper.dp2pixels(context, (zoom + 1) * 24);
final Resources.Theme theme = context.getTheme();
final Resources res = context.getResources();
try {
final AnnotatedSource a = new AnnotatedSource(source);
if (TextUtils.isEmpty(a.source)) {
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -258,12 +257,12 @@ class ImageHelper {
EntityAttachment attachment = db.attachment().getAttachment(id, cid);
if (attachment == null) {
Log.i("Image not found CID=" + cid);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(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 = res.getDrawable(R.drawable.twotone_photo_library_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_photo_library_24);
d.setBounds(0, 0, px, px);
return d;
} else {
@ -276,7 +275,7 @@ class ImageHelper {
return d;
} catch (IOException ex) {
Log.w(ex);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -284,7 +283,7 @@ class ImageHelper {
Bitmap bm = decodeImage(attachment.getFile(context), scaleToPixels);
if (bm == null) {
Log.i("Image not decodable CID=" + cid);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
} else {
@ -316,7 +315,7 @@ class ImageHelper {
return d;
} catch (IllegalArgumentException ex) {
Log.w(ex);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -362,7 +361,7 @@ class ImageHelper {
} catch (Throwable ex) {
// FileNotFound, Security
Log.w(ex);
Drawable d = context.getResources().getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@ -370,7 +369,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 = res.getDrawable(resid, theme);
Drawable d = context.getDrawable(resid);
d.setBounds(0, 0, px, px);
return d;
}
@ -380,7 +379,7 @@ class ImageHelper {
if (cached != null || view == null) {
if (view == null)
if (cached == null) {
Drawable d = res.getDrawable(R.drawable.twotone_hourglass_top_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_hourglass_top_24);
d.setBounds(0, 0, px, px);
return d;
} else
@ -391,7 +390,7 @@ class ImageHelper {
}
final LevelListDrawable lld = new LevelListDrawable();
Drawable wait = res.getDrawable(R.drawable.twotone_hourglass_top_24, theme);
Drawable wait = context.getDrawable(R.drawable.twotone_hourglass_top_24);
lld.addLevel(1, 1, wait);
lld.setBounds(0, 0, px, px);
lld.setLevel(1);
@ -442,7 +441,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 = res.getDrawable(resid, theme);
Drawable d = context.getDrawable(resid);
d.setBounds(0, 0, px, px);
post(d, a.source);
}
@ -478,7 +477,7 @@ class ImageHelper {
} catch (Throwable ex) {
Log.e(ex);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}

View File

@ -41,7 +41,7 @@ public class ToastEx extends Toast {
ToastEx toast = new ToastEx(context);
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.toast, null);
view.setBackground(context.getResources().getDrawable(R.drawable.toast_background, context.getTheme()));
view.setBackground(context.getDrawable(R.drawable.toast_background));
TextView tv = view.findViewById(android.R.id.message);
tv.setTextColor(Helper.resolveColor(context, R.attr.colorInfoForeground));