forked from hitherejoe/Vineyard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagCardView.java
93 lines (75 loc) · 3.16 KB
/
TagCardView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.hitherejoe.vineyard.ui.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v17.leanback.widget.BaseCardView;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.hitherejoe.vineyard.R;
import butterknife.Bind;
import butterknife.ButterKnife;
public class TagCardView extends BaseCardView {
@Bind(R.id.text_tag_name)
TextView mTagNameText;
@Bind(R.id.image_icon)
ImageView mResultImage;
public TagCardView(Context context, int styleResId) {
super(new ContextThemeWrapper(context, styleResId), null, 0);
buildLoadingCardView(styleResId);
}
public TagCardView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getStyledContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
buildLoadingCardView(getImageCardViewStyle(context, attrs, defStyleAttr));
}
private void buildLoadingCardView(int styleResId) {
setFocusable(false);
setFocusableInTouchMode(false);
setCardType(CARD_TYPE_MAIN_ONLY);
setBackgroundResource(R.color.primary_light);
LayoutInflater inflater = LayoutInflater.from(getContext());
View view = inflater.inflate(R.layout.view_tag_card, this);
ButterKnife.bind(view);
TypedArray cardAttrs =
getContext().obtainStyledAttributes(
styleResId, android.support.v17.leanback.R.styleable.lbImageCardView);
cardAttrs.recycle();
}
public void setCardText(String string) {
mTagNameText.setText(string);
}
public void setCardIcon(int resource) {
mResultImage.setImageDrawable(ContextCompat.getDrawable(getContext(), resource));
}
private static Context getStyledContext(Context context, AttributeSet attrs, int defStyleAttr) {
int style = getImageCardViewStyle(context, attrs, defStyleAttr);
return new ContextThemeWrapper(context, style);
}
private static int getImageCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
// Read style attribute defined in XML layout.
int style = null == attrs ? 0 : attrs.getStyleAttribute();
if (0 == style) {
// Not found? Read global ImageCardView style from Theme attribute.
TypedArray styledAttrs =
context.obtainStyledAttributes(
android.support.v17.leanback.R.styleable.LeanbackTheme);
style = styledAttrs.getResourceId(
android.support.v17.leanback.R.styleable.LeanbackTheme_imageCardViewStyle, 0);
styledAttrs.recycle();
}
return style;
}
public TagCardView(Context context) {
this(context, null);
}
public TagCardView(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v17.leanback.R.attr.imageCardViewStyle);
}
@Override
public boolean hasOverlappingRendering() {
return false;
}
}