| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.contentcapture; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.app.usage.UsageEvents.Event; |
| 23 |
import android.content.ComponentName; |
| 24 |
import android.os.Parcel; |
| 25 |
import android.os.Parcelable; |
| 26 |
|
| 27 |
import java.lang.annotation.Retention; |
| 28 |
import java.lang.annotation.RetentionPolicy; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@SystemApi |
| 36 |
public final class ActivityEvent implements Parcelable { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public static final int TYPE_ACTIVITY_RESUMED = Event.ACTIVITY_RESUMED; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static final int TYPE_ACTIVITY_PAUSED = Event.ACTIVITY_PAUSED; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public static final int TYPE_ACTIVITY_STOPPED = Event.ACTIVITY_STOPPED; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static final int TYPE_ACTIVITY_DESTROYED = Event.ACTIVITY_DESTROYED; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public static final int TYPE_ACTIVITY_STARTED = 10000; |
| 69 |
|
| 70 |
|
| 71 |
@IntDef(prefix = { "TYPE_" }, value = { |
| 72 |
TYPE_ACTIVITY_RESUMED, |
| 73 |
TYPE_ACTIVITY_PAUSED, |
| 74 |
TYPE_ACTIVITY_STOPPED, |
| 75 |
TYPE_ACTIVITY_DESTROYED, |
| 76 |
TYPE_ACTIVITY_STARTED |
| 77 |
}) |
| 78 |
@Retention(RetentionPolicy.SOURCE) |
| 79 |
public @interface ActivityEventType{} |
| 80 |
|
| 81 |
private final @NonNull ComponentName mComponentName; |
| 82 |
private final @ActivityEventType int mType; |
| 83 |
|
| 84 |
|
| 85 |
public ActivityEvent(@NonNull ComponentName componentName, @ActivityEventType int type) { |
| 86 |
mComponentName = componentName; |
| 87 |
mType = type; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
@NonNull |
| 94 |
public ComponentName getComponentName() { |
| 95 |
return mComponentName; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
@ActivityEventType |
| 106 |
public int getEventType() { |
| 107 |
return mType; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
public static String getTypeAsString(@ActivityEventType int type) { |
| 112 |
switch (type) { |
| 113 |
case TYPE_ACTIVITY_RESUMED: |
| 114 |
return "ACTIVITY_RESUMED"; |
| 115 |
case TYPE_ACTIVITY_PAUSED: |
| 116 |
return "ACTIVITY_PAUSED"; |
| 117 |
case TYPE_ACTIVITY_STOPPED: |
| 118 |
return "ACTIVITY_STOPPED"; |
| 119 |
case TYPE_ACTIVITY_DESTROYED: |
| 120 |
return "ACTIVITY_DESTROYED"; |
| 121 |
case TYPE_ACTIVITY_STARTED: |
| 122 |
return "ACTIVITY_STARTED"; |
| 123 |
default: |
| 124 |
return "UKNOWN_TYPE: " + type; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
@NonNull |
| 129 |
@Override |
| 130 |
public String toString() { |
| 131 |
return new StringBuilder("ActivityEvent[").append(mComponentName.toShortString()) |
| 132 |
.append("]:").append(getTypeAsString(mType)).toString(); |
| 133 |
} |
| 134 |
|
| 135 |
@Override |
| 136 |
public int describeContents() { |
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public void writeToParcel(@NonNull Parcel parcel, int flags) { |
| 142 |
parcel.writeParcelable(mComponentName, flags); |
| 143 |
parcel.writeInt(mType); |
| 144 |
} |
| 145 |
|
| 146 |
public static final @android.annotation.NonNull Creator<ActivityEvent> CREATOR = |
| 147 |
new Creator<ActivityEvent>() { |
| 148 |
|
| 149 |
@Override |
| 150 |
@NonNull |
| 151 |
public ActivityEvent createFromParcel(@NonNull Parcel parcel) { |
| 152 |
final ComponentName componentName = parcel.readParcelable(null, android.content.ComponentName.class); |
| 153 |
final int eventType = parcel.readInt(); |
| 154 |
return new ActivityEvent(componentName, eventType); |
| 155 |
} |
| 156 |
|
| 157 |
@Override |
| 158 |
@NonNull |
| 159 |
public ActivityEvent[] newArray(int size) { |
| 160 |
return new ActivityEvent[size]; |
| 161 |
} |
| 162 |
}; |
| 163 |
} |