Wrap a white adaptive background if it is not an AdaptiveIcon
Bug: 183501919 Test: manual test Change-Id: I6a899aa0fcb724d5318274190f359080fc2d0615
This commit is contained in:
@@ -48,6 +48,7 @@ import android.content.res.TypedArray;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.VectorDrawable;
|
import android.graphics.drawable.VectorDrawable;
|
||||||
@@ -94,6 +95,7 @@ import android.widget.EditText;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
|
|
||||||
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.core.graphics.drawable.IconCompat;
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
@@ -111,6 +113,7 @@ import com.android.settings.dashboard.profileselector.ProfileFragmentBridge;
|
|||||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||||
import com.android.settingslib.widget.ActionBarShadowController;
|
import com.android.settingslib.widget.ActionBarShadowController;
|
||||||
|
import com.android.settingslib.widget.AdaptiveIcon;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -967,15 +970,36 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the preference icon with a drawable that is scaled down to to avoid crashing Settings if
|
* Gets the adaptive icon with a drawable that wrapped with an adaptive background using {@code
|
||||||
* it's too big.
|
* backgroundColor} if it is not a {@link AdaptiveIconDrawable}
|
||||||
|
*
|
||||||
|
* If the given {@code icon} is too big, it will be auto scaled down to to avoid crashing
|
||||||
|
* Settings.
|
||||||
*/
|
*/
|
||||||
public static void setSafeIcon(Preference pref, Drawable icon) {
|
public static Drawable getAdaptiveIcon(Context context, Drawable icon,
|
||||||
|
@ColorInt int backgroundColor) {
|
||||||
|
Drawable adaptiveIcon = getSafeIcon(icon);
|
||||||
|
|
||||||
|
if (!(adaptiveIcon instanceof AdaptiveIconDrawable)) {
|
||||||
|
adaptiveIcon = new AdaptiveIcon(context, adaptiveIcon);
|
||||||
|
((AdaptiveIcon) adaptiveIcon).setBackgroundColor(backgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return adaptiveIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the icon with a drawable that is scaled down to to avoid crashing Settings if it's too
|
||||||
|
* big and not a {@link VectorDrawable}.
|
||||||
|
*/
|
||||||
|
public static Drawable getSafeIcon(Drawable icon) {
|
||||||
Drawable safeIcon = icon;
|
Drawable safeIcon = icon;
|
||||||
|
|
||||||
if ((icon != null) && !(icon instanceof VectorDrawable)) {
|
if ((icon != null) && !(icon instanceof VectorDrawable)) {
|
||||||
safeIcon = getSafeDrawable(icon, 500, 500);
|
safeIcon = getSafeDrawable(icon, 500, 500);
|
||||||
}
|
}
|
||||||
pref.setIcon(safeIcon);
|
|
||||||
|
return safeIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -985,7 +1009,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
* @param maxWidth maximum width, in pixels.
|
* @param maxWidth maximum width, in pixels.
|
||||||
* @param maxHeight maximum height, in pixels.
|
* @param maxHeight maximum height, in pixels.
|
||||||
*/
|
*/
|
||||||
public static Drawable getSafeDrawable(Drawable original, int maxWidth, int maxHeight) {
|
private static Drawable getSafeDrawable(Drawable original, int maxWidth, int maxHeight) {
|
||||||
final int actualWidth = original.getMinimumWidth();
|
final int actualWidth = original.getMinimumWidth();
|
||||||
final int actualHeight = original.getMinimumHeight();
|
final int actualHeight = original.getMinimumHeight();
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -663,7 +664,7 @@ public class AccessibilitySettings extends DashboardFragment {
|
|||||||
preference.setKey(key);
|
preference.setKey(key);
|
||||||
preference.setTitle(title);
|
preference.setTitle(title);
|
||||||
preference.setSummary(summary);
|
preference.setSummary(summary);
|
||||||
Utils.setSafeIcon(preference, icon);
|
preference.setIcon(Utils.getAdaptiveIcon(mContext, icon, Color.WHITE));
|
||||||
preference.setFragment(fragment);
|
preference.setFragment(fragment);
|
||||||
preference.setIconSize(ICON_SIZE_MEDIUM);
|
preference.setIconSize(ICON_SIZE_MEDIUM);
|
||||||
preference.setPersistent(false); // Disable SharedPreferences.
|
preference.setPersistent(false); // Disable SharedPreferences.
|
||||||
|
@@ -124,7 +124,7 @@ public class PasswordsPreferenceController extends BasePreferenceController
|
|||||||
serviceInfo,
|
serviceInfo,
|
||||||
serviceInfo.applicationInfo,
|
serviceInfo.applicationInfo,
|
||||||
user);
|
user);
|
||||||
Utils.setSafeIcon(pref, icon);
|
pref.setIcon(Utils.getSafeIcon(icon));
|
||||||
pref.setIntent(
|
pref.setIntent(
|
||||||
new Intent(Intent.ACTION_MAIN)
|
new Intent(Intent.ACTION_MAIN)
|
||||||
.setClassName(serviceInfo.packageName, service.getPasswordsActivity()));
|
.setClassName(serviceInfo.packageName, service.getPasswordsActivity()));
|
||||||
|
@@ -66,7 +66,7 @@ public abstract class DefaultAppPreferenceController extends AbstractPreferenceC
|
|||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(defaultAppLabel)) {
|
if (!TextUtils.isEmpty(defaultAppLabel)) {
|
||||||
preference.setSummary(defaultAppLabel);
|
preference.setSummary(defaultAppLabel);
|
||||||
Utils.setSafeIcon(preference, getDefaultAppIcon());
|
preference.setIcon(Utils.getSafeIcon(getDefaultAppIcon()));
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "No default app");
|
Log.d(TAG, "No default app");
|
||||||
preference.setSummary(R.string.app_list_preference_none);
|
preference.setSummary(R.string.app_list_preference_none);
|
||||||
|
@@ -88,6 +88,6 @@ public class CurrentDreamPreferenceController extends BasePreferenceController {
|
|||||||
}
|
}
|
||||||
final GearPreference gearPref = (GearPreference) preference;
|
final GearPreference gearPref = (GearPreference) preference;
|
||||||
gearPref.setIconSize(RestrictedPreference.ICON_SIZE_SMALL);
|
gearPref.setIconSize(RestrictedPreference.ICON_SIZE_SMALL);
|
||||||
Utils.setSafeIcon(gearPref, mBackend.getActiveIcon());
|
gearPref.setIcon(Utils.getSafeIcon(mBackend.getActiveIcon()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -205,7 +205,7 @@ public abstract class RadioButtonPickerFragment extends InstrumentedPreferenceFr
|
|||||||
public RadioButtonPreference bindPreference(RadioButtonPreference pref,
|
public RadioButtonPreference bindPreference(RadioButtonPreference pref,
|
||||||
String key, CandidateInfo info, String defaultKey) {
|
String key, CandidateInfo info, String defaultKey) {
|
||||||
pref.setTitle(info.loadLabel());
|
pref.setTitle(info.loadLabel());
|
||||||
Utils.setSafeIcon(pref, info.loadIcon());
|
pref.setIcon(Utils.getSafeIcon(info.loadIcon()));
|
||||||
pref.setKey(key);
|
pref.setKey(key);
|
||||||
if (TextUtils.equals(defaultKey, key)) {
|
if (TextUtils.equals(defaultKey, key)) {
|
||||||
pref.setChecked(true);
|
pref.setChecked(true);
|
||||||
|
Reference in New Issue
Block a user