22
33import  android .app .DownloadManager ;
44import  android .content .Context ;
5+ import  android .content .DialogInterface ;
56import  android .content .Intent ;
67import  android .content .res .TypedArray ;
78import  android .database .Cursor ;
9+ import  android .graphics .Color ;
810import  android .net .Uri ;
911import  android .os .Bundle ;
1012import  android .os .Environment ;
2628import  androidx .appcompat .app .AppCompatActivity ;
2729import  androidx .appcompat .widget .Toolbar ;
2830
29- import  com .android .colorpicker .ColorPickerDialog ;
30- import  com .android .colorpicker .ColorPickerSwatch ;
3131import  com .bumptech .glide .Glide ;
32+ import  com .flask .colorpicker .ColorPickerView ;
33+ import  com .flask .colorpicker .OnColorSelectedListener ;
34+ import  com .flask .colorpicker .builder .ColorPickerClickListener ;
35+ import  com .flask .colorpicker .builder .ColorPickerDialogBuilder ;
3236import  com .stfalcon .chatkit .commons .ImageLoader ;
3337import  com .stfalcon .chatkit .messages .MessageHolders ;
3438import  com .stfalcon .chatkit .messages .MessagesList ;
4246import  java .util .Calendar ;
4347
4448public  class  ChatActivity  extends  AppCompatActivity 
45-  implements  ColorPickerSwatch .OnColorSelectedListener ,
46-  MessageHolders .ContentChecker <Message >,
49+  implements  MessageHolders .ContentChecker <Message >,
4750 MessagesListAdapter .OnMessageLongClickListener <Message > {
4851
4952 private  static  final  int  PICK_FILE_REQUEST  = 1 ;
@@ -64,7 +67,6 @@ public class ChatActivity extends AppCompatActivity
6467 ImageButton  btnAttachement , btnImage ;
6568 EditText  input ;
6669
67-  ColorPickerDialog  colorPickerDialog ;
6870 RelativeLayout  back_view ;
6971 int [] colors ;
7072
@@ -125,9 +127,6 @@ public void loadImage(ImageView imageView, @Nullable String url, @Nullable Objec
125127 colors [i ] = ta .getColor (i , 0 );
126128 }
127129 ta .recycle ();
128-  colorPickerDialog  = new  ColorPickerDialog ();
129-  colorPickerDialog .initialize (R .string .color_title , colors , colors [0 ], 5 , colors .length );
130-  colorPickerDialog .setOnColorSelectedListener (this );
131130
132131 adapter .setOnMessageLongClickListener (this );
133132 }
@@ -157,24 +156,42 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
157156 Toast .makeText (getApplicationContext (), "Select All Clicked" , Toast .LENGTH_SHORT ).show ();
158157 break ;
159158 case  R .id .background_button :
160-  colorPickerDialog .show (getFragmentManager (), "COLOR" );
159+  ColorPickerDialogBuilder 
160+  .with (this )
161+  .setTitle ("Choose color" )
162+  .initialColor (Color .WHITE )
163+  .wheelType (ColorPickerView .WHEEL_TYPE .FLOWER )
164+  .density (12 )
165+  .setOnColorSelectedListener (new  OnColorSelectedListener () {
166+  @ Override 
167+  public  void  onColorSelected (int  selectedColor ) {
168+  Toast .makeText (getApplicationContext (),"onColorSelected: 0x"  + Integer .toHexString (selectedColor ),Toast .LENGTH_SHORT ).show ();
169+  }
170+  })
171+  .setPositiveButton ("ok" , new  ColorPickerClickListener () {
172+  @ Override 
173+  public  void  onClick (DialogInterface  dialog , int  selectedColor , Integer [] allColors ) {
174+  Message  message  = new  Message (Integer .toString (++cnt ), me , null , Calendar .getInstance ().getTime ());
175+  message .setColor (selectedColor );
176+  message .setIsColor (true );
177+ 178+  sender  = new  SendMessage (user .getIpAddress (), user .getPort (), message , ChatActivity .this );
179+  sender .execute ();
180+  back_view .setBackgroundColor (selectedColor );
181+  }
182+  })
183+  .setNegativeButton ("cancel" , new  DialogInterface .OnClickListener () {
184+  @ Override 
185+  public  void  onClick (DialogInterface  dialog , int  which ) {
186+  }
187+  })
188+  .build ()
189+  .show ();
161190 break ;
162191 }
163192 return  super .onOptionsItemSelected (item );
164193 }
165194
166-  @ Override 
167-  public  void  onColorSelected (int  color ) {
168-  Message  message  = new  Message (Integer .toString (++cnt ), me , null , Calendar .getInstance ().getTime ());
169-  message .setColor (color );
170-  message .setIsColor (true );
171- 172-  sender  = new  SendMessage (user .getIpAddress (), user .getPort (), message , this );
173-  sender .execute ();
174- 175-  back_view .setBackgroundColor (color );
176-  }
177- 178195 public  void  onBtnSendClick (View  view ) {
179196 if  (input .getText ().toString () == null ) return ;
180197
0 commit comments