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 two APIs for NumberPickerBuilder #347

Open
wants to merge 4 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -51,6 +51,8 @@ public class NumberPicker extends LinearLayout implements Button.OnClickListener
private int mDividerColor;
private int mDeleteDrawableSrcResId;
private int mTheme = -1;
private boolean mDecimalBolding;
private boolean mShowLeftNegSym;

private BigDecimal mMinNumber = null;
private BigDecimal mMaxNumber = null;
Expand Down Expand Up @@ -94,7 +96,7 @@ protected int getLayoutId() {
*
* @param themeResId the resource ID of the new style
*/
public void setTheme(int themeResId) {
public void setTheme(int themeResId, boolean decimalBolding, boolean showNegSymbol) {
mTheme = themeResId;
if (mTheme != -1) {
TypedArray a = getContext().obtainStyledAttributes(themeResId, R.styleable.BetterPickersDialogFragment);
Expand All @@ -105,6 +107,8 @@ public void setTheme(int themeResId) {
mDividerColor = a.getColor(R.styleable.BetterPickersDialogFragment_bpDividerColor, mDividerColor);
mDeleteDrawableSrcResId = a.getResourceId(R.styleable.BetterPickersDialogFragment_bpDeleteIcon, mDeleteDrawableSrcResId);
}
mDecimalBolding = decimalBolding;
mShowLeftNegSym = showNegSymbol;

restyleViews();
}
Expand Down Expand Up @@ -132,7 +136,7 @@ private void restyleViews() {
mDelete.setImageDrawable(getResources().getDrawable(mDeleteDrawableSrcResId));
}
if (mEnteredNumber != null) {
mEnteredNumber.setTheme(mTheme);
mEnteredNumber.setTheme(mTheme, mDecimalBolding, mShowLeftNegSym);
}
if (mLabel != null) {
mLabel.setTextColor(mTextColor);
Expand Down
Expand Up @@ -29,6 +29,8 @@ public class NumberPickerBuilder {
private Integer currentNumberValue;
private Double currentDecimalValue;
private Integer currentSignValue;
private Boolean decimalBolding;
private Boolean showLeftNegSym;
private OnDialogDismissListener mOnDismissListener;

/**
Expand Down Expand Up @@ -134,6 +136,28 @@ public NumberPickerBuilder setMaxNumber(BigDecimal maxNumber) {
return this;
}

/**
* Set whether integer-part of number is bolded with decimal numbers
*
* @param decimalBolding true if integer-part will be bolded
* @return the current Builder object
*/
public NumberPickerBuilder setDecimalBolding(Boolean decimalBolding) {
this.decimalBolding = decimalBolding;
return this;
}

/**
* Set whether negative-symbol is shown left of number, or as superscript
*
* @param showLeftNegSym true if symbol is shown left of number
* @return the current Builder object
*/
public NumberPickerBuilder setShowLeftNegSym(Boolean showLeftNegSym) {
this.showLeftNegSym = showLeftNegSym;
return this;
}

/**
* Set the visibility of the +/- button. This takes an int corresponding to Android's View.VISIBLE, View.INVISIBLE,
* or View.GONE. When using View.INVISIBLE, the +/- button will still be present in the layout but be
Expand Down Expand Up @@ -217,7 +241,8 @@ public void show() {

final NumberPickerDialogFragment fragment = NumberPickerDialogFragment
.newInstance(mReference, styleResId, minNumber, maxNumber, plusMinusVisibility, decimalVisibility,
labelText, currentNumberValue, currentDecimalValue, currentSignValue);
labelText, currentNumberValue, currentDecimalValue, currentSignValue, decimalBolding,
showLeftNegSym);
if (targetFragment != null) {
fragment.setTargetFragment(targetFragment, 0);
}
Expand Down
Expand Up @@ -34,6 +34,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 DECIMAL_BOLDING_KEY = "NumberPickerDialogFragment_DecimalBolding";
private static final String SHOW_LEFT_NEG_SYM_KEY = "NumberPickerDialogFragment_ShowLeftNegSym";

private NumberPicker mPicker;

Expand All @@ -50,6 +52,8 @@ public class NumberPickerDialogFragment extends DialogFragment {
private Integer mCurrentSign = null;
private int mPlusMinusVisibility = View.VISIBLE;
private int mDecimalVisibility = View.VISIBLE;
private boolean mDecimalBolding = true;
private boolean mShowLeftNegSym = false;
private Vector<NumberPickerDialogHandlerV2> mNumberPickerDialogHandlersV2 = new Vector<NumberPickerDialogHandlerV2>();
private OnDialogDismissListener mDismissCallback;

Expand All @@ -75,7 +79,9 @@ public static NumberPickerDialogFragment newInstance(int reference,
String labelText,
Integer currentNumberValue,
Double currentDecimalValue,
Integer currentNumberSign) {
Integer currentNumberSign,
Boolean decimalBolding,
Boolean showLeftNegSym) {
final NumberPickerDialogFragment frag = new NumberPickerDialogFragment();
Bundle args = new Bundle();
args.putInt(REFERENCE_KEY, reference);
Expand Down Expand Up @@ -104,6 +110,12 @@ public static NumberPickerDialogFragment newInstance(int reference,
if (currentNumberSign != null) {
args.putInt(CURRENT_SIGN_KEY, currentNumberSign);
}
if (decimalBolding != null) {
args.putBoolean(DECIMAL_BOLDING_KEY, decimalBolding);
}
if (showLeftNegSym != null) {
args.putBoolean(SHOW_LEFT_NEG_SYM_KEY, showLeftNegSym);
}
frag.setArguments(args);
return frag;
}
Expand Down Expand Up @@ -148,6 +160,12 @@ public void onCreate(Bundle savedInstanceState) {
if (args != null && args.containsKey(CURRENT_SIGN_KEY)) {
mCurrentSign = args.getInt(CURRENT_SIGN_KEY);
}
if (args != null && args.containsKey(DECIMAL_BOLDING_KEY)) {
mDecimalBolding = args.getBoolean(DECIMAL_BOLDING_KEY);
}
if (args != null && args.containsKey(SHOW_LEFT_NEG_SYM_KEY)) {
mShowLeftNegSym = args.getBoolean(SHOW_LEFT_NEG_SYM_KEY);
}

setStyle(DialogFragment.STYLE_NO_TITLE, 0);

Expand Down Expand Up @@ -217,7 +235,7 @@ public void onClick(View view) {

mPicker = (NumberPicker) view.findViewById(R.id.number_picker);
mPicker.setSetButton(doneButton);
mPicker.setTheme(mTheme);
mPicker.setTheme(mTheme, mDecimalBolding, mShowLeftNegSym);
mPicker.setDecimalVisibility(mDecimalVisibility);
mPicker.setPlusMinusVisibility(mPlusMinusVisibility);
mPicker.setLabelText(mLabelText);
Expand Down
Expand Up @@ -18,6 +18,8 @@ public class NumberView extends LinearLayout {
private ZeroTopPaddingTextView mMinusLabel;
private final Typeface mAndroidClockMonoThin;
private Typeface mOriginalNumberTypeface;
private boolean mDecimalBolding;
private boolean mShowLeftNegSym;

private ColorStateList mTextColor;

Expand Down Expand Up @@ -50,13 +52,17 @@ public NumberView(Context context, AttributeSet attrs) {
* Set a theme and restyle the views. This View will change its title color.
*
* @param themeResId the resource ID for theming
* @param decimalBolding true if integer-part will be bolded
* @param showNegSymbol true if symbol is shown left of number
*/
public void setTheme(int themeResId) {
public void setTheme(int themeResId, boolean decimalBolding, boolean showNegSymbol) {
if (themeResId != -1) {
TypedArray a = getContext().obtainStyledAttributes(themeResId, R.styleable.BetterPickersDialogFragment);

mTextColor = a.getColorStateList(R.styleable.BetterPickersDialogFragment_bpTextColor);
}
mDecimalBolding = decimalBolding;
mShowLeftNegSym = showNegSymbol;

restyleViews();
}
Expand Down Expand Up @@ -110,16 +116,17 @@ protected void onFinishInflate() {
*/
public void setNumber(String numbersDigit, String decimalDigit, boolean showDecimal,
boolean isNegative) {
mMinusLabel.setVisibility(isNegative ? View.VISIBLE : View.GONE);
mMinusLabel.setVisibility((isNegative && !mShowLeftNegSym)? View.VISIBLE : View.GONE);
if (mNumber != null) {
if (mShowLeftNegSym && isNegative) numbersDigit = "-" + numbersDigit;
if (numbersDigit.equals("")) {
// Set to -
mNumber.setText("-");
mNumber.setTypeface(mAndroidClockMonoThin);
mNumber.setEnabled(false);
mNumber.updatePadding();
mNumber.setVisibility(View.VISIBLE);
} else if (showDecimal) {
} else if (mDecimalBolding && showDecimal) {
// Set to bold
mNumber.setText(numbersDigit);
mNumber.setTypeface(mOriginalNumberTypeface);
Expand Down