Skip to content

Commit 098e5f7

Browse files
committed
added about dialog and draw only once
1 parent 2062567 commit 098e5f7

File tree

7 files changed

+134
-52
lines changed

7 files changed

+134
-52
lines changed

app/src/main/java/com/example/caden/drawingtest/DrawView.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class DrawView extends View {
3030
private Matrix mMatrix = new Matrix();
3131
private Matrix mInvMatrix = new Matrix();
3232
private int mDrawnLineSize = 0;
33-
private boolean mSetuped = false;
33+
private boolean mHasBeenSetup = false;
3434

3535
private float mTmpPoints[] = new float[2];
3636

@@ -47,7 +47,8 @@ public void setModel(DrawModel model) {
4747
public void reset() {
4848
mDrawnLineSize = 0;
4949
if (mOffscreenBitmap != null) {
50-
mPaint.setColor(Color.parseColor("#E0E0E0"));
50+
// used to be gray #E0E0E0
51+
mPaint.setColor(Color.parseColor("#000000"));
5152
int width = mOffscreenBitmap.getWidth();
5253
int height = mOffscreenBitmap.getHeight();
5354
mOffscreenCanvas.drawRect(new Rect(0, 0, width, height), mPaint);
@@ -61,7 +62,16 @@ public void addBackground() {
6162
Log.d("DRAWVIEW", "IMAGE DATA IS NOT NULL");
6263
Bitmap img = BitmapFactory.decodeByteArray(ImageManager.imgData, 0, ImageManager.imgData.length);
6364
// use the width of the screen, and for height, scale it proportional to how much width was scaled
64-
Rect dest = new Rect(0, 0, mOffscreenBitmap.getWidth(), img.getHeight() * (mOffscreenBitmap.getWidth()/img.getWidth()));
65+
// (mOffscreenBitmap.getWidth() - img.getHeight()) / 2
66+
67+
// Log.d("img", img.getWidth() + "..." + img.getHeight());
68+
// Log.d("offscreenbmp", mOffscreenBitmap.getWidth() + "..." + mOffscreenBitmap.getHeight());
69+
// Log.d("drawview", this.getWidth() + "..." + this.getHeight());
70+
// Log.d("calculated", 0 + "..." + 0 + "..." + mOffscreenBitmap.getWidth() + "..." + img.getHeight() * (mOffscreenBitmap.getWidth()/img.getWidth()));
71+
// FIXME for now draw same dimensions as mOffscreenBitmap
72+
Rect dest = new Rect(0, 0,
73+
mOffscreenBitmap.getWidth(),
74+
mOffscreenBitmap.getHeight());
6575
Paint paint = new Paint();
6676
paint.setFilterBitmap(true);
6777
mOffscreenCanvas.drawBitmap(img, null, dest, paint);
@@ -72,7 +82,7 @@ public void addBackground() {
7282

7383
//create the view, for a given length and width
7484
private void setup() {
75-
mSetuped = true;
85+
mHasBeenSetup = true;
7686

7787
// View size
7888
float width = getWidth();
@@ -98,7 +108,7 @@ private void setup() {
98108
mMatrix.setScale(scale, scale);
99109
mMatrix.postTranslate(dx, dy);
100110
mMatrix.invert(mInvMatrix);
101-
mSetuped = true;
111+
mHasBeenSetup = true;
102112
}
103113

104114
@Override
@@ -108,7 +118,7 @@ public void onDraw(Canvas canvas) {
108118
if (mModel == null) {
109119
return;
110120
}
111-
if (!mSetuped) {
121+
if (!mHasBeenSetup) {
112122
setup();
113123
}
114124
if (mOffscreenBitmap == null) {
@@ -168,27 +178,27 @@ private void releaseBitmap() {
168178
/**
169179
* Get 28x28 pixel data for input.
170180
*/
171-
public float[] getPixelData() {
172-
if (mOffscreenBitmap == null) {
173-
return null;
174-
}
175-
176-
int width = mOffscreenBitmap.getWidth();
177-
int height = mOffscreenBitmap.getHeight();
178-
179-
// Get 28x28 pixel data from bitmap
180-
int[] pixels = new int[width * height];
181-
mOffscreenBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
182-
183-
float[] retPixels = new float[pixels.length];
184-
for (int i = 0; i < pixels.length; ++i) {
185-
// Set 0 for white and 255 for black pixel
186-
int pix = pixels[i];
187-
int b = pix & 0xff;
188-
retPixels[i] = (float)((0xff - b)/255.0);
189-
}
190-
return retPixels;
191-
}
181+
// public float[] getPixelData() {
182+
// if (mOffscreenBitmap == null) {
183+
// return null;
184+
// }
185+
//
186+
// int width = mOffscreenBitmap.getWidth();
187+
// int height = mOffscreenBitmap.getHeight();
188+
//
189+
// // Get 28x28 pixel data from bitmap
190+
// int[] pixels = new int[width * height];
191+
// mOffscreenBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
192+
//
193+
// float[] retPixels = new float[pixels.length];
194+
// for (int i = 0; i < pixels.length; ++i) {
195+
// // Set 0 for white and 255 for black pixel
196+
// int pix = pixels[i];
197+
// int b = pix & 0xff;
198+
// retPixels[i] = (float)((0xff - b)/255.0);
199+
// }
200+
// return retPixels;
201+
// }
192202

193203
public Bitmap getBitmapData() {
194204
return this.mOffscreenBitmap;

app/src/main/java/com/example/caden/drawingtest/DrawingActivity.java

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.annotation.SuppressLint;
44
import android.content.Intent;
55
import android.content.res.ColorStateList;
6+
import android.content.res.Resources;
67
import android.graphics.Bitmap;
78
import android.graphics.Color;
89
import android.graphics.PointF;
@@ -14,13 +15,15 @@
1415
import android.support.v7.app.AppCompatActivity;
1516
import android.support.v7.widget.Toolbar;
1617
import android.transition.TransitionManager;
18+
import android.util.Log;
1719
import android.util.TypedValue;
1820
import android.view.Menu;
1921
import android.view.MenuItem;
2022
import android.view.MotionEvent;
2123
import android.view.View;
2224
import android.widget.Button;
2325
import android.widget.ProgressBar;
26+
import android.widget.RatingBar;
2427
import android.widget.TextView;
2528

2629
import com.flask.colorpicker.ColorPickerView;
@@ -42,6 +45,7 @@
4245
import java.text.SimpleDateFormat;
4346
import java.util.Date;
4447
import java.util.HashMap;
48+
import java.util.Locale;
4549
import java.util.Map;
4650
import java.util.Random;
4751
import 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) {

app/src/main/java/com/example/caden/drawingtest/LoginActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example.caden.drawingtest;
22

3+
import android.app.Dialog;
34
import android.content.Intent;
45
import android.support.design.widget.Snackbar;
56
import android.support.v7.app.AlertDialog;
@@ -11,6 +12,8 @@
1112
import android.view.View;
1213
import android.widget.EditText;
1314
import android.widget.ProgressBar;
15+
import android.widget.RatingBar;
16+
import android.widget.TextView;
1417

1518
import com.google.android.gms.auth.api.signin.GoogleSignIn;
1619
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
@@ -85,7 +88,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
8588

8689
private void about_screen() {
8790
new AlertDialog.Builder(this)
88-
.setMessage(R.string.about_text)
91+
.setMessage("Created by Caden 2017")
8992
.setTitle(R.string.app_name)
9093
.setPositiveButton("OK", (dialog, id) -> dialog.cancel())
9194
.show();

app/src/main/java/com/example/caden/drawingtest/RegistrationActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
6060

6161
private void about_screen() {
6262
new AlertDialog.Builder(this)
63-
.setMessage(R.string.about_text)
63+
.setMessage("Created by Caden 2017")
6464
.setTitle(R.string.app_name)
6565
.setPositiveButton("OK", (dialog, id) -> dialog.cancel())
6666
.show();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
9+
<RatingBar
10+
android:id="@+id/ratingBar"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:layout_marginEnd="16dp"
14+
android:layout_marginStart="16dp"
15+
android:layout_marginTop="16dp"
16+
app:layout_constraintEnd_toEndOf="parent"
17+
app:layout_constraintHorizontal_bias="0.497"
18+
app:layout_constraintStart_toStartOf="parent"
19+
app:layout_constraintTop_toTopOf="parent" />
20+
21+
<MultiAutoCompleteTextView
22+
android:id="@+id/tv_feedback"
23+
android:layout_width="0dp"
24+
android:layout_height="wrap_content"
25+
android:layout_marginEnd="16dp"
26+
android:layout_marginStart="16dp"
27+
android:layout_marginTop="16dp"
28+
app:layout_constraintEnd_toEndOf="parent"
29+
app:layout_constraintStart_toStartOf="parent"
30+
app:layout_constraintTop_toBottomOf="@+id/ratingBar" />
31+
</android.support.constraint.ConstraintLayout>

app/src/main/res/layout/activity_drawing.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
android:layout_height="350dp"
5151
android:layout_margin="0dp"
5252
android:layout_marginTop="0dp"
53+
android:background="#000000"
5354
android:padding="0dp"
5455
app:layout_constraintEnd_toEndOf="parent"
5556
app:layout_constraintHorizontal_bias="0.0"
@@ -77,7 +78,7 @@
7778
android:layout_marginEnd="32dp"
7879
android:layout_marginTop="16dp"
7980
android:fontFamily="monospace"
80-
android:text=""
81+
android:text="###/###.png"
8182
android:textColor="@color/common_google_signin_btn_text_light_default"
8283
android:textSize="12sp"
8384
app:layout_constraintEnd_toEndOf="parent"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<resources>
22
<string name="app_name">Wurm Paint</string>
3-
<string name="about_text">Created by Caden 2017</string>
3+
<string name="about_text">Created by Caden 2017, I love to hear your feedback on the app,
4+
feel free to post your response below!</string>
45

56
<string name="start_text">Start</string>
67
<string name="register_text">Register</string>

0 commit comments

Comments
 (0)