Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.tablet; |
| 18 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 19 | import java.io.FileDescriptor; |
| 20 | import java.io.PrintWriter; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 21 | import java.util.ArrayList; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 22 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 23 | import android.animation.LayoutTransition; |
| 24 | import android.animation.ObjectAnimator; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 25 | import android.app.ActivityManagerNative; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 27 | import android.app.Notification; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 28 | import android.app.StatusBarManager; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.res.Resources; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 32 | import android.graphics.PixelFormat; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 33 | import android.graphics.Rect; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 34 | import android.os.Handler; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 35 | import android.os.IBinder; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 36 | import android.os.Message; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 37 | import android.os.RemoteException; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 38 | import android.text.TextUtils; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 39 | import android.util.Slog; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 40 | import android.view.animation.Animation; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 41 | import android.view.animation.AnimationUtils; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 42 | import android.view.Gravity; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 43 | import android.view.LayoutInflater; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 44 | import android.view.MotionEvent; |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 45 | import android.view.VelocityTracker; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 46 | import android.view.View; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 47 | import android.view.ViewConfiguration; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 48 | import android.view.ViewGroup; |
| 49 | import android.view.WindowManager; |
| 50 | import android.view.WindowManagerImpl; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 51 | import android.widget.FrameLayout; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 52 | import android.widget.ImageView; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 53 | import android.widget.LinearLayout; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 54 | import android.widget.RemoteViews; |
| 55 | import android.widget.ScrollView; |
| 56 | import android.widget.TextSwitcher; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 57 | import android.widget.TextView; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 58 | |
| 59 | import com.android.internal.statusbar.StatusBarIcon; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 60 | import com.android.internal.statusbar.StatusBarNotification; |
| 61 | |
| 62 | import com.android.systemui.statusbar.*; |
Joe Onorato | 013cfc1 | 2010-09-08 15:23:18 -0400 | [diff] [blame] | 63 | import com.android.systemui.recent.RecentApplicationsActivity; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 64 | import com.android.systemui.R; |
| 65 | |
| 66 | public class TabletStatusBarService extends StatusBarService { |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 67 | public static final boolean DEBUG = false; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 68 | public static final String TAG = "TabletStatusBarService"; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 69 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 70 | public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; |
| 71 | public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 72 | public static final int MSG_OPEN_NOTIFICATION_PEEK = 1002; |
| 73 | public static final int MSG_CLOSE_NOTIFICATION_PEEK = 1003; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 74 | public static final int MSG_OPEN_SYSTEM_PANEL = 1010; |
| 75 | public static final int MSG_CLOSE_SYSTEM_PANEL = 1011; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 76 | public static final int MSG_OPEN_RECENTS_PANEL = 1020; |
| 77 | public static final int MSG_CLOSE_RECENTS_PANEL = 1021; |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 78 | public static final int MSG_LIGHTS_ON = 1030; |
| 79 | public static final int MSG_LIGHTS_OUT = 1031; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 80 | |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 81 | private static final int MAX_IMAGE_LEVEL = 10000; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 82 | private static final boolean USE_2D_RECENTS = true; |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 83 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 84 | int mIconSize; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 85 | |
| 86 | H mHandler = new H(); |
| 87 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 88 | // tracking all current notifications |
| 89 | private NotificationData mNotns = new NotificationData(); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 90 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 91 | TabletStatusBarView mStatusBarView; |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 92 | ImageView mNotificationTrigger; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 93 | NotificationIconArea mNotificationIconArea; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 94 | View mNotificationButtons; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 95 | View mSystemInfo; |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 96 | View mNavigationArea; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 97 | View mMenuButton; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 98 | View mRecentButton; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 99 | |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 100 | InputMethodButton mInputMethodButton; |
| 101 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 102 | NotificationPanel mNotificationPanel; |
Daniel Sandler | 6425ef9 | 2010-08-11 16:10:19 -0400 | [diff] [blame] | 103 | SystemPanel mSystemPanel; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 104 | NotificationPanel mNotificationPeekWindow; |
| 105 | ViewGroup mNotificationPeekRow; |
| 106 | int mNotificationPeekIndex; |
| 107 | LayoutTransition mNotificationPeekScrubLeft, mNotificationPeekScrubRight; |
| 108 | |
| 109 | int mNotificationPeekTapDuration; |
| 110 | int mNotificationFlingVelocity; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 111 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 112 | ViewGroup mPile; |
| 113 | TextView mClearButton; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 114 | TextView mDoNotDisturbButton; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 115 | |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 116 | ImageView mBatteryMeter; |
| 117 | ImageView mSignalMeter; |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 118 | ImageView mSignalIcon; |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 119 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 120 | View mBarContents; |
| 121 | View mCurtains; |
| 122 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 123 | NotificationIconArea.IconLayout mIconLayout; |
| 124 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 125 | TabletTicker mTicker; |
| 126 | View mTickerView; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 127 | boolean mTicking; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 128 | |
| 129 | // for disabling the status bar |
| 130 | int mDisabled = 0; |
| 131 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 132 | boolean mNotificationsOn = true; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 133 | private RecentAppsPanel mRecentsPanel; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 134 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 135 | protected void addPanelWindows() { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 136 | final Context context = mContext; |
| 137 | |
| 138 | final Resources res = context.getResources(); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 139 | final int barHeight= res.getDimensionPixelSize( |
| 140 | com.android.internal.R.dimen.status_bar_height); |
| 141 | |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 142 | // Notification Panel |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 143 | mNotificationPanel = (NotificationPanel)View.inflate(context, |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 144 | R.layout.sysbar_panel_notifications, null); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 145 | mNotificationPanel.setVisibility(View.GONE); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 146 | mNotificationPanel.setOnTouchListener( |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 147 | new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel)); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 148 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 149 | mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 150 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 151 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 152 | 512, // ViewGroup.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 153 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 154 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 155 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame^] | 156 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
| 157 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 158 | PixelFormat.TRANSLUCENT); |
Joe Onorato | ea70e63 | 2010-09-27 17:59:37 -0700 | [diff] [blame] | 159 | lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 160 | lp.setTitle("NotificationPanel"); |
| 161 | lp.windowAnimations = com.android.internal.R.style.Animation_SlidingCard; |
| 162 | |
| 163 | WindowManagerImpl.getDefault().addView(mNotificationPanel, lp); |
| 164 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 165 | // Notification preview window |
| 166 | mNotificationPeekWindow = (NotificationPanel) View.inflate(context, |
| 167 | R.layout.sysbar_panel_notification_peek, null); |
| 168 | mNotificationPeekRow = (ViewGroup) mNotificationPeekWindow.findViewById(R.id.content); |
| 169 | mNotificationPeekWindow.setVisibility(View.GONE); |
| 170 | mNotificationPeekWindow.setOnTouchListener( |
| 171 | new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPeekWindow)); |
| 172 | mNotificationPeekScrubRight = new LayoutTransition(); |
| 173 | mNotificationPeekScrubRight.setAnimator(LayoutTransition.APPEARING, |
| 174 | ObjectAnimator.ofInt(null, "left", -512, 0)); |
| 175 | mNotificationPeekScrubRight.setAnimator(LayoutTransition.DISAPPEARING, |
| 176 | ObjectAnimator.ofInt(null, "left", -512, 0)); |
| 177 | mNotificationPeekScrubRight.setDuration(500); |
| 178 | |
| 179 | mNotificationPeekScrubLeft = new LayoutTransition(); |
| 180 | mNotificationPeekScrubLeft.setAnimator(LayoutTransition.APPEARING, |
| 181 | ObjectAnimator.ofInt(null, "left", 512, 0)); |
| 182 | mNotificationPeekScrubLeft.setAnimator(LayoutTransition.DISAPPEARING, |
| 183 | ObjectAnimator.ofInt(null, "left", 512, 0)); |
| 184 | mNotificationPeekScrubLeft.setDuration(500); |
| 185 | |
| 186 | // XXX: setIgnoreChildren? |
| 187 | lp = new WindowManager.LayoutParams( |
| 188 | 512, // ViewGroup.LayoutParams.WRAP_CONTENT, |
| 189 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 190 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 191 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame^] | 192 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
| 193 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 194 | PixelFormat.TRANSLUCENT); |
| 195 | lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; |
| 196 | lp.setTitle("NotificationPeekWindow"); |
| 197 | lp.windowAnimations = com.android.internal.R.style.Animation_Toast; |
| 198 | |
| 199 | WindowManagerImpl.getDefault().addView(mNotificationPeekWindow, lp); |
| 200 | |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 201 | // System Panel |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 202 | mSystemPanel = (SystemPanel) View.inflate(context, R.layout.sysbar_panel_system, null); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 203 | mSystemPanel.setVisibility(View.GONE); |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 204 | mSystemPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_SYSTEM_PANEL, |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 205 | mSystemPanel)); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 206 | mStatusBarView.setIgnoreChildren(1, mSystemInfo, mSystemPanel); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 207 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 208 | lp = new WindowManager.LayoutParams( |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 209 | 800, |
Daniel Sandler | 6425ef9 | 2010-08-11 16:10:19 -0400 | [diff] [blame] | 210 | ViewGroup.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 211 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 212 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame^] | 213 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
| 214 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 215 | PixelFormat.TRANSLUCENT); |
| 216 | lp.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; |
| 217 | lp.setTitle("SystemPanel"); |
| 218 | lp.windowAnimations = com.android.internal.R.style.Animation_SlidingCard; |
| 219 | |
| 220 | WindowManagerImpl.getDefault().addView(mSystemPanel, lp); |
Daniel Sandler | 6425ef9 | 2010-08-11 16:10:19 -0400 | [diff] [blame] | 221 | mSystemPanel.setBar(this); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 222 | |
| 223 | |
| 224 | // Recents Panel |
| 225 | if (USE_2D_RECENTS) { |
| 226 | mRecentsPanel = (RecentAppsPanel) View.inflate(context, R.layout.sysbar_panel_recent, |
| 227 | null); |
| 228 | mRecentsPanel.setVisibility(View.GONE); |
| 229 | mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, |
| 230 | mRecentsPanel)); |
| 231 | mStatusBarView.setIgnoreChildren(2, mRecentButton, mRecentsPanel); |
| 232 | |
| 233 | lp = new WindowManager.LayoutParams( |
| 234 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 235 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 236 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 237 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame^] | 238 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
| 239 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 240 | PixelFormat.TRANSLUCENT); |
| 241 | lp.gravity = Gravity.BOTTOM | Gravity.LEFT; |
| 242 | lp.setTitle("RecentsPanel"); |
| 243 | lp.windowAnimations = com.android.internal.R.style.Animation_SlidingCard; |
| 244 | |
| 245 | WindowManagerImpl.getDefault().addView(mRecentsPanel, lp); |
| 246 | mRecentsPanel.setBar(this); |
| 247 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 248 | } |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 249 | |
| 250 | @Override |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 251 | public void start() { |
| 252 | super.start(); // will add the main bar view |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | protected View makeStatusBarView() { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 256 | final Context context = mContext; |
| 257 | final Resources res = context.getResources(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 258 | |
| 259 | mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); |
| 260 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 261 | final TabletStatusBarView sb = (TabletStatusBarView)View.inflate( |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 262 | context, R.layout.status_bar, null); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 263 | mStatusBarView = sb; |
| 264 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 265 | sb.setHandler(mHandler); |
| 266 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 267 | mBarContents = sb.findViewById(R.id.bar_contents); |
| 268 | mCurtains = sb.findViewById(R.id.lights_out); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 269 | mSystemInfo = sb.findViewById(R.id.systemInfo); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 270 | mRecentButton = sb.findViewById(R.id.recent_apps); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 271 | |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 272 | mSystemInfo.setOnTouchListener(new ClockTouchListener()); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 273 | |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 274 | mRecentButton = sb.findViewById(R.id.recent_apps); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 275 | mRecentButton.setOnClickListener(mOnClickListener); |
| 276 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 277 | SetLightsOnListener on = new SetLightsOnListener(true); |
| 278 | mCurtains.setOnClickListener(on); |
| 279 | mCurtains.setOnLongClickListener(on); |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 280 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 281 | // the button to open the notification area |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 282 | mNotificationTrigger = (ImageView) sb.findViewById(R.id.notificationTrigger); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 283 | mNotificationTrigger.setOnClickListener(mOnClickListener); |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 284 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 285 | // the more notifications icon |
| 286 | mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons); |
| 287 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 288 | // the clear and dnd buttons |
| 289 | mNotificationButtons = sb.findViewById(R.id.notificationButtons); |
| 290 | mClearButton = (TextView)mNotificationButtons.findViewById(R.id.clear_all_button); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 291 | mClearButton.setOnClickListener(mOnClickListener); |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 292 | mDoNotDisturbButton = (TextView)mNotificationButtons.findViewById(R.id.do_not_disturb); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 293 | mDoNotDisturbButton.setOnClickListener(mOnClickListener); |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 294 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 295 | // where the icons go |
| 296 | mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons); |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 297 | mIconLayout.setOnTouchListener(new NotificationIconTouchListener()); |
| 298 | |
| 299 | ViewConfiguration vc = ViewConfiguration.get(context); |
| 300 | mNotificationPeekTapDuration = vc.getTapTimeout(); |
| 301 | mNotificationFlingVelocity = 300; // px/s |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 302 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 303 | mTicker = new TabletTicker(context, (FrameLayout)sb.findViewById(R.id.ticker)); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 304 | |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 305 | // System info (center) |
| 306 | mBatteryMeter = (ImageView) sb.findViewById(R.id.battery); |
| 307 | mSignalMeter = (ImageView) sb.findViewById(R.id.signal); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 308 | mSignalIcon = (ImageView) sb.findViewById(R.id.signal_icon); |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 309 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 310 | // The navigation buttons |
| 311 | mNavigationArea = sb.findViewById(R.id.navigationArea); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 312 | mMenuButton = mNavigationArea.findViewById(R.id.menu); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 313 | |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 314 | // The bar contents buttons |
| 315 | mInputMethodButton = (InputMethodButton) mBarContents.findViewById(R.id.imeButton); |
| 316 | |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 317 | // set the initial view visibility |
| 318 | setAreThereNotifications(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 319 | refreshNotificationTrigger(); |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 320 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 321 | // Add the windows |
| 322 | addPanelWindows(); |
| 323 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 324 | mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content); |
| 325 | mPile.removeAllViews(); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 326 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 327 | ScrollView scroller = (ScrollView)mPile.getParent(); |
| 328 | scroller.setFillViewport(true); |
| 329 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 330 | return sb; |
| 331 | } |
| 332 | |
| 333 | protected int getStatusBarGravity() { |
| 334 | return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL; |
| 335 | } |
| 336 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 337 | private class H extends Handler { |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 338 | public void handleMessage(Message m) { |
| 339 | switch (m.what) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 340 | case MSG_OPEN_NOTIFICATION_PEEK: |
| 341 | if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1); |
| 342 | if (m.arg1 >= 0) { |
| 343 | final int N = mNotns.size(); |
| 344 | if (mNotificationPeekIndex < N) { |
| 345 | NotificationData.Entry entry = mNotns.get(N-1-mNotificationPeekIndex); |
| 346 | entry.icon.setBackgroundColor(0); |
| 347 | } |
| 348 | |
| 349 | final int peekIndex = m.arg1; |
| 350 | if (peekIndex < N) { |
| 351 | Slog.d(TAG, "loading peek: " + peekIndex); |
| 352 | NotificationData.Entry entry = mNotns.get(N-1-peekIndex); |
| 353 | NotificationData.Entry copy = new NotificationData.Entry( |
| 354 | entry.key, |
| 355 | entry.notification, |
| 356 | entry.icon); |
| 357 | inflateViews(copy, mNotificationPeekRow); |
| 358 | |
| 359 | entry.icon.setBackgroundColor(0x20FFFFFF); |
| 360 | |
| 361 | // mNotificationPeekRow.setLayoutTransition( |
| 362 | // peekIndex < mNotificationPeekIndex |
| 363 | // ? mNotificationPeekScrubLeft |
| 364 | // : mNotificationPeekScrubRight); |
| 365 | |
| 366 | mNotificationPeekRow.removeAllViews(); |
| 367 | mNotificationPeekRow.addView(copy.row); |
| 368 | |
| 369 | mNotificationPeekWindow.setVisibility(View.VISIBLE); |
| 370 | mNotificationPanel.setVisibility(View.GONE); |
| 371 | |
| 372 | mNotificationPeekIndex = peekIndex; |
| 373 | } |
| 374 | } |
| 375 | break; |
| 376 | case MSG_CLOSE_NOTIFICATION_PEEK: |
| 377 | if (DEBUG) Slog.d(TAG, "closing notification peek window"); |
| 378 | mNotificationPeekWindow.setVisibility(View.GONE); |
| 379 | mNotificationPeekRow.removeAllViews(); |
| 380 | final int N = mNotns.size(); |
| 381 | if (mNotificationPeekIndex < N) { |
| 382 | NotificationData.Entry entry = mNotns.get(N-1-mNotificationPeekIndex); |
| 383 | entry.icon.setBackgroundColor(0); |
| 384 | } |
| 385 | break; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 386 | case MSG_OPEN_NOTIFICATION_PANEL: |
| 387 | if (DEBUG) Slog.d(TAG, "opening notifications panel"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 388 | if (mNotificationPanel.getVisibility() == View.GONE) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 389 | mNotificationPeekWindow.setVisibility(View.GONE); |
| 390 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 391 | mDoNotDisturbButton.setText(mNotificationsOn |
| 392 | ? R.string.status_bar_do_not_disturb_button |
| 393 | : R.string.status_bar_please_disturb_button); |
| 394 | mNotificationPanel.setVisibility(View.VISIBLE); |
| 395 | setViewVisibility(mNotificationIconArea, View.GONE, |
| 396 | R.anim.notification_icons_out); |
| 397 | setViewVisibility(mNotificationButtons, View.VISIBLE, |
| 398 | R.anim.notification_buttons_in); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 399 | refreshNotificationTrigger(); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 400 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 401 | break; |
| 402 | case MSG_CLOSE_NOTIFICATION_PANEL: |
| 403 | if (DEBUG) Slog.d(TAG, "closing notifications panel"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 404 | if (mNotificationPanel.getVisibility() == View.VISIBLE) { |
| 405 | mNotificationPanel.setVisibility(View.GONE); |
| 406 | setViewVisibility(mNotificationIconArea, View.VISIBLE, |
| 407 | R.anim.notification_icons_in); |
| 408 | setViewVisibility(mNotificationButtons, View.GONE, |
| 409 | R.anim.notification_buttons_out); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 410 | refreshNotificationTrigger(); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 411 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 412 | break; |
| 413 | case MSG_OPEN_SYSTEM_PANEL: |
| 414 | if (DEBUG) Slog.d(TAG, "opening system panel"); |
| 415 | mSystemPanel.setVisibility(View.VISIBLE); |
| 416 | break; |
| 417 | case MSG_CLOSE_SYSTEM_PANEL: |
| 418 | if (DEBUG) Slog.d(TAG, "closing system panel"); |
| 419 | mSystemPanel.setVisibility(View.GONE); |
Joe Onorato | 31b2610 | 2010-10-27 14:32:28 -0700 | [diff] [blame] | 420 | break; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 421 | case MSG_OPEN_RECENTS_PANEL: |
| 422 | if (DEBUG) Slog.d(TAG, "opening recents panel"); |
| 423 | if (mRecentsPanel != null) mRecentsPanel.setVisibility(View.VISIBLE); |
| 424 | break; |
| 425 | case MSG_CLOSE_RECENTS_PANEL: |
| 426 | if (DEBUG) Slog.d(TAG, "closing recents panel"); |
| 427 | if (mRecentsPanel != null) mRecentsPanel.setVisibility(View.GONE); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 428 | break; |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 429 | case MSG_LIGHTS_ON: |
| 430 | setViewVisibility(mCurtains, View.GONE, R.anim.lights_out_out); |
| 431 | setViewVisibility(mBarContents, View.VISIBLE, R.anim.status_bar_in); |
| 432 | break; |
| 433 | case MSG_LIGHTS_OUT: |
| 434 | animateCollapse(); |
| 435 | setViewVisibility(mCurtains, View.VISIBLE, R.anim.lights_out_in); |
| 436 | setViewVisibility(mBarContents, View.GONE, R.anim.status_bar_out); |
| 437 | break; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | } |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 441 | |
| 442 | public void refreshNotificationTrigger() { |
Daniel Sandler | cf3c7cf | 2010-10-22 15:30:12 -0400 | [diff] [blame] | 443 | if (mNotificationTrigger == null) return; |
| 444 | |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 445 | int resId; |
| 446 | boolean panel = (mNotificationPanel != null |
| 447 | && mNotificationPanel.getVisibility() == View.VISIBLE); |
| 448 | if (!mNotificationsOn) { |
| 449 | resId = R.drawable.ic_sysbar_noti_dnd; |
| 450 | } else if (mNotns.size() > 0) { |
| 451 | resId = panel ? R.drawable.ic_sysbar_noti_avail_open : R.drawable.ic_sysbar_noti_avail; |
| 452 | } else { |
| 453 | resId = panel ? R.drawable.ic_sysbar_noti_none_open : R.drawable.ic_sysbar_noti_none; |
| 454 | } |
| 455 | mNotificationTrigger.setImageResource(resId); |
| 456 | } |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 457 | |
Daniel Sandler | d7db7b1 | 2010-08-13 16:26:39 -0400 | [diff] [blame] | 458 | public void setBatteryMeter(int level, boolean plugged) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 459 | if (DEBUG) Slog.d(TAG, "battery=" + level + (plugged ? " - plugged" : " - unplugged")); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 460 | mBatteryMeter.setImageResource(R.drawable.sysbar_batterymini); |
| 461 | // adjust percent to permyriad for ClipDrawable's sake |
| 462 | mBatteryMeter.setImageLevel(level * (MAX_IMAGE_LEVEL / 100)); |
Daniel Sandler | d7db7b1 | 2010-08-13 16:26:39 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 465 | public void setSignalMeter(int level, boolean isWifi) { |
| 466 | if (DEBUG) Slog.d(TAG, "signal=" + level); |
| 467 | if (level < 0) { |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 468 | mSignalMeter.setImageDrawable(null); |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 469 | mSignalMeter.setImageLevel(0); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 470 | mSignalIcon.setImageDrawable(null); |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 471 | } else { |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 472 | mSignalMeter.setImageResource(R.drawable.sysbar_wifimini); |
| 473 | // adjust to permyriad |
| 474 | mSignalMeter.setImageLevel(level * (MAX_IMAGE_LEVEL / 100)); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 475 | mSignalIcon.setImageResource(isWifi ? R.drawable.ic_sysbar_wifi_mini |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 476 | : R.drawable.ic_sysbar_wifi_mini); // XXX |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 477 | } |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 478 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 479 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 480 | public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 481 | if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | public void updateIcon(String slot, int index, int viewIndex, |
| 485 | StatusBarIcon old, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 486 | if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | public void removeIcon(String slot, int index, int viewIndex) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 490 | if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")"); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | public void addNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 494 | if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")"); |
| 495 | addNotificationViews(key, notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 496 | |
| 497 | boolean immersive = false; |
| 498 | try { |
| 499 | immersive = ActivityManagerNative.getDefault().isTopActivityImmersive(); |
| 500 | Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); |
| 501 | } catch (RemoteException ex) { |
| 502 | } |
| 503 | if (immersive) { |
| 504 | // TODO: immersive mode popups for tablet |
| 505 | } else if (notification.notification.fullScreenIntent != null) { |
| 506 | // not immersive & a full-screen alert should be shown |
| 507 | Slog.d(TAG, "Notification has fullScreenIntent and activity is not immersive;" |
| 508 | + " sending fullScreenIntent"); |
| 509 | try { |
| 510 | notification.notification.fullScreenIntent.send(); |
| 511 | } catch (PendingIntent.CanceledException e) { |
| 512 | } |
| 513 | } else { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 514 | tick(notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 515 | } |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 516 | |
| 517 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 521 | if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO"); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 522 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 523 | final NotificationData.Entry oldEntry = mNotns.findByKey(key); |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 524 | if (oldEntry == null) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 525 | Slog.w(TAG, "updateNotification for unknown key: " + key); |
| 526 | return; |
| 527 | } |
| 528 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 529 | final StatusBarNotification oldNotification = oldEntry.notification; |
| 530 | final RemoteViews oldContentView = oldNotification.notification.contentView; |
| 531 | |
| 532 | final RemoteViews contentView = notification.notification.contentView; |
| 533 | |
| 534 | if (false) { |
| 535 | Slog.d(TAG, "old notification: when=" + oldNotification.notification.when |
| 536 | + " ongoing=" + oldNotification.isOngoing() |
| 537 | + " expanded=" + oldEntry.expanded |
| 538 | + " contentView=" + oldContentView); |
| 539 | Slog.d(TAG, "new notification: when=" + notification.notification.when |
| 540 | + " ongoing=" + oldNotification.isOngoing() |
| 541 | + " contentView=" + contentView); |
| 542 | } |
| 543 | |
| 544 | // Can we just reapply the RemoteViews in place? If when didn't change, the order |
| 545 | // didn't change. |
| 546 | if (notification.notification.when == oldNotification.notification.when |
| 547 | && notification.isOngoing() == oldNotification.isOngoing() |
| 548 | && oldEntry.expanded != null |
| 549 | && contentView != null |
| 550 | && oldContentView != null |
| 551 | && contentView.getPackage() != null |
| 552 | && oldContentView.getPackage() != null |
| 553 | && oldContentView.getPackage().equals(contentView.getPackage()) |
| 554 | && oldContentView.getLayoutId() == contentView.getLayoutId()) { |
| 555 | if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key); |
| 556 | oldEntry.notification = notification; |
| 557 | try { |
| 558 | // Reapply the RemoteViews |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 559 | contentView.reapply(mContext, oldEntry.content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 560 | // update the contentIntent |
| 561 | final PendingIntent contentIntent = notification.notification.contentIntent; |
| 562 | if (contentIntent != null) { |
| 563 | oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent, |
| 564 | notification.pkg, notification.tag, notification.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 565 | } else { |
| 566 | oldEntry.content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 567 | } |
| 568 | // Update the icon. |
| 569 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 570 | notification.notification.icon, notification.notification.iconLevel, |
| 571 | notification.notification.number); |
| 572 | if (!oldEntry.icon.set(ic)) { |
| 573 | handleNotificationError(key, notification, "Couldn't update icon: " + ic); |
| 574 | return; |
| 575 | } |
| 576 | } |
| 577 | catch (RuntimeException e) { |
| 578 | // It failed to add cleanly. Log, and remove the view from the panel. |
| 579 | Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); |
| 580 | removeNotificationViews(key); |
| 581 | addNotificationViews(key, notification); |
| 582 | } |
| 583 | } else { |
| 584 | if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key); |
| 585 | removeNotificationViews(key); |
| 586 | addNotificationViews(key, notification); |
| 587 | } |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 588 | // TODO: ticker; immersive mode |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 589 | |
| 590 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | public void removeNotification(IBinder key) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 594 | if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ") // TODO"); |
| 595 | removeNotificationViews(key); |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 596 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | public void disable(int state) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 600 | int old = mDisabled; |
| 601 | int diff = state ^ old; |
| 602 | Slog.d(TAG, "disable... old=0x" + Integer.toHexString(old) |
| 603 | + " diff=0x" + Integer.toHexString(diff) |
| 604 | + " state=0x" + Integer.toHexString(state)); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 605 | mDisabled = state; |
| 606 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 607 | // act accordingly |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 608 | if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 609 | if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 610 | Slog.d(TAG, "DISABLE_EXPAND: yes"); |
| 611 | animateCollapse(); |
| 612 | } |
| 613 | } |
| 614 | if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 615 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 616 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 617 | setViewVisibility(mNotificationTrigger, View.GONE, |
| 618 | R.anim.notification_icons_out); |
| 619 | setViewVisibility(mNotificationIconArea, View.GONE, |
| 620 | R.anim.notification_icons_out); |
| 621 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 622 | } else { |
| 623 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 624 | setViewVisibility(mNotificationTrigger, View.VISIBLE, |
| 625 | R.anim.notification_icons_in); |
| 626 | setViewVisibility(mNotificationIconArea, View.VISIBLE, |
| 627 | R.anim.notification_icons_in); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 628 | } |
| 629 | } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 630 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 631 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 632 | } |
| 633 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 634 | if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { |
| 635 | if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { |
| 636 | Slog.d(TAG, "DISABLE_SYSTEM_INFO: yes"); |
| 637 | setViewVisibility(mSystemInfo, View.GONE, R.anim.navigation_out); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 638 | } else { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 639 | Slog.d(TAG, "DISABLE_SYSTEM_INFO: no"); |
| 640 | setViewVisibility(mSystemInfo, View.VISIBLE, R.anim.navigation_in); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 641 | } |
| 642 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 643 | if ((diff & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 644 | if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 645 | Slog.d(TAG, "DISABLE_NAVIGATION: yes"); |
| 646 | setViewVisibility(mNavigationArea, View.GONE, R.anim.navigation_out); |
| 647 | } else { |
| 648 | Slog.d(TAG, "DISABLE_NAVIGATION: no"); |
| 649 | setViewVisibility(mNavigationArea, View.VISIBLE, R.anim.navigation_in); |
| 650 | } |
| 651 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 652 | } |
| 653 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 654 | private boolean hasTicker(Notification n) { |
| 655 | return !TextUtils.isEmpty(n.tickerText) |
| 656 | || !TextUtils.isEmpty(n.tickerTitle) |
| 657 | || !TextUtils.isEmpty(n.tickerSubtitle); |
| 658 | } |
| 659 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 660 | private void tick(StatusBarNotification n) { |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 661 | // Don't show the ticker when the windowshade is open. |
| 662 | if (mNotificationPanel.getVisibility() == View.VISIBLE) { |
| 663 | return; |
| 664 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 665 | // Show the ticker if one is requested. Also don't do this |
| 666 | // until status bar window is attached to the window manager, |
| 667 | // because... well, what's the point otherwise? And trying to |
| 668 | // run a ticker without being attached will crash! |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 669 | if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 670 | if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 671 | | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 672 | mTicker.add(n); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 677 | public void animateExpand() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 678 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); |
| 679 | mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | public void animateCollapse() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 683 | mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL); |
| 684 | mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL); |
| 685 | mHandler.removeMessages(MSG_CLOSE_SYSTEM_PANEL); |
| 686 | mHandler.sendEmptyMessage(MSG_CLOSE_SYSTEM_PANEL); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 687 | mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); |
| 688 | mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 689 | } |
| 690 | |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 691 | // called by StatusBarService |
| 692 | @Override |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 693 | public void setLightsOn(boolean on) { |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 694 | mHandler.removeMessages(MSG_LIGHTS_OUT); |
| 695 | mHandler.removeMessages(MSG_LIGHTS_ON); |
| 696 | mHandler.sendEmptyMessage(on ? MSG_LIGHTS_ON : MSG_LIGHTS_OUT); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 697 | } |
| 698 | |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 699 | public void setMenuKeyVisible(boolean visible) { |
| 700 | if (DEBUG) { |
| 701 | Slog.d(TAG, (visible?"showing":"hiding") + " the MENU button"); |
| 702 | } |
| 703 | setViewVisibility(mMenuButton, |
| 704 | visible ? View.VISIBLE : View.INVISIBLE, |
| 705 | visible ? R.anim.navigation_in : R.anim.navigation_out); |
| 706 | } |
| 707 | |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 708 | public void setIMEButtonVisible(boolean visible) { |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 709 | if (DEBUG) { |
| 710 | Slog.d(TAG, (visible?"showing":"hiding") + " the IME button"); |
| 711 | } |
| 712 | mInputMethodButton.setIMEButtonVisible(visible); |
| 713 | } |
| 714 | |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 715 | private void setAreThereNotifications() { |
| 716 | final boolean hasClearable = mNotns.hasClearableItems(); |
| 717 | |
| 718 | //Slog.d(TAG, "setAreThereNotifications hasClerable=" + hasClearable); |
| 719 | |
| 720 | // Show or hide the "Clear all" button. Note that we don't do an animation |
| 721 | // if it's not on screen, so that if someone opens the bar right then they |
| 722 | // don't see the animation in progress. |
| 723 | // (no ongoing notifications are clearable) |
| 724 | if (hasClearable) { |
| 725 | if (mNotificationButtons.getVisibility() == View.VISIBLE) { |
| 726 | setViewVisibility(mClearButton, View.VISIBLE, R.anim.notification_buttons_in); |
| 727 | } else { |
| 728 | mClearButton.setVisibility(View.VISIBLE); |
| 729 | } |
| 730 | } else { |
| 731 | if (mNotificationButtons.getVisibility() == View.VISIBLE) { |
| 732 | setViewVisibility(mClearButton, View.GONE, R.anim.notification_buttons_out); |
| 733 | } else { |
| 734 | mClearButton.setVisibility(View.GONE); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | mOngoingTitle.setVisibility(ongoing ? View.VISIBLE : View.GONE); |
| 740 | mLatestTitle.setVisibility(latest ? View.VISIBLE : View.GONE); |
| 741 | |
| 742 | if (ongoing || latest) { |
| 743 | mNoNotificationsTitle.setVisibility(View.GONE); |
| 744 | } else { |
| 745 | mNoNotificationsTitle.setVisibility(View.VISIBLE); |
| 746 | } |
| 747 | */ |
| 748 | } |
| 749 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 750 | /** |
| 751 | * Cancel this notification and tell the status bar service about the failure. Hold no locks. |
| 752 | */ |
| 753 | void handleNotificationError(IBinder key, StatusBarNotification n, String message) { |
| 754 | removeNotification(key); |
| 755 | try { |
| 756 | mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); |
| 757 | } catch (RemoteException ex) { |
| 758 | // The end is nigh. |
| 759 | } |
| 760 | } |
| 761 | |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 762 | private class ClockTouchListener implements View.OnTouchListener { |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 763 | VelocityTracker mVT = null; |
| 764 | int mInitX, mInitY; |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 765 | public boolean onTouch (View v, MotionEvent event) { |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 766 | final int x = (int) event.getX(); |
| 767 | final int y = (int) event.getY(); |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 768 | switch (event.getAction()) { |
| 769 | case MotionEvent.ACTION_DOWN: |
| 770 | mVT = VelocityTracker.obtain(); |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 771 | mInitX = x; |
| 772 | mInitY = y; |
| 773 | mHandler.sendEmptyMessageDelayed(MSG_LIGHTS_OUT, |
| 774 | ViewConfiguration.getLongPressTimeout()); |
| 775 | break; |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 776 | case MotionEvent.ACTION_OUTSIDE: |
| 777 | case MotionEvent.ACTION_MOVE: |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 778 | final Rect r = new Rect(); |
| 779 | final float radius = mSystemInfo.getHeight() / 2; |
| 780 | if (Math.abs(x - mInitX) > radius || Math.abs(y - mInitY) > radius) { |
| 781 | mHandler.removeMessages(MSG_LIGHTS_OUT); |
| 782 | } |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 783 | if (mVT == null) break; |
| 784 | mVT.addMovement(event); |
| 785 | mVT.computeCurrentVelocity(1000); |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 786 | if (mVT.getYVelocity() < -200 && mSystemPanel.getVisibility() == View.GONE) { |
| 787 | mHandler.removeMessages(MSG_OPEN_SYSTEM_PANEL); |
| 788 | mHandler.sendEmptyMessage(MSG_OPEN_SYSTEM_PANEL); |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 789 | } else if (mVT.getYVelocity() > 200) { |
| 790 | mHandler.sendEmptyMessage(MSG_LIGHTS_OUT); |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 791 | } |
| 792 | return true; |
| 793 | case MotionEvent.ACTION_UP: |
| 794 | case MotionEvent.ACTION_CANCEL: |
| 795 | mVT.recycle(); |
| 796 | mVT = null; |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 797 | mHandler.removeMessages(MSG_LIGHTS_OUT); |
Daniel Sandler | 8304da4 | 2010-10-25 15:53:25 -0400 | [diff] [blame] | 798 | return true; |
| 799 | } |
| 800 | return false; |
| 801 | } |
| 802 | } |
| 803 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 804 | private View.OnClickListener mOnClickListener = new View.OnClickListener() { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 805 | public void onClick(View v) { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 806 | if (v == mClearButton) { |
| 807 | onClickClearButton(); |
| 808 | } else if (v == mDoNotDisturbButton) { |
| 809 | onClickDoNotDisturb(); |
| 810 | } else if (v == mNotificationTrigger) { |
| 811 | onClickNotificationTrigger(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 812 | } else if (v == mRecentButton) { |
| 813 | onClickRecentButton(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 814 | } |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 815 | } |
| 816 | }; |
| 817 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 818 | void onClickClearButton() { |
| 819 | try { |
| 820 | mBarService.onClearAllNotifications(); |
| 821 | } catch (RemoteException ex) { |
| 822 | // system process is dead if we're here. |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 823 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 824 | animateCollapse(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 825 | refreshNotificationTrigger(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | void onClickDoNotDisturb() { |
| 829 | mNotificationsOn = !mNotificationsOn; |
Daniel Sandler | cf3c7cf | 2010-10-22 15:30:12 -0400 | [diff] [blame] | 830 | mIconLayout.setVisibility(mNotificationsOn ? View.VISIBLE : View.INVISIBLE); // TODO: animation |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 831 | animateCollapse(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 832 | refreshNotificationTrigger(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | public void onClickNotificationTrigger() { |
| 836 | if (DEBUG) Slog.d(TAG, "clicked notification icons"); |
| 837 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 838 | if (!mNotificationsOn) { |
| 839 | mNotificationsOn = true; |
Daniel Sandler | cf3c7cf | 2010-10-22 15:30:12 -0400 | [diff] [blame] | 840 | mIconLayout.setVisibility(View.VISIBLE); // TODO: animation |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 841 | refreshNotificationTrigger(); |
| 842 | } else { |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 843 | int msg = (mNotificationPanel.getVisibility() == View.GONE) |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 844 | ? MSG_OPEN_NOTIFICATION_PANEL |
| 845 | : MSG_CLOSE_NOTIFICATION_PANEL; |
| 846 | mHandler.removeMessages(msg); |
| 847 | mHandler.sendEmptyMessage(msg); |
| 848 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
| 852 | public void onClickSystemInfo() { |
| 853 | if (DEBUG) Slog.d(TAG, "clicked system info"); |
| 854 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 855 | int msg = (mSystemPanel.getVisibility() == View.GONE) |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 856 | ? MSG_OPEN_SYSTEM_PANEL |
| 857 | : MSG_CLOSE_SYSTEM_PANEL; |
| 858 | mHandler.removeMessages(msg); |
| 859 | mHandler.sendEmptyMessage(msg); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | public void onClickRecentButton() { |
| 864 | if (DEBUG) Slog.d(TAG, "clicked recent apps"); |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 865 | if (mRecentsPanel == null) { |
| 866 | Intent intent = new Intent(); |
| 867 | intent.setClass(mContext, RecentApplicationsActivity.class); |
| 868 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 869 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 870 | mContext.startActivity(intent); |
| 871 | } else { |
| 872 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
| 873 | int msg = (mRecentsPanel.getVisibility() == View.GONE) |
| 874 | ? MSG_OPEN_RECENTS_PANEL |
| 875 | : MSG_CLOSE_RECENTS_PANEL; |
| 876 | mHandler.removeMessages(msg); |
| 877 | mHandler.sendEmptyMessage(msg); |
| 878 | } |
| 879 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 880 | } |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 881 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 882 | private class NotificationClicker implements View.OnClickListener { |
| 883 | private PendingIntent mIntent; |
| 884 | private String mPkg; |
| 885 | private String mTag; |
| 886 | private int mId; |
| 887 | |
| 888 | NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { |
| 889 | mIntent = intent; |
| 890 | mPkg = pkg; |
| 891 | mTag = tag; |
| 892 | mId = id; |
| 893 | } |
| 894 | |
| 895 | public void onClick(View v) { |
| 896 | try { |
| 897 | // The intent we are sending is for the application, which |
| 898 | // won't have permission to immediately start an activity after |
| 899 | // the user switches to home. We know it is safe to do at this |
| 900 | // point, so make sure new activity switches are now allowed. |
| 901 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 902 | } catch (RemoteException e) { |
| 903 | } |
| 904 | |
| 905 | if (mIntent != null) { |
| 906 | int[] pos = new int[2]; |
| 907 | v.getLocationOnScreen(pos); |
| 908 | Intent overlay = new Intent(); |
| 909 | overlay.setSourceBounds( |
| 910 | new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); |
| 911 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 912 | mIntent.send(mContext, 0, overlay); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 913 | } catch (PendingIntent.CanceledException e) { |
| 914 | // the stack trace isn't very helpful here. Just log the exception message. |
| 915 | Slog.w(TAG, "Sending contentIntent failed: " + e); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | try { |
| 920 | mBarService.onNotificationClick(mPkg, mTag, mId); |
| 921 | } catch (RemoteException ex) { |
| 922 | // system process is dead if we're here. |
| 923 | } |
| 924 | |
| 925 | // close the shade if it was open |
| 926 | animateCollapse(); |
| 927 | |
| 928 | // If this click was on the intruder alert, hide that instead |
| 929 | // mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | StatusBarNotification removeNotificationViews(IBinder key) { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 934 | NotificationData.Entry entry = mNotns.remove(key); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 935 | if (entry == null) { |
| 936 | Slog.w(TAG, "removeNotification for unknown key: " + key); |
| 937 | return null; |
| 938 | } |
| 939 | // Remove the expanded view. |
| 940 | ViewGroup rowParent = (ViewGroup)entry.row.getParent(); |
| 941 | if (rowParent != null) rowParent.removeView(entry.row); |
| 942 | // Remove the icon. |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 943 | // ViewGroup iconParent = (ViewGroup)entry.icon.getParent(); |
| 944 | // if (iconParent != null) iconParent.removeView(entry.icon); |
| 945 | refreshIcons(); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 946 | |
| 947 | return entry.notification; |
| 948 | } |
| 949 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 950 | private class NotificationIconTouchListener implements View.OnTouchListener { |
| 951 | VelocityTracker mVT; |
| 952 | |
| 953 | public NotificationIconTouchListener() { |
| 954 | } |
| 955 | |
| 956 | public boolean onTouch(View v, MotionEvent event) { |
| 957 | boolean peeking = mNotificationPeekWindow.getVisibility() != View.GONE; |
| 958 | boolean panelShowing = mNotificationPanel.getVisibility() != View.GONE; |
| 959 | if (panelShowing) return false; |
| 960 | |
| 961 | switch (event.getAction()) { |
| 962 | case MotionEvent.ACTION_DOWN: |
| 963 | mVT = VelocityTracker.obtain(); |
| 964 | |
| 965 | // fall through |
| 966 | case MotionEvent.ACTION_OUTSIDE: |
| 967 | case MotionEvent.ACTION_MOVE: |
| 968 | // peek and switch icons if necessary |
| 969 | int numIcons = mIconLayout.getChildCount(); |
| 970 | int peekIndex = |
| 971 | (int)((float)event.getX() * numIcons / mIconLayout.getWidth()); |
| 972 | if (peekIndex > numIcons - 1) peekIndex = numIcons - 1; |
| 973 | else if (peekIndex < 0) peekIndex = 0; |
| 974 | |
| 975 | if (!peeking || mNotificationPeekIndex != peekIndex) { |
| 976 | if (DEBUG) Slog.d(TAG, "will peek at notification #" + peekIndex); |
| 977 | Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); |
| 978 | peekMsg.arg1 = peekIndex; |
| 979 | |
| 980 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); |
| 981 | |
| 982 | // no delay if we're scrubbing left-right |
| 983 | mHandler.sendMessageDelayed(peekMsg, |
| 984 | peeking ? 0 : mNotificationPeekTapDuration); |
| 985 | } |
| 986 | |
| 987 | // check for fling |
| 988 | if (mVT != null) { |
| 989 | mVT.addMovement(event); |
| 990 | mVT.computeCurrentVelocity(1000); |
| 991 | // require a little more oomph once we're already in peekaboo mode |
| 992 | if (!panelShowing && ( |
| 993 | (peeking && mVT.getYVelocity() < -mNotificationFlingVelocity*3) |
| 994 | || (mVT.getYVelocity() < -mNotificationFlingVelocity))) { |
| 995 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); |
| 996 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); |
| 997 | mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); |
| 998 | mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); |
| 999 | } |
| 1000 | } |
| 1001 | return true; |
| 1002 | case MotionEvent.ACTION_UP: |
| 1003 | case MotionEvent.ACTION_CANCEL: |
| 1004 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); |
| 1005 | if (peeking) { |
| 1006 | mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK, 250); |
| 1007 | } |
| 1008 | mVT.recycle(); |
| 1009 | mVT = null; |
| 1010 | return true; |
| 1011 | } |
| 1012 | return false; |
| 1013 | } |
| 1014 | } |
| 1015 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1016 | StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1017 | if (DEBUG) { |
| 1018 | Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); |
| 1019 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1020 | // Construct the icon. |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1021 | final StatusBarIconView iconView = new StatusBarIconView(mContext, |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1022 | notification.pkg + "/0x" + Integer.toHexString(notification.id)); |
| 1023 | iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 1024 | |
| 1025 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 1026 | notification.notification.icon, |
| 1027 | notification.notification.iconLevel, |
| 1028 | notification.notification.number); |
| 1029 | if (!iconView.set(ic)) { |
| 1030 | handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic); |
| 1031 | return null; |
| 1032 | } |
| 1033 | // Construct the expanded view. |
| 1034 | NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1035 | if (!inflateViews(entry, mPile)) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1036 | handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " |
| 1037 | + notification); |
| 1038 | return null; |
| 1039 | } |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1040 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1041 | // Add the icon. |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1042 | mNotns.add(entry); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1043 | refreshIcons(); |
| 1044 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1045 | return iconView; |
| 1046 | } |
| 1047 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1048 | private void refreshIcons() { |
| 1049 | // XXX: need to implement a new limited linear layout class |
| 1050 | // to avoid removing & readding everything |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1051 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1052 | final int ICON_LIMIT = 4; |
| 1053 | final LinearLayout.LayoutParams params |
| 1054 | = new LinearLayout.LayoutParams(mIconSize, mIconSize); |
| 1055 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1056 | int N = mNotns.size(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1057 | |
| 1058 | if (DEBUG) { |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1059 | Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1062 | ArrayList<View> toShow = new ArrayList<View>(); |
| 1063 | |
| 1064 | for (int i=0; i<ICON_LIMIT; i++) { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1065 | if (i>=N) break; |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1066 | toShow.add(mNotns.get(N-i-1).icon); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1067 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1068 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1069 | ArrayList<View> toRemove = new ArrayList<View>(); |
| 1070 | for (int i=0; i<mIconLayout.getChildCount(); i++) { |
| 1071 | View child = mIconLayout.getChildAt(i); |
| 1072 | if (!toShow.contains(child)) { |
| 1073 | toRemove.add(child); |
| 1074 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 1075 | } |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 1076 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1077 | for (View remove : toRemove) { |
| 1078 | mIconLayout.removeView(remove); |
| 1079 | } |
| 1080 | |
| 1081 | for (int i=0; i<toShow.size(); i++) { |
| 1082 | View v = toShow.get(i); |
| 1083 | if (v.getParent() == null) { |
| 1084 | mIconLayout.addView(toShow.get(i), i, params); |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | loadNotificationPanel(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 1089 | refreshNotificationTrigger(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 1092 | private void loadNotificationPanel() { |
| 1093 | int N = mNotns.size(); |
| 1094 | |
| 1095 | ArrayList<View> toShow = new ArrayList<View>(); |
| 1096 | |
| 1097 | for (int i=0; i<N; i++) { |
| 1098 | View row = mNotns.get(N-i-1).row; |
| 1099 | toShow.add(row); |
| 1100 | } |
| 1101 | |
| 1102 | ArrayList<View> toRemove = new ArrayList<View>(); |
| 1103 | for (int i=0; i<mPile.getChildCount(); i++) { |
| 1104 | View child = mPile.getChildAt(i); |
| 1105 | if (!toShow.contains(child)) { |
| 1106 | toRemove.add(child); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | for (View remove : toRemove) { |
| 1111 | mPile.removeView(remove); |
| 1112 | } |
| 1113 | |
| 1114 | for (int i=0; i<toShow.size(); i++) { |
| 1115 | View v = toShow.get(i); |
| 1116 | if (v.getParent() == null) { |
| 1117 | mPile.addView(toShow.get(i)); |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1122 | private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { |
| 1123 | StatusBarNotification sbn = entry.notification; |
| 1124 | RemoteViews remoteViews = sbn.notification.contentView; |
| 1125 | if (remoteViews == null) { |
| 1126 | return false; |
| 1127 | } |
| 1128 | |
| 1129 | // create the row view |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1130 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( |
| 1131 | Context.LAYOUT_INFLATER_SERVICE); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1132 | View row = inflater.inflate(R.layout.status_bar_latest_event, parent, false); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1133 | View vetoButton = row.findViewById(R.id.veto); |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 1134 | if (entry.notification.isClearable()) { |
| 1135 | final String _pkg = sbn.pkg; |
| 1136 | final String _tag = sbn.tag; |
| 1137 | final int _id = sbn.id; |
Jim Miller | 44c66fe | 2010-10-20 18:32:52 -0700 | [diff] [blame] | 1138 | vetoButton.setOnClickListener(new View.OnClickListener() { |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 1139 | public void onClick(View v) { |
| 1140 | try { |
| 1141 | mBarService.onNotificationClear(_pkg, _tag, _id); |
| 1142 | } catch (RemoteException ex) { |
| 1143 | // system process is dead if we're here. |
| 1144 | } |
| 1145 | // animateCollapse(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 1146 | } |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 1147 | }); |
| 1148 | } else { |
| 1149 | vetoButton.setVisibility(View.INVISIBLE); |
| 1150 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1151 | |
| 1152 | // bind the click event to the content area |
| 1153 | ViewGroup content = (ViewGroup)row.findViewById(R.id.content); |
| 1154 | // XXX: update to allow controls within notification views |
| 1155 | content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); |
| 1156 | // content.setOnFocusChangeListener(mFocusChangeListener); |
| 1157 | PendingIntent contentIntent = sbn.notification.contentIntent; |
| 1158 | if (contentIntent != null) { |
| 1159 | content.setOnClickListener(new NotificationClicker(contentIntent, |
| 1160 | sbn.pkg, sbn.tag, sbn.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 1161 | } else { |
| 1162 | content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | View expanded = null; |
| 1166 | Exception exception = null; |
| 1167 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1168 | expanded = remoteViews.apply(mContext, content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 1169 | } |
| 1170 | catch (RuntimeException e) { |
| 1171 | exception = e; |
| 1172 | } |
| 1173 | if (expanded == null) { |
| 1174 | String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); |
| 1175 | Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); |
| 1176 | return false; |
| 1177 | } else { |
| 1178 | content.addView(expanded); |
| 1179 | row.setDrawingCacheEnabled(true); |
| 1180 | } |
| 1181 | |
| 1182 | entry.row = row; |
| 1183 | entry.content = content; |
| 1184 | entry.expanded = expanded; |
| 1185 | |
| 1186 | return true; |
| 1187 | } |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 1188 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 1189 | public class SetLightsOnListener implements View.OnLongClickListener, |
| 1190 | View.OnClickListener { |
| 1191 | private boolean mOn; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 1192 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 1193 | SetLightsOnListener(boolean on) { |
| 1194 | mOn = on; |
| 1195 | } |
| 1196 | |
| 1197 | public void onClick(View v) { |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 1198 | setLightsOn(mOn); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | public boolean onLongClick(View v) { |
Daniel Sandler | 06e6630 | 2010-11-05 15:00:06 -0400 | [diff] [blame] | 1202 | setLightsOn(mOn); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 1203 | return true; |
| 1204 | } |
| 1205 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 1206 | } |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1207 | |
| 1208 | public class TouchOutsideListener implements View.OnTouchListener { |
| 1209 | private int mMsg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1210 | private StatusBarPanel mPanel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1211 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1212 | public TouchOutsideListener(int msg, StatusBarPanel panel) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1213 | mMsg = msg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1214 | mPanel = panel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | public boolean onTouch(View v, MotionEvent ev) { |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1218 | final int action = ev.getAction(); |
| 1219 | if (action == MotionEvent.ACTION_OUTSIDE |
| 1220 | || (action == MotionEvent.ACTION_DOWN |
| 1221 | && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 1222 | mHandler.removeMessages(mMsg); |
| 1223 | mHandler.sendEmptyMessage(mMsg); |
| 1224 | return true; |
| 1225 | } |
| 1226 | return false; |
| 1227 | } |
| 1228 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 1229 | |
| 1230 | private void setViewVisibility(View v, int vis, int anim) { |
| 1231 | if (v.getVisibility() != vis) { |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 1232 | //Slog.d(TAG, "setViewVisibility vis=" + (vis == View.VISIBLE) + " v=" + v); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1233 | v.setAnimation(AnimationUtils.loadAnimation(mContext, anim)); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 1234 | v.setVisibility(vis); |
| 1235 | } |
| 1236 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 1237 | |
| 1238 | |
| 1239 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1240 | pw.print("mDisabled=0x"); |
| 1241 | pw.println(Integer.toHexString(mDisabled)); |
| 1242 | } |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 1243 | } |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 1244 | |
| 1245 | |