blob: 2052ee6cdac5f39c6abebf2525c198875d8a2fbb [file] [log] [blame]
John Spurlock7edfbca2013-09-14 11:58:55 -04001/*
2 * Copyright (C) 2013 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.phone;
18
19import android.animation.Animator;
20import android.animation.AnimatorSet;
21import android.animation.ObjectAnimator;
22import android.content.res.Resources;
John Spurlock7edfbca2013-09-14 11:58:55 -040023import android.view.View;
24
25import com.android.systemui.R;
26
27public final class PhoneStatusBarTransitions extends BarTransitions {
John Spurlockbd957402013-10-03 11:38:39 -040028 private static final float ICON_ALPHA_WHEN_NOT_OPAQUE = 1;
John Spurlocke631b412013-09-18 16:33:57 -040029 private static final float ICON_ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK = 0.5f;
30 private static final float ICON_ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK = 0;
John Spurlock7edfbca2013-09-14 11:58:55 -040031
John Spurlocke631b412013-09-18 16:33:57 -040032 private final float mIconAlphaWhenOpaque;
John Spurlock7edfbca2013-09-14 11:58:55 -040033
Beverlyf937f292020-02-20 13:45:36 -050034 private View mLeftSide, mStatusIcons, mBattery;
John Spurlock7edfbca2013-09-14 11:58:55 -040035 private Animator mCurrentAnimation;
36
Beverlyf937f292020-02-20 13:45:36 -050037 /**
38 * @param backgroundView view to apply the background drawable
39 */
40 public PhoneStatusBarTransitions(PhoneStatusBarView statusBarView, View backgroundView) {
41 super(backgroundView, R.drawable.status_background);
42 final Resources res = statusBarView.getContext().getResources();
John Spurlocke631b412013-09-18 16:33:57 -040043 mIconAlphaWhenOpaque = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1);
Beverlyf937f292020-02-20 13:45:36 -050044 mLeftSide = statusBarView.findViewById(R.id.status_bar_left_side);
45 mStatusIcons = statusBarView.findViewById(R.id.statusIcons);
46 mBattery = statusBarView.findViewById(R.id.battery);
Jorim Jaggiacea1002014-05-10 01:30:10 +020047 applyModeBackground(-1, getMode(), false /*animate*/);
48 applyMode(getMode(), false /*animate*/);
John Spurlock7edfbca2013-09-14 11:58:55 -040049 }
50
John Spurlock7edfbca2013-09-14 11:58:55 -040051 public ObjectAnimator animateTransitionTo(View v, float toAlpha) {
52 return ObjectAnimator.ofFloat(v, "alpha", v.getAlpha(), toAlpha);
53 }
54
55 private float getNonBatteryClockAlphaFor(int mode) {
Adrian Roosc0f0a742014-10-28 16:39:56 +010056 return isLightsOut(mode) ? ICON_ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK
John Spurlockbd957402013-10-03 11:38:39 -040057 : !isOpaque(mode) ? ICON_ALPHA_WHEN_NOT_OPAQUE
John Spurlocke631b412013-09-18 16:33:57 -040058 : mIconAlphaWhenOpaque;
John Spurlock7edfbca2013-09-14 11:58:55 -040059 }
60
61 private float getBatteryClockAlpha(int mode) {
Adrian Roosc0f0a742014-10-28 16:39:56 +010062 return isLightsOut(mode) ? ICON_ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK
John Spurlock7edfbca2013-09-14 11:58:55 -040063 : getNonBatteryClockAlphaFor(mode);
64 }
65
John Spurlockbd957402013-10-03 11:38:39 -040066 private boolean isOpaque(int mode) {
Adrian Roosea562512014-05-05 13:33:03 +020067 return !(mode == MODE_SEMI_TRANSPARENT || mode == MODE_TRANSLUCENT
Adrian Roosc0f0a742014-10-28 16:39:56 +010068 || mode == MODE_TRANSPARENT || mode == MODE_LIGHTS_OUT_TRANSPARENT);
John Spurlock7edfbca2013-09-14 11:58:55 -040069 }
70
71 @Override
72 protected void onTransition(int oldMode, int newMode, boolean animate) {
73 super.onTransition(oldMode, newMode, animate);
74 applyMode(newMode, animate);
75 }
76
77 private void applyMode(int mode, boolean animate) {
78 if (mLeftSide == null) return; // pre-init
John Spurlock7edfbca2013-09-14 11:58:55 -040079 float newAlpha = getNonBatteryClockAlphaFor(mode);
80 float newAlphaBC = getBatteryClockAlpha(mode);
81 if (mCurrentAnimation != null) {
82 mCurrentAnimation.cancel();
83 }
84 if (animate) {
85 AnimatorSet anims = new AnimatorSet();
86 anims.playTogether(
87 animateTransitionTo(mLeftSide, newAlpha),
88 animateTransitionTo(mStatusIcons, newAlpha),
Evan Laird4b68e2f72018-03-29 18:21:48 -040089 animateTransitionTo(mBattery, newAlphaBC)
John Spurlock7edfbca2013-09-14 11:58:55 -040090 );
Adrian Roosc0f0a742014-10-28 16:39:56 +010091 if (isLightsOut(mode)) {
John Spurlock7edfbca2013-09-14 11:58:55 -040092 anims.setDuration(LIGHTS_OUT_DURATION);
93 }
94 anims.start();
95 mCurrentAnimation = anims;
96 } else {
97 mLeftSide.setAlpha(newAlpha);
98 mStatusIcons.setAlpha(newAlpha);
John Spurlock7edfbca2013-09-14 11:58:55 -040099 mBattery.setAlpha(newAlphaBC);
John Spurlock7edfbca2013-09-14 11:58:55 -0400100 }
101 }
Matt Pietalf07bac42020-01-29 15:07:48 -0500102}