forked from hitherejoe/Vineyard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadingCardView.java
79 lines (63 loc) · 2.78 KB
/
LoadingCardView.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
package com.hitherejoe.vineyard.ui.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v17.leanback.widget.BaseCardView;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import com.hitherejoe.vineyard.R;
public class LoadingCardView extends BaseCardView {
private ProgressBar mProgressBar;
public LoadingCardView(Context context, int styleResId) {
super(new ContextThemeWrapper(context, styleResId), null, 0);
buildLoadingCardView(styleResId);
}
public LoadingCardView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getStyledContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
buildLoadingCardView(getImageCardViewStyle(context, attrs, defStyleAttr));
}
@Override
public boolean hasOverlappingRendering() {
return false;
}
private void buildLoadingCardView(int styleResId) {
setFocusable(false);
setFocusableInTouchMode(false);
setCardType(CARD_TYPE_MAIN_ONLY);
setBackgroundResource(R.color.primary_light);
LayoutInflater inflater = LayoutInflater.from(getContext());
inflater.inflate(R.layout.view_loading_card, this);
TypedArray cardAttrs =
getContext().obtainStyledAttributes(
styleResId, android.support.v17.leanback.R.styleable.lbImageCardView);
mProgressBar = (ProgressBar) findViewById(R.id.progress_indicator);
cardAttrs.recycle();
}
public void isLoading(boolean isLoading) {
mProgressBar.setVisibility(isLoading ? View.VISIBLE : View.GONE);
}
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) {
int style = null == attrs ? 0 : attrs.getStyleAttribute();
if (0 == style) {
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 LoadingCardView(Context context) {
this(context, null);
}
public LoadingCardView(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v17.leanback.R.attr.imageCardViewStyle);
}
}