version:
fix: update:更换为酷信
This commit is contained in:
1 parent
625a121cbb
commit
8799e85443
723 files changed
+4158
-4041
No files matched your search
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.uiuipad.os.icons;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.uiuipad.os.icons.cache.CachingLogic;
|
||||
|
||||
public interface ComponentWithLabel {
|
||||
|
||||
ComponentName getComponent();
|
||||
|
||||
UserHandle getUser();
|
||||
|
||||
CharSequence getLabel(PackageManager pm);
|
||||
|
||||
|
||||
class ComponentCachingLogic implements CachingLogic<ComponentWithLabel> {
|
||||
|
||||
private final PackageManager mPackageManager;
|
||||
|
||||
public ComponentCachingLogic(Context context) {
|
||||
mPackageManager = context.getPackageManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentName getComponent(ComponentWithLabel object) {
|
||||
return object.getComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserHandle getUser(ComponentWithLabel object) {
|
||||
return object.getUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getLabel(ComponentWithLabel object) {
|
||||
return object.getLabel(mPackageManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIcon(Context context,
|
||||
ComponentWithLabel object, BitmapInfo target) {
|
||||
// Do not load icon.
|
||||
target.icon = BitmapInfo.LOW_RES_ICON;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.uiuipad.os.icons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.LauncherActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.uiuipad.os.AppInfo;
|
||||
import com.uiuipad.os.IconProvider;
|
||||
import com.uiuipad.os.InvariantDeviceProfile;
|
||||
import com.uiuipad.os.ItemInfoWithIcon;
|
||||
import com.uiuipad.os.LauncherFiles;
|
||||
import com.uiuipad.os.LauncherModel;
|
||||
import com.uiuipad.os.MainThreadExecutor;
|
||||
import com.uiuipad.os.R;
|
||||
import com.uiuipad.os.uiuiutils.BitmapUtils;
|
||||
import com.uiuipad.os.WorkspaceItemInfo;
|
||||
import com.uiuipad.os.Utilities;
|
||||
import com.uiuipad.os.compat.LauncherAppsCompat;
|
||||
import com.uiuipad.os.compat.UserManagerCompat;
|
||||
import com.uiuipad.os.icons.cache.BaseIconCache;
|
||||
import com.uiuipad.os.icons.cache.CachingLogic;
|
||||
import com.uiuipad.os.icons.cache.HandlerRunnable;
|
||||
import com.uiuipad.os.model.PackageItemInfo;
|
||||
import com.uiuipad.os.util.InstantAppResolver;
|
||||
import com.uiuipad.os.util.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Cache of application icons. Icons can be made from any thread.
|
||||
*/
|
||||
public class IconCache extends BaseIconCache {
|
||||
|
||||
private static final String TAG = "Launcher.IconCache";
|
||||
|
||||
private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
|
||||
|
||||
private final CachingLogic<ComponentWithLabel> mComponentWithLabelCachingLogic;
|
||||
private final CachingLogic<LauncherActivityInfo> mLauncherActivityInfoCachingLogic;
|
||||
|
||||
private final LauncherAppsCompat mLauncherApps;
|
||||
private final UserManagerCompat mUserManager;
|
||||
private final InstantAppResolver mInstantAppResolver;
|
||||
private final IconProvider mIconProvider;
|
||||
|
||||
private int mPendingIconRequestCount = 0;
|
||||
|
||||
public IconCache(Context context, InvariantDeviceProfile inv) {
|
||||
super(context, LauncherFiles.APP_ICONS_DB, LauncherModel.getWorkerLooper(),
|
||||
inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */);
|
||||
mComponentWithLabelCachingLogic = new ComponentWithLabel.ComponentCachingLogic(context);
|
||||
mLauncherActivityInfoCachingLogic = new LauncherActivtiyCachingLogic(this);
|
||||
mLauncherApps = LauncherAppsCompat.getInstance(mContext);
|
||||
mUserManager = UserManagerCompat.getInstance(mContext);
|
||||
mInstantAppResolver = InstantAppResolver.newInstance(mContext);
|
||||
mIconProvider = IconProvider.newInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getSerialNumberForUser(UserHandle user) {
|
||||
return mUserManager.getSerialNumberForUser(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isInstantApp(ApplicationInfo info) {
|
||||
return mInstantAppResolver.isInstantApp(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseIconFactory getIconFactory() {
|
||||
return LauncherIcons.obtain(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the entries related to the given package in memory and persistent DB.
|
||||
*/
|
||||
public synchronized void updateIconsForPkg(String packageName, UserHandle user) {
|
||||
removeIconsForPkg(packageName, user);
|
||||
try {
|
||||
PackageInfo info = mPackageManager.getPackageInfo(packageName,
|
||||
PackageManager.GET_UNINSTALLED_PACKAGES);
|
||||
long userSerial = mUserManager.getSerialNumberForUser(user);
|
||||
for (LauncherActivityInfo app : mLauncherApps.getActivityList(packageName, user)) {
|
||||
addIconToDBAndMemCache(app, mLauncherActivityInfoCachingLogic, info, userSerial,
|
||||
false /*replace existing*/);
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.d(TAG, "Package not found", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches high-res icon for the provided ItemInfo and updates the caller when done.
|
||||
*
|
||||
* @return a request ID that can be used to cancel the request.
|
||||
*/
|
||||
public IconLoadRequest updateIconInBackground(final ItemInfoUpdateReceiver caller,
|
||||
final ItemInfoWithIcon info) {
|
||||
Preconditions.assertUIThread();
|
||||
if (mPendingIconRequestCount <= 0) {
|
||||
LauncherModel.setWorkerPriority(Process.THREAD_PRIORITY_FOREGROUND);
|
||||
}
|
||||
mPendingIconRequestCount++;
|
||||
|
||||
IconLoadRequest request = new IconLoadRequest(mWorkerHandler, this::onIconRequestEnd) {
|
||||
@Override
|
||||
public void run() {
|
||||
if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) {
|
||||
getTitleAndIcon(info, false);
|
||||
} else if (info instanceof PackageItemInfo) {
|
||||
getTitleAndIconForApp((PackageItemInfo) info, false);
|
||||
}
|
||||
mMainThreadExecutor.execute(() -> {
|
||||
caller.reapplyItemInfo(info);
|
||||
onEnd();
|
||||
});
|
||||
}
|
||||
};
|
||||
Utilities.postAsyncCallback(mWorkerHandler, request);
|
||||
return request;
|
||||
}
|
||||
|
||||
private void onIconRequestEnd() {
|
||||
mPendingIconRequestCount--;
|
||||
if (mPendingIconRequestCount <= 0) {
|
||||
LauncherModel.setWorkerPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates {@param application} only if a valid entry is found.
|
||||
*/
|
||||
public synchronized void updateTitleAndIcon(AppInfo application) {
|
||||
CacheEntry entry = cacheLocked(application.componentName,
|
||||
application.user, () -> null, mLauncherActivityInfoCachingLogic,
|
||||
false, application.usingLowResIcon());
|
||||
if (entry.icon != null && !isDefaultIcon(entry.icon, application.user)) {
|
||||
applyCacheEntry(entry, application);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in {@param info} with the icon and label for {@param activityInfo}
|
||||
*/
|
||||
public synchronized void getTitleAndIcon(ItemInfoWithIcon info,
|
||||
LauncherActivityInfo activityInfo, boolean useLowResIcon) {
|
||||
// If we already have activity info, no need to use package icon
|
||||
getTitleAndIcon(info, () -> activityInfo, false, useLowResIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in {@param info} with the icon and label. If the
|
||||
* corresponding activity is not found, it reverts to the package icon.
|
||||
*/
|
||||
public synchronized void getTitleAndIcon(ItemInfoWithIcon info, boolean useLowResIcon) {
|
||||
// null info means not installed, but if we have a component from the intent then
|
||||
// we should still look in the cache for restored app icons.
|
||||
if (info.getTargetComponent() == null) {
|
||||
info.applyFrom(getDefaultIcon(info.user));
|
||||
info.title = "";
|
||||
info.contentDescription = "";
|
||||
} else {
|
||||
Intent intent = info.getIntent();
|
||||
getTitleAndIcon(info, () -> mLauncherApps.resolveActivity(intent, info.user),
|
||||
true, useLowResIcon);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized String getTitleNoCache(ComponentWithLabel info) {
|
||||
CacheEntry entry = cacheLocked(info.getComponent(), info.getUser(), () -> info,
|
||||
mComponentWithLabelCachingLogic, false /* usePackageIcon */,
|
||||
true /* useLowResIcon */, false /* addToMemCache */);
|
||||
return Utilities.trim(entry.title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in {@param mWorkspaceItemInfo} with the icon and label for {@param info}
|
||||
*/
|
||||
private synchronized void getTitleAndIcon(
|
||||
@NonNull ItemInfoWithIcon infoInOut,
|
||||
@NonNull Supplier<LauncherActivityInfo> activityInfoProvider,
|
||||
boolean usePkgIcon, boolean useLowResIcon) {
|
||||
CacheEntry entry = cacheLocked(infoInOut.getTargetComponent(), infoInOut.user,
|
||||
activityInfoProvider, mLauncherActivityInfoCachingLogic, usePkgIcon, useLowResIcon);
|
||||
applyCacheEntry(entry, infoInOut);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill in {@param infoInOut} with the corresponding icon and label.
|
||||
*/
|
||||
public synchronized void getTitleAndIconForApp(
|
||||
PackageItemInfo infoInOut, boolean useLowResIcon) {
|
||||
CacheEntry entry = getEntryForPackageLocked(
|
||||
infoInOut.packageName, infoInOut.user, useLowResIcon);
|
||||
applyCacheEntry(entry, infoInOut);
|
||||
}
|
||||
|
||||
protected void applyCacheEntry(CacheEntry entry, ItemInfoWithIcon info) {
|
||||
info.title = Utilities.trim(entry.title);
|
||||
info.contentDescription = entry.contentDescription;
|
||||
info.applyFrom((entry.icon == null) ? getDefaultIcon(info.user) : entry);
|
||||
}
|
||||
|
||||
private List<String> appClassNameList = new ArrayList<String>() {{
|
||||
this.add("com.aoleyun.appstore.activity.SplashActivity");//应用市场
|
||||
this.add("com.aoleyun.browser.BrowserActivity");//浏览器
|
||||
this.add("com.aoleyun.sn.activity.SplashActivity");//
|
||||
this.add("com.aoleyun.info.activity.main.MainActivity");//
|
||||
this.add("com.android.calculator2.Calculator");//计算器
|
||||
this.add("com.android.calendar.AllInOneActivity");//日历
|
||||
this.add("com.android.camera.CameraLauncher");//相机
|
||||
this.add("com.mediatek.camera.CameraLauncher");//相机
|
||||
this.add("com.android.contacts.activities.PeopleActivity");//通讯录
|
||||
this.add("com.android.deskclock.DeskClock");//时钟
|
||||
this.add("com.android.dialer.DialtactsActivity");//电话
|
||||
this.add("com.android.dialer.app.DialtactsActivity");//电话
|
||||
this.add("com.android.dialer.main.impl.MainActivity");//电话
|
||||
this.add("com.android.gallery3d.v2.app.GalleryActivity2");//图库
|
||||
this.add("com.android.gallery3d.app.GalleryActivity");//图库
|
||||
this.add("com.android.messaging.ui.conversationlist.ConversationListActivity");//信息
|
||||
this.add("com.android.music.MusicBrowserActivity");//音乐
|
||||
this.add("com.android.providers.downloads.ui.DownloadList");//下载
|
||||
this.add("com.android.quicksearchbox.SearchActivity");//搜索
|
||||
this.add("com.android.settings.Settings");//设置
|
||||
this.add("com.sprd.soundrecorder.RecorderActivity");//录音机
|
||||
this.add("com.android.soundrecorder.SoundRecorder");//录音机
|
||||
this.add("com.android.stk.StkMain");//sim卡
|
||||
this.add("com.sprd.gallery3d.app.NewVideoActivity");//视频
|
||||
this.add("com.mediatek.filemanager.FileManagerOperationActivity");//文件管理
|
||||
this.add("com.android.documentsui.LauncherActivity");//下载
|
||||
this.add("com.mediatek.fmradio.FmRadioActivity");//收音机
|
||||
this.add("com.android.fmradio.FmMainActivity");//收音机
|
||||
this.add("com.android.email.activity.Welcome");//电子邮件
|
||||
}};
|
||||
private List<String> appIconList = new ArrayList<String>() {{
|
||||
this.add("com_android_appstore");
|
||||
this.add("com_android_browser");
|
||||
this.add("com_aoleyun_sn");
|
||||
this.add("com_aoleyun_info");
|
||||
this.add("com_android_calculator2");
|
||||
this.add("com_android_calendar");
|
||||
this.add("com_android_camera");
|
||||
this.add("com_android_camera");
|
||||
this.add("com_android_contacts");
|
||||
this.add("com_android_deskclock");
|
||||
this.add("com_android_dialer");
|
||||
this.add("com_android_dialer");
|
||||
this.add("com_android_dialer");
|
||||
this.add("com_android_gallery3d_app");
|
||||
this.add("com_android_gallery3d_app");
|
||||
this.add("com_android_mms_ui");
|
||||
this.add("com_android_music");
|
||||
this.add("com_android_providers_downloads_ui");
|
||||
this.add("com_android_quicksearchbox");
|
||||
this.add("com_android_settings");
|
||||
this.add("com_android_soundrecorder");
|
||||
this.add("com_android_soundrecorder");
|
||||
this.add("com_android_stk_stkmain");
|
||||
this.add("com_android_vdieo");
|
||||
this.add("com_mediatek_filemanager");
|
||||
this.add("com_mediatek_filemanager");
|
||||
this.add("com_mediatek_fmradio");
|
||||
this.add("com_mediatek_fmradio");//收音机
|
||||
this.add("com_android_email");
|
||||
}};
|
||||
|
||||
public Drawable getFullResIcon(LauncherActivityInfo info) {
|
||||
return getFullResIcon(info, true);
|
||||
}
|
||||
|
||||
public Drawable getFullResIcon(LauncherActivityInfo info, boolean flattenDrawable) {
|
||||
//此处修改根据应用包名获取图标
|
||||
Drawable icon = null;
|
||||
|
||||
if (null != info) {
|
||||
String name = info.getComponentName().getClassName();
|
||||
Log.e("getFullResIcon", "getDeskClockIcon: " + name);
|
||||
if (appClassNameList.indexOf(info.getComponentName().getClassName()) == -1) {
|
||||
icon = BitmapUtils.getRoundedBitmap(mIconProvider.getIcon(info, mIconDpi, flattenDrawable), mContext);
|
||||
} else {
|
||||
// if ("com.android.calendar.AllInOneActivity".equals(name)) {
|
||||
// icon = BitmapUtils.createCalendarIconBitmap(mContext.getResources().getDrawable(R.drawable.mask), mContext);
|
||||
// } else if ("com.android.deskclock.DeskClock".equals(name)) {
|
||||
// icon = BitmapUtils.getDeskClockIcon(mContext);
|
||||
// } else {
|
||||
int i = appClassNameList.indexOf(name);
|
||||
String val = appIconList.get(i);
|
||||
int resID = mContext.getResources().getIdentifier(val, "drawable", "com.uiuipad.os");
|
||||
if (resID == 0) {
|
||||
icon = mIconProvider.getIcon(info, mIconDpi, flattenDrawable);
|
||||
} else {
|
||||
icon = mContext.getResources().getDrawable(resID);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
// return mIconProvider.getIcon(info, mIconDpi, flattenDrawable);
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getIconSystemState(String packageName) {
|
||||
return mIconProvider.getSystemStateForPackage(mSystemState, packageName);
|
||||
}
|
||||
|
||||
public static abstract class IconLoadRequest extends HandlerRunnable {
|
||||
IconLoadRequest(Handler handler, Runnable endRunnable) {
|
||||
super(handler, endRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for receiving itemInfo with high-res icon.
|
||||
*/
|
||||
public interface ItemInfoUpdateReceiver {
|
||||
|
||||
void reapplyItemInfo(ItemInfoWithIcon info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.uiuipad.os.icons;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.LauncherActivityInfo;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.uiuipad.os.icons.cache.CachingLogic;
|
||||
|
||||
public class LauncherActivtiyCachingLogic implements CachingLogic<LauncherActivityInfo> {
|
||||
|
||||
private final IconCache mCache;
|
||||
|
||||
public LauncherActivtiyCachingLogic(IconCache cache) {
|
||||
mCache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentName getComponent(LauncherActivityInfo object) {
|
||||
return object.getComponentName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserHandle getUser(LauncherActivityInfo object) {
|
||||
return object.getUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getLabel(LauncherActivityInfo object) {
|
||||
return object.getLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIcon(Context context, LauncherActivityInfo object,
|
||||
BitmapInfo target) {
|
||||
LauncherIcons li = LauncherIcons.obtain(context);
|
||||
li.createBadgedIconBitmap(mCache.getFullResIcon(object),
|
||||
object.getUser(), object.getApplicationInfo().targetSdkVersion).applyTo(target);
|
||||
li.recycle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.uiuipad.os.icons;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Process;
|
||||
|
||||
import com.uiuipad.os.AppInfo;
|
||||
import com.uiuipad.os.FastBitmapDrawable;
|
||||
import com.uiuipad.os.InvariantDeviceProfile;
|
||||
import com.uiuipad.os.ItemInfoWithIcon;
|
||||
import com.uiuipad.os.LauncherAppState;
|
||||
import com.uiuipad.os.R;
|
||||
import com.uiuipad.os.graphics.IconShape;
|
||||
import com.uiuipad.os.model.PackageItemInfo;
|
||||
import com.uiuipad.os.shortcuts.DeepShortcutManager;
|
||||
import com.uiuipad.os.util.Themes;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Wrapper class to provide access to {@link BaseIconFactory} and also to provide pool of this class
|
||||
* that are threadsafe.
|
||||
*/
|
||||
public class LauncherIcons extends BaseIconFactory implements AutoCloseable {
|
||||
|
||||
private static final String EXTRA_BADGEPKG = "badge_package";
|
||||
|
||||
private static final Object sPoolSync = new Object();
|
||||
private static LauncherIcons sPool;
|
||||
private static int sPoolId = 0;
|
||||
|
||||
public static LauncherIcons obtain(Context context) {
|
||||
return obtain(context, IconShape.getShape().enableShapeDetection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new Message instance from the global pool. Allows us to
|
||||
* avoid allocating new objects in many cases.
|
||||
*/
|
||||
public static LauncherIcons obtain(Context context, boolean shapeDetection) {
|
||||
int poolId;
|
||||
synchronized (sPoolSync) {
|
||||
if (sPool != null) {
|
||||
LauncherIcons m = sPool;
|
||||
sPool = m.next;
|
||||
m.next = null;
|
||||
return m;
|
||||
}
|
||||
poolId = sPoolId;
|
||||
}
|
||||
|
||||
InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
|
||||
return new LauncherIcons(context, idp.fillResIconDpi, idp.iconBitmapSize, poolId,
|
||||
shapeDetection);
|
||||
}
|
||||
|
||||
public static void clearPool() {
|
||||
synchronized (sPoolSync) {
|
||||
sPool = null;
|
||||
sPoolId++;
|
||||
}
|
||||
}
|
||||
|
||||
private final int mPoolId;
|
||||
|
||||
private LauncherIcons next;
|
||||
|
||||
private LauncherIcons(Context context, int fillResIconDpi, int iconBitmapSize, int poolId,
|
||||
boolean shapeDetection) {
|
||||
super(context, fillResIconDpi, iconBitmapSize, shapeDetection);
|
||||
mPoolId = poolId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recycles a LauncherIcons that may be in-use.
|
||||
*/
|
||||
public void recycle() {
|
||||
synchronized (sPoolSync) {
|
||||
if (sPoolId != mPoolId) {
|
||||
return;
|
||||
}
|
||||
// Clear any temporary state variables
|
||||
clear();
|
||||
|
||||
next = sPool;
|
||||
sPool = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
recycle();
|
||||
}
|
||||
|
||||
// below methods should also migrate to BaseIconFactory
|
||||
|
||||
public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo) {
|
||||
return createShortcutIcon(shortcutInfo, true /* badged */);
|
||||
}
|
||||
|
||||
public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged) {
|
||||
return createShortcutIcon(shortcutInfo, badged, null);
|
||||
}
|
||||
|
||||
public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo,
|
||||
boolean badged, @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) {
|
||||
Drawable unbadgedDrawable = DeepShortcutManager.getInstance(mContext)
|
||||
.getShortcutIconDrawable(shortcutInfo, mFillResIconDpi);
|
||||
IconCache cache = LauncherAppState.getInstance(mContext).getIconCache();
|
||||
|
||||
final Bitmap unbadgedBitmap;
|
||||
if (unbadgedDrawable != null) {
|
||||
unbadgedBitmap = createScaledBitmapWithoutShadow(unbadgedDrawable, 0);
|
||||
} else {
|
||||
if (fallbackIconProvider != null) {
|
||||
// Fallback icons are already badged and with appropriate shadow
|
||||
ItemInfoWithIcon fullIcon = fallbackIconProvider.get();
|
||||
if (fullIcon != null && fullIcon.iconBitmap != null) {
|
||||
BitmapInfo result = new BitmapInfo();
|
||||
result.icon = fullIcon.iconBitmap;
|
||||
result.color = fullIcon.iconColor;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
unbadgedBitmap = cache.getDefaultIcon(Process.myUserHandle()).icon;
|
||||
}
|
||||
|
||||
BitmapInfo result = new BitmapInfo();
|
||||
if (!badged) {
|
||||
result.color = Themes.getColorAccent(mContext);
|
||||
result.icon = unbadgedBitmap;
|
||||
return result;
|
||||
}
|
||||
|
||||
final Bitmap unbadgedfinal = unbadgedBitmap;
|
||||
final ItemInfoWithIcon badge = getShortcutInfoBadge(shortcutInfo, cache);
|
||||
|
||||
result.color = badge.iconColor;
|
||||
result.icon = BitmapRenderer.createHardwareBitmap(mIconBitmapSize, mIconBitmapSize, (c) -> {
|
||||
getShadowGenerator().recreateIcon(unbadgedfinal, c);
|
||||
badgeWithDrawable(c, new FastBitmapDrawable(badge));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public ItemInfoWithIcon getShortcutInfoBadge(ShortcutInfo shortcutInfo, IconCache cache) {
|
||||
ComponentName cn = shortcutInfo.getActivity();
|
||||
String badgePkg = getBadgePackage(shortcutInfo);
|
||||
boolean hasBadgePkgSet = !badgePkg.equals(shortcutInfo.getPackage());
|
||||
if (cn != null && !hasBadgePkgSet) {
|
||||
// Get the app info for the source activity.
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.user = shortcutInfo.getUserHandle();
|
||||
appInfo.componentName = cn;
|
||||
appInfo.intent = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
.setComponent(cn);
|
||||
cache.getTitleAndIcon(appInfo, false);
|
||||
return appInfo;
|
||||
} else {
|
||||
PackageItemInfo pkgInfo = new PackageItemInfo(badgePkg);
|
||||
cache.getTitleAndIconForApp(pkgInfo, false);
|
||||
return pkgInfo;
|
||||
}
|
||||
}
|
||||
|
||||
private String getBadgePackage(ShortcutInfo si) {
|
||||
String whitelistedPkg = mContext.getString(R.string.shortcutinfo_badgepkg_whitelist);
|
||||
if (whitelistedPkg.equals(si.getPackage())
|
||||
&& si.getExtras() != null
|
||||
&& si.getExtras().containsKey(EXTRA_BADGEPKG)) {
|
||||
return si.getExtras().getString(EXTRA_BADGEPKG);
|
||||
}
|
||||
return si.getPackage();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user