John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorSet; |
| 21 | import android.animation.ObjectAnimator; |
| 22 | import android.content.res.Resources; |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 23 | import android.view.View; |
| 24 | |
| 25 | import com.android.systemui.R; |
| 26 | |
| 27 | public final class PhoneStatusBarTransitions extends BarTransitions { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 28 | private static final float ICON_ALPHA_WHEN_NOT_OPAQUE = 1; |
John Spurlock | e631b41 | 2013-09-18 16:33:57 -0400 | [diff] [blame] | 29 | 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 Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 31 | |
John Spurlock | e631b41 | 2013-09-18 16:33:57 -0400 | [diff] [blame] | 32 | private final float mIconAlphaWhenOpaque; |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 33 | |
Beverly | f937f29 | 2020-02-20 13:45:36 -0500 | [diff] [blame] | 34 | private View mLeftSide, mStatusIcons, mBattery; |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 35 | private Animator mCurrentAnimation; |
| 36 | |
Beverly | f937f29 | 2020-02-20 13:45:36 -0500 | [diff] [blame] | 37 | /** |
| 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 Spurlock | e631b41 | 2013-09-18 16:33:57 -0400 | [diff] [blame] | 43 | mIconAlphaWhenOpaque = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1); |
Beverly | f937f29 | 2020-02-20 13:45:36 -0500 | [diff] [blame] | 44 | mLeftSide = statusBarView.findViewById(R.id.status_bar_left_side); |
| 45 | mStatusIcons = statusBarView.findViewById(R.id.statusIcons); |
| 46 | mBattery = statusBarView.findViewById(R.id.battery); |
Jorim Jaggi | acea1000 | 2014-05-10 01:30:10 +0200 | [diff] [blame] | 47 | applyModeBackground(-1, getMode(), false /*animate*/); |
| 48 | applyMode(getMode(), false /*animate*/); |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 49 | } |
| 50 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 51 | 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 Roos | c0f0a74 | 2014-10-28 16:39:56 +0100 | [diff] [blame] | 56 | return isLightsOut(mode) ? ICON_ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 57 | : !isOpaque(mode) ? ICON_ALPHA_WHEN_NOT_OPAQUE |
John Spurlock | e631b41 | 2013-09-18 16:33:57 -0400 | [diff] [blame] | 58 | : mIconAlphaWhenOpaque; |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | private float getBatteryClockAlpha(int mode) { |
Adrian Roos | c0f0a74 | 2014-10-28 16:39:56 +0100 | [diff] [blame] | 62 | return isLightsOut(mode) ? ICON_ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 63 | : getNonBatteryClockAlphaFor(mode); |
| 64 | } |
| 65 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 66 | private boolean isOpaque(int mode) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 67 | return !(mode == MODE_SEMI_TRANSPARENT || mode == MODE_TRANSLUCENT |
Adrian Roos | c0f0a74 | 2014-10-28 16:39:56 +0100 | [diff] [blame] | 68 | || mode == MODE_TRANSPARENT || mode == MODE_LIGHTS_OUT_TRANSPARENT); |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 69 | } |
| 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 Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 79 | 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 Laird | 4b68e2f7 | 2018-03-29 18:21:48 -0400 | [diff] [blame] | 89 | animateTransitionTo(mBattery, newAlphaBC) |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 90 | ); |
Adrian Roos | c0f0a74 | 2014-10-28 16:39:56 +0100 | [diff] [blame] | 91 | if (isLightsOut(mode)) { |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 92 | anims.setDuration(LIGHTS_OUT_DURATION); |
| 93 | } |
| 94 | anims.start(); |
| 95 | mCurrentAnimation = anims; |
| 96 | } else { |
| 97 | mLeftSide.setAlpha(newAlpha); |
| 98 | mStatusIcons.setAlpha(newAlpha); |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 99 | mBattery.setAlpha(newAlphaBC); |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 100 | } |
| 101 | } |
Matt Pietal | f07bac4 | 2020-01-29 15:07:48 -0500 | [diff] [blame] | 102 | } |