1 /* 2 * Copyright (c) 2016, 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 package com.android.car.radio.service; 17 18 import android.os.Parcel; 19 import android.os.Parcelable; 20 import android.support.annotation.Nullable; 21 22 import java.util.Objects; 23 24 /** 25 * An object that wraps the metadata for a particular radio station. 26 */ 27 public class RadioRds implements Parcelable { 28 private String mProgramService; 29 private String mSongArtist; 30 private String mSongTitle; 31 32 /** 33 * @param programService The programme service for the current station This is typically the 34 * call letters or station identity name. 35 * @param songArtist The name of the artist for the current song. 36 * @param songTitle The name of the current song. 37 */ RadioRds(@ullable String programService, @Nullable String songArtist, @Nullable String songTitle)38 public RadioRds(@Nullable String programService, @Nullable String songArtist, 39 @Nullable String songTitle) { 40 mProgramService = programService; 41 mSongArtist = songArtist; 42 mSongTitle = songTitle; 43 } 44 RadioRds(Parcel in)45 private RadioRds(Parcel in) { 46 mProgramService = in.readString(); 47 mSongArtist = in.readString(); 48 mSongTitle = in.readString(); 49 } 50 51 @Override writeToParcel(Parcel out, int flags)52 public void writeToParcel(Parcel out, int flags) { 53 out.writeString(mProgramService); 54 out.writeString(mSongArtist); 55 out.writeString(mSongTitle); 56 } 57 58 @Nullable getProgramService()59 public String getProgramService() { 60 return mProgramService; 61 } 62 63 @Nullable getSongArtist()64 public String getSongArtist() { 65 return mSongArtist; 66 } 67 68 @Nullable getSongTitle()69 public String getSongTitle() { 70 return mSongTitle; 71 } 72 73 @Override toString()74 public String toString() { 75 return String.format("RadioRds [ps: %s, song artist: %s, song title: %s]", 76 mProgramService, mSongArtist, mSongTitle); 77 } 78 79 /** 80 * Returns {@code true} if two {@link RadioRds}s are equal. {@code RadioRds}s are considered 81 * equal if all their fields are equal. 82 */ 83 @Override equals(Object object)84 public boolean equals(Object object) { 85 if (object == this) { 86 return true; 87 } 88 89 if (!(object instanceof RadioRds)) { 90 return false; 91 } 92 93 RadioRds rds = (RadioRds) object; 94 return Objects.equals(mProgramService, rds.getProgramService()) 95 && Objects.equals(mSongArtist, rds.getSongArtist()) 96 && Objects.equals(mSongTitle, rds.getSongTitle()); 97 } 98 99 @Override hashCode()100 public int hashCode() { 101 return Objects.hash(mProgramService, mSongArtist, mSongTitle); 102 } 103 104 @Override describeContents()105 public int describeContents() { 106 return 0; 107 } 108 109 public static final Parcelable.Creator<RadioRds> CREATOR = new 110 Parcelable.Creator<RadioRds>() { 111 public RadioRds createFromParcel(Parcel in) { 112 return new RadioRds(in); 113 } 114 115 public RadioRds[] newArray(int size) { 116 return new RadioRds[size]; 117 } 118 }; 119 } 120