Launcher2折腾之路(3)

Launcher2中的壁纸选择器在Launcher2 这个Application中是一个Activity,先看一下Manifest.xml

        <activity
            android:name="com.android.launcher2.WallpaperChooser"
            android:theme="@style/Theme.WallpaperPicker"
            android:label="@string/pick_wallpaper"
            android:icon="@mipmap/ic_launcher_wallpaper"
            android:finishOnCloseSystemDialogs="true"
            android:process=":wallpaper_chooser">
            <intent-filter>
                <action android:name="android.intent.action.SET_WALLPAPER" />
10                  <category android:name="android.intent.category.DEFAULT" />
11              </intent-filter>
12              <meta-data android:name="android.wallpaper.preview"
13                  android:resource="@xml/wallpaper_picker_preview" />
14          </activity>

1,壁纸选择器的启动方式有两种,一种是在Workspace的空白处长按,另外一种是在Workspace按MENU键

a,长按启动

onLongClick@Launcher.java

->

startWallpaper();

->

startActivityForResult(chooser, REQUEST_PICK_WALLPAPER );

其中chooser 是一个Intent

final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER );

=>启动了wallpaperChooser Activity

WallpaperChooser.java

=>

WallpaperChooserDialogFragment. newInstance();

=>

WallpaperChooserDialogFragment.java

public static WallpaperChooserDialogFragment newInstance() {

        WallpaperChooserDialogFragment fragment = new WallpaperChooserDialogFragment();

        fragment.setCancelable( true);

return fragment;

    }

启动的这个小窗口就是一个DialogFragment

先看这下WallpaperChooser 这个Activity的布局

wallpaper_chooser_base.xml调用wallpaper_chooser.xml

里面三个就是一个ListView的View

     <Gallery android:id="@+id/gallery"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:spacing="-4dp" />

Image

大概Layout如下

Image

b,menu启动

重写onCreateOptionsMenu()

@Override

public boolean onCreateOptionsMenu (Menu menu) {

增加wallpaper的选项

menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)

            .setIcon(android.R.drawable. ic_menu_gallery)

            .setAlphabeticShortcut( 'W');

在onOptionsItemSelected()函数是响应这个Item选择。殊途同归。

case MENU_WALLPAPER_SETTINGS :

startWallpaper();

return true;

        }

2,Question:

为什么在workspace界面按menu有wallpaper的选项,而在customerview/all app 却没有wallpaper的选项。暂时还没找到逻辑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可夫小子

感谢大佬!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值