11package com .example .caden .drawingtest ;
22
33import android .annotation .SuppressLint ;
4+ import android .content .res .ColorStateList ;
45import android .graphics .Bitmap ;
6+ import android .graphics .Color ;
57import android .graphics .PointF ;
68import android .os .Bundle ;
79import android .support .constraint .ConstraintLayout ;
1113import android .support .v7 .app .AppCompatActivity ;
1214import android .support .v7 .widget .Toolbar ;
1315import android .transition .TransitionManager ;
16+ import android .util .Log ;
1417import android .util .TypedValue ;
1518import android .view .Menu ;
1619import android .view .MenuItem ;
1720import android .view .MotionEvent ;
1821import android .view .View ;
22+ import android .widget .Button ;
1923import android .widget .ProgressBar ;
2024
25+ import com .flask .colorpicker .ColorPickerView ;
26+ import com .flask .colorpicker .builder .ColorPickerDialogBuilder ;
2127import com .google .firebase .auth .FirebaseAuth ;
2228import com .google .firebase .auth .FirebaseUser ;
2329import com .google .firebase .database .DatabaseReference ;
@@ -47,7 +53,9 @@ public class DrawingActivity extends AppCompatActivity implements View.OnTouchLi
4753 private float mLastY ;
4854
4955 private ImageManager im ;
50- private int brushColor ;
56+ int brushColor ;
57+ Button btnBrushColor ;
58+
5159
5260 // FireBase
5361 private FirebaseStorage mStorage ;
@@ -75,6 +83,8 @@ protected void onCreate(Bundle savedInstanceState) {
7583 drawView = findViewById (R .id .draw );
7684 //get the model object
7785 drawModel = new DrawModel (PIXEL_WIDTH , PIXEL_WIDTH );
86+ btnBrushColor = findViewById (R .id .btn_brush_color );
87+ // brushColor = btnBrushColor.getBackgroundTintList();
7888 clDrawMain = findViewById (R .id .cl_draw_main );
7989 constraintSet .clone (clDrawMain );
8090 dp56 = dpToPx (56 );
@@ -85,7 +95,6 @@ protected void onCreate(Bundle savedInstanceState) {
8595 drawView .setOnTouchListener (this );
8696
8797 im = new ImageManager ();
88- brushColor = getIntent ().getIntExtra ("color" , 0 );
8998
9099 fabSend = findViewById (R .id .fab_send );
91100 barSend = findViewById (R .id .pbar_send );
@@ -226,7 +235,7 @@ public void sendImage(View v) {
226235
227236 UUID uuid = UUID .randomUUID ();
228237 DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd EEE" );
229- DateFormat timeFormat = new SimpleDateFormat ("hh :mm:ss aaa " );
238+ DateFormat timeFormat = new SimpleDateFormat ("HH :mm:ss" );
230239 DateFormat uploadFormat = new SimpleDateFormat ("yyyy-MM-dd" );
231240 Date date = new Date ();
232241 String imageFileName = im .imgFileName ;
@@ -253,10 +262,29 @@ public void sendImage(View v) {
253262
254263 /* Update Database Reference */
255264 mDatabase .child (imageFileName ).child (dateFormat .format (date )).child (timeFormat .format (date )).child ("image_name" ).setValue (uuid .toString ());
256- mDatabase .child (imageFileName ).child (dateFormat .format (date )).child (timeFormat .format (date )).child ("username " ).setValue (u .getEmail ());
265+ mDatabase .child (imageFileName ).child (dateFormat .format (date )).child (timeFormat .format (date )).child ("user_email " ).setValue (u .getEmail ());
257266 mDatabase .child (imageFileName ).child (dateFormat .format (date )).child (timeFormat .format (date )).child ("user_uid" ).setValue (u .getUid ());
258267 }
259268
269+ public void changeColor (View v ) {
270+ ColorPickerDialogBuilder
271+ .with (this )
272+ .setTitle ("Pick Color" )
273+ .initialColor (Color .parseColor ("#FFFFFF" ))
274+ .wheelType (ColorPickerView .WHEEL_TYPE .FLOWER )
275+ .lightnessSliderOnly ()
276+ .density (16 )
277+ .setOnColorSelectedListener (selectedColor -> {})
278+ .setPositiveButton ("ok" , (dialog , selectedColor , allColors ) -> {
279+ btnBrushColor .setBackgroundTintList (ColorStateList .valueOf (selectedColor ));
280+ brushColor = selectedColor ;
281+ ImageManager .setBrushColor (selectedColor );
282+ })
283+ .setNegativeButton ("cancel" , (dialog , which ) -> {})
284+ .build ()
285+ .show ();
286+ }
287+
260288 /**
261289 * Converts dp into pixel values
262290 * @param dp display pixels
0 commit comments