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