-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathElasticDownloadView.java
More file actions
139 lines (111 loc) · 4.16 KB
/
ElasticDownloadView.java
File metadata and controls
139 lines (111 loc) · 4.16 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package is.arontibo.library;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
/**
* Created by thibaultguegan on 15/03/15.
*/
public class ElasticDownloadView extends FrameLayout implements IntroView.EnterAnimationListener {
private static final String LOG_TAG = ElasticDownloadView.class.getSimpleName();
private IntroView mIntroView;
private ProgressDownloadView mProgressDownloadView;
private int mBackgroundColor;
/**
* MARK: Constructor
*/
public ElasticDownloadView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ColorOptionsView, 0, 0);
mBackgroundColor = a.getColor(R.styleable.ColorOptionsView_backgroundColor,
getResources().getColor(R.color.orange_salmon));
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.view_elasticdownload, this, true);
}
/**
* MARK: Overrides
*/
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mIntroView = (IntroView) findViewById(R.id.intro_view);
mIntroView.setListener(this);
mProgressDownloadView = (ProgressDownloadView) findViewById(R.id.progress_download_view);
ViewTreeObserver vto = mProgressDownloadView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mProgressDownloadView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mProgressDownloadView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
mIntroView.getLayoutParams().width = mProgressDownloadView.getWidth();
mIntroView.getLayoutParams().height = mProgressDownloadView.getHeight();
mProgressDownloadView.setBackgroundColor(mBackgroundColor);
}
});
}
@Override
public void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state);
mIntroView.init();
mIntroView.setVisibility(VISIBLE);
}
/**
* MARK: Public methods
*/
public void startIntro() {
mIntroView.startAnimation();
}
public void setProgress(float progress) {
mProgressDownloadView.setPercentage(progress);
}
public void success() {
mProgressDownloadView.drawSuccess();
}
public void fail() {
mProgressDownloadView.drawFail();
}
/**
* MARK: Enter animation overrides
*/
@Override
public void onEnterAnimationFinished() {
mIntroView.setVisibility(INVISIBLE);
mProgressDownloadView.setVisibility(VISIBLE);
mProgressDownloadView.setProgress(mProgressDownloadView.getProgress());
// Do further actions if necessary
}
/**
* Set the background color of the Elastic Download View
* @param passedColor int Color Color to set the background
*/
public void setBackgroundColor(int passedColor) {
this.mBackgroundColor = passedColor;
this.mProgressDownloadView.setBackgroundColor(mBackgroundColor);
}
/**
* Overloaded method, takes in a String color to parse
* @param passedColor String of a color hex color (IE: #fd5c79) that can be parsed by
* Color.parseColor(string)
*/
public void setBackgroundColor(String passedColor) {
if (passedColor == null){
return;
}
try {
int color = Color.parseColor(passedColor);
this.setBackgroundColor(color);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}