Skip to content

Commit

Permalink
CHANGELOG: Battery bar: fixed charging animation opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
siavash79 committed Oct 10, 2024
1 parent 1f61981 commit c79bf4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/edit2MakeNewCanary
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Editing this file will trigger the build script for a new canary..
Editing this file will trigger the build script for a new canary.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ private void animateChargingIndicator() {
public BatteryBarView(Context context) {
super(context);
instance = this;

chargingIndicatorView = new ImageView(context);
chargingIndicatorViewForCenter = new ImageView(context);
initChargingAnimationView();

this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

mDrawable.setShape(new RectShape());
Expand All @@ -203,16 +208,6 @@ public BatteryBarView(Context context) {
barView = new ImageView(context);
barView.setImageDrawable(mDrawable);

chargingIndicatorView = new ImageView(context);
chargingIndicatorView.setLayoutParams(new LayoutParams(20, barHeight));
chargingIndicatorView.setBackgroundColor(singleColorTone);
chargingIndicatorView.setAlpha(alphaPct / 100f);

chargingIndicatorViewForCenter = new ImageView(context);
chargingIndicatorViewForCenter.setLayoutParams(new LayoutParams(20, barHeight));
chargingIndicatorViewForCenter.setBackgroundColor(singleColorTone);
chargingIndicatorViewForCenter.setAlpha(alphaPct / 100f);

maskLayout = new FrameLayout(context);
maskLayout.addView(barView);
maskLayout.setClipChildren(true);
Expand All @@ -231,6 +226,17 @@ public BatteryBarView(Context context) {
BatteryBarView instance = this;
BatteryDataProvider.registerInfoCallback(() -> instance.post(instance::refreshLayout));
}

private void initChargingAnimationView() {
ViewGroup.LayoutParams lp = new LayoutParams(20, barHeight);

chargingIndicatorView.setLayoutParams(lp);
chargingIndicatorViewForCenter.setLayoutParams(lp);

chargingIndicatorView.setBackgroundColor(singleColorTone);
chargingIndicatorViewForCenter.setBackgroundColor(singleColorTone);
}

@Override
public void setLayoutDirection(int direction) {
super.setLayoutDirection(direction);
Expand Down Expand Up @@ -346,8 +352,9 @@ private static void refreshShadeColors() {
public void setAlphaPct(int alphaPct) {
this.alphaPct = alphaPct;
mDrawable.setAlpha(Math.round(alphaPct * 2.55f));
if (chargingIndicatorView != null) chargingIndicatorView.setAlpha(alphaPct / 100f);
if (chargingIndicatorViewForCenter != null) chargingIndicatorViewForCenter.setAlpha(alphaPct / 100f);

chargingIndicatorView.setAlpha(alphaPct / 100f);
chargingIndicatorViewForCenter.setAlpha(alphaPct / 100f);

}

Expand Down

0 comments on commit c79bf4e

Please sign in to comment.