The following is a brief analysis of how luncher modifies the wallpaper in the source code (the following code is from the luncher source code ):
1. When we press menu on the luncher interface, the third option is wallpaper, which is defined as follows (source code: 1116 lines, partial). Menu. Add the second option is to select Wallpaper:
public boolean onCreateOptionsMenu(Menu menu) { if (isWorkspaceLocked()) { return false; } super.onCreateOptionsMenu(menu); menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) .setIcon(android.R.drawable.ic_menu_add) .setAlphabeticShortcut('A'); menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) .setIcon(android.R.drawable.ic_menu_gallery) .setAlphabeticShortcut('W');
2. What events will be triggered when we press wallpaper? Take a look at the code (source code 1171 lines ):
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_ADD: addItems(); return true; case MENU_WALLPAPER_SETTINGS: startWallpaper(); return true; case MENU_SEARCH: onSearchRequested(); return true; case MENU_NOTIFICATIONS: showNotifications(); return true; } return super.onOptionsItemSelected(item); }
We can see:
The event it calls is
startWallpaper();
The pictures you see are different from mine. Haha, this is because I wrote a very simple demo and then the system called it. So you can see a wallpaperdemo that is more than yours. In the next log, I will explain how this demo is implemented.
3. Let's take a look at the startwallpaper () method (source code 1370 lines ):
private void startWallpaper() { closeAllApps(true); final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); Intent chooser = Intent.createChooser(pickWallpaper, getText(R.string.chooser_wallpaper)); // NOTE: Adds a configure option to the chooser if the wallpaper supports it // Removed in Eclair MR1// WallpaperManager wm = (WallpaperManager)// getSystemService(Context.WALLPAPER_SERVICE);// WallpaperInfo wi = wm.getWallpaperInfo();// if (wi != null && wi.getSettingsActivity() != null) {// LabeledIntent li = new LabeledIntent(getPackageName(),// R.string.configure_wallpaper, 0);// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });// } startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); }
Many may decide how to implement the Redirect settings? The implementation principle of intent. createchooser () is curious, because you cannot find the live wallpapers and galleryde implementations in the luncher source code. Because it uses a broadcast-like mechanism.
In the next log http://blog.csdn.net/aomandeshangxiao/article/details/6768249, We will detail the usage of intent. createchooser.
I wrote a simple small example: http://download.csdn.net/detail/aomandeshangxiao/3593740