NavigationBarTransitions.java revision bd95740648372449a4d5c164d7050eee352d4c24
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 17package com.android.systemui.statusbar.phone; 18 19import android.animation.Animator; 20import android.animation.AnimatorListenerAdapter; 21import android.content.Context; 22import android.os.ServiceManager; 23import android.view.MotionEvent; 24import android.view.View; 25import android.view.animation.AccelerateInterpolator; 26 27import com.android.internal.statusbar.IStatusBarService; 28import com.android.systemui.R; 29import com.android.systemui.statusbar.policy.KeyButtonView; 30 31public final class NavigationBarTransitions extends BarTransitions { 32 33 private final NavigationBarView mView; 34 private final IStatusBarService mBarService; 35 36 private boolean mLightsOut; 37 private boolean mVertical; 38 private int mRequestedMode; 39 40 public NavigationBarTransitions(NavigationBarView view) { 41 super(view, R.drawable.nav_background); 42 mView = view; 43 mBarService = IStatusBarService.Stub.asInterface( 44 ServiceManager.getService(Context.STATUS_BAR_SERVICE)); 45 } 46 47 public void init(boolean isVertical) { 48 setVertical(isVertical); 49 applyModeBackground(-1, getMode(), false /*animate*/); 50 applyMode(getMode(), false /*animate*/, true /*force*/); 51 } 52 53 public void setVertical(boolean isVertical) { 54 mVertical = isVertical; 55 transitionTo(mRequestedMode, false /*animate*/); 56 } 57 58 @Override 59 public void transitionTo(int mode, boolean animate) { 60 mRequestedMode = mode; 61 if (mVertical && mode == MODE_TRANSLUCENT) { 62 // translucent mode not allowed when vertical 63 mode = MODE_OPAQUE; 64 } 65 super.transitionTo(mode, animate); 66 } 67 68 @Override 69 protected void onTransition(int oldMode, int newMode, boolean animate) { 70 super.onTransition(oldMode, newMode, animate); 71 applyMode(newMode, animate, false /*force*/); 72 } 73 74 private void applyMode(int mode, boolean animate, boolean force) { 75 // apply to key buttons 76 final boolean isOpaque = mode == MODE_OPAQUE || mode == MODE_LIGHTS_OUT; 77 final float alpha = isOpaque ? KeyButtonView.DEFAULT_QUIESCENT_ALPHA : 1f; 78 setKeyButtonViewQuiescentAlpha(mView.getBackButton(), alpha, animate); 79 setKeyButtonViewQuiescentAlpha(mView.getHomeButton(), alpha, animate); 80 setKeyButtonViewQuiescentAlpha(mView.getRecentsButton(), alpha, animate); 81 setKeyButtonViewQuiescentAlpha(mView.getMenuButton(), alpha, animate); 82 setKeyButtonViewQuiescentAlpha(mView.getCameraButton(), alpha, animate); 83 84 // apply to lights out 85 applyLightsOut(mode == MODE_LIGHTS_OUT, animate, force); 86 } 87 88 private void setKeyButtonViewQuiescentAlpha(View button, float alpha, boolean animate) { 89 if (button instanceof KeyButtonView) { 90 ((KeyButtonView) button).setQuiescentAlpha(alpha, animate); 91 } 92 } 93 94 private void applyLightsOut(boolean lightsOut, boolean animate, boolean force) { 95 if (!force && lightsOut == mLightsOut) return; 96 97 mLightsOut = lightsOut; 98 99 final View navButtons = mView.getCurrentView().findViewById(R.id.nav_buttons); 100 final View lowLights = mView.getCurrentView().findViewById(R.id.lights_out); 101 102 // ok, everyone, stop it right there 103 navButtons.animate().cancel(); 104 lowLights.animate().cancel(); 105 106 final float navButtonsAlpha = lightsOut ? 0f : 1f; 107 final float lowLightsAlpha = lightsOut ? 1f : 0f; 108 109 if (!animate) { 110 navButtons.setAlpha(navButtonsAlpha); 111 lowLights.setAlpha(lowLightsAlpha); 112 lowLights.setVisibility(lightsOut ? View.VISIBLE : View.GONE); 113 } else { 114 final int duration = lightsOut ? LIGHTS_OUT_DURATION : LIGHTS_IN_DURATION; 115 navButtons.animate() 116 .alpha(navButtonsAlpha) 117 .setDuration(duration) 118 .start(); 119 120 lowLights.setOnTouchListener(mLightsOutListener); 121 if (lowLights.getVisibility() == View.GONE) { 122 lowLights.setAlpha(0f); 123 lowLights.setVisibility(View.VISIBLE); 124 } 125 lowLights.animate() 126 .alpha(lowLightsAlpha) 127 .setDuration(duration) 128 .setInterpolator(new AccelerateInterpolator(2.0f)) 129 .setListener(lightsOut ? null : new AnimatorListenerAdapter() { 130 @Override 131 public void onAnimationEnd(Animator _a) { 132 lowLights.setVisibility(View.GONE); 133 } 134 }) 135 .start(); 136 } 137 } 138 139 private final View.OnTouchListener mLightsOutListener = new View.OnTouchListener() { 140 @Override 141 public boolean onTouch(View v, MotionEvent ev) { 142 if (ev.getAction() == MotionEvent.ACTION_DOWN) { 143 // even though setting the systemUI visibility below will turn these views 144 // on, we need them to come up faster so that they can catch this motion 145 // event 146 applyLightsOut(false, false, false); 147 148 try { 149 mBarService.setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE); 150 } catch (android.os.RemoteException ex) { 151 } 152 } 153 return false; 154 } 155 }; 156} 157