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; |
| 21 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 22 | import android.app.ActivityManagerNative; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 23 | import android.app.PendingIntent; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 24 | import android.app.Notification; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 25 | import android.app.StatusBarManager; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
| 28 | import android.content.res.Resources; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 29 | import android.graphics.PixelFormat; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 30 | import android.graphics.Rect; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 31 | import android.os.Handler; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 32 | import android.os.IBinder; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 33 | import android.os.Message; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 34 | import android.os.RemoteException; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 35 | import android.text.TextUtils; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 36 | import android.util.Slog; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 37 | import android.view.animation.Animation; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 38 | import android.view.animation.AnimationUtils; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 39 | import android.view.Gravity; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 40 | import android.view.LayoutInflater; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 41 | import android.view.MotionEvent; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 42 | import android.view.View; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 43 | import android.view.ViewGroup; |
| 44 | import android.view.WindowManager; |
| 45 | import android.view.WindowManagerImpl; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 46 | import android.widget.FrameLayout; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 47 | import android.widget.ImageView; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 48 | import android.widget.LinearLayout; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 49 | import android.widget.RemoteViews; |
| 50 | import android.widget.ScrollView; |
| 51 | import android.widget.TextSwitcher; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 52 | import android.widget.TextView; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 53 | |
| 54 | import com.android.internal.statusbar.StatusBarIcon; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 55 | import com.android.internal.statusbar.StatusBarNotification; |
| 56 | |
| 57 | import com.android.systemui.statusbar.*; |
Joe Onorato | 013cfc1 | 2010-09-08 15:23:18 -0400 | [diff] [blame] | 58 | import com.android.systemui.recent.RecentApplicationsActivity; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 59 | import com.android.systemui.R; |
| 60 | |
| 61 | public class TabletStatusBarService extends StatusBarService { |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 62 | public static final boolean DEBUG = false; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 63 | public static final String TAG = "TabletStatusBarService"; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 64 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 65 | public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; |
| 66 | public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001; |
| 67 | public static final int MSG_OPEN_SYSTEM_PANEL = 1010; |
| 68 | public static final int MSG_CLOSE_SYSTEM_PANEL = 1011; |
| 69 | |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 70 | private static final int MAX_IMAGE_LEVEL = 10000; |
| 71 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 72 | int mIconSize; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 73 | |
| 74 | H mHandler = new H(); |
| 75 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 76 | // tracking all current notifications |
| 77 | private NotificationData mNotns = new NotificationData(); |
| 78 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 79 | TabletStatusBarView mStatusBarView; |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 80 | ImageView mNotificationTrigger; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 81 | NotificationIconArea mNotificationIconArea; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 82 | View mNotificationButtons; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 83 | View mSystemInfo; |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 84 | View mNavigationArea; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 85 | View mMenuButton; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 86 | View mRecentButton; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 87 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 88 | NotificationPanel mNotificationPanel; |
Daniel Sandler | 6425ef9 | 2010-08-11 16:10:19 -0400 | [diff] [blame] | 89 | SystemPanel mSystemPanel; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 90 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 91 | ViewGroup mPile; |
| 92 | TextView mClearButton; |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 93 | TextView mDoNotDisturbButton; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 94 | |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 95 | ImageView mBatteryMeter; |
| 96 | ImageView mSignalMeter; |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 97 | ImageView mSignalIcon; |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 98 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 99 | View mBarContents; |
| 100 | View mCurtains; |
| 101 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 102 | NotificationIconArea.IconLayout mIconLayout; |
| 103 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 104 | TabletTicker mTicker; |
| 105 | View mTickerView; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 106 | boolean mTicking; |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 107 | |
| 108 | // for disabling the status bar |
| 109 | int mDisabled = 0; |
| 110 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 111 | boolean mNotificationsOn = true; |
| 112 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 113 | protected void addPanelWindows() { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 114 | final Context context = mContext; |
| 115 | |
| 116 | final Resources res = context.getResources(); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 117 | final int barHeight= res.getDimensionPixelSize( |
| 118 | com.android.internal.R.dimen.status_bar_height); |
| 119 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 120 | mNotificationPanel = (NotificationPanel)View.inflate(context, |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 121 | R.layout.sysbar_panel_notifications, null); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 122 | mNotificationPanel.setVisibility(View.GONE); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 123 | mNotificationPanel.setOnTouchListener( |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 124 | new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel)); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 125 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 126 | mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 127 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 128 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 129 | 400, // ViewGroup.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 130 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 131 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 132 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 133 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
| 134 | PixelFormat.TRANSLUCENT); |
Joe Onorato | ea70e63 | 2010-09-27 17:59:37 -0700 | [diff] [blame] | 135 | lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 136 | lp.setTitle("NotificationPanel"); |
| 137 | lp.windowAnimations = com.android.internal.R.style.Animation_SlidingCard; |
| 138 | |
| 139 | WindowManagerImpl.getDefault().addView(mNotificationPanel, lp); |
| 140 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 141 | mSystemPanel = (SystemPanel) View.inflate(context, R.layout.sysbar_panel_system, null); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 142 | mSystemPanel.setVisibility(View.GONE); |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 143 | mSystemPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_SYSTEM_PANEL, |
| 144 | mSystemPanel)); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 145 | |
| 146 | mStatusBarView.setIgnoreChildren(1, mSystemInfo, mSystemPanel); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 147 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 148 | lp = new WindowManager.LayoutParams( |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 149 | 800, |
Daniel Sandler | 6425ef9 | 2010-08-11 16:10:19 -0400 | [diff] [blame] | 150 | ViewGroup.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 151 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
| 152 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 153 | | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
| 154 | PixelFormat.TRANSLUCENT); |
| 155 | lp.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; |
| 156 | lp.setTitle("SystemPanel"); |
| 157 | lp.windowAnimations = com.android.internal.R.style.Animation_SlidingCard; |
| 158 | |
| 159 | WindowManagerImpl.getDefault().addView(mSystemPanel, lp); |
Daniel Sandler | 6425ef9 | 2010-08-11 16:10:19 -0400 | [diff] [blame] | 160 | mSystemPanel.setBar(this); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 161 | } |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 162 | |
| 163 | @Override |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 164 | public void start() { |
| 165 | super.start(); // will add the main bar view |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | protected View makeStatusBarView() { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 169 | final Context context = mContext; |
| 170 | final Resources res = context.getResources(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 171 | |
| 172 | mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); |
| 173 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 174 | final TabletStatusBarView sb = (TabletStatusBarView)View.inflate( |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 175 | context, R.layout.status_bar, null); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 176 | mStatusBarView = sb; |
| 177 | |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 178 | sb.setHandler(mHandler); |
| 179 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 180 | mBarContents = sb.findViewById(R.id.bar_contents); |
| 181 | mCurtains = sb.findViewById(R.id.lights_out); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 182 | mSystemInfo = sb.findViewById(R.id.systemInfo); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 183 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 184 | mSystemInfo.setOnClickListener(mOnClickListener); |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 185 | mSystemInfo.setOnLongClickListener(new SetLightsOnListener(false)); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 186 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 187 | mRecentButton = sb.findViewById(R.id.recent); |
| 188 | mRecentButton.setOnClickListener(mOnClickListener); |
| 189 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 190 | SetLightsOnListener on = new SetLightsOnListener(true); |
| 191 | mCurtains.setOnClickListener(on); |
| 192 | mCurtains.setOnLongClickListener(on); |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 193 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 194 | // the button to open the notification area |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 195 | mNotificationTrigger = (ImageView) sb.findViewById(R.id.notificationTrigger); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 196 | mNotificationTrigger.setOnClickListener(mOnClickListener); |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 197 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 198 | // the more notifications icon |
| 199 | mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons); |
| 200 | |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 201 | // the clear and dnd buttons |
| 202 | mNotificationButtons = sb.findViewById(R.id.notificationButtons); |
| 203 | mClearButton = (TextView)mNotificationButtons.findViewById(R.id.clear_all_button); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 204 | mClearButton.setOnClickListener(mOnClickListener); |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 205 | mDoNotDisturbButton = (TextView)mNotificationButtons.findViewById(R.id.do_not_disturb); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 206 | mDoNotDisturbButton.setOnClickListener(mOnClickListener); |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 207 | |
| 208 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 209 | // where the icons go |
| 210 | mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons); |
| 211 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 212 | mTicker = new TabletTicker(context, (FrameLayout)sb.findViewById(R.id.ticker)); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 213 | |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 214 | // System info (center) |
| 215 | mBatteryMeter = (ImageView) sb.findViewById(R.id.battery); |
| 216 | mSignalMeter = (ImageView) sb.findViewById(R.id.signal); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 217 | mSignalIcon = (ImageView) sb.findViewById(R.id.signal_icon); |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 218 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 219 | // The navigation buttons |
| 220 | mNavigationArea = sb.findViewById(R.id.navigationArea); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 221 | mMenuButton = mNavigationArea.findViewById(R.id.menu); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 222 | |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 223 | // set the initial view visibility |
| 224 | setAreThereNotifications(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 225 | refreshNotificationTrigger(); |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 226 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 227 | // Add the windows |
| 228 | addPanelWindows(); |
| 229 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 230 | mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content); |
| 231 | mPile.removeAllViews(); |
| 232 | |
| 233 | ScrollView scroller = (ScrollView)mPile.getParent(); |
| 234 | scroller.setFillViewport(true); |
| 235 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 236 | return sb; |
| 237 | } |
| 238 | |
| 239 | protected int getStatusBarGravity() { |
| 240 | return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL; |
| 241 | } |
| 242 | |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 243 | private class H extends Handler { |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 244 | public void handleMessage(Message m) { |
| 245 | switch (m.what) { |
| 246 | case MSG_OPEN_NOTIFICATION_PANEL: |
| 247 | if (DEBUG) Slog.d(TAG, "opening notifications panel"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 248 | if (mNotificationPanel.getVisibility() == View.GONE) { |
| 249 | mDoNotDisturbButton.setText(mNotificationsOn |
| 250 | ? R.string.status_bar_do_not_disturb_button |
| 251 | : R.string.status_bar_please_disturb_button); |
| 252 | mNotificationPanel.setVisibility(View.VISIBLE); |
| 253 | setViewVisibility(mNotificationIconArea, View.GONE, |
| 254 | R.anim.notification_icons_out); |
| 255 | setViewVisibility(mNotificationButtons, View.VISIBLE, |
| 256 | R.anim.notification_buttons_in); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 257 | refreshNotificationTrigger(); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 258 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 259 | break; |
| 260 | case MSG_CLOSE_NOTIFICATION_PANEL: |
| 261 | if (DEBUG) Slog.d(TAG, "closing notifications panel"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 262 | if (mNotificationPanel.getVisibility() == View.VISIBLE) { |
| 263 | mNotificationPanel.setVisibility(View.GONE); |
| 264 | setViewVisibility(mNotificationIconArea, View.VISIBLE, |
| 265 | R.anim.notification_icons_in); |
| 266 | setViewVisibility(mNotificationButtons, View.GONE, |
| 267 | R.anim.notification_buttons_out); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 268 | refreshNotificationTrigger(); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 269 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 270 | break; |
| 271 | case MSG_OPEN_SYSTEM_PANEL: |
| 272 | if (DEBUG) Slog.d(TAG, "opening system panel"); |
| 273 | mSystemPanel.setVisibility(View.VISIBLE); |
| 274 | break; |
| 275 | case MSG_CLOSE_SYSTEM_PANEL: |
| 276 | if (DEBUG) Slog.d(TAG, "closing system panel"); |
| 277 | mSystemPanel.setVisibility(View.GONE); |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 282 | |
| 283 | public void refreshNotificationTrigger() { |
Daniel Sandler | cf3c7cf | 2010-10-22 15:30:12 -0400 | [diff] [blame^] | 284 | if (mNotificationTrigger == null) return; |
| 285 | |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 286 | int resId; |
| 287 | boolean panel = (mNotificationPanel != null |
| 288 | && mNotificationPanel.getVisibility() == View.VISIBLE); |
| 289 | if (!mNotificationsOn) { |
| 290 | resId = R.drawable.ic_sysbar_noti_dnd; |
| 291 | } else if (mNotns.size() > 0) { |
| 292 | resId = panel ? R.drawable.ic_sysbar_noti_avail_open : R.drawable.ic_sysbar_noti_avail; |
| 293 | } else { |
| 294 | resId = panel ? R.drawable.ic_sysbar_noti_none_open : R.drawable.ic_sysbar_noti_none; |
| 295 | } |
| 296 | mNotificationTrigger.setImageResource(resId); |
| 297 | } |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 298 | |
Daniel Sandler | d7db7b1 | 2010-08-13 16:26:39 -0400 | [diff] [blame] | 299 | public void setBatteryMeter(int level, boolean plugged) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 300 | if (DEBUG) Slog.d(TAG, "battery=" + level + (plugged ? " - plugged" : " - unplugged")); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 301 | mBatteryMeter.setImageResource(R.drawable.sysbar_batterymini); |
| 302 | // adjust percent to permyriad for ClipDrawable's sake |
| 303 | mBatteryMeter.setImageLevel(level * (MAX_IMAGE_LEVEL / 100)); |
Daniel Sandler | d7db7b1 | 2010-08-13 16:26:39 -0400 | [diff] [blame] | 304 | } |
| 305 | |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 306 | public void setSignalMeter(int level, boolean isWifi) { |
| 307 | if (DEBUG) Slog.d(TAG, "signal=" + level); |
| 308 | if (level < 0) { |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 309 | mSignalMeter.setImageDrawable(null); |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 310 | mSignalMeter.setImageLevel(0); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 311 | mSignalIcon.setImageDrawable(null); |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 312 | } else { |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 313 | mSignalMeter.setImageResource(R.drawable.sysbar_wifimini); |
| 314 | // adjust to permyriad |
| 315 | mSignalMeter.setImageLevel(level * (MAX_IMAGE_LEVEL / 100)); |
| 316 | mSignalIcon.setImageResource(isWifi ? R.drawable.ic_sysbar_wifi_mini |
| 317 | : R.drawable.ic_sysbar_wifi_mini); // XXX |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 318 | } |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 319 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 320 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 321 | public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 322 | if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | public void updateIcon(String slot, int index, int viewIndex, |
| 326 | StatusBarIcon old, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 327 | if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | public void removeIcon(String slot, int index, int viewIndex) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 331 | if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")"); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | public void addNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 335 | if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")"); |
| 336 | addNotificationViews(key, notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 337 | |
| 338 | boolean immersive = false; |
| 339 | try { |
| 340 | immersive = ActivityManagerNative.getDefault().isTopActivityImmersive(); |
| 341 | Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); |
| 342 | } catch (RemoteException ex) { |
| 343 | } |
| 344 | if (immersive) { |
| 345 | // TODO: immersive mode popups for tablet |
| 346 | } else if (notification.notification.fullScreenIntent != null) { |
| 347 | // not immersive & a full-screen alert should be shown |
| 348 | Slog.d(TAG, "Notification has fullScreenIntent and activity is not immersive;" |
| 349 | + " sending fullScreenIntent"); |
| 350 | try { |
| 351 | notification.notification.fullScreenIntent.send(); |
| 352 | } catch (PendingIntent.CanceledException e) { |
| 353 | } |
| 354 | } else { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 355 | tick(notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 356 | } |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 357 | |
| 358 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 362 | if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO"); |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 363 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 364 | final NotificationData.Entry oldEntry = mNotns.findByKey(key); |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 365 | if (oldEntry == null) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 366 | Slog.w(TAG, "updateNotification for unknown key: " + key); |
| 367 | return; |
| 368 | } |
| 369 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 370 | final StatusBarNotification oldNotification = oldEntry.notification; |
| 371 | final RemoteViews oldContentView = oldNotification.notification.contentView; |
| 372 | |
| 373 | final RemoteViews contentView = notification.notification.contentView; |
| 374 | |
| 375 | if (false) { |
| 376 | Slog.d(TAG, "old notification: when=" + oldNotification.notification.when |
| 377 | + " ongoing=" + oldNotification.isOngoing() |
| 378 | + " expanded=" + oldEntry.expanded |
| 379 | + " contentView=" + oldContentView); |
| 380 | Slog.d(TAG, "new notification: when=" + notification.notification.when |
| 381 | + " ongoing=" + oldNotification.isOngoing() |
| 382 | + " contentView=" + contentView); |
| 383 | } |
| 384 | |
| 385 | // Can we just reapply the RemoteViews in place? If when didn't change, the order |
| 386 | // didn't change. |
| 387 | if (notification.notification.when == oldNotification.notification.when |
| 388 | && notification.isOngoing() == oldNotification.isOngoing() |
| 389 | && oldEntry.expanded != null |
| 390 | && contentView != null |
| 391 | && oldContentView != null |
| 392 | && contentView.getPackage() != null |
| 393 | && oldContentView.getPackage() != null |
| 394 | && oldContentView.getPackage().equals(contentView.getPackage()) |
| 395 | && oldContentView.getLayoutId() == contentView.getLayoutId()) { |
| 396 | if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key); |
| 397 | oldEntry.notification = notification; |
| 398 | try { |
| 399 | // Reapply the RemoteViews |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 400 | contentView.reapply(mContext, oldEntry.content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 401 | // update the contentIntent |
| 402 | final PendingIntent contentIntent = notification.notification.contentIntent; |
| 403 | if (contentIntent != null) { |
| 404 | oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent, |
| 405 | notification.pkg, notification.tag, notification.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 406 | } else { |
| 407 | oldEntry.content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 408 | } |
| 409 | // Update the icon. |
| 410 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 411 | notification.notification.icon, notification.notification.iconLevel, |
| 412 | notification.notification.number); |
| 413 | if (!oldEntry.icon.set(ic)) { |
| 414 | handleNotificationError(key, notification, "Couldn't update icon: " + ic); |
| 415 | return; |
| 416 | } |
| 417 | } |
| 418 | catch (RuntimeException e) { |
| 419 | // It failed to add cleanly. Log, and remove the view from the panel. |
| 420 | Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); |
| 421 | removeNotificationViews(key); |
| 422 | addNotificationViews(key, notification); |
| 423 | } |
| 424 | } else { |
| 425 | if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key); |
| 426 | removeNotificationViews(key); |
| 427 | addNotificationViews(key, notification); |
| 428 | } |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 429 | // TODO: ticker; immersive mode |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 430 | |
| 431 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | public void removeNotification(IBinder key) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 435 | if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ") // TODO"); |
| 436 | removeNotificationViews(key); |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 437 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | public void disable(int state) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 441 | int old = mDisabled; |
| 442 | int diff = state ^ old; |
| 443 | Slog.d(TAG, "disable... old=0x" + Integer.toHexString(old) |
| 444 | + " diff=0x" + Integer.toHexString(diff) |
| 445 | + " state=0x" + Integer.toHexString(state)); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 446 | mDisabled = state; |
| 447 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 448 | // act accordingly |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 449 | if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 450 | if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 451 | Slog.d(TAG, "DISABLE_EXPAND: yes"); |
| 452 | animateCollapse(); |
| 453 | } |
| 454 | } |
| 455 | if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 456 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 457 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 458 | setViewVisibility(mNotificationTrigger, View.GONE, |
| 459 | R.anim.notification_icons_out); |
| 460 | setViewVisibility(mNotificationIconArea, View.GONE, |
| 461 | R.anim.notification_icons_out); |
| 462 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 463 | } else { |
| 464 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 465 | setViewVisibility(mNotificationTrigger, View.VISIBLE, |
| 466 | R.anim.notification_icons_in); |
| 467 | setViewVisibility(mNotificationIconArea, View.VISIBLE, |
| 468 | R.anim.notification_icons_in); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 469 | } |
| 470 | } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 471 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 472 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 473 | } |
| 474 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 475 | if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { |
| 476 | if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { |
| 477 | Slog.d(TAG, "DISABLE_SYSTEM_INFO: yes"); |
| 478 | setViewVisibility(mSystemInfo, View.GONE, R.anim.navigation_out); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 479 | } else { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 480 | Slog.d(TAG, "DISABLE_SYSTEM_INFO: no"); |
| 481 | setViewVisibility(mSystemInfo, View.VISIBLE, R.anim.navigation_in); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 482 | } |
| 483 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 484 | if ((diff & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 485 | if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 486 | Slog.d(TAG, "DISABLE_NAVIGATION: yes"); |
| 487 | setViewVisibility(mNavigationArea, View.GONE, R.anim.navigation_out); |
| 488 | } else { |
| 489 | Slog.d(TAG, "DISABLE_NAVIGATION: no"); |
| 490 | setViewVisibility(mNavigationArea, View.VISIBLE, R.anim.navigation_in); |
| 491 | } |
| 492 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 495 | private boolean hasTicker(Notification n) { |
| 496 | return !TextUtils.isEmpty(n.tickerText) |
| 497 | || !TextUtils.isEmpty(n.tickerTitle) |
| 498 | || !TextUtils.isEmpty(n.tickerSubtitle); |
| 499 | } |
| 500 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 501 | private void tick(StatusBarNotification n) { |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 502 | // Don't show the ticker when the windowshade is open. |
| 503 | if (mNotificationPanel.getVisibility() == View.VISIBLE) { |
| 504 | return; |
| 505 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 506 | // Show the ticker if one is requested. Also don't do this |
| 507 | // until status bar window is attached to the window manager, |
| 508 | // because... well, what's the point otherwise? And trying to |
| 509 | // run a ticker without being attached will crash! |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 510 | if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 511 | if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 512 | | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 513 | mTicker.add(n); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 518 | public void animateExpand() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 519 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); |
| 520 | mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | public void animateCollapse() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 524 | mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL); |
| 525 | mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL); |
| 526 | mHandler.removeMessages(MSG_CLOSE_SYSTEM_PANEL); |
| 527 | mHandler.sendEmptyMessage(MSG_CLOSE_SYSTEM_PANEL); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 528 | } |
| 529 | |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 530 | public void setLightsOn(boolean on) { |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 531 | if (on) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 532 | setViewVisibility(mCurtains, View.GONE, R.anim.lights_out_out); |
| 533 | setViewVisibility(mBarContents, View.VISIBLE, R.anim.status_bar_in); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 534 | } else { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 535 | animateCollapse(); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 536 | setViewVisibility(mCurtains, View.VISIBLE, R.anim.lights_out_in); |
| 537 | setViewVisibility(mBarContents, View.GONE, R.anim.status_bar_out); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 538 | } |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 541 | public void setMenuKeyVisible(boolean visible) { |
| 542 | if (DEBUG) { |
| 543 | Slog.d(TAG, (visible?"showing":"hiding") + " the MENU button"); |
| 544 | } |
| 545 | setViewVisibility(mMenuButton, |
| 546 | visible ? View.VISIBLE : View.INVISIBLE, |
| 547 | visible ? R.anim.navigation_in : R.anim.navigation_out); |
| 548 | } |
| 549 | |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 550 | private void setAreThereNotifications() { |
| 551 | final boolean hasClearable = mNotns.hasClearableItems(); |
| 552 | |
| 553 | //Slog.d(TAG, "setAreThereNotifications hasClerable=" + hasClearable); |
| 554 | |
| 555 | // Show or hide the "Clear all" button. Note that we don't do an animation |
| 556 | // if it's not on screen, so that if someone opens the bar right then they |
| 557 | // don't see the animation in progress. |
| 558 | // (no ongoing notifications are clearable) |
| 559 | if (hasClearable) { |
| 560 | if (mNotificationButtons.getVisibility() == View.VISIBLE) { |
| 561 | setViewVisibility(mClearButton, View.VISIBLE, R.anim.notification_buttons_in); |
| 562 | } else { |
| 563 | mClearButton.setVisibility(View.VISIBLE); |
| 564 | } |
| 565 | } else { |
| 566 | if (mNotificationButtons.getVisibility() == View.VISIBLE) { |
| 567 | setViewVisibility(mClearButton, View.GONE, R.anim.notification_buttons_out); |
| 568 | } else { |
| 569 | mClearButton.setVisibility(View.GONE); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | /* |
| 574 | mOngoingTitle.setVisibility(ongoing ? View.VISIBLE : View.GONE); |
| 575 | mLatestTitle.setVisibility(latest ? View.VISIBLE : View.GONE); |
| 576 | |
| 577 | if (ongoing || latest) { |
| 578 | mNoNotificationsTitle.setVisibility(View.GONE); |
| 579 | } else { |
| 580 | mNoNotificationsTitle.setVisibility(View.VISIBLE); |
| 581 | } |
| 582 | */ |
| 583 | } |
| 584 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 585 | /** |
| 586 | * Cancel this notification and tell the status bar service about the failure. Hold no locks. |
| 587 | */ |
| 588 | void handleNotificationError(IBinder key, StatusBarNotification n, String message) { |
| 589 | removeNotification(key); |
| 590 | try { |
| 591 | mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); |
| 592 | } catch (RemoteException ex) { |
| 593 | // The end is nigh. |
| 594 | } |
| 595 | } |
| 596 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 597 | private View.OnClickListener mOnClickListener = new View.OnClickListener() { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 598 | public void onClick(View v) { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 599 | if (v == mClearButton) { |
| 600 | onClickClearButton(); |
| 601 | } else if (v == mDoNotDisturbButton) { |
| 602 | onClickDoNotDisturb(); |
| 603 | } else if (v == mNotificationTrigger) { |
| 604 | onClickNotificationTrigger(); |
| 605 | } else if (v == mSystemInfo) { |
| 606 | onClickSystemInfo(); |
| 607 | } else if (v == mRecentButton) { |
| 608 | onClickRecentButton(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 609 | } |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 610 | } |
| 611 | }; |
| 612 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 613 | void onClickClearButton() { |
| 614 | try { |
| 615 | mBarService.onClearAllNotifications(); |
| 616 | } catch (RemoteException ex) { |
| 617 | // system process is dead if we're here. |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 618 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 619 | animateCollapse(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 620 | refreshNotificationTrigger(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | void onClickDoNotDisturb() { |
| 624 | mNotificationsOn = !mNotificationsOn; |
Daniel Sandler | cf3c7cf | 2010-10-22 15:30:12 -0400 | [diff] [blame^] | 625 | mIconLayout.setVisibility(mNotificationsOn ? View.VISIBLE : View.INVISIBLE); // TODO: animation |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 626 | animateCollapse(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 627 | refreshNotificationTrigger(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | public void onClickNotificationTrigger() { |
| 631 | if (DEBUG) Slog.d(TAG, "clicked notification icons"); |
| 632 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 633 | if (!mNotificationsOn) { |
| 634 | mNotificationsOn = true; |
Daniel Sandler | cf3c7cf | 2010-10-22 15:30:12 -0400 | [diff] [blame^] | 635 | mIconLayout.setVisibility(View.VISIBLE); // TODO: animation |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 636 | refreshNotificationTrigger(); |
| 637 | } else { |
| 638 | int msg = (mNotificationPanel.getVisibility() == View.GONE) |
| 639 | ? MSG_OPEN_NOTIFICATION_PANEL |
| 640 | : MSG_CLOSE_NOTIFICATION_PANEL; |
| 641 | mHandler.removeMessages(msg); |
| 642 | mHandler.sendEmptyMessage(msg); |
| 643 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
| 647 | public void onClickSystemInfo() { |
| 648 | if (DEBUG) Slog.d(TAG, "clicked system info"); |
| 649 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
| 650 | int msg = (mSystemPanel.getVisibility() == View.GONE) |
| 651 | ? MSG_OPEN_SYSTEM_PANEL |
| 652 | : MSG_CLOSE_SYSTEM_PANEL; |
| 653 | mHandler.removeMessages(msg); |
| 654 | mHandler.sendEmptyMessage(msg); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | public void onClickRecentButton() { |
| 659 | if (DEBUG) Slog.d(TAG, "clicked recent apps"); |
| 660 | Intent intent = new Intent(); |
| 661 | intent.setClass(mContext, RecentApplicationsActivity.class); |
| 662 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 663 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 664 | mContext.startActivity(intent); |
| 665 | } |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 666 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 667 | private class NotificationClicker implements View.OnClickListener { |
| 668 | private PendingIntent mIntent; |
| 669 | private String mPkg; |
| 670 | private String mTag; |
| 671 | private int mId; |
| 672 | |
| 673 | NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { |
| 674 | mIntent = intent; |
| 675 | mPkg = pkg; |
| 676 | mTag = tag; |
| 677 | mId = id; |
| 678 | } |
| 679 | |
| 680 | public void onClick(View v) { |
| 681 | try { |
| 682 | // The intent we are sending is for the application, which |
| 683 | // won't have permission to immediately start an activity after |
| 684 | // the user switches to home. We know it is safe to do at this |
| 685 | // point, so make sure new activity switches are now allowed. |
| 686 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 687 | } catch (RemoteException e) { |
| 688 | } |
| 689 | |
| 690 | if (mIntent != null) { |
| 691 | int[] pos = new int[2]; |
| 692 | v.getLocationOnScreen(pos); |
| 693 | Intent overlay = new Intent(); |
| 694 | overlay.setSourceBounds( |
| 695 | new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); |
| 696 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 697 | mIntent.send(mContext, 0, overlay); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 698 | } catch (PendingIntent.CanceledException e) { |
| 699 | // the stack trace isn't very helpful here. Just log the exception message. |
| 700 | Slog.w(TAG, "Sending contentIntent failed: " + e); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | try { |
| 705 | mBarService.onNotificationClick(mPkg, mTag, mId); |
| 706 | } catch (RemoteException ex) { |
| 707 | // system process is dead if we're here. |
| 708 | } |
| 709 | |
| 710 | // close the shade if it was open |
| 711 | animateCollapse(); |
| 712 | |
| 713 | // If this click was on the intruder alert, hide that instead |
| 714 | // mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | StatusBarNotification removeNotificationViews(IBinder key) { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 719 | NotificationData.Entry entry = mNotns.remove(key); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 720 | if (entry == null) { |
| 721 | Slog.w(TAG, "removeNotification for unknown key: " + key); |
| 722 | return null; |
| 723 | } |
| 724 | // Remove the expanded view. |
| 725 | ViewGroup rowParent = (ViewGroup)entry.row.getParent(); |
| 726 | if (rowParent != null) rowParent.removeView(entry.row); |
| 727 | // Remove the icon. |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 728 | // ViewGroup iconParent = (ViewGroup)entry.icon.getParent(); |
| 729 | // if (iconParent != null) iconParent.removeView(entry.icon); |
| 730 | refreshIcons(); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 731 | |
| 732 | return entry.notification; |
| 733 | } |
| 734 | |
| 735 | StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 736 | if (DEBUG) { |
| 737 | Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); |
| 738 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 739 | // Construct the icon. |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 740 | final StatusBarIconView iconView = new StatusBarIconView(mContext, |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 741 | notification.pkg + "/0x" + Integer.toHexString(notification.id)); |
| 742 | iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 743 | |
| 744 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 745 | notification.notification.icon, |
| 746 | notification.notification.iconLevel, |
| 747 | notification.notification.number); |
| 748 | if (!iconView.set(ic)) { |
| 749 | handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic); |
| 750 | return null; |
| 751 | } |
| 752 | // Construct the expanded view. |
| 753 | NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 754 | if (!inflateViews(entry, mPile)) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 755 | handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " |
| 756 | + notification); |
| 757 | return null; |
| 758 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 759 | // Add the icon. |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 760 | mNotns.add(entry); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 761 | refreshIcons(); |
| 762 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 763 | return iconView; |
| 764 | } |
| 765 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 766 | private void refreshIcons() { |
| 767 | // XXX: need to implement a new limited linear layout class |
| 768 | // to avoid removing & readding everything |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 769 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 770 | int N = mNotns.size(); |
| 771 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mIconSize, mIconSize); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 772 | |
| 773 | if (DEBUG) { |
| 774 | Slog.d(TAG, "refreshing icons (" + N + " notifications, mIconLayout=" |
| 775 | + mIconLayout + ", mPile=" + mPile); |
| 776 | } |
| 777 | |
| 778 | mIconLayout.removeAllViews(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 779 | for (int i=0; i<4; i++) { |
| 780 | if (i>=N) break; |
| 781 | mIconLayout.addView(mNotns.get(N-i-1).icon, i, params); |
| 782 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 783 | |
| 784 | mPile.removeAllViews(); |
| 785 | for (int i=0; i<N; i++) { |
| 786 | mPile.addView(mNotns.get(N-i-1).row); |
| 787 | } |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame] | 788 | |
| 789 | refreshNotificationTrigger(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 792 | private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { |
| 793 | StatusBarNotification sbn = entry.notification; |
| 794 | RemoteViews remoteViews = sbn.notification.contentView; |
| 795 | if (remoteViews == null) { |
| 796 | return false; |
| 797 | } |
| 798 | |
| 799 | // create the row view |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 800 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( |
| 801 | Context.LAYOUT_INFLATER_SERVICE); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 802 | View row = inflater.inflate(R.layout.status_bar_latest_event, parent, false); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 803 | View vetoButton = row.findViewById(R.id.veto); |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 804 | if (entry.notification.isClearable()) { |
| 805 | final String _pkg = sbn.pkg; |
| 806 | final String _tag = sbn.tag; |
| 807 | final int _id = sbn.id; |
| 808 | vetoButton.setOnClickListener(new View.OnClickListener() { |
| 809 | public void onClick(View v) { |
| 810 | try { |
| 811 | mBarService.onNotificationClear(_pkg, _tag, _id); |
| 812 | } catch (RemoteException ex) { |
| 813 | // system process is dead if we're here. |
| 814 | } |
| 815 | // animateCollapse(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 816 | } |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 817 | }); |
| 818 | } else { |
| 819 | vetoButton.setVisibility(View.INVISIBLE); |
| 820 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 821 | |
| 822 | // bind the click event to the content area |
| 823 | ViewGroup content = (ViewGroup)row.findViewById(R.id.content); |
| 824 | // XXX: update to allow controls within notification views |
| 825 | content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); |
| 826 | // content.setOnFocusChangeListener(mFocusChangeListener); |
| 827 | PendingIntent contentIntent = sbn.notification.contentIntent; |
| 828 | if (contentIntent != null) { |
| 829 | content.setOnClickListener(new NotificationClicker(contentIntent, |
| 830 | sbn.pkg, sbn.tag, sbn.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 831 | } else { |
| 832 | content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | View expanded = null; |
| 836 | Exception exception = null; |
| 837 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 838 | expanded = remoteViews.apply(mContext, content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 839 | } |
| 840 | catch (RuntimeException e) { |
| 841 | exception = e; |
| 842 | } |
| 843 | if (expanded == null) { |
| 844 | String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); |
| 845 | Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); |
| 846 | return false; |
| 847 | } else { |
| 848 | content.addView(expanded); |
| 849 | row.setDrawingCacheEnabled(true); |
| 850 | } |
| 851 | |
| 852 | entry.row = row; |
| 853 | entry.content = content; |
| 854 | entry.expanded = expanded; |
| 855 | |
| 856 | return true; |
| 857 | } |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 858 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 859 | public class SetLightsOnListener implements View.OnLongClickListener, |
| 860 | View.OnClickListener { |
| 861 | private boolean mOn; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 862 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 863 | SetLightsOnListener(boolean on) { |
| 864 | mOn = on; |
| 865 | } |
| 866 | |
| 867 | public void onClick(View v) { |
| 868 | try { |
| 869 | mBarService.setLightsOn(mOn); |
| 870 | } catch (RemoteException ex) { |
| 871 | // system process |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | public boolean onLongClick(View v) { |
| 876 | try { |
| 877 | mBarService.setLightsOn(mOn); |
| 878 | } catch (RemoteException ex) { |
| 879 | // system process |
| 880 | } |
| 881 | return true; |
| 882 | } |
| 883 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 884 | } |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 885 | |
| 886 | public class TouchOutsideListener implements View.OnTouchListener { |
| 887 | private int mMsg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 888 | private StatusBarPanel mPanel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 889 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 890 | public TouchOutsideListener(int msg, StatusBarPanel panel) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 891 | mMsg = msg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 892 | mPanel = panel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | public boolean onTouch(View v, MotionEvent ev) { |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 896 | final int action = ev.getAction(); |
| 897 | if (action == MotionEvent.ACTION_OUTSIDE |
| 898 | || (action == MotionEvent.ACTION_DOWN |
| 899 | && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 900 | mHandler.removeMessages(mMsg); |
| 901 | mHandler.sendEmptyMessage(mMsg); |
| 902 | return true; |
| 903 | } |
| 904 | return false; |
| 905 | } |
| 906 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 907 | |
| 908 | private void setViewVisibility(View v, int vis, int anim) { |
| 909 | if (v.getVisibility() != vis) { |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 910 | //Slog.d(TAG, "setViewVisibility vis=" + (vis == View.VISIBLE) + " v=" + v); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 911 | v.setAnimation(AnimationUtils.loadAnimation(mContext, anim)); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 912 | v.setVisibility(vis); |
| 913 | } |
| 914 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 915 | |
| 916 | |
| 917 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 918 | pw.print("mDisabled=0x"); |
| 919 | pw.println(Integer.toHexString(mDisabled)); |
| 920 | } |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 921 | } |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 922 | |
| 923 | |