主要要的逻辑就是想办法替换掉应用icon的drawable,然后通过自定义drawable的方式来实现动态Icon。
直接贴代码吧,没什么难的。
首先在IconCache.java 中的修改
<pre name="code" class="java"> private static class CacheEntry {
public Bitmap icon;
public CharSequence title;
public CharSequence contentDescription;
public IconScript script;//icon的脚本
}
public IconScript getScript(Intent intent, UserHandleCompat user){
synchronized (mCache) {
ComponentName component = intent.getComponent();
if (component == null) {
return null;
}
LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, true, -1);
return entry.script;
}
}
private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
HashMap<Object, CharSequence> labelCache, UserHandleCompat user,
boolean usePackageIcon, int unreadNum) {
<span style="white-space:pre"> </span>……
<span style="white-space:pre"> </span> if(componentName.getPackageName().equals("com.android.deskclock"))
entry.script = new ClockScript();
if(componentName.getPackageName().equals("com.android.calendar"))
entry.script = new CalendarScript();
return entry;
}
ShortcutInfo.java
public IconScript getScript(IconCache iconCache){
return iconCache.getScript(promisedIntent != null ? promisedIntent : intent, user);
}
BubbleTextView.java
public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
boolean setDefaultPad