Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.

Commit 071e52e

Browse files
committed
Setting text's size, style and typeface are added.
1 parent 619629c commit 071e52e

File tree

8 files changed

+109
-59
lines changed

8 files changed

+109
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ and:
3636

3737
```gradle
3838
dependencies {
39-
compile 'com.github.ceryle:RadioRealButton:v1.4.3'
39+
compile 'com.github.ceryle:RadioRealButton:v1.4.4'
4040
}
4141
```
4242

library/src/main/java/co/ceryle/radiorealbutton/library/RadioRealButton.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
import android.content.Context;
2020
import android.content.res.TypedArray;
2121
import android.graphics.Color;
22+
import android.graphics.Typeface;
2223
import android.os.Build;
2324
import android.util.AttributeSet;
24-
import android.view.Gravity;
25+
import android.util.TypedValue;
2526
import android.view.View;
2627
import android.view.ViewGroup;
2728
import android.view.animation.Interpolator;
@@ -94,9 +95,9 @@ public interface OnClickedButton {
9495
void onClickedButton(View view);
9596
}
9697

97-
private int buttonImage, buttonImageTint, buttonTextColor, buttonBackgroundColor, buttonRippleColor, buttonImageWidth, buttonImageHeight, buttonPadding, buttonPaddingLeft, buttonPaddingRight, buttonPaddingTop, buttonPaddingBottom, marginBetweenImgAndText;
98+
private int buttonTextStyle, buttonTextSize, buttonImage, buttonImageTint, buttonTextColor, buttonBackgroundColor, buttonRippleColor, buttonImageWidth, buttonImageHeight, buttonPadding, buttonPaddingLeft, buttonPaddingRight, buttonPaddingTop, buttonPaddingBottom, marginBetweenImgAndText;
9899

99-
private String buttonText;
100+
private String buttonText, buttonTextTypeface;
100101
private boolean buttonRipple, hasPadding, hasPaddingLeft, hasPaddingRight, hasPaddingTop, hasPaddingBottom, hasButtonImageTint, hasImage, hasText;
101102

102103

@@ -142,6 +143,10 @@ private void getAttributes(AttributeSet attrs) {
142143
imageTop = typedArray.getBoolean(R.styleable.RadioRealButton_rrb_imageTop, false);
143144
imageBottom = typedArray.getBoolean(R.styleable.RadioRealButton_rrb_imageBottom, false);
144145

146+
buttonTextSize = typedArray.getDimensionPixelSize(R.styleable.RadioRealButton_rrb_textSize, -1);
147+
buttonTextStyle = typedArray.getInt(R.styleable.RadioRealButton_rrb_textStyle, -1);
148+
buttonTextTypeface = typedArray.getString(R.styleable.RadioRealButton_rrb_textTypeface);
149+
145150
typedArray.recycle();
146151
}
147152

@@ -170,6 +175,12 @@ private void setImageAttrs() {
170175
private void setTextAttrs() {
171176
textView.setText(buttonText);
172177
textView.setTextColor(buttonTextColor);
178+
179+
setTextSize(buttonTextSize);
180+
setTextStyle(buttonTextStyle);
181+
setTextTypeface(buttonTextTypeface);
182+
183+
173184
}
174185

175186
private void setOtherAttrs() {
@@ -255,7 +266,7 @@ else if (imageBottom)
255266
protected void bounceImage(float scale, int duration, Interpolator interpolator) {
256267
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
257268
imageView.animate().setDuration(duration).setInterpolator(interpolator).scaleXBy(scale).scaleYBy(scale);
258-
}else{
269+
} else {
259270
imageView.setScaleX(scale);
260271
textView.setScaleY(scale);
261272
}
@@ -264,12 +275,35 @@ protected void bounceImage(float scale, int duration, Interpolator interpolator)
264275
protected void bounceText(float scale, int duration, Interpolator interpolator) {
265276
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
266277
textView.animate().setDuration(duration).setInterpolator(interpolator).scaleXBy(scale).scaleYBy(scale);
267-
}else{
278+
} else {
268279
textView.setScaleX(scale);
269280
textView.setScaleY(scale);
270281
}
271282
}
272283

284+
public void setTextSize(float size) {
285+
if (size > -1)
286+
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
287+
}
288+
289+
public void setTextStyle(int typeface) {
290+
if (typeface > -1 && typeface < 4) {
291+
int[] typefaces = {Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC};
292+
textView.setTypeface(textView.getTypeface(), typefaces[typeface]);
293+
}
294+
}
295+
296+
public void setTextTypeface(Typeface typeface) {
297+
textView.setTypeface(typeface);
298+
}
299+
300+
public void setTextTypeface(String location) {
301+
if (null != location && !location.equals("")) {
302+
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), location);
303+
textView.setTypeface(typeface);
304+
}
305+
}
306+
273307
// Direct access to imageView if it is needed
274308
public ImageView getImageView() {
275309
return imageView;

library/src/main/java/co/ceryle/radiorealbutton/library/RadioRealButtonGroup.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import android.support.v4.view.animation.FastOutSlowInInterpolator;
2626
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
2727
import android.util.AttributeSet;
28-
import android.util.Log;
2928
import android.view.Gravity;
3029
import android.view.View;
3130
import android.view.ViewGroup;

library/src/main/res/values/attrs.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<attr name="rrb_imageTint" format="color"/>
66
<attr name="rrb_imageWidth" format="dimension"/>
77
<attr name="rrb_imageHeight" format="dimension"/>
8+
89
<attr name="rrb_buttonPadding" format="dimension"/>
910
<attr name="rrb_buttonPaddingLeft" format="dimension"/>
1011
<attr name="rrb_buttonPaddingRight" format="dimension"/>
@@ -18,6 +19,14 @@
1819

1920
<attr name="rrb_text" format="string"/>
2021
<attr name="rrb_textColor" format="color"/>
22+
<attr name="rrb_textSize" format="dimension"/>
23+
<attr name="rrb_textStyle" format="integer">
24+
<flag name="bold" value="1"/>
25+
<flag name="italic" value="2"/>
26+
<flag name="normal" value="0"/>
27+
</attr>
28+
<attr name="rrb_textTypeface" format="string"/>
29+
2130
<attr name="rrb_marginBetweenImageAndText" format="dimension"/>
2231

2332
<attr name="rrb_imageLeft" format="boolean"/>
@@ -66,10 +75,6 @@
6675
<attr name="rrbg_position" format="integer"/>
6776

6877

69-
70-
71-
72-
7378
<attr name="rrbg_animateSelectorDuration" format="integer"/>
7479
<attr name="rrbg_animateSelector" format="integer">
7580
<flag name="fastOutSlowIn" value="0"/>
114 KB
Binary file not shown.
26.6 KB
Binary file not shown.

sample/src/main/java/co/ceryle/radiorealbutton/MainActivity.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,46 @@
1919
import android.os.Bundle;
2020
import android.view.View;
2121
import android.widget.Button;
22-
import android.widget.Toast;
2322

2423
import co.ceryle.radiorealbutton.library.RadioRealButtonGroup;
2524

2625
public class MainActivity extends AppCompatActivity {
2726

28-
private int position;
27+
private Button button;
28+
private RadioRealButtonGroup rrbg;
2929

3030
@Override
3131
protected void onCreate(Bundle savedInstanceState) {
3232
super.onCreate(savedInstanceState);
3333
setContentView(R.layout.activity_main);
3434

35-
final RadioRealButtonGroup rrbg = (RadioRealButtonGroup) findViewById(R.id.radioRealButtonGroup_1);
35+
button = (Button) findViewById(R.id.button);
36+
rrbg = (RadioRealButtonGroup) findViewById(R.id.radioRealButtonGroup_1);
37+
38+
button.setTransformationMethod(null);
39+
setPosition(rrbg.getPosition());
40+
41+
3642
rrbg.setOnClickedButtonPosition(new RadioRealButtonGroup.OnClickedButtonPosition() {
3743
@Override
3844
public void onClickedButtonPosition(int position) {
39-
Toast.makeText(MainActivity.this, "Clicked position: " + position, Toast.LENGTH_SHORT).show();
45+
setPosition(position);
4046
}
4147
});
4248

43-
final Button b = (Button) findViewById(R.id.button);
44-
b.setTransformationMethod(null);
45-
position = rrbg.getPosition();
46-
b.setText("Position: " + position);
47-
b.setOnClickListener(new View.OnClickListener() {
49+
button.setOnClickListener(new View.OnClickListener() {
4850
@Override
4951
public void onClick(View v) {
52+
int position = rrbg.getPosition();
5053
position = ++position % rrbg.getNumberOfButton();
5154
rrbg.setPositionWithAnimation(position);
5255

53-
b.setText("Position: " + rrbg.getPosition());
56+
setPosition(position);
5457
}
5558
});
5659
}
60+
61+
private void setPosition(int position) {
62+
button.setText("Position: " + position);
63+
}
5764
}

0 commit comments

Comments
 (0)