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.policy; 18 19 import com.android.systemui.R; 20 import com.android.systemui.statusbar.ScrimView; 21 import com.android.systemui.statusbar.phone.PhoneStatusBar; 22 import com.android.systemui.statusbar.phone.StatusBarWindowView; 23 24 import android.view.View; 25 import android.view.ViewPropertyAnimator; 26 import android.widget.FrameLayout; 27 28 /** 29 * Controls showing and hiding of the brightness mirror. 30 */ 31 public class BrightnessMirrorController { 32 33 public long TRANSITION_DURATION_OUT = 150; 34 public long TRANSITION_DURATION_IN = 200; 35 36 private final ScrimView mScrimBehind; 37 private final View mBrightnessMirror; 38 private final View mPanelHolder; 39 private final int[] mInt2Cache = new int[2]; 40 BrightnessMirrorController(StatusBarWindowView statusBarWindow)41 public BrightnessMirrorController(StatusBarWindowView statusBarWindow) { 42 mScrimBehind = (ScrimView) statusBarWindow.findViewById(R.id.scrim_behind); 43 mBrightnessMirror = statusBarWindow.findViewById(R.id.brightness_mirror); 44 mPanelHolder = statusBarWindow.findViewById(R.id.panel_holder); 45 } 46 showMirror()47 public void showMirror() { 48 mBrightnessMirror.setVisibility(View.VISIBLE); 49 mScrimBehind.animateViewAlpha(0.0f, TRANSITION_DURATION_OUT, PhoneStatusBar.ALPHA_OUT); 50 outAnimation(mPanelHolder.animate()) 51 .withLayer(); 52 } 53 hideMirror()54 public void hideMirror() { 55 mScrimBehind.animateViewAlpha(1.0f, TRANSITION_DURATION_IN, PhoneStatusBar.ALPHA_IN); 56 inAnimation(mPanelHolder.animate()) 57 .withLayer() 58 .withEndAction(new Runnable() { 59 @Override 60 public void run() { 61 mBrightnessMirror.setVisibility(View.GONE); 62 } 63 }); 64 } 65 outAnimation(ViewPropertyAnimator a)66 private ViewPropertyAnimator outAnimation(ViewPropertyAnimator a) { 67 return a.alpha(0.0f) 68 .setDuration(TRANSITION_DURATION_OUT) 69 .setInterpolator(PhoneStatusBar.ALPHA_OUT); 70 } inAnimation(ViewPropertyAnimator a)71 private ViewPropertyAnimator inAnimation(ViewPropertyAnimator a) { 72 return a.alpha(1.0f) 73 .setDuration(TRANSITION_DURATION_IN) 74 .setInterpolator(PhoneStatusBar.ALPHA_IN); 75 } 76 77 setLocation(View original)78 public void setLocation(View original) { 79 original.getLocationInWindow(mInt2Cache); 80 int originalY = mInt2Cache[1]; 81 mBrightnessMirror.getLocationInWindow(mInt2Cache); 82 int mirrorY = mInt2Cache[1]; 83 84 mBrightnessMirror.setTranslationY(mBrightnessMirror.getTranslationY() 85 + originalY - mirrorY); 86 } 87 getMirror()88 public View getMirror() { 89 return mBrightnessMirror; 90 } 91 updateResources()92 public void updateResources() { 93 FrameLayout.LayoutParams lp = 94 (FrameLayout.LayoutParams) mBrightnessMirror.getLayoutParams(); 95 lp.width = mBrightnessMirror.getResources().getDimensionPixelSize( 96 R.dimen.notification_panel_width); 97 lp.gravity = mBrightnessMirror.getResources().getInteger( 98 R.integer.notification_panel_layout_gravity); 99 mBrightnessMirror.setLayoutParams(lp); 100 101 int padding = mBrightnessMirror.getResources().getDimensionPixelSize( 102 R.dimen.notification_side_padding); 103 mBrightnessMirror.setPadding(padding, mBrightnessMirror.getPaddingTop(), 104 padding, mBrightnessMirror.getPaddingBottom()); 105 } 106 } 107