1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package com.example.android.leanback; 15 16 import android.annotation.SuppressLint; 17 import android.os.Parcel; 18 import android.os.Parcelable; 19 20 /** 21 * PhotoItem. 22 */ 23 @SuppressLint("BanParcelableUsage") 24 public final class PhotoItem implements Parcelable { 25 private int mId; 26 private String mTitle; 27 private String mContent; 28 private int mImageResourceId; 29 PhotoItem(String title, int imageResourceId)30 public PhotoItem(String title, int imageResourceId) { 31 this(title, null, imageResourceId); 32 } 33 PhotoItem(String title, int imageResourceId, int id)34 public PhotoItem(String title, int imageResourceId, int id) { 35 this(title, imageResourceId); 36 mId = id; 37 } 38 PhotoItem(String title, String content, int imageResourceId)39 public PhotoItem(String title, String content, int imageResourceId) { 40 mTitle = title; 41 mContent = content; 42 mImageResourceId = imageResourceId; 43 // the id was set to -1 if user don't provide this parameter 44 mId = -1; 45 } 46 PhotoItem(String title, String content, int imageResourceId, int id)47 public PhotoItem(String title, String content, int imageResourceId, int id) { 48 this(title, content, imageResourceId); 49 mId = id; 50 } 51 getImageResourceId()52 public int getImageResourceId() { 53 return mImageResourceId; 54 } 55 getTitle()56 public String getTitle() { 57 return mTitle; 58 } 59 getContent()60 public String getContent() { 61 return mContent; 62 } 63 64 @Override toString()65 public String toString() { 66 return mTitle; 67 } 68 69 @Override describeContents()70 public int describeContents() { 71 return 0; 72 } 73 74 @Override writeToParcel(Parcel dest, int flags)75 public void writeToParcel(Parcel dest, int flags) { 76 dest.writeString(mTitle); 77 dest.writeInt(mImageResourceId); 78 } 79 80 public static final Parcelable.Creator<PhotoItem> CREATOR 81 = new Parcelable.Creator<PhotoItem>() { 82 @Override 83 public PhotoItem createFromParcel(Parcel in) { 84 return new PhotoItem(in); 85 } 86 87 @Override 88 public PhotoItem[] newArray(int size) { 89 return new PhotoItem[size]; 90 } 91 }; 92 getId()93 public int getId() { 94 return this.mId; 95 } 96 PhotoItem(Parcel in)97 private PhotoItem(Parcel in) { 98 mTitle = in.readString(); 99 mImageResourceId = in.readInt(); 100 } 101 102 @Override equals(Object o)103 public boolean equals(Object o) { 104 if (this == o) return true; 105 if (!(o instanceof PhotoItem)) return false; 106 PhotoItem photoItem = (PhotoItem) o; 107 if (mId != photoItem.mId) return false; 108 if (mImageResourceId != photoItem.mImageResourceId) return false; 109 if (mTitle != null ? !mTitle.equals(photoItem.mTitle) : photoItem.mTitle != null) { 110 return false; 111 } 112 return mContent != null ? mContent.equals(photoItem.mContent) : photoItem.mContent == null; 113 } 114 115 @Override hashCode()116 public int hashCode() { 117 int result = mId; 118 result = 31 * result + (mTitle != null ? mTitle.hashCode() : 0); 119 result = 31 * result + (mContent != null ? mContent.hashCode() : 0); 120 result = 31 * result + mImageResourceId; 121 return result; 122 } 123 }