@@ -78,6 +78,7 @@ public class PalettesFragment extends Fragment {
78
78
String newPaletteName = "" ;
79
79
int [] palette ;
80
80
final String PALETTE_ID_REGEX = "^[a-z0-9]{2,}$" ;
81
+ boolean newPalette = false ;
81
82
82
83
public View onCreateView (@ NonNull LayoutInflater inflater ,
83
84
ViewGroup container , Bundle savedInstanceState ) {
@@ -107,6 +108,7 @@ public void run() {
107
108
palette = Utils .gbcPalettesList .get (palettePos ).getPaletteColorsInt ().clone ();//Clone so it doesn't overwrite base palette colors.
108
109
newPaletteId = Utils .gbcPalettesList .get (palettePos ).getPaletteId ();
109
110
newPaletteName = Utils .gbcPalettesList .get (palettePos ).getPaletteName ();
111
+ newPalette = false ;
110
112
paletteDialog (palette , newPaletteId , newPaletteName );
111
113
}
112
114
};
@@ -209,6 +211,7 @@ public void onClick(DialogInterface dialog, int which) {
209
211
@ Override
210
212
public void onClick (View v ) {
211
213
palette = Utils .gbcPalettesList .get (0 ).getPaletteColorsInt ().clone ();//Clone so it doesn't overwrite base palette colors.
214
+ newPalette = true ;
212
215
paletteDialog (palette , "" , "" );
213
216
}
214
217
});
@@ -242,9 +245,9 @@ private void PaletteJsonCreator() throws JSONException {
242
245
JSONArray paletteArr = new JSONArray ();
243
246
for (int color : palette .getPaletteColorsInt ()) {
244
247
String hexColor ;
245
- if (color == 0 ){//For total transparency color
248
+ if (color == 0 ) {//For total transparency color
246
249
hexColor = "#000000" ;
247
- }else {
250
+ } else {
248
251
hexColor = "#" + Integer .toHexString (color ).substring (2 );
249
252
}
250
253
@@ -271,11 +274,13 @@ private void PaletteJsonCreator() throws JSONException {
271
274
272
275
private void paletteDialog (int [] palette , String paletteId , String paletteName ) {
273
276
final Dialog dialog = new Dialog (getContext ());
277
+ dialog .setCancelable (false );
274
278
dialog .setContentView (R .layout .palette_creator );
275
279
final boolean [] validId = {false };
276
280
277
281
ImageView ivPalette = dialog .findViewById (R .id .ivPalette );
278
282
Button btnSavePalette = dialog .findViewById (R .id .btnSavePalette );
283
+ Button btnCancelPalette = dialog .findViewById (R .id .btnCancelPalette );
279
284
btnSavePalette .setEnabled (false );
280
285
281
286
EditText etPaletteId = dialog .findViewById (R .id .etPaletteId );
@@ -503,8 +508,8 @@ public void onClick(View v) {
503
508
ColorPickerDialogBuilder
504
509
.with (getContext ())
505
510
.setTitle (getString (R .string .choose_color ))
506
- .initialColor (lastPickedColor )
507
- .wheelType (ColorPickerView .WHEEL_TYPE .FLOWER )
511
+ .initialColor (newPalette ? lastPickedColor : palette [ 0 ] )
512
+ .wheelType (ColorPickerView .WHEEL_TYPE .CIRCLE )
508
513
.density (12 )
509
514
.showAlphaSlider (false )
510
515
.setOnColorSelectedListener (new OnColorSelectedListener () {
@@ -543,7 +548,7 @@ public void onClick(View v) {
543
548
ColorPickerDialogBuilder
544
549
.with (getContext ())
545
550
.setTitle (getString (R .string .choose_color ))
546
- .initialColor (lastPickedColor )
551
+ .initialColor (newPalette ? lastPickedColor : palette [ 1 ] )
547
552
.wheelType (ColorPickerView .WHEEL_TYPE .CIRCLE )
548
553
.density (12 )
549
554
.showAlphaSlider (false )
@@ -585,8 +590,8 @@ public void onClick(View v) {
585
590
ColorPickerDialogBuilder
586
591
.with (getContext ())
587
592
.setTitle (getString (R .string .choose_color ))
588
- .initialColor (lastPickedColor )
589
- .wheelType (ColorPickerView .WHEEL_TYPE .FLOWER )
593
+ .initialColor (newPalette ? lastPickedColor : palette [ 2 ] )
594
+ .wheelType (ColorPickerView .WHEEL_TYPE .CIRCLE )
590
595
.density (12 )
591
596
.showAlphaSlider (false )
592
597
.setOnColorSelectedListener (new OnColorSelectedListener () {
@@ -627,8 +632,8 @@ public void onClick(View v) {
627
632
ColorPickerDialogBuilder
628
633
.with (getContext ())
629
634
.setTitle (getString (R .string .choose_color ))
630
- .initialColor (lastPickedColor )
631
- .wheelType (ColorPickerView .WHEEL_TYPE .FLOWER )
635
+ .initialColor (newPalette ? lastPickedColor : palette [ 3 ] )
636
+ .wheelType (ColorPickerView .WHEEL_TYPE .CIRCLE )
632
637
.density (12 )
633
638
.showAlphaSlider (false )
634
639
.setOnColorSelectedListener (new OnColorSelectedListener () {
@@ -661,7 +666,12 @@ public void onClick(DialogInterface dialog, int which) {
661
666
.show ();
662
667
}
663
668
});
664
-
669
+ btnCancelPalette .setOnClickListener (new View .OnClickListener () {
670
+ @ Override
671
+ public void onClick (View v ) {
672
+ dialog .dismiss ();
673
+ }
674
+ });
665
675
btnSavePalette .setOnClickListener (new View .OnClickListener () {
666
676
@ Override
667
677
public void onClick (View v ) {
0 commit comments