ImageCardView.java revision b55f0880c367c0b7e4132e7d954b60725e01e0b2
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 */
14package android.support.v17.leanback.widget;
15
16import android.content.Context;
17import android.graphics.drawable.Drawable;
18import android.support.v17.leanback.R;
19import android.util.AttributeSet;
20import android.util.Log;
21import android.view.LayoutInflater;
22import android.view.View;
23import android.widget.ImageView;
24import android.widget.TextView;
25
26public class ImageCardView extends BaseCardView {
27    private static final String TAG = "ImageCardView";
28    private static final boolean DEBUG = false;
29
30    private ImageView mImageView;
31    private View mInfoArea;
32    private TextView mTitleView;
33    private TextView mContentView;
34    private ImageView mBadgeImage;
35    private ImageView mBadgeFadeMask;
36
37    public ImageCardView(Context context) {
38        this(context, null);
39    }
40
41    public ImageCardView(Context context, AttributeSet attrs) {
42        this(context, attrs, R.attr.imageCardViewStyle);
43    }
44
45    public ImageCardView(Context context, AttributeSet attrs, int defStyle) {
46        super(context, attrs, defStyle);
47
48        LayoutInflater inflater = LayoutInflater.from(context);
49        View v = inflater.inflate(R.layout.lb_image_card_view, this);
50
51        mImageView = (ImageView) v.findViewById(R.id.main_image);
52        mInfoArea = v.findViewById(R.id.info_field);
53        mTitleView = (TextView) v.findViewById(R.id.title_text);
54        mContentView = (TextView) v.findViewById(R.id.content_text);
55        mBadgeImage = (ImageView) v.findViewById(R.id.extra_badge);
56        mBadgeFadeMask = (ImageView) v.findViewById(R.id.fade_mask);
57    }
58
59    public void setMainImage(Drawable drawable) {
60        if (mImageView == null) {
61            return;
62        }
63
64        mImageView.setImageDrawable(drawable);
65    }
66
67    public Drawable getMainImage() {
68        if (mImageView == null) {
69            return null;
70        }
71
72        return mImageView.getDrawable();
73    }
74
75    public void setTitleText(CharSequence text) {
76        if (mTitleView == null) {
77            return;
78        }
79
80        mTitleView.setText(text);
81    }
82
83    public CharSequence getTitleText() {
84        if (mTitleView == null) {
85            return null;
86        }
87
88        return mTitleView.getText();
89    }
90
91    public void setContentText(CharSequence text) {
92        if (mContentView == null) {
93            return;
94        }
95
96        mContentView.setText(text);
97    }
98
99    public CharSequence getContentText() {
100        if (mContentView == null) {
101            return null;
102        }
103
104        return mContentView.getText();
105    }
106
107    public void setBadgeImage(Drawable drawable) {
108        if (mBadgeImage == null) {
109            return;
110        }
111
112        if (drawable != null) {
113            mBadgeImage.setImageDrawable(drawable);
114            mBadgeImage.setVisibility(View.VISIBLE);
115            mBadgeFadeMask.setVisibility(View.VISIBLE);
116        } else {
117            mBadgeImage.setVisibility(View.GONE);
118            mBadgeFadeMask.setVisibility(View.GONE);
119        }
120    }
121
122    public Drawable getBadgeImage() {
123        if (mBadgeImage == null) {
124            return null;
125        }
126
127        return mBadgeImage.getDrawable();
128    }
129}
130