blob: 21d03fd8443afe3628b15a0f8326553ff2d09418 [file] [log] [blame]
Adrian Roos5fd872e2014-08-12 17:28:58 +02001/*
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.policy;
18
Selim Cineke803491c2016-04-09 21:24:45 -070019import android.view.LayoutInflater;
Adrian Roos5fd872e2014-08-12 17:28:58 +020020import android.view.View;
Adrian Roos5fd872e2014-08-12 17:28:58 +020021import android.view.ViewPropertyAnimator;
22import android.widget.FrameLayout;
23
Winsonc0d70582016-01-29 10:24:39 -080024import com.android.systemui.Interpolators;
Selim Cinekc18010f2016-01-20 13:41:30 -080025import com.android.systemui.R;
Selim Cinekc18010f2016-01-20 13:41:30 -080026import com.android.systemui.statusbar.ScrimView;
27import com.android.systemui.statusbar.phone.StatusBarWindowView;
Selim Cinek31d37b92016-04-26 09:56:42 -070028import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekc18010f2016-01-20 13:41:30 -080029
Adrian Roos5fd872e2014-08-12 17:28:58 +020030/**
31 * Controls showing and hiding of the brightness mirror.
32 */
33public class BrightnessMirrorController {
34
Selim Cinek31d37b92016-04-26 09:56:42 -070035 private final NotificationStackScrollLayout mStackScroller;
Adrian Roos5fd872e2014-08-12 17:28:58 +020036 public long TRANSITION_DURATION_OUT = 150;
37 public long TRANSITION_DURATION_IN = 200;
38
Selim Cineke803491c2016-04-09 21:24:45 -070039 private final StatusBarWindowView mStatusBarWindow;
Selim Cineka0fad3b2014-09-19 17:20:05 +020040 private final ScrimView mScrimBehind;
Xiaohui Chen9f967112016-01-07 14:14:06 -080041 private final View mNotificationPanel;
Adrian Roos5fd872e2014-08-12 17:28:58 +020042 private final int[] mInt2Cache = new int[2];
Selim Cineke803491c2016-04-09 21:24:45 -070043 private View mBrightnessMirror;
Adrian Roos5fd872e2014-08-12 17:28:58 +020044
45 public BrightnessMirrorController(StatusBarWindowView statusBarWindow) {
Selim Cineke803491c2016-04-09 21:24:45 -070046 mStatusBarWindow = statusBarWindow;
Selim Cineka0fad3b2014-09-19 17:20:05 +020047 mScrimBehind = (ScrimView) statusBarWindow.findViewById(R.id.scrim_behind);
Adrian Roos5fd872e2014-08-12 17:28:58 +020048 mBrightnessMirror = statusBarWindow.findViewById(R.id.brightness_mirror);
Xiaohui Chen9f967112016-01-07 14:14:06 -080049 mNotificationPanel = statusBarWindow.findViewById(R.id.notification_panel);
Selim Cinek31d37b92016-04-26 09:56:42 -070050 mStackScroller = (NotificationStackScrollLayout) statusBarWindow.findViewById(
51 R.id.notification_stack_scroller);
Adrian Roos5fd872e2014-08-12 17:28:58 +020052 }
53
54 public void showMirror() {
55 mBrightnessMirror.setVisibility(View.VISIBLE);
Selim Cinek07304f5222016-05-19 18:31:36 -070056 mStackScroller.setFadingOut(true);
Selim Cinekc18010f2016-01-20 13:41:30 -080057 mScrimBehind.animateViewAlpha(0.0f, TRANSITION_DURATION_OUT, Interpolators.ALPHA_OUT);
Xiaohui Chen9f967112016-01-07 14:14:06 -080058 outAnimation(mNotificationPanel.animate())
Adrian Roos5fd872e2014-08-12 17:28:58 +020059 .withLayer();
60 }
61
62 public void hideMirror() {
Selim Cinekc18010f2016-01-20 13:41:30 -080063 mScrimBehind.animateViewAlpha(1.0f, TRANSITION_DURATION_IN, Interpolators.ALPHA_IN);
Xiaohui Chen9f967112016-01-07 14:14:06 -080064 inAnimation(mNotificationPanel.animate())
Adrian Roos5fd872e2014-08-12 17:28:58 +020065 .withLayer()
66 .withEndAction(new Runnable() {
Selim Cineke803491c2016-04-09 21:24:45 -070067 @Override
68 public void run() {
69 mBrightnessMirror.setVisibility(View.INVISIBLE);
Selim Cinek07304f5222016-05-19 18:31:36 -070070 mStackScroller.setFadingOut(false);
Selim Cineke803491c2016-04-09 21:24:45 -070071 }
72 });
Adrian Roos5fd872e2014-08-12 17:28:58 +020073 }
74
75 private ViewPropertyAnimator outAnimation(ViewPropertyAnimator a) {
76 return a.alpha(0.0f)
77 .setDuration(TRANSITION_DURATION_OUT)
Selim Cinek31d37b92016-04-26 09:56:42 -070078 .setInterpolator(Interpolators.ALPHA_OUT)
79 .withEndAction(null);
Adrian Roos5fd872e2014-08-12 17:28:58 +020080 }
81 private ViewPropertyAnimator inAnimation(ViewPropertyAnimator a) {
82 return a.alpha(1.0f)
83 .setDuration(TRANSITION_DURATION_IN)
Selim Cinekc18010f2016-01-20 13:41:30 -080084 .setInterpolator(Interpolators.ALPHA_IN);
Adrian Roos5fd872e2014-08-12 17:28:58 +020085 }
86
87
88 public void setLocation(View original) {
89 original.getLocationInWindow(mInt2Cache);
Adrian Roos5fd872e2014-08-12 17:28:58 +020090
Jorim Jaggi97993692015-05-13 17:39:18 -070091 // Original is slightly larger than the mirror, so make sure to use the center for the
92 // positioning.
Jason Monk66eaf312016-02-25 12:29:29 -050093 int originalX = mInt2Cache[0] + original.getWidth() / 2;
94 int originalY = mInt2Cache[1] + original.getHeight() / 2;
Jorim Jaggi97993692015-05-13 17:39:18 -070095 mBrightnessMirror.setTranslationX(0);
96 mBrightnessMirror.setTranslationY(0);
97 mBrightnessMirror.getLocationInWindow(mInt2Cache);
Jason Monk66eaf312016-02-25 12:29:29 -050098 int mirrorX = mInt2Cache[0] + mBrightnessMirror.getWidth() / 2;
99 int mirrorY = mInt2Cache[1] + mBrightnessMirror.getHeight() / 2;
Jorim Jaggi97993692015-05-13 17:39:18 -0700100 mBrightnessMirror.setTranslationX(originalX - mirrorX);
101 mBrightnessMirror.setTranslationY(originalY - mirrorY);
Adrian Roos5fd872e2014-08-12 17:28:58 +0200102 }
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 Roos5fd872e2014-08-12 17:28:58 +0200116 }
Selim Cineke803491c2016-04-09 21:24:45 -0700117
Selim Cinek3e7592d2016-04-11 09:35:54 +0800118 public void onDensityOrFontScaleChanged() {
Selim Cineke803491c2016-04-09 21:24:45 -0700119 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 Roos5fd872e2014-08-12 17:28:58 +0200125}