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 * CarPreset object corresponds to a preset that is stored on the car's Radio unit. 25 * @hide 26 */ 27 @SystemApi 28 public class CarRadioPreset implements Parcelable { 29 30 /* 31 * Preset number at which this preset is stored. 32 * 33 * The value is 1 index based. 34 */ 35 private final int mPresetNumber; 36 /** 37 * Radio band this preset belongs to. 38 * See {@link RadioManager.BAND_FM}, {@link RadioManager.BAND_AM} etc. 39 */ 40 private final int mBand; 41 /** 42 * Channel number. 43 */ 44 private final int mChannel; 45 /** 46 * Sub channel number. 47 */ 48 private final int mSubChannel; 49 describeContents()50 public int describeContents() { 51 return 0; 52 } 53 writeToParcel(Parcel out, int flags)54 public void writeToParcel(Parcel out, int flags) { 55 out.writeInt(mPresetNumber); 56 out.writeInt(mBand); 57 out.writeInt(mChannel); 58 out.writeInt(mSubChannel); 59 } 60 61 public static final Parcelable.Creator<CarRadioPreset> CREATOR 62 = new Parcelable.Creator<CarRadioPreset>() { 63 public CarRadioPreset createFromParcel(Parcel in) { 64 return new CarRadioPreset(in); 65 } 66 67 public CarRadioPreset[] newArray(int size) { 68 return new CarRadioPreset[size]; 69 } 70 }; 71 CarRadioPreset(Parcel in)72 private CarRadioPreset(Parcel in) { 73 mPresetNumber = in.readInt(); 74 mBand = in.readInt(); 75 mChannel = in.readInt(); 76 mSubChannel = in.readInt(); 77 } 78 CarRadioPreset(int presetNumber, int bandType, int channel, int subChannel)79 public CarRadioPreset(int presetNumber, int bandType, int channel, int subChannel) { 80 mPresetNumber = presetNumber; 81 mBand = bandType; 82 mChannel = channel; 83 mSubChannel = subChannel; 84 } 85 86 // Getters. getPresetNumber()87 public int getPresetNumber() { return mPresetNumber; } 88 getBand()89 public int getBand() { return mBand; } 90 getChannel()91 public int getChannel() { return mChannel; } 92 getSubChannel()93 public int getSubChannel() { return mSubChannel; } 94 95 // Printer. toString()96 public String toString() { 97 return "Preset Number: " + mPresetNumber + "\n" + 98 "Band: " + mBand + "\n" + 99 "Channel: " + mChannel + "\n" + 100 "Sub channel: " + mSubChannel; 101 } 102 103 // Comparator. equals(Object o)104 public boolean equals(Object o) { 105 CarRadioPreset that = (CarRadioPreset) o; 106 107 return that.getPresetNumber() == mPresetNumber && 108 that.getBand() == mBand && 109 that.getChannel() == mChannel && 110 that.getSubChannel() == mSubChannel; 111 112 } 113 } 114