Android源码开发之长按power键添加GlobalActions

来源:互联网 发布:东京著衣淘宝上没有了 编辑:程序博客网 时间:2024/05/17 06:14

应客户需求,开发一个长按power键,弹出截图的菜单,原本按power键只会弹出关机和重启、飞行模式等。

1.找到frameworks/base/core/res/res/values/config.xml

添加数组

    <string-array translatable="false" name="config_globalActionsList">
        <item>power</item>
        <item>reboot</item>
        <item>airplane</item>
<item>screenshot</item>
    </string-array>

2.找到frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java

添加GlobalActions

private static final String GLOBAL_ACTION_KEY_SCREEN_SHOT = "screenshot";

--------

    private GlobalActionsDialog createDialog() {

---------------

else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
                mItems.add(mAirplaneModeOn);
            }else if(GLOBAL_ACTION_KEY_SCREEN_SHOT.equals(actionKey)){
mItems.add(getScreenShotActions());
}

------------

//添加action

private Action getScreenShotAction(){
return new SinglePressAction(
                    com.android.internal.R.drawable.ic_screenshot,
                    R.string.global_screenshot) {

                public void onPress() {
                    mWindowManagerFuncs.ScreenShot();//回调截图
                }
                public boolean onLongPress() {
                    return true;
                }
                public boolean showDuringKeyguard() {
                    return true;
                }
                public boolean showBeforeProvisioning() {
                    return true;
                }
            };
}

具体mWindowManagerFuncs.ScreenShot();回调的实现需要读者去实现

0 0
原创粉丝点击