Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -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 | 2026e8d | 2010-11-20 13:20:56 -0800 | [diff] [blame] | 19 | import java.util.Arrays; |
| 20 | |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 21 | import android.animation.LayoutTransition; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 22 | import android.app.Notification; |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 23 | import android.app.PendingIntent; |
Daniel Sandler | 5feceeb | 2013-03-22 18:29:23 -0700 | [diff] [blame] | 24 | import android.service.notification.StatusBarNotification; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 25 | import android.content.Context; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 26 | import android.content.res.Resources; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 27 | import android.graphics.PixelFormat; |
Joe Onorato | 2026e8d | 2010-11-20 13:20:56 -0800 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 29 | import android.os.Handler; |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 30 | import android.os.IBinder; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 31 | import android.os.Message; |
| 32 | import android.util.Slog; |
| 33 | import android.view.Gravity; |
| 34 | import android.view.LayoutInflater; |
| 35 | import android.view.View; |
| 36 | import android.view.ViewGroup; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 37 | import android.view.WindowManager; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 38 | import android.widget.FrameLayout; |
| 39 | import android.widget.ImageView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 40 | import android.widget.TextView; |
| 41 | |
Joe Onorato | 2026e8d | 2010-11-20 13:20:56 -0800 | [diff] [blame] | 42 | import com.android.internal.statusbar.StatusBarIcon; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 43 | |
| 44 | import com.android.systemui.R; |
Joe Onorato | 2026e8d | 2010-11-20 13:20:56 -0800 | [diff] [blame] | 45 | import com.android.systemui.statusbar.StatusBarIconView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 46 | |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 47 | public class TabletTicker |
| 48 | extends Handler |
| 49 | implements LayoutTransition.TransitionListener { |
| 50 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 51 | private static final String TAG = "StatusBar.TabletTicker"; |
| 52 | |
Daniel Sandler | e2c251b | 2011-01-27 20:39:12 -0500 | [diff] [blame] | 53 | private static final boolean CLICKABLE_TICKER = true; |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 54 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 55 | // 3 is enough to let us see most cases, but not get so far behind that it's too annoying. |
| 56 | private static final int QUEUE_LENGTH = 3; |
| 57 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 58 | private static final int MSG_ADVANCE = 1; |
| 59 | |
Joe Onorato | 6c1af93 | 2010-11-21 17:07:20 -0800 | [diff] [blame] | 60 | private static final int ADVANCE_DELAY = 5000; // 5 seconds |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 61 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 62 | private final Context mContext; |
| 63 | private final WindowManager mWindowManager; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 64 | |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 65 | private ViewGroup mWindow; |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 66 | private IBinder mCurrentKey; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 67 | private StatusBarNotification mCurrentNotification; |
| 68 | private View mCurrentView; |
| 69 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 70 | private IBinder[] mKeys = new IBinder[QUEUE_LENGTH]; |
| 71 | private StatusBarNotification[] mQueue = new StatusBarNotification[QUEUE_LENGTH]; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 72 | private int mQueuePos; |
| 73 | |
Daniel Sandler | a3850b6 | 2011-12-06 13:36:03 -0500 | [diff] [blame] | 74 | private final int mLargeIconHeight; |
| 75 | |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 76 | private TabletStatusBar mBar; |
| 77 | |
| 78 | private LayoutTransition mLayoutTransition; |
| 79 | private boolean mWindowShouldClose; |
| 80 | |
| 81 | public TabletTicker(TabletStatusBar bar) { |
| 82 | mBar = bar; |
| 83 | mContext = bar.getContext(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 84 | mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
Daniel Sandler | a3850b6 | 2011-12-06 13:36:03 -0500 | [diff] [blame] | 85 | final Resources res = mContext.getResources(); |
| 86 | mLargeIconHeight = res.getDimensionPixelSize( |
| 87 | android.R.dimen.notification_large_icon_height); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 90 | public void add(IBinder key, StatusBarNotification notification) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 91 | if (false) { |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 92 | Slog.d(TAG, "add 1 mCurrentNotification=" + mCurrentNotification |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 93 | + " mQueuePos=" + mQueuePos + " mQueue=" + Arrays.toString(mQueue)); |
| 94 | } |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 95 | |
| 96 | // If it's already in here, remove whatever's in there and put the new one at the end. |
| 97 | remove(key, false); |
| 98 | |
| 99 | mKeys[mQueuePos] = key; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 100 | mQueue[mQueuePos] = notification; |
| 101 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 102 | // If nothing is running now, start the next one. |
| 103 | if (mQueuePos == 0 && mCurrentNotification == null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 104 | sendEmptyMessage(MSG_ADVANCE); |
| 105 | } |
| 106 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 107 | if (mQueuePos < QUEUE_LENGTH - 1) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 108 | mQueuePos++; |
| 109 | } |
| 110 | } |
| 111 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 112 | public void remove(IBinder key) { |
| 113 | remove(key, true); |
| 114 | } |
| 115 | |
| 116 | public void remove(IBinder key, boolean advance) { |
| 117 | if (mCurrentKey == key) { |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 118 | // Showing now |
| 119 | if (advance) { |
| 120 | removeMessages(MSG_ADVANCE); |
| 121 | sendEmptyMessage(MSG_ADVANCE); |
| 122 | } |
| 123 | } else { |
| 124 | // In the queue |
| 125 | for (int i=0; i<QUEUE_LENGTH; i++) { |
| 126 | if (mKeys[i] == key) { |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 127 | for (; i<QUEUE_LENGTH-1; i++) { |
| 128 | mKeys[i] = mKeys[i+1]; |
| 129 | mQueue[i] = mQueue[i+1]; |
| 130 | } |
| 131 | mKeys[QUEUE_LENGTH-1] = null; |
| 132 | mQueue[QUEUE_LENGTH-1] = null; |
| 133 | if (mQueuePos > 0) { |
| 134 | mQueuePos--; |
| 135 | } |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 142 | public void halt() { |
| 143 | removeMessages(MSG_ADVANCE); |
Joe Onorato | af5e4da | 2010-11-27 17:24:14 -0800 | [diff] [blame] | 144 | if (mCurrentView != null || mQueuePos != 0) { |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 145 | for (int i=0; i<QUEUE_LENGTH; i++) { |
| 146 | mKeys[i] = null; |
Joe Onorato | 091e1b8 | 2010-09-26 18:04:44 -0700 | [diff] [blame] | 147 | mQueue[i] = null; |
| 148 | } |
| 149 | mQueuePos = 0; |
| 150 | sendEmptyMessage(MSG_ADVANCE); |
| 151 | } |
| 152 | } |
| 153 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 154 | public void handleMessage(Message msg) { |
| 155 | switch (msg.what) { |
| 156 | case MSG_ADVANCE: |
| 157 | advance(); |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | private void advance() { |
| 163 | // Out with the old... |
| 164 | if (mCurrentView != null) { |
Daniel Sandler | bec7d63 | 2011-02-15 14:24:58 -0500 | [diff] [blame] | 165 | if (mWindow != null) { |
| 166 | mWindow.removeView(mCurrentView); |
| 167 | } |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 168 | mCurrentView = null; |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 169 | mCurrentKey = null; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 170 | mCurrentNotification = null; |
| 171 | } |
| 172 | |
| 173 | // In with the new... |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 174 | dequeue(); |
| 175 | while (mCurrentNotification != null) { |
| 176 | mCurrentView = makeTickerView(mCurrentNotification); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 177 | if (mCurrentView != null) { |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 178 | if (mWindow == null) { |
| 179 | mWindow = makeWindow(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 180 | mWindowManager.addView(mWindow, mWindow.getLayoutParams()); |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 181 | } |
Daniel Sandler | 6aa2d3a | 2011-01-26 11:52:48 -0500 | [diff] [blame] | 182 | |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 183 | mWindow.addView(mCurrentView); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 184 | sendEmptyMessageDelayed(MSG_ADVANCE, ADVANCE_DELAY); |
| 185 | break; |
| 186 | } |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 187 | dequeue(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 188 | } |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 189 | |
| 190 | // if there's nothing left, close the window |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 191 | mWindowShouldClose = (mCurrentView == null && mWindow != null); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 194 | private void dequeue() { |
| 195 | mCurrentKey = mKeys[0]; |
| 196 | mCurrentNotification = mQueue[0]; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 197 | if (false) { |
| 198 | Slog.d(TAG, "dequeue mQueuePos=" + mQueuePos + " mQueue=" + Arrays.toString(mQueue)); |
| 199 | } |
| 200 | final int N = mQueuePos; |
| 201 | for (int i=0; i<N; i++) { |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 202 | mKeys[i] = mKeys[i+1]; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 203 | mQueue[i] = mQueue[i+1]; |
| 204 | } |
Joe Onorato | 50ec5ec | 2010-11-28 17:15:26 -0800 | [diff] [blame] | 205 | mKeys[N] = null; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 206 | mQueue[N] = null; |
| 207 | if (mQueuePos > 0) { |
| 208 | mQueuePos--; |
| 209 | } |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 212 | private ViewGroup makeWindow() { |
| 213 | final Resources res = mContext.getResources(); |
| 214 | final FrameLayout view = new FrameLayout(mContext); |
| 215 | final int width = res.getDimensionPixelSize(R.dimen.notification_ticker_width); |
Joe Onorato | ec51a82 | 2011-01-04 16:33:01 -0800 | [diff] [blame] | 216 | int windowFlags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Joe Onorato | 6c1af93 | 2010-11-21 17:07:20 -0800 | [diff] [blame] | 217 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
Joe Onorato | ec51a82 | 2011-01-04 16:33:01 -0800 | [diff] [blame] | 218 | | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 219 | if (CLICKABLE_TICKER) { |
| 220 | windowFlags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
| 221 | } else { |
| 222 | windowFlags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 223 | } |
Daniel Sandler | a3850b6 | 2011-12-06 13:36:03 -0500 | [diff] [blame] | 224 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, mLargeIconHeight, |
Daniel Sandler | 4ce64fb | 2012-05-03 10:53:10 -0400 | [diff] [blame] | 225 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, windowFlags, |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 226 | PixelFormat.TRANSLUCENT); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 227 | lp.gravity = Gravity.BOTTOM | Gravity.END; |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 228 | // lp.windowAnimations = com.android.internal.R.style.Animation_Toast; |
| 229 | |
| 230 | mLayoutTransition = new LayoutTransition(); |
| 231 | mLayoutTransition.addTransitionListener(this); |
| 232 | view.setLayoutTransition(mLayoutTransition); |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 233 | lp.setTitle("NotificationTicker"); |
| 234 | view.setLayoutParams(lp); |
| 235 | return view; |
| 236 | } |
| 237 | |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 238 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 239 | View view, int transitionType) {} |
| 240 | |
| 241 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 242 | View view, int transitionType) { |
| 243 | if (mWindowShouldClose) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 244 | mWindowManager.removeView(mWindow); |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 245 | mWindow = null; |
| 246 | mWindowShouldClose = false; |
Daniel Sandler | b8027d8 | 2010-12-16 19:35:54 -0500 | [diff] [blame] | 247 | mBar.doneTicking(); |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 251 | private View makeTickerView(StatusBarNotification notification) { |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 252 | final Notification n = notification.getNotification(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 253 | |
| 254 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( |
| 255 | Context.LAYOUT_INFLATER_SERVICE); |
| 256 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 257 | ViewGroup group; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 258 | int layoutId; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 259 | int iconId; |
| 260 | if (n.largeIcon != null) { |
| 261 | iconId = R.id.right_icon; |
| 262 | } else { |
| 263 | iconId = R.id.left_icon; |
| 264 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 265 | if (n.tickerView != null) { |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 266 | group = (ViewGroup)inflater.inflate(R.layout.system_bar_ticker_panel, null, false); |
Daniel Sandler | 6aa2d3a | 2011-01-26 11:52:48 -0500 | [diff] [blame] | 267 | ViewGroup content = (FrameLayout) group.findViewById(R.id.ticker_expanded); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 268 | View expanded = null; |
| 269 | Exception exception = null; |
| 270 | try { |
Daniel Sandler | 6aa2d3a | 2011-01-26 11:52:48 -0500 | [diff] [blame] | 271 | expanded = n.tickerView.apply(mContext, content); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 272 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 273 | catch (RuntimeException e) { |
| 274 | exception = e; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 275 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 276 | if (expanded == null) { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 277 | final String ident = notification.getPackageName() |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 278 | + "/0x" + Integer.toHexString(notification.getId()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 279 | Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); |
| 280 | return null; |
| 281 | } |
Daniel Sandler | 6aa2d3a | 2011-01-26 11:52:48 -0500 | [diff] [blame] | 282 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( |
| 283 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 284 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 285 | content.addView(expanded, lp); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 286 | } else if (n.tickerText != null) { |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 287 | group = (ViewGroup)inflater.inflate(R.layout.system_bar_ticker_compat, mWindow, false); |
Joe Onorato | 2026e8d | 2010-11-20 13:20:56 -0800 | [diff] [blame] | 288 | final Drawable icon = StatusBarIconView.getIcon(mContext, |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 289 | new StatusBarIcon(notification.getPackageName(), notification.getUser(), n.icon, n.iconLevel, 0, |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 290 | n.tickerText)); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 291 | ImageView iv = (ImageView)group.findViewById(iconId); |
Joe Onorato | 2026e8d | 2010-11-20 13:20:56 -0800 | [diff] [blame] | 292 | iv.setImageDrawable(icon); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 293 | iv.setVisibility(View.VISIBLE); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 294 | TextView tv = (TextView)group.findViewById(R.id.text); |
| 295 | tv.setText(n.tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 296 | } else { |
| 297 | throw new RuntimeException("tickerView==null && tickerText==null"); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 298 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 299 | ImageView largeIcon = (ImageView)group.findViewById(R.id.large_icon); |
| 300 | if (n.largeIcon != null) { |
| 301 | largeIcon.setImageBitmap(n.largeIcon); |
| 302 | largeIcon.setVisibility(View.VISIBLE); |
Daniel Sandler | a3850b6 | 2011-12-06 13:36:03 -0500 | [diff] [blame] | 303 | final ViewGroup.LayoutParams lp = largeIcon.getLayoutParams(); |
| 304 | final int statusBarHeight = mBar.getStatusBarHeight(); |
| 305 | if (n.largeIcon.getHeight() <= statusBarHeight) { |
| 306 | // for smallish largeIcons, it looks a little odd to have them floating halfway up |
| 307 | // the ticker, so we vertically center them in the status bar area instead |
| 308 | lp.height = statusBarHeight; |
| 309 | } else { |
| 310 | lp.height = mLargeIconHeight; |
| 311 | } |
| 312 | largeIcon.setLayoutParams(lp); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 313 | } |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 314 | |
| 315 | if (CLICKABLE_TICKER) { |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 316 | PendingIntent contentIntent = notification.getNotification().contentIntent; |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 317 | if (contentIntent != null) { |
Daniel Sandler | e2c251b | 2011-01-27 20:39:12 -0500 | [diff] [blame] | 318 | // create the usual notification clicker, but chain it together with a halt() call |
| 319 | // to abort the ticker too |
| 320 | final View.OnClickListener clicker = mBar.makeClicker(contentIntent, |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 321 | notification.getPackageName(), notification.getTag(), notification.getId()); |
Daniel Sandler | e2c251b | 2011-01-27 20:39:12 -0500 | [diff] [blame] | 322 | group.setOnClickListener(new View.OnClickListener() { |
| 323 | public void onClick(View v) { |
| 324 | halt(); |
| 325 | clicker.onClick(v); |
| 326 | } |
| 327 | }); |
Daniel Sandler | c51451a | 2010-12-16 19:06:46 -0500 | [diff] [blame] | 328 | } else { |
| 329 | group.setOnClickListener(null); |
| 330 | } |
| 331 | } |
| 332 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 333 | return group; |
| 334 | } |
| 335 | } |
| 336 | |