blob: 7d6c57bbf8991645d8374d49184656f937863aff [file] [log] [blame]
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001/*
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
17package com.android.systemui.statusbar.phone;
18
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
21import android.animation.ObjectAnimator;
Daniel Sandler8956dbb2011-04-22 07:55:02 -040022import android.content.Context;
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040023import android.os.ServiceManager;
Daniel Sandler8956dbb2011-04-22 07:55:02 -040024import android.util.AttributeSet;
25import android.view.Display;
26import android.view.KeyEvent;
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040027import android.view.MotionEvent;
Daniel Sandler8956dbb2011-04-22 07:55:02 -040028import android.view.View;
29import android.view.Surface;
30import android.view.WindowManager;
31import android.widget.LinearLayout;
32import android.content.res.Configuration;
33
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040034import com.android.internal.statusbar.IStatusBarService;
35
Daniel Sandler8956dbb2011-04-22 07:55:02 -040036import com.android.systemui.R;
37
38public class NavigationBarView extends LinearLayout {
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040039 protected IStatusBarService mBarService;
Daniel Sandler8956dbb2011-04-22 07:55:02 -040040 final Display mDisplay;
41 View[] mRotatedViews = new View[4];
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040042 View mBackground;
43 Animator mLastAnimator = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -040044
45 public NavigationBarView(Context context, AttributeSet attrs) {
46 super(context, attrs);
47 mDisplay = ((WindowManager)context.getSystemService(
48 Context.WINDOW_SERVICE)).getDefaultDisplay();
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040049 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 Sandler8956dbb2011-04-22 07:55:02 -040081 }
82
83 public void onFinishInflate() {
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040084 mBackground = findViewById(R.id.background);
85
Daniel Sandler8956dbb2011-04-22 07:55:02 -040086 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 Sandler1d4d30a2011-04-28 12:35:29 -040094 @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 Sandler8956dbb2011-04-22 07:55:02 -0400101 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}