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() { |
| 284 | int resId; |
| 285 | boolean panel = (mNotificationPanel != null |
| 286 | && mNotificationPanel.getVisibility() == View.VISIBLE); |
| 287 | if (!mNotificationsOn) { |
| 288 | resId = R.drawable.ic_sysbar_noti_dnd; |
| 289 | } else if (mNotns.size() > 0) { |
| 290 | resId = panel ? R.drawable.ic_sysbar_noti_avail_open : R.drawable.ic_sysbar_noti_avail; |
| 291 | } else { |
| 292 | resId = panel ? R.drawable.ic_sysbar_noti_none_open : R.drawable.ic_sysbar_noti_none; |
| 293 | } |
| 294 | mNotificationTrigger.setImageResource(resId); |
| 295 | } |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 296 | |
Daniel Sandler | d7db7b1 | 2010-08-13 16:26:39 -0400 | [diff] [blame] | 297 | public void setBatteryMeter(int level, boolean plugged) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 298 | if (DEBUG) Slog.d(TAG, "battery=" + level + (plugged ? " - plugged" : " - unplugged")); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 299 | mBatteryMeter.setImageResource(R.drawable.sysbar_batterymini); |
| 300 | // adjust percent to permyriad for ClipDrawable's sake |
| 301 | mBatteryMeter.setImageLevel(level * (MAX_IMAGE_LEVEL / 100)); |
Daniel Sandler | d7db7b1 | 2010-08-13 16:26:39 -0400 | [diff] [blame] | 302 | } |
| 303 | |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 304 | public void setSignalMeter(int level, boolean isWifi) { |
| 305 | if (DEBUG) Slog.d(TAG, "signal=" + level); |
| 306 | if (level < 0) { |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 307 | mSignalMeter.setImageDrawable(null); |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 308 | mSignalMeter.setImageLevel(0); |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 309 | mSignalIcon.setImageDrawable(null); |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 310 | } else { |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 311 | mSignalMeter.setImageResource(R.drawable.sysbar_wifimini); |
| 312 | // adjust to permyriad |
| 313 | mSignalMeter.setImageLevel(level * (MAX_IMAGE_LEVEL / 100)); |
| 314 | mSignalIcon.setImageResource(isWifi ? R.drawable.ic_sysbar_wifi_mini |
| 315 | : R.drawable.ic_sysbar_wifi_mini); // XXX |
Daniel Sandler | 764b4da | 2010-08-24 16:24:35 -0400 | [diff] [blame] | 316 | } |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 317 | } |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 318 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 319 | public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 320 | if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | public void updateIcon(String slot, int index, int viewIndex, |
| 324 | StatusBarIcon old, StatusBarIcon icon) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 325 | if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | public void removeIcon(String slot, int index, int viewIndex) { |
Daniel Sandler | 1e3ed8f | 2010-08-13 10:12:48 -0400 | [diff] [blame] | 329 | if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")"); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | public void addNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 333 | if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")"); |
| 334 | addNotificationViews(key, notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 335 | |
| 336 | boolean immersive = false; |
| 337 | try { |
| 338 | immersive = ActivityManagerNative.getDefault().isTopActivityImmersive(); |
| 339 | Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); |
| 340 | } catch (RemoteException ex) { |
| 341 | } |
| 342 | if (immersive) { |
| 343 | // TODO: immersive mode popups for tablet |
| 344 | } else if (notification.notification.fullScreenIntent != null) { |
| 345 | // not immersive & a full-screen alert should be shown |
| 346 | Slog.d(TAG, "Notification has fullScreenIntent and activity is not immersive;" |
| 347 | + " sending fullScreenIntent"); |
| 348 | try { |
| 349 | notification.notification.fullScreenIntent.send(); |
| 350 | } catch (PendingIntent.CanceledException e) { |
| 351 | } |
| 352 | } else { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 353 | tick(notification); |
Daniel Sandler | fb970e9 | 2010-08-20 10:57:17 -0400 | [diff] [blame] | 354 | } |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 355 | |
| 356 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 360 | if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO"); |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 361 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 362 | final NotificationData.Entry oldEntry = mNotns.findByKey(key); |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 363 | if (oldEntry == null) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 364 | Slog.w(TAG, "updateNotification for unknown key: " + key); |
| 365 | return; |
| 366 | } |
| 367 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 368 | final StatusBarNotification oldNotification = oldEntry.notification; |
| 369 | final RemoteViews oldContentView = oldNotification.notification.contentView; |
| 370 | |
| 371 | final RemoteViews contentView = notification.notification.contentView; |
| 372 | |
| 373 | if (false) { |
| 374 | Slog.d(TAG, "old notification: when=" + oldNotification.notification.when |
| 375 | + " ongoing=" + oldNotification.isOngoing() |
| 376 | + " expanded=" + oldEntry.expanded |
| 377 | + " contentView=" + oldContentView); |
| 378 | Slog.d(TAG, "new notification: when=" + notification.notification.when |
| 379 | + " ongoing=" + oldNotification.isOngoing() |
| 380 | + " contentView=" + contentView); |
| 381 | } |
| 382 | |
| 383 | // Can we just reapply the RemoteViews in place? If when didn't change, the order |
| 384 | // didn't change. |
| 385 | if (notification.notification.when == oldNotification.notification.when |
| 386 | && notification.isOngoing() == oldNotification.isOngoing() |
| 387 | && oldEntry.expanded != null |
| 388 | && contentView != null |
| 389 | && oldContentView != null |
| 390 | && contentView.getPackage() != null |
| 391 | && oldContentView.getPackage() != null |
| 392 | && oldContentView.getPackage().equals(contentView.getPackage()) |
| 393 | && oldContentView.getLayoutId() == contentView.getLayoutId()) { |
| 394 | if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key); |
| 395 | oldEntry.notification = notification; |
| 396 | try { |
| 397 | // Reapply the RemoteViews |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 398 | contentView.reapply(mContext, oldEntry.content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 399 | // update the contentIntent |
| 400 | final PendingIntent contentIntent = notification.notification.contentIntent; |
| 401 | if (contentIntent != null) { |
| 402 | oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent, |
| 403 | notification.pkg, notification.tag, notification.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 404 | } else { |
| 405 | oldEntry.content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 406 | } |
| 407 | // Update the icon. |
| 408 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 409 | notification.notification.icon, notification.notification.iconLevel, |
| 410 | notification.notification.number); |
| 411 | if (!oldEntry.icon.set(ic)) { |
| 412 | handleNotificationError(key, notification, "Couldn't update icon: " + ic); |
| 413 | return; |
| 414 | } |
| 415 | } |
| 416 | catch (RuntimeException e) { |
| 417 | // It failed to add cleanly. Log, and remove the view from the panel. |
| 418 | Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); |
| 419 | removeNotificationViews(key); |
| 420 | addNotificationViews(key, notification); |
| 421 | } |
| 422 | } else { |
| 423 | if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key); |
| 424 | removeNotificationViews(key); |
| 425 | addNotificationViews(key, notification); |
| 426 | } |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 427 | // TODO: ticker; immersive mode |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 428 | |
| 429 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | public void removeNotification(IBinder key) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 433 | if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ") // TODO"); |
| 434 | removeNotificationViews(key); |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 435 | setAreThereNotifications(); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | public void disable(int state) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 439 | int old = mDisabled; |
| 440 | int diff = state ^ old; |
| 441 | Slog.d(TAG, "disable... old=0x" + Integer.toHexString(old) |
| 442 | + " diff=0x" + Integer.toHexString(diff) |
| 443 | + " state=0x" + Integer.toHexString(state)); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 444 | mDisabled = state; |
| 445 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 446 | // act accordingly |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 447 | if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 448 | if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { |
| 449 | Slog.d(TAG, "DISABLE_EXPAND: yes"); |
| 450 | animateCollapse(); |
| 451 | } |
| 452 | } |
| 453 | if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 454 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { |
| 455 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 456 | setViewVisibility(mNotificationTrigger, View.GONE, |
| 457 | R.anim.notification_icons_out); |
| 458 | setViewVisibility(mNotificationIconArea, View.GONE, |
| 459 | R.anim.notification_icons_out); |
| 460 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 461 | } else { |
| 462 | Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 463 | setViewVisibility(mNotificationTrigger, View.VISIBLE, |
| 464 | R.anim.notification_icons_in); |
| 465 | setViewVisibility(mNotificationIconArea, View.VISIBLE, |
| 466 | R.anim.notification_icons_in); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 467 | } |
| 468 | } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 469 | if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 470 | mTicker.halt(); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 471 | } |
| 472 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 473 | if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { |
| 474 | if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { |
| 475 | Slog.d(TAG, "DISABLE_SYSTEM_INFO: yes"); |
| 476 | setViewVisibility(mSystemInfo, View.GONE, R.anim.navigation_out); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 477 | } else { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 478 | Slog.d(TAG, "DISABLE_SYSTEM_INFO: no"); |
| 479 | setViewVisibility(mSystemInfo, View.VISIBLE, R.anim.navigation_in); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 480 | } |
| 481 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 482 | if ((diff & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 483 | if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) { |
| 484 | Slog.d(TAG, "DISABLE_NAVIGATION: yes"); |
| 485 | setViewVisibility(mNavigationArea, View.GONE, R.anim.navigation_out); |
| 486 | } else { |
| 487 | Slog.d(TAG, "DISABLE_NAVIGATION: no"); |
| 488 | setViewVisibility(mNavigationArea, View.VISIBLE, R.anim.navigation_in); |
| 489 | } |
| 490 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 491 | } |
| 492 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 493 | private boolean hasTicker(Notification n) { |
| 494 | return !TextUtils.isEmpty(n.tickerText) |
| 495 | || !TextUtils.isEmpty(n.tickerTitle) |
| 496 | || !TextUtils.isEmpty(n.tickerSubtitle); |
| 497 | } |
| 498 | |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 499 | private void tick(StatusBarNotification n) { |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 500 | // Don't show the ticker when the windowshade is open. |
| 501 | if (mNotificationPanel.getVisibility() == View.VISIBLE) { |
| 502 | return; |
| 503 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 504 | // Show the ticker if one is requested. Also don't do this |
| 505 | // until status bar window is attached to the window manager, |
| 506 | // because... well, what's the point otherwise? And trying to |
| 507 | // run a ticker without being attached will crash! |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 508 | if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 509 | if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 510 | | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 511 | mTicker.add(n); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | } |
| 515 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 516 | public void animateExpand() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 517 | mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); |
| 518 | mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | public void animateCollapse() { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 522 | mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL); |
| 523 | mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL); |
| 524 | mHandler.removeMessages(MSG_CLOSE_SYSTEM_PANEL); |
| 525 | mHandler.sendEmptyMessage(MSG_CLOSE_SYSTEM_PANEL); |
Daniel Sandler | 9120d55 | 2010-07-23 09:11:14 -0400 | [diff] [blame] | 526 | } |
| 527 | |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 528 | public void setLightsOn(boolean on) { |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 529 | if (on) { |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 530 | setViewVisibility(mCurtains, View.GONE, R.anim.lights_out_out); |
| 531 | setViewVisibility(mBarContents, View.VISIBLE, R.anim.status_bar_in); |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 532 | } else { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 533 | animateCollapse(); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 534 | setViewVisibility(mCurtains, View.VISIBLE, R.anim.lights_out_in); |
| 535 | setViewVisibility(mBarContents, View.GONE, R.anim.status_bar_out); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 536 | } |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 539 | public void setMenuKeyVisible(boolean visible) { |
| 540 | if (DEBUG) { |
| 541 | Slog.d(TAG, (visible?"showing":"hiding") + " the MENU button"); |
| 542 | } |
| 543 | setViewVisibility(mMenuButton, |
| 544 | visible ? View.VISIBLE : View.INVISIBLE, |
| 545 | visible ? R.anim.navigation_in : R.anim.navigation_out); |
| 546 | } |
| 547 | |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 548 | private void setAreThereNotifications() { |
| 549 | final boolean hasClearable = mNotns.hasClearableItems(); |
| 550 | |
| 551 | //Slog.d(TAG, "setAreThereNotifications hasClerable=" + hasClearable); |
| 552 | |
| 553 | // Show or hide the "Clear all" button. Note that we don't do an animation |
| 554 | // if it's not on screen, so that if someone opens the bar right then they |
| 555 | // don't see the animation in progress. |
| 556 | // (no ongoing notifications are clearable) |
| 557 | if (hasClearable) { |
| 558 | if (mNotificationButtons.getVisibility() == View.VISIBLE) { |
| 559 | setViewVisibility(mClearButton, View.VISIBLE, R.anim.notification_buttons_in); |
| 560 | } else { |
| 561 | mClearButton.setVisibility(View.VISIBLE); |
| 562 | } |
| 563 | } else { |
| 564 | if (mNotificationButtons.getVisibility() == View.VISIBLE) { |
| 565 | setViewVisibility(mClearButton, View.GONE, R.anim.notification_buttons_out); |
| 566 | } else { |
| 567 | mClearButton.setVisibility(View.GONE); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | mOngoingTitle.setVisibility(ongoing ? View.VISIBLE : View.GONE); |
| 573 | mLatestTitle.setVisibility(latest ? View.VISIBLE : View.GONE); |
| 574 | |
| 575 | if (ongoing || latest) { |
| 576 | mNoNotificationsTitle.setVisibility(View.GONE); |
| 577 | } else { |
| 578 | mNoNotificationsTitle.setVisibility(View.VISIBLE); |
| 579 | } |
| 580 | */ |
| 581 | } |
| 582 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 583 | /** |
| 584 | * Cancel this notification and tell the status bar service about the failure. Hold no locks. |
| 585 | */ |
| 586 | void handleNotificationError(IBinder key, StatusBarNotification n, String message) { |
| 587 | removeNotification(key); |
| 588 | try { |
| 589 | mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); |
| 590 | } catch (RemoteException ex) { |
| 591 | // The end is nigh. |
| 592 | } |
| 593 | } |
| 594 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 595 | private View.OnClickListener mOnClickListener = new View.OnClickListener() { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 596 | public void onClick(View v) { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 597 | if (v == mClearButton) { |
| 598 | onClickClearButton(); |
| 599 | } else if (v == mDoNotDisturbButton) { |
| 600 | onClickDoNotDisturb(); |
| 601 | } else if (v == mNotificationTrigger) { |
| 602 | onClickNotificationTrigger(); |
| 603 | } else if (v == mSystemInfo) { |
| 604 | onClickSystemInfo(); |
| 605 | } else if (v == mRecentButton) { |
| 606 | onClickRecentButton(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 607 | } |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 608 | } |
| 609 | }; |
| 610 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 611 | void onClickClearButton() { |
| 612 | try { |
| 613 | mBarService.onClearAllNotifications(); |
| 614 | } catch (RemoteException ex) { |
| 615 | // system process is dead if we're here. |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 616 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 617 | animateCollapse(); |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame^] | 618 | refreshNotificationTrigger(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | void onClickDoNotDisturb() { |
| 622 | mNotificationsOn = !mNotificationsOn; |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame^] | 623 | setViewVisibility(mIconLayout, |
| 624 | mNotificationsOn ? View.VISIBLE : View.INVISIBLE, |
| 625 | mNotificationsOn ? R.anim.notification_dnd_off : R.anim.notification_dnd_on); |
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; |
| 635 | setViewVisibility(mIconLayout, |
| 636 | View.VISIBLE, |
| 637 | R.anim.notification_dnd_off); |
| 638 | refreshNotificationTrigger(); |
| 639 | } else { |
| 640 | int msg = (mNotificationPanel.getVisibility() == View.GONE) |
| 641 | ? MSG_OPEN_NOTIFICATION_PANEL |
| 642 | : MSG_CLOSE_NOTIFICATION_PANEL; |
| 643 | mHandler.removeMessages(msg); |
| 644 | mHandler.sendEmptyMessage(msg); |
| 645 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
| 649 | public void onClickSystemInfo() { |
| 650 | if (DEBUG) Slog.d(TAG, "clicked system info"); |
| 651 | if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { |
| 652 | int msg = (mSystemPanel.getVisibility() == View.GONE) |
| 653 | ? MSG_OPEN_SYSTEM_PANEL |
| 654 | : MSG_CLOSE_SYSTEM_PANEL; |
| 655 | mHandler.removeMessages(msg); |
| 656 | mHandler.sendEmptyMessage(msg); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | public void onClickRecentButton() { |
| 661 | if (DEBUG) Slog.d(TAG, "clicked recent apps"); |
| 662 | Intent intent = new Intent(); |
| 663 | intent.setClass(mContext, RecentApplicationsActivity.class); |
| 664 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 665 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 666 | mContext.startActivity(intent); |
| 667 | } |
Joe Onorato | 55d2d76 | 2010-09-26 13:02:01 -0700 | [diff] [blame] | 668 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 669 | private class NotificationClicker implements View.OnClickListener { |
| 670 | private PendingIntent mIntent; |
| 671 | private String mPkg; |
| 672 | private String mTag; |
| 673 | private int mId; |
| 674 | |
| 675 | NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { |
| 676 | mIntent = intent; |
| 677 | mPkg = pkg; |
| 678 | mTag = tag; |
| 679 | mId = id; |
| 680 | } |
| 681 | |
| 682 | public void onClick(View v) { |
| 683 | try { |
| 684 | // The intent we are sending is for the application, which |
| 685 | // won't have permission to immediately start an activity after |
| 686 | // the user switches to home. We know it is safe to do at this |
| 687 | // point, so make sure new activity switches are now allowed. |
| 688 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 689 | } catch (RemoteException e) { |
| 690 | } |
| 691 | |
| 692 | if (mIntent != null) { |
| 693 | int[] pos = new int[2]; |
| 694 | v.getLocationOnScreen(pos); |
| 695 | Intent overlay = new Intent(); |
| 696 | overlay.setSourceBounds( |
| 697 | new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); |
| 698 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 699 | mIntent.send(mContext, 0, overlay); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 700 | } catch (PendingIntent.CanceledException e) { |
| 701 | // the stack trace isn't very helpful here. Just log the exception message. |
| 702 | Slog.w(TAG, "Sending contentIntent failed: " + e); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | try { |
| 707 | mBarService.onNotificationClick(mPkg, mTag, mId); |
| 708 | } catch (RemoteException ex) { |
| 709 | // system process is dead if we're here. |
| 710 | } |
| 711 | |
| 712 | // close the shade if it was open |
| 713 | animateCollapse(); |
| 714 | |
| 715 | // If this click was on the intruder alert, hide that instead |
| 716 | // mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | StatusBarNotification removeNotificationViews(IBinder key) { |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 721 | NotificationData.Entry entry = mNotns.remove(key); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 722 | if (entry == null) { |
| 723 | Slog.w(TAG, "removeNotification for unknown key: " + key); |
| 724 | return null; |
| 725 | } |
| 726 | // Remove the expanded view. |
| 727 | ViewGroup rowParent = (ViewGroup)entry.row.getParent(); |
| 728 | if (rowParent != null) rowParent.removeView(entry.row); |
| 729 | // Remove the icon. |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 730 | // ViewGroup iconParent = (ViewGroup)entry.icon.getParent(); |
| 731 | // if (iconParent != null) iconParent.removeView(entry.icon); |
| 732 | refreshIcons(); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 733 | |
| 734 | return entry.notification; |
| 735 | } |
| 736 | |
| 737 | StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 738 | if (DEBUG) { |
| 739 | Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); |
| 740 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 741 | // Construct the icon. |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 742 | final StatusBarIconView iconView = new StatusBarIconView(mContext, |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 743 | notification.pkg + "/0x" + Integer.toHexString(notification.id)); |
| 744 | iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 745 | |
| 746 | final StatusBarIcon ic = new StatusBarIcon(notification.pkg, |
| 747 | notification.notification.icon, |
| 748 | notification.notification.iconLevel, |
| 749 | notification.notification.number); |
| 750 | if (!iconView.set(ic)) { |
| 751 | handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic); |
| 752 | return null; |
| 753 | } |
| 754 | // Construct the expanded view. |
| 755 | NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 756 | if (!inflateViews(entry, mPile)) { |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 757 | handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " |
| 758 | + notification); |
| 759 | return null; |
| 760 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 761 | // Add the icon. |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 762 | mNotns.add(entry); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 763 | refreshIcons(); |
| 764 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 765 | return iconView; |
| 766 | } |
| 767 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 768 | private void refreshIcons() { |
| 769 | // XXX: need to implement a new limited linear layout class |
| 770 | // to avoid removing & readding everything |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 771 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 772 | int N = mNotns.size(); |
| 773 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mIconSize, mIconSize); |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 774 | |
| 775 | if (DEBUG) { |
| 776 | Slog.d(TAG, "refreshing icons (" + N + " notifications, mIconLayout=" |
| 777 | + mIconLayout + ", mPile=" + mPile); |
| 778 | } |
| 779 | |
| 780 | mIconLayout.removeAllViews(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 781 | for (int i=0; i<4; i++) { |
| 782 | if (i>=N) break; |
| 783 | mIconLayout.addView(mNotns.get(N-i-1).icon, i, params); |
| 784 | } |
Daniel Sandler | dfa08db | 2010-08-05 16:18:42 -0400 | [diff] [blame] | 785 | |
| 786 | mPile.removeAllViews(); |
| 787 | for (int i=0; i<N; i++) { |
| 788 | mPile.addView(mNotns.get(N-i-1).row); |
| 789 | } |
Daniel Sandler | 271ea12 | 2010-10-22 14:06:10 -0400 | [diff] [blame^] | 790 | |
| 791 | refreshNotificationTrigger(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 792 | } |
| 793 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 794 | private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { |
| 795 | StatusBarNotification sbn = entry.notification; |
| 796 | RemoteViews remoteViews = sbn.notification.contentView; |
| 797 | if (remoteViews == null) { |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | // create the row view |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 802 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( |
| 803 | Context.LAYOUT_INFLATER_SERVICE); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 804 | View row = inflater.inflate(R.layout.status_bar_latest_event, parent, false); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 805 | View vetoButton = row.findViewById(R.id.veto); |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 806 | if (entry.notification.isClearable()) { |
| 807 | final String _pkg = sbn.pkg; |
| 808 | final String _tag = sbn.tag; |
| 809 | final int _id = sbn.id; |
| 810 | vetoButton.setOnClickListener(new View.OnClickListener() { |
| 811 | public void onClick(View v) { |
| 812 | try { |
| 813 | mBarService.onNotificationClear(_pkg, _tag, _id); |
| 814 | } catch (RemoteException ex) { |
| 815 | // system process is dead if we're here. |
| 816 | } |
| 817 | // animateCollapse(); |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 818 | } |
Joe Onorato | a4a6503 | 2010-09-27 15:53:44 -0700 | [diff] [blame] | 819 | }); |
| 820 | } else { |
| 821 | vetoButton.setVisibility(View.INVISIBLE); |
| 822 | } |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 823 | |
| 824 | // bind the click event to the content area |
| 825 | ViewGroup content = (ViewGroup)row.findViewById(R.id.content); |
| 826 | // XXX: update to allow controls within notification views |
| 827 | content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); |
| 828 | // content.setOnFocusChangeListener(mFocusChangeListener); |
| 829 | PendingIntent contentIntent = sbn.notification.contentIntent; |
| 830 | if (contentIntent != null) { |
| 831 | content.setOnClickListener(new NotificationClicker(contentIntent, |
| 832 | sbn.pkg, sbn.tag, sbn.id)); |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 833 | } else { |
| 834 | content.setOnClickListener(null); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | View expanded = null; |
| 838 | Exception exception = null; |
| 839 | try { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 840 | expanded = remoteViews.apply(mContext, content); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 841 | } |
| 842 | catch (RuntimeException e) { |
| 843 | exception = e; |
| 844 | } |
| 845 | if (expanded == null) { |
| 846 | String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); |
| 847 | Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); |
| 848 | return false; |
| 849 | } else { |
| 850 | content.addView(expanded); |
| 851 | row.setDrawingCacheEnabled(true); |
| 852 | } |
| 853 | |
| 854 | entry.row = row; |
| 855 | entry.content = content; |
| 856 | entry.expanded = expanded; |
| 857 | |
| 858 | return true; |
| 859 | } |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 860 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 861 | public class SetLightsOnListener implements View.OnLongClickListener, |
| 862 | View.OnClickListener { |
| 863 | private boolean mOn; |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 864 | |
Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 865 | SetLightsOnListener(boolean on) { |
| 866 | mOn = on; |
| 867 | } |
| 868 | |
| 869 | public void onClick(View v) { |
| 870 | try { |
| 871 | mBarService.setLightsOn(mOn); |
| 872 | } catch (RemoteException ex) { |
| 873 | // system process |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | public boolean onLongClick(View v) { |
| 878 | try { |
| 879 | mBarService.setLightsOn(mOn); |
| 880 | } catch (RemoteException ex) { |
| 881 | // system process |
| 882 | } |
| 883 | return true; |
| 884 | } |
| 885 | |
Daniel Sandler | ce70d91 | 2010-09-02 11:59:41 -0400 | [diff] [blame] | 886 | } |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 887 | |
| 888 | public class TouchOutsideListener implements View.OnTouchListener { |
| 889 | private int mMsg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 890 | private StatusBarPanel mPanel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 891 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 892 | public TouchOutsideListener(int msg, StatusBarPanel panel) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 893 | mMsg = msg; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 894 | mPanel = panel; |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | public boolean onTouch(View v, MotionEvent ev) { |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 898 | final int action = ev.getAction(); |
| 899 | if (action == MotionEvent.ACTION_OUTSIDE |
| 900 | || (action == MotionEvent.ACTION_DOWN |
| 901 | && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { |
Joe Onorato | b62ac12 | 2010-09-20 16:16:32 -0400 | [diff] [blame] | 902 | mHandler.removeMessages(mMsg); |
| 903 | mHandler.sendEmptyMessage(mMsg); |
| 904 | return true; |
| 905 | } |
| 906 | return false; |
| 907 | } |
| 908 | } |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 909 | |
| 910 | private void setViewVisibility(View v, int vis, int anim) { |
| 911 | if (v.getVisibility() != vis) { |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 912 | //Slog.d(TAG, "setViewVisibility vis=" + (vis == View.VISIBLE) + " v=" + v); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 913 | v.setAnimation(AnimationUtils.loadAnimation(mContext, anim)); |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 914 | v.setVisibility(vis); |
| 915 | } |
| 916 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 917 | |
| 918 | |
| 919 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 920 | pw.print("mDisabled=0x"); |
| 921 | pw.println(Integer.toHexString(mDisabled)); |
| 922 | } |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 923 | } |
Daniel Sandler | d39e388 | 2010-08-31 14:16:13 -0400 | [diff] [blame] | 924 | |
| 925 | |