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