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 17 package com.android.systemui.statusbar; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.animation.AnimationUtils; 22 import android.view.animation.Interpolator; 23 import com.android.systemui.R; 24 25 /** 26 * The view representing the separation between important and less important notifications 27 */ 28 public class SpeedBumpView extends ExpandableView { 29 30 private final int mSpeedBumpHeight; 31 private AlphaOptimizedView mLine; 32 private boolean mIsVisible = true; 33 private final Interpolator mFastOutSlowInInterpolator; 34 SpeedBumpView(Context context, AttributeSet attrs)35 public SpeedBumpView(Context context, AttributeSet attrs) { 36 super(context, attrs); 37 mSpeedBumpHeight = getResources() 38 .getDimensionPixelSize(R.dimen.speed_bump_height); 39 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(), 40 android.R.interpolator.fast_out_slow_in); 41 } 42 43 @Override onFinishInflate()44 protected void onFinishInflate() { 45 super.onFinishInflate(); 46 mLine = (AlphaOptimizedView) findViewById(R.id.speedbump_line); 47 } 48 49 @Override getInitialHeight()50 protected int getInitialHeight() { 51 return mSpeedBumpHeight; 52 } 53 54 @Override getIntrinsicHeight()55 public int getIntrinsicHeight() { 56 return mSpeedBumpHeight; 57 } 58 59 @Override onLayout(boolean changed, int left, int top, int right, int bottom)60 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 61 super.onLayout(changed, left, top, right, bottom); 62 mLine.setPivotX(mLine.getWidth() / 2); 63 mLine.setPivotY(mLine.getHeight() / 2); 64 setOutlineProvider(null); 65 } 66 67 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)68 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 69 measureChildren(widthMeasureSpec, heightMeasureSpec); 70 int height = mSpeedBumpHeight; 71 setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), height); 72 } 73 74 @Override isTransparent()75 public boolean isTransparent() { 76 return true; 77 } 78 performVisibilityAnimation(boolean nowVisible, long delay)79 public void performVisibilityAnimation(boolean nowVisible, long delay) { 80 animateDivider(nowVisible, delay, null /* onFinishedRunnable */); 81 } 82 83 /** 84 * Animate the divider to a new visibility. 85 * 86 * @param nowVisible should it now be visible 87 * @param delay the delay after the animation should start 88 * @param onFinishedRunnable A runnable which should be run when the animation is 89 * finished. 90 */ animateDivider(boolean nowVisible, long delay, Runnable onFinishedRunnable)91 public void animateDivider(boolean nowVisible, long delay, Runnable onFinishedRunnable) { 92 if (nowVisible != mIsVisible) { 93 // Animate dividers 94 float endValue = nowVisible ? 1.0f : 0.0f; 95 mLine.animate() 96 .alpha(endValue) 97 .setStartDelay(delay) 98 .scaleX(endValue) 99 .scaleY(endValue) 100 .setInterpolator(mFastOutSlowInInterpolator) 101 .withEndAction(onFinishedRunnable); 102 mIsVisible = nowVisible; 103 } else { 104 if (onFinishedRunnable != null) { 105 onFinishedRunnable.run(); 106 } 107 } 108 } 109 setInvisible()110 public void setInvisible() { 111 mLine.setAlpha(0.0f); 112 mLine.setScaleX(0.0f); 113 mLine.setScaleY(0.0f); 114 mIsVisible = false; 115 } 116 117 @Override performRemoveAnimation(long duration, float translationDirection, Runnable onFinishedRunnable)118 public void performRemoveAnimation(long duration, float translationDirection, 119 Runnable onFinishedRunnable) { 120 // TODO: Use duration 121 performVisibilityAnimation(false, 0 /* delay */); 122 } 123 124 @Override performAddAnimation(long delay, long duration)125 public void performAddAnimation(long delay, long duration) { 126 // TODO: Use duration 127 performVisibilityAnimation(true, delay); 128 } 129 } 130