Skip to content

Commit

Permalink
[ProgressIndicator] Renamed indeterminateAnimationType enums "seamles…
Browse files Browse the repository at this point in the history
…s" and "spacing".

PiperOrigin-RevId: 345467359
(cherry picked from commit e5375fc)
  • Loading branch information
pekingme authored and dsn5ft committed Dec 15, 2020
1 parent d568e55 commit 77cf940
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_right_to_left_linear_multiple_colors_anchored_bottom_seamless_animation"/>
android:text="@string/cat_progress_indicator_right_to_left_linear_multiple_colors_anchored_bottom_contiguous_animation"/>
<com.google.android.material.progressindicator.LinearProgressIndicator
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
app:indicatorColor="@array/cat_custom_progress_colors"
app:indeterminateAnimationType="seamless"
app:indeterminateAnimationType="contiguous"
app:indicatorDirectionLinear="rightToLeft"
app:showAnimationBehavior="outward"
app:hideAnimationBehavior="inward"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@
description="A right-to-left linear progress indicator anchoring at the bottom edge with multiple colors [CHAR LIMIT=NONE]">
Multiple color right-to-left linear, anchoring at the bottom edge
</string>
<string name="cat_progress_indicator_right_to_left_linear_multiple_colors_anchored_bottom_seamless_animation"
description="A right-to-left linear progress indicator anchoring at the bottom edge with multiple colors and seamless animation [CHAR LIMIT=NONE]">
Multiple color right-to-left linear with seamless animation, anchoring at the bottom edge
<string name="cat_progress_indicator_right_to_left_linear_multiple_colors_anchored_bottom_contiguous_animation"
description="A right-to-left linear progress indicator anchoring at the bottom edge with multiple colors and contiguous animation [CHAR LIMIT=NONE]">
Multiple color right-to-left linear with contiguous animation, anchoring at the bottom edge
</string>

<string name="cat_progress_indicator_clockwise_circular_single_color"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static IndeterminateDrawable<LinearProgressIndicatorSpec> createLinearDra
/*baseSpec=*/ spec,
new LinearDrawingDelegate(spec),
spec.indeterminateAnimationType
== LinearProgressIndicator.INDETERMINATE_ANIMATION_TYPE_SEAMLESS
? new LinearIndeterminateSeamlessAnimatorDelegate(spec)
: new LinearIndeterminateSpacingAnimatorDelegate(context, spec));
== LinearProgressIndicator.INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS
? new LinearIndeterminateContiguousAnimatorDelegate(spec)
: new LinearIndeterminateDisjointAnimatorDelegate(context, spec));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import com.google.android.material.math.MathUtils;

/**
* This is the implementation class for drawing progress indicator in the linear seamless
* This is the implementation class for drawing progress indicator in the linear contiguous
* indeterminate mode.
*/
final class LinearIndeterminateSeamlessAnimatorDelegate
final class LinearIndeterminateContiguousAnimatorDelegate
extends IndeterminateAnimatorDelegate<AnimatorSet> {

// Constants for animation timing.
Expand All @@ -44,15 +44,15 @@ final class LinearIndeterminateSeamlessAnimatorDelegate
// The general spec.
private final BaseProgressIndicatorSpec baseSpec;

// The animator controls seamless linear indeterminate animation.
// The animator controls contiguous linear indeterminate animation.
private AnimatorSet animatorSet;

// Internal parameters controlled by the animator.
private int referenceSegmentColorIndex;
private float lineConnectPoint1Fraction;
private float lineConnectPoint2Fraction;

public LinearIndeterminateSeamlessAnimatorDelegate(@NonNull LinearProgressIndicatorSpec spec) {
public LinearIndeterminateContiguousAnimatorDelegate(@NonNull LinearProgressIndicatorSpec spec) {
super(/*segmentCount=*/ 3);

baseSpec = spec;
Expand Down Expand Up @@ -126,7 +126,7 @@ public void resetPropertiesForNewStart() {

@Override
public void resetPropertiesForNextCycle() {
// In seamless mode, there's no concept of cycle. This is left as blank in purpose.
// In contiguous type, there's no concept of cycle. This is left as blank in purpose.
}

@Override
Expand All @@ -138,7 +138,7 @@ public void cancelAnimatorImmediately() {

@Override
public void requestCancelAnimatorAfterCurrentCycle() {
// In seamless mode, there's no concept of cycle. This is left as blank in purpose.
// In contiguous type, there's no concept of cycle. This is left as blank in purpose.
}

@Override
Expand All @@ -148,12 +148,12 @@ public void invalidateSpecValues() {

@Override
public void registerAnimatorsCompleteCallback(@Nullable AnimationCallback callback) {
// In seamless mode, indeterminate mode cannot be switched. This is left as blank in purpose.
// In contiguous type, indeterminate mode cannot be switched. This is left as blank in purpose.
}

@Override
public void unregisterAnimatorsCompleteCallback() {
// In seamless mode, indeterminate mode cannot be switched. This is left as blank in purpose.
// In contiguous type, indeterminate mode cannot be switched. This is left as blank in purpose.
}

// ******************* Helper methods *******************
Expand Down Expand Up @@ -229,45 +229,45 @@ void setLineConnectPoint2Fraction(float lineConnectPoint2Fraction) {
// ******************* Properties *******************

/**
* The property controlled by the main animator for seamless mode. It indicates the ratio to the
* The property controlled by the main animator in contiguous type. It indicates the ratio to the
* total track width of the distance between the left (right when inverse) end of the track and
* the connecting position of one side line and the central line.
*
* @see #LINE_CONNECT_POINT_2_FRACTION
*/
private static final Property<LinearIndeterminateSeamlessAnimatorDelegate, Float>
private static final Property<LinearIndeterminateContiguousAnimatorDelegate, Float>
LINE_CONNECT_POINT_1_FRACTION =
new Property<LinearIndeterminateSeamlessAnimatorDelegate, Float>(
new Property<LinearIndeterminateContiguousAnimatorDelegate, Float>(
Float.class, "lineConnectPoint1Fraction") {
@Override
public Float get(LinearIndeterminateSeamlessAnimatorDelegate drawable) {
public Float get(LinearIndeterminateContiguousAnimatorDelegate drawable) {
return drawable.getLineConnectPoint1Fraction();
}

@Override
public void set(LinearIndeterminateSeamlessAnimatorDelegate drawable, Float value) {
public void set(LinearIndeterminateContiguousAnimatorDelegate drawable, Float value) {
drawable.setLineConnectPoint1Fraction(value);
}
};

/**
* The property controlled by the main animator for seamless mode. It indicates the ratio to the
* The property controlled by the main animator in contiguous type. It indicates the ratio to the
* total track width of the distance between the left (right when inverse) end of the track and
* the connecting position of the other side line to the central line.
*
* @see #LINE_CONNECT_POINT_1_FRACTION
*/
private static final Property<LinearIndeterminateSeamlessAnimatorDelegate, Float>
private static final Property<LinearIndeterminateContiguousAnimatorDelegate, Float>
LINE_CONNECT_POINT_2_FRACTION =
new Property<LinearIndeterminateSeamlessAnimatorDelegate, Float>(
new Property<LinearIndeterminateContiguousAnimatorDelegate, Float>(
Float.class, "lineConnectPoint2Fraction") {
@Override
public Float get(LinearIndeterminateSeamlessAnimatorDelegate drawable) {
public Float get(LinearIndeterminateContiguousAnimatorDelegate drawable) {
return drawable.getLineConnectPoint2Fraction();
}

@Override
public void set(LinearIndeterminateSeamlessAnimatorDelegate drawable, Float value) {
public void set(LinearIndeterminateContiguousAnimatorDelegate drawable, Float value) {
drawable.setLineConnectPoint2Fraction(value);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import java.util.Arrays;

/**
* This is the implementation class for drawing progress indicator in the linear non-seamless
* This is the implementation class for drawing progress indicator in the linear disjoint
* indeterminate mode.
*/
final class LinearIndeterminateSpacingAnimatorDelegate
final class LinearIndeterminateDisjointAnimatorDelegate
extends IndeterminateAnimatorDelegate<AnimatorSet> {

// Constants for animation timing.
Expand All @@ -52,7 +52,7 @@ final class LinearIndeterminateSpacingAnimatorDelegate
// The base spec.
private final BaseProgressIndicatorSpec baseSpec;

// The animator controls non-seamless linear indeterminate animation.
// The animator controls disjoint linear indeterminate animation.
private AnimatorSet animatorSet;

// Internal parameters controlled by the animator.
Expand All @@ -66,7 +66,7 @@ final class LinearIndeterminateSpacingAnimatorDelegate
boolean animatorCompleteEndRequested = false;
AnimationCallback animatorCompleteCallback = null;

public LinearIndeterminateSpacingAnimatorDelegate(
public LinearIndeterminateDisjointAnimatorDelegate(
@NonNull Context context, @NonNull LinearProgressIndicatorSpec spec) {
super(/*segmentCount=*/ 2);

Expand Down Expand Up @@ -261,81 +261,81 @@ void setLine2TailFraction(float line2TailFraction) {
// ******************* Properties *******************

/**
* The property controlled by the main animator for non seamless mode. It indicates the ratio to
* the total track width of the distance between the left (right when inverse) end of the track
* and the right (left) end of the first line.
* The property controlled by the main animator in disjoint type. It indicates the ratio to the
* total track width of the distance between the left (right when inverse) end of the track and
* the right (left) end of the first line.
*/
private static final Property<LinearIndeterminateSpacingAnimatorDelegate, Float>
private static final Property<LinearIndeterminateDisjointAnimatorDelegate, Float>
LINE_1_HEAD_FRACTION =
new Property<LinearIndeterminateSpacingAnimatorDelegate, Float>(
new Property<LinearIndeterminateDisjointAnimatorDelegate, Float>(
Float.class, "line1HeadFraction") {
@Override
public Float get(LinearIndeterminateSpacingAnimatorDelegate drawable) {
public Float get(LinearIndeterminateDisjointAnimatorDelegate drawable) {
return drawable.getLine1HeadFraction();
}

@Override
public void set(LinearIndeterminateSpacingAnimatorDelegate drawable, Float value) {
public void set(LinearIndeterminateDisjointAnimatorDelegate drawable, Float value) {
drawable.setLine1HeadFraction(value);
}
};

/**
* The property controlled by the main animator for non seamless mode. It indicates the ratio to
* the total track width of the distance between the left (right when inverse) end of the track
* and the left (right) end of the first line.
* The property controlled by the main animator in disjoint type. It indicates the ratio to the
* total track width of the distance between the left (right when inverse) end of the track and
* the left (right) end of the first line.
*/
private static final Property<LinearIndeterminateSpacingAnimatorDelegate, Float>
private static final Property<LinearIndeterminateDisjointAnimatorDelegate, Float>
LINE_1_TAIL_FRACTION =
new Property<LinearIndeterminateSpacingAnimatorDelegate, Float>(
new Property<LinearIndeterminateDisjointAnimatorDelegate, Float>(
Float.class, "line1TailFraction") {
@Override
public Float get(LinearIndeterminateSpacingAnimatorDelegate drawable) {
public Float get(LinearIndeterminateDisjointAnimatorDelegate drawable) {
return drawable.getLine1TailFraction();
}

@Override
public void set(LinearIndeterminateSpacingAnimatorDelegate drawable, Float value) {
public void set(LinearIndeterminateDisjointAnimatorDelegate drawable, Float value) {
drawable.setLine1TailFraction(value);
}
};

/**
* The property controlled by the main animator for non seamless mode. It indicates the ratio to
* the total track width of the distance between the left (right when inverse) end of the track
* and the right (left) end of the second line.
* The property controlled by the main animator in disjoint type. It indicates the ratio to the
* total track width of the distance between the left (right when inverse) end of the track and
* the right (left) end of the second line.
*/
private static final Property<LinearIndeterminateSpacingAnimatorDelegate, Float>
private static final Property<LinearIndeterminateDisjointAnimatorDelegate, Float>
LINE_2_HEAD_FRACTION =
new Property<LinearIndeterminateSpacingAnimatorDelegate, Float>(
new Property<LinearIndeterminateDisjointAnimatorDelegate, Float>(
Float.class, "line2HeadFraction") {
@Override
public Float get(LinearIndeterminateSpacingAnimatorDelegate drawable) {
public Float get(LinearIndeterminateDisjointAnimatorDelegate drawable) {
return drawable.getLine2HeadFraction();
}

@Override
public void set(LinearIndeterminateSpacingAnimatorDelegate drawable, Float value) {
public void set(LinearIndeterminateDisjointAnimatorDelegate drawable, Float value) {
drawable.setLine2HeadFraction(value);
}
};

/**
* The property controlled by the main animator for non seamless mode. It indicates the ratio to
* the total track width of the distance between the left (right when inverse) end of the track
* and the left (right) end of the second line.
* The property controlled by the main animator in disjoint type. It indicates the ratio to the
* total track width of the distance between the left (right when inverse) end of the track and
* the left (right) end of the second line.
*/
private static final Property<LinearIndeterminateSpacingAnimatorDelegate, Float>
private static final Property<LinearIndeterminateDisjointAnimatorDelegate, Float>
LINE_2_TAIL_FRACTION =
new Property<LinearIndeterminateSpacingAnimatorDelegate, Float>(
new Property<LinearIndeterminateDisjointAnimatorDelegate, Float>(
Float.class, "line2TailFraction") {
@Override
public Float get(LinearIndeterminateSpacingAnimatorDelegate drawable) {
public Float get(LinearIndeterminateDisjointAnimatorDelegate drawable) {
return drawable.getLine2TailFraction();
}

@Override
public void set(LinearIndeterminateSpacingAnimatorDelegate drawable, Float value) {
public void set(LinearIndeterminateDisjointAnimatorDelegate drawable, Float value) {
drawable.setLine2TailFraction(value);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public final class LinearProgressIndicator
extends BaseProgressIndicator<LinearProgressIndicatorSpec> {
public static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_LinearProgressIndicator;

public static final int INDETERMINATE_ANIMATION_TYPE_SEAMLESS = 0;
public static final int INDETERMINATE_ANIMATION_TYPE_SPACING = 1;
public static final int INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS = 0;
public static final int INDETERMINATE_ANIMATION_TYPE_DISJOINT = 1;

public static final int INDICATOR_DIRECTION_LEFT_TO_RIGHT = 0;
public static final int INDICATOR_DIRECTION_RIGHT_TO_LEFT = 1;
Expand Down Expand Up @@ -126,7 +126,7 @@ private void initializeDrawables() {
*
* @param indicatorColors The new colors used in indicator.
* @throws IllegalArgumentException if there are less than 3 indicator colors when
* indeterminateAnimationType is {@link #INDETERMINATE_ANIMATION_TYPE_SEAMLESS}.
* indeterminateAnimationType is {@link #INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS}.
*/
@Override
public void setIndicatorColor(@NonNull int... indicatorColors) {
Expand All @@ -139,7 +139,7 @@ public void setIndicatorColor(@NonNull int... indicatorColors) {
*
* @param trackCornerRadius The new corner radius in pixels.
* @throws IllegalArgumentException if trackCornerRadius is not zero, when
* indeterminateAnimationType is {@link #INDETERMINATE_ANIMATION_TYPE_SEAMLESS}.
* indeterminateAnimationType is {@link #INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS}.
*/
@Override
public void setTrackCornerRadius(int trackCornerRadius) {
Expand Down Expand Up @@ -179,12 +179,12 @@ public void setIndeterminateAnimationType(
}
spec.indeterminateAnimationType = indeterminateAnimationType;
spec.validateSpec();
if (indeterminateAnimationType == INDETERMINATE_ANIMATION_TYPE_SEAMLESS) {
if (indeterminateAnimationType == INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS) {
getIndeterminateDrawable()
.setAnimatorDelegate(new LinearIndeterminateSeamlessAnimatorDelegate(spec));
.setAnimatorDelegate(new LinearIndeterminateContiguousAnimatorDelegate(spec));
} else {
getIndeterminateDrawable()
.setAnimatorDelegate(new LinearIndeterminateSpacingAnimatorDelegate(getContext(), spec));
.setAnimatorDelegate(new LinearIndeterminateDisjointAnimatorDelegate(getContext(), spec));
}
invalidate();
}
Expand Down Expand Up @@ -223,17 +223,18 @@ public void setIndicatorDirection(@IndicatorDirection int indicatorDirection) {
/**
* Sets the current progress to the specified value with/without animation based on the input.
*
* <p>If it's in the indeterminate mode and using non-seamless animation, it will smoothly
* transition to determinate mode by finishing the current indeterminate animation cycle.
* <p>If it's in the indeterminate mode and using disjoint animation, it will smoothly transition
* to determinate mode by finishing the current indeterminate animation cycle.
*
* @param progress The new progress value.
* @param animated Whether to update the progress with the animation.
* @see BaseProgressIndicator#setProgress(int)
*/
@Override
public void setProgressCompat(int progress, boolean animated) {
// Doesn't support to switching into determinate mode while seamless animation is used.
if (spec != null && spec.indeterminateAnimationType == INDETERMINATE_ANIMATION_TYPE_SEAMLESS
// Doesn't support to switching into determinate mode while disjoint animation is used.
if (spec != null
&& spec.indeterminateAnimationType == INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS
&& isIndeterminate()) {
return;
}
Expand All @@ -244,7 +245,7 @@ && isIndeterminate()) {

/** @hide */
@RestrictTo(Scope.LIBRARY_GROUP)
@IntDef({INDETERMINATE_ANIMATION_TYPE_SEAMLESS, INDETERMINATE_ANIMATION_TYPE_SPACING})
@IntDef({INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS, INDETERMINATE_ANIMATION_TYPE_DISJOINT})
@Retention(RetentionPolicy.SOURCE)
public @interface IndeterminateAnimationType {}

Expand Down

0 comments on commit 77cf940

Please sign in to comment.