1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
|
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.statusbar.tablet;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.app.ActivityManagerNative;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.Notification;
import android.app.StatusBarManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.LayerDrawable;
import android.provider.Settings;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.TextUtils;
import android.util.Slog;
import android.view.accessibility.AccessibilityEvent;
import android.view.Display;
import android.view.Gravity;
import android.view.IWindowManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.ScrollView;
import android.widget.TextView;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.statusbar.StatusBarNotification;
import com.android.systemui.R;
import com.android.systemui.statusbar.*;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.CompatModeButton;
import com.android.systemui.statusbar.policy.LocationController;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.Prefs;
import com.android.systemui.recent.RecentsPanelView;
public class TabletStatusBar extends StatusBar implements
HeightReceiver.OnBarHeightChangedListener,
InputMethodsPanel.OnHardKeyboardEnabledChangeListener {
public static final boolean DEBUG = false;
public static final boolean DEBUG_COMPAT_HELP = false;
public static final String TAG = "TabletStatusBar";
public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000;
public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001;
public static final int MSG_OPEN_NOTIFICATION_PEEK = 1002;
public static final int MSG_CLOSE_NOTIFICATION_PEEK = 1003;
public static final int MSG_OPEN_RECENTS_PANEL = 1020;
public static final int MSG_CLOSE_RECENTS_PANEL = 1021;
public static final int MSG_SHOW_CHROME = 1030;
public static final int MSG_HIDE_CHROME = 1031;
public static final int MSG_OPEN_INPUT_METHODS_PANEL = 1040;
public static final int MSG_CLOSE_INPUT_METHODS_PANEL = 1041;
public static final int MSG_OPEN_COMPAT_MODE_PANEL = 1050;
public static final int MSG_CLOSE_COMPAT_MODE_PANEL = 1051;
public static final int MSG_STOP_TICKER = 2000;
// Fitts' Law assistance for LatinIME; see policy.EventHole
private static final boolean FAKE_SPACE_BAR = true;
// Notification "peeking" (flyover preview of individual notifications)
final static boolean NOTIFICATION_PEEK_ENABLED = false;
final static int NOTIFICATION_PEEK_HOLD_THRESH = 200; // ms
final static int NOTIFICATION_PEEK_FADE_DELAY = 3000; // ms
// The height of the bar, as definied by the build. It may be taller if we're plugged
// into hdmi.
int mNaturalBarHeight = -1;
int mIconSize = -1;
int mIconHPadding = -1;
private int mMaxNotificationIcons = 5;
H mHandler = new H();
IWindowManager mWindowManager;
// tracking all current notifications
private NotificationData mNotificationData = new NotificationData();
TabletStatusBarView mStatusBarView;
View mNotificationArea;
View mNotificationTrigger;
NotificationIconArea mNotificationIconArea;
ViewGroup mNavigationArea;
boolean mNotificationDNDMode;
NotificationData.Entry mNotificationDNDDummyEntry;
ImageView mBackButton;
View mHomeButton;
View mMenuButton;
View mRecentButton;
ViewGroup mFeedbackIconArea; // notification icons, IME icon, compat icon
InputMethodButton mInputMethodSwitchButton;
CompatModeButton mCompatModeButton;
NotificationPanel mNotificationPanel;
WindowManager.LayoutParams mNotificationPanelParams;
NotificationPeekPanel mNotificationPeekWindow;
ViewGroup mNotificationPeekRow;
int mNotificationPeekIndex;
IBinder mNotificationPeekKey;
LayoutTransition mNotificationPeekScrubLeft, mNotificationPeekScrubRight;
int mNotificationPeekTapDuration;
int mNotificationFlingVelocity;
ViewGroup mPile;
HeightReceiver mHeightReceiver;
BatteryController mBatteryController;
BluetoothController mBluetoothController;
LocationController mLocationController;
NetworkController mNetworkController;
ViewGroup mBarContents;
LayoutTransition mBarContentsLayoutTransition;
// hide system chrome ("lights out") support
View mShadow;
NotificationIconArea.IconLayout mIconLayout;
TabletTicker mTicker;
View mFakeSpaceBar;
KeyEvent mSpaceBarKeyEvent = null;
View mCompatibilityHelpDialog = null;
// for disabling the status bar
int mDisabled = 0;
private RecentsPanelView mRecentsPanel;
private InputMethodsPanel mInputMethodsPanel;
private CompatModePanel mCompatModePanel;
private int mSystemUiVisibility = 0;
// used to notify status bar for suppressing notification LED
private boolean mPanelSlightlyVisible;
public Context getContext() { return mContext; }
protected void addPanelWindows() {
final Context context = mContext;
final Resources res = mContext.getResources();
// Notification Panel
mNotificationPanel = (NotificationPanel)View.inflate(context,
R.layout.status_bar_notification_panel, null);
mNotificationPanel.setBar(this);
mNotificationPanel.show(false, false);
mNotificationPanel.setOnTouchListener(
new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel));
// the battery icon
mBatteryController.addIconView((ImageView)mNotificationPanel.findViewById(R.id.battery));
mBatteryController.addLabelView(
(TextView)mNotificationPanel.findViewById(R.id.battery_text));
// Bt
mBluetoothController.addIconView(
(ImageView)mNotificationPanel.findViewById(R.id.bluetooth));
// network icons: either a combo icon that switches between mobile and data, or distinct
// mobile and data icons
final ImageView comboRSSI =
(ImageView)mNotificationPanel.findViewById(R.id.network_signal);
if (comboRSSI != null) {
mNetworkController.addCombinedSignalIconView(comboRSSI);
}
final ImageView mobileRSSI =
(ImageView)mNotificationPanel.findViewById(R.id.mobile_signal);
if (mobileRSSI != null) {
mNetworkController.addPhoneSignalIconView(mobileRSSI);
}
final ImageView wifiRSSI =
(ImageView)mNotificationPanel.findViewById(R.id.wifi_signal);
if (wifiRSSI != null) {
mNetworkController.addWifiIconView(wifiRSSI);
}
mNetworkController.addDataTypeIconView(
(ImageView)mNotificationPanel.findViewById(R.id.network_type));
mNetworkController.addDataDirectionOverlayIconView(
(ImageView)mNotificationPanel.findViewById(R.id.network_direction));
mNetworkController.addLabelView(
(TextView)mNotificationPanel.findViewById(R.id.network_text));
mNetworkController.addLabelView(
(TextView)mBarContents.findViewById(R.id.network_text));
mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel);
WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams(
res.getDimensionPixelSize(R.dimen.notification_panel_width),
getNotificationPanelHeight(),
WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
lp.setTitle("NotificationPanel");
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
lp.windowAnimations = com.android.internal.R.style.Animation; // == no animation
// lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade
WindowManagerImpl.getDefault().addView(mNotificationPanel, lp);
// Notification preview window
if (NOTIFICATION_PEEK_ENABLED) {
mNotificationPeekWindow = (NotificationPeekPanel) View.inflate(context,
R.layout.status_bar_notification_peek, null);
mNotificationPeekWindow.setBar(this);
mNotificationPeekRow = (ViewGroup) mNotificationPeekWindow.findViewById(R.id.content);
mNotificationPeekWindow.setVisibility(View.GONE);
mNotificationPeekWindow.setOnTouchListener(
new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PEEK, mNotificationPeekWindow));
mNotificationPeekScrubRight = new LayoutTransition();
mNotificationPeekScrubRight.setAnimator(LayoutTransition.APPEARING,
ObjectAnimator.ofInt(null, "left", -512, 0));
mNotificationPeekScrubRight.setAnimator(LayoutTransition.DISAPPEARING,
ObjectAnimator.ofInt(null, "left", -512, 0));
mNotificationPeekScrubRight.setDuration(500);
mNotificationPeekScrubLeft = new LayoutTransition();
mNotificationPeekScrubLeft.setAnimator(LayoutTransition.APPEARING,
ObjectAnimator.ofInt(null, "left", 512, 0));
mNotificationPeekScrubLeft.setAnimator(LayoutTransition.DISAPPEARING,
ObjectAnimator.ofInt(null, "left", 512, 0));
mNotificationPeekScrubLeft.setDuration(500);
// XXX: setIgnoreChildren?
lp = new WindowManager.LayoutParams(
512, // ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
PixelFormat.TRANSLUCENT);
lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
lp.y = res.getDimensionPixelOffset(R.dimen.peek_window_y_offset);
lp.setTitle("NotificationPeekWindow");
lp.windowAnimations = com.android.internal.R.style.Animation_Toast;
WindowManagerImpl.getDefault().addView(mNotificationPeekWindow, lp);
}
// Recents Panel
mRecentsPanel = (RecentsPanelView) View.inflate(context,
R.layout.status_bar_recent_panel, null);
mRecentsPanel.setVisibility(View.GONE);
mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL,
mRecentsPanel));
mStatusBarView.setIgnoreChildren(2, mRecentButton, mRecentsPanel);
lp = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
lp.gravity = Gravity.BOTTOM | Gravity.LEFT;
lp.setTitle("RecentsPanel");
lp.windowAnimations = R.style.Animation_RecentPanel;
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
WindowManagerImpl.getDefault().addView(mRecentsPanel, lp);
mRecentsPanel.setBar(this);
// Input methods Panel
mInputMethodsPanel = (InputMethodsPanel) View.inflate(context,
R.layout.status_bar_input_methods_panel, null);
mInputMethodsPanel.setHardKeyboardEnabledChangeListener(this);
mInputMethodsPanel.setOnTouchListener(new TouchOutsideListener(
MSG_CLOSE_INPUT_METHODS_PANEL, mInputMethodsPanel));
mInputMethodsPanel.setImeSwitchButton(mInputMethodSwitchButton);
mStatusBarView.setIgnoreChildren(3, mInputMethodSwitchButton, mInputMethodsPanel);
lp = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
lp.setTitle("InputMethodsPanel");
lp.windowAnimations = R.style.Animation_RecentPanel;
WindowManagerImpl.getDefault().addView(mInputMethodsPanel, lp);
// Compatibility mode selector panel
mCompatModePanel = (CompatModePanel) View.inflate(context,
R.layout.status_bar_compat_mode_panel, null);
mCompatModePanel.setOnTouchListener(new TouchOutsideListener(
MSG_CLOSE_COMPAT_MODE_PANEL, mCompatModePanel));
mCompatModePanel.setTrigger(mCompatModeButton);
mCompatModePanel.setVisibility(View.GONE);
mStatusBarView.setIgnoreChildren(4, mCompatModeButton, mCompatModePanel);
lp = new WindowManager.LayoutParams(
250,
ViewGroup.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
lp.setTitle("CompatModePanel");
lp.windowAnimations = android.R.style.Animation_Dialog;
WindowManagerImpl.getDefault().addView(mCompatModePanel, lp);
}
private int getNotificationPanelHeight() {
final Resources res = mContext.getResources();
final Display d = WindowManagerImpl.getDefault().getDefaultDisplay();
final Point size = new Point();
d.getRealSize(size);
return Math.max(res.getDimensionPixelSize(R.dimen.notification_panel_min_height), size.y);
}
@Override
public void start() {
super.start(); // will add the main bar view
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
mHeightReceiver.updateHeight(); // display size may have changed
loadDimens();
mNotificationPanelParams.height = getNotificationPanelHeight();
WindowManagerImpl.getDefault().updateViewLayout(mNotificationPanel,
mNotificationPanelParams);
}
protected void loadDimens() {
final Resources res = mContext.getResources();
mNaturalBarHeight = res.getDimensionPixelSize(
com.android.internal.R.dimen.system_bar_height);
int newIconSize = res.getDimensionPixelSize(
com.android.internal.R.dimen.system_bar_icon_size);
int newIconHPadding = res.getDimensionPixelSize(
R.dimen.status_bar_icon_padding);
if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) {
// Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding);
mIconHPadding = newIconHPadding;
mIconSize = newIconSize;
reloadAllNotificationIcons(); // reload the tray
}
final int numIcons = res.getInteger(R.integer.config_maxNotificationIcons);
if (numIcons != mMaxNotificationIcons) {
mMaxNotificationIcons = numIcons;
if (DEBUG) Slog.d(TAG, "max notification icons: " + mMaxNotificationIcons);
reloadAllNotificationIcons();
}
}
protected View makeStatusBarView() {
final Context context = mContext;
mWindowManager = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
// This guy will listen for HDMI plugged broadcasts so we can resize the
// status bar as appropriate.
mHeightReceiver = new HeightReceiver(mContext);
mHeightReceiver.registerReceiver();
loadDimens();
final TabletStatusBarView sb = (TabletStatusBarView)View.inflate(
context, R.layout.status_bar, null);
mStatusBarView = sb;
sb.setHandler(mHandler);
mBarContents = (ViewGroup) sb.findViewById(R.id.bar_contents);
// layout transitions for the status bar's contents
mBarContentsLayoutTransition = new LayoutTransition();
// add/removal will fade as normal
mBarContentsLayoutTransition.setAnimator(LayoutTransition.APPEARING,
ObjectAnimator.ofFloat(null, "alpha", 0f, 1f));
mBarContentsLayoutTransition.setAnimator(LayoutTransition.DISAPPEARING,
ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
// no animations for siblings on change: just jump into place please
mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_APPEARING, null);
mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, null);
// quick like bunny
mBarContentsLayoutTransition.setDuration(250 * (DEBUG?10:1));
mBarContents.setLayoutTransition(mBarContentsLayoutTransition);
// the whole right-hand side of the bar
mNotificationArea = sb.findViewById(R.id.notificationArea);
if (!NOTIFICATION_PEEK_ENABLED) {
mNotificationArea.setOnTouchListener(new NotificationTriggerTouchListener());
}
// the button to open the notification area
mNotificationTrigger = sb.findViewById(R.id.notificationTrigger);
if (NOTIFICATION_PEEK_ENABLED) {
mNotificationTrigger.setOnTouchListener(new NotificationTriggerTouchListener());
}
// the more notifications icon
mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons);
// where the icons go
mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons);
if (NOTIFICATION_PEEK_ENABLED) {
mIconLayout.setOnTouchListener(new NotificationIconTouchListener());
}
ViewConfiguration vc = ViewConfiguration.get(context);
mNotificationPeekTapDuration = vc.getTapTimeout();
mNotificationFlingVelocity = 300; // px/s
mTicker = new TabletTicker(this);
// The icons
mLocationController = new LocationController(mContext); // will post a notification
mBatteryController = new BatteryController(mContext);
mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery));
mBluetoothController = new BluetoothController(mContext);
mBluetoothController.addIconView((ImageView)sb.findViewById(R.id.bluetooth));
mNetworkController = new NetworkController(mContext);
final SignalClusterView signalCluster =
(SignalClusterView)sb.findViewById(R.id.signal_cluster);
mNetworkController.addSignalCluster(signalCluster);
// The navigation buttons
mBackButton = (ImageView)sb.findViewById(R.id.back);
mNavigationArea = (ViewGroup) sb.findViewById(R.id.navigationArea);
mHomeButton = mNavigationArea.findViewById(R.id.home);
mMenuButton = mNavigationArea.findViewById(R.id.menu);
mRecentButton = mNavigationArea.findViewById(R.id.recent_apps);
mRecentButton.setOnClickListener(mOnClickListener);
mNavigationArea.setLayoutTransition(mBarContentsLayoutTransition);
// no multi-touch on the nav buttons
mNavigationArea.setMotionEventSplittingEnabled(false);
// The bar contents buttons
mFeedbackIconArea = (ViewGroup)sb.findViewById(R.id.feedbackIconArea);
mInputMethodSwitchButton = (InputMethodButton) sb.findViewById(R.id.imeSwitchButton);
// Overwrite the lister
mInputMethodSwitchButton.setOnClickListener(mOnClickListener);
mCompatModeButton = (CompatModeButton) sb.findViewById(R.id.compatModeButton);
mCompatModeButton.setOnClickListener(mOnClickListener);
// for redirecting errant bar taps to the IME
mFakeSpaceBar = sb.findViewById(R.id.fake_space_bar);
// "shadows" of the status bar features, for lights-out mode
mShadow = sb.findViewById(R.id.bar_shadow);
mShadow.setOnTouchListener(
new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
// even though setting the systemUI visibility below will turn these views
// on, we need them to come up faster so that they can catch this motion
// event
mShadow.setVisibility(View.GONE);
mBarContents.setVisibility(View.VISIBLE);
try {
mBarService.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
} catch (RemoteException ex) {
// system process dead
}
}
return false;
}
});
// tuning parameters
final int LIGHTS_GOING_OUT_SYSBAR_DURATION = 600;
final int LIGHTS_GOING_OUT_SHADOW_DURATION = 1000;
final int LIGHTS_GOING_OUT_SHADOW_DELAY = 500;
final int LIGHTS_COMING_UP_SYSBAR_DURATION = 200;
// final int LIGHTS_COMING_UP_SYSBAR_DELAY = 50;
final int LIGHTS_COMING_UP_SHADOW_DURATION = 0;
LayoutTransition xition = new LayoutTransition();
xition.setAnimator(LayoutTransition.APPEARING,
ObjectAnimator.ofFloat(null, "alpha", 0.5f, 1f));
xition.setDuration(LayoutTransition.APPEARING, LIGHTS_COMING_UP_SYSBAR_DURATION);
xition.setStartDelay(LayoutTransition.APPEARING, 0);
xition.setAnimator(LayoutTransition.DISAPPEARING,
ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_GOING_OUT_SYSBAR_DURATION);
xition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
((ViewGroup)sb.findViewById(R.id.bar_contents_holder)).setLayoutTransition(xition);
xition = new LayoutTransition();
xition.setAnimator(LayoutTransition.APPEARING,
ObjectAnimator.ofFloat(null, "alpha", 0f, 1f));
xition.setDuration(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DURATION);
xition.setStartDelay(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DELAY);
xition.setAnimator(LayoutTransition.DISAPPEARING,
ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_COMING_UP_SHADOW_DURATION);
xition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
((ViewGroup)sb.findViewById(R.id.bar_shadow_holder)).setLayoutTransition(xition);
// set the initial view visibility
setAreThereNotifications();
// Add the windows
addPanelWindows();
mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content);
mPile.removeAllViews();
ScrollView scroller = (ScrollView)mPile.getParent();
scroller.setFillViewport(true);
mHeightReceiver.addOnBarHeightChangedListener(this);
return sb;
}
public int getStatusBarHeight() {
return mHeightReceiver.getHeight();
}
protected int getStatusBarGravity() {
return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL;
}
public void onBarHeightChanged(int height) {
final WindowManager.LayoutParams lp
= (WindowManager.LayoutParams)mStatusBarView.getLayoutParams();
if (lp == null) {
// haven't been added yet
return;
}
if (lp.height != height) {
lp.height = height;
final WindowManager wm = WindowManagerImpl.getDefault();
wm.updateViewLayout(mStatusBarView, lp);
}
}
private class H extends Handler {
public void handleMessage(Message m) {
switch (m.what) {
case MSG_OPEN_NOTIFICATION_PEEK:
if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1);
if (m.arg1 >= 0) {
final int N = mNotificationData.size();
if (!mNotificationDNDMode) {
if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) {
NotificationData.Entry entry = mNotificationData.get(N-1-mNotificationPeekIndex);
entry.icon.setBackgroundColor(0);
mNotificationPeekIndex = -1;
mNotificationPeekKey = null;
}
}
final int peekIndex = m.arg1;
if (peekIndex < N) {
//Slog.d(TAG, "loading peek: " + peekIndex);
NotificationData.Entry entry =
mNotificationDNDMode
? mNotificationDNDDummyEntry
: mNotificationData.get(N-1-peekIndex);
NotificationData.Entry copy = new NotificationData.Entry(
entry.key,
entry.notification,
entry.icon);
inflateViews(copy, mNotificationPeekRow);
if (mNotificationDNDMode) {
copy.content.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SharedPreferences.Editor editor = Prefs.edit(mContext);
editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, false);
editor.apply();
animateCollapse();
visibilityChanged(false);
}
});
}
entry.icon.setBackgroundColor(0x20FFFFFF);
// mNotificationPeekRow.setLayoutTransition(
// peekIndex < mNotificationPeekIndex
// ? mNotificationPeekScrubLeft
// : mNotificationPeekScrubRight);
mNotificationPeekRow.removeAllViews();
mNotificationPeekRow.addView(copy.row);
mNotificationPeekWindow.setVisibility(View.VISIBLE);
mNotificationPanel.show(false, true);
mNotificationPeekIndex = peekIndex;
mNotificationPeekKey = entry.key;
}
}
break;
case MSG_CLOSE_NOTIFICATION_PEEK:
if (DEBUG) Slog.d(TAG, "closing notification peek window");
mNotificationPeekWindow.setVisibility(View.GONE);
mNotificationPeekRow.removeAllViews();
final int N = mNotificationData.size();
if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) {
NotificationData.Entry entry =
mNotificationDNDMode
? mNotificationDNDDummyEntry
: mNotificationData.get(N-1-mNotificationPeekIndex);
entry.icon.setBackgroundColor(0);
}
mNotificationPeekIndex = -1;
mNotificationPeekKey = null;
break;
case MSG_OPEN_NOTIFICATION_PANEL:
if (DEBUG) Slog.d(TAG, "opening notifications panel");
if (!mNotificationPanel.isShowing()) {
if (NOTIFICATION_PEEK_ENABLED) {
mNotificationPeekWindow.setVisibility(View.GONE);
}
mNotificationPanel.show(true, true);
mNotificationArea.setVisibility(View.INVISIBLE);
mTicker.halt();
}
break;
case MSG_CLOSE_NOTIFICATION_PANEL:
if (DEBUG) Slog.d(TAG, "closing notifications panel");
if (mNotificationPanel.isShowing()) {
mNotificationPanel.show(false, true);
mNotificationArea.setVisibility(View.VISIBLE);
}
break;
case MSG_OPEN_RECENTS_PANEL:
if (DEBUG) Slog.d(TAG, "opening recents panel");
if (mRecentsPanel != null) {
disable(StatusBarManager.DISABLE_BACK);
mRecentsPanel.setVisibility(View.VISIBLE);
mRecentsPanel.show(true, true);
}
break;
case MSG_CLOSE_RECENTS_PANEL:
if (DEBUG) Slog.d(TAG, "closing recents panel");
if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
disable(StatusBarManager.DISABLE_NONE);
mRecentsPanel.show(false, true);
}
break;
case MSG_OPEN_INPUT_METHODS_PANEL:
if (DEBUG) Slog.d(TAG, "opening input methods panel");
if (mInputMethodsPanel != null) mInputMethodsPanel.openPanel();
break;
case MSG_CLOSE_INPUT_METHODS_PANEL:
if (DEBUG) Slog.d(TAG, "closing input methods panel");
if (mInputMethodsPanel != null) mInputMethodsPanel.closePanel(false);
break;
case MSG_OPEN_COMPAT_MODE_PANEL:
if (DEBUG) Slog.d(TAG, "opening compat panel");
if (mCompatModePanel != null) mCompatModePanel.openPanel();
break;
case MSG_CLOSE_COMPAT_MODE_PANEL:
if (DEBUG) Slog.d(TAG, "closing compat panel");
if (mCompatModePanel != null) mCompatModePanel.closePanel();
break;
case MSG_SHOW_CHROME:
if (DEBUG) Slog.d(TAG, "hiding shadows (lights on)");
mBarContents.setVisibility(View.VISIBLE);
mShadow.setVisibility(View.GONE);
mSystemUiVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
notifyUiVisibilityChanged();
break;
case MSG_HIDE_CHROME:
if (DEBUG) Slog.d(TAG, "showing shadows (lights out)");
animateCollapse();
visibilityChanged(false);
mBarContents.setVisibility(View.GONE);
mShadow.setVisibility(View.VISIBLE);
mSystemUiVisibility |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
notifyUiVisibilityChanged();
break;
case MSG_STOP_TICKER:
mTicker.halt();
break;
}
}
}
public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon);
}
public void updateIcon(String slot, int index, int viewIndex,
StatusBarIcon old, StatusBarIcon icon) {
if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon);
}
public void removeIcon(String slot, int index, int viewIndex) {
if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")");
}
public void addNotification(IBinder key, StatusBarNotification notification) {
if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")");
addNotificationViews(key, notification);
final boolean immersive = isImmersive();
if (false && immersive) {
// TODO: immersive mode popups for tablet
} else if (notification.notification.fullScreenIntent != null) {
// not immersive & a full-screen alert should be shown
Slog.w(TAG, "Notification has fullScreenIntent and activity is not immersive;"
+ " sending fullScreenIntent");
try {
notification.notification.fullScreenIntent.send();
} catch (PendingIntent.CanceledException e) {
}
} else {
tick(key, notification, true);
}
setAreThereNotifications();
}
public void updateNotification(IBinder key, StatusBarNotification notification) {
if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ")");
final NotificationData.Entry oldEntry = mNotificationData.findByKey(key);
if (oldEntry == null) {
Slog.w(TAG, "updateNotification for unknown key: " + key);
return;
}
final StatusBarNotification oldNotification = oldEntry.notification;
final RemoteViews oldContentView = oldNotification.notification.contentView;
final RemoteViews contentView = notification.notification.contentView;
if (DEBUG) {
Slog.d(TAG, "old notification: when=" + oldNotification.notification.when
+ " ongoing=" + oldNotification.isOngoing()
+ " expanded=" + oldEntry.expanded
+ " contentView=" + oldContentView
+ " rowParent=" + oldEntry.row.getParent());
Slog.d(TAG, "new notification: when=" + notification.notification.when
+ " ongoing=" + oldNotification.isOngoing()
+ " contentView=" + contentView);
}
// Can we just reapply the RemoteViews in place? If when didn't change, the order
// didn't change.
boolean contentsUnchanged = oldEntry.expanded != null
&& contentView != null && oldContentView != null
&& contentView.getPackage() != null
&& oldContentView.getPackage() != null
&& oldContentView.getPackage().equals(contentView.getPackage())
&& oldContentView.getLayoutId() == contentView.getLayoutId();
ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent();
boolean orderUnchanged = notification.notification.when==oldNotification.notification.when
&& notification.priority == oldNotification.priority;
// priority now encompasses isOngoing()
boolean isLastAnyway = rowParent.indexOfChild(oldEntry.row) == rowParent.getChildCount()-1;
if (contentsUnchanged && (orderUnchanged || isLastAnyway)) {
if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key);
oldEntry.notification = notification;
try {
// Reapply the RemoteViews
contentView.reapply(mContext, oldEntry.content);
// update the contentIntent
final PendingIntent contentIntent = notification.notification.contentIntent;
if (contentIntent != null) {
oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent,
notification.pkg, notification.tag, notification.id));
} else {
oldEntry.content.setOnClickListener(null);
}
// Update the icon.
final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
notification.notification.icon, notification.notification.iconLevel,
notification.notification.number,
notification.notification.tickerText);
if (!oldEntry.icon.set(ic)) {
handleNotificationError(key, notification, "Couldn't update icon: " + ic);
return;
}
// Update the large icon
if (notification.notification.largeIcon != null) {
oldEntry.largeIcon.setImageBitmap(notification.notification.largeIcon);
} else {
oldEntry.largeIcon.getLayoutParams().width = 0;
oldEntry.largeIcon.setVisibility(View.INVISIBLE);
}
if (NOTIFICATION_PEEK_ENABLED && key == mNotificationPeekKey) {
// must update the peek window
Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK);
peekMsg.arg1 = mNotificationPeekIndex;
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
mHandler.sendMessage(peekMsg);
}
}
catch (RuntimeException e) {
// It failed to add cleanly. Log, and remove the view from the panel.
Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e);
removeNotificationViews(key);
addNotificationViews(key, notification);
}
} else {
if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key);
removeNotificationViews(key);
addNotificationViews(key, notification);
}
// fullScreenIntent doesn't happen on updates. You need to clear & repost a new
// notification.
final boolean immersive = isImmersive();
if (false && immersive) {
// TODO: immersive mode
} else {
tick(key, notification, false);
}
setAreThereNotifications();
}
public void removeNotification(IBinder key) {
if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ")");
removeNotificationViews(key);
mTicker.remove(key);
setAreThereNotifications();
}
public void showClock(boolean show) {
View clock = mBarContents.findViewById(R.id.clock);
View network_text = mBarContents.findViewById(R.id.network_text);
if (clock != null) {
clock.setVisibility(show ? View.VISIBLE : View.GONE);
}
if (network_text != null) {
network_text.setVisibility((!show) ? View.VISIBLE : View.GONE);
}
}
public void disable(int state) {
int old = mDisabled;
int diff = state ^ old;
mDisabled = state;
// act accordingly
if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) {
boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0;
Slog.i(TAG, "DISABLE_CLOCK: " + (show ? "no" : "yes"));
showClock(show);
}
if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) {
boolean show = (state & StatusBarManager.DISABLE_SYSTEM_INFO) == 0;
Slog.i(TAG, "DISABLE_SYSTEM_INFO: " + (show ? "no" : "yes"));
mNotificationTrigger.setVisibility(show ? View.VISIBLE : View.GONE);
}
if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
Slog.i(TAG, "DISABLE_EXPAND: yes");
animateCollapse();
visibilityChanged(false);
}
}
if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
mNotificationDNDMode = Prefs.read(mContext)
.getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT);
if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: yes" + (mNotificationDNDMode?" (DND)":""));
mTicker.halt();
} else {
Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: no" + (mNotificationDNDMode?" (DND)":""));
}
// refresh icons to show either notifications or the DND message
reloadAllNotificationIcons();
} else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
mTicker.halt();
}
}
if ((diff & StatusBarManager.DISABLE_NAVIGATION) != 0) {
if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) {
Slog.i(TAG, "DISABLE_NAVIGATION: yes");
mNavigationArea.setVisibility(View.INVISIBLE);
mInputMethodSwitchButton.setScreenLocked(true);
} else {
Slog.i(TAG, "DISABLE_NAVIGATION: no");
mNavigationArea.setVisibility(View.VISIBLE);
mInputMethodSwitchButton.setScreenLocked(false);
}
}
if ((diff & StatusBarManager.DISABLE_BACK) != 0) {
if ((state & StatusBarManager.DISABLE_BACK) != 0) {
Slog.i(TAG, "DISABLE_BACK: yes");
mBackButton.setEnabled(false);
mInputMethodSwitchButton.setScreenLocked(true);
} else {
Slog.i(TAG, "DISABLE_BACK: no");
mBackButton.setEnabled(true);
mInputMethodSwitchButton.setScreenLocked(false);
}
}
}
private boolean hasTicker(Notification n) {
return n.tickerView != null || !TextUtils.isEmpty(n.tickerText);
}
private void tick(IBinder key, StatusBarNotification n, boolean firstTime) {
// Don't show the ticker when the windowshade is open.
if (mNotificationPanel.isShowing()) {
return;
}
// If they asked for FLAG_ONLY_ALERT_ONCE, then only show this notification
// if it's a new notification.
if (!firstTime && (n.notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0) {
return;
}
// Show the ticker if one is requested. Also don't do this
// until status bar window is attached to the window manager,
// because... well, what's the point otherwise? And trying to
// run a ticker without being attached will crash!
if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) {
if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS
| StatusBarManager.DISABLE_NOTIFICATION_TICKER))) {
mTicker.add(key, n);
mFeedbackIconArea.setVisibility(View.GONE);
}
}
}
// called by TabletTicker when it's done with all queued ticks
public void doneTicking() {
mFeedbackIconArea.setVisibility(View.VISIBLE);
}
public void animateExpand() {
if (NOTIFICATION_PEEK_ENABLED) {
mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
}
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL);
mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL);
}
public void animateCollapse() {
mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL);
mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL);
mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
mHandler.removeMessages(MSG_CLOSE_INPUT_METHODS_PANEL);
mHandler.sendEmptyMessage(MSG_CLOSE_INPUT_METHODS_PANEL);
mHandler.removeMessages(MSG_CLOSE_COMPAT_MODE_PANEL);
mHandler.sendEmptyMessage(MSG_CLOSE_COMPAT_MODE_PANEL);
if (NOTIFICATION_PEEK_ENABLED) {
mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
}
}
/**
* The LEDs are turned o)ff when the notification panel is shown, even just a little bit.
* This was added last-minute and is inconsistent with the way the rest of the notifications
* are handled, because the notification isn't really cancelled. The lights are just
* turned off. If any other notifications happen, the lights will turn back on. Steve says
* this is what he wants. (see bug 1131461)
*/
void visibilityChanged(boolean visible) {
if (mPanelSlightlyVisible != visible) {
mPanelSlightlyVisible = visible;
try {
mBarService.onPanelRevealed();
} catch (RemoteException ex) {
// Won't fail unless the world has ended.
}
}
}
private void notifyUiVisibilityChanged() {
try {
mWindowManager.statusBarVisibilityChanged(mSystemUiVisibility);
} catch (RemoteException ex) {
}
}
@Override // CommandQueue
public void setSystemUiVisibility(int vis) {
if (vis != mSystemUiVisibility) {
mSystemUiVisibility = vis;
mHandler.removeMessages(MSG_HIDE_CHROME);
mHandler.removeMessages(MSG_SHOW_CHROME);
mHandler.sendEmptyMessage(0 == (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE)
? MSG_SHOW_CHROME : MSG_HIDE_CHROME);
notifyUiVisibilityChanged();
}
}
public void setLightsOn(boolean on) {
// Policy note: if the frontmost activity needs the menu key, we assume it is a legacy app
// that can't handle lights-out mode.
if (mMenuButton.getVisibility() == View.VISIBLE) {
on = true;
}
Slog.v(TAG, "setLightsOn(" + on + ")");
if (on) {
setSystemUiVisibility(mSystemUiVisibility & ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
} else {
setSystemUiVisibility(mSystemUiVisibility | View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
}
public void topAppWindowChanged(boolean showMenu) {
if (DEBUG) {
Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button");
}
mMenuButton.setVisibility(showMenu ? View.VISIBLE : View.GONE);
// See above re: lights-out policy for legacy apps.
if (showMenu) setLightsOn(true);
mCompatModeButton.refresh();
if (mCompatModeButton.getVisibility() == View.VISIBLE) {
if (DEBUG_COMPAT_HELP
|| ! Prefs.read(mContext).getBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, false)) {
showCompatibilityHelp();
}
} else {
hideCompatibilityHelp();
mCompatModePanel.closePanel();
}
}
private void showCompatibilityHelp() {
if (mCompatibilityHelpDialog != null) {
return;
}
mCompatibilityHelpDialog = View.inflate(mContext, R.layout.compat_mode_help, null);
View button = mCompatibilityHelpDialog.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideCompatibilityHelp();
SharedPreferences.Editor editor = Prefs.edit(mContext);
editor.putBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, true);
editor.apply();
}
});
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
PixelFormat.TRANSLUCENT);
lp.setTitle("CompatibilityModeDialog");
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade
WindowManagerImpl.getDefault().addView(mCompatibilityHelpDialog, lp);
}
private void hideCompatibilityHelp() {
if (mCompatibilityHelpDialog != null) {
WindowManagerImpl.getDefault().removeView(mCompatibilityHelpDialog);
mCompatibilityHelpDialog = null;
}
}
public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
mInputMethodSwitchButton.setImeWindowStatus(token,
(vis & InputMethodService.IME_ACTIVE) != 0);
updateNotificationIcons();
mInputMethodsPanel.setImeToken(token);
int res;
switch (backDisposition) {
case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
res = R.drawable.ic_sysbar_back;
break;
case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
res = R.drawable.ic_sysbar_back_ime;
break;
case InputMethodService.BACK_DISPOSITION_DEFAULT:
default:
if ((vis & InputMethodService.IME_VISIBLE) != 0) {
res = R.drawable.ic_sysbar_back_ime;
} else {
res = R.drawable.ic_sysbar_back;
}
break;
}
mBackButton.setImageResource(res);
if (FAKE_SPACE_BAR) {
mFakeSpaceBar.setVisibility(((vis & InputMethodService.IME_VISIBLE) != 0)
? View.VISIBLE : View.GONE);
}
}
@Override
public void setHardKeyboardStatus(boolean available, boolean enabled) {
if (DEBUG) {
Slog.d(TAG, "Set hard keyboard status: available=" + available
+ ", enabled=" + enabled);
}
mInputMethodSwitchButton.setHardKeyboardStatus(available);
updateNotificationIcons();
mInputMethodsPanel.setHardKeyboardStatus(available, enabled);
}
@Override
public void onHardKeyboardEnabledChange(boolean enabled) {
try {
mBarService.setHardKeyboardEnabled(enabled);
} catch (RemoteException ex) {
}
}
private boolean isImmersive() {
try {
return ActivityManagerNative.getDefault().isTopActivityImmersive();
//Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive"));
} catch (RemoteException ex) {
// the end is nigh
return false;
}
}
private void setAreThereNotifications() {
if (mNotificationPanel != null) {
mNotificationPanel.setClearable(mNotificationData.hasClearableItems());
}
}
/**
* Cancel this notification and tell the status bar service about the failure. Hold no locks.
*/
void handleNotificationError(IBinder key, StatusBarNotification n, String message) {
removeNotification(key);
try {
mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message);
} catch (RemoteException ex) {
// The end is nigh.
}
}
private void sendKey(KeyEvent key) {
try {
if (DEBUG) Slog.d(TAG, "injecting key event: " + key);
mWindowManager.injectInputEventNoWait(key);
} catch (RemoteException ex) {
}
}
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
if (v == mRecentButton) {
onClickRecentButton();
} else if (v == mInputMethodSwitchButton) {
onClickInputMethodSwitchButton();
} else if (v == mCompatModeButton) {
onClickCompatModeButton();
}
}
};
public void onClickRecentButton() {
if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled);
if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) {
int msg = (mRecentsPanel.getVisibility() == View.GONE)
? MSG_OPEN_RECENTS_PANEL
: MSG_CLOSE_RECENTS_PANEL;
mHandler.removeMessages(msg);
mHandler.sendEmptyMessage(msg);
}
}
public void onClickInputMethodSwitchButton() {
if (DEBUG) Slog.d(TAG, "clicked input methods panel; disabled=" + mDisabled);
int msg = (mInputMethodsPanel.getVisibility() == View.GONE) ?
MSG_OPEN_INPUT_METHODS_PANEL : MSG_CLOSE_INPUT_METHODS_PANEL;
mHandler.removeMessages(msg);
mHandler.sendEmptyMessage(msg);
}
public void onClickCompatModeButton() {
int msg = (mCompatModePanel.getVisibility() == View.GONE) ?
MSG_OPEN_COMPAT_MODE_PANEL : MSG_CLOSE_COMPAT_MODE_PANEL;
mHandler.removeMessages(msg);
mHandler.sendEmptyMessage(msg);
}
public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) {
return new NotificationClicker(intent, pkg, tag, id);
}
private class NotificationClicker implements View.OnClickListener {
private PendingIntent mIntent;
private String mPkg;
private String mTag;
private int mId;
NotificationClicker(PendingIntent intent, String pkg, String tag, int id) {
mIntent = intent;
mPkg = pkg;
mTag = tag;
mId = id;
}
public void onClick(View v) {
try {
// The intent we are sending is for the application, which
// won't have permission to immediately start an activity after
// the user switches to home. We know it is safe to do at this
// point, so make sure new activity switches are now allowed.
ActivityManagerNative.getDefault().resumeAppSwitches();
} catch (RemoteException e) {
}
if (mIntent != null) {
int[] pos = new int[2];
v.getLocationOnScreen(pos);
Intent overlay = new Intent();
overlay.setSourceBounds(
new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight()));
try {
mIntent.send(mContext, 0, overlay);
} catch (PendingIntent.CanceledException e) {
// the stack trace isn't very helpful here. Just log the exception message.
Slog.w(TAG, "Sending contentIntent failed: " + e);
}
}
try {
mBarService.onNotificationClick(mPkg, mTag, mId);
} catch (RemoteException ex) {
// system process is dead if we're here.
}
// close the shade if it was open
animateCollapse();
visibilityChanged(false);
// If this click was on the intruder alert, hide that instead
// mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER);
}
}
StatusBarNotification removeNotificationViews(IBinder key) {
NotificationData.Entry entry = mNotificationData.remove(key);
if (entry == null) {
Slog.w(TAG, "removeNotification for unknown key: " + key);
return null;
}
// Remove the expanded view.
ViewGroup rowParent = (ViewGroup)entry.row.getParent();
if (rowParent != null) rowParent.removeView(entry.row);
if (NOTIFICATION_PEEK_ENABLED && key == mNotificationPeekKey) {
// must close the peek as well, since it's gone
mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
}
// Remove the icon.
// ViewGroup iconParent = (ViewGroup)entry.icon.getParent();
// if (iconParent != null) iconParent.removeView(entry.icon);
updateNotificationIcons();
return entry.notification;
}
private class NotificationTriggerTouchListener implements View.OnTouchListener {
VelocityTracker mVT;
float mInitialTouchX, mInitialTouchY;
int mTouchSlop;
public NotificationTriggerTouchListener() {
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
}
private Runnable mHiliteOnR = new Runnable() { public void run() {
mNotificationArea.setBackgroundResource(
com.android.internal.R.drawable.list_selector_pressed_holo_dark);
}};
public void hilite(final boolean on) {
if (on) {
mNotificationArea.postDelayed(mHiliteOnR, 100);
} else {
mNotificationArea.removeCallbacks(mHiliteOnR);
mNotificationArea.setBackgroundDrawable(null);
}
}
public boolean onTouch(View v, MotionEvent event) {
// Slog.d(TAG, String.format("touch: (%.1f, %.1f) initial: (%.1f, %.1f)",
// event.getX(),
// event.getY(),
// mInitialTouchX,
// mInitialTouchY));
if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
return true;
}
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
mVT = VelocityTracker.obtain();
mInitialTouchX = event.getX();
mInitialTouchY = event.getY();
hilite(true);
// fall through
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_MOVE:
// check for fling
if (mVT != null) {
mVT.addMovement(event);
mVT.computeCurrentVelocity(1000); // pixels per second
// require a little more oomph once we're already in peekaboo mode
if (mVT.getYVelocity() < -mNotificationFlingVelocity) {
animateExpand();
visibilityChanged(true);
hilite(false);
mVT.recycle();
mVT = null;
}
}
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
hilite(false);
if (mVT != null) {
if (action == MotionEvent.ACTION_UP
// was this a sloppy tap?
&& Math.abs(event.getX() - mInitialTouchX) < mTouchSlop
&& Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3)
// dragging off the bottom doesn't count
&& (int)event.getY() < v.getBottom()) {
animateExpand();
visibilityChanged(true);
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
v.playSoundEffect(SoundEffectConstants.CLICK);
}
mVT.recycle();
mVT = null;
return true;
}
}
return false;
}
}
public void resetNotificationPeekFadeTimer() {
if (DEBUG) {
Slog.d(TAG, "setting peek fade timer for " + NOTIFICATION_PEEK_FADE_DELAY
+ "ms from now");
}
mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK,
NOTIFICATION_PEEK_FADE_DELAY);
}
private class NotificationIconTouchListener implements View.OnTouchListener {
VelocityTracker mVT;
int mPeekIndex;
float mInitialTouchX, mInitialTouchY;
int mTouchSlop;
public NotificationIconTouchListener() {
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
}
public boolean onTouch(View v, MotionEvent event) {
boolean peeking = mNotificationPeekWindow.getVisibility() != View.GONE;
boolean panelShowing = mNotificationPanel.isShowing();
if (panelShowing) return false;
int numIcons = mIconLayout.getChildCount();
int newPeekIndex = (int)(event.getX() * numIcons / mIconLayout.getWidth());
if (newPeekIndex > numIcons - 1) newPeekIndex = numIcons - 1;
else if (newPeekIndex < 0) newPeekIndex = 0;
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
mVT = VelocityTracker.obtain();
mInitialTouchX = event.getX();
mInitialTouchY = event.getY();
mPeekIndex = -1;
// fall through
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_MOVE:
// peek and switch icons if necessary
if (newPeekIndex != mPeekIndex) {
mPeekIndex = newPeekIndex;
if (DEBUG) Slog.d(TAG, "will peek at notification #" + mPeekIndex);
Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK);
peekMsg.arg1 = mPeekIndex;
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
if (peeking) {
// no delay if we're scrubbing left-right
mHandler.sendMessage(peekMsg);
} else {
// wait for fling
mHandler.sendMessageDelayed(peekMsg, NOTIFICATION_PEEK_HOLD_THRESH);
}
}
// check for fling
if (mVT != null) {
mVT.addMovement(event);
mVT.computeCurrentVelocity(1000); // pixels per second
// require a little more oomph once we're already in peekaboo mode
if (!panelShowing && (
(peeking && mVT.getYVelocity() < -mNotificationFlingVelocity*3)
|| (mVT.getYVelocity() < -mNotificationFlingVelocity))) {
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL);
mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL);
}
}
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
if (!peeking) {
if (action == MotionEvent.ACTION_UP
// was this a sloppy tap?
&& Math.abs(event.getX() - mInitialTouchX) < mTouchSlop
&& Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3)
// dragging off the bottom doesn't count
&& (int)event.getY() < v.getBottom()) {
Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK);
peekMsg.arg1 = mPeekIndex;
mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
mHandler.sendMessage(peekMsg);
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
v.playSoundEffect(SoundEffectConstants.CLICK);
peeking = true; // not technically true yet, but the next line will run
}
}
if (peeking) {
resetNotificationPeekFadeTimer();
}
mVT.recycle();
mVT = null;
return true;
}
return false;
}
}
StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) {
if (DEBUG) {
Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification);
}
// Construct the icon.
final StatusBarIconView iconView = new StatusBarIconView(mContext,
notification.pkg + "/0x" + Integer.toHexString(notification.id),
notification.notification);
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
notification.notification.icon,
notification.notification.iconLevel,
notification.notification.number,
notification.notification.tickerText);
if (!iconView.set(ic)) {
handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic);
return null;
}
// Construct the expanded view.
NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView);
if (!inflateViews(entry, mPile)) {
handleNotificationError(key, notification, "Couldn't expand RemoteViews for: "
+ notification);
return null;
}
// Add the icon.
int pos = mNotificationData.add(entry);
if (DEBUG) {
Slog.d(TAG, "addNotificationViews: added at " + pos);
}
updateNotificationIcons();
return iconView;
}
private void reloadAllNotificationIcons() {
if (mIconLayout == null) return;
mIconLayout.removeAllViews();
updateNotificationIcons();
}
private void updateNotificationIcons() {
// XXX: need to implement a new limited linear layout class
// to avoid removing & readding everything
if (mIconLayout == null) return;
// first, populate the main notification panel
loadNotificationPanel();
final LinearLayout.LayoutParams params
= new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight);
// alternate behavior in DND mode
if (mNotificationDNDMode) {
if (mIconLayout.getChildCount() == 0) {
final Notification dndNotification = new Notification.Builder(mContext)
.setContentTitle(mContext.getText(R.string.notifications_off_title))
.setContentText(mContext.getText(R.string.notifications_off_text))
.setSmallIcon(R.drawable.ic_notification_dnd)
.setOngoing(true)
.getNotification();
final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd",
dndNotification);
iconView.setImageResource(R.drawable.ic_notification_dnd);
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0);
mNotificationDNDDummyEntry = new NotificationData.Entry(
null,
new StatusBarNotification("", 0, "", 0, 0, dndNotification),
iconView);
mIconLayout.addView(iconView, params);
}
return;
} else if (0 != (mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS)) {
// if icons are disabled but we're not in DND mode, this is probably Setup and we should
// just leave the area totally empty
return;
}
int N = mNotificationData.size();
if (DEBUG) {
Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout);
}
ArrayList<View> toShow = new ArrayList<View>();
// Extra Special Icons
// The IME switcher and compatibility mode icons take the place of notifications. You didn't
// need to see all those new emails, did you?
int maxNotificationIconsCount = mMaxNotificationIcons;
if (mInputMethodSwitchButton.getVisibility() != View.GONE) maxNotificationIconsCount --;
if (mCompatModeButton.getVisibility() != View.GONE) maxNotificationIconsCount --;
for (int i=0; i< maxNotificationIconsCount; i++) {
if (i>=N) break;
toShow.add(mNotificationData.get(N-i-1).icon);
}
ArrayList<View> toRemove = new ArrayList<View>();
for (int i=0; i<mIconLayout.getChildCount(); i++) {
View child = mIconLayout.getChildAt(i);
if (!toShow.contains(child)) {
toRemove.add(child);
}
}
for (View remove : toRemove) {
mIconLayout.removeView(remove);
}
for (int i=0; i<toShow.size(); i++) {
View v = toShow.get(i);
v.setPadding(mIconHPadding, 0, mIconHPadding, 0);
if (v.getParent() == null) {
mIconLayout.addView(v, i, params);
}
}
}
private void loadNotificationPanel() {
int N = mNotificationData.size();
ArrayList<View> toShow = new ArrayList<View>();
for (int i=0; i<N; i++) {
View row = mNotificationData.get(N-i-1).row;
toShow.add(row);
}
ArrayList<View> toRemove = new ArrayList<View>();
for (int i=0; i<mPile.getChildCount(); i++) {
View child = mPile.getChildAt(i);
if (!toShow.contains(child)) {
toRemove.add(child);
}
}
for (View remove : toRemove) {
mPile.removeView(remove);
}
for (int i=0; i<toShow.size(); i++) {
View v = toShow.get(i);
if (v.getParent() == null) {
mPile.addView(v, N-1-i); // the notification panel has newest at the bottom
}
}
mNotificationPanel.setNotificationCount(N);
}
void workAroundBadLayerDrawableOpacity(View v) {
LayerDrawable d = (LayerDrawable)v.getBackground();
if (d == null) return;
v.setBackgroundDrawable(null);
d.setOpacity(PixelFormat.TRANSLUCENT);
v.setBackgroundDrawable(d);
}
private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) {
StatusBarNotification sbn = entry.notification;
RemoteViews remoteViews = sbn.notification.contentView;
if (remoteViews == null) {
return false;
}
// create the row view
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false);
workAroundBadLayerDrawableOpacity(row);
View vetoButton = row.findViewById(R.id.veto);
if (entry.notification.isClearable()) {
final String _pkg = sbn.pkg;
final String _tag = sbn.tag;
final int _id = sbn.id;
vetoButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
mBarService.onNotificationClear(_pkg, _tag, _id);
} catch (RemoteException ex) {
// system process is dead if we're here.
}
}
});
} else {
if ((sbn.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) {
vetoButton.setVisibility(View.INVISIBLE);
vetoButton.setContentDescription("VETO");
} else {
vetoButton.setVisibility(View.GONE);
}
}
vetoButton.setContentDescription(mContext.getString(
R.string.accessibility_remove_notification));
// the large icon
ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon);
if (sbn.notification.largeIcon != null) {
largeIcon.setImageBitmap(sbn.notification.largeIcon);
largeIcon.setContentDescription(sbn.notification.tickerText);
} else {
largeIcon.getLayoutParams().width = 0;
largeIcon.setVisibility(View.INVISIBLE);
}
largeIcon.setContentDescription(sbn.notification.tickerText);
// bind the click event to the content area
ViewGroup content = (ViewGroup)row.findViewById(R.id.content);
// XXX: update to allow controls within notification views
content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
// content.setOnFocusChangeListener(mFocusChangeListener);
PendingIntent contentIntent = sbn.notification.contentIntent;
if (contentIntent != null) {
content.setOnClickListener(new NotificationClicker(contentIntent,
sbn.pkg, sbn.tag, sbn.id));
} else {
content.setOnClickListener(null);
}
View expanded = null;
Exception exception = null;
try {
expanded = remoteViews.apply(mContext, content);
}
catch (RuntimeException e) {
exception = e;
}
if (expanded == null) {
final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id);
Slog.e(TAG, "couldn't inflate view for notification " + ident, exception);
return false;
} else {
content.addView(expanded);
row.setDrawingCacheEnabled(true);
}
entry.row = row;
entry.content = content;
entry.expanded = expanded;
entry.largeIcon = largeIcon;
return true;
}
public void clearAll() {
try {
mBarService.onClearAllNotifications();
} catch (RemoteException ex) {
// system process is dead if we're here.
}
animateCollapse();
visibilityChanged(false);
}
public void userActivity() {
}
public void toggleRecentApps() {
int msg = (mRecentsPanel.getVisibility() == View.GONE)
? MSG_OPEN_RECENTS_PANEL : MSG_CLOSE_RECENTS_PANEL;
mHandler.removeMessages(msg);
mHandler.sendEmptyMessage(msg);
}
public class TouchOutsideListener implements View.OnTouchListener {
private int mMsg;
private StatusBarPanel mPanel;
public TouchOutsideListener(int msg, StatusBarPanel panel) {
mMsg = msg;
mPanel = panel;
}
public boolean onTouch(View v, MotionEvent ev) {
final int action = ev.getAction();
if (action == MotionEvent.ACTION_OUTSIDE
|| (action == MotionEvent.ACTION_DOWN
&& !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) {
mHandler.removeMessages(mMsg);
mHandler.sendEmptyMessage(mMsg);
return true;
}
return false;
}
}
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.print("mDisabled=0x");
pw.println(Integer.toHexString(mDisabled));
pw.println("mNetworkController:");
mNetworkController.dump(fd, pw, args);
}
}
|