• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.music.utils;
18 
19 import android.media.MediaMetadata;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.text.TextUtils;
23 
24 /**
25  * Holder class that encapsulates a MediaMetadata and allows the actual metadata to be modified
26  * without requiring to rebuild the collections the metadata is in.
27  */
28 public class Song implements Parcelable {
29     private MediaMetadata mMetadata;
30     private long mSongId;
31     private long mSortKey;
32 
Song(long songId, MediaMetadata metadata, Long sortKey)33     public Song(long songId, MediaMetadata metadata, Long sortKey) {
34         mMetadata = metadata;
35         mSongId = songId;
36         if (sortKey != null) {
37             mSortKey = sortKey;
38         }
39     }
40 
getSongId()41     public long getSongId() {
42         return mSongId;
43     }
getSortKey()44     public long getSortKey() {
45         return mSortKey;
46     }
setSortKey(long sortKey)47     public void setSortKey(long sortKey) {
48         mSortKey = sortKey;
49     }
50 
getMetadata()51     public MediaMetadata getMetadata() {
52         return mMetadata;
53     }
setMetadata(MediaMetadata metadata)54     public void setMetadata(MediaMetadata metadata) {
55         mMetadata = metadata;
56     }
57 
58     @Override
equals(Object o)59     public boolean equals(Object o) {
60         if (this == o) {
61             return true;
62         }
63         if (o == null || o.getClass() != Song.class) {
64             return false;
65         }
66 
67         Song that = (Song) o;
68 
69         return mSongId == that.getSongId();
70     }
71 
72     @Override
hashCode()73     public int hashCode() {
74         return Long.hashCode(mSongId);
75     }
76 
77     @Override
describeContents()78     public int describeContents() {
79         return 0;
80     }
81 
82     @Override
writeToParcel(Parcel out, int flags)83     public void writeToParcel(Parcel out, int flags) {
84         out.writeLong(mSortKey);
85         out.writeLong(mSongId);
86         out.writeParcelable(mMetadata, flags);
87     }
88 
89     public static final Parcelable.Creator<Song> CREATOR = new Parcelable.Creator<Song>() {
90         public Song createFromParcel(Parcel in) {
91             MediaMetadata metadata = in.readParcelable(null);
92             long songId = in.readLong();
93             long sortKey = in.readLong();
94             return new Song(songId, metadata, sortKey);
95         }
96 
97         public Song[] newArray(int size) {
98             return new Song[size];
99         }
100     };
101 }
102