1. 程式人生 > >android充電指示燈顏色修改

android充電指示燈顏色修改

檔案位置:frameworks\base\services\core\java\com\android\server\BatteryService.java

 /**
         * Synchronize on BatteryService.
         */
        public void updateLightsLocked() {
            final int level = mBatteryProps.batteryLevel;
            final int status = mBatteryProps.batteryStatus;
            if (mIPOBoot)
            {
                //Get led status in IPO mode
                getIpoLedStatus();
            }
            if (level < mLowBatteryWarningLevel) {
                if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
                    updateLedStatus();
                    // Solid red when battery is charging
					//wdh_changed
					Log.d(TAG, "level=" + level+"status="+status);
                    mBatteryLight.setColor(mBatteryMediumARGB);
                } else {
                    LowLevelFlag = true;
                    updateLedStatus();
                    // Flash red when battery is low and not charging
                    mBatteryLight.setFlashing(mBatteryLowARGB, Light.LIGHT_FLASH_TIMED,
                            mBatteryLedOn, mBatteryLedOff);
                }
            } else if (status == BatteryManager.BATTERY_STATUS_CHARGING
                    || status == BatteryManager.BATTERY_STATUS_FULL) {
                if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) {
                    updateLedStatus();
                    // Solid green when full or charging and nearly full
                    mBatteryLight.setColor(mBatteryFullARGB);
                } else {
                    updateLedStatus();
                    // Solid orange when charging and halfway full
                    mBatteryLight.setColor(mBatteryMediumARGB);
                }
            } else {
                if (ipo_led_on && mIPOBoot) {
                    if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) {
                        mBatteryLight.setColor(mBatteryFullARGB);
                    }
                    else {
                        mBatteryLight.setColor(mBatteryMediumARGB);
                    }
                    mIPOBoot = false;
                    ipo_led_on = false;
                }
                // No lights if not charging and not low
                mBatteryLight.turnOff();
            }
        }

上面是更新充電指示燈的狀態, mBatteryLight.setColor(mBatteryFullARGB)是設定指示燈顏色

mBatteryLowARGB:低電量顏色,也是低電量警告顏色

mBatteryMediumARGB:中電量顏色,一般是低電量以上到90%電量之間,充電顯示此顏色

mBatteryFullARGB:滿電顏色,一般是充電狀態下,90%到100%之間顯示此顏色

mBatteryLight.setFlashing(mBatteryLowARGB, Light.LIGHT_FLASH_TIMED,
                            mBatteryLedOn, mBatteryLedOff);此方法是低電量,閃燈狀態,閃燈警告