状态栏 添加 system icon

 

1.  添加网速

网速的显示和 ICON

 

 

 

2.  添加蓝牙耳机和电量显示(9.0 连接上蓝牙耳机后, 在 setting 中可以查看到 蓝牙耳机的相关逻辑)

https://blog.csdn.net/jcxxxxx55/article/details/52847291?locationNum=4&fps=1

1.HeadsetStateMachine.java

    static {
        classInitNative();
        VENDOR_SPECIFIC_AT_COMMAND_COMPANY_ID = new HashMap<String, Integer>();
        VENDOR_SPECIFIC_AT_COMMAND_COMPANY_ID.put("+XEVENT", BluetoothAssignedNumbers.PLANTRONICS);
        VENDOR_SPECIFIC_AT_COMMAND_COMPANY_ID.put("+ANDROID", BluetoothAssignedNumbers.GOOGLE);
        // 添加以下两行 (高版本中已经自带, 去这个文件中看一下)
        VENDOR_SPECIFIC_AT_COMMAND_COMPANY_ID.put("+XAPL", BluetoothAssignedNumbers.APPLE);
        VENDOR_SPECIFIC_AT_COMMAND_COMPANY_ID.put("+IPHONEACCEV", BluetoothAssignedNumbers.APPLE);
    }



2.PhoneStatusBarPolicy.java

    public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot,
            UserInfoController userInfoController, BluetoothController bluetooth) {

	    filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT); //蓝牙耳机电量
            filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.APPLE);
	    filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGE); //蓝牙耳机连接状态
            mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
  

    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
	    ...
            case :BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)   
                 updateBluetoothBattery(intent);
		 break;
            case :BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGE
	         break;
        }
    };

    private void updateBluetoothBattery(Intent intent) {

        if (intent.hasExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD)) {
            String command = intent.getStringExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD);
            if ("+IPHONEACCEV".equals(command)) {

		//其实外层的判断可以去掉
                Object[] args = (Object[]) intent.getSerializableExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS);
		if(args == null ){
		   return;
		}
                if (args.length >= 3 && args[0] instanceof Integer && ((Integer)args[0])*2+1<=args.length) {
                    for (int i=0;i<((Integer)args[0]);i++) {
                        if (!(args[i*2+1] instanceof Integer) || !(args[i*2+2] instanceof Integer)) {
                            continue;
                        }
                        if (args[i*2+1].equals(1)) {
                            mBluetoothBatteryLevel = (((Integer)args[i*2+2])+1)/10.0f;
                            updateBluetooth();
                            break;
                        }
                    }
                }
            }
        }
    }

    private final void updateBluetooth() {
        int iconId = R.drawable.stat_sys_data_bluetooth;
        String contentDescription =
                mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
        boolean bluetoothEnabled = false;
        if (mBluetooth != null) {
            bluetoothEnabled = mBluetooth.isBluetoothEnabled();
            if (mBluetooth.isBluetoothConnected()) {
                if (mBluetoothBatteryLevel == null) {
                    iconId = R.drawable.stat_sys_data_bluetooth_connected;
                } else {
                    if (mBluetoothBatteryLevel <= 0.15f) {
                        iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_0;
                    } else if (mBluetoothBatteryLevel <= 0.25f) {
                        iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_1;
                    } else if (mBluetoothBatteryLevel <= 0.375f) {
                        iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_2;
                    } else if (mBluetoothBatteryLevel <= 0.625f) {
                        iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_3;
                    } else if (mBluetoothBatteryLevel <= 0.85f) {
                        iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_4;
                    } else {
                        iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_5;
                    }
                }
                contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
            } else {
                mBluetoothBatteryLevel = null;
            }
        }

        mIconControll.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
        mIconControll.setIconVisibility(SLOT_BLUETOOTH, bluetoothEnabled);
    }

  setting 中的蓝牙耳机

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

空白的泡

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值