Preference pen_color = null; Preference canvas_bg_color = null; String pen_width_key; String pen_color_key; CheckBoxPreference pen_style = null; Preference versionName; Preference lastBuildTime; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** * Inflates the settings.xml to this activity. */ addPreferencesFromResource(R.xml.settings); pen_width_key = getResources().getString(R.string.pen_width_key); pen_color_key = getResources().getString(R.string.pen_color_key); /** * Find the target to be handled. */ pen_width = (Preference) findPreference(getResources().getString( R.string.pen_width_key)); pen_color = (Preference) findPreference(getString(R.string.pen_color_key)); versionName = (Preference) findPreference(getString(R.string.setting_about_version_key)); lastBuildTime = (Preference) findPreference(getString(R.string.setting_about_build_key)); versionName.setSummary(getVersionName()); lastBuildTime.setSummary(getLastBuiltTime()); /** * Register the listeners */ pen_width.setOnPreferenceClickListener(this); pen_color.setOnPreferenceClickListener(this); }
- 16 -
private String getLastBuiltTime() { String lastBuiltTimeString = \ try { ApplicationInfo ai = getPackageManager().getApplicationInfo( getPackageName(), 0); ZipFile zf = new ZipFile(ai.sourceDir); ZipEntry ze = zf.getEntry(\ long time = ze.getTime(); lastBuiltTimeString = new SimpleDateFormat(\ .format(new java.util.Date(time)); }
}
catch (Exception e) { // Just leave the last built time to be \}
return lastBuiltTimeString;
private String getVersionName() { String versionName = \ try { versionName = this.getPackageManager().getPackageInfo( getPackageName(), 0).versionName; } catch (NameNotFoundException e) { // Just leave the versionName to be \ } return versionName; }
/**
* Handle the event that the preference is clicked. */
public boolean onPreferenceClick(Preference preference) { if (preference.getKey().equals(pen_color_key))
- 17 -
{ String str = getResources().getString(R.string.tip_choose_color); new ColorPickerDialog(this, this, Brush.getPen().getColor(), str) .show(); } else if (preference.getKey().equals(pen_width_key)) { showSetBrushWidthDialog(); } return true; } /** * Pop up a dialog with SeekBar to control the width of the brush. */ private void showSetBrushWidthDialog() { SeekBarDialog seekBarDialog = new SeekBarDialog(this); seekBarDialog.setTitle(Brush.getPen().getStrokeWidth() + \ seekBarDialog.setButton( getResources().getString(R.string.alert_dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); seekBarDialog.show(); } /** * When brush's color is changed, this method will be called. */ public void colorChanged(int color) { Brush pen = Brush.getPen(); pen.setColor(color); } }
2. package org.vhow.paintpad.setting;
import org.vhow.paintpad.tools.Brush;
- 18 -
import android.app.AlertDialog; import android.content.Context; import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; /**
* Use this class to set the width of the brush. */
public class SeekBarDialog extends AlertDialog { Context context; TextView textView = null; SeekBar seekBar = null; public SeekBarDialog(Context context) { this(context, android.R.style.Theme_Panel); this.context = context; } public SeekBarDialog(Context context, int theme) { super(context, theme); } @Override protected void onCreate(Bundle savedInstanceState) { this.seekBar = new SeekBar(this.context); setSeekBar(); setView(seekBar); super.onCreate(savedInstanceState); } private void setSeekBar() { this.seekBar.setMax(20); this.seekBar.setProgress((int) Brush.getPen().getStrokeWidth()); this.seekBar.setOnSeekBarChangeListener(seekBarListener); }
- 19 -
OnSeekBarChangeListener seekBarListener = new OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar seekBar) { } public void onStartTrackingTouch(SeekBar seekBar) { } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Brush.getPen().setStrokeWidth(progress); SeekBarDialog.this.setTitle(Brush.getPen().getStrokeWidth() + \ } }; /** * @param max * the max width of the brush */ public void setSeekBarMax(int max) { this.seekBar.setMax(max); } public int getSeekBarMax() { return this.seekBar.getMax(); } }
3. package org.vhow.paintpad.helper;
import android.app.Dialog; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Shader;
import android.graphics.SweepGradient;
- 20 -
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Andriod课程设计(4)在线全文阅读。
相关推荐: