Skip to content

Commit

Permalink
[ProgressIndicator] Updated the default value of wavelength and sette…
Browse files Browse the repository at this point in the history
…rs of wavelength and amplitude.

PiperOrigin-RevId: 617998236
  • Loading branch information
pekingme authored and paulfthomas committed Mar 25, 2024
1 parent 000ccae commit e2cc0bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.android.material.R;

import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap;
import static java.lang.Math.abs;
import static java.lang.Math.min;

import android.content.Context;
Expand Down Expand Up @@ -82,6 +83,7 @@ public abstract class BaseProgressIndicator<S extends BaseProgressIndicatorSpec>

static final float DEFAULT_OPACITY = 0.2f;
static final int MAX_ALPHA = 255;

/**
* The maximum time, in milliseconds, that the requested hide action is allowed to wait once
* {@link #show()} is called.
Expand All @@ -93,6 +95,7 @@ public abstract class BaseProgressIndicator<S extends BaseProgressIndicatorSpec>

/** A temp place to hold new progress while switching from indeterminate to determinate mode. */
private int storedProgress;

/**
* A temp place to hold whether use animator to update the new progress after switching from
* indeterminate to determinate mode.
Expand Down Expand Up @@ -236,7 +239,7 @@ public void hide() {
delayedHide.run();
return;
}
postDelayed(delayedHide, /*delayMillis=*/ minHideDelay - timeElapsedSinceShowStart);
postDelayed(delayedHide, /* delayMillis= */ minHideDelay - timeElapsedSinceShowStart);
}

/**
Expand All @@ -248,7 +251,7 @@ public void hide() {
*/
private void internalHide() {
((DrawableWithAnimatedVisibilityChange) getCurrentDrawable())
.setVisible(/*visible=*/ false, /*restart=*/ false, /*animate=*/ true);
.setVisible(/* visible= */ false, /* restart= */ false, /* animate= */ true);

if (isNoLongerNeedToBeVisible()) {
setVisibility(INVISIBLE);
Expand All @@ -258,13 +261,13 @@ private void internalHide() {
@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
applyNewVisibility(/*animate=*/ visibility == VISIBLE);
applyNewVisibility(/* animate= */ visibility == VISIBLE);
}

@Override
protected void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility);
applyNewVisibility(/*animate=*/ false);
applyNewVisibility(/* animate= */ false);
}

/**
Expand All @@ -279,7 +282,7 @@ protected void applyNewVisibility(boolean animate) {
}

((DrawableWithAnimatedVisibilityChange) getCurrentDrawable())
.setVisible(visibleToUser(), /*restart=*/ false, animate);
.setVisible(visibleToUser(), /* restart= */ false, animate);
}

@Override
Expand Down Expand Up @@ -521,7 +524,7 @@ public synchronized void setIndeterminate(boolean indeterminate) {
DrawableWithAnimatedVisibilityChange newDrawable =
(DrawableWithAnimatedVisibilityChange) getCurrentDrawable();
if (newDrawable != null) {
newDrawable.setVisible(visibleToUser(), /*restart=*/ false, /*animate=*/ false);
newDrawable.setVisible(visibleToUser(), /* restart= */ false, /* animate= */ false);
}
if (newDrawable instanceof IndeterminateDrawable && visibleToUser()) {
((IndeterminateDrawable) newDrawable).getAnimatorDelegate().startAnimator();
Expand Down Expand Up @@ -690,7 +693,7 @@ public int getAmplitude() {
*/
public void setAmplitude(@Px int amplitude) {
if (spec.amplitude != amplitude) {
spec.amplitude = amplitude;
spec.amplitude = abs(amplitude);
requestLayout();
}
}
Expand All @@ -708,15 +711,13 @@ public int getWavelength() {
/**
* Sets the wavelength of the indicator's waveform in pixels.
*
* @param wavelength The new wavelength in pixels. No-op, if it equals to 0.
* @param wavelength The new wavelength in pixels. No waves are drawn, if it equals to 0 with a
* non-zero amplitude.
* @see #getWavelength()
*/
public void setWavelength(@Px int wavelength) {
if (wavelength == 0) {
throw new IllegalArgumentException("Cannot set 0 wavelength.");
}
if (spec.wavelength != wavelength) {
spec.wavelength = wavelength;
spec.wavelength = abs(wavelength);
requestLayout();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import static com.google.android.material.resources.MaterialResources.getDimensionPixelSize;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;

import android.content.Context;
Expand Down Expand Up @@ -115,14 +114,10 @@ protected BaseProgressIndicatorSpec(
a.getInt(
R.styleable.BaseProgressIndicator_hideAnimationBehavior,
BaseProgressIndicator.HIDE_NONE);
indicatorTrackGapSize = a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_indicatorTrackGapSize, 0);

wavelength =
max(
abs(
a.getDimensionPixelSize(
R.styleable.BaseProgressIndicator_wavelength, Integer.MAX_VALUE)),
1);
indicatorTrackGapSize =
a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_indicatorTrackGapSize, 0);

wavelength = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_wavelength, 0));
amplitude = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_amplitude, 0));

loadIndicatorColors(context, a);
Expand Down Expand Up @@ -200,7 +195,7 @@ public boolean isHideAnimationEnabled() {
}

public boolean hasWavyEffect() {
return amplitude > 0 && wavelength < Integer.MAX_VALUE;
return amplitude > 0 && wavelength > 0;
}

@CallSuper
Expand Down

0 comments on commit e2cc0bb

Please sign in to comment.