Skip to content

Commit ae86c08

Browse files
committed
Update 1.0.2
1 parent 2060102 commit ae86c08

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737
Or Gradle Maven Central:
3838

3939
```groovy
40-
compile 'com.github.devlight.shadowlayout:library:1.0.1'
40+
compile 'com.github.devlight.shadowlayout:library:1.0.2'
4141
```
4242

4343
Or Maven:
@@ -46,7 +46,7 @@ Or Maven:
4646
<dependency>
4747
<groupId>com.github.devlight.shadowlayout</groupId>
4848
<artifactId>library</artifactId>
49-
<version>1.0.1</version>
49+
<version>1.0.2</version>
5050
<type>aar</type>
5151
</dependency>
5252
```

app/src/main/res/layout/activity_main.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
android:layout_weight="1"
9696
android:background="#7C7C7C"
9797
app:sl_shadow_angle="225"
98-
app:sl_shadow_color="#000"
98+
app:sl_shadow_color="#5b000000"
9999
app:sl_shadow_distance="4dp"
100100
app:sl_shadow_radius="5dp">
101101

library/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray"
1919
apply plugin: 'com.github.dcendents.android-maven'
2020
apply plugin: 'maven'
2121

22-
version = "1.0.1"
22+
version = "1.0.2"
2323

2424
android {
2525
compileSdkVersion 23
@@ -29,7 +29,7 @@ android {
2929
minSdkVersion 11
3030
targetSdkVersion 23
3131
versionCode 1
32-
versionName "1.0.1"
32+
versionName "1.0.2"
3333
}
3434
buildTypes {
3535
release {

library/src/main/java/com/gigamole/library/ShadowLayout.java

+26-12
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@
3535
public class ShadowLayout extends FrameLayout {
3636

3737
// Default shadow values
38-
private final static float DEFAULT_SHADOW_RADIUS = 30.0f;
39-
private final static float DEFAULT_SHADOW_DISTANCE = 15.0f;
40-
private final static float DEFAULT_SHADOW_ANGLE = 45.0f;
38+
private final static float DEFAULT_SHADOW_RADIUS = 30.0F;
39+
private final static float DEFAULT_SHADOW_DISTANCE = 15.0F;
40+
private final static float DEFAULT_SHADOW_ANGLE = 45.0F;
4141
private final static int DEFAULT_SHADOW_COLOR = Color.DKGRAY;
4242

4343
// Shadow bounds values
44-
private final static float MAX_ANGLE = 360.0f;
45-
private final static float MIN_RADIUS = 0.1f;
46-
private final static float MIN_ANGLE = 0.0f;
44+
private final static int MAX_ALPHA = 255;
45+
private final static float MAX_ANGLE = 360.0F;
46+
private final static float MIN_RADIUS = 0.1F;
47+
private final static float MIN_ANGLE = 0.0F;
4748
// Shadow paint
4849
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG) {
4950
{
@@ -53,9 +54,9 @@ public class ShadowLayout extends FrameLayout {
5354
};
5455
// Shadow bitmap and canvas
5556
private Bitmap mBitmap;
56-
private Canvas mCanvas = new Canvas();
57+
private final Canvas mCanvas = new Canvas();
5758
// View bounds
58-
private Rect mBounds = new Rect();
59+
private final Rect mBounds = new Rect();
5960
// Check whether need to redraw shadow
6061
private boolean mInvalidateShadow = true;
6162

@@ -64,6 +65,7 @@ public class ShadowLayout extends FrameLayout {
6465

6566
// Shadow variables
6667
private int mShadowColor;
68+
private int mShadowAlpha;
6769
private float mShadowRadius;
6870
private float mShadowDistance;
6971
private float mShadowAngle;
@@ -170,8 +172,8 @@ public int getShadowColor() {
170172

171173
public void setShadowColor(final int shadowColor) {
172174
mShadowColor = shadowColor;
175+
mShadowAlpha = Color.alpha(shadowColor);
173176

174-
mPaint.setColor(shadowColor);
175177
resetShadow();
176178
}
177179

@@ -186,15 +188,24 @@ public float getShadowDy() {
186188
// Reset shadow layer
187189
private void resetShadow() {
188190
// Detect shadow axis offset
189-
mShadowDx = (float) ((mShadowDistance) * Math.cos(mShadowAngle / 180.0f * Math.PI));
190-
mShadowDy = (float) ((mShadowDistance) * Math.sin(mShadowAngle / 180.0f * Math.PI));
191+
mShadowDx = (float) ((mShadowDistance) * Math.cos(mShadowAngle / 180.0F * Math.PI));
192+
mShadowDy = (float) ((mShadowDistance) * Math.sin(mShadowAngle / 180.0F * Math.PI));
191193

192194
// Set padding for shadow bitmap
193195
final int padding = (int) (mShadowDistance + mShadowRadius);
194196
setPadding(padding, padding, padding, padding);
195197
requestLayout();
196198
}
197199

200+
private int adjustShadowAlpha(final boolean adjust) {
201+
return Color.argb(
202+
adjust ? MAX_ALPHA : mShadowAlpha,
203+
Color.red(mShadowColor),
204+
Color.green(mShadowColor),
205+
Color.blue(mShadowColor)
206+
);
207+
}
208+
198209
@Override
199210
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
200211
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -241,6 +252,7 @@ protected void dispatchDraw(final Canvas canvas) {
241252
mCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
242253

243254
// Draw extracted alpha bounds of our local canvas
255+
mPaint.setColor(adjustShadowAlpha(false));
244256
mCanvas.drawBitmap(extractedAlpha, mShadowDx, mShadowDy, mPaint);
245257

246258
// Recycle and clear extracted alpha
@@ -251,9 +263,11 @@ protected void dispatchDraw(final Canvas canvas) {
251263
}
252264
}
253265

266+
// Reset alpha to draw child with full alpha
267+
mPaint.setColor(adjustShadowAlpha(true));
254268
// Draw shadow bitmap
255269
if (mCanvas != null && mBitmap != null && !mBitmap.isRecycled())
256-
canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
270+
canvas.drawBitmap(mBitmap, 0.0F, 0.0F, mPaint);
257271
}
258272

259273
// Draw child`s

0 commit comments

Comments
 (0)