[Dock Defend] Cache the density in the drawable so we don't re-fetch it
constantly. Bug: 255625888 Test: verified density got updated each time display size changed Change-Id: I8cbb9ffe0e3ef18dc43fe13749b7584eb83640e1
This commit is contained in:
@@ -57,6 +57,8 @@ class AccessorizedBatteryDrawable(
|
||||
private var shieldLeftOffsetScaled = SHIELD_LEFT_OFFSET
|
||||
private var shieldTopOffsetScaled = SHIELD_TOP_OFFSET
|
||||
|
||||
private var density = context.resources.displayMetrics.density
|
||||
|
||||
private val dualTone =
|
||||
context.resources.getBoolean(com.android.internal.R.bool.config_batterymeterDualTone)
|
||||
|
||||
@@ -126,8 +128,7 @@ class AccessorizedBatteryDrawable(
|
||||
} else {
|
||||
BATTERY_HEIGHT
|
||||
}
|
||||
// TODO(b/255625888): Cache the density so we don't have to re-fetch.
|
||||
return (height * context.resources.displayMetrics.density).toInt()
|
||||
return (height * density).toInt()
|
||||
}
|
||||
|
||||
override fun getIntrinsicWidth(): Int {
|
||||
@@ -137,8 +138,7 @@ class AccessorizedBatteryDrawable(
|
||||
} else {
|
||||
BATTERY_WIDTH
|
||||
}
|
||||
// TODO(b/255625888): Cache the density so we don't have to re-fetch.
|
||||
return (width * context.resources.displayMetrics.density).toInt()
|
||||
return (width * density).toInt()
|
||||
}
|
||||
|
||||
override fun draw(c: Canvas) {
|
||||
@@ -195,6 +195,11 @@ class AccessorizedBatteryDrawable(
|
||||
mainBatteryDrawable.setColors(fgColor, bgColor, singleToneColor)
|
||||
}
|
||||
|
||||
/** Notifies this drawable that the density might have changed. */
|
||||
fun notifyDensityChanged() {
|
||||
density = context.resources.displayMetrics.density
|
||||
}
|
||||
|
||||
private fun loadPaths() {
|
||||
val shieldPathString = context.resources.getString(R.string.config_batterymeterShieldPath)
|
||||
shieldPath.set(PathParser.createPathFromPathData(shieldPathString))
|
||||
|
||||
@@ -179,6 +179,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
|
||||
protected void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
updatePercentView();
|
||||
mDrawable.notifyDensityChanged();
|
||||
}
|
||||
|
||||
public void setColorsFromContext(Context context) {
|
||||
|
||||
Reference in New Issue
Block a user