Fields Summary |
---|
private static final float | GLOW_MAX_SCALE_FACTOR |
private static final float | GLOW_MAX_ALPHA |
private static final int | ANIMATION_DURATION_SCALE |
private static final int | ANIMATION_DURATION_FADE |
private android.graphics.Paint | mRipplePaint |
private android.graphics.CanvasProperty | mLeftProp |
private android.graphics.CanvasProperty | mTopProp |
private android.graphics.CanvasProperty | mRightProp |
private android.graphics.CanvasProperty | mBottomProp |
private android.graphics.CanvasProperty | mRxProp |
private android.graphics.CanvasProperty | mRyProp |
private android.graphics.CanvasProperty | mPaintProp |
private float | mGlowAlpha |
private float | mGlowScale |
private boolean | mPressed |
private boolean | mDrawingHardwareGlow |
private int | mMaxWidth |
private final android.view.animation.Interpolator | mInterpolator |
private final android.view.animation.Interpolator | mAlphaExitInterpolator |
private boolean | mSupportHardware |
private final android.view.View | mTargetView |
private final HashSet | mRunningAnimations |
private final ArrayList | mTmpArray |
private final android.animation.AnimatorListenerAdapter | mAnimatorListener |
Methods Summary |
---|
private void | cancelAnimations()
mTmpArray.addAll(mRunningAnimations);
int size = mTmpArray.size();
for (int i = 0; i < size; i++) {
Animator a = mTmpArray.get(i);
a.cancel();
}
mTmpArray.clear();
mRunningAnimations.clear();
|
public void | draw(android.graphics.Canvas canvas)
mSupportHardware = canvas.isHardwareAccelerated();
if (mSupportHardware) {
drawHardware((HardwareCanvas) canvas);
} else {
drawSoftware(canvas);
}
|
private void | drawHardware(android.view.HardwareCanvas c)
if (mDrawingHardwareGlow) {
c.drawRoundRect(mLeftProp, mTopProp, mRightProp, mBottomProp, mRxProp, mRyProp,
mPaintProp);
}
|
private void | drawSoftware(android.graphics.Canvas canvas)
if (mGlowAlpha > 0f) {
final Paint p = getRipplePaint();
p.setAlpha((int)(mGlowAlpha * 255f));
final float w = getBounds().width();
final float h = getBounds().height();
final boolean horizontal = w > h;
final float diameter = getRippleSize() * mGlowScale;
final float radius = diameter * .5f;
final float cx = w * .5f;
final float cy = h * .5f;
final float rx = horizontal ? radius : cx;
final float ry = horizontal ? cy : radius;
final float corner = horizontal ? cy : cx;
canvas.drawRoundRect(cx - rx, cy - ry,
cx + rx, cy + ry,
corner, corner, p);
}
|
private void | enterHardware()
cancelAnimations();
mDrawingHardwareGlow = true;
setExtendStart(CanvasProperty.createFloat(getExtendSize() / 2));
final RenderNodeAnimator startAnim = new RenderNodeAnimator(getExtendStart(),
getExtendSize()/2 - GLOW_MAX_SCALE_FACTOR * getRippleSize()/2);
startAnim.setDuration(ANIMATION_DURATION_SCALE);
startAnim.setInterpolator(mInterpolator);
startAnim.addListener(mAnimatorListener);
startAnim.setTarget(mTargetView);
setExtendEnd(CanvasProperty.createFloat(getExtendSize() / 2));
final RenderNodeAnimator endAnim = new RenderNodeAnimator(getExtendEnd(),
getExtendSize()/2 + GLOW_MAX_SCALE_FACTOR * getRippleSize()/2);
endAnim.setDuration(ANIMATION_DURATION_SCALE);
endAnim.setInterpolator(mInterpolator);
endAnim.addListener(mAnimatorListener);
endAnim.setTarget(mTargetView);
if (isHorizontal()) {
mTopProp = CanvasProperty.createFloat(0f);
mBottomProp = CanvasProperty.createFloat(getBounds().height());
mRxProp = CanvasProperty.createFloat(getBounds().height()/2);
mRyProp = CanvasProperty.createFloat(getBounds().height()/2);
} else {
mLeftProp = CanvasProperty.createFloat(0f);
mRightProp = CanvasProperty.createFloat(getBounds().width());
mRxProp = CanvasProperty.createFloat(getBounds().width()/2);
mRyProp = CanvasProperty.createFloat(getBounds().width()/2);
}
mGlowScale = GLOW_MAX_SCALE_FACTOR;
mGlowAlpha = GLOW_MAX_ALPHA;
mRipplePaint = getRipplePaint();
mRipplePaint.setAlpha((int) (mGlowAlpha * 255));
mPaintProp = CanvasProperty.createPaint(mRipplePaint);
startAnim.start();
endAnim.start();
mRunningAnimations.add(startAnim);
mRunningAnimations.add(endAnim);
invalidateSelf();
|
private void | enterSoftware()
cancelAnimations();
mGlowAlpha = GLOW_MAX_ALPHA;
ObjectAnimator scaleAnimator = ObjectAnimator.ofFloat(this, "glowScale",
0f, GLOW_MAX_SCALE_FACTOR);
scaleAnimator.setInterpolator(mInterpolator);
scaleAnimator.setDuration(ANIMATION_DURATION_SCALE);
scaleAnimator.addListener(mAnimatorListener);
scaleAnimator.start();
mRunningAnimations.add(scaleAnimator);
|
private void | exitHardware()
mPaintProp = CanvasProperty.createPaint(getRipplePaint());
final RenderNodeAnimator opacityAnim = new RenderNodeAnimator(mPaintProp,
RenderNodeAnimator.PAINT_ALPHA, 0);
opacityAnim.setDuration(ANIMATION_DURATION_FADE);
opacityAnim.setInterpolator(mAlphaExitInterpolator);
opacityAnim.addListener(mAnimatorListener);
opacityAnim.setTarget(mTargetView);
opacityAnim.start();
mRunningAnimations.add(opacityAnim);
invalidateSelf();
|
private void | exitSoftware()
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(this, "glowAlpha", mGlowAlpha, 0f);
alphaAnimator.setInterpolator(mAlphaExitInterpolator);
alphaAnimator.setDuration(ANIMATION_DURATION_FADE);
alphaAnimator.addListener(mAnimatorListener);
alphaAnimator.start();
mRunningAnimations.add(alphaAnimator);
|
private android.graphics.CanvasProperty | getExtendEnd()
return isHorizontal() ? mRightProp : mBottomProp;
|
private int | getExtendSize()
return isHorizontal() ? getBounds().width() : getBounds().height();
|
private android.graphics.CanvasProperty | getExtendStart()
return isHorizontal() ? mLeftProp : mTopProp;
|
public float | getGlowAlpha()
return mGlowAlpha;
|
public float | getGlowScale()
return mGlowScale;
|
public int | getOpacity()
return PixelFormat.TRANSLUCENT;
|
private android.graphics.Paint | getRipplePaint()
if (mRipplePaint == null) {
mRipplePaint = new Paint();
mRipplePaint.setAntiAlias(true);
mRipplePaint.setColor(0xffffffff);
}
return mRipplePaint;
|
private int | getRippleSize()
int size = isHorizontal() ? getBounds().width() : getBounds().height();
return Math.min(size, mMaxWidth);
|
private boolean | isHorizontal()
return getBounds().width() > getBounds().height();
|
public boolean | isStateful()
return true;
|
public void | jumpToCurrentState()
cancelAnimations();
|
protected boolean | onStateChange(int[] state)
boolean pressed = false;
for (int i = 0; i < state.length; i++) {
if (state[i] == android.R.attr.state_pressed) {
pressed = true;
break;
}
}
if (pressed != mPressed) {
setPressed(pressed);
mPressed = pressed;
return true;
} else {
return false;
}
|
public void | setAlpha(int alpha)
// Not supported.
|
public void | setColorFilter(android.graphics.ColorFilter cf)
// Not supported.
|
private void | setExtendEnd(android.graphics.CanvasProperty prop)Sets the right/bottom property for the round rect to {@code prop} depending on whether we are
horizontal or vertical mode.
if (isHorizontal()) {
mRightProp = prop;
} else {
mBottomProp = prop;
}
|
private void | setExtendStart(android.graphics.CanvasProperty prop)Sets the left/top property for the round rect to {@code prop} depending on whether we are
horizontal or vertical mode.
if (isHorizontal()) {
mLeftProp = prop;
} else {
mTopProp = prop;
}
|
public void | setGlowAlpha(float x)
mGlowAlpha = x;
invalidateSelf();
|
public void | setGlowScale(float x)
mGlowScale = x;
invalidateSelf();
|
public void | setPressed(boolean pressed)
if (mSupportHardware) {
setPressedHardware(pressed);
} else {
setPressedSoftware(pressed);
}
|
private void | setPressedHardware(boolean pressed)
if (pressed) {
enterHardware();
} else {
exitHardware();
}
|
private void | setPressedSoftware(boolean pressed)
if (pressed) {
enterSoftware();
} else {
exitSoftware();
}
|