Skip to content

Commit 7775bf4

Browse files
committed
added color picker
1 parent 8a073dc commit 7775bf4

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.example.caden.drawingtest;
22

33
import android.annotation.SuppressLint;
4+
import android.content.res.ColorStateList;
45
import android.graphics.Bitmap;
6+
import android.graphics.Color;
57
import android.graphics.PointF;
68
import android.os.Bundle;
79
import android.support.constraint.ConstraintLayout;
@@ -11,13 +13,17 @@
1113
import android.support.v7.app.AppCompatActivity;
1214
import android.support.v7.widget.Toolbar;
1315
import android.transition.TransitionManager;
16+
import android.util.Log;
1417
import android.util.TypedValue;
1518
import android.view.Menu;
1619
import android.view.MenuItem;
1720
import android.view.MotionEvent;
1821
import android.view.View;
22+
import android.widget.Button;
1923
import android.widget.ProgressBar;
2024

25+
import com.flask.colorpicker.ColorPickerView;
26+
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
2127
import com.google.firebase.auth.FirebaseAuth;
2228
import com.google.firebase.auth.FirebaseUser;
2329
import 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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,15 @@
9696
app:layout_constraintTop_toBottomOf="@+id/tv_user_email">
9797

9898
<Button
99-
android:id="@+id/button3"
99+
android:id="@+id/btn_brush_color"
100100
style="@style/Widget.AppCompat.Button.Colored"
101101
android:layout_width="0dp"
102102
android:layout_height="52dp"
103103
android:layout_marginEnd="8dp"
104104
android:layout_marginStart="8dp"
105105
android:drawableLeft="@drawable/ic_color_lens"
106106
android:drawableTint="#ffffff"
107+
android:onClick="changeColor"
107108
android:text="Color"
108109
app:layout_constraintEnd_toStartOf="@+id/guideline"
109110
app:layout_constraintStart_toStartOf="parent"
@@ -124,7 +125,7 @@
124125
app:layout_constraintBottom_toBottomOf="parent"
125126
app:layout_constraintEnd_toStartOf="@+id/guideline"
126127
app:layout_constraintStart_toStartOf="parent"
127-
app:layout_constraintTop_toBottomOf="@+id/button3" />
128+
app:layout_constraintTop_toBottomOf="@+id/btn_brush_color" />
128129

129130
<android.support.v7.widget.CardView
130131
android:id="@+id/cv_controls"

0 commit comments

Comments
 (0)