Skip to content

Commit

Permalink
Merge pull request #61 from TonyHaddad91/master
Browse files Browse the repository at this point in the history
Adding ability to change selected text size
  • Loading branch information
ShawnLin013 authored Jun 12, 2017
2 parents 49ef5a2 + 0410a0c commit b0562d3
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ numberPicker.setTextColorResource(R.color.dark_grey);
numberPicker.setTextSize(getResources().getDimension(R.dimen.text_size));
numberPicker.setTextSize(R.dimen.text_size);

// set selected text size
numberPicker.setSelectedTextSize(getResources().getDimension(R.dimen.selected_text_size));
numberPicker.setSelectedTextSize(R.dimen.selected_text_size);

// set typeface
numberPicker.setTypeface(Typeface.create(getString(R.string.roboto_light), Typeface.NORMAL));
numberPicker.setTypeface(getString(R.string.roboto_light), Typeface.NORMAL);
Expand Down Expand Up @@ -68,6 +72,7 @@ add `xmlns:app="http://schemas.android.com/apk/res-auto"`
app:np_selectedTextColor="@color/colorPrimary"
app:np_textColor="@color/colorPrimary"
app:np_textSize="@dimen/text_size"
app:np_selectedTextSize="@dimen/selected_text_size"
app:np_typeface="@string/roboto_light"
app:np_value="3" />
```
Expand All @@ -88,6 +93,7 @@ add `xmlns:app="http://schemas.android.com/apk/res-auto"`
|np_selectedTextColor|The text color of the selected number.|
|np_textColor|The text color of the numbers.|
|np_textSize|The text size of the numbers.|
|np_selectedTextSize|The text size of the selected number.|
|np_typeface|The typeface of the numbers.|
|np_value|The current value of this widget.|
|np_wheelItemCount|The number of items show in the selector wheel.|
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.novoda:bintray-release:0.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 17 00:26:16 CST 2016
#Sat Jun 10 11:18:32 SGT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ public static final Formatter getTwoDigitFormatter() {
*/
private float mTextSize = DEFAULT_TEXT_SIZE;

/**
* The size of the selected text.
*/
private float mSelectedTextSize = DEFAULT_TEXT_SIZE;

/**
* The typeface of the text.
*/
Expand Down Expand Up @@ -585,6 +590,7 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
mSelectedTextColor = attributesArray.getColor(R.styleable.NumberPicker_np_selectedTextColor, mSelectedTextColor);
mTextColor = attributesArray.getColor(R.styleable.NumberPicker_np_textColor, mTextColor);
mTextSize = attributesArray.getDimension(R.styleable.NumberPicker_np_textSize, spToPx(mTextSize));
mSelectedTextSize = attributesArray.getDimension(R.styleable.NumberPicker_np_selectedTextSize, spToPx(mSelectedTextSize));
mTypeface = Typeface.create(attributesArray.getString(R.styleable.NumberPicker_np_typeface), Typeface.NORMAL);
mFormatter = stringToFormatter(attributesArray.getString(R.styleable.NumberPicker_np_formatter));
mWheelItemCount = attributesArray.getInt(R.styleable.NumberPicker_np_wheelItemCount, mWheelItemCount);
Expand Down Expand Up @@ -614,6 +620,7 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
setSelectedTextColor(mSelectedTextColor);
setTextColor(mTextColor);
setTextSize(mTextSize);
setSelectedTextSize(mSelectedTextSize);
setTypeface(mTypeface);
setFormatter(mFormatter);
updateInputTextView();
Expand Down Expand Up @@ -1365,8 +1372,10 @@ protected void onDraw(Canvas canvas) {
int[] selectorIndices = mSelectorIndices;
for (int i = 0; i < selectorIndices.length; i++) {
if (i == mWheelMiddleItemIndex) {
mSelectorWheelPaint.setTextSize(mSelectedTextSize);
mSelectorWheelPaint.setColor(mSelectedTextColor);
} else {
mSelectorWheelPaint.setTextSize(mTextSize);
mSelectorWheelPaint.setColor(mTextColor);
}

Expand Down Expand Up @@ -2072,14 +2081,20 @@ public void setTextColorResource(@ColorRes int colorId) {

public void setTextSize(float textSize) {
mTextSize = textSize;
mSelectedText.setTextSize(pxToSp(mTextSize));
mSelectorWheelPaint.setTextSize(mTextSize);
}

public void setTextSize(@DimenRes int dimenId) {
setTextSize(getResources().getDimension(dimenId));
}
public void setSelectedTextSize(float textSize) {
mSelectedTextSize = textSize;
mSelectedText.setTextSize(pxToSp(mSelectedTextSize));
}

public void setSelectedTextSize(@DimenRes int dimenId) {
setSelectedTextSize(getResources().getDimension(dimenId));
}
public void setTypeface(Typeface typeface) {
mTypeface = typeface;
if (mTypeface != null) {
Expand Down Expand Up @@ -2183,4 +2198,7 @@ public Typeface getTypeface() {
return mTypeface;
}

public float getmSelectedTextSize() {
return mSelectedTextSize;
}
}
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<attr name="np_selectedTextColor" format="color" />
<attr name="np_textColor" format="color" />
<attr name="np_textSize" format="dimension" />
<attr name="np_selectedTextSize" format="dimension" />
<attr name="np_typeface" format="string" />
<attr name="np_value" format="integer" />
<attr name="np_wheelItemCount" format="integer" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ protected void onCreate(Bundle savedInstanceState) {
numberPicker.setTextSize(getResources().getDimension(R.dimen.text_size));
numberPicker.setTextSize(R.dimen.text_size);

// set selected text size
numberPicker.setSelectedTextSize(getResources().getDimension(R.dimen.selected_text_size));
numberPicker.setSelectedTextSize(R.dimen.selected_text_size);

// set typeface
numberPicker.setTypeface(Typeface.create(getString(R.string.roboto_light), Typeface.NORMAL));
numberPicker.setTypeface(getString(R.string.roboto_light), Typeface.NORMAL);
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
app:np_selectedTextColor="@color/colorAccent"
app:np_textColor="@color/colorAccent"
app:np_textSize="@dimen/text_size"
app:np_selectedTextSize="@dimen/selected_text_size"
app:np_typeface="@string/roboto_light" />

</RelativeLayout>
1 change: 1 addition & 0 deletions sample/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<dimen name="fab_margin">16dp</dimen>

<dimen name="text_size">30dp</dimen>
<dimen name="selected_text_size">35dp</dimen>
</resources>

0 comments on commit b0562d3

Please sign in to comment.