Systemui qsSetting添加新图标

参考文章

https://blog.youkuaiyun.com/h1217256980/article/details/105726771

补充

按照文章中的可以实现效果,本文针对第一点自定义类做一些细化。
新增按钮其实比较简单,因为原生框架已经搭建好了,我们只要集成实现关键方法就可以了。
QS添加按钮主要注意以下己点:
1、按钮状态(打开、关闭、不可用)
2、点击事件
3、长按事件
4、状态更新
adb获取当前qsSetting列表配置
adb shell settings get secure sysui_qs_tiles

西瓜桶

------因为这一天同事请我喝了一杯西瓜桶奶茶,刚好我在做添加新按钮,所以这个demo就叫这个名字了~!哈哈哈

demo代码仅供参考,因为Android大版本不同,构造方法和实现父类方法可能有一些区别。

package com.android.systemui.qs.tiles;

import android.content.Intent;
import android.graphics.Color;
import android.media.AudioManager;
import android.service.quicksettings.Tile;

import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;

import javax.inject.Inject;

public class XiGuaTong extends QSTileImpl<QSTile.BooleanState> {

    int index = 0;
    int[] color = {Color.BLUE,Color.DKGRAY,Color.YELLOW};
    @Inject
    protected XiGuaTong(QSHost host) {
        super(host);
    }

    @Override
    public BooleanState newTileState() {
        BooleanState state = new BooleanState();
        state.label = this.getClass().getSimpleName();
        state.handlesLongClick = false;
        return state;
    }

    @Override
    protected void handleClick() {
        index++;
        refreshState();
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.state = index%4 == 3? Tile.STATE_INACTIVE: Tile.STATE_ACTIVE;
        state.secondaryLabel = String.valueOf(index);
        state.label = this.getClass().getSimpleName();
        switch (index%4) {
            case 0:
                state.icon = new DrawableIcon(mContext.getDrawable(com.android.systemui.R.drawable.ic_volume_ringer));
                break;
            case 1:
                state.icon = new DrawableIcon(mContext.getDrawable(com.android.systemui.R.drawable.ic_volume_ringer_vibrate));
                break;
            case 2:
                state.icon = new DrawableIcon(mContext.getDrawable(com.android.systemui.R.drawable.ic_volume_ringer_mute));
                break;
            case 3:
                break;
            default:
                break;
        }
//        int color = this.color[index%3];
    }

    @Override
    public int getMetricsCategory() {
        return 0;
    }

    @Override
    public Intent getLongClickIntent() {
        //
        return null;
    }

    @Override
    public CharSequence getTileLabel() {
        return this.getClass().getSimpleName();
    }
}

疑问

我本来想自己控制按钮的颜色,比如点击按钮,按钮背景色改变成想要的颜色,但是没找到。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值