-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorPickerDialogBuilder.java
More file actions
635 lines (520 loc) · 23 KB
/
ColorPickerDialogBuilder.java
File metadata and controls
635 lines (520 loc) · 23 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
package com.realdev.betrage.ColorPickerDialog;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.realdev.betrage.R;
public class ColorPickerDialogBuilder extends AlertDialog.Builder {
public CustomHSVSeekBar alphaHSV,
hue,
brightness,
saturation;
public CustomRGBSeekBar alphaRGB,red,green,blue;
public LinearLayout layout,view;
public View previewRGB,previewHSV;
public Custom2DSeekBar satAndBright;
public EditText hexHSV,
hexRGB;
public CustomRGBEditText alphaBox,
greenBox,
blueBox,
redBox;
public Button rgbBtn,hsvBtn;
int aHSV=255,aRGB,dp10,r,g,b,argb;
float[] hsv=new float[]{0,1,1};
Context contxt;
public ColorPickerDialogBuilder(Context context) {
super(context);
contxt=context;
dp10=(int)TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
10,
contxt.getResources().getDisplayMetrics());
argb=Color.WHITE;
layout=generateMainLayout();
setView(layout);
LinearLayout rgbLayout=getRGBLayout();
LinearLayout hsvLayout=getHSVLayout();
view.addView(hsvLayout);
rgbBtn.setEnabled(true);
hsvBtn.setEnabled(false);
hsvBtn.setOnClickListener(view1 -> {
view.removeAllViews();
view.addView(hsvLayout);
rgbBtn.setEnabled(true);
hsvBtn.setEnabled(false);
});
rgbBtn.setOnClickListener(view1 -> {
view.removeAllViews();
view.addView(rgbLayout);
rgbBtn.setEnabled(false);
hsvBtn.setEnabled(true);
});
setTitle("Choose a color");
}
public LinearLayout generateMainLayout(){
LinearLayout layout=new LinearLayout(contxt);
layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout tabs=new LinearLayout(contxt);
tabs.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,1));
tabs.setOrientation(LinearLayout.HORIZONTAL);
rgbBtn=new Button(contxt);
hsvBtn=new Button(contxt);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,1);
rgbBtn.setLayoutParams(params);
hsvBtn.setLayoutParams(params);
rgbBtn.setText(R.string.rgb_upper);
hsvBtn.setText(R.string.hsv_upper);
tabs.addView(rgbBtn);
tabs.addView(hsvBtn);
layout.addView(tabs);
view=new LinearLayout(contxt);
view.setOrientation(LinearLayout.VERTICAL);
view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
layout.addView(view);
return layout;
}
public LinearLayout getHSVLayout(){
LinearLayout hsvLayout=new LinearLayout(contxt);
hsvLayout.setOrientation(LinearLayout.VERTICAL);
hsvLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
hue=new CustomHSVSeekBar(contxt,360);
brightness=new CustomHSVSeekBar(contxt,100);
saturation=new CustomHSVSeekBar(contxt,100);
alphaHSV=new CustomHSVSeekBar(contxt,255);
LinearLayout container =new LinearLayout(contxt);
container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,0f));
container.setOrientation(LinearLayout.HORIZONTAL);
hexHSV=new EditText(contxt);
hexHSV.setEms(10);
hexHSV.setText(R.string.color_red_hex);
hexHSV.setImeOptions(EditorInfo.IME_ACTION_DONE);
hexHSV.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
hexHSV.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
previewHSV=new View(contxt);
previewHSV.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,dp10*5));
satAndBright=new Custom2DSeekBar(contxt,Color.RED,dp10*20);
satAndBright.setBackground(Color.RED);
container.addView(hexHSV);
container.addView(previewHSV);
hsvLayout.addView(satAndBright);
hsvLayout.addView(hue);
hsvLayout.addView(brightness);
hsvLayout.addView(saturation);
hsvLayout.addView(alphaHSV);
hsvLayout.addView(container);
alphaHSV.setProgress(255);
brightness.setProgress(100);
saturation.setProgress(100);
update();
hue.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[]{
Color.RED,Color.GREEN,Color.BLUE,Color.RED
}));
alphaHSV.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[]{
Color.TRANSPARENT,Color.RED
}));
brightness.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[]{
Color.BLACK,Color.RED
}));
saturation.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[]{
Color.WHITE,Color.RED
}));
hexHSV.setOnFocusChangeListener((view1, b) -> hexFun(((EditText)view1).getText().toString()));
hexHSV.setOnEditorActionListener((textView, i, keyEvent) -> hexFun(textView.getText().toString()));
hue.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
hsv[0]=i;
update();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
alphaHSV.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
aHSV=i;
update();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
hsv[2]=i/100f;
satAndBright.setCords(satAndBright.x,(1-hsv[2])*satAndBright.height);
update();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
saturation.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
hsv[1]=i/100f;
satAndBright.setCords(hsv[1]*satAndBright.width,satAndBright.y);
update();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
satAndBright.setCordsChangedListener((x, y) -> {
hsv[1]=x/satAndBright.width;
hsv[2]=1-y/satAndBright.height;
update();
});
return hsvLayout;
}
public LinearLayout getRGBLayout(){
LinearLayout rgbLayout=new LinearLayout(contxt);
rgbLayout.setOrientation(LinearLayout.VERTICAL);
rgbLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
previewRGB=new View(contxt);
previewRGB.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,dp10*10));
rgbLayout.addView(previewRGB);
red=new CustomRGBSeekBar(contxt);
blue=new CustomRGBSeekBar(contxt);
green=new CustomRGBSeekBar(contxt);
alphaRGB=new CustomRGBSeekBar(contxt);
redBox=new CustomRGBEditText(contxt);
greenBox=new CustomRGBEditText(contxt);
blueBox=new CustomRGBEditText(contxt);
alphaBox=new CustomRGBEditText(contxt);
rgbLayout.addView(new CustomRGBContainer(contxt,"Red : ",red,redBox));
rgbLayout.addView(new CustomRGBContainer(contxt,"Green : ",green,greenBox));
rgbLayout.addView(new CustomRGBContainer(contxt,"Blue : ",blue,blueBox));
rgbLayout.addView(new CustomRGBContainer(contxt,"Alpha : ",alphaRGB,alphaBox));
hexRGB=new EditText(contxt);
hexRGB.setText(R.string.color_white_hex);
hexRGB.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
hexRGB.setEms(10);
hexRGB.setHint("Hex value of color");
hexRGB.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PERSON_NAME);
hexRGB.setPadding(dp10,0,dp10,0);
rgbLayout.addView(hexRGB);
setArgb(argb);
alphaRGB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean bo) {
setArgb(Color.argb(i,r,g,b));
alphaBox.setText(String.valueOf(i));
hexRGB.setText(getColorHex(argb));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
red.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean bo) {
setArgb(Color.argb(aRGB,i,g,b));
redBox.setText(String.valueOf(i));
hexRGB.setText(getColorHex(argb));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
green.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean bo) {
setArgb(Color.argb(aRGB,r,i,b));
greenBox.setText(String.valueOf(i));
hexRGB.setText(getColorHex(argb));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
blue.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean bo) {
setArgb(Color.argb(aRGB,r,g,i));
blueBox.setText(String.valueOf(i));
hexRGB.setText(getColorHex(argb));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
alphaBox.setOnEditorActionListener((textView, i, keyEvent) -> boxFun(textView.getText().toString(),0));
redBox.setOnEditorActionListener((textView, i, keyEvent) -> boxFun(textView.getText().toString(),1));
greenBox.setOnEditorActionListener((textView, i, keyEvent) -> boxFun(textView.getText().toString(),2));
blueBox.setOnEditorActionListener((textView, i, keyEvent) -> boxFun(textView.getText().toString(),3));
alphaBox.setOnFocusChangeListener((view, b) -> {
if(!b){
boxFun(((EditText)view).getText().toString(),0);
}
});
redBox.setOnFocusChangeListener((view, b) -> {
if(!b){
boxFun(((EditText)view).getText().toString(),1);
}
});
greenBox.setOnFocusChangeListener((view, b) -> {
if(!b){
boxFun(((EditText)view).getText().toString(),2);
}
});
blueBox.setOnFocusChangeListener((view, b) -> {
if(!b){
boxFun(((EditText)view).getText().toString(),3);
}
});
hexRGB.setOnEditorActionListener((textView, i, keyEvent) -> {
if(i== EditorInfo.IME_ACTION_DONE){
try{
String hexa=textView.getText().toString().toUpperCase().replace("#","");
hexa="#"+((hexa.length()==6)?"FF":"")+hexa;
int color=Color.parseColor(hexa);
int i1=0xFF & (color>>24),
i2=0xFF & (color>>16),
i3=0xFF & (color>>8),
i4=0xFF & color;
alphaRGB.setProgress(i1);
red.setProgress(i2);
green.setProgress(i3);
blue.setProgress(i4);
}catch (Exception e){
Toast.makeText(contxt, "Enter a valid hex", Toast.LENGTH_SHORT).show();
}
return true;
}
return false;
});
return rgbLayout;
}
public void show(ColorPickedListener listener){
if(listener==null){return;}
setPositiveButton("Choose", (dialogInterface, i) -> {
int color=hsvBtn.isEnabled() ? argb : getColorHSV(false);
listener.OnColorPicked(color,getColorHex(color));
});
show();
}
public interface ColorPickedListener {
void OnColorPicked(int color,String hex);
}
void update(){
int pure=getColorHSV(true),processed=getColorHSV(false);
previewHSV.setBackgroundColor(processed);
alphaHSV.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[]{Color.TRANSPARENT,pure}));
brightness.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[]{Color.BLACK,pure}));
saturation.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[]{Color.WHITE,pure}));
satAndBright.setBackground(pure);
hexHSV.setText(getColorHex(processed));
}
boolean hexFun(String colorString){
try{
String hexa=colorString.toUpperCase().replace("#","");
hexa="#"+((hexa.length()==6)?"FF":"")+hexa;
int color=Color.parseColor(hexa);
Color.colorToHSV(color,hsv);
alphaHSV.setProgress(Color.alpha(color));
saturation.setProgress((int)hsv[1]);
brightness.setProgress((int)hsv[2]);
hue.setProgress((int)hsv[0]);
update();
return true;
}catch (Exception e){
Toast.makeText(contxt, "Enter a valid hex", Toast.LENGTH_SHORT).show();
}
return false;
}
public int getColorHSV(boolean isPure){
return (isPure?Color.HSVToColor(new float[]{hsv[0],1,1}):Color.HSVToColor(aHSV,hsv));
}
public String getColorHex(int color){
return ("#"+correctHex(Integer.toHexString(Color.alpha(color)))+correctHex(Integer.toHexString(Color.red(color)))+correctHex(Integer.toHexString(Color.green(color)))+correctHex(Integer.toHexString(Color.blue(color)))).toUpperCase();
}
String correctHex(String hex){
return hex.length()<2?"0"+hex:hex;
}
public void setArgb(int color){
argb=color;
aRGB=0xFF & (argb>>24);
r=0xFF & (argb>>16);
g=0xFF & (argb>>8);
b=0xFF & argb;
previewRGB.setBackgroundColor(argb);
}
boolean boxFun(String txt,int index){
try{
int i=Integer.parseInt(txt);
if(i>255 || i<0){
Toast.makeText(contxt, "Value should be in between 0 and 255", Toast.LENGTH_SHORT).show();
}else{
SeekBar[] arr=new SeekBar[]{alphaRGB,red,green,blue};
arr[index].setProgress(i);
}
return true;
}catch (Exception e){
Toast.makeText(contxt, "Enter a valid value", Toast.LENGTH_SHORT).show();
}
return false;
}
public class CustomHSVSeekBar extends androidx.appcompat.widget.AppCompatSeekBar{
public CustomHSVSeekBar(Context context,int max) {
super(context);
setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,1f));
setMax(max);
setPadding(dp10,dp10,dp10,dp10);
setProgress(0);
GradientDrawable thumb=new GradientDrawable();
thumb.setShape(GradientDrawable.RECTANGLE);
thumb.setSize(dp10/2,dp10*2);
thumb.setColor(Color.BLACK);
setThumb(thumb);
}
}
public class CustomRGBSeekBar extends androidx.appcompat.widget.AppCompatSeekBar{
public CustomRGBSeekBar(Context context) {
super(context);
setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,1));
setMax(255);
setPadding(dp10,dp10,dp10,dp10);
setProgress(255);
}
}
public class CustomRGBEditText extends androidx.appcompat.widget.AppCompatEditText{
public CustomRGBEditText(Context context) {
super(context);
setLayoutParams(new ViewGroup.LayoutParams(dp10*5, ViewGroup.LayoutParams.WRAP_CONTENT));
setEms(10);
setText(R.string.number_255);
setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
setImeOptions(EditorInfo.IME_ACTION_DONE);
}
}
public class CustomRGBContainer extends LinearLayout{
public CustomRGBContainer(Context context,String TextViewText,SeekBar seekBar,EditText editText) {
super(context);
setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
setGravity(Gravity.CENTER);
setOrientation(LinearLayout.HORIZONTAL);
TextView text=new TextView(contxt);
text.setLayoutParams(new ViewGroup.LayoutParams(dp10*5, ViewGroup.LayoutParams.WRAP_CONTENT));
text.setText(TextViewText);
addView(text);
addView(seekBar);
addView(editText);
}
}
@SuppressLint("ViewConstructor")
public static class Custom2DSeekBar extends View{
LayerDrawable corneredGradient;
GradientDrawable blackToTransparent;
Paint whiteStroke=new Paint(),blackStroke=new Paint();
public float x=0,y=0,radius,width,height;
Context contxt;
public Custom2DSeekBar(Context context,int initColor,int initHeight) {
super(context);
contxt=context;
blackToTransparent= new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP,new int[]{
Color.BLACK,Color.TRANSPARENT
});
radius=initHeight/15f;
setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,initHeight));
setBackground(initColor);
whiteStroke.setColor(Color.WHITE);
whiteStroke.setStrokeWidth(radius/2.5f);
whiteStroke.setStyle(Paint.Style.STROKE);
blackStroke.setColor(Color.BLACK);
blackStroke.setStrokeWidth(radius/2.5f);
blackStroke.setStyle(Paint.Style.STROKE);
addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> {
width=i2-i;
height=i3-i1;
});
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(x,y,radius*0.8f,whiteStroke);
canvas.drawCircle(x,y,radius,blackStroke);
}
@SuppressLint("ClickableViewAccessibility")
public void setCordsChangedListener(SeekBar2DCordsChangedListener listener){
if(listener==null){return;}
setOnTouchListener((view, motionEvent) -> {
switch (motionEvent.getActionMasked()){
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
setCords(motionEvent.getX(),motionEvent.getY());
listener.changed(x,y);
return true;
}
return false;
});
}
public void setCords(float X, float Y){
x=Math.min(width, Math.max(0,X));
y=Math.min(height, Math.max(0,Y));
invalidate();
}
public void setBackground(int color){
corneredGradient=new LayerDrawable(new Drawable[]{
new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[]{
Color.WHITE,color
}),blackToTransparent
});
setBackground(corneredGradient);
}
public interface SeekBar2DCordsChangedListener{
void changed(float x,float y);
}
}
}