1 /* 2 * Copyright (C) 2014 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 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 * A class representing an event for Activity changes. 29 * 30 * @hide 31 */ 32 public class ActivityChangedEvent implements Parcelable { 33 private final List<ActivityRecognitionEvent> mActivityRecognitionEvents; 34 ActivityChangedEvent(ActivityRecognitionEvent[] activityRecognitionEvents)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 getActivityRecognitionEvents()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 describeContents()68 public int describeContents() { 69 return 0; 70 } 71 72 @Override writeToParcel(Parcel parcel, int flags)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 toString()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 } 93