Skip to content

Commit

Permalink
add IndicatorCreatedListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Relex committed May 26, 2019
1 parent 002f078 commit b45062a
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;

class BaseCircleIndicator extends LinearLayout {

Expand All @@ -32,6 +33,8 @@ class BaseCircleIndicator extends LinearLayout {

protected int mLastPosition = -1;

@Nullable private IndicatorCreatedListener mIndicatorCreatedListener;

public BaseCircleIndicator(Context context) {
super(context);
init(context, null);
Expand Down Expand Up @@ -114,6 +117,21 @@ public void initialize(Config config) {
setGravity(config.gravity >= 0 ? config.gravity : Gravity.CENTER);
}

public interface IndicatorCreatedListener {
/**
* IndicatorCreatedListener
*
* @param view internal indicator view
* @param position position
*/
void onIndicatorCreated(View view, int position);
}

public void setIndicatorCreatedListener(
@Nullable IndicatorCreatedListener indicatorCreatedListener) {
mIndicatorCreatedListener = indicatorCreatedListener;
}

protected Animator createAnimatorOut(Config config) {
return AnimatorInflater.loadAnimator(getContext(), config.animatorResId);
}
Expand All @@ -131,17 +149,22 @@ protected Animator createAnimatorIn(Config config) {

protected void createIndicators(int count, int currentPosition) {
int orientation = getOrientation();
View indicator;
for (int i = 0; i < count; i++) {
if (currentPosition == i) {
addIndicator(orientation, mIndicatorBackgroundResId, mImmediateAnimatorOut);
indicator =
addIndicator(orientation, mIndicatorBackgroundResId, mImmediateAnimatorOut);
} else {
addIndicator(orientation, mIndicatorUnselectedBackgroundResId,
indicator = addIndicator(orientation, mIndicatorUnselectedBackgroundResId,
mImmediateAnimatorIn);
}
if (mIndicatorCreatedListener != null) {
mIndicatorCreatedListener.onIndicatorCreated(indicator, i);
}
}
}

protected void addIndicator(int orientation, @DrawableRes int backgroundDrawableId,
protected View addIndicator(int orientation, @DrawableRes int backgroundDrawableId,
Animator animator) {
if (animator.isRunning()) {
animator.end();
Expand All @@ -163,6 +186,8 @@ protected void addIndicator(int orientation, @DrawableRes int backgroundDrawable
indicator.setLayoutParams(lp);
animator.setTarget(indicator);
animator.start();

return indicator;
}

protected void internalPageSelected(int position) {
Expand Down

0 comments on commit b45062a

Please sign in to comment.