1. 程式人生 > >Android Launcher分析和修改1——Launcher預設介面配置(default_workspace)

Android Launcher分析和修改1——Launcher預設介面配置(default_workspace)

複製程式碼
//Edited by mythou
//
//傳入default_workspace檔案的資源ID和資料庫實力,把xml裡面資料解析,儲存到Launcher資料庫。返回總共解析了多少個標籤。
private int loadFavorites(SQLiteDatabase db, int workspaceResourceId) {

         //.........
int type;
                while (((type = parser.next()) != XmlPullParser.END_TAG ||
                        parser.getDepth() 
> depth) && type != XmlPullParser.END_DOCUMENT)          { if (type != XmlPullParser.START_TAG) { continue; } boolean added = false; final String name = parser.getName(); TypedArray a
= mContext.obtainStyledAttributes(attrs, R.styleable.Favorite); long container = LauncherSettings.Favorites.CONTAINER_DESKTOP; if (a.hasValue(R.styleable.Favorite_container)) { container = Long.valueOf(a.getString(R.styleable.Favorite_container)); } String screen
= a.getString(R.styleable.Favorite_screen); String x = a.getString(R.styleable.Favorite_x); String y = a.getString(R.styleable.Favorite_y); // If we are adding to the hotseat, the screen is used as the position in the // hotseat. This screen can't be at position 0 because AllApps is in the // zeroth position. if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && Integer.valueOf(screen) == allAppsButtonRank) { throw new RuntimeException("Invalid screen position for hotseat item"); } values.clear(); values.put(LauncherSettings.Favorites.CONTAINER, container); values.put(LauncherSettings.Favorites.SCREEN, screen); values.put(LauncherSettings.Favorites.CELLX, x); values.put(LauncherSettings.Favorites.CELLY, y);             //解析xml裡面的標籤,從這裡可以找到支援的標籤型別和相關屬性引數。 if (TAG_FAVORITE.equals(name)) { long id = addAppShortcut(db, values, a, packageManager, intent); added = id >= 0; } else if (TAG_SEARCH.equals(name)) { added = addSearchWidget(db, values); } else if (TAG_CLOCK.equals(name)) { added = addClockWidget(db, values); } else if (TAG_APPWIDGET.equals(name)) { added = addAppWidget(parser, attrs, type, db, values, a, packageManager); } else if (TAG_SHORTCUT.equals(name)) { long id = addUriShortcut(db, values, a); added = id >= 0; } else if (TAG_FOLDER.equals(name))             {             //.........                              //folder屬性裡面的引數要多於2個,才能形成資料夾。 if (folderItems.size() < 2 && folderId >= 0) { // We just delete the folder and any items that made it deleteId(db, folderId); if (folderItems.size() > 0) { deleteId(db, folderItems.get(0)); } added = false; } } if (added) i++; a.recycle(); }         //......... return i; }
複製程式碼