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 mode == MODE_LIGHTS_OUT ? 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 mode == MODE_LIGHTS_OUT ? 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     }
     73 
     74     @Override
     75     protected void onTransition(int oldMode, int newMode, boolean animate) {
     76         super.onTransition(oldMode, newMode, animate);
     77         applyMode(newMode, animate);
     78     }
     79 
     80     private void applyMode(int mode, boolean animate) {
     81         if (mLeftSide == null) return; // pre-init
     82         float newAlpha = getNonBatteryClockAlphaFor(mode);
     83         float newAlphaBC = getBatteryClockAlpha(mode);
     84         if (mCurrentAnimation != null) {
     85             mCurrentAnimation.cancel();
     86         }
     87         if (animate) {
     88             AnimatorSet anims = new AnimatorSet();
     89             anims.playTogether(
     90                     animateTransitionTo(mLeftSide, newAlpha),
     91                     animateTransitionTo(mStatusIcons, newAlpha),
     92                     animateTransitionTo(mSignalCluster, newAlpha),
     93                     animateTransitionTo(mBattery, newAlphaBC),
     94                     animateTransitionTo(mClock, newAlphaBC)
     95                     );
     96             if (mode == MODE_LIGHTS_OUT) {
     97                 anims.setDuration(LIGHTS_OUT_DURATION);
     98             }
     99             anims.start();
    100             mCurrentAnimation = anims;
    101         } else {
    102             mLeftSide.setAlpha(newAlpha);
    103             mStatusIcons.setAlpha(newAlpha);
    104             mSignalCluster.setAlpha(newAlpha);
    105             mBattery.setAlpha(newAlphaBC);
    106             mClock.setAlpha(newAlphaBC);
    107         }
    108     }
    109 }