Launcher简要分析:Launcher的其他内容

Launcher可以说是对外在和内涵要求都非常高的一个应用,太丑了用户第一眼映像就不要;操作效果华丽但是不流畅卡顿也会大大影响用户的使用。所以Launcher中对性能的优化也做下了一定的苦工。

一个应用程序的启动,我们通常而言是通过与Intent匹配的Activity启动的,而实际上,在任何应用程序启动前,该应用程序的Application类已经运行了。Launcher在Applcation中为各个功能做了不少的伏笔与优化。

 LauncherApplicaton

LauncherApplication属于自定义的Application类,并在AndroidManifest.xml里指定了自定义Application类,如下:

<application
android:name="com.android.launcher2.LauncherApplication"
android:process="@string/process"
android:label="@string/application_name"
android:icon="@drawable/ic_launcher_home">
</application>

作用:

  • 创建全局使用的应用程序快捷方式的缓存.

IconCache,即在LauncherApplication中创建.

  • 创建全局使用的数据库加载类LauncherModel.
  • 为LauncherModel注册package remove,update相关的Boradcast.为LauncherModel 注册favorites 修改的observer.
// Register intent receivers
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package");
registerReceiver(mModel, filter);
filter = new IntentFilter();
filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
registerReceiver(mModel, filter);
// Register for changes to the favorites
ContentResolver resolver = getContentResolver();
resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
mFavoritesObserver);
  • 提供全局使用的LauncherModel的入口.
LauncherModel getModel() {
return mModel;
}
  • (父类)提供获取PackageManager,Resource,相关资源的方法.
LauncherModel.java
app.getPackageManager().getDefaultActivityIcon();
app.getResources().getInteger();
  • 提供Context作用.

IconCache

概括: 这个类是提供系统全局使用的应用程序基本信息(title,icon)的缓存信息.这样每次使用的时候都能够从系统里很快得到. 作用:

  • 声明内部类对应存储应用程序的基本信息,因为home的作用就是需要展现这些东西。
private static class CacheEntry {
public Bitmap icon;
public String title;
public Bitmap titleBitmap;
}
  • 提供应用程序的默认图标.
private Bitmap makeDefaultIcon();
  • 提供全局的缓存信息.
private final HashMap<ComponentName, CacheEntry> mCache;

LauncherModel

概括: 在程序包,以及程序的快捷方式更改,添加时,更新数据库的表。加载更新workspace,all apps view的程序及快捷方式. 作用:

  • 声明接口Callbacks,提供了一系列加载程序及快捷方式的抽象方法.
public interface Callbacks {
public boolean setLoadOnResume();
public int getCurrentWorkspaceScreen();
public void startBinding();
public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
public void bindFolders(HashMap<Long,FolderInfo> folders);
public void finishBindingItems();
public void bindAppWidget(LauncherAppWidgetInfo info);
public void bindAllApplications(ArrayList<ApplicationInfo> apps);
public void bindAppsAdded(ArrayList<ApplicationInfo> apps);
public void bindAppsUpdated(ArrayList<ApplicationInfo> apps);
public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent);
public boolean isAllAppsVisible();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值