/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java

https://github.com/aizuzi/platform_frameworks_base · Java · 159 lines · 117 code · 14 blank · 28 comment · 21 complexity · ae5a6a4d5dea6ddbe04141063fb1da93 MD5 · raw file

  1. /*
  2. * Copyright (C) 2008 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. package com.android.systemui.statusbar;
  17. import android.os.IBinder;
  18. import android.service.notification.StatusBarNotification;
  19. import android.view.View;
  20. import android.widget.ImageView;
  21. import com.android.systemui.R;
  22. import java.util.ArrayList;
  23. import java.util.Comparator;
  24. /**
  25. * The list of currently displaying notifications.
  26. */
  27. public class NotificationData {
  28. public static final class Entry {
  29. public IBinder key;
  30. public StatusBarNotification notification;
  31. public StatusBarIconView icon;
  32. public ExpandableNotificationRow row; // the outer expanded view
  33. public View content; // takes the click events and sends the PendingIntent
  34. public View expanded; // the inflated RemoteViews
  35. public ImageView largeIcon;
  36. private View expandedBig;
  37. private boolean interruption;
  38. public Entry() {}
  39. public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) {
  40. this.key = key;
  41. this.notification = n;
  42. this.icon = ic;
  43. }
  44. public void setBigContentView(View bigContentView) {
  45. this.expandedBig = bigContentView;
  46. row.setExpandable(bigContentView != null);
  47. }
  48. public View getBigContentView() {
  49. return expandedBig;
  50. }
  51. /**
  52. * Set the flag indicating that this is being touched by the user.
  53. */
  54. public void setUserLocked(boolean userLocked) {
  55. row.setUserLocked(userLocked);
  56. }
  57. public void setInterruption() {
  58. interruption = true;
  59. }
  60. }
  61. private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
  62. private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
  63. // sort first by score, then by when
  64. public int compare(Entry a, Entry b) {
  65. final StatusBarNotification na = a.notification;
  66. final StatusBarNotification nb = b.notification;
  67. int d = na.getScore() - nb.getScore();
  68. if (a.interruption != b.interruption) {
  69. return a.interruption ? 1 : -1;
  70. } else if (d != 0) {
  71. return d;
  72. } else {
  73. return (int) (na.getNotification().when - nb.getNotification().when);
  74. }
  75. }
  76. };
  77. public int size() {
  78. return mEntries.size();
  79. }
  80. public Entry get(int i) {
  81. return mEntries.get(i);
  82. }
  83. public Entry findByKey(IBinder key) {
  84. for (Entry e : mEntries) {
  85. if (e.key == key) {
  86. return e;
  87. }
  88. }
  89. return null;
  90. }
  91. public int add(Entry entry) {
  92. int i;
  93. int N = mEntries.size();
  94. for (i=0; i<N; i++) {
  95. if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
  96. break;
  97. }
  98. }
  99. mEntries.add(i, entry);
  100. return i;
  101. }
  102. public int add(IBinder key, StatusBarNotification notification, ExpandableNotificationRow row,
  103. View content, View expanded, StatusBarIconView icon) {
  104. Entry entry = new Entry();
  105. entry.key = key;
  106. entry.notification = notification;
  107. entry.row = row;
  108. entry.content = content;
  109. entry.expanded = expanded;
  110. entry.icon = icon;
  111. entry.largeIcon = null; // TODO add support for large icons
  112. return add(entry);
  113. }
  114. public Entry remove(IBinder key) {
  115. Entry e = findByKey(key);
  116. if (e != null) {
  117. mEntries.remove(e);
  118. }
  119. return e;
  120. }
  121. /**
  122. * Return whether there are any visible items (i.e. items without an error).
  123. */
  124. public boolean hasVisibleItems() {
  125. for (Entry e : mEntries) {
  126. if (e.expanded != null) { // the view successfully inflated
  127. return true;
  128. }
  129. }
  130. return false;
  131. }
  132. /**
  133. * Return whether there are any clearable items (that aren't errors).
  134. */
  135. public boolean hasClearableItems() {
  136. for (Entry e : mEntries) {
  137. if (e.expanded != null) { // the view successfully inflated
  138. if (e.notification.isClearable()) {
  139. return true;
  140. }
  141. }
  142. }
  143. return false;
  144. }
  145. }