Skip to content

Commit

Permalink
[ProgressIndicator] Added the custom drawable support (1/7)
Browse files Browse the repository at this point in the history
- Added an interface for indeterminate animator delegate.
- Marked DrawingDelegate to public.

PiperOrigin-RevId: 318084805
  • Loading branch information
pekingme authored and ymarian committed Jun 26, 2020
1 parent 68e807e commit 02c3b3d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* A delegate interface for drawing the graphics in different drawable classes used in {@link
* ProgressIndicator}.
*/
interface DrawingDelegate {
public interface DrawingDelegate {

/**
* Prepares the bound of the canvas for the actual drawing. Should be called before any drawing.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.material.progressindicator;

import android.animation.Animator;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback;

/**
* A delegate abstract class for animating properties used in drawing the graphics in different
* drawable classes for {@link ProgressIndicator}.
*/
public abstract class IndeterminateAnimatorDelegate<T extends Animator> {

// The drawable associated with this delegate.
protected Drawable drawable;
// A float array of numbers in [0, 1] representing the positions of ends of each segment on the
// track.
protected final float[] segmentPositions;
// An integer array of displayed colors used for each indicator segment defined by every two
// segment positions.
protected final int[] segmentColors;

/**
* This constructor should be overridden with other necessary actions, e.g. instantiating the
* animator.
*/
protected IndeterminateAnimatorDelegate(int segmentCount) {
this.segmentPositions = new float[segmentCount * 2];
this.segmentColors = new int[segmentCount];
}

/** Registers the drawable associated to this delegate. */
protected void registerDrawable(@NonNull Drawable drawable) {
this.drawable = drawable;
}

/** Starts the animator. */
abstract void startAnimator();

/** Cancels the animator immediately. */
abstract void cancelAnimatorImmediately();

/** Requests to cancel the main animator after the current cycle finishes. */
abstract void requestCancelAnimatorAfterCurrentCycle();

/**
* Resets all properties controlled by the animator for a fresh start. This should be called after
* the drawable is hidden or before the drawable becomes visible.
*/
abstract void resetPropertiesForNewStart();

/**
* Resets all properties controlled by the animator for the next animation cycle. This should be
* called between the animation cycles.
*/
abstract void resetPropertiesForNextCycle();

/**
* Registers an {@link AnimationCallback} to the animator for the process what needs to be done
* after the current animation cycle.
*
* @param callback Callback to execute the process at the end of current animation cycle. Note:
* only {@link AnimationCallback#onAnimationEnd(Drawable)} should be overridden. Overriding
* other events may cause undesired result.
*/
abstract void registerAnimatorsCompleteCallback(AnimationCallback callback);
}

0 comments on commit 02c3b3d

Please sign in to comment.