StackScrollerDecorView.java revision a2052ea218386877e6d5d2136483a62b2b31f774
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17package com.android.systemui.statusbar; 18 19import android.content.Context; 20import android.util.AttributeSet; 21import android.view.View; 22import android.view.animation.Interpolator; 23 24import com.android.systemui.statusbar.phone.PhoneStatusBar; 25 26/** 27 * A common base class for all views in the notification stack scroller which don't have a 28 * background. 29 */ 30public abstract class StackScrollerDecorView extends ExpandableView { 31 32 protected View mContent; 33 private boolean mIsVisible; 34 private boolean mAnimating; 35 private boolean mWillBeGone; 36 37 public StackScrollerDecorView(Context context, AttributeSet attrs) { 38 super(context, attrs); 39 } 40 41 @Override 42 protected void onFinishInflate() { 43 super.onFinishInflate(); 44 mContent = findContentView(); 45 setInvisible(); 46 } 47 48 @Override 49 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 50 super.onLayout(changed, left, top, right, bottom); 51 setOutlineProvider(null); 52 } 53 54 @Override 55 public boolean isTransparent() { 56 return true; 57 } 58 59 public void performVisibilityAnimation(boolean nowVisible) { 60 animateText(nowVisible, null /* onFinishedRunnable */); 61 } 62 63 public void performVisibilityAnimation(boolean nowVisible, Runnable onFinishedRunnable) { 64 animateText(nowVisible, onFinishedRunnable); 65 } 66 67 public boolean isVisible() { 68 return mIsVisible || mAnimating; 69 } 70 71 /** 72 * Animate the text to a new visibility. 73 * 74 * @param nowVisible should it now be visible 75 * @param onFinishedRunnable A runnable which should be run when the animation is 76 * finished. 77 */ 78 private void animateText(boolean nowVisible, final Runnable onFinishedRunnable) { 79 if (nowVisible != mIsVisible) { 80 // Animate text 81 float endValue = nowVisible ? 1.0f : 0.0f; 82 Interpolator interpolator; 83 if (nowVisible) { 84 interpolator = PhoneStatusBar.ALPHA_IN; 85 } else { 86 interpolator = PhoneStatusBar.ALPHA_OUT; 87 } 88 mAnimating = true; 89 mContent.animate() 90 .alpha(endValue) 91 .setInterpolator(interpolator) 92 .setDuration(260) 93 .withLayer() 94 .withEndAction(new Runnable() { 95 @Override 96 public void run() { 97 mAnimating = false; 98 if (onFinishedRunnable != null) { 99 onFinishedRunnable.run(); 100 } 101 } 102 }); 103 mIsVisible = nowVisible; 104 } else { 105 if (onFinishedRunnable != null) { 106 onFinishedRunnable.run(); 107 } 108 } 109 } 110 111 public void setInvisible() { 112 mContent.setAlpha(0.0f); 113 mIsVisible = false; 114 } 115 116 @Override 117 public void performRemoveAnimation(long duration, float translationDirection, 118 Runnable onFinishedRunnable) { 119 // TODO: Use duration 120 performVisibilityAnimation(false); 121 } 122 123 @Override 124 public void performAddAnimation(long delay, long duration) { 125 // TODO: use delay and duration 126 performVisibilityAnimation(true); 127 } 128 129 @Override 130 public void setScrimAmount(float scrimAmount) { 131 // We don't need to scrim the dismissView 132 } 133 134 @Override 135 public boolean hasOverlappingRendering() { 136 return false; 137 } 138 139 public void cancelAnimation() { 140 mContent.animate().cancel(); 141 } 142 143 public boolean willBeGone() { 144 return mWillBeGone; 145 } 146 147 public void setWillBeGone(boolean willBeGone) { 148 mWillBeGone = willBeGone; 149 } 150 151 protected abstract View findContentView(); 152} 153