Sometimes, for launcher development, you need to remove the search box and protipwidget on the launcher. In addition, protipwidget is added after Android 2.2. After searching for N for a long time, the original definition file is in launcher2/RES/XML/default_workspace.xml, and the file is pasted below:
<?xml version="1.0" encoding="utf-8"?><favorites xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"> <!-- Far-left screen [0] --> <!-- Left screen [1] --> <appwidget launcher:packageName="com.google.android.apps.genie.geniewidget" launcher:className="com.google.android.apps.genie.geniewidget.miniwidget.MiniWidgetProvider" launcher:screen="1" launcher:x="0" launcher:y="0" launcher:spanX="4" launcher:spanY="1" /> <!-- Middle screen [2] --> <search launcher:screen="2" launcher:x="0" launcher:y="0" /> <appwidget launcher:packageName="com.android.protips" launcher:className="com.android.protips.ProtipWidget" launcher:screen="2" launcher:x="0" launcher:y="1" launcher:spanX="4" launcher:spanY="1" /> <!-- Right screen [3] --> <appwidget launcher:packageName="com.android.music" launcher:className="com.android.music.MediaAppWidgetProvider" launcher:screen="3" launcher:x="0" launcher:y="0" launcher:spanX="4" launcher:spanY="1" /> <appwidget launcher:packageName="com.android.vending" launcher:className="com.android.vending.MarketWidgetProvider" launcher:screen="3" launcher:x="1" launcher:y="1" launcher:spanX="2" launcher:spanY="2" /> <!-- Far-right screen [4] --></favorites>
Then,
<! -- Middle screen [2] --> <search Launcher: screen = "2" // number of screens Launcher: x = "0" // Launcher: y = "0"/> <appwidget Launcher: packagename = "com. android. protips "// The package name of the widget Launcher: classname =" com. android. protips. protipwidget "// display the widget Launcher: screen =" 2 "// number of screens Launcher: x =" 0 "// The Position of the icon X, which is 0 in the upper left corner, ascending to the right, 0-5 6 Launcher: Y = "1" // icon y position, 0 in the upper left corner, ascending downward, 0-2 3 Launcher: spanx = "4" // number of cells in the X direction Launcher: spany = "1"/>
These two are the search box we are looking for and protipwidget (I don't know how to translate them). Search is defined by Google in advance and we can use it directly here, in addition, there are clock (alarm clock) and so on.
If you want to add a shortcut to the launcher, OK, just add it in the above format, to see which one is not pleasing to the eye, just remove it.
Let's take a look at his:
How is the default_workspace.xml file parsed? In the source code of launcher2, there is a class of launcherprovider. Java (635 rows ),
XmlResourceParser parser = mContext.getResources().getXml(R.xml.default_workspace); AttributeSet attrs = Xml.asAttributeSet(parser); XmlUtils.beginDocument(parser, TAG_FAVORITES); final int depth = parser.getDepth(); 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); values.clear(); values.put(LauncherSettings.Favorites.CONTAINER, LauncherSettings.Favorites.CONTAINER_DESKTOP); values.put(LauncherSettings.Favorites.SCREEN, a.getString(R.styleable.Favorite_screen)); values.put(LauncherSettings.Favorites.CELLX, a.getString(R.styleable.Favorite_x)); values.put(LauncherSettings.Favorites.CELLY, a.getString(R.styleable.Favorite_y)); if (TAG_FAVORITE.equals(name)) { added = addAppShortcut(db, values, a, packageManager, intent); } 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(db, values, a, packageManager); } else if (TAG_SHORTCUT.equals(name)) { added = addUriShortcut(db, values, a); } if (added) i++; a.recycle(); }
Here we provide File Parsing. You can see that the widget information is stored in the database. In addition, protipwidget is added after Android 2.2.