1 /* 2 * Copyright (C) 2015 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.car.hardware.radio; 18 19 import android.annotation.SystemApi; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * A CarRadioEvent object corresponds to a single radio event coming from the car. 25 * 26 * This works in conjunction with the callbacks already defined in {@link RadioCallback.Callback}. 27 * @hide 28 */ 29 @SystemApi 30 public class CarRadioEvent implements Parcelable { 31 /** 32 * Event specifying that a radio preset has been changed. 33 */ 34 public static final int RADIO_PRESET = 0; 35 36 /** 37 * Event type. 38 */ 39 private final int mType; 40 41 /** 42 * CarRadioPreset for the event type EVENT_RADIO_PRESET. 43 */ 44 private final CarRadioPreset mPreset; 45 46 // Getters. getPreset()47 public CarRadioPreset getPreset() { 48 return mPreset; 49 } 50 getEventType()51 public int getEventType() { 52 return mType; 53 } 54 55 @Override describeContents()56 public int describeContents() { 57 return 0; 58 } 59 60 @Override writeToParcel(Parcel dest, int flags)61 public void writeToParcel(Parcel dest, int flags) { 62 dest.writeInt(mType); 63 dest.writeParcelable(mPreset, 0); 64 } 65 66 public static final Parcelable.Creator<CarRadioEvent> CREATOR 67 = new Parcelable.Creator<CarRadioEvent>() { 68 public CarRadioEvent createFromParcel(Parcel in) { 69 return new CarRadioEvent(in); 70 } 71 72 public CarRadioEvent[] newArray(int size) { 73 return new CarRadioEvent[size]; 74 } 75 }; 76 CarRadioEvent(int type, CarRadioPreset preset)77 public CarRadioEvent(int type, CarRadioPreset preset) { 78 mType = type; 79 mPreset = preset; 80 } 81 CarRadioEvent(Parcel in)82 private CarRadioEvent(Parcel in) { 83 mType = in.readInt(); 84 mPreset = in.readParcelable(CarRadioPreset.class.getClassLoader()); 85 } 86 toString()87 public String toString() { 88 String data = ""; 89 switch (mType) { 90 case RADIO_PRESET: 91 data = mPreset.toString(); 92 } 93 return mType + " " + data; 94 } 95 } 96