SpeedBumpView.java revision 7b7ca3cdf25bee73aa9e58aaaf6ce75fe81bd045
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.animation.AnimationUtils; 22import android.view.animation.Interpolator; 23import com.android.systemui.R; 24 25/** 26 * The view representing the separation between important and less important notifications 27 */ 28public 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 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 44 protected void onFinishInflate() { 45 super.onFinishInflate(); 46 mLine = (AlphaOptimizedView) findViewById(R.id.speedbump_line); 47 } 48 49 @Override 50 protected int getInitialHeight() { 51 return mSpeedBumpHeight; 52 } 53 54 @Override 55 public int getIntrinsicHeight() { 56 return mSpeedBumpHeight; 57 } 58 59 @Override 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 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 75 public boolean isTransparent() { 76 return true; 77 } 78 79 public void performVisibilityAnimation(boolean nowVisible) { 80 animateDivider(nowVisible, null /* onFinishedRunnable */); 81 } 82 83 /** 84 * Animate the divider to a new visibility. 85 * 86 * @param nowVisible should it now be visible 87 * @param onFinishedRunnable A runnable which should be run when the animation is 88 * finished. 89 */ 90 public void animateDivider(boolean nowVisible, Runnable onFinishedRunnable) { 91 if (nowVisible != mIsVisible) { 92 // Animate dividers 93 float endValue = nowVisible ? 1.0f : 0.0f; 94 mLine.animate() 95 .alpha(endValue) 96 .scaleX(endValue) 97 .scaleY(endValue) 98 .setInterpolator(mFastOutSlowInInterpolator) 99 .withEndAction(onFinishedRunnable); 100 mIsVisible = nowVisible; 101 } else { 102 if (onFinishedRunnable != null) { 103 onFinishedRunnable.run(); 104 } 105 } 106 } 107 108 public void setInvisible() { 109 mLine.setAlpha(0.0f); 110 mLine.setScaleX(0.0f); 111 mLine.setScaleY(0.0f); 112 mIsVisible = false; 113 } 114 115 @Override 116 public void performRemoveAnimation(float translationDirection, Runnable onFinishedRunnable) { 117 performVisibilityAnimation(false); 118 } 119 120 @Override 121 public void performAddAnimation(long delay) { 122 performVisibilityAnimation(true); 123 } 124 125 @Override 126 public void setScrimAmount(float scrimAmount) { 127 // We don't need to scrim the speedbumps 128 } 129} 130