项目:LaunchEnr
文件:LauncherIcons.java
/**
* Creates a normalized bitmap suitable for the all apps view. The bitmap is also visually
* normalized with other icons and has enough spacing to add shadow.
*/
public static Bitmap createScaledBitmapWithoutShadow(Drawable icon,Context context,int iconAppTargetSdk) {
RectF iconBounds = new RectF();
Iconnormalizer normalizer;
float scale = 1f;
normalizer = Iconnormalizer.getInstance(context);
if (AndroidVersion.isAtLeastOreo() && iconAppTargetSdk >= Build.VERSION_CODES.O) {
boolean[] outShape = new boolean[1];
AdaptiveIconDrawable dr = (AdaptiveIconDrawable)
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
dr.setBounds(0,1,1);
scale = normalizer.getScale(icon,iconBounds,dr.getIconMask(),outShape);
if (AndroidVersion.isAtLeastOreo() &&
!outShape[0]) {
Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context,icon,scale);
if (wrappedIcon != icon) {
icon = wrappedIcon;
scale = normalizer.getScale(icon,null,null);
}
}
}
scale = Math.min(scale,ShadowGenerator.getScaleForBounds(iconBounds));
return createIconBitmap(icon,context,scale);
}
项目:LaunchEnr
文件:LauncherIcons.java
/**
* If the platform is running O but the app is not providing AdaptiveIconDrawable,then
* shrink the legacy icon and set it as foreground. Use color drawable as background to
* create AdaptiveIconDrawable.
*/
private static Drawable wrapToAdaptiveIconDrawable(Context context,Drawable drawable,float scale) {
if (!(AndroidVersion.isAtLeastOreo())) {
return drawable;
}
try {
if (!(drawable instanceof AdaptiveIconDrawable)) {
AdaptiveIconDrawable iconWrapper = (AdaptiveIconDrawable)
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
FixedScaleDrawable fsd = ((FixedScaleDrawable) iconWrapper.getForeground());
fsd.setDrawable(drawable);
fsd.setScale(scale);
return (Drawable) iconWrapper;
}
} catch (Exception e) {
return drawable;
}
return drawable;
}
项目:emerald
文件:IconPackManager.java
public Bitmap getDefaultBitmap(Drawable d) {
if (d instanceof BitmapDrawable) {
return ((BitmapDrawable) d).getBitmap();
} else if (Build.VERSION.SDK_INT >= 26) {
if (d instanceof AdaptiveIconDrawable) {
AdaptiveIconDrawable icon = ((AdaptiveIconDrawable)d);
int w = icon.getIntrinsicWidth();
int h = icon.getIntrinsicHeight();
Bitmap result = Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
icon.setBounds(0,canvas.getWidth(),canvas.getHeight());
icon.draw(canvas);
return result;
}
}
float density = context.getResources().getdisplayMetrics().density;
int defaultWidth = (int)(48* density);
int defaultHeight = (int)(48* density);
return Bitmap.createBitmap(defaultWidth,defaultHeight,Bitmap.Config.ARGB_8888);
}
项目:Phonograph
文件:AppShortcutIconGenerator.java
private static IconCompat generateThemedIcon(Context context,int iconId,int foregroundColor,int backgroundColor) {
// Get and tint foreground and background drawables
Drawable vectorDrawable = Util.getTintedVectorDrawable(context,iconId,foregroundColor);
Drawable backgroundDrawable = Util.getTintedVectorDrawable(context,R.drawable.ic_app_shortcut_background,backgroundColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(backgroundDrawable,vectorDrawable);
return IconCompat.createWithAdaptiveBitmap(drawabletoBitmap(adaptiveIconDrawable));
} else {
// Squash the two drawables together
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable,vectorDrawable});
// Return as an Icon
return IconCompat.createWithBitmap(drawabletoBitmap(layerDrawable));
}
}
项目:LaunchEnr
文件:LauncherIcons.java
/**
* Returns a bitmap suitable for the all apps view. The icon is badged for {@param user}.
* The bitmap is also visually normalized with other icons.
*/
public static Bitmap createBadgedIconBitmap(
Drawable icon,UserHandle user,int iconAppTargetSdk) {
Iconnormalizer normalizer;
float scale = 1f;
normalizer = Iconnormalizer.getInstance(context);
if (AndroidVersion.isAtLeastOreo() && iconAppTargetSdk >= Build.VERSION_CODES.O) {
boolean[] outShape = new boolean[1];
AdaptiveIconDrawable dr = (AdaptiveIconDrawable)
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
dr.setBounds(0,outShape);
if (!outShape[0]){
Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context,null);
}
}
}
Bitmap bitmap = createIconBitmap(icon,scale);
if (AndroidVersion.isAtLeastOreo() &&
icon instanceof AdaptiveIconDrawable) {
bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap);
}
return badgeIconForUser(bitmap,user,context);
}
项目:LaunchEnr
文件:LauncherIcons.java
/**
* Returns a bitmap suitable for the all apps view.
*/
public static Bitmap createIconBitmap(Drawable icon,Context context) {
float scale = 1f;
if (AndroidVersion.isAtLeastOreo() &&
icon instanceof AdaptiveIconDrawable) {
scale = ShadowGenerator.getScaleForBounds(new RectF(0,0));
}
Bitmap bitmap = createIconBitmap(icon,scale);
if (AndroidVersion.isAtLeastOreo() &&
icon instanceof AdaptiveIconDrawable) {
bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap);
}
return bitmap;
}
项目:Leanplum-Android-SDK
文件:LeanplumNotificationHelper.java
/**
* Checks a possibility to create icon drawable from current app icon.
*
* @param context Current application context.
* @return boolean True if it is possible to create a drawable from current app icon.
*/
private static boolean canCreateIconDrawable(Context context) {
try {
// Try to create icon drawable.
Drawable drawable = AdaptiveIconDrawable.createFromStream(
context.getResources().openRawResource(context.getApplicationInfo().icon),"applicationInfo.icon");
// If there was no crash,we still need to check for null.
if (drawable != null) {
return true;
}
} catch (Throwable ignored) {
}
return false;
}
项目:Jockey
文件:PresetThemeStore.java
@Override
public Drawable getLargeAppIcon() {
Drawable icon = ResourcesCompat.getDrawableForDensity(mContext.getResources(),getIconId(),getLargerdisplayDensity(),mContext.getTheme());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && icon instanceof AdaptiveIconDrawable) {
return ((AdaptiveIconDrawable) icon).getForeground();
} else {
return icon;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。