android14的电池图标的修改

上次在13修改了一点修改成​​​​​​ ,感觉不太美观,之后又进行了完善

 现在给图个进行了加粗,充电图标也进行了修改,这里主要就是在之前的基础上改一下矢量图的路径,这个狠让人头疼,

我这里直接放上电池图标的路径

diff --git a/res/values/config.xml b/res/values/config.xml
index 9462362e..73c755b8 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -806,7 +805,6 @@
 
     
     
-        @*android:string/status_bar_volume
         @*android:string/status_bar_alarm_clock
         @*android:string/status_bar_call_strength
     
@@ -917,12 +915,12 @@
     -->
     
 
-     
-                M0,20.75L0,3.25Q0,3.09 0.016,2.931Q0.031,2.773 0.062,2.616Q0.094,2.459 0.14,2.307Q0.186,2.154 0.247,2.006Q0.308,1.859 0.384,1.718Q0.459,1.577 0.548,1.444Q0.636,1.312 0.738,1.188Q0.839,1.065 0.952,0.952Q1.065,0.839 1.188,0.738Q1.312,0.636 1.444,0.548Q1.577,0.459 1.718,0.384Q1.859,0.308 2.006,0.247Q2.154,0.186 2.307,0.14Q2.459,0.094 2.616,0.062Q2.773,0.031 2.931,0.016Q3.09,0 3.25,0L44.75,0Q45.07,0 45.384,0.062Q45.698,0.125 45.993,0.247Q46.289,0.37 46.555,0.547Q46.821,0.725 47.047,0.951L47.048,0.951L47.048,0.952L47.048,0.952L47.049,0.953Q47.275,1.179 47.453,1.445Q47.63,1.711 47.753,2.007Q47.875,2.302 47.938,2.616Q48,2.93 48,3.25L48,20.75Q48,21.069 47.938,21.382Q47.876,21.694 47.755,21.989Q47.633,22.284 47.456,22.549Q47.28,22.815 47.055,23.041Q47.054,23.042 47.053,23.043Q47.047,23.049 47.042,23.055L47.041,23.055Q46.815,23.28 46.549,23.456Q46.284,23.633 45.989,23.754Q45.694,23.876 45.382,23.938Q45.069,24 44.75,24L3.25,24Q2.931,24 2.618,23.938Q2.306,23.876 2.011,23.754Q1.716,23.633 1.451,23.456Q1.185,23.28 0.959,23.055Q0.958,23.054 0.957,23.053Q0.951,23.047 0.945,23.042L0.945,23.041Q0.72,22.815 0.544,22.549Q0.367,22.284 0.246,21.989Q0.124,21.694 0.062,21.382Q0,21.069 0,20.75ZM1.659,1.659Q1,2.318 1,3.25L1,20.75Q1,21.682 1.659,22.341Q2.318,23 3.25,23L44.75,23Q45.682,23 46.341,22.341Q47,21.682 47,20.75L47,3.25Q47,2.318 46.341,1.659Q45.682,1 44.75,1L3.25,1Q2.318,1 1.659,1.659ZM50,9.169L50,15.874C50.355,15.783 50.69,15.644 51,15.465C52.196,14.773 53,13.481 53,12C53,10.519 52.196,9.227 51,8.535C50.69,8.356 50.355,8.217 50,8.126L50,9.169ZM51,9.76L51,14.24Q51.193,14.065 51.361,13.851Q52,13.038 52,12Q52,10.962 51.361,10.148Q51.193,9.935 51,9.76Z
+        
+               M6.404,0.001L32.3,0C34.63,0 35.475,0.243 36.326,0.698C37.178,1.154 37.846,1.822 38.302,2.674C38.757,3.525 39,4.37 39,6.7L39,13.3L38.995,13.875C38.956,15.777 38.718,16.549 38.302,17.326C37.846,18.178 37.178,18.846 36.326,19.302C35.475,19.757 34.63,20 32.3,20L6.7,20L6.125,19.995C4.223,19.956 3.451,19.718 2.674,19.302C1.822,18.846 1.154,18.178 0.698,17.326L0.579,17.093C0.218,16.346 0.02,15.503 0.001,13.596L0,6.7C0,4.37 0.243,3.525 0.698,2.674C1.154,1.822 1.822,1.154 2.674,0.698L2.907,0.579C3.654,0.218 4.497,0.02 6.404,0.001ZM32.3,1.608L6.419,1.609L5.897,1.619C4.598,1.657 4.029,1.796 3.432,2.116C2.86,2.422 2.422,2.86 2.116,3.432C1.74,4.135 1.608,4.818 1.608,6.699L1.609,13.581L1.619,14.103C1.657,15.402 1.796,15.971 2.116,16.568C2.422,17.14 2.86,17.578 3.432,17.884C4.073,18.227 4.662,18.357 6.14,18.387L6.7,18.392L32.3,18.392C34.182,18.392 34.865,18.26 35.568,17.884C36.14,17.578 36.578,17.14 36.884,16.568C37.227,15.927 37.357,15.338 37.387,13.86L37.392,13.3L37.392,6.7C37.392,4.818 37.26,4.135 36.884,3.432C36.578,2.86 36.14,2.422 35.568,2.116C34.939,1.78 34.326,1.639 32.856,1.613L32.3,1.608ZM40.566,6.772C41.966,7.142 43,8.447 43,10C43,11.553 41.966,12.858 40.566,13.228L40.566,6.772Z
     
     @string/config_batterymeterPerimeterPath
     
-        M5.5,4L42.5,4A1.5,1.5 0,0 1,44 5.5L44,18.5A1.5,1.5 0,0 1,42.5 20L5.5,20A1.5,1.5 0,0 1,4 18.5L4,5.5A1.5,1.5 0,0 1,5.5 4z
+        M6.092,3L27.908,3C28.983,3 29.373,3.112 29.766,3.322C30.159,3.532 30.468,3.841 30.678,4.234C30.888,4.627 31,5.017 31,6.092L31,13.908C31,14.983 30.888,15.373 30.678,15.766C30.468,16.159 30.159,16.468 29.766,16.678C29.373,16.888 28.983,17 27.908,17L6.092,17C5.017,17 4.627,16.888 4.234,16.678C3.841,16.468 3.532,16.159 3.322,15.766C3.112,15.373 3,14.983 3,13.908L3,6.092C3,5.017 3.112,4.627 3.322,4.234C3.532,3.841 3.841,3.532 4.234,3.322C4.627,3.112 5.017,3 6.092,3Z
     
     
         M5,17.5 V12 H3 L7,4.5 V10 h2 L5,17.5 z
@@ -936,12 +934,16 @@
 false
 
     
-        M22,17.5l0,-5l-2,0l4,-8l0,5l2,0 z
+      M21.539,0.447L21.539,8.46L25.515,8.46C25.643,8.46 25.761,8.531 25.823,8.646C25.885,8.761 25.881,8.901 25.812,9.011L19.11,19.745C19.026,19.881 18.865,19.943 18.715,19.898C18.564,19.854 18.461,19.713 18.461,19.553L18.461,11.54L14.485,11.54C14.357,11.54 14.239,11.469 14.177,11.354C14.115,11.239 14.119,11.099 14.188,10.989L20.89,0.255C20.974,0.119 21.135,0.057 21.285,0.102C21.436,0.146 21.539,0.287 21.539,0.447L21.539,0.447Z
     
     
-        M22,13.5l0,-4l-2,0l3,-5l0,4l2,0z M24,17.5l0,-2.5l-1,0l2,-3l0,2l1,0z
+      M21.539,0.447L21.539,8.46L25.515,8.46C25.643,8.46 25.761,8.531 25.823,8.646C25.885,8.761 25.881,8.901 25.812,9.011L19.11,19.745C19.026,19.881 18.865,19.943 18.715,19.898C18.564,19.854 18.461,19.713 18.461,19.553L18.461,11.54L14.485,11.54C14.357,11.54 14.239,11.469 14.177,11.354C14.115,11.239 14.119,11.099 14.188,10.989L20.89,0.255C20.974,0.119 21.135,0.057 21.285,0.102C21.436,0.146 21.539,0.287 21.539,0.447L21.539,0.447Z
     
     
-        M25,8.7059l2,0l-2,4.7059l2,0l-5.1429,6.5882l1.1429,-4.7059l-2,0l2,-4.7059l-2,0l5.1429,-6.5882z
-    
+      M21.539,0.447L21.539,8.46L25.515,8.46C25.643,8.46 25.761,8.531 25.823,8.646C25.885,8.761 25.881,8.901 25.812,9.011L19.11,19.745C19.026,19.881 18.865,19.943 18.715,19.898C18.564,19.854 18.461,19.713 18.461,19.553L18.461,11.54L14.485,11.54C14.357,11.54 14.239,11.469 14.177,11.354C14.115,11.239 14.119,11.099 14.188,10.989L20.89,0.255C20.974,0.119 21.135,0.057 21.285,0.102C21.436,0.146 21.539,0.287 21.539,0.447L21.539,0.447Z 
+     
+
+     
+       M19.066,-0.827L12.367,9.901C11.906,10.644 11.878,11.565 12.289,12.327L12.38,12.482C12.829,13.186 13.619,13.627 14.485,13.627L16.326,13.627L16.327,19.553C16.327,20.62 17.033,21.581 18.096,21.896C19.188,22.219 20.351,21.769 20.934,20.827L27.633,10.099C28.094,9.356 28.122,8.435 27.711,7.673L27.62,7.518C27.171,6.814 26.381,6.373 25.515,6.373L23.673,6.372L23.673,0.447C23.673,-0.62 22.967,-1.581 21.904,-1.896C20.812,-2.219 19.649,-1.769 19.066,-0.827ZM21.285,0.102C21.436,0.146 21.539,0.287 21.539,0.447L21.539,8.46L25.515,8.46C25.643,8.46 25.761,8.531 25.823,8.646C25.885,8.761 25.881,8.901 25.812,9.011L19.11,19.745C19.026,19.881 18.865,19.943 18.715,19.898C18.564,19.854 18.461,19.713 18.461,19.553L18.461,11.54L14.485,11.54C14.357,11.54 14.239,11.469 14.177,11.354C14.115,11.239 14.119,11.099 14.188,10.989L20.89,0.255C20.974,0.119 21.135,0.057 21.285,0.102Z
+      
 

加了这些之后主要就是修改一下绘制时候的逻辑和充电图标的显示

diff --git a/src/com/android/systemui/battery/BatteryMeterView.java b/src/com/android/systemui/battery/BatteryMeterView.java
index 263df335..f34940ee 100644
--- a/src/com/android/systemui/battery/BatteryMeterView.java
+++ b/src/com/android/systemui/battery/BatteryMeterView.java
@@ -67,7 +67,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
     public static final int MODE_OFF = 2;
     public static final int MODE_ESTIMATE = 3;
 
-    private final AccessorizedBatteryDrawable mDrawable;
+    private final ThemedBatteryDrawable mDrawable;
     private final ImageView mBatteryIconView;
     private TextView mBatteryPercentView;
 
@@ -108,7 +108,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
         final int frameColor = atts.getColor(R.styleable.BatteryMeterView_frameColor,
                 context.getColor(R.color.meter_background_color));
         mPercentageStyleId = atts.getResourceId(R.styleable.BatteryMeterView_textAppearance, 0);
-        mDrawable = new AccessorizedBatteryDrawable(context, frameColor);
+        mDrawable = new ThemedBatteryDrawable(context, frameColor);
         atts.recycle();
 
         mShowPercentAvailable = context.getResources().getBoolean(
@@ -118,12 +118,6 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
 
         mBatteryIconView = new ImageView(context);
         mBatteryIconView.setImageDrawable(mDrawable);
-        final MarginLayoutParams mlp = new MarginLayoutParams(
-                getResources().getDimensionPixelSize(R.dimen.status_bar_battery_icon_width),
-                getResources().getDimensionPixelSize(R.dimen.status_bar_battery_icon_height));
-        mlp.setMargins(0, 0, 0,
-                getResources().getDimensionPixelOffset(R.dimen.battery_margin_bottom));
-        addView(mBatteryIconView, mlp);
 
         updateShowPercent();
         mDualToneHandler = new DualToneHandler(context);
@@ -179,7 +173,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
     protected void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
         updatePercentView();
-        mDrawable.notifyDensityChanged();
+       // mDrawable.notifyDensityChanged();
     }
 
     public void setColorsFromContext(Context context) {
@@ -349,6 +343,12 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
                 addView(mBatteryPercentView, new LayoutParams(
                         LayoutParams.WRAP_CONTENT,
                         LayoutParams.MATCH_PARENT));
+                        final MarginLayoutParams mlp = new MarginLayoutParams(
+                getResources().getDimensionPixelSize(R.dimen.status_bar_battery_icon_width),
+                getResources().getDimensionPixelSize(R.dimen.status_bar_battery_icon_height));
+                mlp.setMargins(0, 3, 0, 0);
+                addView(mBatteryIconView, mlp);
+
             }
         } else {
             if (showing) {
@@ -416,7 +416,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
             marginTop = shieldHeightAddition
                     - res.getDimensionPixelSize(R.dimen.status_bar_battery_extra_vertical_spacing);
         } else {
-            marginTop = 0;
+            marginTop = 3;
         }
 
         int marginBottom = res.getDimensionPixelSize(R.dimen.battery_margin_bottom);
@@ -426,7 +426,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
                 Math.round(fullBatteryIconHeight));
         scaledLayoutParams.setMargins(0, marginTop, 0, marginBottom);
 
-        mDrawable.setDisplayShield(displayShield);
+       // mDrawable.setDisplayShield(displayShield);
         mBatteryIconView.setLayoutParams(scaledLayoutParams);
         mBatteryIconView.invalidateDrawable(mDrawable);
     }
(END)

这个文件的作用主要是用来让充电图标显示到电量后面,

之后主要用来显示电池图标的是一个新增的类

/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package com.android.systemui.battery

import android.content.Context
import android.graphics.BlendMode
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.Matrix
import android.graphics.Paint
import android.graphics.Path
import android.graphics.PixelFormat
import android.graphics.Rect
import android.graphics.RectF
import android.graphics.drawable.Drawable
import android.util.PathParser
import android.util.TypedValue

import android.util.Log

import com.android.systemui.R
import com.android.settingslib.Utils

/**
 * A battery meter drawable that respects paths configured in
 * frameworks/base/core/res/res/values/config.xml to allow for an easily overrideable battery icon
 */
open class ThemedBatteryDrawable(private val context: Context, frameColor: Int) : Drawable() {

    // Need to load:
    // 1. perimeter shape
    // 2. fill mask (if smaller than perimeter, this would create a fill that
    //    doesn't touch the walls
    private val perimeterPath = Path()
    private val scaledPerimeter = Path()
    private val errorPerimeterPath = Path()
    private val scaledErrorPerimeter = Path()
    // Fill will cover the whole bounding rect of the fillMask, and be masked by the path
    private val fillMask = Path()
    private val scaledFill = Path()
    // Based off of the mask, the fill will interpolate across this space
    private val fillRect = RectF()
    // Top of this rect changes based on level, 100% == fillRect
    private val levelRect = RectF()
    private val levelPath = Path()
    // Updates the transform of the paths when our bounds change
    private val scaleMatrix = Matrix()
    private val padding = Rect()
    // The net result of fill + perimeter paths
    private val unifiedPath = Path()
    
     private val outlinePath = Path()
     private val outlineOverPath = Path()
    // Bolt path (used while charging)
    private val boltPath = Path()
    private val scaledBolt = Path()

    // Plus sign (used for power save mode)
    private val plusPath = Path()
    private val scaledPlus = Path()

    private var intrinsicHeight: Int
    private var intrinsicWidth: Int

    // To implement hysteresis, keep track of the need to invert the interior icon of the battery
    private var invertFillIcon = false

    // Colors can be configured based on battery level (see res/values/arrays.xml)
    private var colorLevels: IntArray

    private var fillColor: Int = Color.MAGENTA
    private var backgroundColor: Int = Color.MAGENTA
    // updated whenever level changes
    private var levelColor: Int = Color.MAGENTA

    // Dual tone implies that battery level is a clipped overlay over top of the whole shape
    private var dualTone = false

    private var batteryLevel = 0
    private var chargingSpeed = -1

    private val invalidateRunnable: () -> Unit = {
        invalidateSelf()
    }

    open var criticalLevel: Int = context.resources.getInteger(
          R.integer.config_criticalBatteryWarningLevel)

    var charging = false
        set(value) {
            field = value
            postInvalidate()
        }

    var powerSaveEnabled = false
        set(value) {
            field = value
            postInvalidate()
        }

    private val fillColorStrokePaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
        p.color = frameColor
        p.alpha = 255
        p.isDither = true
        p.strokeWidth = 5f
        p.style = Paint.Style.STROKE
        p.blendMode = BlendMode.SRC
        p.strokeMiter = 5f
        p.strokeJoin = Paint.Join.ROUND
    }

    private val whiteFillPaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
    p.color = Color.WHITE // 设置填充颜色为白色
    p.alpha = 255 // 设置颜色的透明度为不透明
    p.isDither = true // 启用抖动,可以改善颜色梯度
    p.strokeWidth = 0f // 设置描边宽度为0,因为我们只需要填充
    p.style = Paint.Style.FILL // 设置画笔样式为填充
}

    // 深蓝色填充的Paint对象
    private val blueFillPaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
        p.color = Color.parseColor("#01020B") // 设置填充颜色为深蓝色
        p.alpha = 255 // 设置颜色的透明度为不透明
        p.isDither = true // 启用抖动,可以改善颜色梯度
        p.strokeWidth = 0f // 设置描边宽度为0,因为我们只需要填充
        p.style = Paint.Style.FILL // 设置画笔样式为填充
    }

    private val fillColorStrokeProtection = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
        p.isDither = true
        p.strokeWidth = 5f
        p.style = Paint.Style.STROKE
        p.blendMode = BlendMode.CLEAR
        p.strokeMiter = 5f
        p.strokeJoin = Paint.Join.ROUND
    }

    private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
        p.color = frameColor
        p.alpha = 255
        p.isDither = true
        p.strokeWidth = 0f
        p.style = Paint.Style.FILL_AND_STROKE
    }

    private val errorPaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
        p.color = Utils.getColorStateListDefaultColor(context, R.color.batterymeter_plus_color)
        p.alpha = 255
        p.isDither = true
        p.strokeWidth = 0f
        p.style = Paint.Style.FILL_AND_STROKE
        p.blendMode = BlendMode.SRC
    }

    // Only used if dualTone is set to true
    private val dualToneBackgroundFill = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
        p.color = frameColor
        p.alpha = 85 // ~0.3 alpha by default
        p.isDither = true
        p.strokeWidth = 0f
        p.style = Paint.Style.FILL_AND_STROKE
    }

    init {
        val density = context.resources.displayMetrics.density
        intrinsicHeight = (Companion.HEIGHT * density).toInt()
        intrinsicWidth = (Companion.WIDTH * density).toInt()

        val res = context.resources
        val levels = res.obtainTypedArray(R.array.batterymeter_color_levels)
        val colors = res.obtainTypedArray(R.array.batterymeter_color_values)
        val N = levels.length()
        colorLevels = IntArray(2 * N)
        for (i in 0 until N) {
            colorLevels[2 * i] = levels.getInt(i, 0)
            if (colors.getType(i) == TypedValue.TYPE_ATTRIBUTE) {
                colorLevels[2 * i + 1] = Utils.getColorAttrDefaultColor(context,
                        colors.getThemeAttributeId(i, 0))
            } else {
                colorLevels[2 * i + 1] = colors.getColor(i, 0)
            }
        }
        levels.recycle()
        colors.recycle()

        loadPaths()
    }

    override fun draw(c: Canvas) {
        c.saveLayer(null, null)
        unifiedPath.reset()
        levelPath.reset()
        levelRect.set(fillRect)
        val fillFraction = batteryLevel / 100f
        val fillRight =
                if (batteryLevel >= 95)
                    fillRect.right
                else
                    fillRect.right - (fillRect.width() * (1 - fillFraction))

        levelRect.right = Math.floor(fillRight.toDouble()).toFloat()
        levelPath.addRect(levelRect, Path.Direction.CCW)

        // The perimeter should never change
        unifiedPath.addPath(scaledPerimeter)
        // If drawing dual tone, the level is used only to clip the whole drawable path
        if (!dualTone) {
            unifiedPath.op(levelPath, Path.Op.UNION)
        }

        fillPaint.color = levelColor

        // Deal with unifiedPath clipping before it draws
        if (charging) {
             Log.d("xsr_battrey", "charging"+charging)
            // Clip out the bolt shape
           // unifiedPath.op(scaledBolt, Path.Op.DIFFERENCE)
           // if (!invertFillIcon) {
           //     c.drawPath(scaledBolt, fillPaint)
           // }
        }

        if (dualTone) {
            // Dual tone means we draw the shape again, clipped to the charge level
            c.drawPath(unifiedPath, dualToneBackgroundFill)
            c.save()
            c.clipRect(0f,
                    bounds.bottom - bounds.height() * fillFraction,
                    bounds.right.toFloat(),
                    bounds.bottom.toFloat())
            c.drawPath(unifiedPath, fillPaint)
            c.restore()
        } else {
            // Non dual-tone means we draw the perimeter (with the level fill), and potentially
            // draw the fill again with a critical color
            fillPaint.color = fillColor
            c.drawPath(unifiedPath, fillPaint)
            fillPaint.color = levelColor

            // Show colorError below this level
            if (batteryLevel <= Companion.CRITICAL_LEVEL && !charging) {
                c.save()
                c.clipPath(scaledFill)
                c.drawPath(levelPath, fillPaint)
                c.restore()
            }
        }

        if (charging) {
                //fillColorStrokePaint.color = Color.parseColor("#18C378")
                //
                   // c.clipOutPath(scaledBolt)
                 fillPaint.color = Color.parseColor("#18C378")
                c.drawPath(levelPath, fillPaint)
                c.save()
                blueFillPaint.color = Color.parseColor("#01020B")
               c.drawPath(outlineOverPath, blueFillPaint)
              
               c.drawPath(scaledBolt, whiteFillPaint )
               c.clipOutPath(scaledBolt)
                c.restore()
            
        
        } else if (powerSaveEnabled) {
            // If power save is enabled draw the perimeter path with colorError
            c.drawPath(scaledErrorPerimeter, errorPaint)
            // And draw the plus sign on top of the fill
            c.drawPath(scaledPlus, errorPaint)
        }
        c.restore()
    }

    private fun batteryColorForLevel(level: Int): Int {
         Log.d("xsr_battrey", "Determining color for battery level: $level")
        return when {
            charging || powerSaveEnabled -> Color.parseColor("#18C378")
            else -> getColorForLevel(level)
        }
    }

    private fun getColorForLevel(level: Int): Int {
        var thresh: Int
        var color = 0
        var i = 0
        while (i < colorLevels.size) {
            thresh = colorLevels[i]
            color = colorLevels[i + 1]
            if (level <= thresh) {

                // Respect tinting for "normal" level
                return if (i == colorLevels.size - 2) {
                    fillColor
                } else {
                    color
                }
            }
            i += 2
        }
          Log.d("xsr_battrey", "color "+color)
        return color
    }

    /**
     * Alpha is unused internally, and should be defined in the colors passed to {@link setColors}.
     * Further, setting an alpha for a dual tone battery meter doesn't make sense without bounds
     * defining the minimum background fill alpha. This is because fill + background must be equal
     * to the net alpha passed in here.
     */
    override fun setAlpha(alpha: Int) {
    }

    override fun setColorFilter(colorFilter: ColorFilter?) {
        fillPaint.colorFilter = colorFilter
        fillColorStrokePaint.colorFilter = colorFilter
        dualToneBackgroundFill.colorFilter = colorFilter
    }

    /**
     * Deprecated, but required by Drawable
     */
    override fun getOpacity(): Int {
        return PixelFormat.OPAQUE
    }

    override fun getIntrinsicHeight(): Int {
        return intrinsicHeight
    }

    override fun getIntrinsicWidth(): Int {
        return intrinsicWidth
    }

    /**
     * Set the fill level
     */
    public open fun setBatteryLevel(l: Int) {
        invertFillIcon = if (l >= 67) true else if (l <= 33) false else invertFillIcon
        batteryLevel = l
        levelColor = batteryColorForLevel(batteryLevel)
        invalidateSelf()
    }

    /**
     * Set the charging speed
     */
    /* UNISOC: Modify for bug 1838475 @{ */
    private fun LoadChargingBoltPath() {
        boltPath.reset()
        val boltPathString = when (chargingSpeed) {
            1 -> context.resources.getString(R.string.config_batterymeterRegularBoltPath)
            2 -> context.resources.getString(R.string.config_batterymeterFastBoltPath)
            else -> context.resources.getString(R.string.config_batterymeterSlowBoltPath)
        }
        boltPath.set(PathParser.createPathFromPathData(boltPathString))
    }

    public open fun setChargingSpeed(l: Int) {
        chargingSpeed = l
        LoadChargingBoltPath()
        boltPath.transform(scaleMatrix, scaledBolt) 
        outlinePath.transform(scaleMatrix, outlineOverPath)
    }
    /* @} */

    public fun getBatteryLevel(): Int {
        return batteryLevel
    }

    override fun onBoundsChange(bounds: Rect?) {
        super.onBoundsChange(bounds)
        updateSize()
    }

    fun setPadding(left: Int, top: Int, right: Int, bottom: Int) {
        padding.left = left
        padding.top = top
        padding.right = right
        padding.bottom = bottom

        updateSize()
    }

    fun setColors(fgColor: Int, bgColor: Int, singleToneColor: Int) {
        fillColor = if (dualTone) fgColor else singleToneColor

        fillPaint.color = fillColor
        fillColorStrokePaint.color = fillColor

        backgroundColor = bgColor
        dualToneBackgroundFill.color = bgColor

        // Also update the level color, since fillColor may have changed
        levelColor = batteryColorForLevel(batteryLevel)

        invalidateSelf()
    }

    private fun postInvalidate() {
        unscheduleSelf(invalidateRunnable)
        scheduleSelf(invalidateRunnable, 0)
    }

    private fun updateSize() {
        val b = bounds
        if (b.isEmpty) {
            scaleMatrix.setScale(1f, 1f)
        } else {
            scaleMatrix.setScale((b.right / WIDTH), (b.bottom / HEIGHT))
        }

        perimeterPath.transform(scaleMatrix, scaledPerimeter)
        errorPerimeterPath.transform(scaleMatrix, scaledErrorPerimeter)
        fillMask.transform(scaleMatrix, scaledFill)
        scaledFill.computeBounds(fillRect, true)
        boltPath.transform(scaleMatrix, scaledBolt)
        outlinePath.transform(scaleMatrix, outlineOverPath)
        plusPath.transform(scaleMatrix, scaledPlus)

        // It is expected that this view only ever scale by the same factor in each dimension, so
        // just pick one to scale the strokeWidths
        val scaledStrokeWidth =
                Math.max(b.right / WIDTH * PROTECTION_STROKE_WIDTH, PROTECTION_MIN_STROKE_WIDTH)

        fillColorStrokePaint.strokeWidth = scaledStrokeWidth
        fillColorStrokeProtection.strokeWidth = scaledStrokeWidth
    }

    private fun loadPaths() {
        val pathString = context.resources.getString(
                R.string.config_batterymeterPerimeterPath)
        perimeterPath.set(PathParser.createPathFromPathData(pathString))
        perimeterPath.computeBounds(RectF(), true)
     
             val outLineString = context.resources.getString(
                R.string.config_batteryOutLinePath)
        outlinePath.set(PathParser.createPathFromPathData(outLineString))
        outlinePath.computeBounds(RectF(), true)

        val errorPathString = context.resources.getString(
               R.string.config_batterymeterErrorPerimeterPath)
        errorPerimeterPath.set(PathParser.createPathFromPathData(errorPathString))
        errorPerimeterPath.computeBounds(RectF(), true)

        val fillMaskString = context.resources.getString(
                R.string.config_batterymeterFillMask)
        fillMask.set(PathParser.createPathFromPathData(fillMaskString))
        // Set the fill rect so we can calculate the fill properly
        fillMask.computeBounds(fillRect, true)

        LoadChargingBoltPath() //UNISOC: Modify for bug 1838475

        val plusPathString = context.resources.getString(
               R.string.config_batterymeterPowersavePath)
        plusPath.set(PathParser.createPathFromPathData(plusPathString))

        dualTone = context.resources.getBoolean(
               R.bool.config_batterymeterDualTone)
    }

    companion object {
        private const val TAG = "ThemedBatteryDrawable"
        private const val WIDTH = 53f
        private const val HEIGHT = 24f
        private const val CRITICAL_LEVEL = 15
        // On a 12x20 grid, how wide to make the fill protection stroke.
        // Scales when our size changes
        private const val PROTECTION_STROKE_WIDTH = 3f
        // Arbitrarily chosen for visibility at small sizes
        private const val PROTECTION_MIN_STROKE_WIDTH = 6f
    }
}

你可能感兴趣的:(elasticsearch,大数据,搜索引擎)