Fields Summary |
---|
private static final long | ANIMATION_DURATION_LENGTH |
private final android.graphics.Rect | mClipBounds |
private android.view.View | mContractedChild |
private android.view.View | mExpandedChild |
private NotificationViewWrapper | mContractedWrapper |
private int | mSmallHeight |
private int | mClipTopAmount |
private int | mActualHeight |
private final android.view.animation.Interpolator | mLinearInterpolator |
private boolean | mContractedVisible |
private boolean | mDark |
private final android.graphics.Paint | mFadePaint |
private boolean | mAnimate |
private ViewTreeObserver.OnPreDrawListener | mEnableAnimationPredrawListener |
Methods Summary |
---|
public android.view.View | getContractedChild()
return mContractedChild;
|
public android.view.View | getExpandedChild()
return mExpandedChild;
|
public int | getMaxHeight()
// The maximum height is just the laid out height.
return getHeight();
|
public int | getMinHeight()
return mSmallHeight;
|
public boolean | hasOverlappingRendering()
// This is not really true, but good enough when fading from the contracted to the expanded
// layout, and saves us some layers.
return false;
|
public boolean | isContentExpandable()
return mExpandedChild != null;
|
public void | notifyContentUpdated()
selectLayout(false /* animate */, true /* force */);
if (mContractedChild != null) {
mContractedWrapper.notifyContentUpdated();
mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */);
}
|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
updateVisibility();
|
protected void | onLayout(boolean changed, int left, int top, int right, int bottom)
super.onLayout(changed, left, top, right, bottom);
updateClipping();
|
protected void | onVisibilityChanged(android.view.View changedView, int visibility)
super.onVisibilityChanged(changedView, visibility);
updateVisibility();
|
public void | reset(boolean resetActualHeight)
if (mContractedChild != null) {
mContractedChild.animate().cancel();
}
if (mExpandedChild != null) {
mExpandedChild.animate().cancel();
}
removeAllViews();
mContractedChild = null;
mExpandedChild = null;
mSmallHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height);
mContractedVisible = true;
if (resetActualHeight) {
mActualHeight = mSmallHeight;
}
|
private void | runSwitchAnimation(boolean showContractedChild)
mContractedChild.setVisibility(View.VISIBLE);
mExpandedChild.setVisibility(View.VISIBLE);
mContractedChild.setLayerType(LAYER_TYPE_HARDWARE, mFadePaint);
mExpandedChild.setLayerType(LAYER_TYPE_HARDWARE, mFadePaint);
setLayerType(LAYER_TYPE_HARDWARE, null);
mContractedChild.animate()
.alpha(showContractedChild ? 1f : 0f)
.setDuration(ANIMATION_DURATION_LENGTH)
.setInterpolator(mLinearInterpolator);
mExpandedChild.animate()
.alpha(showContractedChild ? 0f : 1f)
.setDuration(ANIMATION_DURATION_LENGTH)
.setInterpolator(mLinearInterpolator)
.withEndAction(new Runnable() {
@Override
public void run() {
mContractedChild.setLayerType(LAYER_TYPE_NONE, null);
mExpandedChild.setLayerType(LAYER_TYPE_NONE, null);
setLayerType(LAYER_TYPE_NONE, null);
mContractedChild.setVisibility(showContractedChild
? View.VISIBLE
: View.INVISIBLE);
mExpandedChild.setVisibility(showContractedChild
? View.INVISIBLE
: View.VISIBLE);
}
});
|
private void | sanitizeContractedLayoutParams(android.view.View contractedChild)
LayoutParams lp = (LayoutParams) contractedChild.getLayoutParams();
lp.height = mSmallHeight;
contractedChild.setLayoutParams(lp);
|
private void | selectLayout(boolean animate, boolean force)
if (mContractedChild == null) {
return;
}
boolean showContractedChild = showContractedChild();
if (showContractedChild != mContractedVisible || force) {
if (animate && mExpandedChild != null) {
runSwitchAnimation(showContractedChild);
} else if (mExpandedChild != null) {
mContractedChild.setVisibility(showContractedChild ? View.VISIBLE : View.INVISIBLE);
mContractedChild.setAlpha(showContractedChild ? 1f : 0f);
mExpandedChild.setVisibility(showContractedChild ? View.INVISIBLE : View.VISIBLE);
mExpandedChild.setAlpha(showContractedChild ? 0f : 1f);
}
}
mContractedVisible = showContractedChild;
|
public void | setActualHeight(int actualHeight)
mActualHeight = actualHeight;
selectLayout(mAnimate /* animate */, false /* force */);
updateClipping();
|
public void | setClipTopAmount(int clipTopAmount)
mClipTopAmount = clipTopAmount;
updateClipping();
|
public void | setContractedChild(android.view.View child)
if (mContractedChild != null) {
mContractedChild.animate().cancel();
removeView(mContractedChild);
}
sanitizeContractedLayoutParams(child);
addView(child);
mContractedChild = child;
mContractedWrapper = NotificationViewWrapper.wrap(getContext(), child);
selectLayout(false /* animate */, true /* force */);
mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */);
|
public void | setDark(boolean dark, boolean fade, long delay)
if (mDark == dark || mContractedChild == null) return;
mDark = dark;
mContractedWrapper.setDark(dark, fade, delay);
|
public void | setExpandedChild(android.view.View child)
if (mExpandedChild != null) {
mExpandedChild.animate().cancel();
removeView(mExpandedChild);
}
addView(child);
mExpandedChild = child;
selectLayout(false /* animate */, true /* force */);
|
private void | setVisible(boolean isVisible)
if (isVisible) {
// We only animate if we are drawn at least once, otherwise the view might animate when
// it's shown the first time
getViewTreeObserver().addOnPreDrawListener(mEnableAnimationPredrawListener);
} else {
getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener);
mAnimate = false;
}
|
private boolean | showContractedChild()
return mActualHeight <= mSmallHeight || mExpandedChild == null;
|
private void | updateClipping()
mClipBounds.set(0, mClipTopAmount, getWidth(), mActualHeight);
setClipBounds(mClipBounds);
|
private void | updateVisibility()
setVisible(isShown());
|