├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── cqmc
│ │ └── badgeradiobutton
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── cqmc
│ │ │ └── badgeradiobutton
│ │ │ ├── MainActivity.java
│ │ │ └── widget
│ │ │ ├── BadgeRadioButton.java
│ │ │ ├── DrawableCenterRadioButton.java
│ │ │ ├── DrawableCenterTextView.java
│ │ │ └── MeasureTextView.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ └── ic_main_user_normal.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── cqmc
│ └── badgeradiobutton
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .idea
8 | .DS_Store
9 | /build
10 | /captures
11 | .externalNativeBuild
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BadgeRadioButton-
2 | 带角标的RadioButton
3 |
4 | # 显示效果
5 | 
6 |
7 | # 增加可自定义的方法
8 |
9 | 方法名 | 默认值 | 使用效果
10 | ---|---|---
11 | setBadgeNum | null | 设置角标数字,>=0就显示,没有就不显示
12 | setBadgeText | null | 设置角标文本
13 | setBadgeTextSize | 8sp | 设置角标字体大小
14 | setBadgePadding | 4dp |设置角标的内边距,最大不能超过布局边距
15 | setBadgeShowShadow | true |角标是否显示阴影
16 | setBadgeColorBackground | Red |设置角标的背景颜色
17 | setBadgeColorBadgeText | White |设置角标的字体颜色
18 | setBadgeOffX | 0 |设置X偏移量
19 | setBadgeOffY | 0 |设置Y偏移量
20 | setBadgeGravity | 0 |设置位置
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.0"
6 | defaultConfig {
7 | applicationId "com.cqmc.badgeradiobutton"
8 | minSdkVersion 14
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:26.+'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in F:\Users\Administrator\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/cqmc/badgeradiobutton/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.cqmc.badgeradiobutton;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.cqmc.badgeradiobutton", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cqmc/badgeradiobutton/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.cqmc.badgeradiobutton;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.Gravity;
7 |
8 | import com.cqmc.badgeradiobutton.widget.BadgeRadioButton;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | /** 首页 */
13 | private BadgeRadioButton mBrbMain0;
14 | /** 首页 */
15 | private BadgeRadioButton mBrbMain1;
16 | /** 首页 */
17 | private BadgeRadioButton mBrbMain2;
18 | /** 首页 */
19 | private BadgeRadioButton mBrbMain3;
20 | /** 首页 */
21 | private BadgeRadioButton mBrbMain4;
22 | /** 首页 */
23 | private BadgeRadioButton mBrbMain5;
24 | /** 首页 */
25 | private BadgeRadioButton mBrbMain6;
26 | /** 首页 */
27 | private BadgeRadioButton mBrbMain7;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_main);
33 | initView();
34 | }
35 |
36 | private void initView() {
37 | mBrbMain0 = (BadgeRadioButton) findViewById(R.id.brb_main_0);
38 | mBrbMain1 = (BadgeRadioButton) findViewById(R.id.brb_main_1);
39 | mBrbMain2 = (BadgeRadioButton) findViewById(R.id.brb_main_2);
40 | mBrbMain3 = (BadgeRadioButton) findViewById(R.id.brb_main_3);
41 | mBrbMain4 = (BadgeRadioButton) findViewById(R.id.brb_main_4);
42 | mBrbMain5 = (BadgeRadioButton) findViewById(R.id.brb_main_5);
43 | mBrbMain6 = (BadgeRadioButton) findViewById(R.id.brb_main_6);
44 | mBrbMain7 = (BadgeRadioButton) findViewById(R.id.brb_main_7);
45 |
46 | mBrbMain0.setBadgeNumber(1);
47 | mBrbMain1.setBadgeNumber(10).setBadgeColorBackground(Color.GREEN);
48 | mBrbMain2.setBadgeNumber(100).setBadgeOffX(10).setBadgeColorBadgeText(Color.BLUE);
49 | mBrbMain3.setBadgeNumber(0).setBadgeOffX(-10).setBadgeOffY(10);
50 | mBrbMain4.setBadgeText("new");
51 | mBrbMain5.setBadgeText("免费");
52 | mBrbMain6.setBadgeText("free").setBadgeGravity(Gravity.LEFT);
53 | mBrbMain7.setBadgeText("free").setBadgeGravity(Gravity.RIGHT);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cqmc/badgeradiobutton/widget/BadgeRadioButton.java:
--------------------------------------------------------------------------------
1 | package com.cqmc.badgeradiobutton.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.graphics.Typeface;
11 | import android.graphics.drawable.Drawable;
12 | import android.support.annotation.ColorInt;
13 | import android.text.TextPaint;
14 | import android.text.TextUtils;
15 | import android.util.AttributeSet;
16 | import android.view.Gravity;
17 | import android.view.View;
18 |
19 |
20 | /**
21 | *
带标记的 RadioButton,目前仅支持 drawableTop 的按钮 right的没测试
22 | *
23 | * @author - lwc
24 | * @date - 2017/6/14
25 | * @note -
26 | * 使用时直接 setBadgeNum
27 | * setBadgeTextSize -- 设置字体颜色
28 | * setBadgePadding -- 设置内边距
29 | * setBadgeShowShadow -- 设置是否显示阴影
30 | * setBadgeColorBackground -- 设置背景颜色
31 | * setBadgeColorBadgeText -- 设置字体颜色
32 | * setBadgeExact -- 设置是否截取图标
33 | * setBadgeOffX -- 设置X的偏移量
34 | * setBadgeOffY -- 设置Y的偏移量
35 | * -------------------------------------------------------------------------------------------------
36 | * @modified - lwc
37 | * @date - 2017/12/14
38 | * @note -
39 | * setBadgeText -- 设置文本
40 | * setBadgeGravity -- 设置标记的位置
41 | */
42 | public class BadgeRadioButton extends DrawableCenterRadioButton {
43 | /** 字体高度 */
44 | private float mFontHeight;
45 | /** 字体宽度 */
46 | private float mFontWidth;
47 | /** 位图集合 */
48 | private Drawable[] mDrawables;
49 | /** 位图 */
50 | private Drawable mDrawableBackground;
51 | /** 背景画笔 */
52 | private Paint mBadgeBackgroundPaint;
53 | /** 数字画笔 */
54 | private Paint mBadgeTextPaint;
55 | /** 数字字体大小 默认8sp */
56 | private float mBadgeTextSize;
57 | /** 内边距 默认4dp */
58 | private int mBadgePadding;
59 | /** x偏移量 */
60 | private int mBadgeOffX;
61 | /** Y偏移量 */
62 | private int mBadgeOffY;
63 | /** 数字 */
64 | private int mBadgeNumber;
65 | /** 数字文本 */
66 | private String mBadgeText;
67 | /** 是否存在阴影 默认存在 */
68 | private boolean mBadgeShowShadow;
69 | /** 背景颜色 默认红色 */
70 | private int mBadgeColorBackground;
71 | /** 字体颜色 默认白色 */
72 | private int mBadgeColorBadgeText;
73 | /** 是否截取数字 */
74 | private boolean mBadgeExact;
75 | /** 背景矩形 */
76 | private RectF mBadgeBackgroundRect;
77 | /** 位置,默认中心 */
78 | private int mGravity = Gravity.CENTER;
79 |
80 | /**
81 | * 构造函数
82 | *
83 | * @param context 上下文
84 | */
85 | public BadgeRadioButton(Context context) {
86 | super(context);
87 | init();
88 | }
89 |
90 | /**
91 | * 构造函数
92 | *
93 | * @param context 上下文
94 | * @param attrs 属性
95 | */
96 | public BadgeRadioButton(Context context, AttributeSet attrs) {
97 | super(context, attrs);
98 | init();
99 | }
100 |
101 | /**
102 | * 构造函数
103 | *
104 | * @param context 上下文
105 | * @param attrs 属性
106 | * @param defStyle 样式
107 | */
108 | public BadgeRadioButton(Context context, AttributeSet attrs, int defStyle) {
109 | super(context, attrs, defStyle);
110 | init();
111 | }
112 |
113 | @Override
114 | protected void onDraw(Canvas canvas) {
115 | super.onDraw(canvas);
116 | if (null != mDrawableBackground && null != mBadgeText) {
117 | showShadowImpl(mBadgeShowShadow, mBadgeBackgroundPaint);
118 | float maxPadding = getOffSize();
119 | if (mBadgePadding > maxPadding) {
120 | if (mBadgePadding - maxPadding > mBadgeOffY) {
121 | mBadgeOffY = (int) (mBadgePadding - maxPadding);
122 | }
123 | }
124 | drawWithDrawable(canvas);
125 | } else if (null == mDrawableBackground && null != mBadgeText) {
126 | showShadowImpl(mBadgeShowShadow, mBadgeBackgroundPaint);
127 | float maxPadding = getOffSize();
128 | if (mBadgePadding > maxPadding) {
129 | if (mBadgePadding - maxPadding > mBadgeOffY) {
130 | mBadgeOffY = (int) (mBadgePadding - maxPadding);
131 | }
132 | }
133 | drawWithNoDrawable(canvas);
134 | }
135 | }
136 |
137 | /**
138 | * 无图标时候,绘制标签
139 | *
140 | * @param canvas 画布
141 | */
142 | private void drawWithNoDrawable(Canvas canvas) {
143 | float textWidth = getPaint().measureText(getText().toString());
144 | if (mBadgeText.length() == 0) {
145 | //绘制圆
146 | if (mGravity == Gravity.CENTER) {
147 | canvas.drawCircle((getWidth() + textWidth) / 2 + mBadgeOffX, mFontHeight / 2 + mBadgeOffY, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
148 | } else if (mGravity == Gravity.RIGHT) {
149 | canvas.drawCircle(getWidth() - mFontWidth / 2 - mBadgePadding, mFontHeight / 2 + mBadgeOffY, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
150 | } else if (mGravity == Gravity.LEFT) {
151 | canvas.drawCircle(mFontWidth / 2 + mBadgePadding, mFontHeight / 2 + mBadgeOffY, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
152 | }
153 | } else {
154 | //多个字符,绘制椭圆
155 | mBadgeBackgroundRect.left = (getWidth() + textWidth) / 2 - mFontWidth / 2 - mBadgePadding + mBadgeOffX;
156 | mBadgeBackgroundRect.right = (getWidth() + textWidth) / 2 + mFontWidth / 2 + mBadgePadding + mBadgeOffX;
157 | mBadgeBackgroundRect.top = -mBadgePadding + mBadgeOffY;
158 | mBadgeBackgroundRect.bottom = mFontHeight + mBadgePadding + mBadgeOffY;
159 | if (mGravity == Gravity.RIGHT) {
160 | mBadgeBackgroundRect.left = getWidth() - mFontWidth - mBadgePadding * 2;
161 | mBadgeBackgroundRect.right = getWidth();
162 | } else if (mGravity == Gravity.LEFT) {
163 | mBadgeBackgroundRect.left = 0;
164 | mBadgeBackgroundRect.right = mFontWidth + mBadgePadding * 2;
165 | }
166 | canvas.drawRoundRect(mBadgeBackgroundRect, mFontHeight / 2 + mBadgePadding, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
167 | }
168 | //绘制文本
169 | if (mGravity == Gravity.RIGHT) {
170 | canvas.drawText(mBadgeText, getWidth() - mFontWidth - mBadgePadding, mFontHeight + mBadgeOffY, mBadgeTextPaint);
171 | } else if (mGravity == Gravity.LEFT) {
172 | canvas.drawText(mBadgeText, mBadgePadding, mFontHeight + mBadgeOffY, mBadgeTextPaint);
173 | } else {
174 | canvas.drawText(mBadgeText, (getWidth() + textWidth) / 2 - mFontWidth / 2 + mBadgeOffX, mFontHeight + mBadgeOffY, mBadgeTextPaint);
175 | }
176 | }
177 |
178 | /**
179 | * 有图标时候,绘制标签
180 | *
181 | * @param canvas 画布
182 | */
183 | private void drawWithDrawable(Canvas canvas) {
184 | if (mBadgeText.length() == 0) {
185 | //绘制圆
186 | if (mGravity == Gravity.CENTER) {
187 | canvas.drawCircle((getWidth() + mDrawableBackground.getIntrinsicWidth()) / 2 + mBadgeOffX, mFontHeight / 2 + mBadgeOffY, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
188 | } else if (mGravity == Gravity.RIGHT) {
189 | canvas.drawCircle(getWidth() - mFontWidth / 2 - mBadgePadding, mFontHeight / 2 + mBadgeOffY, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
190 | } else if (mGravity == Gravity.LEFT) {
191 | canvas.drawCircle(mFontWidth / 2 + mBadgePadding, mFontHeight / 2 + mBadgeOffY, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
192 | }
193 | } else {
194 | //多个字符,绘制椭圆
195 | mBadgeBackgroundRect.left = (getWidth() + mDrawableBackground.getIntrinsicWidth()) / 2 - mFontWidth / 2 - mBadgePadding + mBadgeOffX;
196 | mBadgeBackgroundRect.right = (getWidth() + mDrawableBackground.getIntrinsicWidth()) / 2 + mFontWidth / 2 + mBadgePadding + mBadgeOffX;
197 | mBadgeBackgroundRect.top = -mBadgePadding + mBadgeOffY;
198 | mBadgeBackgroundRect.bottom = mFontHeight + mBadgePadding + mBadgeOffY;
199 | if (mGravity == Gravity.RIGHT) {
200 | mBadgeBackgroundRect.left = getWidth() - mFontWidth - mBadgePadding * 2;
201 | mBadgeBackgroundRect.right = getWidth();
202 | } else if (mGravity == Gravity.LEFT) {
203 | mBadgeBackgroundRect.left = 0;
204 | mBadgeBackgroundRect.right = mFontWidth + mBadgePadding * 2;
205 | }
206 | canvas.drawRoundRect(mBadgeBackgroundRect, mFontHeight / 2 + mBadgePadding, mFontHeight / 2 + mBadgePadding, mBadgeBackgroundPaint);
207 | }
208 | //绘制文本
209 | if (mGravity == Gravity.RIGHT) {
210 | canvas.drawText(mBadgeText, getWidth() - mFontWidth - mBadgePadding, mFontHeight + mBadgeOffY, mBadgeTextPaint);
211 | } else if (mGravity == Gravity.LEFT) {
212 | canvas.drawText(mBadgeText, mBadgePadding, mFontHeight + mBadgeOffY, mBadgeTextPaint);
213 | } else {
214 | canvas.drawText(mBadgeText, (getWidth() + mDrawableBackground.getIntrinsicWidth()) / 2 - mFontWidth / 2 + mBadgeOffX, mFontHeight + mBadgeOffY, mBadgeTextPaint);
215 | }
216 | }
217 |
218 | /**
219 | * 设置显示数字
220 | *
221 | * @param badgeNumber 标记数字
222 | */
223 | public BadgeRadioButton setBadgeNumber(int badgeNumber) {
224 | mBadgeNumber = badgeNumber;
225 | if (mBadgeNumber < 0) {
226 | mBadgeText = null;
227 | } else if (mBadgeNumber > 99) {
228 | mBadgeText = mBadgeExact ? String.valueOf(mBadgeNumber) : "99+";
229 | } else if (mBadgeNumber > 0 && mBadgeNumber <= 99) {
230 | mBadgeText = String.valueOf(mBadgeNumber);
231 | } else if (mBadgeNumber == 0) {
232 | mBadgeText = "";
233 | }
234 | return invalidateLayout();
235 | }
236 |
237 | /**
238 | * 设置显示数字
239 | *
240 | * @param badge 标记文本
241 | */
242 | public BadgeRadioButton setBadgeText(String badge) {
243 | mBadgeText = badge;
244 | return invalidateLayout();
245 | }
246 |
247 | /**
248 | * 重新刷新界面
249 | */
250 | private BadgeRadioButton invalidateLayout() {
251 | if (!TextUtils.isEmpty(mBadgeText)) {
252 | measureText();
253 | }
254 | invalidate();
255 | return this;
256 | }
257 |
258 | /**
259 | * 测量文本高度和宽度
260 | */
261 | private void measureText() {
262 | mFontHeight = Math.abs(mBadgeTextPaint.getFontMetrics().descent + mBadgeTextPaint.getFontMetrics().ascent);
263 | mFontWidth = mBadgeTextPaint.measureText(mBadgeText);
264 | }
265 |
266 | /**
267 | * 为画笔设置阴影
268 | *
269 | * @param showShadow 是否显示
270 | * @param badgeBackgroundPaint 画笔
271 | */
272 | private void showShadowImpl(boolean showShadow, Paint badgeBackgroundPaint) {
273 | int x = dp2px(1);
274 | int y = dp2px(1.5f);
275 | badgeBackgroundPaint.setShadowLayer(showShadow ? dp2px(2f) : 0, x, y, 0x33000000);
276 | }
277 |
278 | @Override
279 | void init() {
280 | super.init();
281 | setLayerType(View.LAYER_TYPE_SOFTWARE, null);
282 |
283 | mBadgeTextSize = dp2px(10);
284 | mBadgePadding = dp2px(4);
285 | mBadgeShowShadow = true;
286 | mBadgeColorBackground = Color.RED;
287 | mBadgeColorBadgeText = Color.WHITE;
288 | mBadgeOffX = 0;
289 | mBadgeOffY = 0;
290 | mFontWidth = 0;
291 | mFontHeight = 0;
292 | mBadgeBackgroundRect = new RectF(0, 0, 0, 0);
293 |
294 | //目前只支持drawableTop的RadioButton
295 | mDrawables = getCompoundDrawables();
296 | if (null != mDrawables[1]) {
297 | mDrawableBackground = mDrawables[1];
298 | }
299 | /* 理论上可以支持drawableRight,但是没测试
300 | else if (null != mDrawables[2]) {
301 | mDrawableBackground = mDrawables[2];
302 | }*/
303 |
304 | mBadgeTextPaint = new TextPaint();
305 | mBadgeTextPaint.setAntiAlias(true);
306 | mBadgeTextPaint.setSubpixelText(true);
307 | mBadgeTextPaint.setFakeBoldText(true);
308 | mBadgeTextPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
309 | mBadgeTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
310 | mBadgeTextPaint.setDither(true);
311 | mBadgeTextPaint.setColor(mBadgeColorBadgeText);
312 | mBadgeTextPaint.setTextSize(mBadgeTextSize);
313 |
314 | mBadgeBackgroundPaint = new Paint();
315 | mBadgeBackgroundPaint.setAntiAlias(true);
316 | mBadgeBackgroundPaint.setStyle(Paint.Style.FILL);
317 | mBadgeBackgroundPaint.setDither(true);
318 | mBadgeBackgroundPaint.setColor(mBadgeColorBackground);
319 | showShadowImpl(mBadgeShowShadow, mBadgeBackgroundPaint);
320 | }
321 |
322 | /**
323 | * 设置字体大小,默认8dp
324 | *
325 | * @param badgeTextSize 内边距
326 | */
327 | public BadgeRadioButton setBadgeTextSize(float badgeTextSize) {
328 | mBadgeTextSize = badgeTextSize;
329 | mBadgeTextPaint.setTextSize(mBadgeTextSize);
330 | return invalidateLayout();
331 | }
332 |
333 | /**
334 | * 设置标记的位置
335 | * 目前仅支持Gravity.LEFT Gravity.RIGHT Gravity.CENTER,默认Gravity.CENTER
336 | *
337 | * @param gravity {@link Gravity}
338 | */
339 | public BadgeRadioButton setBadgeGravity(int gravity) {
340 | mGravity = gravity;
341 | return invalidateLayout();
342 | }
343 |
344 | /**
345 | * 设置内边距,默认4dp
346 | *
347 | * @param badgePadding 内边距
348 | */
349 | public BadgeRadioButton setBadgePadding(int badgePadding) {
350 | mBadgePadding = badgePadding;
351 | return invalidateLayout();
352 | }
353 |
354 | /**
355 | * 设置是否显示阴影,默认显示
356 | *
357 | * @param badgeShowShadow true - 显示
358 | */
359 | public BadgeRadioButton setBadgeShowShadow(boolean badgeShowShadow) {
360 | mBadgeShowShadow = badgeShowShadow;
361 | return invalidateLayout();
362 | }
363 |
364 | /**
365 | * 设置背景颜色,默认红色
366 | *
367 | * @param badgeColorBackground 背景颜色
368 | */
369 | public BadgeRadioButton setBadgeColorBackground(@ColorInt int badgeColorBackground) {
370 | mBadgeColorBackground = badgeColorBackground;
371 | mBadgeBackgroundPaint.setColor(mBadgeColorBackground);
372 | return invalidateLayout();
373 | }
374 |
375 | /**
376 | * 设置标记字体颜色,默认白色
377 | *
378 | * @param badgeColorBadgeText 字体颜色
379 | */
380 | public BadgeRadioButton setBadgeColorBadgeText(int badgeColorBadgeText) {
381 | mBadgeColorBadgeText = badgeColorBadgeText;
382 | mBadgeTextPaint.setColor(mBadgeColorBadgeText);
383 | return invalidateLayout();
384 | }
385 |
386 | /**
387 | * 设置X偏移量
388 | *
389 | * @param badgeOffX x偏移量
390 | */
391 | public BadgeRadioButton setBadgeOffX(int badgeOffX) {
392 | mBadgeOffX = badgeOffX;
393 | return invalidateLayout();
394 | }
395 |
396 | /**
397 | * 设置Y偏移量
398 | *
399 | * @param badgeOffY Y偏移量
400 | */
401 | public BadgeRadioButton setBadgeOffY(int badgeOffY) {
402 | mBadgeOffY = badgeOffY;
403 | return invalidateLayout();
404 | }
405 |
406 | /**
407 | * 是否截取字体,默认截取,如 100 -> 99+
408 | *
409 | * @param badgeExact true - 截取
410 | */
411 | public BadgeRadioButton setBadgeExact(boolean badgeExact) {
412 | mBadgeExact = badgeExact;
413 | return invalidateLayout();
414 | }
415 |
416 | /**
417 | * dp转px
418 | *
419 | * @param dpValue dp值
420 | * @return px值
421 | */
422 | public int dp2px(float dpValue) {
423 | final float scale = getContext().getResources().getDisplayMetrics().density;
424 | return (int) (dpValue * scale + 0.5f);
425 | }
426 | }
427 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cqmc/badgeradiobutton/widget/DrawableCenterRadioButton.java:
--------------------------------------------------------------------------------
1 | package com.cqmc.badgeradiobutton.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.drawable.Drawable;
7 | import android.text.TextUtils;
8 | import android.util.AttributeSet;
9 | import android.view.Gravity;
10 |
11 | /**
12 | * Drawable居中的TextView
13 | *
14 | * @author mos
15 | * @date 2017.02.24
16 | * @note 1. 支持Drawable上、下、左、右四个方向。
17 | * -------------------------------------------------------------------------------------------------
18 | * @modified -
19 | * @date -
20 | * @note -
21 | */
22 | public class DrawableCenterRadioButton extends android.support.v7.widget.AppCompatRadioButton {
23 | /** 字体高度 */
24 | private float mFontHeight;
25 | /** 位图集合 */
26 | private Drawable[] mDrawables;
27 | /** 字体偏移数据 */
28 | private float mOffSize;
29 |
30 | /**
31 | * 构造函数
32 | *
33 | * @param context 上下文
34 | */
35 | public DrawableCenterRadioButton(Context context) {
36 | super(context);
37 | init();
38 | }
39 |
40 | /**
41 | * 构造函数
42 | *
43 | * @param context 上下文
44 | * @param attrs 属性
45 | */
46 | public DrawableCenterRadioButton(Context context, AttributeSet attrs) {
47 | super(context, attrs);
48 | init();
49 | }
50 |
51 | /**
52 | * 构造函数
53 | *
54 | * @param context 上下文
55 | * @param attrs 属性
56 | * @param defStyle 样式
57 | */
58 | public DrawableCenterRadioButton(Context context, AttributeSet attrs, int defStyle) {
59 | super(context, attrs, defStyle);
60 | init();
61 | }
62 |
63 |
64 | @Override
65 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
66 | mDrawables = getCompoundDrawables();
67 | if (mDrawables[0] != null || mDrawables[2] != null) {
68 | // 左、右
69 | setGravity(Gravity.CENTER_VERTICAL | (mDrawables[0] != null ? Gravity.LEFT : Gravity.RIGHT));
70 |
71 | } else if (mDrawables[1] != null || mDrawables[3] != null) {
72 | // 上、下
73 | setGravity(Gravity.CENTER_HORIZONTAL | (mDrawables[1] != null ? Gravity.TOP : Gravity.BOTTOM));
74 | Paint.FontMetrics fm = getPaint().getFontMetrics();
75 | mFontHeight = (float) Math.ceil(fm.descent - fm.ascent);
76 | }
77 | super.onLayout(changed, left, top, right, bottom);
78 | }
79 |
80 |
81 | @Override
82 | protected void onDraw(Canvas canvas) {
83 |
84 | int drawablePadding = getCompoundDrawablePadding();
85 | if (mDrawables[0] != null) {
86 | // 左
87 | float textWidth = getPaint().measureText(getText().toString());
88 | int drawableWidth = mDrawables[0].getIntrinsicWidth();
89 | float bodyWidth = textWidth + drawableWidth + drawablePadding;
90 | if (TextUtils.isEmpty(getText())) {
91 | bodyWidth = drawableWidth;
92 | }
93 | mOffSize = (getWidth() - bodyWidth) / 2;
94 | canvas.translate(mOffSize, 0);
95 |
96 | } else if (mDrawables[2] != null) {
97 | // 右
98 | float textWidth = getPaint().measureText(getText().toString());
99 | int drawableWidth = mDrawables[2].getIntrinsicWidth();
100 | float bodyWidth = textWidth + drawableWidth + drawablePadding;
101 | if (TextUtils.isEmpty(getText())) {
102 | bodyWidth = drawableWidth;
103 | }
104 | mOffSize = (bodyWidth - getWidth()) / 2;
105 | canvas.translate(mOffSize, 0);
106 | } else if (mDrawables[1] != null) {
107 | // 上
108 | int drawableHeight = mDrawables[1].getIntrinsicHeight();
109 | float bodyHeight = mFontHeight + drawableHeight + drawablePadding;
110 | if (TextUtils.isEmpty(getText())) {
111 | bodyHeight = drawableHeight;
112 | }
113 | mOffSize = (getHeight() - bodyHeight) / 2;
114 | canvas.translate(0, mOffSize);
115 | } else if (mDrawables[3] != null) {
116 | // 下
117 | int drawableHeight = mDrawables[3].getIntrinsicHeight();
118 | float bodyHeight = mFontHeight + drawableHeight + drawablePadding;
119 | if (TextUtils.isEmpty(getText())) {
120 | bodyHeight = drawableHeight;
121 | }
122 | mOffSize = (bodyHeight - getHeight()) / 2;
123 | canvas.translate(0, mOffSize);
124 | }
125 | super.onDraw(canvas);
126 | }
127 |
128 | public float getOffSize() {
129 | return mOffSize;
130 | }
131 |
132 | /**
133 | * 初始化
134 | */
135 | void init() {
136 |
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cqmc/badgeradiobutton/widget/DrawableCenterTextView.java:
--------------------------------------------------------------------------------
1 | package com.cqmc.badgeradiobutton.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.drawable.Drawable;
7 | import android.text.TextUtils;
8 | import android.util.AttributeSet;
9 | import android.view.Gravity;
10 |
11 | /**
12 | * Drawable居中的TextView
13 | *
14 | * @author lwc
15 | * @date 2016.4.27
16 | * @note 1. 支持Drawable上、下、左、右四个方向。
17 | */
18 | public class DrawableCenterTextView extends android.support.v7.widget.AppCompatTextView {
19 | /** 字体高度 */
20 | private float mFontHeight;
21 | /** 位图集合 */
22 | private Drawable[] mDrawables;
23 | /** 字体偏移数据 */
24 | private float mOffSize;
25 |
26 | /**
27 | * 构造函数
28 | *
29 | * @param context 上下文
30 | */
31 | public DrawableCenterTextView(Context context) {
32 | super(context);
33 | init();
34 | }
35 |
36 | /**
37 | * 构造函数
38 | *
39 | * @param context 上下文
40 | * @param attrs 属性
41 | */
42 | public DrawableCenterTextView(Context context, AttributeSet attrs) {
43 | super(context, attrs);
44 | init();
45 | }
46 |
47 | /**
48 | * 构造函数
49 | *
50 | * @param context 上下文
51 | * @param attrs 属性
52 | * @param defStyle 样式
53 | */
54 | public DrawableCenterTextView(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 | init();
57 | }
58 |
59 |
60 | @Override
61 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
62 | mDrawables = getCompoundDrawables();
63 | if (mDrawables[0] != null || mDrawables[2] != null) {
64 | // 左、右
65 | setGravity(Gravity.CENTER_VERTICAL | (mDrawables[0] != null ? Gravity.LEFT : Gravity.RIGHT));
66 |
67 | } else if (mDrawables[1] != null || mDrawables[3] != null) {
68 | // 上、下
69 | setGravity(Gravity.CENTER_HORIZONTAL | (mDrawables[1] != null ? Gravity.TOP : Gravity.BOTTOM));
70 | Paint.FontMetrics fm = getPaint().getFontMetrics();
71 | mFontHeight = (float) Math.ceil(fm.descent - fm.ascent);
72 | }
73 | super.onLayout(changed, left, top, right, bottom);
74 | }
75 |
76 |
77 | @Override
78 | protected void onDraw(Canvas canvas) {
79 |
80 | int drawablePadding = getCompoundDrawablePadding();
81 | if (mDrawables[0] != null) {
82 | // 左
83 | float textWidth = getPaint().measureText(getText().toString());
84 | int drawableWidth = mDrawables[0].getIntrinsicWidth();
85 | float bodyWidth = textWidth + drawableWidth + drawablePadding;
86 | if (TextUtils.isEmpty(getText())) {
87 | bodyWidth = drawableWidth;
88 | }
89 | mOffSize = (getWidth() - bodyWidth) / 2;
90 | canvas.translate(mOffSize, 0);
91 |
92 | } else if (mDrawables[2] != null) {
93 | // 右
94 | float textWidth = getPaint().measureText(getText().toString());
95 | int drawableWidth = mDrawables[2].getIntrinsicWidth();
96 | float bodyWidth = textWidth + drawableWidth + drawablePadding;
97 | if (TextUtils.isEmpty(getText())) {
98 | bodyWidth = drawableWidth;
99 | }
100 | mOffSize = (bodyWidth - getWidth()) / 2;
101 | canvas.translate(mOffSize, 0);
102 | } else if (mDrawables[1] != null) {
103 | // 上
104 | int drawableHeight = mDrawables[1].getIntrinsicHeight();
105 | float bodyHeight = mFontHeight + drawableHeight + drawablePadding;
106 | if (TextUtils.isEmpty(getText())) {
107 | bodyHeight = drawableHeight;
108 | }
109 | mOffSize = (getHeight() - bodyHeight) / 2;
110 | canvas.translate(0, mOffSize);
111 | } else if (mDrawables[3] != null) {
112 | // 下
113 | int drawableHeight = mDrawables[3].getIntrinsicHeight();
114 | float bodyHeight = mFontHeight + drawableHeight + drawablePadding;
115 | if (TextUtils.isEmpty(getText())) {
116 | bodyHeight = drawableHeight;
117 | }
118 | mOffSize = (bodyHeight - getHeight()) / 2;
119 | canvas.translate(0, mOffSize);
120 | }
121 | super.onDraw(canvas);
122 | }
123 |
124 | public float getOffSize() {
125 | return mOffSize;
126 | }
127 |
128 | /**
129 | * 初始化
130 | */
131 | void init() {
132 |
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cqmc/badgeradiobutton/widget/MeasureTextView.java:
--------------------------------------------------------------------------------
1 | package com.cqmc.badgeradiobutton.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.support.annotation.Nullable;
8 | import android.util.AttributeSet;
9 |
10 | /**
11 | * 测量Text字的位置
12 | *
13 | * @author - lwc
14 | * @date - 2017/6/21
15 | * @note -
16 | * -------------------------------------------------------------------------------------------------
17 | */
18 | public class MeasureTextView extends android.support.v7.widget.AppCompatTextView {
19 | Paint mPaint;
20 |
21 |
22 | public MeasureTextView(Context context) {
23 | super(context);
24 | init();
25 | }
26 |
27 | public MeasureTextView(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | init();
30 | }
31 |
32 | public MeasureTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | init();
35 | }
36 |
37 | private void init() {
38 | mPaint = new Paint();
39 | }
40 |
41 | @Override
42 | protected void onDraw(Canvas canvas) {
43 | super.onDraw(canvas);
44 |
45 | mPaint.setColor(Color.RED);
46 | mPaint.setTextSize(sp2px(8));
47 |
48 | Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
49 | //baseline
50 | canvas.drawLine(0, getBaseline(), getWidth(), getBaseline(), mPaint);
51 | canvas.drawText("baseline", 0, getBaseline(), mPaint);
52 | //top
53 | canvas.drawLine(0, fontMetrics.top + getBaseline(), getWidth(), fontMetrics.top + getBaseline(), mPaint);
54 | canvas.drawText("top", getWidth() / 5, fontMetrics.top + getBaseline(), mPaint);
55 | //ascent
56 | canvas.drawLine(0, fontMetrics.ascent + getBaseline(), getWidth(), fontMetrics.ascent + getBaseline(), mPaint);
57 | canvas.drawText("ascent", getWidth() * 2 / 5, fontMetrics.ascent + getBaseline(), mPaint);
58 | //descent
59 | canvas.drawLine(0, fontMetrics.descent + getBaseline(), getWidth(), fontMetrics.descent + getBaseline(), mPaint);
60 | canvas.drawText("descent", getWidth() * 3 / 5, fontMetrics.descent + getBaseline(), mPaint);
61 | //bottom
62 | canvas.drawLine(0, fontMetrics.bottom + getBaseline(), getWidth(), fontMetrics.bottom + getBaseline(), mPaint);
63 | canvas.drawText("bottom", getWidth() * 4 / 5, fontMetrics.bottom + getBaseline(), mPaint);
64 | //leading
65 | canvas.drawLine(0, fontMetrics.leading + getBaseline(), getWidth(), fontMetrics.leading + getBaseline(), mPaint);
66 | canvas.drawText("leading", getWidth(), fontMetrics.leading + getBaseline(), mPaint);
67 | }
68 |
69 | /**
70 | * sp转px
71 | *
72 | * @param spValue sp值
73 | * @return px值
74 | */
75 | public int sp2px(float spValue) {
76 | final float fontScale = getContext().getResources().getDisplayMetrics().scaledDensity;
77 | return (int) (spValue * fontScale + 0.5f);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
25 |
26 |
33 |
34 |
38 |
39 |
43 |
44 |
54 |
55 |
65 |
66 |
76 |
77 |
87 |
88 |
89 |
93 |
94 |
104 |
105 |
115 |
116 |
126 |
127 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_main_user_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-xxhdpi/ic_main_user_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BadgeRadioButton
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/cqmc/badgeradiobutton/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.cqmc.badgeradiobutton;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwcye/BadgeRadioButton/6def52e50c24d0fc38ccecdadb8e536c7f78ab48/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jun 21 16:28:58 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------