15fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos/* 25fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * Copyright (C) 2014 The Android Open Source Project 35fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * 45fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * Licensed under the Apache License, Version 2.0 (the "License"); 55fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * you may not use this file except in compliance with the License. 65fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * You may obtain a copy of the License at 75fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * 85fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * http://www.apache.org/licenses/LICENSE-2.0 95fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * 105fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * Unless required by applicable law or agreed to in writing, software 115fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * distributed under the License is distributed on an "AS IS" BASIS, 125fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * See the License for the specific language governing permissions and 145fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * limitations under the License 155fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos */ 165fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 175fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roospackage com.android.systemui.statusbar.policy; 185fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 19e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinekimport android.view.LayoutInflater; 205fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roosimport android.view.View; 215fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roosimport android.view.ViewPropertyAnimator; 225fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roosimport android.widget.FrameLayout; 235fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 24c0d7058b14c24cd07912f5629c26b39b7b4673d5Winsonimport com.android.systemui.Interpolators; 25c18010f6720f606003cde3cd376ddacaca30f6e5Selim Cinekimport com.android.systemui.R; 26c18010f6720f606003cde3cd376ddacaca30f6e5Selim Cinekimport com.android.systemui.statusbar.ScrimView; 27c18010f6720f606003cde3cd376ddacaca30f6e5Selim Cinekimport com.android.systemui.statusbar.phone.StatusBarWindowView; 2831d37b918680c83360af6675aef4eb15b3f81425Selim Cinekimport com.android.systemui.statusbar.stack.NotificationStackScrollLayout; 29c18010f6720f606003cde3cd376ddacaca30f6e5Selim Cinek 305fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos/** 315fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos * Controls showing and hiding of the brightness mirror. 325fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos */ 335fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roospublic class BrightnessMirrorController { 345fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 3531d37b918680c83360af6675aef4eb15b3f81425Selim Cinek private final NotificationStackScrollLayout mStackScroller; 365fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public long TRANSITION_DURATION_OUT = 150; 375fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public long TRANSITION_DURATION_IN = 200; 385fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 39e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek private final StatusBarWindowView mStatusBarWindow; 40a0fad3ba06d0352f640532e69ed3d540b3795535Selim Cinek private final ScrimView mScrimBehind; 419f96711e1adf4a28f961c440da1626ad40c03bc8Xiaohui Chen private final View mNotificationPanel; 425fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos private final int[] mInt2Cache = new int[2]; 43e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek private View mBrightnessMirror; 445fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 455fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public BrightnessMirrorController(StatusBarWindowView statusBarWindow) { 46e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek mStatusBarWindow = statusBarWindow; 47a0fad3ba06d0352f640532e69ed3d540b3795535Selim Cinek mScrimBehind = (ScrimView) statusBarWindow.findViewById(R.id.scrim_behind); 485fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos mBrightnessMirror = statusBarWindow.findViewById(R.id.brightness_mirror); 499f96711e1adf4a28f961c440da1626ad40c03bc8Xiaohui Chen mNotificationPanel = statusBarWindow.findViewById(R.id.notification_panel); 5031d37b918680c83360af6675aef4eb15b3f81425Selim Cinek mStackScroller = (NotificationStackScrollLayout) statusBarWindow.findViewById( 5131d37b918680c83360af6675aef4eb15b3f81425Selim Cinek R.id.notification_stack_scroller); 525fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 535fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 545fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public void showMirror() { 555fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos mBrightnessMirror.setVisibility(View.VISIBLE); 5607304f52243d405a0ad79abb3cf49f889a2c2907Selim Cinek mStackScroller.setFadingOut(true); 57c18010f6720f606003cde3cd376ddacaca30f6e5Selim Cinek mScrimBehind.animateViewAlpha(0.0f, TRANSITION_DURATION_OUT, Interpolators.ALPHA_OUT); 589f96711e1adf4a28f961c440da1626ad40c03bc8Xiaohui Chen outAnimation(mNotificationPanel.animate()) 595fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos .withLayer(); 605fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 615fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 625fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public void hideMirror() { 63c18010f6720f606003cde3cd376ddacaca30f6e5Selim Cinek mScrimBehind.animateViewAlpha(1.0f, TRANSITION_DURATION_IN, Interpolators.ALPHA_IN); 649f96711e1adf4a28f961c440da1626ad40c03bc8Xiaohui Chen inAnimation(mNotificationPanel.animate()) 655fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos .withLayer() 665fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos .withEndAction(new Runnable() { 67e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek @Override 68e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek public void run() { 69e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek mBrightnessMirror.setVisibility(View.INVISIBLE); 7007304f52243d405a0ad79abb3cf49f889a2c2907Selim Cinek mStackScroller.setFadingOut(false); 71e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek } 72e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek }); 735fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 745fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 755fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos private ViewPropertyAnimator outAnimation(ViewPropertyAnimator a) { 765fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos return a.alpha(0.0f) 775fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos .setDuration(TRANSITION_DURATION_OUT) 7831d37b918680c83360af6675aef4eb15b3f81425Selim Cinek .setInterpolator(Interpolators.ALPHA_OUT) 7931d37b918680c83360af6675aef4eb15b3f81425Selim Cinek .withEndAction(null); 805fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 815fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos private ViewPropertyAnimator inAnimation(ViewPropertyAnimator a) { 825fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos return a.alpha(1.0f) 835fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos .setDuration(TRANSITION_DURATION_IN) 84c18010f6720f606003cde3cd376ddacaca30f6e5Selim Cinek .setInterpolator(Interpolators.ALPHA_IN); 855fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 865fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 875fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 885fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public void setLocation(View original) { 895fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos original.getLocationInWindow(mInt2Cache); 90979936920ee2e654e23678172c49b301e886c374Jorim Jaggi 91979936920ee2e654e23678172c49b301e886c374Jorim Jaggi // Original is slightly larger than the mirror, so make sure to use the center for the 92979936920ee2e654e23678172c49b301e886c374Jorim Jaggi // positioning. 9366eaf31a7a1040a1dd9fe6300621e5a5e5184451Jason Monk int originalX = mInt2Cache[0] + original.getWidth() / 2; 9466eaf31a7a1040a1dd9fe6300621e5a5e5184451Jason Monk int originalY = mInt2Cache[1] + original.getHeight() / 2; 95979936920ee2e654e23678172c49b301e886c374Jorim Jaggi mBrightnessMirror.setTranslationX(0); 96979936920ee2e654e23678172c49b301e886c374Jorim Jaggi mBrightnessMirror.setTranslationY(0); 975fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos mBrightnessMirror.getLocationInWindow(mInt2Cache); 9866eaf31a7a1040a1dd9fe6300621e5a5e5184451Jason Monk int mirrorX = mInt2Cache[0] + mBrightnessMirror.getWidth() / 2; 9966eaf31a7a1040a1dd9fe6300621e5a5e5184451Jason Monk int mirrorY = mInt2Cache[1] + mBrightnessMirror.getHeight() / 2; 100979936920ee2e654e23678172c49b301e886c374Jorim Jaggi mBrightnessMirror.setTranslationX(originalX - mirrorX); 101979936920ee2e654e23678172c49b301e886c374Jorim Jaggi mBrightnessMirror.setTranslationY(originalY - mirrorY); 1025fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 1035fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 1045fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public View getMirror() { 1055fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos return mBrightnessMirror; 1065fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 1075fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos 1085fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos public void updateResources() { 1095fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos FrameLayout.LayoutParams lp = 1105fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos (FrameLayout.LayoutParams) mBrightnessMirror.getLayoutParams(); 1115fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos lp.width = mBrightnessMirror.getResources().getDimensionPixelSize( 1125fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos R.dimen.notification_panel_width); 1135fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos lp.gravity = mBrightnessMirror.getResources().getInteger( 1145fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos R.integer.notification_panel_layout_gravity); 1155fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos mBrightnessMirror.setLayoutParams(lp); 1165fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos } 117e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek 1183e7592d0cbbde5b0b85d98b82d991ee5d2aab8a9Selim Cinek public void onDensityOrFontScaleChanged() { 119e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek int index = mStatusBarWindow.indexOfChild(mBrightnessMirror); 120e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek mStatusBarWindow.removeView(mBrightnessMirror); 121e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek mBrightnessMirror = LayoutInflater.from(mBrightnessMirror.getContext()).inflate( 122e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek R.layout.brightness_mirror, mStatusBarWindow, false); 123e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek mStatusBarWindow.addView(mBrightnessMirror, index); 124e803491cb0f4a3d3cb842771757fcf26bed080a0Selim Cinek } 1255fd872e8ea44ffcd4fce1d1196736dca4f270508Adrian Roos} 126