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
|
package org.cyanogenmod.theme.chooserv2;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.cyanogenmod.theme.chooser.R;
public class ComponentCardView extends LinearLayout {
public static final int CARD_FADE_DURATION = 300;
private TextView mLabel;
// Expanded Padding
int mExpandPadLeft;
int mExpandPadTop;
int mExpandPadRight;
int mExpandPadBottom;
public ComponentCardView(Context context) {
this(context, null);
}
public ComponentCardView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ComponentCardView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onFinishInflate() {
mLabel = (TextView) findViewById(R.id.label);
Resources r = getContext().getResources();
mExpandPadLeft =
(int) r.getDimension(R.dimen.card_padding_left_right) + getPaddingLeft();
mExpandPadTop =
(int) r.getDimension(R.dimen.card_padding_top) + getPaddingTop();
mExpandPadRight =
(int) r.getDimension(R.dimen.card_padding_left_right) + getPaddingRight();
mExpandPadBottom =
(int) r.getDimension(R.dimen.card_padding_bottom) + getPaddingBottom();
}
public void expand() {
TransitionDrawable bg = (TransitionDrawable) getBackground();
Rect paddingRect = new Rect();
bg.getPadding(paddingRect);
setPadding(mExpandPadLeft, mExpandPadTop, mExpandPadRight, mExpandPadBottom);
if (mLabel != null) {
mLabel.setVisibility(View.VISIBLE);
}
}
public void animateExpand() {
if (getBackground() instanceof TransitionDrawable) {
TransitionDrawable background = (TransitionDrawable) getBackground();
if (mLabel != null) {
mLabel.setVisibility(View.VISIBLE);
mLabel.animate().alpha(1f).setDuration(CARD_FADE_DURATION);
}
background.startTransition(CARD_FADE_DURATION);
}
}
public void collapse() {
if (mLabel != null) {
mLabel.setVisibility(View.GONE);
}
setPadding(0, 0, 0, 0);
}
public void animateFadeOut() {
if (mLabel != null) {
mLabel.animate().alpha(0f).setDuration(CARD_FADE_DURATION);
}
TransitionDrawable background = (TransitionDrawable) getBackground();
background.reverseTransition(CARD_FADE_DURATION);
}
}
|