Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 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 | |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 19 | import android.view.LayoutInflater; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 20 | import android.view.View; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 21 | import android.view.ViewPropertyAnimator; |
| 22 | import android.widget.FrameLayout; |
| 23 | |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 24 | import com.android.systemui.Interpolators; |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 25 | import com.android.systemui.R; |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 26 | import com.android.systemui.statusbar.ScrimView; |
| 27 | import com.android.systemui.statusbar.phone.StatusBarWindowView; |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 28 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 29 | |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 30 | /** |
| 31 | * Controls showing and hiding of the brightness mirror. |
| 32 | */ |
| 33 | public class BrightnessMirrorController { |
| 34 | |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 35 | private final NotificationStackScrollLayout mStackScroller; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 36 | public long TRANSITION_DURATION_OUT = 150; |
| 37 | public long TRANSITION_DURATION_IN = 200; |
| 38 | |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 39 | private final StatusBarWindowView mStatusBarWindow; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 40 | private final ScrimView mScrimBehind; |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 41 | private final View mNotificationPanel; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 42 | private final int[] mInt2Cache = new int[2]; |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 43 | private View mBrightnessMirror; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 44 | |
| 45 | public BrightnessMirrorController(StatusBarWindowView statusBarWindow) { |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 46 | mStatusBarWindow = statusBarWindow; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 47 | mScrimBehind = (ScrimView) statusBarWindow.findViewById(R.id.scrim_behind); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 48 | mBrightnessMirror = statusBarWindow.findViewById(R.id.brightness_mirror); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 49 | mNotificationPanel = statusBarWindow.findViewById(R.id.notification_panel); |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 50 | mStackScroller = (NotificationStackScrollLayout) statusBarWindow.findViewById( |
| 51 | R.id.notification_stack_scroller); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | public void showMirror() { |
| 55 | mBrightnessMirror.setVisibility(View.VISIBLE); |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 56 | mStackScroller.setFadingOut(true); |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 57 | mScrimBehind.animateViewAlpha(0.0f, TRANSITION_DURATION_OUT, Interpolators.ALPHA_OUT); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 58 | outAnimation(mNotificationPanel.animate()) |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 59 | .withLayer(); |
| 60 | } |
| 61 | |
| 62 | public void hideMirror() { |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 63 | mScrimBehind.animateViewAlpha(1.0f, TRANSITION_DURATION_IN, Interpolators.ALPHA_IN); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 64 | inAnimation(mNotificationPanel.animate()) |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 65 | .withLayer() |
| 66 | .withEndAction(new Runnable() { |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 67 | @Override |
| 68 | public void run() { |
| 69 | mBrightnessMirror.setVisibility(View.INVISIBLE); |
Selim Cinek | 07304f522 | 2016-05-19 18:31:36 -0700 | [diff] [blame] | 70 | mStackScroller.setFadingOut(false); |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 71 | } |
| 72 | }); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | private ViewPropertyAnimator outAnimation(ViewPropertyAnimator a) { |
| 76 | return a.alpha(0.0f) |
| 77 | .setDuration(TRANSITION_DURATION_OUT) |
Selim Cinek | 31d37b9 | 2016-04-26 09:56:42 -0700 | [diff] [blame] | 78 | .setInterpolator(Interpolators.ALPHA_OUT) |
| 79 | .withEndAction(null); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 80 | } |
| 81 | private ViewPropertyAnimator inAnimation(ViewPropertyAnimator a) { |
| 82 | return a.alpha(1.0f) |
| 83 | .setDuration(TRANSITION_DURATION_IN) |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 84 | .setInterpolator(Interpolators.ALPHA_IN); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | |
| 88 | public void setLocation(View original) { |
| 89 | original.getLocationInWindow(mInt2Cache); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 90 | |
Jorim Jaggi | 9799369 | 2015-05-13 17:39:18 -0700 | [diff] [blame] | 91 | // Original is slightly larger than the mirror, so make sure to use the center for the |
| 92 | // positioning. |
Jason Monk | 66eaf31 | 2016-02-25 12:29:29 -0500 | [diff] [blame] | 93 | int originalX = mInt2Cache[0] + original.getWidth() / 2; |
| 94 | int originalY = mInt2Cache[1] + original.getHeight() / 2; |
Jorim Jaggi | 9799369 | 2015-05-13 17:39:18 -0700 | [diff] [blame] | 95 | mBrightnessMirror.setTranslationX(0); |
| 96 | mBrightnessMirror.setTranslationY(0); |
| 97 | mBrightnessMirror.getLocationInWindow(mInt2Cache); |
Jason Monk | 66eaf31 | 2016-02-25 12:29:29 -0500 | [diff] [blame] | 98 | int mirrorX = mInt2Cache[0] + mBrightnessMirror.getWidth() / 2; |
| 99 | int mirrorY = mInt2Cache[1] + mBrightnessMirror.getHeight() / 2; |
Jorim Jaggi | 9799369 | 2015-05-13 17:39:18 -0700 | [diff] [blame] | 100 | mBrightnessMirror.setTranslationX(originalX - mirrorX); |
| 101 | mBrightnessMirror.setTranslationY(originalY - mirrorY); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | public View getMirror() { |
| 105 | return mBrightnessMirror; |
| 106 | } |
| 107 | |
| 108 | public void updateResources() { |
| 109 | FrameLayout.LayoutParams lp = |
| 110 | (FrameLayout.LayoutParams) mBrightnessMirror.getLayoutParams(); |
| 111 | lp.width = mBrightnessMirror.getResources().getDimensionPixelSize( |
| 112 | R.dimen.notification_panel_width); |
| 113 | lp.gravity = mBrightnessMirror.getResources().getInteger( |
| 114 | R.integer.notification_panel_layout_gravity); |
| 115 | mBrightnessMirror.setLayoutParams(lp); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 116 | } |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 117 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 118 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 119 | int index = mStatusBarWindow.indexOfChild(mBrightnessMirror); |
| 120 | mStatusBarWindow.removeView(mBrightnessMirror); |
| 121 | mBrightnessMirror = LayoutInflater.from(mBrightnessMirror.getContext()).inflate( |
| 122 | R.layout.brightness_mirror, mStatusBarWindow, false); |
| 123 | mStatusBarWindow.addView(mBrightnessMirror, index); |
| 124 | } |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 125 | } |