From 155ca56d51ca912da0657e0dd05fef60ad109b7b Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Sun, 29 Sep 2024 10:43:19 +0200 Subject: [PATCH 1/3] BatteryBarView: endX always width/2 when center --- .../pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java b/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java index d484cd50..487d65e0 100644 --- a/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java +++ b/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java @@ -168,7 +168,7 @@ private void animateChargingIndicator() { startX = screenWidth; endX = Math.round(getWidth() * getCurrentLevel() / 100f); } - if (isCenterBased) endX = getWidth() / 2f + chargingIndicatorView.getWidth() / 2f; + if (isCenterBased) endX = getWidth() / 2f; TranslateAnimation animation = new TranslateAnimation(startX, endX, 0, 0); animation.setDuration(ANIM_DURATION); From b8d7c476ebe26622e9a0c4a07fbfeac2dacf0413 Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Sun, 29 Sep 2024 11:18:13 +0200 Subject: [PATCH 2/3] BatteryBarView: RTL Gravity END --- .../modpacks/utils/batteryStyles/BatteryBarView.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java b/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java index 487d65e0..1b3d3244 100644 --- a/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java +++ b/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java @@ -230,8 +230,7 @@ private LayoutParams charginLayoutParams() { int pixels = (int) (metrics.density * dp + 0.5f); LayoutParams result = new LayoutParams(pixels, barHeight); - result.gravity = (RTL) ? Gravity.CENTER : Gravity.START; - + result.gravity = (RTL) ? Gravity.END : Gravity.START; result.gravity |= (onTop) ? Gravity.TOP : Gravity.BOTTOM; return result; From 725b1567f5a909b0d0ee3cdaaa32ac718257c25d Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Sun, 29 Sep 2024 11:35:25 +0200 Subject: [PATCH 3/3] BatteryBarView: Animate both edges when center based --- .../utils/batteryStyles/BatteryBarView.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java b/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java index 1b3d3244..7171080e 100644 --- a/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java +++ b/app/src/main/java/sh/siava/pixelxpert/modpacks/utils/batteryStyles/BatteryBarView.java @@ -40,6 +40,7 @@ public class BatteryBarView extends FrameLayout { private final ShapeDrawable mDrawable = new ShapeDrawable(); FrameLayout maskLayout; private final ImageView chargingIndicatorView; + private final ImageView chargingIndicatorViewForCenter; private boolean colorful = false; private int alphaPct = 100; private int singleColorTone = Color.WHITE; @@ -106,6 +107,7 @@ public void refreshLayout() { maskLayout.setLayoutParams(maskLayoutParams()); barView.setLayoutParams(barLayoutParams()); chargingIndicatorView.setLayoutParams(charginLayoutParams()); + chargingIndicatorViewForCenter.setLayoutParams(charginLayoutParams()); refreshColors(barView.getWidth(), barView.getHeight()); mDrawable.invalidateSelf(); @@ -152,20 +154,27 @@ private void stopChargingAnimation() { if (chargingAnimationRunnable != null) { animationHandler.removeCallbacks(chargingAnimationRunnable); chargingIndicatorView.post(() -> chargingIndicatorView.setVisibility(GONE)); + chargingIndicatorViewForCenter.post(() -> chargingIndicatorViewForCenter.setVisibility(GONE)); chargingAnimationRunnable = null; } } private void animateChargingIndicator() { - chargingIndicatorView.post(() -> chargingIndicatorView.setVisibility(VISIBLE)); int screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels; - float startX, endX; + + chargingIndicatorView.post(() -> chargingIndicatorView.setVisibility(VISIBLE)); + int secondaryVisiblity = (isCenterBased) ? GONE : VISIBLE; + chargingIndicatorViewForCenter.post(() -> chargingIndicatorViewForCenter.setVisibility(secondaryVisiblity)); + + float startX, startXCenter, endX; if (RTL) { startX = 0; + startXCenter = getWidth(); endX = getWidth() - Math.round(getWidth() * getCurrentLevel() / 100f); } else { startX = screenWidth; + startXCenter = 0; endX = Math.round(getWidth() * getCurrentLevel() / 100f); } if (isCenterBased) endX = getWidth() / 2f; @@ -174,6 +183,13 @@ private void animateChargingIndicator() { animation.setDuration(ANIM_DURATION); animation.setInterpolator(new LinearInterpolator()); chargingIndicatorView.startAnimation(animation); + + if (isCenterBased) { + TranslateAnimation animationCenter = new TranslateAnimation(startXCenter, endX, 0, 0); + animationCenter.setDuration(ANIM_DURATION); + animationCenter.setInterpolator(new LinearInterpolator()); + chargingIndicatorViewForCenter.startAnimation(animationCenter); + } } public BatteryBarView(Context context) { @@ -192,12 +208,17 @@ public BatteryBarView(Context context) { chargingIndicatorView.setLayoutParams(new LayoutParams(20, barHeight)); chargingIndicatorView.setBackgroundColor(singleColorTone); + chargingIndicatorViewForCenter = new ImageView(context); + chargingIndicatorViewForCenter.setLayoutParams(new LayoutParams(20, barHeight)); + chargingIndicatorViewForCenter.setBackgroundColor(singleColorTone); + maskLayout = new FrameLayout(context); maskLayout.addView(barView); maskLayout.setClipChildren(true); this.addView(maskLayout); this.addView(chargingIndicatorView); + this.addView(chargingIndicatorViewForCenter); this.setClipChildren(true); RTL = (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL); @@ -261,10 +282,12 @@ public void refreshColors(int lenX, int lenY) { if (isFastCharging() && indicateFastCharging) //fast charging color { chargingIndicatorView.setBackgroundColor(fastChargingColor); + chargingIndicatorViewForCenter.setBackgroundColor(fastChargingColor); mPaint.setColor(fastChargingColor); } else if (isCharging() && indicateCharging) //normal charging color { chargingIndicatorView.setBackgroundColor(chargingColor); + chargingIndicatorViewForCenter.setBackgroundColor(chargingColor); mPaint.setColor(chargingColor); } else if (isPowerSaving() && indicatePowerSave) //power saving color {