package org.mtransit.android.util;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.style.ImageSpan;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;

import org.mtransit.android.R;
import org.mtransit.android.commons.MTLog;
import org.mtransit.android.commons.SpanUtils;
import org.mtransit.android.commons.ThemeUtils;
import org.mtransit.android.ui.MTSuperscriptImageSpan;

public class UISpanUtils extends SpanUtils implements MTLog.Loggable {

	private static final String LOG_TAG = UISpanUtils.class.getSimpleName();

	@NonNull
	@Override
	public String getLogTag() {
		return LOG_TAG;
	}

	@Nullable
	public static ImageSpan getNewImage(@NonNull Context context, @DrawableRes int id, int verticalAlignment) {
		Drawable drawable = ContextCompat.getDrawable(context, id);
		if (drawable == null) {
			MTLog.w(LOG_TAG, "Cannot load new image span!");
			return null;
		}
		drawable = DrawableCompat.wrap(drawable); // tint
		int left = 0;
		int right = drawable.getIntrinsicWidth();
		int top = 0;
		int bottom = drawable.getIntrinsicHeight();
		drawable.setBounds(left, top, right, bottom);
		DrawableCompat.setTint(drawable, ThemeUtils.resolveColorAttribute(context, R.attr.colorOnSurface));
		return new MTSuperscriptImageSpan(drawable, verticalAlignment);
	}
}

@@ -251,24 +251,73 @@
 n.Nullable;%0A
+import androidx.appcompat.app.AppCompatDelegate;%0A
 import andro
@@ -776,16 +776,138 @@
 ame();%0A%0A
+%09static %7B%0A%09%09AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); // enable Vector Drawable for API Level %3C 21%0A%09%7D%0A%0A
 %09@NonNul

Fix Vector Drawable crash on Android 4.x