Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [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 | |
| 17 | package com.android.systemui.statusbar.tablet; |
| 18 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 19 | import java.io.FileDescriptor; |
| 20 | import java.io.PrintWriter; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 21 | import java.util.ArrayList; |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 22 | import java.util.Map; |
| 23 | import java.util.IdentityHashMap; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 24 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 25 | import android.animation.LayoutTransition; |
| 26 | import android.animation.ObjectAnimator; |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 27 | import android.animation.AnimatorSet; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 28 | import android.app.ActivityManagerNative; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 29 | import android.app.PendingIntent; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 30 | import android.app.Notification; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 31 | import android.app.StatusBarManager; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 34 | import android.content.res.Configuration; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 35 | import android.content.res.Resources; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 36 | import android.graphics.PixelFormat; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 37 | import android.graphics.Rect; |
Joe Onorato | 4daaeaf | 2010-11-17 20:43:12 -0800 | [diff] [blame] | 38 | import android.graphics.drawable.Drawable; |
| 39 | import android.graphics.drawable.LayerDrawable; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 40 | import android.os.Handler; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 41 | import android.os.IBinder; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 42 | import android.os.Message; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 43 | import android.os.RemoteException; |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 44 | import android.os.ServiceManager; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 45 | import android.text.TextUtils; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 46 | import android.util.Slog; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 47 | import android.view.animation.Animation; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 48 | import android.view.animation.AnimationUtils; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 49 | import android.view.Gravity; |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 50 | import android.view.IWindowManager; |
| 51 | import android.view.KeyEvent; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 52 | import android.view.LayoutInflater; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 53 | import android.view.MotionEvent; |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 54 | import android.view.VelocityTracker; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 55 | import android.view.View; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 56 | import android.view.ViewConfiguration; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 57 | import android.view.ViewGroup; |
| 58 | import android.view.WindowManager; |
| 59 | import android.view.WindowManagerImpl; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 60 | import android.widget.FrameLayout; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 61 | import android.widget.ImageView; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 62 | import android.widget.LinearLayout; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 63 | import android.widget.RemoteViews; |
| 64 | import android.widget.ScrollView; |
| 65 | import android.widget.TextSwitcher; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 66 | import android.widget.TextView; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 67 | |
| 68 | import com.android.internal.statusbar.StatusBarIcon; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 69 | import com.android.internal.statusbar.StatusBarNotification; |
| 70 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 71 | import com.android.systemui.R; |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 72 | import com.android.systemui.statusbar.*; |
| 73 | import com.android.systemui.statusbar.policy.BatteryController; |
| 74 | import com.android.systemui.statusbar.policy.NetworkController; |
| 75 | import com.android.systemui.recent.RecentApplicationsActivity; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 76 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 77 | public class TabletStatusBar extends StatusBar { |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 78 | public static final boolean DEBUG = false; |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 79 | public static final String TAG = "TabletStatusBar"; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 80 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 81 | public static final int MAX_NOTIFICATION_ICONS = 5; |
| 82 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 83 | public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; |
| 84 | public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 85 | public static final int MSG_OPEN_NOTIFICATION_PEEK = 1002; |
| 86 | public static final int MSG_CLOSE_NOTIFICATION_PEEK = 1003; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 87 | public static final int MSG_OPEN_RECENTS_PANEL = 1020; |
| 88 | public static final int MSG_CLOSE_RECENTS_PANEL = 1021; |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 89 | public static final int MSG_SHOW_CHROME = 1030; |
| 90 | public static final int MSG_HIDE_CHROME = 1031; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 91 | |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 92 | // Fitts' Law assistance for LatinIME; TODO: replace with a more general approach |
| 93 | private static final boolean FAKE_SPACE_BAR = true; |
| 94 | |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 95 | private static final int MAX_IMAGE_LEVEL = 10000; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 96 | private static final boolean USE_2D_RECENTS = true; |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 97 | |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 98 | public static final int LIGHTS_ON_DELAY = 5000; |
| 99 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 100 | int mBarHeight = -1; |
| 101 | int mIconSize = -1; |
| 102 | int mIconHPadding = -1; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 103 | |
| 104 | H mHandler = new H(); |
| 105 | |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 106 | IWindowManager mWindowManager; |
| 107 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 108 | // tracking all current notifications |
| 109 | private NotificationData mNotns = new NotificationData(); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 110 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 111 | TabletStatusBarView mStatusBarView; |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 112 | View mNotificationArea; |
| 113 | View mNotificationTrigger; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 114 | NotificationIconArea mNotificationIconArea; |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 115 | View mNavigationArea; |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 116 | |
Joe Onorato | 536c58f | 2010-11-28 17:52:28 -0800 | [diff] [blame] | 117 | ImageView mBackButton; |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 118 | View mHomeButton; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 119 | View mMenuButton; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 120 | View mRecentButton; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 121 | |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 122 | InputMethodButton mInputMethodSwitchButton; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 123 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 124 | NotificationPanel mNotificationPanel; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 125 | NotificationPeekPanel mNotificationPeekWindow; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 126 | ViewGroup mNotificationPeekRow; |
| 127 | int mNotificationPeekIndex; |
Daniel Sandler | a8e5b06 | 2010-12-01 13:53:08 -0500 | [diff] [blame] | 128 | IBinder mNotificationPeekKey; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 129 | LayoutTransition mNotificationPeekScrubLeft, mNotificationPeekScrubRight; |
| 130 | |
| 131 | int mNotificationPeekTapDuration; |
| 132 | int mNotificationFlingVelocity; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 133 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 134 | ViewGroup mPile; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 135 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 136 | BatteryController mBatteryController; |
| 137 | NetworkController mNetworkController; |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 138 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 139 | View mBarContents; |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 140 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 141 | // hide system chrome ("lights out") support |
| 142 | View mShadow; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 143 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 144 | NotificationIconArea.IconLayout mIconLayout; |
| 145 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 146 | TabletTicker mTicker; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 147 | |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 148 | View mFakeSpaceBar; |
| 149 | KeyEvent mSpaceBarKeyEvent = null; |
| 150 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 151 | // for disabling the status bar |
| 152 | int mDisabled = 0; |
| 153 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 154 | boolean mNotificationsOn = true; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 155 | private RecentAppsPanel mRecentsPanel; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 156 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 157 | protected void addPanelWindows() { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 158 | final Context context = mContext; |
| 159 | |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 160 | // Notification Panel |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 161 | mNotificationPanel = (NotificationPanel)View.inflate(context, |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 162 | R.layout.status_bar_notification_panel, null); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 163 | mNotificationPanel.show(false, false); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 164 | mNotificationPanel.setOnTouchListener( |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 165 | new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel)); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 166 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 167 | // the battery and network icons |
| 168 | mBatteryController.addIconView((ImageView)mNotificationPanel.findViewById(R.id.battery)); |
| 169 | mBatteryController.addLabelView( |
| 170 | (TextView)mNotificationPanel.findViewById(R.id.battery_text)); |
Joe Onorato | ddbba42 | 2010-11-23 15:42:28 -0800 | [diff] [blame] | 171 | mNetworkController.addCombinedSignalIconView( |
Joe Onorato | 42f8e13 | 2010-11-29 15:52:43 -0800 | [diff] [blame] | 172 | (ImageView)mNotificationPanel.findViewById(R.id.network_signal)); |
| 173 | mNetworkController.addDataTypeIconView( |
| 174 | (ImageView)mNotificationPanel.findViewById(R.id.network_type)); |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 175 | mNetworkController.addLabelView( |
| 176 | (TextView)mNotificationPanel.findViewById(R.id.network_text)); |
Daniel Sandler | 3e8f5a2 | 2010-12-03 14:52:10 -0500 | [diff] [blame] | 177 | mNetworkController.addLabelView( |
| 178 | (TextView)mBarContents.findViewById(R.id.network_text)); |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 179 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 180 | mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 181 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 182 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Joe Onorato | 4cddc98 | 2010-11-21 11:48:15 -0800 | [diff] [blame] | 183 | ViewGroup.LayoutParams.MATCH_PARENT, |
Joe Onorato | cf2b199 | 2010-11-16 21:36:42 -0800 | [diff] [blame] | 184 | ViewGroup.LayoutParams.MATCH_PARENT, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 185 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 186 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame] | 187 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 188 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 189 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 190 | PixelFormat.TRANSLUCENT); |
Joe Onorato | ea70e63 | 2010-09-27 17:59:37 -0700 | [diff] [blame] | 191 | lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 192 | lp.setTitle("NotificationPanel"); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 193 | lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED |
| 194 | | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 195 | lp.windowAnimations = com.android.internal.R.style.Animation; // == no animation |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 196 | |
| 197 | WindowManagerImpl.getDefault().addView(mNotificationPanel, lp); |
| 198 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 199 | // Notification preview window |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 200 | mNotificationPeekWindow = (NotificationPeekPanel) View.inflate(context, |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 201 | R.layout.status_bar_notification_peek, null); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 202 | mNotificationPeekRow = (ViewGroup) mNotificationPeekWindow.findViewById(R.id.content); |
| 203 | mNotificationPeekWindow.setVisibility(View.GONE); |
| 204 | mNotificationPeekWindow.setOnTouchListener( |
Joe Onorato | 5e75946 | 2010-11-28 17:43:50 -0800 | [diff] [blame] | 205 | new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PEEK, mNotificationPeekWindow)); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 206 | mNotificationPeekScrubRight = new LayoutTransition(); |
| 207 | mNotificationPeekScrubRight.setAnimator(LayoutTransition.APPEARING, |
| 208 | ObjectAnimator.ofInt(null, "left", -512, 0)); |
| 209 | mNotificationPeekScrubRight.setAnimator(LayoutTransition.DISAPPEARING, |
| 210 | ObjectAnimator.ofInt(null, "left", -512, 0)); |
| 211 | mNotificationPeekScrubRight.setDuration(500); |
| 212 | |
| 213 | mNotificationPeekScrubLeft = new LayoutTransition(); |
| 214 | mNotificationPeekScrubLeft.setAnimator(LayoutTransition.APPEARING, |
| 215 | ObjectAnimator.ofInt(null, "left", 512, 0)); |
| 216 | mNotificationPeekScrubLeft.setAnimator(LayoutTransition.DISAPPEARING, |
| 217 | ObjectAnimator.ofInt(null, "left", 512, 0)); |
| 218 | mNotificationPeekScrubLeft.setDuration(500); |
| 219 | |
| 220 | // XXX: setIgnoreChildren? |
| 221 | lp = new WindowManager.LayoutParams( |
| 222 | 512, // ViewGroup.LayoutParams.WRAP_CONTENT, |
| 223 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 224 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 225 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame] | 226 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
| 227 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 228 | PixelFormat.TRANSLUCENT); |
| 229 | lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; |
| 230 | lp.setTitle("NotificationPeekWindow"); |
| 231 | lp.windowAnimations = com.android.internal.R.style.Animation_Toast; |
| 232 | |
| 233 | WindowManagerImpl.getDefault().addView(mNotificationPeekWindow, lp); |
| 234 | |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 235 | // Recents Panel |
| 236 | if (USE_2D_RECENTS) { |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 237 | mRecentsPanel = (RecentAppsPanel) View.inflate(context, |
| 238 | R.layout.status_bar_recent_panel, null); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 239 | mRecentsPanel.setVisibility(View.GONE); |
| 240 | mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, |
| 241 | mRecentsPanel)); |
| 242 | mStatusBarView.setIgnoreChildren(2, mRecentButton, mRecentsPanel); |
| 243 | |
| 244 | lp = new WindowManager.LayoutParams( |
| 245 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 246 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 247 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 248 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame] | 249 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
Jim Miller | 169a211 | 2010-12-10 18:30:07 -0800 | [diff] [blame] | 250 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 251 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 252 | PixelFormat.TRANSLUCENT); |
| 253 | lp.gravity = Gravity.BOTTOM | Gravity.LEFT; |
| 254 | lp.setTitle("RecentsPanel"); |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 255 | lp.windowAnimations = R.style.Animation_RecentPanel; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 256 | |
| 257 | WindowManagerImpl.getDefault().addView(mRecentsPanel, lp); |
| 258 | mRecentsPanel.setBar(this); |
| 259 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 260 | } |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 261 | |
| 262 | @Override |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 263 | public void start() { |
| 264 | super.start(); // will add the main bar view |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 265 | } |
| 266 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 267 | @Override |
| 268 | protected void onConfigurationChanged (Configuration newConfig) { |
| 269 | loadDimens(); |
| 270 | } |
| 271 | |
| 272 | protected void loadDimens() { |
| 273 | final Resources res = mContext.getResources(); |
| 274 | |
| 275 | mBarHeight = res.getDimensionPixelSize( |
| 276 | com.android.internal.R.dimen.status_bar_height); |
| 277 | |
| 278 | int newIconSize = res.getDimensionPixelSize( |
| 279 | com.android.internal.R.dimen.status_bar_icon_size); |
| 280 | int newIconHPadding = res.getDimensionPixelSize( |
| 281 | R.dimen.status_bar_icon_padding); |
| 282 | |
| 283 | if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) { |
| 284 | // Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding); |
| 285 | mIconHPadding = newIconHPadding; |
| 286 | mIconSize = newIconSize; |
| 287 | reloadAllNotificationIcons(); // reload the tray |
| 288 | } |
| 289 | } |
| 290 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 291 | protected View makeStatusBarView() { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 292 | final Context context = mContext; |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 293 | |
| 294 | mWindowManager = IWindowManager.Stub.asInterface( |
| 295 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 296 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 297 | loadDimens(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 298 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 299 | final TabletStatusBarView sb = (TabletStatusBarView)View.inflate( |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 300 | context, R.layout.status_bar, null); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 301 | mStatusBarView = sb; |
| 302 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 303 | sb.setHandler(mHandler); |
| 304 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 305 | mBarContents = sb.findViewById(R.id.bar_contents); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 306 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 307 | // the whole right-hand side of the bar |
| 308 | mNotificationArea = sb.findViewById(R.id.notificationArea); |
| 309 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 310 | // the button to open the notification area |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 311 | mNotificationTrigger = sb.findViewById(R.id.notificationTrigger); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 312 | mNotificationTrigger.setOnClickListener(mOnClickListener); |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 313 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 314 | // the more notifications icon |
| 315 | mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons); |
| 316 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 317 | // where the icons go |
| 318 | mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 319 | mIconLayout.setOnTouchListener(new NotificationIconTouchListener()); |
| 320 | |
| 321 | ViewConfiguration vc = ViewConfiguration.get(context); |
| 322 | mNotificationPeekTapDuration = vc.getTapTimeout(); |
| 323 | mNotificationFlingVelocity = 300; // px/s |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 324 | |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 325 | mTicker = new TabletTicker(context); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 326 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 327 | // The icons |
| 328 | mBatteryController = new BatteryController(mContext); |
| 329 | mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery)); |
| 330 | mNetworkController = new NetworkController(mContext); |
Joe Onorato | 42f8e13 | 2010-11-29 15:52:43 -0800 | [diff] [blame] | 331 | mNetworkController.addCombinedSignalIconView( |
| 332 | (ImageView)sb.findViewById(R.id.network_signal)); |
| 333 | mNetworkController.addDataTypeIconView( |
| 334 | (ImageView)sb.findViewById(R.id.network_type)); |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 335 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 336 | // The navigation buttons |
| 337 | mNavigationArea = sb.findViewById(R.id.navigationArea); |
Joe Onorato | 536c58f | 2010-11-28 17:52:28 -0800 | [diff] [blame] | 338 | mBackButton = (ImageView)mNavigationArea.findViewById(R.id.back); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 339 | mHomeButton = mNavigationArea.findViewById(R.id.home); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 340 | mMenuButton = mNavigationArea.findViewById(R.id.menu); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 341 | mRecentButton = mNavigationArea.findViewById(R.id.recent_apps); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 342 | mRecentButton.setOnClickListener(mOnClickListener); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 343 | |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 344 | // The bar contents buttons |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 345 | mInputMethodSwitchButton = (InputMethodButton) sb.findViewById(R.id.imeSwitchButton); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 346 | |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 347 | // for redirecting errant bar taps to the IME |
| 348 | mFakeSpaceBar = sb.findViewById(R.id.fake_space_bar); |
| 349 | |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 350 | // "shadows" of the status bar features, for lights-out mode |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 351 | mShadow = sb.findViewById(R.id.bar_shadow); |
| 352 | mShadow.setOnTouchListener( |
| 353 | new View.OnTouchListener() { |
| 354 | public boolean onTouch(View v, MotionEvent ev) { |
| 355 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 356 | mShadow.setVisibility(View.GONE); |
| 357 | mBarContents.setVisibility(View.VISIBLE); |
| 358 | } |
| 359 | return false; |
| 360 | } |
| 361 | }); |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 362 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 363 | // tuning parameters |
| 364 | final int LIGHTS_GOING_OUT_SYSBAR_DURATION = 600; |
| 365 | final int LIGHTS_GOING_OUT_SHADOW_DURATION = 1000; |
| 366 | final int LIGHTS_GOING_OUT_SHADOW_DELAY = 500; |
| 367 | |
| 368 | final int LIGHTS_COMING_UP_SYSBAR_DURATION = 200; |
| 369 | // final int LIGHTS_COMING_UP_SYSBAR_DELAY = 50; |
| 370 | final int LIGHTS_COMING_UP_SHADOW_DURATION = 0; |
| 371 | |
| 372 | LayoutTransition xition = new LayoutTransition(); |
| 373 | xition.setAnimator(LayoutTransition.APPEARING, |
| 374 | ObjectAnimator.ofFloat(null, "alpha", 0.5f, 1f)); |
| 375 | xition.setDuration(LayoutTransition.APPEARING, LIGHTS_COMING_UP_SYSBAR_DURATION); |
| 376 | xition.setStartDelay(LayoutTransition.APPEARING, 0); |
| 377 | xition.setAnimator(LayoutTransition.DISAPPEARING, |
| 378 | ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); |
| 379 | xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_GOING_OUT_SYSBAR_DURATION); |
| 380 | xition.setStartDelay(LayoutTransition.DISAPPEARING, 0); |
| 381 | ((ViewGroup)sb.findViewById(R.id.bar_contents_holder)).setLayoutTransition(xition); |
| 382 | |
| 383 | xition = new LayoutTransition(); |
| 384 | xition.setAnimator(LayoutTransition.APPEARING, |
| 385 | ObjectAnimator.ofFloat(null, "alpha", 0f, 1f)); |
| 386 | xition.setDuration(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DURATION); |
| 387 | xition.setStartDelay(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DELAY); |
| 388 | xition.setAnimator(LayoutTransition.DISAPPEARING, |
| 389 | ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); |
| 390 | xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_COMING_UP_SHADOW_DURATION); |
| 391 | xition.setStartDelay(LayoutTransition.DISAPPEARING, 0); |
| 392 | ((ViewGroup)sb.findViewById(R.id.bar_shadow_holder)).setLayoutTransition(xition); |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 393 | |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 394 | // set the initial view visibility |
| 395 | setAreThereNotifications(); |
| 396 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 397 | // Add the windows |
| 398 | addPanelWindows(); |
| 399 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 400 | mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content); |
| 401 | mPile.removeAllViews(); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 402 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 403 | ScrollView scroller = (ScrollView)mPile.getParent(); |
| 404 | scroller.setFillViewport(true); |
| 405 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 406 | return sb; |
| 407 | } |
| 408 | |
| 409 | protected int getStatusBarGravity() { |
| 410 | return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL; |
| 411 | } |
| 412 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 413 | private class H extends Handler { |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 414 | public void handleMessage(Message m) { |
| 415 | switch (m.what) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 416 | case MSG_OPEN_NOTIFICATION_PEEK: |
| 417 | if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1); |
| 418 | if (m.arg1 >= 0) { |
| 419 | final int N = mNotns.size(); |
Daniel Sandler | a8e5b06 | 2010-12-01 13:53:08 -0500 | [diff] [blame] | 420 | if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 421 | NotificationData.Entry entry = mNotns.get(N-1-mNotificationPeekIndex); |
| 422 | entry.icon.setBackgroundColor(0); |
Daniel Sandler | a8e5b06 | 2010-12-01 13:53:08 -0500 | [diff] [blame] | 423 | mNotificationPeekIndex = -1; |
| 424 | mNotificationPeekKey = null; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | final int peekIndex = m.arg1; |
| 428 | if (peekIndex < N) { |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 429 | //Slog.d(TAG, "loading peek: " + peekIndex); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 430 | NotificationData.Entry entry = mNotns.get(N-1-peekIndex); |
| 431 | NotificationData.Entry copy = new NotificationData.Entry( |
| 432 | entry.key, |
| 433 | entry.notification, |
| 434 | entry.icon); |
| 435 | inflateViews(copy, mNotificationPeekRow); |
| 436 | |
| 437 | entry.icon.setBackgroundColor(0x20FFFFFF); |
| 438 | |
| 439 | // mNotificationPeekRow.setLayoutTransition( |
| 440 | // peekIndex < mNotificationPeekIndex |
| 441 | // ? mNotificationPeekScrubLeft |
| 442 | // : mNotificationPeekScrubRight); |
| 443 | |
| 444 | mNotificationPeekRow.removeAllViews(); |
| 445 | mNotificationPeekRow.addView(copy.row); |
| 446 | |
| 447 | mNotificationPeekWindow.setVisibility(View.VISIBLE); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 448 | mNotificationPanel.show(false, true); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 449 | |
| 450 | mNotificationPeekIndex = peekIndex; |
Daniel Sandler | a8e5b06 | 2010-12-01 13:53:08 -0500 | [diff] [blame] | 451 | mNotificationPeekKey = entry.key; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | break; |
| 455 | case MSG_CLOSE_NOTIFICATION_PEEK: |
| 456 | if (DEBUG) Slog.d(TAG, "closing notification peek window"); |
| 457 | mNotificationPeekWindow.setVisibility(View.GONE); |
| 458 | mNotificationPeekRow.removeAllViews(); |
| 459 | final int N = mNotns.size(); |
Daniel Sandler | a8e5b06 | 2010-12-01 13:53:08 -0500 | [diff] [blame] | 460 | if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 461 | NotificationData.Entry entry = mNotns.get(N-1-mNotificationPeekIndex); |
| 462 | entry.icon.setBackgroundColor(0); |
| 463 | } |
Daniel Sandler | a8e5b06 | 2010-12-01 13:53:08 -0500 | [diff] [blame] | 464 | |
| 465 | mNotificationPeekIndex = -1; |
| 466 | mNotificationPeekKey = null; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 467 | break; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 468 | case MSG_OPEN_NOTIFICATION_PANEL: |
| 469 | if (DEBUG) Slog.d(TAG, "opening notifications panel"); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 470 | if (!mNotificationPanel.isShowing()) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 471 | mNotificationPeekWindow.setVisibility(View.GONE); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 472 | mNotificationPanel.show(true, true); |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 473 | mNotificationArea.setVisibility(View.GONE); |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 474 | mTicker.halt(); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 475 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 476 | break; |
| 477 | case MSG_CLOSE_NOTIFICATION_PANEL: |
| 478 | if (DEBUG) Slog.d(TAG, "closing notifications panel"); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 479 | if (mNotificationPanel.isShowing()) { |
| 480 | mNotificationPanel.show(false, true); |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 481 | mNotificationArea.setVisibility(View.VISIBLE); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 482 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 483 | break; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 484 | case MSG_OPEN_RECENTS_PANEL: |
| 485 | if (DEBUG) Slog.d(TAG, "opening recents panel"); |
| 486 | if (mRecentsPanel != null) mRecentsPanel.setVisibility(View.VISIBLE); |
| 487 | break; |
| 488 | case MSG_CLOSE_RECENTS_PANEL: |
| 489 | if (DEBUG) Slog.d(TAG, "closing recents panel"); |
| 490 | if (mRecentsPanel != null) mRecentsPanel.setVisibility(View.GONE); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 491 | break; |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 492 | case MSG_SHOW_CHROME: |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 493 | if (DEBUG) Slog.d(TAG, "hiding shadows (lights on)"); |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 494 | mBarContents.setVisibility(View.VISIBLE); |
| 495 | mShadow.setVisibility(View.GONE); |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 496 | break; |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 497 | case MSG_HIDE_CHROME: |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 498 | if (DEBUG) Slog.d(TAG, "showing shadows (lights out)"); |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 499 | animateCollapse(); |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 500 | mBarContents.setVisibility(View.GONE); |
| 501 | mShadow.setVisibility(View.VISIBLE); |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 502 | break; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | } |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 506 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 507 | public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 508 | if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | public void updateIcon(String slot, int index, int viewIndex, |
| 512 | StatusBarIcon old, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 513 | if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | public void removeIcon(String slot, int index, int viewIndex) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 517 | if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")"); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | public void addNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 521 | if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")"); |
| 522 | addNotificationViews(key, notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 523 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 524 | final boolean immersive = isImmersive(); |
Joe Onorato | cf2b199 | 2010-11-16 21:36:42 -0800 | [diff] [blame] | 525 | if (false && immersive) { |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 526 | // TODO: immersive mode popups for tablet |
| 527 | } else if (notification.notification.fullScreenIntent != null) { |
| 528 | // not immersive & a full-screen alert should be shown |
| 529 | Slog.d(TAG, "Notification has fullScreenIntent and activity is not immersive;" |
| 530 | + " sending fullScreenIntent"); |
| 531 | try { |
| 532 | notification.notification.fullScreenIntent.send(); |
| 533 | } catch (PendingIntent.CanceledException e) { |
| 534 | } |
| 535 | } else { |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 536 | tick(key, notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 537 | } |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 538 | |
| 539 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 543 | if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO"); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 544 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 545 | final NotificationData.Entry oldEntry = mNotns.findByKey(key); |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 546 | if (oldEntry == null) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 547 | Slog.w(TAG, "updateNotification for unknown key: " + key); |
| 548 | return; |
| 549 | } |
| 550 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 551 | final StatusBarNotification oldNotification = oldEntry.notification; |
| 552 | final RemoteViews oldContentView = oldNotification.notification.contentView; |
| 553 | |
| 554 | final RemoteViews contentView = notification.notification.contentView; |
| 555 | |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 556 | if (DEBUG) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 557 | Slog.d(TAG, "old notification: when=" + oldNotification.notification.when |
| 558 | + " ongoing=" + oldNotification.isOngoing() |
| 559 | + " expanded=" + oldEntry.expanded |
| 560 | + " contentView=" + oldContentView); |
| 561 | Slog.d(TAG, "new notification: when=" + notification.notification.when |
| 562 | + " ongoing=" + oldNotification.isOngoing() |
| 563 | + " contentView=" + contentView); |
| 564 | } |
| 565 | |
| 566 | // Can we just reapply the RemoteViews in place? If when didn't change, the order |
| 567 | // didn't change. |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 568 | boolean orderUnchanged = (notification.notification.when == oldNotification.notification.when |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 569 | && notification.isOngoing() == oldNotification.isOngoing() |
| 570 | && oldEntry.expanded != null |
| 571 | && contentView != null |
| 572 | && oldContentView != null |
| 573 | && contentView.getPackage() != null |
| 574 | && oldContentView.getPackage() != null |
| 575 | && oldContentView.getPackage().equals(contentView.getPackage()) |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 576 | && oldContentView.getLayoutId() == contentView.getLayoutId()); |
| 577 | ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent(); |
| 578 | boolean isLastAnyway = rowParent.indexOfChild(oldEntry.row) == rowParent.getChildCount() - 1; |
| 579 | if (orderUnchanged || isLastAnyway) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 580 | if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key); |
| 581 | oldEntry.notification = notification; |
| 582 | try { |
| 583 | // Reapply the RemoteViews |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 584 | contentView.reapply(mContext, oldEntry.content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 585 | // update the contentIntent |
| 586 | final PendingIntent contentIntent = notification.notification.contentIntent; |
| 587 | if (contentIntent != null) { |
| 588 | oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent, |
| 589 | notification.pkg, notification.tag, notification.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 590 | } else { |
| 591 | oldEntry.content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 592 | } |
| 593 | // Update the icon. |
| 594 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 595 | notification.notification.icon, notification.notification.iconLevel, |
| 596 | notification.notification.number); |
| 597 | if (!oldEntry.icon.set(ic)) { |
| 598 | handleNotificationError(key, notification, "Couldn't update icon: " + ic); |
| 599 | return; |
| 600 | } |
| 601 | } |
| 602 | catch (RuntimeException e) { |
| 603 | // It failed to add cleanly. Log, and remove the view from the panel. |
| 604 | Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); |
| 605 | removeNotificationViews(key); |
| 606 | addNotificationViews(key, notification); |
| 607 | } |
| 608 | } else { |
| 609 | if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key); |
| 610 | removeNotificationViews(key); |
| 611 | addNotificationViews(key, notification); |
| 612 | } |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 613 | // fullScreenIntent doesn't happen on updates. You need to clear & repost a new |
| 614 | // notification. |
| 615 | final boolean immersive = isImmersive(); |
| 616 | if (false && immersive) { |
| 617 | // TODO: immersive mode |
| 618 | } else { |
| 619 | tick(key, notification); |
| 620 | } |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 621 | |
| 622 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | public void removeNotification(IBinder key) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 626 | if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ") // TODO"); |
| 627 | removeNotificationViews(key); |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 628 | mTicker.remove(key); |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 629 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Daniel Sandler | 3e8f5a2 | 2010-12-03 14:52:10 -0500 | [diff] [blame] | 632 | public void showClock(boolean show) { |
| 633 | View clock = mBarContents.findViewById(R.id.clock); |
| 634 | View network_text = mBarContents.findViewById(R.id.network_text); |
| 635 | if (clock != null) { |
| 636 | clock.setVisibility(show ? View.VISIBLE : View.GONE); |
| 637 | } |
| 638 | if (network_text != null) { |
| 639 | network_text.setVisibility((!show) ? View.VISIBLE : View.GONE); |
| 640 | } |
| 641 | } |
| 642 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 643 | public void disable(int state) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 644 | int old = mDisabled; |
| 645 | int diff = state ^ old; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 646 | mDisabled = state; |
| 647 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 648 | // act accordingly |
Daniel Sandler | 3e8f5a2 | 2010-12-03 14:52:10 -0500 | [diff] [blame] | 649 | if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) { |
| 650 | boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0; |
| 651 | Slog.d(TAG, "DISABLE_CLOCK: " + (show ? "no" : "yes")); |
| 652 | showClock(show); |
| 653 | } |
Daniel Sandler | 6f6cf3c | 2010-12-16 12:54:03 -0500 | [diff] [blame^] | 654 | if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { |
| 655 | boolean show = (state & StatusBarManager.DISABLE_SYSTEM_INFO) == 0; |
| 656 | Slog.d(TAG, "DISABLE_SYSTEM_INFO: " + (show ? "no" : "yes")); |
| 657 | mNotificationTrigger.setVisibility(show ? View.VISIBLE : View.GONE); |
| 658 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 659 | if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 660 | if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 661 | Slog.d(TAG, "DISABLE_EXPAND: yes"); |
| 662 | animateCollapse(); |
| 663 | } |
| 664 | } |
| 665 | if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 666 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 667 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 668 | // synchronize with current shadow state |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 669 | mNotificationIconArea.setVisibility(View.GONE); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 670 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 671 | } else { |
| 672 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 673 | // synchronize with current shadow state |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 674 | mNotificationIconArea.setVisibility(View.VISIBLE); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 675 | } |
| 676 | } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 677 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 678 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 679 | } |
| 680 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 681 | if ((diff & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 682 | if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 683 | Slog.d(TAG, "DISABLE_NAVIGATION: yes"); |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 684 | mNavigationArea.setVisibility(View.GONE); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 685 | } else { |
| 686 | Slog.d(TAG, "DISABLE_NAVIGATION: no"); |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 687 | mNavigationArea.setVisibility(View.VISIBLE); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 688 | } |
| 689 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 690 | } |
| 691 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 692 | private boolean hasTicker(Notification n) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 693 | return n.tickerView != null || !TextUtils.isEmpty(n.tickerText); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 694 | } |
| 695 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 696 | private void tick(IBinder key, StatusBarNotification n) { |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 697 | // Don't show the ticker when the windowshade is open. |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 698 | if (mNotificationPanel.isShowing()) { |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 699 | return; |
| 700 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 701 | // Show the ticker if one is requested. Also don't do this |
| 702 | // until status bar window is attached to the window manager, |
| 703 | // because... well, what's the point otherwise? And trying to |
| 704 | // run a ticker without being attached will crash! |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 705 | if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 706 | if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 707 | | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 708 | mTicker.add(key, n); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | } |
| 712 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 713 | public void animateExpand() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 714 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); |
| 715 | mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | public void animateCollapse() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 719 | mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL); |
| 720 | mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 721 | mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); |
| 722 | mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 723 | } |
| 724 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 725 | // called by StatusBar |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 726 | @Override |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 727 | public void setLightsOn(boolean on) { |
Daniel Sandler | 59485d74 | 2010-12-02 00:11:33 -0500 | [diff] [blame] | 728 | // Policy note: if the frontmost activity needs the menu key, we assume it is a legacy app |
| 729 | // that can't handle lights-out mode. |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 730 | if (mMenuButton.getVisibility() == View.VISIBLE) { |
Daniel Sandler | 59485d74 | 2010-12-02 00:11:33 -0500 | [diff] [blame] | 731 | on = true; |
| 732 | } |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 733 | mHandler.removeMessages(MSG_HIDE_CHROME); |
| 734 | mHandler.removeMessages(MSG_SHOW_CHROME); |
| 735 | mHandler.sendEmptyMessage(on ? MSG_SHOW_CHROME : MSG_HIDE_CHROME); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 736 | } |
| 737 | |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 738 | public void setMenuKeyVisible(boolean visible) { |
| 739 | if (DEBUG) { |
| 740 | Slog.d(TAG, (visible?"showing":"hiding") + " the MENU button"); |
| 741 | } |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 742 | mMenuButton.setVisibility(visible ? View.VISIBLE : View.GONE); |
Daniel Sandler | 59485d74 | 2010-12-02 00:11:33 -0500 | [diff] [blame] | 743 | |
| 744 | // See above re: lights-out policy for legacy apps. |
| 745 | if (visible) setLightsOn(true); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 746 | } |
| 747 | |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 748 | public void setIMEButtonVisible(IBinder token, boolean visible) { |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 749 | if (DEBUG) { |
| 750 | Slog.d(TAG, (visible?"showing":"hiding") + " the IME button"); |
| 751 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 752 | mInputMethodSwitchButton.setIMEButtonVisible(token, visible); |
Joe Onorato | 536c58f | 2010-11-28 17:52:28 -0800 | [diff] [blame] | 753 | mBackButton.setImageResource( |
| 754 | visible ? R.drawable.ic_sysbar_back_ime : R.drawable.ic_sysbar_back); |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 755 | if (FAKE_SPACE_BAR) { |
| 756 | mFakeSpaceBar.setVisibility(visible ? View.VISIBLE : View.GONE); |
| 757 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 758 | } |
| 759 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 760 | private boolean isImmersive() { |
| 761 | try { |
| 762 | return ActivityManagerNative.getDefault().isTopActivityImmersive(); |
| 763 | //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); |
| 764 | } catch (RemoteException ex) { |
| 765 | // the end is nigh |
| 766 | return false; |
| 767 | } |
| 768 | } |
| 769 | |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 770 | private void setAreThereNotifications() { |
| 771 | final boolean hasClearable = mNotns.hasClearableItems(); |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 774 | /** |
| 775 | * Cancel this notification and tell the status bar service about the failure. Hold no locks. |
| 776 | */ |
| 777 | void handleNotificationError(IBinder key, StatusBarNotification n, String message) { |
| 778 | removeNotification(key); |
| 779 | try { |
| 780 | mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); |
| 781 | } catch (RemoteException ex) { |
| 782 | // The end is nigh. |
| 783 | } |
| 784 | } |
| 785 | |
Daniel Sandler | 10163c6 | 2010-12-08 11:51:05 -0500 | [diff] [blame] | 786 | private void sendKey(KeyEvent key) { |
| 787 | try { |
| 788 | if (DEBUG) Slog.d(TAG, "injecting key event: " + key); |
| 789 | mWindowManager.injectInputEventNoWait(key); |
| 790 | } catch (RemoteException ex) { |
| 791 | } |
| 792 | } |
| 793 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 794 | private View.OnClickListener mOnClickListener = new View.OnClickListener() { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 795 | public void onClick(View v) { |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 796 | if (v == mNotificationTrigger) { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 797 | onClickNotificationTrigger(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 798 | } else if (v == mRecentButton) { |
| 799 | onClickRecentButton(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 800 | } |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 801 | } |
| 802 | }; |
| 803 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 804 | public void onClickNotificationTrigger() { |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 805 | if (DEBUG) Slog.d(TAG, "clicked notification icons; disabled=" + mDisabled); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 806 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 807 | if (!mNotificationsOn) { |
| 808 | mNotificationsOn = true; |
Daniel Sandler | cf3c7cf | 2010-10-22 15:30:12 -0400 | [diff] [blame] | 809 | mIconLayout.setVisibility(View.VISIBLE); // TODO: animation |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 810 | } else { |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 811 | int msg = !mNotificationPanel.isShowing() |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 812 | ? MSG_OPEN_NOTIFICATION_PANEL |
| 813 | : MSG_CLOSE_NOTIFICATION_PANEL; |
| 814 | mHandler.removeMessages(msg); |
| 815 | mHandler.sendEmptyMessage(msg); |
| 816 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 820 | public void onClickRecentButton() { |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 821 | if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 822 | if (mRecentsPanel == null) { |
| 823 | Intent intent = new Intent(); |
| 824 | intent.setClass(mContext, RecentApplicationsActivity.class); |
| 825 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 826 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 827 | mContext.startActivity(intent); |
| 828 | } else { |
| 829 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
| 830 | int msg = (mRecentsPanel.getVisibility() == View.GONE) |
| 831 | ? MSG_OPEN_RECENTS_PANEL |
| 832 | : MSG_CLOSE_RECENTS_PANEL; |
| 833 | mHandler.removeMessages(msg); |
| 834 | mHandler.sendEmptyMessage(msg); |
| 835 | } |
| 836 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 837 | } |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 838 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 839 | private class NotificationClicker implements View.OnClickListener { |
| 840 | private PendingIntent mIntent; |
| 841 | private String mPkg; |
| 842 | private String mTag; |
| 843 | private int mId; |
| 844 | |
| 845 | NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { |
| 846 | mIntent = intent; |
| 847 | mPkg = pkg; |
| 848 | mTag = tag; |
| 849 | mId = id; |
| 850 | } |
| 851 | |
| 852 | public void onClick(View v) { |
| 853 | try { |
| 854 | // The intent we are sending is for the application, which |
| 855 | // won't have permission to immediately start an activity after |
| 856 | // the user switches to home. We know it is safe to do at this |
| 857 | // point, so make sure new activity switches are now allowed. |
| 858 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 859 | } catch (RemoteException e) { |
| 860 | } |
| 861 | |
| 862 | if (mIntent != null) { |
| 863 | int[] pos = new int[2]; |
| 864 | v.getLocationOnScreen(pos); |
| 865 | Intent overlay = new Intent(); |
| 866 | overlay.setSourceBounds( |
| 867 | new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); |
| 868 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 869 | mIntent.send(mContext, 0, overlay); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 870 | } catch (PendingIntent.CanceledException e) { |
| 871 | // the stack trace isn't very helpful here. Just log the exception message. |
| 872 | Slog.w(TAG, "Sending contentIntent failed: " + e); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | try { |
| 877 | mBarService.onNotificationClick(mPkg, mTag, mId); |
| 878 | } catch (RemoteException ex) { |
| 879 | // system process is dead if we're here. |
| 880 | } |
| 881 | |
| 882 | // close the shade if it was open |
| 883 | animateCollapse(); |
| 884 | |
| 885 | // If this click was on the intruder alert, hide that instead |
| 886 | // mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | StatusBarNotification removeNotificationViews(IBinder key) { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 891 | NotificationData.Entry entry = mNotns.remove(key); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 892 | if (entry == null) { |
| 893 | Slog.w(TAG, "removeNotification for unknown key: " + key); |
| 894 | return null; |
| 895 | } |
| 896 | // Remove the expanded view. |
| 897 | ViewGroup rowParent = (ViewGroup)entry.row.getParent(); |
| 898 | if (rowParent != null) rowParent.removeView(entry.row); |
Daniel Sandler | a8e5b06 | 2010-12-01 13:53:08 -0500 | [diff] [blame] | 899 | |
| 900 | if (key == mNotificationPeekKey) { |
| 901 | // must close the peek as well, since it's gone |
| 902 | mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); |
| 903 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 904 | // Remove the icon. |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 905 | // ViewGroup iconParent = (ViewGroup)entry.icon.getParent(); |
| 906 | // if (iconParent != null) iconParent.removeView(entry.icon); |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 907 | updateNotificationIcons(); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 908 | |
| 909 | return entry.notification; |
| 910 | } |
| 911 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 912 | private class NotificationIconTouchListener implements View.OnTouchListener { |
| 913 | VelocityTracker mVT; |
| 914 | |
| 915 | public NotificationIconTouchListener() { |
| 916 | } |
| 917 | |
| 918 | public boolean onTouch(View v, MotionEvent event) { |
| 919 | boolean peeking = mNotificationPeekWindow.getVisibility() != View.GONE; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 920 | boolean panelShowing = mNotificationPanel.isShowing(); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 921 | if (panelShowing) return false; |
| 922 | |
| 923 | switch (event.getAction()) { |
| 924 | case MotionEvent.ACTION_DOWN: |
| 925 | mVT = VelocityTracker.obtain(); |
| 926 | |
| 927 | // fall through |
| 928 | case MotionEvent.ACTION_OUTSIDE: |
| 929 | case MotionEvent.ACTION_MOVE: |
| 930 | // peek and switch icons if necessary |
| 931 | int numIcons = mIconLayout.getChildCount(); |
Joe Onorato | 5e75946 | 2010-11-28 17:43:50 -0800 | [diff] [blame] | 932 | int peekIndex = (int)((float)event.getX() * numIcons / mIconLayout.getWidth()); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 933 | if (peekIndex > numIcons - 1) peekIndex = numIcons - 1; |
| 934 | else if (peekIndex < 0) peekIndex = 0; |
| 935 | |
| 936 | if (!peeking || mNotificationPeekIndex != peekIndex) { |
| 937 | if (DEBUG) Slog.d(TAG, "will peek at notification #" + peekIndex); |
| 938 | Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); |
| 939 | peekMsg.arg1 = peekIndex; |
| 940 | |
| 941 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); |
| 942 | |
| 943 | // no delay if we're scrubbing left-right |
Joe Onorato | 5e75946 | 2010-11-28 17:43:50 -0800 | [diff] [blame] | 944 | mHandler.sendMessage(peekMsg); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | // check for fling |
| 948 | if (mVT != null) { |
| 949 | mVT.addMovement(event); |
| 950 | mVT.computeCurrentVelocity(1000); |
| 951 | // require a little more oomph once we're already in peekaboo mode |
| 952 | if (!panelShowing && ( |
| 953 | (peeking && mVT.getYVelocity() < -mNotificationFlingVelocity*3) |
| 954 | || (mVT.getYVelocity() < -mNotificationFlingVelocity))) { |
| 955 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); |
| 956 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); |
| 957 | mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); |
| 958 | mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); |
| 959 | } |
| 960 | } |
| 961 | return true; |
| 962 | case MotionEvent.ACTION_UP: |
| 963 | case MotionEvent.ACTION_CANCEL: |
| 964 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); |
| 965 | if (peeking) { |
Joe Onorato | 5e75946 | 2010-11-28 17:43:50 -0800 | [diff] [blame] | 966 | mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK, 5000); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 967 | } |
| 968 | mVT.recycle(); |
| 969 | mVT = null; |
| 970 | return true; |
| 971 | } |
| 972 | return false; |
| 973 | } |
| 974 | } |
| 975 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 976 | StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 977 | if (DEBUG) { |
| 978 | Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); |
| 979 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 980 | // Construct the icon. |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 981 | final StatusBarIconView iconView = new StatusBarIconView(mContext, |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 982 | notification.pkg + "/0x" + Integer.toHexString(notification.id)); |
| 983 | iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 984 | |
| 985 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 986 | notification.notification.icon, |
| 987 | notification.notification.iconLevel, |
| 988 | notification.notification.number); |
| 989 | if (!iconView.set(ic)) { |
| 990 | handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic); |
| 991 | return null; |
| 992 | } |
| 993 | // Construct the expanded view. |
| 994 | NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 995 | if (!inflateViews(entry, mPile)) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 996 | handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " |
| 997 | + notification); |
| 998 | return null; |
| 999 | } |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1000 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1001 | // Add the icon. |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1002 | mNotns.add(entry); |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1003 | updateNotificationIcons(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1004 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1005 | return iconView; |
| 1006 | } |
| 1007 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1008 | private void reloadAllNotificationIcons() { |
| 1009 | if (mIconLayout == null) return; |
| 1010 | mIconLayout.removeAllViews(); |
| 1011 | updateNotificationIcons(); |
| 1012 | } |
| 1013 | |
| 1014 | private void updateNotificationIcons() { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1015 | // XXX: need to implement a new limited linear layout class |
| 1016 | // to avoid removing & readding everything |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1017 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1018 | if (mIconLayout == null) return; |
| 1019 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1020 | final LinearLayout.LayoutParams params |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1021 | = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mBarHeight); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1022 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1023 | int N = mNotns.size(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1024 | |
| 1025 | if (DEBUG) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1026 | Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1027 | } |
| 1028 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1029 | ArrayList<View> toShow = new ArrayList<View>(); |
| 1030 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1031 | for (int i=0; i<MAX_NOTIFICATION_ICONS; i++) { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1032 | if (i>=N) break; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1033 | toShow.add(mNotns.get(N-i-1).icon); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1034 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1035 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1036 | ArrayList<View> toRemove = new ArrayList<View>(); |
| 1037 | for (int i=0; i<mIconLayout.getChildCount(); i++) { |
| 1038 | View child = mIconLayout.getChildAt(i); |
| 1039 | if (!toShow.contains(child)) { |
| 1040 | toRemove.add(child); |
| 1041 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1042 | } |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 1043 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1044 | for (View remove : toRemove) { |
| 1045 | mIconLayout.removeView(remove); |
| 1046 | } |
| 1047 | |
| 1048 | for (int i=0; i<toShow.size(); i++) { |
| 1049 | View v = toShow.get(i); |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1050 | v.setPadding(mIconHPadding, 0, mIconHPadding, 0); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1051 | if (v.getParent() == null) { |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1052 | mIconLayout.addView(v, i, params); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | loadNotificationPanel(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1057 | } |
| 1058 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1059 | private void loadNotificationPanel() { |
| 1060 | int N = mNotns.size(); |
| 1061 | |
| 1062 | ArrayList<View> toShow = new ArrayList<View>(); |
| 1063 | |
| 1064 | for (int i=0; i<N; i++) { |
| 1065 | View row = mNotns.get(N-i-1).row; |
| 1066 | toShow.add(row); |
| 1067 | } |
| 1068 | |
| 1069 | ArrayList<View> toRemove = new ArrayList<View>(); |
| 1070 | for (int i=0; i<mPile.getChildCount(); i++) { |
| 1071 | View child = mPile.getChildAt(i); |
| 1072 | if (!toShow.contains(child)) { |
| 1073 | toRemove.add(child); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | for (View remove : toRemove) { |
| 1078 | mPile.removeView(remove); |
| 1079 | } |
| 1080 | |
| 1081 | for (int i=0; i<toShow.size(); i++) { |
| 1082 | View v = toShow.get(i); |
| 1083 | if (v.getParent() == null) { |
| 1084 | mPile.addView(toShow.get(i)); |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | |
Joe Onorato | 4daaeaf | 2010-11-17 20:43:12 -0800 | [diff] [blame] | 1089 | void workAroundBadLayerDrawableOpacity(View v) { |
| 1090 | LayerDrawable d = (LayerDrawable)v.getBackground(); |
| 1091 | v.setBackgroundDrawable(null); |
| 1092 | d.setOpacity(PixelFormat.TRANSLUCENT); |
| 1093 | v.setBackgroundDrawable(d); |
| 1094 | } |
| 1095 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1096 | private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { |
| 1097 | StatusBarNotification sbn = entry.notification; |
| 1098 | RemoteViews remoteViews = sbn.notification.contentView; |
| 1099 | if (remoteViews == null) { |
| 1100 | return false; |
| 1101 | } |
| 1102 | |
| 1103 | // create the row view |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1104 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( |
| 1105 | Context.LAYOUT_INFLATER_SERVICE); |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 1106 | View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false); |
Joe Onorato | 4daaeaf | 2010-11-17 20:43:12 -0800 | [diff] [blame] | 1107 | workAroundBadLayerDrawableOpacity(row); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1108 | View vetoButton = row.findViewById(R.id.veto); |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 1109 | if (entry.notification.isClearable()) { |
| 1110 | final String _pkg = sbn.pkg; |
| 1111 | final String _tag = sbn.tag; |
| 1112 | final int _id = sbn.id; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 1113 | vetoButton.setOnClickListener(new View.OnClickListener() { |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 1114 | public void onClick(View v) { |
| 1115 | try { |
| 1116 | mBarService.onNotificationClear(_pkg, _tag, _id); |
| 1117 | } catch (RemoteException ex) { |
| 1118 | // system process is dead if we're here. |
| 1119 | } |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1120 | } |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 1121 | }); |
| 1122 | } else { |
| 1123 | vetoButton.setVisibility(View.INVISIBLE); |
| 1124 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1125 | |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1126 | // the large icon |
| 1127 | ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon); |
| 1128 | if (sbn.notification.largeIcon != null) { |
| 1129 | largeIcon.setImageBitmap(sbn.notification.largeIcon); |
| 1130 | } else { |
| 1131 | largeIcon.getLayoutParams().width = 0; |
| 1132 | largeIcon.setVisibility(View.INVISIBLE); |
| 1133 | } |
| 1134 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1135 | // bind the click event to the content area |
| 1136 | ViewGroup content = (ViewGroup)row.findViewById(R.id.content); |
| 1137 | // XXX: update to allow controls within notification views |
| 1138 | content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); |
| 1139 | // content.setOnFocusChangeListener(mFocusChangeListener); |
| 1140 | PendingIntent contentIntent = sbn.notification.contentIntent; |
| 1141 | if (contentIntent != null) { |
| 1142 | content.setOnClickListener(new NotificationClicker(contentIntent, |
| 1143 | sbn.pkg, sbn.tag, sbn.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 1144 | } else { |
| 1145 | content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | View expanded = null; |
| 1149 | Exception exception = null; |
| 1150 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1151 | expanded = remoteViews.apply(mContext, content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1152 | } |
| 1153 | catch (RuntimeException e) { |
| 1154 | exception = e; |
| 1155 | } |
| 1156 | if (expanded == null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1157 | final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1158 | Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); |
| 1159 | return false; |
| 1160 | } else { |
| 1161 | content.addView(expanded); |
| 1162 | row.setDrawingCacheEnabled(true); |
| 1163 | } |
| 1164 | |
| 1165 | entry.row = row; |
| 1166 | entry.content = content; |
| 1167 | entry.expanded = expanded; |
| 1168 | |
| 1169 | return true; |
| 1170 | } |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 1171 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1172 | /* |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1173 | public class ShadowController { |
| 1174 | boolean mShowShadows; |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 1175 | Map<View, View> mShadowsForElements = new IdentityHashMap<View, View>(7); |
| 1176 | Map<View, View> mElementsForShadows = new IdentityHashMap<View, View>(7); |
| 1177 | LayoutTransition mElementTransition, mShadowTransition; |
| 1178 | |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1179 | View mTouchTarget; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 1180 | |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1181 | ShadowController(boolean showShadows) { |
| 1182 | mShowShadows = showShadows; |
| 1183 | mTouchTarget = null; |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 1184 | |
| 1185 | mElementTransition = new LayoutTransition(); |
| 1186 | // AnimatorSet s = new AnimatorSet(); |
| 1187 | // s.play(ObjectAnimator.ofInt(null, "top", 48, 0)) |
| 1188 | // .with(ObjectAnimator.ofFloat(null, "scaleY", 0.5f, 1f)) |
| 1189 | // .with(ObjectAnimator.ofFloat(null, "alpha", 0.5f, 1f)) |
| 1190 | // ; |
| 1191 | mElementTransition.setAnimator(LayoutTransition.APPEARING, //s); |
| 1192 | ObjectAnimator.ofInt(null, "top", 48, 0)); |
| 1193 | mElementTransition.setDuration(LayoutTransition.APPEARING, 100); |
| 1194 | mElementTransition.setStartDelay(LayoutTransition.APPEARING, 0); |
| 1195 | |
| 1196 | // s = new AnimatorSet(); |
| 1197 | // s.play(ObjectAnimator.ofInt(null, "top", 0, 48)) |
| 1198 | // .with(ObjectAnimator.ofFloat(null, "scaleY", 1f, 0.5f)) |
| 1199 | // .with(ObjectAnimator.ofFloat(null, "alpha", 1f, 0.5f)) |
| 1200 | // ; |
| 1201 | mElementTransition.setAnimator(LayoutTransition.DISAPPEARING, //s); |
| 1202 | ObjectAnimator.ofInt(null, "top", 0, 48)); |
| 1203 | mElementTransition.setDuration(LayoutTransition.DISAPPEARING, 400); |
| 1204 | |
| 1205 | mShadowTransition = new LayoutTransition(); |
| 1206 | mShadowTransition.setAnimator(LayoutTransition.APPEARING, |
| 1207 | ObjectAnimator.ofFloat(null, "alpha", 0f, 1f)); |
| 1208 | mShadowTransition.setDuration(LayoutTransition.APPEARING, 200); |
| 1209 | mShadowTransition.setStartDelay(LayoutTransition.APPEARING, 100); |
| 1210 | mShadowTransition.setAnimator(LayoutTransition.DISAPPEARING, |
| 1211 | ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); |
| 1212 | mShadowTransition.setDuration(LayoutTransition.DISAPPEARING, 100); |
| 1213 | |
| 1214 | ViewGroup bar = (ViewGroup) TabletStatusBar.this.mBarContents; |
| 1215 | bar.setLayoutTransition(mElementTransition); |
| 1216 | ViewGroup nav = (ViewGroup) TabletStatusBar.this.mNavigationArea; |
| 1217 | nav.setLayoutTransition(mElementTransition); |
| 1218 | ViewGroup shadowGroup = (ViewGroup) bar.findViewById(R.id.shadows); |
| 1219 | shadowGroup.setLayoutTransition(mShadowTransition); |
| 1220 | } |
| 1221 | |
| 1222 | public void add(View element, View shadow) { |
| 1223 | shadow.setOnTouchListener(makeTouchListener()); |
| 1224 | mShadowsForElements.put(element, shadow); |
| 1225 | mElementsForShadows.put(shadow, element); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1228 | public boolean getShadowState() { |
| 1229 | return mShowShadows; |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1232 | public View.OnTouchListener makeTouchListener() { |
| 1233 | return new View.OnTouchListener() { |
| 1234 | public boolean onTouch(View v, MotionEvent ev) { |
| 1235 | final int action = ev.getAction(); |
| 1236 | |
| 1237 | if (DEBUG) Slog.d(TAG, "ShadowController: v=" + v + ", ev=" + ev); |
| 1238 | |
| 1239 | // currently redirecting events? |
| 1240 | if (mTouchTarget == null) { |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 1241 | mTouchTarget = mElementsForShadows.get(v); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | if (mTouchTarget != null && mTouchTarget.getVisibility() != View.GONE) { |
| 1245 | boolean last = false; |
| 1246 | switch (action) { |
| 1247 | case MotionEvent.ACTION_CANCEL: |
| 1248 | case MotionEvent.ACTION_UP: |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 1249 | mHandler.removeMessages(MSG_RESTORE_SHADOWS); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1250 | if (mShowShadows) { |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 1251 | mHandler.sendEmptyMessageDelayed(MSG_RESTORE_SHADOWS, |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1252 | v == mNotificationShadow ? 5000 : 500); |
| 1253 | } |
| 1254 | last = true; |
| 1255 | break; |
| 1256 | case MotionEvent.ACTION_DOWN: |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 1257 | mHandler.removeMessages(MSG_RESTORE_SHADOWS); |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 1258 | setElementShadow(mTouchTarget, false); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1259 | break; |
| 1260 | } |
| 1261 | mTouchTarget.dispatchTouchEvent(ev); |
| 1262 | if (last) mTouchTarget = null; |
| 1263 | return true; |
| 1264 | } |
| 1265 | |
| 1266 | return false; |
| 1267 | } |
| 1268 | }; |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 1271 | public void refresh() { |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 1272 | for (View element : mShadowsForElements.keySet()) { |
| 1273 | setElementShadow(element, mShowShadows); |
| 1274 | } |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 1275 | } |
| 1276 | |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1277 | public void showAllShadows() { |
| 1278 | mShowShadows = true; |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 1279 | refresh(); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | public void hideAllShadows() { |
| 1283 | mShowShadows = false; |
Daniel Sandler | e03d1bc | 2010-11-17 21:36:40 -0500 | [diff] [blame] | 1284 | refresh(); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | // Use View.INVISIBLE for things hidden due to shadowing, and View.GONE for things that are |
| 1288 | // disabled (and should not be shadowed or re-shown) |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 1289 | public void setElementShadow(View button, boolean shade) { |
| 1290 | View shadow = mShadowsForElements.get(button); |
Daniel Sandler | b6d3dc6 | 2010-11-17 16:51:26 -0500 | [diff] [blame] | 1291 | if (shadow != null) { |
| 1292 | if (button.getVisibility() != View.GONE) { |
| 1293 | shadow.setVisibility(shade ? View.VISIBLE : View.INVISIBLE); |
| 1294 | button.setVisibility(shade ? View.INVISIBLE : View.VISIBLE); |
| 1295 | } |
| 1296 | } |
| 1297 | } |
Daniel Sandler | b960699 | 2010-11-19 14:47:59 -0500 | [diff] [blame] | 1298 | |
| 1299 | // Hide both element and shadow, using default layout animations. |
| 1300 | public void hideElement(View button) { |
| 1301 | Slog.d(TAG, "hiding: " + button); |
| 1302 | View shadow = mShadowsForElements.get(button); |
| 1303 | if (shadow != null) { |
| 1304 | shadow.setVisibility(View.GONE); |
| 1305 | } |
| 1306 | button.setVisibility(View.GONE); |
| 1307 | } |
| 1308 | |
| 1309 | // Honoring the current shadow state. |
| 1310 | public void showElement(View button) { |
| 1311 | Slog.d(TAG, "showing: " + button); |
| 1312 | View shadow = mShadowsForElements.get(button); |
| 1313 | if (shadow != null) { |
| 1314 | shadow.setVisibility(mShowShadows ? View.VISIBLE : View.INVISIBLE); |
| 1315 | } |
| 1316 | button.setVisibility(mShowShadows ? View.INVISIBLE : View.VISIBLE); |
| 1317 | } |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 1318 | } |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 1319 | */ |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1320 | |
| 1321 | public class TouchOutsideListener implements View.OnTouchListener { |
| 1322 | private int mMsg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1323 | private StatusBarPanel mPanel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1324 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1325 | public TouchOutsideListener(int msg, StatusBarPanel panel) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1326 | mMsg = msg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1327 | mPanel = panel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | public boolean onTouch(View v, MotionEvent ev) { |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1331 | final int action = ev.getAction(); |
| 1332 | if (action == MotionEvent.ACTION_OUTSIDE |
| 1333 | || (action == MotionEvent.ACTION_DOWN |
| 1334 | && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1335 | mHandler.removeMessages(mMsg); |
| 1336 | mHandler.sendEmptyMessage(mMsg); |
| 1337 | return true; |
| 1338 | } |
| 1339 | return false; |
| 1340 | } |
| 1341 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 1342 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1343 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1344 | pw.print("mDisabled=0x"); |
| 1345 | pw.println(Integer.toHexString(mDisabled)); |
| 1346 | } |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 1347 | } |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 1348 | |
| 1349 | |