Home | History | Annotate | Download | only in phone
      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;
     23 import android.view.View;
     24 
     25 import com.android.systemui.R;
     26 
     27 public final class PhoneStatusBarTransitions extends BarTransitions {
     28     private static final float ICON_ALPHA_WHEN_NOT_OPAQUE = 1;
     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;
     31 
     32     private final PhoneStatusBarView mView;
     33     private final float mIconAlphaWhenOpaque;
     34 
     35     private View mLeftSide, mStatusIcons, mSignalCluster, mBattery, mClock;
     36     private Animator mCurrentAnimation;
     37 
     38     public PhoneStatusBarTransitions(PhoneStatusBarView view) {
     39         super(view, R.drawable.status_background);
     40         mView = view;
     41         final Resources res = mView.getContext().getResources();
     42         mIconAlphaWhenOpaque = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1);
     43     }
     44 
     45     public void init() {
     46         mLeftSide = mView.findViewById(R.id.notification_icon_area);
     47         mStatusIcons = mView.findViewById(R.id.statusIcons);
     48         mSignalCluster = mView.findViewById(R.id.signal_cluster);
     49         mBattery = mView.findViewById(R.id.battery);
     50         mClock = mView.findViewById(R.id.clock);
     51         applyModeBackground(-1, getMode(), false /*animate*/);
     52         applyMode(getMode(), false /*animate*/);
     53     }
     54 
     55     public ObjectAnimator animateTransitionTo(View v, float toAlpha) {
     56         return ObjectAnimator.ofFloat(v, "alpha", v.getAlpha(), toAlpha);
     57     }
     58 
     59     private float getNonBatteryClockAlphaFor(int mode) {
     60         return isLightsOut(mode) ? ICON_ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK
     61                 : !isOpaque(mode) ? ICON_ALPHA_WHEN_NOT_OPAQUE
     62                 : mIconAlphaWhenOpaque;
     63     }
     64 
     65     private float getBatteryClockAlpha(int mode) {
     66         return isLightsOut(mode) ? ICON_ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK
     67                 : getNonBatteryClockAlphaFor(mode);
     68     }
     69 
     70     private boolean isOpaque(int mode) {
     71         return !(mode == MODE_SEMI_TRANSPARENT || mode == MODE_TRANSLUCENT
     72                 || mode == MODE_TRANSPARENT || mode == MODE_LIGHTS_OUT_TRANSPARENT);
     73     }
     74 
     75     @Override
     76     protected void onTransition(int oldMode, int newMode, boolean animate) {
     77         super.onTransition(oldMode, newMode, animate);
     78         applyMode(newMode, animate);
     79     }
     80 
     81     private void applyMode(int mode, boolean animate) {
     82         if (mLeftSide == null) return; // pre-init
     83         float newAlpha = getNonBatteryClockAlphaFor(mode);
     84         float newAlphaBC = getBatteryClockAlpha(mode);
     85         if (mCurrentAnimation != null) {
     86             mCurrentAnimation.cancel();
     87         }
     88         if (animate) {
     89             AnimatorSet anims = new AnimatorSet();
     90             anims.playTogether(
     91                     animateTransitionTo(mLeftSide, newAlpha),
     92                     animateTransitionTo(mStatusIcons, newAlpha),
     93                     animateTransitionTo(mSignalCluster, newAlpha),
     94                     animateTransitionTo(mBattery, newAlphaBC),
     95                     animateTransitionTo(mClock, newAlphaBC)
     96                     );
     97             if (isLightsOut(mode)) {
     98                 anims.setDuration(LIGHTS_OUT_DURATION);
     99             }
    100             anims.start();
    101             mCurrentAnimation = anims;
    102         } else {
    103             mLeftSide.setAlpha(newAlpha);
    104             mStatusIcons.setAlpha(newAlpha);
    105             mSignalCluster.setAlpha(newAlpha);
    106             mBattery.setAlpha(newAlphaBC);
    107             mClock.setAlpha(newAlphaBC);
    108         }
    109     }
    110 }