Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Joe Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 18 | |
| 19 | import android.app.Service; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.res.Resources; |
| 23 | import android.graphics.PixelFormat; |
| 24 | import android.os.IBinder; |
| 25 | import android.os.RemoteException; |
| 26 | import android.os.ServiceManager; |
| 27 | import android.util.Slog; |
| 28 | import android.util.Log; |
| 29 | import android.view.Gravity; |
| 30 | import android.view.View; |
| 31 | import android.view.ViewGroup; |
| 32 | import android.view.WindowManager; |
| 33 | import android.view.WindowManagerImpl; |
| 34 | |
| 35 | import java.util.ArrayList; |
| 36 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 37 | import com.android.internal.statusbar.IStatusBar; |
| 38 | import com.android.internal.statusbar.IStatusBarService; |
| 39 | import com.android.internal.statusbar.StatusBarIcon; |
| 40 | import com.android.internal.statusbar.StatusBarIconList; |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 41 | import com.android.internal.statusbar.StatusBarNotification; |
| 42 | |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 43 | import com.android.systemui.R; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 44 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 45 | public abstract class StatusBarService extends Service implements CommandQueue.Callbacks { |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 46 | static final String TAG = "StatusBarService"; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 47 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 48 | protected CommandQueue mCommandQueue; |
| 49 | protected IStatusBarService mBarService; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 50 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 51 | // Up-call methods |
| 52 | protected abstract View makeStatusBarView(); |
| 53 | protected abstract int getStatusBarGravity(); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 54 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 55 | /** |
| 56 | * Nobody binds to us. |
| 57 | */ |
| 58 | @Override |
| 59 | public IBinder onBind(Intent intent) { |
| 60 | return null; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 61 | } |
| 62 | |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 63 | @Override |
| 64 | public void onCreate() { |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 65 | // First set up our views and stuff. |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 66 | View sb = makeStatusBarView(); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 67 | |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 68 | // Connect in to the status bar manager service |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 69 | StatusBarIconList iconList = new StatusBarIconList(); |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 70 | ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>(); |
| 71 | ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>(); |
Joe Onorato | 66d7d01 | 2010-05-14 10:05:10 -0700 | [diff] [blame] | 72 | mCommandQueue = new CommandQueue(this, iconList); |
Joe Onorato | 25f95f9 | 2010-04-08 18:37:10 -0500 | [diff] [blame] | 73 | mBarService = IStatusBarService.Stub.asInterface( |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 74 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 75 | try { |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 76 | mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 77 | } catch (RemoteException ex) { |
| 78 | // If the system process isn't there we're doomed anyway. |
| 79 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 80 | |
| 81 | // Set up the initial icon state |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 82 | int N = iconList.size(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 83 | int viewIndex = 0; |
| 84 | for (int i=0; i<N; i++) { |
| 85 | StatusBarIcon icon = iconList.getIcon(i); |
| 86 | if (icon != null) { |
| 87 | addIcon(iconList.getSlot(i), i, viewIndex, icon); |
| 88 | viewIndex++; |
| 89 | } |
| 90 | } |
| 91 | |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 92 | // Set up the initial notification state |
| 93 | N = notificationKeys.size(); |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 94 | if (N == notifications.size()) { |
| 95 | for (int i=0; i<N; i++) { |
| 96 | addNotification(notificationKeys.get(i), notifications.get(i)); |
| 97 | } |
| 98 | } else { |
| 99 | Log.wtf(TAG, "Notification list length mismatch: keys=" + N |
| 100 | + " notifications=" + notifications.size()); |
| 101 | } |
| 102 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 103 | // Put up the view |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 104 | final Resources res = getResources(); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 105 | final int height= res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
| 106 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 107 | final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 108 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 109 | height, |
| 110 | WindowManager.LayoutParams.TYPE_STATUS_BAR, |
| 111 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 112 | | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING, |
| 113 | PixelFormat.RGBX_8888); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 114 | lp.gravity = getStatusBarGravity(); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 115 | lp.setTitle("StatusBar"); |
| 116 | // TODO lp.windowAnimations = R.style.Animation_StatusBar; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 117 | WindowManagerImpl.getDefault().addView(sb, lp); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 118 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 119 | Slog.d(TAG, "Added status bar view w/ gravity 0x" + Integer.toHexString(lp.gravity)); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 120 | } |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 121 | } |
| 122 | |