TrustDrawablepublic class TrustDrawable extends android.graphics.drawable.Drawable
Fields Summary |
---|
private static final long | ENTERING_FROM_UNSET_START_DELAY | private static final long | VISIBLE_DURATION | private static final long | EXIT_DURATION | private static final long | ENTER_DURATION | private static final int | ALPHA_VISIBLE_MIN | private static final int | ALPHA_VISIBLE_MAX | private static final int | STATE_UNSET | private static final int | STATE_GONE | private static final int | STATE_ENTERING | private static final int | STATE_VISIBLE | private static final int | STATE_EXITING | private int | mAlpha | private boolean | mAnimating | private int | mCurAlpha | private float | mCurInnerRadius | private android.animation.Animator | mCurAnimator | private int | mState | private android.graphics.Paint | mPaint | private boolean | mTrustManaged | private final float | mInnerRadiusVisibleMin | private final float | mInnerRadiusVisibleMax | private final float | mInnerRadiusExit | private final float | mInnerRadiusEnter | private final float | mThickness | private final android.animation.Animator | mVisibleAnimator | private final android.view.animation.Interpolator | mLinearOutSlowInInterpolator | private final android.view.animation.Interpolator | mFastOutSlowInInterpolator | private final android.view.animation.Interpolator | mAccelerateDecelerateInterpolator | private final ValueAnimator.AnimatorUpdateListener | mAlphaUpdateListener | private final ValueAnimator.AnimatorUpdateListener | mRadiusUpdateListener |
Constructors Summary |
---|
public TrustDrawable(android.content.Context context)
Resources r = context.getResources();
mInnerRadiusVisibleMin = r.getDimension(R.dimen.trust_circle_inner_radius_visible_min);
mInnerRadiusVisibleMax = r.getDimension(R.dimen.trust_circle_inner_radius_visible_max);
mInnerRadiusExit = r.getDimension(R.dimen.trust_circle_inner_radius_exit);
mInnerRadiusEnter = r.getDimension(R.dimen.trust_circle_inner_radius_enter);
mThickness = r.getDimension(R.dimen.trust_circle_thickness);
mCurInnerRadius = mInnerRadiusEnter;
mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(
context, android.R.interpolator.linear_out_slow_in);
mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(
context, android.R.interpolator.fast_out_slow_in);
mAccelerateDecelerateInterpolator = new AccelerateDecelerateInterpolator();
mVisibleAnimator = makeVisibleAnimator();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.WHITE);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(mThickness);
|
Methods Summary |
---|
private android.animation.ValueAnimator | configureAnimator(android.animation.ValueAnimator animator, long duration, ValueAnimator.AnimatorUpdateListener updateListener, android.view.animation.Interpolator interpolator, boolean repeating)
animator.setDuration(duration);
animator.addUpdateListener(updateListener);
animator.setInterpolator(interpolator);
if (repeating) {
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
}
return animator;
| public void | draw(android.graphics.Canvas canvas)
int newAlpha = (mCurAlpha * mAlpha) / 256;
if (newAlpha == 0) {
return;
}
final Rect r = getBounds();
mPaint.setAlpha(newAlpha);
canvas.drawCircle(r.exactCenterX(), r.exactCenterY(), mCurInnerRadius, mPaint);
| public int | getAlpha()
return mAlpha;
| public int | getOpacity()
return PixelFormat.TRANSLUCENT;
| private android.animation.Animator | makeAnimators(float startRadius, float endRadius, int startAlpha, int endAlpha, long duration, android.view.animation.Interpolator interpolator, boolean repeating, boolean stateUpdateListener)
ValueAnimator alphaAnimator = configureAnimator(
ValueAnimator.ofInt(startAlpha, endAlpha),
duration, mAlphaUpdateListener, interpolator, repeating);
ValueAnimator sizeAnimator = configureAnimator(
ValueAnimator.ofFloat(startRadius, endRadius),
duration, mRadiusUpdateListener, interpolator, repeating);
AnimatorSet set = new AnimatorSet();
set.playTogether(alphaAnimator, sizeAnimator);
if (stateUpdateListener) {
set.addListener(new StateUpdateAnimatorListener());
}
return set;
| private android.animation.Animator | makeEnterAnimator(float radius, int alpha)
return makeAnimators(radius, mInnerRadiusVisibleMax,
alpha, ALPHA_VISIBLE_MAX, ENTER_DURATION, mLinearOutSlowInInterpolator,
false /* repeating */, true /* stateUpdateListener */);
| private android.animation.Animator | makeExitAnimator(float radius, int alpha)
return makeAnimators(radius, mInnerRadiusExit,
alpha, 0, EXIT_DURATION, mFastOutSlowInInterpolator,
false /* repeating */, true /* stateUpdateListener */);
| private android.animation.Animator | makeVisibleAnimator()
return makeAnimators(mInnerRadiusVisibleMax, mInnerRadiusVisibleMin,
ALPHA_VISIBLE_MAX, ALPHA_VISIBLE_MIN, VISIBLE_DURATION,
mAccelerateDecelerateInterpolator,
true /* repeating */, false /* stateUpdateListener */);
| public void | setAlpha(int alpha)
mAlpha = alpha;
| public void | setColorFilter(android.graphics.ColorFilter cf)
throw new UnsupportedOperationException("not implemented");
| public void | setTrustManaged(boolean trustManaged)
if (trustManaged == mTrustManaged && mState != STATE_UNSET) return;
mTrustManaged = trustManaged;
updateState(true);
| public void | start()
if (!mAnimating) {
mAnimating = true;
updateState(true);
invalidateSelf();
}
| public void | stop()
if (mAnimating) {
mAnimating = false;
if (mCurAnimator != null) {
mCurAnimator.cancel();
mCurAnimator = null;
}
mState = STATE_UNSET;
mCurAlpha = 0;
mCurInnerRadius = mInnerRadiusEnter;
invalidateSelf();
}
| private void | updateState(boolean allowTransientState)
if (!mAnimating) {
return;
}
int nextState = mState;
if (mState == STATE_UNSET) {
nextState = mTrustManaged ? STATE_ENTERING : STATE_GONE;
} else if (mState == STATE_GONE) {
if (mTrustManaged) nextState = STATE_ENTERING;
} else if (mState == STATE_ENTERING) {
if (!mTrustManaged) nextState = STATE_EXITING;
} else if (mState == STATE_VISIBLE) {
if (!mTrustManaged) nextState = STATE_EXITING;
} else if (mState == STATE_EXITING) {
if (mTrustManaged) nextState = STATE_ENTERING;
}
if (!allowTransientState) {
if (nextState == STATE_ENTERING) nextState = STATE_VISIBLE;
if (nextState == STATE_EXITING) nextState = STATE_GONE;
}
if (nextState != mState) {
if (mCurAnimator != null) {
mCurAnimator.cancel();
mCurAnimator = null;
}
if (nextState == STATE_GONE) {
mCurAlpha = 0;
mCurInnerRadius = mInnerRadiusEnter;
} else if (nextState == STATE_ENTERING) {
mCurAnimator = makeEnterAnimator(mCurInnerRadius, mCurAlpha);
if (mState == STATE_UNSET) {
mCurAnimator.setStartDelay(ENTERING_FROM_UNSET_START_DELAY);
}
} else if (nextState == STATE_VISIBLE) {
mCurAlpha = ALPHA_VISIBLE_MAX;
mCurInnerRadius = mInnerRadiusVisibleMax;
mCurAnimator = mVisibleAnimator;
} else if (nextState == STATE_EXITING) {
mCurAnimator = makeExitAnimator(mCurInnerRadius, mCurAlpha);
}
mState = nextState;
if (mCurAnimator != null) {
mCurAnimator.start();
}
invalidateSelf();
}
|
|