Skip to content

Commit 2a58073

Browse files
committed
change color of icon
1 parent 4ecb008 commit 2a58073

File tree

2 files changed

+18
-153
lines changed

2 files changed

+18
-153
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.gloop.drawed;
22

33
import android.app.Dialog;
4+
import android.graphics.Color;
5+
import android.graphics.PorterDuff;
6+
import android.graphics.drawable.Drawable;
47
import android.os.Bundle;
58
import android.support.v4.app.Fragment;
69
import android.view.LayoutInflater;
@@ -19,20 +22,20 @@
1922
* in two-pane mode (on tablets) or a {@link BoardDetailActivity}
2023
* on handsets.
2124
*/
22-
public class BoardDetailFragment extends Fragment implements View.OnClickListener {
25+
public class BoardDetailFragment extends Fragment {
2326

2427
public static final String ARG_BOARD = "board";
2528

2629
private Board board;
2730

2831
private DrawingView drawView;
2932

30-
private ImageButton currPaint;
31-
32-
private String currentColor;
33+
private String currentColor = "#FF000000";
3334

3435
private float smallBrush, mediumBrush, largeBrush;
3536

37+
private ImageView changeColorButton;
38+
3639
public BoardDetailFragment() {
3740
// Mandatory empty constructor for the fragment manager to instantiate the fragment
3841
}
@@ -61,7 +64,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6164
// currPaint = (ImageButton) paintLayout.getChildAt(0);
6265
// currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed));
6366

64-
currentColor = "#FF000000";
6567
drawView.setColor(currentColor);
6668

6769
//sizes from dimensions
@@ -72,7 +74,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
7274
//set initial size
7375
drawView.setBrushSize(smallBrush);
7476

75-
ImageView changeColorButton = (ImageView) rootView.findViewById(R.id.draw_view_btn_change_color);
77+
changeColorButton = (ImageView) rootView.findViewById(R.id.draw_view_btn_change_color);
7678
changeColorButton.setOnClickListener(new View.OnClickListener() {
7779
@Override
7880
public void onClick(View view) {
@@ -88,24 +90,6 @@ public void onClick(View view) {
8890
}
8991
});
9092

91-
92-
// //draw button
93-
// ImageButton drawBtn = (ImageButton) rootView.findViewById(R.id.draw_btn);
94-
// drawBtn.setOnClickListener(this);
95-
//
96-
//
97-
// //erase button
98-
// ImageButton eraseBtn = (ImageButton) rootView.findViewById(R.id.erase_btn);
99-
// eraseBtn.setOnClickListener(this);
100-
//
101-
// //new button
102-
// ImageButton newBtn = (ImageButton) rootView.findViewById(R.id.new_btn);
103-
// newBtn.setOnClickListener(this);
104-
//
105-
// //save button
106-
// ImageButton saveBtn = (ImageButton) rootView.findViewById(R.id.save_btn);
107-
// saveBtn.setOnClickListener(this);
108-
10993
return rootView;
11094
}
11195

@@ -147,11 +131,15 @@ private void showChangeColorPopup() {
147131
@SuppressWarnings("deprecation")
148132
private class ColorChangeListener implements View.OnClickListener {
149133
private ImageButton imgView;
134+
private ImageView colorIcon;
150135
private Dialog dialog;
151136

137+
// TODO do not pass as arguments, change to global variable
152138
ColorChangeListener(ImageButton imgView, Dialog dialog) {
153139
this.imgView = imgView;
154140
this.dialog = dialog;
141+
this.colorIcon = colorIcon;
142+
155143
// set currently selected color
156144
if (this.imgView.getTag().toString().equals(currentColor))
157145
this.imgView.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed));
@@ -163,6 +151,11 @@ public void onClick(View view) {
163151

164152
drawView.setColor(currentColor);
165153

154+
// change color of icon
155+
Drawable myIcon = getResources().getDrawable(R.drawable.ic_color_lens_black_24dp);
156+
myIcon.setColorFilter(Color.parseColor(currentColor), PorterDuff.Mode.SRC_ATOP);
157+
changeColorButton.setImageDrawable(myIcon);
158+
166159
// set selected color
167160
imgView.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed));
168161
dialog.dismiss();
@@ -220,132 +213,4 @@ public void onClick(View v) {
220213
//show and wait for user interaction
221214
dialog.show();
222215
}
223-
224-
225-
@Override
226-
public void onClick(View view) {
227-
228-
// if (view.getId() == R.id.draw_btn) {
229-
// //draw button clicked
230-
// final Dialog brushDialog = new Dialog(getContext());
231-
// brushDialog.setTitle("Brush size:");
232-
// brushDialog.setContentView(R.layout.popup_chooser_line_thickness);
233-
// //listen for clicks on size buttons
234-
// ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush);
235-
// smallBtn.setOnClickListener(new View.OnClickListener() {
236-
// @Override
237-
// public void onClick(View v) {
238-
// drawView.setErase(false);
239-
// drawView.setBrushSize(smallBrush);
240-
// drawView.setLastBrushSize(smallBrush);
241-
// brushDialog.dismiss();
242-
// }
243-
// });
244-
// ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush);
245-
// mediumBtn.setOnClickListener(new View.OnClickListener() {
246-
// @Override
247-
// public void onClick(View v) {
248-
// drawView.setErase(false);
249-
// drawView.setBrushSize(mediumBrush);
250-
// drawView.setLastBrushSize(mediumBrush);
251-
// brushDialog.dismiss();
252-
// }
253-
// });
254-
// ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush);
255-
// largeBtn.setOnClickListener(new View.OnClickListener() {
256-
// @Override
257-
// public void onClick(View v) {
258-
// drawView.setErase(false);
259-
// drawView.setBrushSize(largeBrush);
260-
// drawView.setLastBrushSize(largeBrush);
261-
// brushDialog.dismiss();
262-
// }
263-
// });
264-
// //show and wait for user interaction
265-
// brushDialog.show();
266-
// } else if (view.getId() == R.id.erase_btn) {
267-
// //switch to erase - choose size
268-
// final Dialog brushDialog = new Dialog(getContext());
269-
// brushDialog.setTitle("Eraser size:");
270-
// brushDialog.setContentView(R.layout.popup_chooser_line_thickness);
271-
// //size buttons
272-
// ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush);
273-
// smallBtn.setOnClickListener(new View.OnClickListener() {
274-
// @Override
275-
// public void onClick(View v) {
276-
// drawView.setErase(true);
277-
// drawView.setBrushSize(smallBrush);
278-
// brushDialog.dismiss();
279-
// }
280-
// });
281-
// ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush);
282-
// mediumBtn.setOnClickListener(new View.OnClickListener() {
283-
// @Override
284-
// public void onClick(View v) {
285-
// drawView.setErase(true);
286-
// drawView.setBrushSize(mediumBrush);
287-
// brushDialog.dismiss();
288-
// }
289-
// });
290-
// ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush);
291-
// largeBtn.setOnClickListener(new View.OnClickListener() {
292-
// @Override
293-
// public void onClick(View v) {
294-
// drawView.setErase(true);
295-
// drawView.setBrushSize(largeBrush);
296-
// brushDialog.dismiss();
297-
// }
298-
// });
299-
// brushDialog.show();
300-
// } else if (view.getId() == R.id.new_btn) {
301-
// //new button
302-
// AlertDialog.Builder newDialog = new AlertDialog.Builder(getContext());
303-
// newDialog.setTitle("New drawing");
304-
// newDialog.setMessage("Start new drawing (you will lose the current drawing)?");
305-
// newDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
306-
// public void onClick(DialogInterface dialog, int which) {
307-
// drawView.startNew();
308-
// dialog.dismiss();
309-
// }
310-
// });
311-
// newDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
312-
// public void onClick(DialogInterface dialog, int which) {
313-
// dialog.cancel();
314-
// }
315-
// });
316-
// newDialog.show();
317-
// } else if (view.getId() == R.id.save_btn) {
318-
// //save drawing
319-
// AlertDialog.Builder saveDialog = new AlertDialog.Builder(getContext());
320-
// saveDialog.setTitle("Save drawing");
321-
// saveDialog.setMessage("Save drawing to device Gallery?");
322-
// saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
323-
// public void onClick(DialogInterface dialog, int which) {
324-
// //save drawing
325-
// drawView.setDrawingCacheEnabled(true);
326-
// //attempt to save
327-
// String imgSaved = MediaStore.Images.Media.insertImage(
328-
// getActivity().getContentResolver(), drawView.getDrawingCache(),
329-
// UUID.randomUUID().toString() + ".png", "drawing");
330-
// //feedback
331-
// if (imgSaved != null) {
332-
// Toast savedToast = Toast.makeText(getContext(),
333-
// "Drawing saved to Gallery!", Toast.LENGTH_SHORT);
334-
// savedToast.show();
335-
// } else {
336-
// Toast unsavedToast = Toast.makeText(getContext(),
337-
// "Oops! Image could not be saved.", Toast.LENGTH_SHORT);
338-
// unsavedToast.show();
339-
// }
340-
// drawView.destroyDrawingCache();
341-
// }
342-
// });
343-
// saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
344-
// public void onClick(DialogInterface dialog, int which) {
345-
// dialog.cancel();
346-
// }
347-
// });
348-
// saveDialog.show();
349-
// }
350-
}
351216
}

0 commit comments

Comments
 (0)