22
33import android .annotation .SuppressLint ;
44import android .content .Intent ;
5- import android .content .res .ColorStateList ;
65import android .content .res .Resources ;
76import android .graphics .Bitmap ;
87import android .graphics .Color ;
2625import android .widget .RatingBar ;
2726import android .widget .TextView ;
2827
29- import com .flask .colorpicker .ColorPickerView ;
30- import com .flask .colorpicker .builder .ColorPickerDialogBuilder ;
3128import com .google .firebase .auth .FirebaseAuth ;
3229import com .google .firebase .auth .FirebaseUser ;
3330import com .google .firebase .database .DataSnapshot ;
@@ -92,7 +89,6 @@ public class DrawingActivity extends AppCompatActivity implements View.OnTouchLi
9289 private static final int PIXEL_WIDTH = 280 ;
9390 private static final int PIXEL_HEIGHT = 280 ;
9491
95- @ SuppressLint ("ClickableViewAccessibility" )
9692 @ Override
9793 protected void onCreate (Bundle savedInstanceState ) {
9894 super .onCreate (savedInstanceState );
@@ -118,7 +114,7 @@ protected void onCreate(Bundle savedInstanceState) {
118114
119115 //get the model object
120116 drawModel = new DrawModel (PIXEL_WIDTH , PIXEL_HEIGHT );
121- btnBrushColor = findViewById (R .id .btn_brush_color );
117+ btnBrushColor = findViewById (R .id .btn_mark_bad );
122118// brushColor = btnBrushColor.getBackgroundTintList();
123119 clDrawMain = findViewById (R .id .cl_draw_main );
124120 tvUserEmail = findViewById (R .id .tv_user_email );
@@ -138,7 +134,7 @@ protected void onCreate(Bundle savedInstanceState) {
138134 /* Readjust the height to be almost the same as screen width */
139135 int scrWidth = Resources .getSystem ().getDisplayMetrics ().widthPixels ;
140136 int scrHeight = Resources .getSystem ().getDisplayMetrics ().heightPixels ;
141- Log .d ("ratio" , scrHeight /(float )scrWidth + "" );
137+ // Log.d("ratio", scrHeight/(float)scrWidth + "");
142138 drawView .getLayoutParams ().height =
143139 (int )(Resources .getSystem ().getDisplayMetrics ().widthPixels * 0.85 );
144140 drawView .requestLayout ();
@@ -301,8 +297,8 @@ public void sendImage(View v) {
301297 constraintSet .applyTo (clDrawMain );
302298
303299 Bitmap bmp = drawView .getBitmapData ();
304- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
305- bmp .compress (Bitmap .CompressFormat .JPEG , 80 , baos );
300+ ByteArrayOutputStream baOS = new ByteArrayOutputStream ();
301+ bmp .compress (Bitmap .CompressFormat .JPEG , 80 , baOS );
306302
307303 UUID uuid = UUID .randomUUID ();
308304 DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd EEE" , Locale .US );
@@ -317,7 +313,7 @@ public void sendImage(View v) {
317313 StorageMetadata metadata = new StorageMetadata .Builder ()
318314 .setCustomMetadata ("text" , "my first upload" )
319315 .build ();
320- UploadTask upTask = mStorageRef .putBytes (baos .toByteArray (), metadata );
316+ UploadTask upTask = mStorageRef .putBytes (baOS .toByteArray (), metadata );
321317 upTask .addOnSuccessListener (this , taskSnapshot -> {
322318 TransitionManager .beginDelayedTransition (clDrawMain );
323319 constraintSet .constrainWidth (R .id .pbar_send , 0 );
@@ -340,22 +336,45 @@ public void sendImage(View v) {
340336 .child (timeFormat .format (date )).child ("user_uid" ).setValue (u .getUid ());
341337 }
342338
343- public void changeColor (View v ) {
344- ColorPickerDialogBuilder
345- .with (this )
346- .setTitle ("Pick Color" )
347- .initialColor (Color .parseColor ("#FFFFFF" ))
348- .wheelType (ColorPickerView .WHEEL_TYPE .FLOWER )
349- .lightnessSliderOnly ()
350- .density (16 )
351- .setOnColorSelectedListener (selectedColor -> {})
352- .setPositiveButton ("ok" , (dialog , selectedColor , allColors ) -> {
353- btnBrushColor .setBackgroundTintList (ColorStateList .valueOf (selectedColor ));
354- brushColor = selectedColor ;
355- ImageManager .setBrushColor (selectedColor );
339+ // public void changeColor(View v) {
340+ // ColorPickerDialogBuilder
341+ // .with(this)
342+ // .setTitle("Pick Color")
343+ // .initialColor(Color.parseColor("#FFFFFF"))
344+ // .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
345+ // .lightnessSliderOnly()
346+ // .density(16)
347+ // .setOnColorSelectedListener(selectedColor -> {})
348+ // .setPositiveButton("ok", (dialog, selectedColor, allColors) -> {
349+ // btnBrushColor.setBackgroundTintList(ColorStateList.valueOf(selectedColor));
350+ // brushColor = selectedColor;
351+ // ImageManager.setBrushColor(selectedColor);
352+ // })
353+ // .setNegativeButton("cancel", (dialog, which) -> {})
354+ // .build()
355+ // .show();
356+ // }
357+
358+ public void markAsBad (View v ) {
359+ /* Update Database Reference */
360+ View aboutDialogView =
361+ getLayoutInflater ().inflate (R .layout .image_comments_dialog ,
362+ new ConstraintLayout (this ), false );
363+
364+ TextView reasonText = aboutDialogView .findViewById (R .id .tv_mark_reason );
365+
366+ String userUID = mAuth .getCurrentUser ().getUid ();
367+
368+ new AlertDialog .Builder (this )
369+ .setView (aboutDialogView )
370+ .setMessage (R .string .reason_marking_image )
371+ .setTitle (R .string .app_name )
372+ .setPositiveButton ("OK" , (dialog , id ) -> {
373+ mDatabase .child ("bad_images" ).child (currBatchName ).child (String .valueOf (currImgNo ))
374+ .child (userUID ).setValue (reasonText .getText ().toString ());
375+ nextImage (v );
376+ dialog .dismiss ();
356377 })
357- .setNegativeButton ("cancel" , (dialog , which ) -> {})
358- .build ()
359378 .show ();
360379 }
361380
@@ -380,20 +399,14 @@ private void initWithImage(HashMap dict) {
380399 int keyLen = keys .size ();
381400 String [] keyArray = (String []) keys .toArray (new String [keyLen ]);
382401 Random rand = new Random ();
383- // TODO set is 0 based need to go from 0 to len - 1
402+ // 0 based need to go from 0 to len - 1
384403 int randKey = rand .nextInt (keyLen );
385404
386405 currBatchName = keyArray [randKey ];
387-
388- // FIXME HARDCODED CHANGE, use currBATCHNAME INSTEAD
389- // currBatchName = "2017-09-23";
390406 currBatchSize = longToInt ((Long ) dict .get (currBatchName ));
391-
392407 currImgNo = rand .nextInt (currBatchSize ) + 1 ;
393-
394408 tvImageName .setText (String .format ("%s / %d.png" , currBatchName , currImgNo ));
395409
396- // FIXME load the image, check this code for errors!
397410 /* Load Drawing */
398411 String path = String .format ("img/%s/%d.png" , currBatchName , currImgNo );
399412 StorageReference mStorageRef = mStorage .getReference (path );
@@ -416,10 +429,10 @@ public void nextImage(View v) {
416429 currBatchName = keyArray [randKey ];
417430 currBatchSize = longToInt ((Long ) uploadsDict .get (currBatchName ));
418431 currImgNo = rand .nextInt (currBatchSize ) + 1 ;
419- tvImageName .setText (String .format ("%s / %d.png" , currBatchName , currImgNo ));
432+ tvImageName .setText (String .format (Locale . US , "%s / %d.png" , currBatchName , currImgNo ));
420433
421434 /* Load Drawing */
422- String path = String .format ("img/%s/%d.png" , currBatchName , currImgNo );
435+ String path = String .format (Locale . US , "img/%s/%d.png" , currBatchName , currImgNo );
423436 StorageReference mStorageRef = mStorage .getReference (path );
424437
425438 final long ONE_KILOBYTE = 1024 ;
0 commit comments