Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
allow for custom titles
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Feb 7, 2019
1 parent 3cbfd55 commit 5a1b0be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(View v) {
new ColorPickerDialog()
.withColor(color)
.withTitle("Example Color Picker")
.withCornerRadius(16)
.withAlphaEnabled(v.getId() != R.id.normal)
.withPresets(v.getId() == R.id.normalAlpha ? new int[]{0, 0x50ffffff, 0x50000000} : new int[]{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ protected void init() {
}

@Override
protected String getTitle() {
return getString(R.string.colorPickerDialog_dialogName);
public String getTitle() {
String title = super.getTitle();
return title != null ? title : getString(R.string.colorPickerDialog_dialogName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
abstract class PickerDialog<T extends PickerDialog> extends AppCompatDialogFragment implements OnColorPickedListener<PickerView>, ActivityRequestHandler, PickerTheme {

private static final String INST_KEY_COLOR = "me.jfenn.colorpickerdialog.INST_KEY_COLOR";
private static final String INST_KEY_TITLE = "me.jfenn.colorpickerdialog.INST_KEY_TITLE";
private static final String INST_KEY_CORNER_RADIUS = "me.jfenn.colorpickerdialog.INST_KEY_CORNER_RADIUS";

@ColorInt
private int color = Color.BLACK;

private String title;
private int cornerRadius;

private OnColorPickedListener<T> listener;
Expand All @@ -50,8 +53,6 @@ public PickerDialog() {

protected abstract void init();

protected abstract String getTitle();

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -88,6 +89,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
color = savedInstanceState.getInt(INST_KEY_COLOR, color);
title = savedInstanceState.getString(INST_KEY_TITLE, title);
cornerRadius = savedInstanceState.getInt(INST_KEY_CORNER_RADIUS, cornerRadius);
}
}
Expand All @@ -96,6 +98,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(INST_KEY_COLOR, color);
outState.putString(INST_KEY_TITLE, title);
outState.putInt(INST_KEY_CORNER_RADIUS, cornerRadius);
}

Expand Down Expand Up @@ -136,6 +139,28 @@ public int getColor() {
return color;
}

/**
* Specify a title for the dialog. Passing "null" will set the dialog to
* its default title.
*
* @param title The (string) title of the dialog.
* @return "This" dialog instance, for method chaining.
*/
public T withTitle(@Nullable String title) {
this.title = title;
return (T) this;
}

/**
* Get the current title of the dialog; "null" if there is not one set.
*
* @return The title of the dialog.
*/
@Nullable
public String getTitle() {
return title;
}

/**
* Specify a theme/style of the dialog. Defaults to @style/ColorPickerDialog
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ protected void init() {
}

@Override
protected String getTitle() {
return getString(R.string.colorPickerDialog_imageColorPicker);
public String getTitle() {
String title = super.getTitle();
return title != null ? title : getString(R.string.colorPickerDialog_imageColorPicker);
}

/**
Expand Down

0 comments on commit 5a1b0be

Please sign in to comment.