| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.statusbar; |
| 18 |
|
| 19 |
import android.os.Message; |
| 20 |
import android.os.Parcel; |
| 21 |
import android.os.Parcelable; |
| 22 |
import android.util.Log; |
| 23 |
|
| 24 |
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 25 |
|
| 26 |
import java.util.ArrayDeque; |
| 27 |
import java.util.Collection; |
| 28 |
|
| 29 |
public class NotificationVisibility implements Parcelable { |
| 30 |
private static final String TAG = "NoViz"; |
| 31 |
private static final int MAX_POOL_SIZE = 25; |
| 32 |
private static int sNexrId = 0; |
| 33 |
|
| 34 |
public String key; |
| 35 |
public int rank; |
| 36 |
public int count; |
| 37 |
public boolean visible = true; |
| 38 |
|
| 39 |
public NotificationLocation location; |
| 40 |
int id; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public enum NotificationLocation { |
| 49 |
LOCATION_UNKNOWN(MetricsEvent.LOCATION_UNKNOWN), |
| 50 |
LOCATION_FIRST_HEADS_UP(MetricsEvent.LOCATION_FIRST_HEADS_UP), |
| 51 |
LOCATION_HIDDEN_TOP(MetricsEvent.LOCATION_HIDDEN_TOP), |
| 52 |
LOCATION_MAIN_AREA(MetricsEvent.LOCATION_MAIN_AREA), |
| 53 |
|
| 54 |
LOCATION_BOTTOM_STACK_PEEKING(MetricsEvent.LOCATION_BOTTOM_STACK_PEEKING), |
| 55 |
|
| 56 |
LOCATION_BOTTOM_STACK_HIDDEN(MetricsEvent.LOCATION_BOTTOM_STACK_HIDDEN), |
| 57 |
LOCATION_GONE(MetricsEvent.LOCATION_GONE); |
| 58 |
|
| 59 |
private final int mMetricsEventNotificationLocation; |
| 60 |
|
| 61 |
NotificationLocation(int metricsEventNotificationLocation) { |
| 62 |
mMetricsEventNotificationLocation = metricsEventNotificationLocation; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public int toMetricsEventEnum() { |
| 69 |
return mMetricsEventNotificationLocation; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
private NotificationVisibility() { |
| 74 |
id = sNexrId++; |
| 75 |
} |
| 76 |
|
| 77 |
private NotificationVisibility(String key, int rank, int count, boolean visible, |
| 78 |
NotificationLocation location) { |
| 79 |
this(); |
| 80 |
this.key = key; |
| 81 |
this.rank = rank; |
| 82 |
this.count = count; |
| 83 |
this.visible = visible; |
| 84 |
this.location = location; |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public String toString() { |
| 89 |
return "NotificationVisibility(id=" + id |
| 90 |
+ " key=" + key |
| 91 |
+ " rank=" + rank |
| 92 |
+ " count=" + count |
| 93 |
+ (visible?" visible":"") |
| 94 |
+ " location=" + location.name() |
| 95 |
+ " )"; |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
public NotificationVisibility clone() { |
| 100 |
return obtain(this.key, this.rank, this.count, this.visible, this.location); |
| 101 |
} |
| 102 |
|
| 103 |
@Override |
| 104 |
public int hashCode() { |
| 105 |
|
| 106 |
return key == null ? 0 : key.hashCode(); |
| 107 |
} |
| 108 |
|
| 109 |
@Override |
| 110 |
public boolean equals(Object that) { |
| 111 |
|
| 112 |
if (that instanceof NotificationVisibility) { |
| 113 |
NotificationVisibility thatViz = (NotificationVisibility) that; |
| 114 |
return (key == null && thatViz.key == null) || key.equals(thatViz.key); |
| 115 |
} |
| 116 |
return false; |
| 117 |
} |
| 118 |
|
| 119 |
@Override |
| 120 |
public int describeContents() { |
| 121 |
return 0; |
| 122 |
} |
| 123 |
|
| 124 |
@Override |
| 125 |
public void writeToParcel(Parcel out, int flags) { |
| 126 |
out.writeString(this.key); |
| 127 |
out.writeInt(this.rank); |
| 128 |
out.writeInt(this.count); |
| 129 |
out.writeInt(this.visible ? 1 : 0); |
| 130 |
out.writeString(this.location.name()); |
| 131 |
} |
| 132 |
|
| 133 |
private void readFromParcel(Parcel in) { |
| 134 |
this.key = in.readString(); |
| 135 |
this.rank = in.readInt(); |
| 136 |
this.count = in.readInt(); |
| 137 |
this.visible = in.readInt() != 0; |
| 138 |
this.location = NotificationLocation.valueOf(in.readString()); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public static NotificationVisibility obtain(String key, int rank, int count, boolean visible) { |
| 145 |
return obtain(key, rank, count, visible, |
| 146 |
NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public static NotificationVisibility obtain(String key, int rank, int count, boolean visible, |
| 153 |
NotificationLocation location) { |
| 154 |
NotificationVisibility vo = obtain(); |
| 155 |
vo.key = key; |
| 156 |
vo.rank = rank; |
| 157 |
vo.count = count; |
| 158 |
vo.visible = visible; |
| 159 |
vo.location = location; |
| 160 |
return vo; |
| 161 |
} |
| 162 |
|
| 163 |
private static NotificationVisibility obtain(Parcel in) { |
| 164 |
NotificationVisibility vo = obtain(); |
| 165 |
vo.readFromParcel(in); |
| 166 |
return vo; |
| 167 |
} |
| 168 |
|
| 169 |
private static NotificationVisibility obtain() { |
| 170 |
return new NotificationVisibility(); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
public void recycle() { |
| 181 |
|
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
public static final Parcelable.Creator<NotificationVisibility> CREATOR |
| 188 |
= new Parcelable.Creator<NotificationVisibility>() |
| 189 |
{ |
| 190 |
public NotificationVisibility createFromParcel(Parcel parcel) |
| 191 |
{ |
| 192 |
return obtain(parcel); |
| 193 |
} |
| 194 |
|
| 195 |
public NotificationVisibility[] newArray(int size) |
| 196 |
{ |
| 197 |
return new NotificationVisibility[size]; |
| 198 |
} |
| 199 |
}; |
| 200 |
} |
| 201 |
|