Skip to content

Commit

Permalink
Add attribute to control opacity of shadow.
Browse files Browse the repository at this point in the history
  • Loading branch information
varunest committed Jun 17, 2018
1 parent 4a265a6 commit 1738d28
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ and then add dependency

```groovy
dependencies {
implementation 'com.github.varunest:TheGlowingLoader:1.0.3'
implementation 'com.github.varunest:TheGlowingLoader:1.0.4'
}
```

Expand Down Expand Up @@ -64,6 +64,7 @@ dependencies {
<attr name="theglowingloader_particle_3_color" format="reference" />
<attr name="theglowingloader_disable_shadows" format="boolean" />
<attr name="theglowingloader_disable_ripple" format="boolean" />
<attr name="theglowingloader_shadow_opacity" format="float" />
```

You can also access and modify all these attributes at runtime by getting the reference of `TheGlowingLoader` and calling its `setConfiguration` method.
Expand Down
4 changes: 2 additions & 2 deletions theglowingloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 4
versionName "1.0.3"
versionCode 5
versionName "1.0.4"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Configuration {
private int lineStrokeWidth;
private boolean disableShadows;
private boolean disableRipple;
private float shadowOpacity;

Configuration() {

Expand All @@ -24,6 +25,7 @@ public class Configuration {
public Configuration(Context context) {
disableShadows = false;
disableRipple = false;
shadowOpacity = .2f;
line1Color = ContextCompat.getColor(context, R.color.white);
line2Color = ContextCompat.getColor(context, R.color.red);
lineStrokeWidth = Constants.DEF_LINE_STROKE_WIDTH;
Expand Down Expand Up @@ -104,4 +106,17 @@ public boolean isDisableRipple() {
public void setDisableRipple(boolean disableRipple) {
this.disableRipple = disableRipple;
}

public float getShadowOpacity() {
return shadowOpacity;
}

public void setShadowOpacity(float shadowOpacity) {
if (shadowOpacity < 0.0f) {
shadowOpacity = 0f;
} else if (shadowOpacity > 1f) {
shadowOpacity = 1f;
}
this.shadowOpacity = shadowOpacity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private void getStuffFromXML(AttributeSet attrs) {
configuration.setLineStrokeWidth(a.getInt(R.styleable.TheGlowingLoader_theglowingloader_line_stroke_width, Constants.DEF_LINE_STROKE_WIDTH));
configuration.setDisableShadows(a.getBoolean(R.styleable.TheGlowingLoader_theglowingloader_disable_shadows, false));
configuration.setDisableRipple(a.getBoolean(R.styleable.TheGlowingLoader_theglowingloader_disable_ripple, false));
configuration.setShadowOpacity(a.getFloat(R.styleable.TheGlowingLoader_theglowingloader_shadow_opacity, .2f));
}

public void setConfiguration(Configuration configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void draw(Canvas canvas, Paint paint) {
paint.setMaskFilter(new BlurMaskFilter(70, BlurMaskFilter.Blur.NORMAL));
paint.setStrokeWidth(2.666f * configuration.getLineStrokeWidth());
paint.setColor(configuration.getLine1Color());
paint.setAlpha(0x38);
paint.setAlpha((int) (255 * configuration.getShadowOpacity()));
if (wxa11 != wxa12 && wya11 != wya12)
canvas.drawLine(wxa11, wya11 + 100, wxa12, wya12 + 100, paint);
if (wxa21 != wxa22 && wya21 != wya22)
Expand All @@ -90,7 +90,7 @@ public void draw(Canvas canvas, Paint paint) {
canvas.drawLine(wxa31, wya31 + 100, wxa32, wya32 + 100, paint);

paint.setColor(configuration.getLine2Color());
paint.setAlpha(0x38);
paint.setAlpha((int) (255 * configuration.getShadowOpacity()));
if (rxa11 != rxa12 && rya11 != rya12)
canvas.drawLine(rxa11, rya11 + 100, rxa12, rya12 + 100, paint);
if (rxa21 != rxa22 && rya21 != rya22)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public void start(final Callback callback, float degree1, float degree2, float d
startCircleMinor(callback);
if (degree1 != Constants.INVALID_DEG)
startParticleAnimation(degree1, PARTICLE_TYPE_TRIANGLE, configuration.getParticle1Color());
if(degree2 != Constants.INVALID_DEG)
if (degree2 != Constants.INVALID_DEG)
startParticleAnimation(degree2, PARTICLE_TYPE_CIRCLE, configuration.getParticle2Color());
if(degree3 != Constants.INVALID_DEG)
if (degree3 != Constants.INVALID_DEG)
startParticleAnimation(degree3, PARTICLE_TYPE_TRIANGLE, configuration.getParticle3Color());
}

Expand All @@ -164,7 +164,7 @@ public void draw(Canvas canvas, Paint paint) {
if (!configuration.isDisableShadows()) {
paint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL));
paint.setStrokeWidth(.28f * circleRadius);
paint.setAlpha((int) (255 * circleAlpha * .4));
paint.setAlpha((int) (255 * circleAlpha * configuration.getShadowOpacity()));
canvas.drawCircle(cX, cY + 100, circleRadius, paint);
}

Expand Down
1 change: 1 addition & 0 deletions theglowingloader/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<attr name="theglowingloader_particle_3_color" format="reference" />
<attr name="theglowingloader_disable_shadows" format="boolean" />
<attr name="theglowingloader_disable_ripple" format="boolean" />
<attr name="theglowingloader_shadow_opacity" format="float" />
</declare-styleable>
</resources>

0 comments on commit 1738d28

Please sign in to comment.