Skip to content

Commit afcf8a0

Browse files
committed
Fixed attrs
1 parent 07a8e1e commit afcf8a0

6 files changed

Lines changed: 68 additions & 76 deletions

File tree

support/src/main/java/com/github/nikartm/support/AnimatedStripedDrawable.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public class AnimatedStripedDrawable extends Drawable implements Animatable {
3232
private float alpha = Constants.STRIPE_ALPHA;
3333
private float cornerRadius = Constants.CORNER;
3434
private int duration = Constants.DURATION;
35-
private float tilt = Constants.TILT;
35+
private float tilt = Constants.STRIPE_TILT;
36+
private boolean stripeRevert = Constants.REVERT;
37+
private boolean showStripes = Constants.SHOW_STRIPES;
3638

3739
private float density;
3840
private int viewHeight;
3941
private int viewWidth;
4042
private float tiltLeft = 0f;
4143
private float tiltRight = 0f;
42-
private boolean stripeRevert = false;
43-
private boolean showStripes = true;
4444
private boolean running = false;
4545

4646
private Context context;
@@ -212,6 +212,7 @@ public float getStripeWidth() {
212212

213213
public AnimatedStripedDrawable setStripeWidth(float stripeWidth) {
214214
this.stripeWidth = stripeWidth;
215+
invalidateSelf();
215216
return this;
216217
}
217218

@@ -221,6 +222,7 @@ public int getColorBack() {
221222

222223
public AnimatedStripedDrawable setColorBack(int colorBack) {
223224
this.colorBack = colorBack;
225+
invalidateSelf();
224226
return this;
225227
}
226228

@@ -230,6 +232,7 @@ public int getColorMain() {
230232

231233
public AnimatedStripedDrawable setColorMain(int colorMain) {
232234
this.colorMain = colorMain;
235+
invalidateSelf();
233236
return this;
234237
}
235238

@@ -239,6 +242,7 @@ public int getColorSub() {
239242

240243
public AnimatedStripedDrawable setColorSub(int colorSub) {
241244
this.colorSub = colorSub;
245+
invalidateSelf();
242246
return this;
243247
}
244248

@@ -248,6 +252,7 @@ public float getStripeAlpha() {
248252

249253
public AnimatedStripedDrawable setStripeAlpha(float alpha) {
250254
this.alpha = alpha;
255+
invalidateSelf();
251256
return this;
252257
}
253258

@@ -257,6 +262,7 @@ public float getCornerRadius() {
257262

258263
public AnimatedStripedDrawable setCornerRadius(float cornerRadius) {
259264
this.cornerRadius = cornerRadius;
265+
invalidateSelf();
260266
return this;
261267
}
262268

@@ -266,6 +272,7 @@ public int getDuration() {
266272

267273
public AnimatedStripedDrawable setDuration(int duration) {
268274
this.duration = duration;
275+
invalidateSelf();
269276
return this;
270277
}
271278

@@ -275,6 +282,7 @@ public float getTilt() {
275282

276283
public AnimatedStripedDrawable setTilt(float tilt) {
277284
this.tilt = tilt;
285+
invalidateSelf();
278286
return this;
279287
}
280288

@@ -284,6 +292,7 @@ public boolean isStripeRevert() {
284292

285293
public AnimatedStripedDrawable setStripeRevert(boolean stripeRevert) {
286294
this.stripeRevert = stripeRevert;
295+
invalidateSelf();
287296
return this;
288297
}
289298

@@ -293,6 +302,7 @@ public boolean isShowStripes() {
293302

294303
public AnimatedStripedDrawable setShowStripes(boolean showStripes) {
295304
this.showStripes = showStripes;
305+
invalidateSelf();
296306
return this;
297307
}
298308
}

support/src/main/java/com/github/nikartm/support/AttributeController.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,26 @@ private void initAttrs(Context context, AttributeSet attrs) {
2525
try {
2626
float stripeWidth = typedArray.getDimension(R.styleable.StripedProgressButton_spb_stripeWidth, Constants.STRIPE_WIDTH);
2727
float stripeAlpha = typedArray.getFloat(R.styleable.StripedProgressButton_spb_stripeAlpha, Constants.STRIPE_ALPHA);
28-
float mainStripeAlpha = typedArray.getFloat(R.styleable.StripedProgressButton_spb_mainStripeAlpha, stripeAlpha);
29-
float subStripeAlpha = typedArray.getFloat(R.styleable.StripedProgressButton_spb_subStripeAlpha, stripeAlpha);
30-
int stripeDegree = typedArray.getInt(R.styleable.StripedProgressButton_spb_degree, Constants.STRIPE_DEGREE);
28+
int stripeTilt = typedArray.getInt(R.styleable.StripedProgressButton_spb_stripeTilt, Constants.STRIPE_TILT);
3129
int duration = typedArray.getInt(R.styleable.StripedProgressButton_spb_duration, Constants.DURATION);
3230
int background = typedArray.getColor(R.styleable.StripedProgressButton_spb_background, Constants.DEF_BACKGROUND);
3331
int mainStripeColor = typedArray.getColor(R.styleable.StripedProgressButton_spb_mainStripColor, Constants.DEF_MAIN_STRIPE);
3432
int subStripeColor = typedArray.getColor(R.styleable.StripedProgressButton_spb_subStripeColor, Constants.DEF_SUB_STRIPE);
33+
float cornerRadius = typedArray.getFloat(R.styleable.StripedProgressButton_spb_cornerRadius, Constants.CORNER);
34+
boolean stripeRevert = typedArray.getBoolean(R.styleable.StripedProgressButton_spb_stripeRevert, Constants.REVERT);
35+
boolean showStripes = typedArray.getBoolean(R.styleable.StripedProgressButton_spb_showStripes, Constants.SHOW_STRIPES);
3536
boolean active = typedArray.getBoolean(R.styleable.StripedProgressButton_spb_active, Constants.ACTIVE);
3637

3738
button.setStripeWidth(stripeWidth)
3839
.setStripeAlpha(stripeAlpha)
39-
.setMainStripeAlpha(mainStripeAlpha)
40-
.setSubStripeAlpha(subStripeAlpha)
41-
.setStripeDegree(stripeDegree)
40+
.setStripeTilt(stripeTilt)
4241
.setDuration(duration)
4342
.setBackground(background)
4443
.setMainStripeColor(mainStripeColor)
4544
.setSubStripeColor(subStripeColor)
45+
.setCornerRadius(cornerRadius)
46+
.setStripeRevert(stripeRevert)
47+
.setShowStripes(showStripes)
4648
.setActive(active);
4749
} finally {
4850
typedArray.recycle();

support/src/main/java/com/github/nikartm/support/StripedProgressButton.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ private void adjustView() {
8383
paint.setStrokeWidth(stripeWidth);
8484
startY = stripeEdge / -1;
8585
stopY = getHeight() + stripeEdge;
86-
mainStripeAlpha = Util.computeAlpha(button.getMainStripeAlpha());
87-
subStripeAlpha = Util.computeAlpha(button.getSubStripeAlpha());
86+
// mainStripeAlpha = Util.computeAlpha(button.getMainStripeAlpha());
87+
// subStripeAlpha = Util.computeAlpha(button.getSubStripeAlpha());
8888
}
8989
}
9090

9191
private void drawStripes(Canvas canvas) {
9292
int startX = 0;
93-
int stopX = button.getStripeDegree() / -1;
93+
int stopX = 0;
9494
canvas.drawColor(button.getBackground());
9595
do {
9696
paint.setColor(button.getMainStripeColor());
@@ -104,7 +104,7 @@ private void drawStripes(Canvas canvas) {
104104
canvas.drawLine(startX, startY, stopX, stopY, paint);
105105
startX += stripeWidth + 1;
106106
stopX += stripeWidth + 1;
107-
} while (startX < getWidth() + button.getStripeDegree());
107+
} while (startX < getWidth() + button.getStripeTilt());
108108
}
109109

110110
private void startAnimation() {
@@ -173,35 +173,6 @@ public StripedProgressButton setStripeAlpha(float stripeAlpha) {
173173
return this;
174174
}
175175

176-
public float getMainStripeAlpha() {
177-
return button.getMainStripeAlpha();
178-
}
179-
180-
public StripedProgressButton setMainStripeAlpha(float mainStripeAlpha) {
181-
button.setMainStripeAlpha(mainStripeAlpha);
182-
invalidate();
183-
return this;
184-
}
185-
186-
public float getSubStripeAlpha() {
187-
return button.getSubStripeAlpha();
188-
}
189-
190-
public StripedProgressButton setSubStripeAlpha(float subStripeAlpha) {
191-
button.setSubStripeAlpha(subStripeAlpha);
192-
invalidate();
193-
return this;
194-
}
195-
196-
public int getStripeDegree() {
197-
return button.getStripeDegree();
198-
}
199-
200-
public StripedProgressButton setStripeDegree(int stripeDegree) {
201-
button.setStripeDegree(stripeDegree);
202-
invalidate();
203-
return this;
204-
}
205176

206177
public long getDuration() {
207178
return button.getDuration();

support/src/main/java/com/github/nikartm/support/constant/Constants.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ public class Constants {
1111
public static final float STRIPE_WIDTH = 13f;
1212
public static final float STRIPE_ALPHA = 0.3f;
1313
public static final int CORNER = 5;
14-
public static final float TILT = 39f;
15-
public static final float MAIN_STRIPE_ALPHA = STRIPE_ALPHA;
16-
public static final float SUB_STRIPE_ALPHA = STRIPE_ALPHA;
17-
public static final int STRIPE_DEGREE = 40;
14+
public static final int STRIPE_TILT = 40;
1815
public static final int DURATION = 250;
16+
public static final boolean REVERT = false;
17+
public static final boolean SHOW_STRIPES = true;
1918
public static final boolean ACTIVE = true;
2019

2120
public static final int DEF_BACKGROUND = Color.parseColor("#4CAF50");

support/src/main/java/com/github/nikartm/support/model/StrippedButton.java

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ public class StrippedButton {
88

99
private float stripeWidth;
1010
private float stripeAlpha;
11-
private float mainStripeAlpha;
12-
private float subStripeAlpha;
13-
private int stripeDegree;
11+
private int stripeTilt;
1412
private long duration;
1513
private int background;
1614
private int mainStripeColor;
1715
private int subStripeColor;
16+
private float cornerRadius;
17+
private boolean stripeRevert;
18+
private boolean showStripes;
1819
private boolean active;
1920

20-
public StrippedButton() {
21-
}
21+
public StrippedButton() {}
2222

2323
public float getStripeWidth() {
2424
return stripeWidth;
@@ -38,30 +38,12 @@ public StrippedButton setStripeAlpha(float stripeAlpha) {
3838
return this;
3939
}
4040

41-
public float getMainStripeAlpha() {
42-
return mainStripeAlpha;
41+
public int getStripeTilt() {
42+
return stripeTilt;
4343
}
4444

45-
public StrippedButton setMainStripeAlpha(float mainStripeAlpha) {
46-
this.mainStripeAlpha = mainStripeAlpha;
47-
return this;
48-
}
49-
50-
public float getSubStripeAlpha() {
51-
return subStripeAlpha;
52-
}
53-
54-
public StrippedButton setSubStripeAlpha(float subStripeAlpha) {
55-
this.subStripeAlpha = subStripeAlpha;
56-
return this;
57-
}
58-
59-
public int getStripeDegree() {
60-
return stripeDegree;
61-
}
62-
63-
public StrippedButton setStripeDegree(int stripeDegree) {
64-
this.stripeDegree = stripeDegree;
45+
public StrippedButton setStripeTilt(int stripeTilt) {
46+
this.stripeTilt = stripeTilt;
6547
return this;
6648
}
6749

@@ -101,6 +83,33 @@ public StrippedButton setSubStripeColor(int subStripeColor) {
10183
return this;
10284
}
10385

86+
public float getCornerRadius() {
87+
return cornerRadius;
88+
}
89+
90+
public StrippedButton setCornerRadius(float cornerRadius) {
91+
this.cornerRadius = cornerRadius;
92+
return this;
93+
}
94+
95+
public boolean isStripeRevert() {
96+
return stripeRevert;
97+
}
98+
99+
public StrippedButton setStripeRevert(boolean stripeRevert) {
100+
this.stripeRevert = stripeRevert;
101+
return this;
102+
}
103+
104+
public boolean isShowStripes() {
105+
return showStripes;
106+
}
107+
108+
public StrippedButton setShowStripes(boolean showStripes) {
109+
this.showStripes = showStripes;
110+
return this;
111+
}
112+
104113
public boolean isActive() {
105114
return active;
106115
}

support/src/main/res/values/attr.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
<attr name="spb_stripeWidth" format="dimension" />
66
<attr name="spb_stripeAlpha" format="float" />
7-
<attr name="spb_mainStripeAlpha" format="float" />
8-
<attr name="spb_subStripeAlpha" format="float" />
9-
<attr name="spb_degree" format="integer" />
7+
<attr name="spb_stripeTilt" format="integer" />
108
<attr name="spb_duration" format="integer" />
119
<attr name="spb_background" format="color" />
1210
<attr name="spb_mainStripColor" format="color" />
1311
<attr name="spb_subStripeColor" format="color" />
12+
<attr name="spb_cornerRadius" format="float" />
13+
<attr name="spb_stripeRevert" format="boolean" />
14+
<attr name="spb_showStripes" format="boolean" />
1415
<attr name="spb_active" format="boolean" />
1516

1617
</declare-styleable>

0 commit comments

Comments
 (0)