Card.java revision ad31f63f5843898de645f6ee1ac244c872ded8cc
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
15package android.support.v17.leanback.supportleanbackshowcase.models;
16
17import android.content.Context;
18import android.graphics.Color;
19import android.util.Log;
20
21import com.google.gson.annotations.SerializedName;
22
23import java.net.URI;
24import java.net.URISyntaxException;
25
26/**
27 * This is a generic example of a custom data object, containing info we might want to keep with
28 * each card on the home screen
29 */
30public class Card {
31
32    @SerializedName("title") private String mTitle = "";
33    @SerializedName("description") private String mDescription = "";
34    @SerializedName("extraText") private String mExtraText = "";
35    @SerializedName("imageUrl") private String mImageUrl;
36    @SerializedName("footerColor") private String mFooterColor = null;
37    @SerializedName("selectedColor") private String mSelectedColor = null;
38    @SerializedName("localImageResource") private String mLocalImageResource = null;
39    @SerializedName("footerIconLocalImageResource") private String mFooterResource = null;
40    @SerializedName("type") private Card.Type mType;
41    @SerializedName("id") private int mId;
42    @SerializedName("width") private int mWidth;
43    @SerializedName("height") private int mHeight;
44
45    public String getTitle() {
46        return mTitle;
47    }
48
49    public int getWidth() {
50        return mWidth;
51    }
52
53    public int getHeight() {
54        return mHeight;
55    }
56
57    public int getId() {
58        return mId;
59    }
60
61    public Card.Type getType() {
62        return mType;
63    }
64
65    public String getDescription() {
66        return mDescription;
67    }
68
69    public String getExtraText() {
70        return mExtraText;
71    }
72
73    public int getFooterColor() {
74        if (mFooterColor == null) return -1;
75        return Color.parseColor(mFooterColor);
76    }
77
78    public int getSelectedColor() {
79        if (mSelectedColor == null) return -1;
80        return Color.parseColor(mSelectedColor);
81    }
82
83    public String getImageUrl() {
84        return mImageUrl;
85    }
86
87    public URI getImageURI() {
88        if (getImageUrl() == null) return null;
89        try {
90            return new URI(getImageUrl());
91        } catch (URISyntaxException e) {
92            Log.d("URI exception: ", getImageUrl());
93            return null;
94        }
95    }
96
97    public int getLocalImageResourceId(Context context) {
98        return context.getResources().getIdentifier(getLocalImageResourceName(), "drawable",
99                                                    context.getPackageName());
100    }
101
102    public String getLocalImageResourceName() {
103        return mLocalImageResource;
104    }
105
106    public String getFooterLocalImageResourceName() {
107        return mFooterResource;
108    }
109
110    public enum Type {
111
112        MOVIE_COMPLETE,
113        MOVIE,
114        MOVIE_BASE,
115        ICON,
116        SQUARE_BIG,
117        SINGLE_LINE,
118        GAME,
119        SQUARE_SMALL,
120        DEFAULT,
121        SIDE_INFO,
122        SIDE_INFO_TEST_1,
123        TEXT,
124        CHARACTER,
125        GRID_SQUARE
126
127    }
128
129}
130