2
2
3
3
import android .app .DownloadManager ;
4
4
import android .content .Context ;
5
+ import android .content .DialogInterface ;
5
6
import android .content .Intent ;
6
7
import android .content .res .TypedArray ;
7
8
import android .database .Cursor ;
9
+ import android .graphics .Color ;
8
10
import android .net .Uri ;
9
11
import android .os .Bundle ;
10
12
import android .os .Environment ;
26
28
import androidx .appcompat .app .AppCompatActivity ;
27
29
import androidx .appcompat .widget .Toolbar ;
28
30
29
- import com .android .colorpicker .ColorPickerDialog ;
30
- import com .android .colorpicker .ColorPickerSwatch ;
31
31
import 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 ;
32
36
import com .stfalcon .chatkit .commons .ImageLoader ;
33
37
import com .stfalcon .chatkit .messages .MessageHolders ;
34
38
import com .stfalcon .chatkit .messages .MessagesList ;
42
46
import java .util .Calendar ;
43
47
44
48
public class ChatActivity extends AppCompatActivity
45
- implements ColorPickerSwatch .OnColorSelectedListener ,
46
- MessageHolders .ContentChecker <Message >,
49
+ implements MessageHolders .ContentChecker <Message >,
47
50
MessagesListAdapter .OnMessageLongClickListener <Message > {
48
51
49
52
private static final int PICK_FILE_REQUEST = 1 ;
@@ -64,7 +67,6 @@ public class ChatActivity extends AppCompatActivity
64
67
ImageButton btnAttachement , btnImage ;
65
68
EditText input ;
66
69
67
- ColorPickerDialog colorPickerDialog ;
68
70
RelativeLayout back_view ;
69
71
int [] colors ;
70
72
@@ -125,9 +127,6 @@ public void loadImage(ImageView imageView, @Nullable String url, @Nullable Objec
125
127
colors [i ] = ta .getColor (i , 0 );
126
128
}
127
129
ta .recycle ();
128
- colorPickerDialog = new ColorPickerDialog ();
129
- colorPickerDialog .initialize (R .string .color_title , colors , colors [0 ], 5 , colors .length );
130
- colorPickerDialog .setOnColorSelectedListener (this );
131
130
132
131
adapter .setOnMessageLongClickListener (this );
133
132
}
@@ -157,24 +156,42 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
157
156
Toast .makeText (getApplicationContext (), "Select All Clicked" , Toast .LENGTH_SHORT ).show ();
158
157
break ;
159
158
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 ();
161
190
break ;
162
191
}
163
192
return super .onOptionsItemSelected (item );
164
193
}
165
194
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
-
178
195
public void onBtnSendClick (View view ) {
179
196
if (input .getText ().toString () == null ) return ;
180
197
0 commit comments