Class ColorDialogFragment
(Figs. 7.34–7.38) extends DialogFragment
to create an AlertDialog
for setting the drawing color. The class’s instance variables (lines 19–24) are used to reference the GUI controls for selecting the new color, displaying a preview of it and storing the color as a 32-bit int
value that represents the color’s ARGB values.
1 // ColorDialogFragment.java
2 // Allows user to set the drawing color on the DoodleView
3 package com.deitel.doodlz;
4
5 import android.app.Activity;
6 import android.app.AlertDialog;
7 import android.app.Dialog;
8 import android.app.DialogFragment;
9 import android.content.DialogInterface;
10 import android.graphics.Color;
11 import android.os.Bundle;
12 import android.view.View;
13 import android.widget.SeekBar;
14 import android.widget.SeekBar.OnSeekBarChangeListener;
15
16 // class for the Select Color dialog
17 public class ColorDialogFragment extends DialogFragment
18 {
19 private SeekBar alphaSeekBar;
20 private SeekBar redSeekBar;
21 private SeekBar greenSeekBar;
22 private SeekBar blueSeekBar;
23 private View colorView;
24 private int color;
25