33import android .annotation .SuppressLint ;
44import android .content .Intent ;
55import android .content .res .ColorStateList ;
6+ import android .content .res .Resources ;
67import android .graphics .Bitmap ;
78import android .graphics .Color ;
89import android .graphics .PointF ;
1415import android .support .v7 .app .AppCompatActivity ;
1516import android .support .v7 .widget .Toolbar ;
1617import android .transition .TransitionManager ;
18+ import android .util .Log ;
1719import android .util .TypedValue ;
1820import android .view .Menu ;
1921import android .view .MenuItem ;
2022import android .view .MotionEvent ;
2123import android .view .View ;
2224import android .widget .Button ;
2325import android .widget .ProgressBar ;
26+ import android .widget .RatingBar ;
2427import android .widget .TextView ;
2528
2629import com .flask .colorpicker .ColorPickerView ;
4245import java .text .SimpleDateFormat ;
4346import java .util .Date ;
4447import java .util .HashMap ;
48+ import java .util .Locale ;
4549import java .util .Map ;
4650import java .util .Random ;
4751import java .util .Set ;
@@ -57,6 +61,7 @@ public class DrawingActivity extends AppCompatActivity implements View.OnTouchLi
5761 int currBatchSize ;
5862 int currImgNo ;
5963 Map uploadsDict ;
64+ boolean alreadyDrawn ;
6065
6166 // views
6267 private DrawModel drawModel ;
@@ -85,6 +90,7 @@ public class DrawingActivity extends AppCompatActivity implements View.OnTouchLi
8590 ConstraintSet constraintSet = new ConstraintSet ();
8691
8792 private static final int PIXEL_WIDTH = 280 ;
93+ private static final int PIXEL_HEIGHT = 280 ;
8894
8995 @ SuppressLint ("ClickableViewAccessibility" )
9096 @ Override
@@ -111,7 +117,7 @@ protected void onCreate(Bundle savedInstanceState) {
111117 fireBaseRetrieveImage ();
112118
113119 //get the model object
114- drawModel = new DrawModel (PIXEL_WIDTH , PIXEL_WIDTH );
120+ drawModel = new DrawModel (PIXEL_WIDTH , PIXEL_HEIGHT );
115121 btnBrushColor = findViewById (R .id .btn_brush_color );
116122// brushColor = btnBrushColor.getBackgroundTintList();
117123 clDrawMain = findViewById (R .id .cl_draw_main );
@@ -128,6 +134,15 @@ protected void onCreate(Bundle savedInstanceState) {
128134 drawView .setModel (drawModel );
129135 // give it a touch listener to activate when the user taps
130136 drawView .setOnTouchListener (this );
137+
138+ /* Readjust the height to be almost the same as screen width */
139+ int scrWidth = Resources .getSystem ().getDisplayMetrics ().widthPixels ;
140+ int scrHeight = Resources .getSystem ().getDisplayMetrics ().heightPixels ;
141+ Log .d ("ratio" , scrHeight /(float )scrWidth + "" );
142+ drawView .getLayoutParams ().height =
143+ (int )(Resources .getSystem ().getDisplayMetrics ().widthPixels * 0.85 );
144+ drawView .requestLayout ();
145+ alreadyDrawn = false ;
131146 }
132147
133148 @ Override
@@ -149,10 +164,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
149164 }
150165
151166 private void about_screen () {
167+
168+ View aboutDialogView =
169+ getLayoutInflater ().inflate (R .layout .about_dialog ,
170+ new ConstraintLayout (this ), false );
171+
172+ TextView feedbackText = aboutDialogView .findViewById (R .id .tv_feedback );
173+ RatingBar ratingBar = aboutDialogView .findViewById (R .id .ratingBar );
174+
175+ String userUID = mAuth .getCurrentUser ().getUid ();
176+ String userEmail = mAuth .getCurrentUser ().getEmail ();
177+
152178 new AlertDialog .Builder (this )
179+ .setView (aboutDialogView )
153180 .setMessage (R .string .about_text )
154181 .setTitle (R .string .app_name )
155- .setPositiveButton ("OK" , (dialog , id ) -> dialog .cancel ())
182+ .setPositiveButton ("OK" , (dialog , id ) -> {
183+ mDatabase .child ("ratings" ).child (userUID )
184+ .child ("feedback" ).setValue (feedbackText .getText ().toString ());
185+ mDatabase .child ("ratings" ).child (userUID )
186+ .child ("rating" ).setValue (ratingBar .getRating ());
187+ mDatabase .child ("ratings" ).child (userUID )
188+ .child ("email" ).setValue (userEmail );
189+ dialog .dismiss ();
190+ })
156191 .show ();
157192 }
158193
@@ -204,17 +239,19 @@ public boolean onTouch(View v, MotionEvent event) {
204239 //draw line down
205240
206241 private void processTouchDown (MotionEvent event ) {
207- //calculate the x, y coordinates where the user has touched
208- mLastX = event .getX ();
209- mLastY = event .getY ();
210- //user them to calculate the position
211- drawView .calcPos (mLastX , mLastY , mTmpPoint );
212- //store them in memory to draw a line between the
213- //difference in positions
214- float lastConvX = mTmpPoint .x ;
215- float lastConvY = mTmpPoint .y ;
216- //and begin the line drawing
217- drawModel .startLine (lastConvX , lastConvY );
242+ if (!alreadyDrawn ) {
243+ //calculate the x, y coordinates where the user has touched
244+ mLastX = event .getX ();
245+ mLastY = event .getY ();
246+ //user them to calculate the position
247+ drawView .calcPos (mLastX , mLastY , mTmpPoint );
248+ //store them in memory to draw a line between the
249+ //difference in positions
250+ float lastConvX = mTmpPoint .x ;
251+ float lastConvY = mTmpPoint .y ;
252+ //and begin the line drawing
253+ drawModel .startLine (lastConvX , lastConvY );
254+ }
218255 }
219256
220257 //the main drawing function
@@ -237,13 +274,17 @@ private void processTouchMove(MotionEvent event) {
237274 }
238275
239276 private void processTouchUp () {
240- drawModel .endLine ();
277+ if (!alreadyDrawn ) {
278+ drawModel .endLine ();
279+ alreadyDrawn = true ;
280+ }
241281 }
242282
243283 public void clear (View v ) {
244284 drawModel .clear ();
245285 drawView .reset ();
246286 drawView .invalidate ();
287+ alreadyDrawn = false ;
247288 }
248289
249290 public void sendImage (View v ) {
@@ -264,11 +305,9 @@ public void sendImage(View v) {
264305 bmp .compress (Bitmap .CompressFormat .JPEG , 80 , baos );
265306
266307 UUID uuid = UUID .randomUUID ();
267- DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd EEE" );
268- DateFormat timeFormat = new SimpleDateFormat ("HH:mm:ss" );
269- DateFormat uploadFormat = new SimpleDateFormat ("yyyy-MM-dd" );
308+ DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd EEE" , Locale .US );
309+ DateFormat timeFormat = new SimpleDateFormat ("HH:mm:ss" , Locale .US );
270310 Date date = new Date ();
271- String imageFileName = im .imgFileName ;
272311 FirebaseUser u = mAuth .getCurrentUser ();
273312
274313 /* Upload Drawing */
@@ -299,9 +338,6 @@ public void sendImage(View v) {
299338 .child (timeFormat .format (date )).child ("user_email" ).setValue (u .getEmail ());
300339 mDatabase .child ("uploads" ).child (currBatchName ).child (String .valueOf (currImgNo )).child (dateFormat .format (date ))
301340 .child (timeFormat .format (date )).child ("user_uid" ).setValue (u .getUid ());
302- // mDatabase.child(imageFileName).child(dateFormat.format(date)).child(timeFormat.format(date)).child("image_name").setValue(uuid.toString());
303- // mDatabase.child(imageFileName).child(dateFormat.format(date)).child(timeFormat.format(date)).child("user_email").setValue(u.getEmail());
304- // mDatabase.child(imageFileName).child(dateFormat.format(date)).child(timeFormat.format(date)).child("user_uid").setValue(u.getUid());
305341 }
306342
307343 public void changeColor (View v ) {
0 commit comments