Luncher modify wallpaper source code tracking (code implementation process analysis)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.