diff --git a/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerBuilder.java b/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerBuilder.java index 371d2a0e..9161beec 100644 --- a/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerBuilder.java +++ b/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerBuilder.java @@ -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. @@ -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. * @@ -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); } diff --git a/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerDialogFragment.java b/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerDialogFragment.java index ebf06a1a..7d28f572 100644 --- a/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerDialogFragment.java +++ b/library/src/main/java/com/codetroopers/betterpickers/numberpicker/NumberPickerDialogFragment.java @@ -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; @@ -49,6 +51,8 @@ public class NumberPickerDialogFragment extends DialogFragment { private int mPlusMinusVisibility = View.VISIBLE; private int mDecimalVisibility = View.VISIBLE; private Vector mNumberPickerDialogHandlersV2 = new Vector(); + private String mCancelText = null; + private String mDoneText = null; /** * Create an instance of the Picker (used internally) @@ -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, @@ -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); @@ -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; } @@ -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); @@ -173,6 +195,9 @@ public void onClick(View view) { dismiss(); } }); + if (mCancelText != null) { + cancelButton.setText(mCancelText); + } doneButton.setTextColor(mTextColor); doneButton.setOnClickListener(new View.OnClickListener() { @@ -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); diff --git a/library/src/main/java/com/codetroopers/betterpickers/radialtimepicker/RadialTimePickerDialogFragment.java b/library/src/main/java/com/codetroopers/betterpickers/radialtimepicker/RadialTimePickerDialogFragment.java index 3c6b3877..7bfd8356 100644 --- a/library/src/main/java/com/codetroopers/betterpickers/radialtimepicker/RadialTimePickerDialogFragment.java +++ b/library/src/main/java/com/codetroopers/betterpickers/radialtimepicker/RadialTimePickerDialogFragment.java @@ -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"; @@ -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); } @@ -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); @@ -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; } @@ -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) diff --git a/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/numberpicker/SampleNumberThemeCustom.java b/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/numberpicker/SampleNumberThemeCustom.java index adb1fa0c..58fcb4d4 100644 --- a/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/numberpicker/SampleNumberThemeCustom.java +++ b/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/numberpicker/SampleNumberThemeCustom.java @@ -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(); } diff --git a/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/radialtimepicker/SampleRadialTimeMinMax.java b/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/radialtimepicker/SampleRadialTimeMinMax.java index 4006a615..26885894 100644 --- a/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/radialtimepicker/SampleRadialTimeMinMax.java +++ b/sample/src/main/java/com/codetroopers/betterpickers/sample/activity/radialtimepicker/SampleRadialTimeMinMax.java @@ -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()) diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 64940b2d..fbd094b2 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -10,6 +10,7 @@ Year: %1$s\nMonth: %2$s\nDay: %3$s Set Time %1$d:%2$d + Today Set Date Year: %1$s\nMonth: %2$s\nDay: %3$s Set Expiration