小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Android

 muyable 2014-05-02

第一步:我們先從LauncherApplication.java開始,先找到onCreate()方法:

  1. public void onCreate() {  
  2.         //設(shè)置最小堆內(nèi)存8M  
  3.         VMRuntime.getRuntime().setMinimumHeapSize(8 * 1024 * 1024); //llx modify the heapsize  
  4.         super.onCreate();  
  5.   
  6.         //建立應(yīng)用圖標緩存器           
  7.         mIconCache = new IconCache(this);  
  8.         //建立LauncherModel  
  9.         mModel = new LauncherModel(this, mIconCache);  
  10.         // Register intent receivers          
  11.         //注冊Intent.ACTION_PACKAGE_ADDED,Intent.ACTION_PACKAGE_REMOVED,  
  12.        //Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE,  
  13.        //Intent.ACTION_LOCALE_CHANGED 事件監(jiān)聽器  
  14.        //LauncherModel作為廣播接收器對上面事件進行監(jiān)聽  
  15.       IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);  
  16.        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);  
  17.        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);  
  18.        filter.addDataScheme("package");  
  19.        registerReceiver(mModel, filter);  
  20.   
  21.        filter = new IntentFilter();  
  22.        filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);  
  23.        filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);  
  24.        registerReceiver(mModel, filter);  
  25.   
  26.        filter = new IntentFilter();  
  27.        filter.addAction(Intent.ACTION_LOCALE_CHANGED);  
  28.        registerReceiver(mModel, filter);  
  29.          
  30.      // Register for changes to the favorites  
  31.         //添加對桌面favorites content provider 數(shù)據(jù)變化監(jiān)聽器  
  32.        ContentResolver resolver = getContentResolver();  
  33.        resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,mFavoritesObserver);  
  34.  }  
第二步:看下Launcher.java中的onCreate()方法:
  1. protected void onCreate(Bundle savedInstanceState) {  
  2.         super.onCreate(savedInstanceState);  
  3.         //獲取LauncherApplication LauncherModel mIconCache等LauncherApplication初始化的對象  
  4.         LauncherApplication app = ((LauncherApplication)getApplication());  
  5.         mModel = app.setLauncher(this);  
  6.         mIconCache = app.getIconCache();  
  7.         //新建拖放控制器new DragController(this)  
  8.         mDragController = new DragController(this);  
  9.         mInflater = getLayoutInflater();  
  10.   
  11.         //獲取桌面組件管理器,啟動桌面組件host  
  12.         mAppWidgetManager = AppWidgetManager.getInstance(this);  
  13.         mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);  
  14.         mAppWidgetHost.startListening();  
  15.         if (PROFILE_STARTUP) {  
  16.             android.os.Debug.startMethodTracing("/sdcard/launcher");  
  17.         }  
  18.         //從array.hotseats中加載所有的hotseats  
  19.         loadHotseats();  
  20.   
  21.         //從加載本地設(shè)置  
  22.         checkForLocaleChange();setWallpaperDimension();  
  23.   
  24.         //加載布局文件  
  25.         setContentView(R.layout.launcher);  
  26.         //初始化所有控件  
  27.         setupViews();  
  28.         registerContentObservers();  
  29.         lockAllApps();  
  30.         //從Bundle savedInstanceState獲取桌面持久化數(shù)據(jù)  
  31.         mSavedState = savedInstanceState;  
  32.         restoreState(mSavedState);  
  33.   
  34.         if (PROFILE_STARTUP) {  
  35.            android.os.Debug.stopMethodTracing();  
  36.          }  
  37.   
  38.         if (!mRestoring) {  
  39.         //LauncherModel.Loader.startLoader() 代碼同步處理  
  40.         mModel.startLoader(this, true);  
  41.          }  
  42.   
  43.        // For handling default keys  
  44.         mDefaultKeySsb = new SpannableStringBuilder();  
  45.         Selection.setSelection(mDefaultKeySsb, 0);  
  46.   
  47.         //注冊Intent.ACTION_CLOSE_SYSTEM_DIALOGS廣播監(jiān)聽  
  48.         IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);  
  49.         registerReceiver(mCloseSystemDialogsReceiver, filter);  
  50.      }  
第三步:加載桌面項: 在LauncherModel.java的Thread的run方法, 是在主線程完成以后才開始加載。

  1. public void run() {  
  2.             // Optimize for end-user experience: if the Launcher is up and // running with the  
  3.             // All Apps interface in the foreground, load All Apps first. Otherwise, load the  
  4.             // workspace first (default).  
  5.             final Callbacks cbk = mCallbacks.get();  
  6.             final boolean loadWorkspaceFirst = cbk != null ? (!cbk.isAllAppsVisible()) : true;  
  7.   
  8.             keep_running: {  
  9.                 // Elevate priority when Home launches for the first time to avoid  
  10.                 // starving at boot time. Staring at a blank home is not cool.  
  11.                 synchronized (mLock) {  
  12.                     android.os.Process.setThreadPriority(mIsLaunching  
  13.                              Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);  
  14.                 }  
  15.                 //判斷是否先加載桌面  
  16.                 if (loadWorkspaceFirst) {  
  17.                     if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace");  
  18.                     //從數(shù)據(jù)庫launcher.db中查詢中所有桌面項構(gòu)造對應(yīng)類型的ItemInfo對象存入  
  19.                     loadAndBindWorkspace();  
  20.                 } else {  
  21.                     if (DEBUG_LOADERS) Log.d(TAG, "step 1: special: loading all apps");  
  22.                     loadAndBindAllApps();  
  23.                 }  
  24.                 if (mStopped) {  
  25.                     break keep_running;  
  26.                 }  
  27.   
  28.                 // Whew! Hard work done.  Slow us down, and wait until the UI thread has  
  29.                 // settled down.  
  30.                 synchronized (mLock) {  
  31.                     if (mIsLaunching) {  
  32.                         android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);  
  33.                     }  
  34.                 }  
  35.                 waitForIdle();  
  36.   
  37.                 // second step  
  38.                 if (loadWorkspaceFirst) {  
  39.                     if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps");  
  40.                     loadAndBindAllApps();  
  41.                 } else {  
  42.                     if (DEBUG_LOADERS) Log.d(TAG, "step 2: special: loading workspace");  
  43.                     loadAndBindWorkspace();  
  44.                 }  
  45.             }  

這里調(diào)用了Launcher.java中startBinding方法

  1. public void startBinding() {  
  2.         final Workspace workspace = mWorkspace;  
  3.         int count = workspace.getChildCount();  
  4.         for (int i = 0; i < count; i++) {  
  5.             // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().  
  6.             ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();  
  7.         }  
  8.   
  9.         if (DEBUG_USER_INTERFACE) {  
  10.             android.widget.Button finishButton = new android.widget.Button(this);  
  11.             finishButton.setText("Finish");  
  12.             workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);  
  13.   
  14.             finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {  
  15.                 public void onClick(View v) {  
  16.                     finish();  
  17.                 }  
  18.             });  
  19.         }  
  20.     }  
還有Launcher.java的bindItem()方法:

  1. public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {  
  2.         setLoadOnResume();  
  3.         //獲取桌面的celllayout對象,也就是workspace下5個用戶桌面中的一個  
  4.         final Workspace workspace = mWorkspace;  
  5.         for (int i=start; i<end; i++) {  
  6.             //根據(jù)ItemInfo對象創(chuàng)建桌面圖標view對象  
  7.             final ItemInfo item = shortcuts.get(i);  
  8.             mDesktopItems.add(item);  
  9.             switch (item.itemType) {  
  10.                 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:  
  11.                 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:  
  12.                     final View shortcut = createShortcut((ShortcutInfo)item);  
  13.                    //獲取item.screen, item.cellX, item.cellY, spanX, spanY并添加到屏幕上。  
  14.                     workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,false);  
  15.                     break;  
  16.                 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:  
  17.                     final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,  
  18.                             (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),  
  19.                             (UserFolderInfo) item);  
  20.                     workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,false);  
  21.                     break;  
  22.                 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:  
  23.                     final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(  
  24.                             R.layout.live_folder_icon, this,  
  25.                             (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),  
  26.                             (LiveFolderInfo) item);  
  27.                     workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,false);  
  28.                     break;  
  29.             }  
  30.         }  
  31.          //.重新設(shè)置桌面圖標view 的layoutparam(類型為cellLayout.layoutparam)  
  32.           workspace.requestLayout();  
  33.     }  
注意,這兩個方法都是異步調(diào)用。原因應(yīng)該很清楚:時間。

另外還要注意一下兩點:

         1.桌面圖標view對象添加OnLongClickListener=laucher,由laucher負責(zé)監(jiān)聽桌面圖標view的longclick事件

         2.如果桌面圖標是DropTarget對象,拖放控制器mDragController添加該view到拖放目的地列表

Launcher.java的代碼中有bindFolders()bindAppWidget()方法,都是回調(diào)方法。主要看下bindAppWidget()方法吧。

  1. /** 
  2.  
  3.      * Add the views for a widget to the workspace. 
  4.      * 
  5.      * Implementation of the method from LauncherModel.Callbacks. 
  6.      */  
  7.     public void bindAppWidget(LauncherAppWidgetInfo item) {  
  8.         setLoadOnResume();  
  9.   
  10.         final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;  
  11.         if (DEBUG_WIDGETS) {  
  12.             Log.d(TAG, "bindAppWidget: " + item);  
  13.         }  
  14.         final Workspace workspace = mWorkspace;  
  15.         //獲取LauncherAppWidgetInfo的appWidgetId  
  16.         final int appWidgetId = item.appWidgetId;  
  17.         //根據(jù)appWidgetInfo創(chuàng)建桌面組件的view AppWidgetHostView對象  
  18.         final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);  
  19.         if (DEBUG_WIDGETS) {  
  20.             Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);  
  21.         }  
  22.   
  23.         item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);  
  24.   
  25.         item.hostView.setAppWidget(appWidgetId, appWidgetInfo);  
  26.         item.hostView.setTag(item);  
  27.         //添加到對應(yīng)桌面的cell  
  28.         workspace.addInScreen(item.hostView, item.screen, item.cellX,  
  29.                 item.cellY, item.spanX, item.spanY, false);  
  30.   
  31.         workspace.requestLayout();  
  32.   
  33.         mDesktopItems.add(item);  
  34.   
  35.         if (DEBUG_WIDGETS) {  
  36.             Log.d(TAG, "bound widget id="+item.appWidgetId+" in "  
  37.                     + (SystemClock.uptimeMillis()-start) + "ms");  
  38.         }  
  39.     }  
  40. <span style="font-size:16px;">  
  41. </span>  

當(dāng)都加載完成以后會執(zhí)行finishBindingItems():

  1. /** 
  2.      * Callback saying that there aren't any more items to bind. 
  3.      * 
  4.      * Implementation of the method from LauncherModel.Callbacks. 
  5.      */  
  6.     public void finishBindingItems() {  
  7.         setLoadOnResume();  
  8.         if (mSavedState != null) {  
  9.             if (!mWorkspace.hasFocus()) {  
  10.                 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();  
  11.             }  
  12.             final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);  
  13.             if (userFolders != null) {  
  14.                 for (long folderId : userFolders) {  
  15.                     final FolderInfo info = sFolders.get(folderId);  
  16.                     if (info != null) {  
  17.                         openFolder(info);  
  18.                     }  
  19.                 }  
  20.                 final Folder openFolder = mWorkspace.getOpenFolder();  
  21.                 if (openFolder != null) {  
  22.                     openFolder.requestFocus();  
  23.                 }  
  24.             }  
  25.             mSavedState = null;  
  26.         }  
  27.         if (mSavedInstanceState != null) {  
  28.             super.onRestoreInstanceState(mSavedInstanceState);  
  29.             mSavedInstanceState = null;  
  30.         }  
  31.         mWorkspaceLoading = false;  
  32.     }  

前面那三個都是都是回調(diào)方法,控制器當(dāng)然是LauncherModel.java了,讓我們在代碼里看一下:

其接口定義如下:

  1. public interface Callbacks {  
  2.         public boolean setLoadOnResume();  
  3.         public int getCurrentWorkspaceScreen();  
  4.         public void startBinding();  
  5.         public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);  
  6.         public void bindFolders(HashMap<Long,FolderInfo> folders);  
  7.         public void finishBindingItems();  
  8.         public void bindAppWidget(LauncherAppWidgetInfo info);  
  9.         public void bindAllApplications(ArrayList<ApplicationInfo> apps);  
  10.         public void bindAppsAdded(ArrayList<ApplicationInfo> apps);  
  11.         public void bindAppsUpdated(ArrayList<ApplicationInfo> apps);  
  12.         public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent);  
  13.         public boolean isAllAppsVisible();  
  14.     }  

想看仔細的,自己可以在代碼中找一下。

最后執(zhí)行 bindAllApplications() , bindAppsAdded()方法

  1. public void bindAllApplications(ArrayList<ApplicationInfo> apps) {  
  2.         mAllAppsGrid.setApps(apps);  
  3.     }  
  4.     /** 
  5.      * A package was installed. 
  6.      * 
  7.      * Implementation of the method from LauncherModel.Callbacks. 
  8.      */  
  9.     public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {  
  10.         setLoadOnResume();  
  11.         removeDialog(DIALOG_CREATE_SHORTCUT);  
  12.         mAllAppsGrid.addApps(apps);  
  13.     }  

到這基本上就是整個的啟動過程了。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多