use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.
the class DialContactEntry method getIconDrawable.
@Override
protected Drawable getIconDrawable(Context ctx) {
if (hasCustomIcon()) {
IconsHandler iconsHandler = TBApplication.getApplication(ctx).iconsHandler();
Drawable drawable = iconsHandler.getCustomIcon(this);
if (drawable != null)
return drawable;
else
iconsHandler.restoreDefaultIcon(this);
}
return super.getIconDrawable(ctx);
}
use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.
the class SystemPage method addSystemIcons.
private void addSystemIcons(Context context, ShapedIconAdapter adapter) {
ArraySet<Bitmap> dSet = new ArraySet<>(3);
// add default icon
{
IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
Drawable drawable = iconsHandler.getDrawableIconForPackage(componentName, userHandle);
// checkDuplicateDrawable(dSet, drawable);
ShapedIconInfo iconInfo = new DefaultIconInfo(drawable);
iconInfo.textId = R.string.default_icon;
adapter.addItem(iconInfo);
}
// add getActivityIcon(componentName)
{
Drawable drawable = null;
try {
drawable = context.getPackageManager().getActivityIcon(componentName);
} catch (PackageManager.NameNotFoundException ignored) {
}
if (drawable != null) {
if (checkDuplicateDrawable(dSet, drawable)) {
{
Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, drawable, mShape, mScale, mBackground);
addQuickOption(R.string.custom_icon_activity, shapedDrawable, drawable, adapter);
}
if (DrawableUtils.isAdaptiveIconDrawable(drawable)) {
Drawable noBackground = DrawableUtils.applyAdaptiveIconBackgroundShape(context, drawable, DrawableUtils.SHAPE_SQUARE, true);
Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, noBackground, mShape, mScale, mBackground);
addQuickOption(R.string.custom_icon_activity_adaptive_no_background, shapedDrawable, noBackground, adapter);
}
}
}
}
// add getApplicationIcon(packageName)
{
Drawable drawable = null;
try {
drawable = context.getPackageManager().getApplicationIcon(componentName.getPackageName());
} catch (PackageManager.NameNotFoundException ignored) {
}
if (drawable != null) {
if (checkDuplicateDrawable(dSet, drawable)) {
Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, drawable, mShape, mScale, mBackground);
addQuickOption(R.string.custom_icon_application, shapedDrawable, drawable, adapter);
}
}
}
// add Activity BadgedIcon
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
assert launcher != null;
List<LauncherActivityInfo> icons = launcher.getActivityList(componentName.getPackageName(), userHandle.getRealHandle());
for (LauncherActivityInfo info : icons) {
Drawable drawable = info.getBadgedIcon(0);
if (drawable != null) {
if (checkDuplicateDrawable(dSet, drawable)) {
Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, drawable, mShape, mScale, mBackground);
addQuickOption(R.string.custom_icon_badged, shapedDrawable, drawable, adapter);
}
}
}
}
}
use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.
the class ShortcutEntry method getAppDrawable.
@WorkerThread
public static Drawable getAppDrawable(@NonNull Context context, @NonNull String shortcutData, @NonNull String packageName, @Nullable ShortcutInfo shortcutInfo, boolean isBadge) {
Drawable appDrawable = null;
final PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> activities = null;
if (shortcutInfo == null) {
try {
Intent intent = Intent.parseUri(shortcutData, 0);
activities = packageManager.queryIntentActivities(intent, 0);
} catch (URISyntaxException e) {
Log.e("Shortcut", "parse `" + shortcutData + "`", e);
}
}
final IconsHandler iconsHandler = TBApplication.iconsHandler(context);
if (activities != null && !activities.isEmpty()) {
ResolveInfo mainPackage = activities.get(0);
String packName = mainPackage.activityInfo.applicationInfo.packageName;
String actName = mainPackage.activityInfo.name;
ComponentName className = new ComponentName(packName, actName);
appDrawable = isBadge ? iconsHandler.getDrawableBadgeForPackage(className, UserHandleCompat.CURRENT_USER) : iconsHandler.getDrawableIconForPackage(className, UserHandleCompat.CURRENT_USER);
}
if (appDrawable == null && shortcutInfo != null) {
// Retrieve app icon
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
UserHandleCompat user = new UserHandleCompat(context, shortcutInfo.getUserHandle());
ComponentName componentName = shortcutInfo.getActivity();
appDrawable = isBadge ? iconsHandler.getDrawableBadgeForPackage(componentName, user) : iconsHandler.getDrawableIconForPackage(componentName, user);
if (appDrawable == null)
try {
appDrawable = packageManager.getActivityIcon(componentName);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Unable to find activity icon " + componentName.toString(), e);
}
}
}
if (appDrawable == null) {
try {
appDrawable = packageManager.getApplicationIcon(packageName);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "get app shortcut icon", e);
return null;
}
appDrawable = iconsHandler.getIconPack().applyBackgroundAndMask(context, appDrawable, true);
}
return appDrawable;
}
use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.
the class ShortcutEntry method getIcon.
public Drawable getIcon(@NonNull Context context) {
if (customIcon > 0) {
IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
Drawable drawable = iconsHandler.getCustomIcon(this);
if (drawable != null)
return drawable;
else
iconsHandler.restoreDefaultIcon(this);
}
Bitmap bitmap = ShortcutUtil.getInitialIcon(context, dbId);
if (bitmap == null)
return null;
return TBApplication.iconsHandler(context).applyShortcutMask(context, bitmap);
}
use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.
the class StaticEntry method getIconDrawable.
@WorkerThread
public Drawable getIconDrawable(Context context) {
if (hasCustomIcon()) {
IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
Drawable drawable = iconsHandler.getCustomIcon(this);
if (drawable != null)
return drawable;
else
iconsHandler.restoreDefaultIcon(this);
}
return getDefaultDrawable(context);
}
Aggregations