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