Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added theme usage to radial time picker pre-header #314

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class NumberPickerBuilder {
private Integer currentNumberValue;
private Double currentDecimalValue;
private Integer currentSignValue;
private String mCancelText;
private String mDoneText;

/**
* Attach a FragmentManager. This is required for creation of the Fragment.
Expand Down Expand Up @@ -186,6 +188,28 @@ public NumberPickerBuilder addNumberPickerDialogHandler(NumberPickerDialogHandle
return this;
}

/**
* Sets the text shown on the cancel button. If this text is not set, the default text is shown.
*
* @param cancelText the String text shown on the cancel button
* @return the current Builder object
*/
public NumberPickerBuilder setCancelText(String cancelText) {
this.mCancelText = cancelText;
return this;
}

/**
* Sets the text shown on the done button. If this text is not set, the default text is shown.
*
* @param doneText the String text shown on the done button
* @return the current Builder object
*/
public NumberPickerBuilder setDoneText(String doneText) {
this.mDoneText = doneText;
return this;
}

/**
* Remove objects previously added as handlers.
*
Expand Down Expand Up @@ -215,7 +239,7 @@ public void show() {

final NumberPickerDialogFragment fragment = NumberPickerDialogFragment
.newInstance(mReference, styleResId, minNumber, maxNumber, plusMinusVisibility, decimalVisibility,
labelText, currentNumberValue, currentDecimalValue, currentSignValue);
labelText, currentNumberValue, currentDecimalValue, currentSignValue, mCancelText, mDoneText);
if (targetFragment != null) {
fragment.setTargetFragment(targetFragment, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class NumberPickerDialogFragment extends DialogFragment {
private static final String CURRENT_NUMBER_KEY = "NumberPickerDialogFragment_CurrentNumberKey";
private static final String CURRENT_DECIMAL_KEY = "NumberPickerDialogFragment_CurrentDecimalKey";
private static final String CURRENT_SIGN_KEY = "NumberPickerDialogFragment_CurrentSignKey";
private static final String CANCEL_TEXT = "NumberPickerDialogFragment_CancelText";
private static final String DONE_TEXT = "NumberPickerDialogFragment_DoneText";

private NumberPicker mPicker;

Expand All @@ -49,6 +51,8 @@ public class NumberPickerDialogFragment extends DialogFragment {
private int mPlusMinusVisibility = View.VISIBLE;
private int mDecimalVisibility = View.VISIBLE;
private Vector<NumberPickerDialogHandlerV2> mNumberPickerDialogHandlersV2 = new Vector<NumberPickerDialogHandlerV2>();
private String mCancelText = null;
private String mDoneText = null;

/**
* Create an instance of the Picker (used internally)
Expand All @@ -60,6 +64,8 @@ public class NumberPickerDialogFragment extends DialogFragment {
* @param plusMinusVisibility (optional) View.VISIBLE, View.INVISIBLE, or View.GONE
* @param decimalVisibility (optional) View.VISIBLE, View.INVISIBLE, or View.GONE
* @param labelText (optional) text to add as a label
* @param cancelText (optional) text shown on the cancel button
* @param doneText (optional) text shown on the done button
* @return a Picker!
*/
public static NumberPickerDialogFragment newInstance(int reference,
Expand All @@ -71,7 +77,9 @@ public static NumberPickerDialogFragment newInstance(int reference,
String labelText,
Integer currentNumberValue,
Double currentDecimalValue,
Integer currentNumberSign) {
Integer currentNumberSign,
String cancelText,
String doneText) {
final NumberPickerDialogFragment frag = new NumberPickerDialogFragment();
Bundle args = new Bundle();
args.putInt(REFERENCE_KEY, reference);
Expand Down Expand Up @@ -100,6 +108,12 @@ public static NumberPickerDialogFragment newInstance(int reference,
if (currentNumberSign != null) {
args.putInt(CURRENT_SIGN_KEY, currentNumberSign);
}
if (cancelText != null) {
args.putString(CANCEL_TEXT, cancelText);
}
if (doneText != null) {
args.putString(DONE_TEXT, doneText);
}
frag.setArguments(args);
return frag;
}
Expand All @@ -114,35 +128,43 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle args = getArguments();
if (args != null && args.containsKey(REFERENCE_KEY)) {
mReference = args.getInt(REFERENCE_KEY);
}
if (args != null && args.containsKey(THEME_RES_ID_KEY)) {
mTheme = args.getInt(THEME_RES_ID_KEY);
}
if (args != null && args.containsKey(PLUS_MINUS_VISIBILITY_KEY)) {
mPlusMinusVisibility = args.getInt(PLUS_MINUS_VISIBILITY_KEY);
}
if (args != null && args.containsKey(DECIMAL_VISIBILITY_KEY)) {
mDecimalVisibility = args.getInt(DECIMAL_VISIBILITY_KEY);
}
if (args != null && args.containsKey(MIN_NUMBER_KEY)) {
mMinNumber = (BigDecimal) args.getSerializable(MIN_NUMBER_KEY);
}
if (args != null && args.containsKey(MAX_NUMBER_KEY)) {
mMaxNumber = (BigDecimal) args.getSerializable(MAX_NUMBER_KEY);
}
if (args != null && args.containsKey(LABEL_TEXT_KEY)) {
mLabelText = args.getString(LABEL_TEXT_KEY);
}
if (args != null && args.containsKey(CURRENT_NUMBER_KEY)) {
mCurrentNumber = args.getInt(CURRENT_NUMBER_KEY);
}
if (args != null && args.containsKey(CURRENT_DECIMAL_KEY)) {
mCurrentDecimal = args.getDouble(CURRENT_DECIMAL_KEY);
}
if (args != null && args.containsKey(CURRENT_SIGN_KEY)) {
mCurrentSign = args.getInt(CURRENT_SIGN_KEY);
if (args != null) {
if (args.containsKey(REFERENCE_KEY)) {
mReference = args.getInt(REFERENCE_KEY);
}
if (args.containsKey(THEME_RES_ID_KEY)) {
mTheme = args.getInt(THEME_RES_ID_KEY);
}
if (args.containsKey(PLUS_MINUS_VISIBILITY_KEY)) {
mPlusMinusVisibility = args.getInt(PLUS_MINUS_VISIBILITY_KEY);
}
if (args.containsKey(DECIMAL_VISIBILITY_KEY)) {
mDecimalVisibility = args.getInt(DECIMAL_VISIBILITY_KEY);
}
if (args.containsKey(MIN_NUMBER_KEY)) {
mMinNumber = (BigDecimal) args.getSerializable(MIN_NUMBER_KEY);
}
if (args.containsKey(MAX_NUMBER_KEY)) {
mMaxNumber = (BigDecimal) args.getSerializable(MAX_NUMBER_KEY);
}
if (args.containsKey(LABEL_TEXT_KEY)) {
mLabelText = args.getString(LABEL_TEXT_KEY);
}
if (args.containsKey(CURRENT_NUMBER_KEY)) {
mCurrentNumber = args.getInt(CURRENT_NUMBER_KEY);
}
if (args.containsKey(CURRENT_DECIMAL_KEY)) {
mCurrentDecimal = args.getDouble(CURRENT_DECIMAL_KEY);
}
if (args.containsKey(CURRENT_SIGN_KEY)) {
mCurrentSign = args.getInt(CURRENT_SIGN_KEY);
}
if (args.containsKey(CANCEL_TEXT)) {
mCancelText = args.getString(CANCEL_TEXT);
}
if (args.containsKey(DONE_TEXT)) {
mDoneText = args.getString(DONE_TEXT);
}
}

setStyle(DialogFragment.STYLE_NO_TITLE, 0);
Expand Down Expand Up @@ -173,6 +195,9 @@ public void onClick(View view) {
dismiss();
}
});
if (mCancelText != null) {
cancelButton.setText(mCancelText);
}

doneButton.setTextColor(mTextColor);
doneButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -210,6 +235,9 @@ public void onClick(View view) {
dismiss();
}
});
if (mDoneText != null) {
doneButton.setText(mDoneText);
}

mPicker = (NumberPicker) view.findViewById(R.id.number_picker);
mPicker.setSetButton(doneButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class RadialTimePickerDialogFragment extends DialogFragment implements On
private static final String KEY_IN_KB_MODE = "in_kb_mode";
private static final String KEY_TYPED_TIMES = "typed_times";
private static final String KEY_STYLE = "theme";
private static final String KEY_TITLE_TEXT = "title_text";
private static final String KEY_FUTURE_MINUTES_LIMIT = "future_minutes_limit";
private static final String KEY_PAST_MINUTES_LIMIT = "past_minutes_limit";
private static final String KEY_CURRENT_DATE = "current_date";
Expand Down Expand Up @@ -270,6 +271,9 @@ public void onCreate(Bundle savedInstanceState) {
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
mStyleResId = savedInstanceState.getInt(KEY_STYLE);
if (savedInstanceState.containsKey(KEY_TITLE_TEXT)) {
mTitleText = savedInstanceState.getString(KEY_TITLE_TEXT);
}
if (savedInstanceState.containsKey(KEY_FUTURE_MINUTES_LIMIT)) {
mFutureMinutesLimit = savedInstanceState.getInt(KEY_FUTURE_MINUTES_LIMIT);
}
Expand Down Expand Up @@ -304,6 +308,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

// Prepare some colors to use.
int headerBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderBackgroundColor, R.color.bpBlue);
int preHeaderBackgroundColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpPreHeaderBackgroundColor, R.color.bpWhite);
int bodyBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpBodyBackgroundColor, R.color.bpWhite);
int buttonBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsBackgroundColor, R.color.bpWhite);
int buttonTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsTextColor, R.color.bpBlue);
Expand Down Expand Up @@ -462,6 +467,7 @@ public void onClick(View v) {
((TextView) view.findViewById(R.id.separator)).setTextColor(mUnselectedColor);
((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mUnselectedColor);
mTimePicker.setBackgroundColor(bodyBgColor);
mTitleTextView.setBackgroundColor(preHeaderBackgroundColor);
return view;
}

Expand Down Expand Up @@ -507,6 +513,8 @@ public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
outState.putInt(KEY_CURRENT_ITEM_SHOWING, mTimePicker.getCurrentItemShowing());
outState.putBoolean(KEY_IN_KB_MODE, mInKbMode);
if (mTitleText != null)
outState.putString(KEY_TITLE_TEXT, mTitleText);
if (mFutureMinutesLimit != null)
outState.putInt(KEY_FUTURE_MINUTES_LIMIT, mFutureMinutesLimit);
if (mPastMinutesLimit != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public void onCreate(Bundle savedInstanceState) {
public void onClick(View v) {
NumberPickerBuilder npb = new NumberPickerBuilder()
.setFragmentManager(getSupportFragmentManager())
.setCancelText(getString(R.string.button_label_custom_cancel))
.setDoneText(getString(R.string.button_label_custom_ok))
.setStyleResId(R.style.MyCustomBetterPickerTheme);
npb.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void onCreate(Bundle savedInstanceState) {
public void onClick(View v) {
RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment()
.setOnTimeSetListener(SampleRadialTimeMinMax.this)
.setTitleText(getString(R.string.radial_time_picker_title_today).toUpperCase())
.setFutureMinutesLimit(60)
.setPastMinutesLimit(60)
.setValidateDateTime(Calendar.getInstance())
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="calendar_date_picker_result_values">Year: %1$s\nMonth: %2$s\nDay: %3$s</string>
<string name="radial_time_picker">Set Time</string>
<string name="radial_time_picker_result_value">%1$d:%2$d</string>
<string name="radial_time_picker_title_today">Today</string>
<string name="date_picker_set">Set Date</string>
<string name="date_picker_result_value">Year: %1$s\nMonth: %2$s\nDay: %3$s</string>
<string name="expiration_picker_set">Set Expiration</string>
Expand Down