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; 29 30public final class NavigationBarTransitions extends BarTransitions { 31 32 private final NavigationBarView mView; 33 private final IStatusBarService mBarService; 34 35 private boolean mLightsOut; 36 37 public NavigationBarTransitions(NavigationBarView view) { 38 super(view, R.drawable.nav_background); 39 mView = view; 40 mBarService = IStatusBarService.Stub.asInterface( 41 ServiceManager.getService(Context.STATUS_BAR_SERVICE)); 42 } 43 44 public void init() { 45 applyModeBackground(-1, getMode(), false /*animate*/); 46 applyMode(getMode(), false /*animate*/, true /*force*/); 47 } 48 49 @Override 50 protected void onTransition(int oldMode, int newMode, boolean animate) { 51 super.onTransition(oldMode, newMode, animate); 52 applyMode(newMode, animate, false /*force*/); 53 } 54 55 private void applyMode(int mode, boolean animate, boolean force) { 56 57 // apply to lights out 58 applyLightsOut(isLightsOut(mode), animate, force); 59 } 60 61 private void applyLightsOut(boolean lightsOut, boolean animate, boolean force) { 62 if (!force && lightsOut == mLightsOut) return; 63 64 mLightsOut = lightsOut; 65 66 final View navButtons = mView.getCurrentView().findViewById(R.id.nav_buttons); 67 68 // ok, everyone, stop it right there 69 navButtons.animate().cancel(); 70 71 final float navButtonsAlpha = lightsOut ? 0.5f : 1f; 72 73 if (!animate) { 74 navButtons.setAlpha(navButtonsAlpha); 75 } else { 76 final int duration = lightsOut ? LIGHTS_OUT_DURATION : LIGHTS_IN_DURATION; 77 navButtons.animate() 78 .alpha(navButtonsAlpha) 79 .setDuration(duration) 80 .start(); 81 } 82 } 83 84 private final View.OnTouchListener mLightsOutListener = new View.OnTouchListener() { 85 @Override 86 public boolean onTouch(View v, MotionEvent ev) { 87 if (ev.getAction() == MotionEvent.ACTION_DOWN) { 88 // even though setting the systemUI visibility below will turn these views 89 // on, we need them to come up faster so that they can catch this motion 90 // event 91 applyLightsOut(false, false, false); 92 93 try { 94 mBarService.setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE, 95 "LightsOutListener"); 96 } catch (android.os.RemoteException ex) { 97 } 98 } 99 return false; 100 } 101 }; 102} 103