17f3028385b0349cfc6c0d6784840be148943b296Dake Gu/* 27f3028385b0349cfc6c0d6784840be148943b296Dake Gu * Copyright (C) 2014 The Android Open Source Project 37f3028385b0349cfc6c0d6784840be148943b296Dake Gu * 47f3028385b0349cfc6c0d6784840be148943b296Dake Gu * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 57f3028385b0349cfc6c0d6784840be148943b296Dake Gu * in compliance with the License. You may obtain a copy of the License at 67f3028385b0349cfc6c0d6784840be148943b296Dake Gu * 77f3028385b0349cfc6c0d6784840be148943b296Dake Gu * http://www.apache.org/licenses/LICENSE-2.0 87f3028385b0349cfc6c0d6784840be148943b296Dake Gu * 97f3028385b0349cfc6c0d6784840be148943b296Dake Gu * Unless required by applicable law or agreed to in writing, software distributed under the License 107f3028385b0349cfc6c0d6784840be148943b296Dake Gu * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 117f3028385b0349cfc6c0d6784840be148943b296Dake Gu * or implied. See the License for the specific language governing permissions and limitations under 127f3028385b0349cfc6c0d6784840be148943b296Dake Gu * the License. 137f3028385b0349cfc6c0d6784840be148943b296Dake Gu */ 147f3028385b0349cfc6c0d6784840be148943b296Dake Gupackage com.example.android.leanback; 157f3028385b0349cfc6c0d6784840be148943b296Dake Gu 167f3028385b0349cfc6c0d6784840be148943b296Dake Guimport android.os.Parcel; 177f3028385b0349cfc6c0d6784840be148943b296Dake Guimport android.os.Parcelable; 187f3028385b0349cfc6c0d6784840be148943b296Dake Gu 197f3028385b0349cfc6c0d6784840be148943b296Dake Gupublic class PhotoItem implements Parcelable { 2057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli private int mId; 217f3028385b0349cfc6c0d6784840be148943b296Dake Gu private String mTitle; 22f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn private String mContent; 237f3028385b0349cfc6c0d6784840be148943b296Dake Gu private int mImageResourceId; 247f3028385b0349cfc6c0d6784840be148943b296Dake Gu 257f3028385b0349cfc6c0d6784840be148943b296Dake Gu public PhotoItem(String title, int imageResourceId) { 26f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn this(title, null, imageResourceId); 27f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn } 28f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn 2957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli public PhotoItem(String title, int imageResourceId, int id) { 3057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli this(title, imageResourceId); 3157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli mId = id; 3257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli } 3357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli 34f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn public PhotoItem(String title, String content, int imageResourceId) { 357f3028385b0349cfc6c0d6784840be148943b296Dake Gu mTitle = title; 36f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn mContent = content; 377f3028385b0349cfc6c0d6784840be148943b296Dake Gu mImageResourceId = imageResourceId; 3857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli // the id was set to -1 if user don't provide this parameter 3957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli mId = -1; 4057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli } 4157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli 4257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli public PhotoItem(String title, String content, int imageResourceId, int id) { 4357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli this(title, content, imageResourceId); 4457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli mId = id; 457f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 467f3028385b0349cfc6c0d6784840be148943b296Dake Gu 477f3028385b0349cfc6c0d6784840be148943b296Dake Gu public int getImageResourceId() { 487f3028385b0349cfc6c0d6784840be148943b296Dake Gu return mImageResourceId; 497f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 507f3028385b0349cfc6c0d6784840be148943b296Dake Gu 517f3028385b0349cfc6c0d6784840be148943b296Dake Gu public String getTitle() { 527f3028385b0349cfc6c0d6784840be148943b296Dake Gu return mTitle; 537f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 547f3028385b0349cfc6c0d6784840be148943b296Dake Gu 55f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn public String getContent() { 56f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn return mContent; 57f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn } 58f1f489269da4b349125df56d54d3259929d48a7dTim Kilbourn 597f3028385b0349cfc6c0d6784840be148943b296Dake Gu @Override 607f3028385b0349cfc6c0d6784840be148943b296Dake Gu public String toString() { 617f3028385b0349cfc6c0d6784840be148943b296Dake Gu return mTitle; 627f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 637f3028385b0349cfc6c0d6784840be148943b296Dake Gu 647f3028385b0349cfc6c0d6784840be148943b296Dake Gu @Override 657f3028385b0349cfc6c0d6784840be148943b296Dake Gu public int describeContents() { 667f3028385b0349cfc6c0d6784840be148943b296Dake Gu return 0; 677f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 687f3028385b0349cfc6c0d6784840be148943b296Dake Gu 697f3028385b0349cfc6c0d6784840be148943b296Dake Gu @Override 707f3028385b0349cfc6c0d6784840be148943b296Dake Gu public void writeToParcel(Parcel dest, int flags) { 717f3028385b0349cfc6c0d6784840be148943b296Dake Gu dest.writeString(mTitle); 727f3028385b0349cfc6c0d6784840be148943b296Dake Gu dest.writeInt(mImageResourceId); 737f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 747f3028385b0349cfc6c0d6784840be148943b296Dake Gu 757f3028385b0349cfc6c0d6784840be148943b296Dake Gu public static final Parcelable.Creator<PhotoItem> CREATOR 767f3028385b0349cfc6c0d6784840be148943b296Dake Gu = new Parcelable.Creator<PhotoItem>() { 777f3028385b0349cfc6c0d6784840be148943b296Dake Gu @Override 787f3028385b0349cfc6c0d6784840be148943b296Dake Gu public PhotoItem createFromParcel(Parcel in) { 797f3028385b0349cfc6c0d6784840be148943b296Dake Gu return new PhotoItem(in); 807f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 817f3028385b0349cfc6c0d6784840be148943b296Dake Gu 827f3028385b0349cfc6c0d6784840be148943b296Dake Gu @Override 837f3028385b0349cfc6c0d6784840be148943b296Dake Gu public PhotoItem[] newArray(int size) { 847f3028385b0349cfc6c0d6784840be148943b296Dake Gu return new PhotoItem[size]; 857f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 867f3028385b0349cfc6c0d6784840be148943b296Dake Gu }; 877f3028385b0349cfc6c0d6784840be148943b296Dake Gu 8857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli public int getId() { 8957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli return this.mId; 9057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli } 9157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli 927f3028385b0349cfc6c0d6784840be148943b296Dake Gu private PhotoItem(Parcel in) { 937f3028385b0349cfc6c0d6784840be148943b296Dake Gu mTitle = in.readString(); 947f3028385b0349cfc6c0d6784840be148943b296Dake Gu mImageResourceId = in.readInt(); 957f3028385b0349cfc6c0d6784840be148943b296Dake Gu } 9657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli 9757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli @Override 9857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli public boolean equals(Object o) { 9957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli if (this == o) return true; 10057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli if (o == null || getClass() != o.getClass()) return false; 10157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli PhotoItem photoItem = (PhotoItem) o; 10257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli if (mId != photoItem.mId) return false; 10357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli if (mImageResourceId != photoItem.mImageResourceId) return false; 10457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli if (mTitle != null ? !mTitle.equals(photoItem.mTitle) : photoItem.mTitle != null) { 10557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli return false; 10657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli } 10757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli return mContent != null ? mContent.equals(photoItem.mContent) : photoItem.mContent == null; 10857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli } 10957ac90cf3fc528ac56b6b83718541624173b1368jingjiangli 11057ac90cf3fc528ac56b6b83718541624173b1368jingjiangli @Override 11157ac90cf3fc528ac56b6b83718541624173b1368jingjiangli public int hashCode() { 11257ac90cf3fc528ac56b6b83718541624173b1368jingjiangli int result = mId; 11357ac90cf3fc528ac56b6b83718541624173b1368jingjiangli result = 31 * result + (mTitle != null ? mTitle.hashCode() : 0); 11457ac90cf3fc528ac56b6b83718541624173b1368jingjiangli result = 31 * result + (mContent != null ? mContent.hashCode() : 0); 11557ac90cf3fc528ac56b6b83718541624173b1368jingjiangli result = 31 * result + mImageResourceId; 11657ac90cf3fc528ac56b6b83718541624173b1368jingjiangli return result; 11757ac90cf3fc528ac56b6b83718541624173b1368jingjiangli } 11857ac90cf3fc528ac56b6b83718541624173b1368jingjiangli}