-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathMasterLayout.java
More file actions
438 lines (324 loc) · 12 KB
/
MasterLayout.java
File metadata and controls
438 lines (324 loc) · 12 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
package com.thbs.progressbutton;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class MasterLayout extends FrameLayout implements OnClickListener {
public CusImage cusview;
public int pix = 0;
public RectF rect;
private ImageView buttonimage, fillcircle, full_circle_image, arc_image;
private Path stop, tick, play, download_triangle, download_rectangle;
private Bitmap third_icon_bmp, second_icon_bmp, first_icon_bmp;
private Paint stroke_color, fill_color, icon_color, final_icon_color;
private AnimationSet in, out;
private RotateAnimation arcRotation;
private ScaleAnimation new_scale_in, scale_in, scale_out;
private AlphaAnimation fade_in, fade_out;
int flg_frmwrk_mode = 0;
boolean first_click = false;
public MasterLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
setOnClickListener(this);
initialise();
setpaint();
setAnimation();
displayMetrics();
iconCreate();
init();
}
public MasterLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
setOnClickListener(this);
setBackgroundColor(Color.CYAN);
initialise();
setpaint();
setAnimation();
displayMetrics();
iconCreate();
init();
}
private void initialise() {
cusview = new CusImage(getContext(), this);
buttonimage = new ImageView(getContext());
full_circle_image = new ImageView(getContext());
arc_image = new ImageView(getContext());
fillcircle = new ImageView(getContext());
cusview.setClickable(false);
buttonimage.setClickable(false);
full_circle_image.setClickable(false);
arc_image.setClickable(false);
cusview.setClickable(false);
setClickable(true);
fillcircle.setClickable(false);
}
private void setpaint() {
// Setting up color
stroke_color = new Paint(Paint.ANTI_ALIAS_FLAG);
stroke_color.setAntiAlias(true);
stroke_color.setColor(Color.rgb(0, 161, 234)); // Edit this to change
// the circle color
stroke_color.setStrokeWidth(3);
stroke_color.setStyle(Paint.Style.STROKE);
icon_color = new Paint(Paint.ANTI_ALIAS_FLAG);
icon_color.setColor(Color.rgb(0, 161, 234));
icon_color.setStyle(Paint.Style.FILL_AND_STROKE); // Edit this to change
// the icon color
icon_color.setAntiAlias(true);
final_icon_color = new Paint(Paint.ANTI_ALIAS_FLAG);
final_icon_color.setColor(Color.WHITE); // Edit this to change the final
// icon color
final_icon_color.setStrokeWidth(12);
final_icon_color.setStyle(Paint.Style.STROKE);
final_icon_color.setAntiAlias(true);
fill_color = new Paint(Paint.ANTI_ALIAS_FLAG);
fill_color.setColor(Color.rgb(0, 161, 234)); // Edit this to change the
// circle fill color
fill_color.setStyle(Paint.Style.FILL_AND_STROKE);
fill_color.setAntiAlias(true);
}
private void setAnimation() {
// Setting up and defining view animations.
arcRotation = new RotateAnimation(0.0f, 360.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
arcRotation.setDuration(1000);
in = new AnimationSet(true);
out = new AnimationSet(true);
out.setInterpolator(new AccelerateDecelerateInterpolator());
in.setInterpolator(new AccelerateDecelerateInterpolator());
scale_in = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
scale_out = new ScaleAnimation(1.0f, 3.0f, 1.0f, 3.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
new_scale_in = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
new_scale_in.setDuration(200);
fade_in = new AlphaAnimation(0.0f, 1.0f);
fade_out = new AlphaAnimation(1.0f, 0.0f);
scale_in.setDuration(150);
scale_out.setDuration(150);
fade_in.setDuration(150);
fade_out.setDuration(150);
in.addAnimation(scale_in);
in.addAnimation(fade_in);
out.addAnimation(fade_out);
out.addAnimation(scale_out);
arcRotation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
first_click = false;
buttonimage.startAnimation(out);
}
});
out.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
System.out.println("print this");
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
buttonimage.setVisibility(View.GONE);
buttonimage.setImageBitmap(second_icon_bmp);
buttonimage.setVisibility(View.VISIBLE);
buttonimage.startAnimation(in);
arc_image.setVisibility(View.GONE);
full_circle_image.setVisibility(View.VISIBLE);
cusview.setVisibility(View.VISIBLE);
flg_frmwrk_mode = 2;
System.out.println("flg_frmwrk_mode" + flg_frmwrk_mode);
}
});
new_scale_in.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
cusview.setVisibility(View.GONE);
buttonimage.setVisibility(View.VISIBLE);
buttonimage.setImageBitmap(third_icon_bmp);
flg_frmwrk_mode = 3;
buttonimage.startAnimation(in);
}
});
}
private void displayMetrics() {
// Responsible for calculating the size of views and canvas based upon
// screen resolution.
DisplayMetrics metrics = getContext().getResources()
.getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
float scarea = width * height;
pix = (int) Math.sqrt(scarea * 0.0217);
}
private void iconCreate() {
// Creating icons using path
// Create your own icons or feel free to use these
play = new Path();
play.moveTo(pix * 40 / 100, pix * 36 / 100);
play.lineTo(pix * 40 / 100, pix * 63 / 100);
play.lineTo(pix * 69 / 100, pix * 50 / 100);
play.close();
stop = new Path();
stop.moveTo(pix * 38 / 100, pix * 38 / 100);
stop.lineTo(pix * 62 / 100, pix * 38 / 100);
stop.lineTo(pix * 62 / 100, pix * 62 / 100);
stop.lineTo(pix * 38 / 100, pix * 62 / 100);
stop.close();
download_triangle = new Path();
download_triangle.moveTo(pix * 375 / 1000, (pix / 2)
+ (pix * 625 / 10000) - (pix * 3 / 100));
download_triangle.lineTo(pix / 2, (pix * 625 / 1000)
+ (pix * 625 / 10000) - (pix * 3 / 100));
download_triangle.lineTo(pix * 625 / 1000, (pix / 2)
+ (pix * 625 / 10000) - (pix * 3 / 100));
download_triangle.close();
download_rectangle = new Path();
download_rectangle.moveTo(pix * 4375 / 10000, (pix / 2)
+ (pix * 625 / 10000) - (pix * 3 / 100));
download_rectangle.lineTo(pix * 5625 / 10000, (pix / 2)
+ (pix * 625 / 10000) - (pix * 3 / 100));
download_rectangle.lineTo(pix * 5625 / 10000, (pix * 375 / 1000)
+ (pix * 625 / 10000) - (pix * 3 / 100));
download_rectangle.lineTo(pix * 4375 / 10000, (pix * 375 / 1000)
+ (pix * 625 / 10000) - (pix * 3 / 100));
download_rectangle.close();
tick = new Path();
tick.moveTo(pix * 30 / 100, pix * 50 / 100);
tick.lineTo(pix * 45 / 100, pix * 625 / 1000);
tick.lineTo(pix * 65 / 100, pix * 350 / 1000);
}
public void init() {
// Defining and drawing bitmaps and assigning views to the layout
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 10, 10, 10);
fillcircle.setVisibility(View.GONE);
Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap full_circle_bmp = Bitmap.createBitmap(pix, pix, conf);
Bitmap arc_bmp = Bitmap.createBitmap(pix, pix, conf);
Bitmap fill_circle_bmp = Bitmap.createBitmap(pix, pix, conf);
first_icon_bmp = Bitmap.createBitmap(pix, pix, conf); // Bitmap to draw
// first icon(
// Default -
// Play )
second_icon_bmp = Bitmap.createBitmap(pix, pix, conf); // Bitmap to draw
// second icon(
// Default -
// Stop )
third_icon_bmp = Bitmap.createBitmap(pix, pix, conf); // Bitmap to draw
// third icon(
// Default -
// Tick )
Canvas first_icon_canvas = new Canvas(first_icon_bmp);
Canvas second_icon_canvas = new Canvas(second_icon_bmp);
Canvas third_icon_canvas = new Canvas(third_icon_bmp);
Canvas fill_circle_canvas = new Canvas(fill_circle_bmp);
Canvas full_circle_canvas = new Canvas(full_circle_bmp);
Canvas arc_canvas = new Canvas(arc_bmp);
float startx = (float) (pix * 0.05);
float endx = (float) (pix * 0.95);
System.out.println("full circle " + full_circle_canvas.getWidth()
+ full_circle_canvas.getHeight());
float starty = (float) (pix * 0.05);
float endy = (float) (pix * 0.95);
rect = new RectF(startx, starty, endx, endy);
first_icon_canvas.drawPath(play, fill_color); // Draw second icon on canvas( Default - Stop ).
// *****Set your second icon here****
second_icon_canvas.drawPath(stop, icon_color); // Draw second icon on canvas( Default - Stop ).
// *****Set your second icon here****
third_icon_canvas.drawPath(tick, final_icon_color); // Draw second icon on canvas( Default - Stop ).
// *****Set your second icon here****
full_circle_canvas.drawArc(rect, 0, 360, false, stroke_color);
fill_circle_canvas.drawArc(rect, 0, 360, false, fill_color);
arc_canvas.drawArc(rect, -80, 340, false, stroke_color);
buttonimage.setImageBitmap(first_icon_bmp);
flg_frmwrk_mode = 1;
fillcircle.setImageBitmap(fill_circle_bmp);
full_circle_image.setImageBitmap(full_circle_bmp);
arc_image.setImageBitmap(arc_bmp);
cusview.setVisibility(View.GONE);
addView(full_circle_image, lp);
addView(arc_image, lp);
addView(fillcircle, lp);
addView(buttonimage, lp);
addView(cusview, lp);
}
public void animation() {
// Starting view animation and setting flag values
if (first_click == false) {
if (flg_frmwrk_mode == 1) {
first_click = true;
full_circle_image.setVisibility(View.GONE);
arc_image.setVisibility(View.VISIBLE);
arc_image.startAnimation(arcRotation);
}
}
}
public void finalAnimation() {
// Responsible for final fill up animation
buttonimage.setVisibility(View.GONE);
fillcircle.setVisibility(View.VISIBLE);
fillcircle.startAnimation(new_scale_in);
}
public void reset() {
// Responsible for resetting the state of view when Stop is clicked
cusview.reset();
cusview.setVisibility(View.GONE);
fillcircle.setVisibility(View.GONE);
buttonimage.setVisibility(View.VISIBLE);
buttonimage.setImageBitmap(first_icon_bmp);
flg_frmwrk_mode = 1;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animation();
System.out.println("Action onclick...");
}
}