LauncherApplication
http://blog.csdn.net/hu2839fdjsfdsan/article/details/6570036
1.LauncherApplication的作用意義分析
概括: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>
作用:
a.創建全局使用的應用程序快捷方式的緩存.
?? ?IconCache,即在LauncherApplication中創建.
b.創建全局使用的數據庫加載類LauncherModel.
?
c.為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);
?
d.提供全局使用的LauncherModel的入口.
?? ?LauncherModel getModel() {
?? ? ? ?return mModel;
?? ?}
?
e.(父類)提供獲取PackageManager,Resource,相關資源的方法.
?? LauncherModel.java
?? ? ? app.getPackageManager().getDefaultActivityIcon();
?? ? ? app.getResources().getInteger();
?
f.提供Context作用.
?
2.IconCache
概括:
?? ?這個類是提供系統全局使用的應用程序基本信息(title,icon)的緩存信息.這樣每次使用的時候都能夠從系統里很快得到.
?
作用:
?? ?a.聲明內部類對應存儲應用程序的基本信息,因為home的作用就是需要展現這些東西。
?? ? ? private static class CacheEntry {
?? ? ? ? ? public Bitmap icon;
?? ? ? ? ? public String title;
?? ? ? ? ? public Bitmap titleBitmap;
?? ? }
?? ?b.提供應用程序的默認圖標.
?? ? ? ? ? private Bitmap makeDefaultIcon();
?? ?c.提供全局的緩存信息.
?? ? ? ? ? private final HashMap<ComponentName, CacheEntry> mCache;
?
?
3.LauncherModel
概括:
?? ?在程序包,以及程序的快捷方式更改,添加時,更新數據庫的表。加載更新workspace,all apps view的程序及快捷方式.
?
作用:
?? ?a.聲明接口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();
? ?}
轉載于:https://www.cnblogs.com/greywolf/archive/2012/12/24/2831267.html
總結
以上是生活随笔為你收集整理的LauncherApplication的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华一银行开发安全内部培训圆满结束
- 下一篇: 得到ios设备的屏幕尺寸信息