| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.location; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.os.Parcel; |
| 21 |
import android.os.Parcelable; |
| 22 |
|
| 23 |
import java.security.InvalidParameterException; |
| 24 |
import java.util.Arrays; |
| 25 |
import java.util.List; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class ActivityChangedEvent implements Parcelable { |
| 33 |
private final List<ActivityRecognitionEvent> mActivityRecognitionEvents; |
| 34 |
|
| 35 |
public ActivityChangedEvent(ActivityRecognitionEvent[] activityRecognitionEvents) { |
| 36 |
if (activityRecognitionEvents == null) { |
| 37 |
throw new InvalidParameterException( |
| 38 |
"Parameter 'activityRecognitionEvents' must not be null."); |
| 39 |
} |
| 40 |
|
| 41 |
mActivityRecognitionEvents = Arrays.asList(activityRecognitionEvents); |
| 42 |
} |
| 43 |
|
| 44 |
@NonNull |
| 45 |
public Iterable<ActivityRecognitionEvent> getActivityRecognitionEvents() { |
| 46 |
return mActivityRecognitionEvents; |
| 47 |
} |
| 48 |
|
| 49 |
public static final @android.annotation.NonNull Creator<ActivityChangedEvent> CREATOR = |
| 50 |
new Creator<ActivityChangedEvent>() { |
| 51 |
@Override |
| 52 |
public ActivityChangedEvent createFromParcel(Parcel source) { |
| 53 |
int activityRecognitionEventsLength = source.readInt(); |
| 54 |
ActivityRecognitionEvent[] activityRecognitionEvents = |
| 55 |
new ActivityRecognitionEvent[activityRecognitionEventsLength]; |
| 56 |
source.readTypedArray(activityRecognitionEvents, ActivityRecognitionEvent.CREATOR); |
| 57 |
|
| 58 |
return new ActivityChangedEvent(activityRecognitionEvents); |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public ActivityChangedEvent[] newArray(int size) { |
| 63 |
return new ActivityChangedEvent[size]; |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
@Override |
| 68 |
public int describeContents() { |
| 69 |
return 0; |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public void writeToParcel(Parcel parcel, int flags) { |
| 74 |
ActivityRecognitionEvent[] activityRecognitionEventArray = |
| 75 |
mActivityRecognitionEvents.toArray(new ActivityRecognitionEvent[0]); |
| 76 |
parcel.writeInt(activityRecognitionEventArray.length); |
| 77 |
parcel.writeTypedArray(activityRecognitionEventArray, flags); |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public String toString() { |
| 82 |
StringBuilder builder = new StringBuilder("[ ActivityChangedEvent:"); |
| 83 |
|
| 84 |
for (ActivityRecognitionEvent event : mActivityRecognitionEvents) { |
| 85 |
builder.append("\n "); |
| 86 |
builder.append(event.toString()); |
| 87 |
} |
| 88 |
builder.append("\n]"); |
| 89 |
|
| 90 |
return builder.toString(); |
| 91 |
} |
| 92 |
} |