Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ObjectAnimator; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 22 | import android.content.Context; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 23 | import android.os.ServiceManager; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 24 | import android.util.AttributeSet; |
| 25 | import android.view.Display; |
| 26 | import android.view.KeyEvent; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 27 | import android.view.MotionEvent; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.view.Surface; |
| 30 | import android.view.WindowManager; |
| 31 | import android.widget.LinearLayout; |
| 32 | import android.content.res.Configuration; |
| 33 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 34 | import com.android.internal.statusbar.IStatusBarService; |
| 35 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 36 | import com.android.systemui.R; |
| 37 | |
| 38 | public class NavigationBarView extends LinearLayout { |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 39 | protected IStatusBarService mBarService; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 40 | final Display mDisplay; |
| 41 | View[] mRotatedViews = new View[4]; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 42 | View mBackground; |
| 43 | Animator mLastAnimator = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 44 | |
| 45 | public NavigationBarView(Context context, AttributeSet attrs) { |
| 46 | super(context, attrs); |
| 47 | mDisplay = ((WindowManager)context.getSystemService( |
| 48 | Context.WINDOW_SERVICE)).getDefaultDisplay(); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 49 | mBarService = IStatusBarService.Stub.asInterface( |
| 50 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 51 | |
| 52 | //setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 53 | |
| 54 | setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { |
| 55 | @Override |
| 56 | public void onSystemUiVisibilityChange(int visibility) { |
| 57 | boolean on = (visibility == View.STATUS_BAR_VISIBLE); |
| 58 | android.util.Log.d("NavigationBarView", "LIGHTS " |
| 59 | + (on ? "ON" : "OUT")); |
| 60 | setLights(on); |
| 61 | } |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | private void setLights(final boolean on) { |
| 66 | float oldAlpha = mBackground.getAlpha(); |
| 67 | android.util.Log.d("NavigationBarView", "animating alpha: " + oldAlpha + " -> " |
| 68 | + (on ? 1f : 0f)); |
| 69 | |
| 70 | if (mLastAnimator != null && mLastAnimator.isRunning()) mLastAnimator.cancel(); |
| 71 | |
| 72 | mLastAnimator = ObjectAnimator.ofFloat(mBackground, "alpha", oldAlpha, on ? 1f : 0f) |
| 73 | .setDuration(on ? 250 : 1500); |
| 74 | mLastAnimator.addListener(new AnimatorListenerAdapter() { |
| 75 | @Override |
| 76 | public void onAnimationEnd(Animator _a) { |
| 77 | mLastAnimator = null; |
| 78 | } |
| 79 | }); |
| 80 | mLastAnimator.start(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | public void onFinishInflate() { |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 84 | mBackground = findViewById(R.id.background); |
| 85 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 86 | mRotatedViews[Surface.ROTATION_0] = |
| 87 | mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0); |
| 88 | |
| 89 | mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90); |
| 90 | |
| 91 | mRotatedViews[Surface.ROTATION_270] = findViewById(R.id.rot270); |
| 92 | } |
| 93 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 94 | @Override |
| 95 | public boolean onTouchEvent(MotionEvent ev) { |
| 96 | // immediately bring up the lights |
| 97 | setLights(true); |
| 98 | return false; // pass it on |
| 99 | } |
| 100 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 101 | public void reorient() { |
| 102 | final int rot = mDisplay.getRotation(); |
| 103 | for (int i=0; i<4; i++) { |
| 104 | mRotatedViews[i].setVisibility(View.GONE); |
| 105 | } |
| 106 | mRotatedViews[rot].setVisibility(View.VISIBLE); |
| 107 | |
| 108 | android.util.Log.d("NavigationBarView", "reorient(): rot=" + mDisplay.getRotation()); |
| 109 | } |
| 110 | } |