Skip to content

Commit

Permalink
Update 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GIGAMOLE committed Aug 13, 2016
1 parent 2060102 commit ae86c08
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
Or Gradle Maven Central:

```groovy
compile 'com.github.devlight.shadowlayout:library:1.0.1'
compile 'com.github.devlight.shadowlayout:library:1.0.2'
```

Or Maven:
Expand All @@ -46,7 +46,7 @@ Or Maven:
<dependency>
<groupId>com.github.devlight.shadowlayout</groupId>
<artifactId>library</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<type>aar</type>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
android:layout_weight="1"
android:background="#7C7C7C"
app:sl_shadow_angle="225"
app:sl_shadow_color="#000"
app:sl_shadow_color="#5b000000"
app:sl_shadow_distance="4dp"
app:sl_shadow_radius="5dp">

Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray"
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven'

version = "1.0.1"
version = "1.0.2"

android {
compileSdkVersion 23
Expand All @@ -29,7 +29,7 @@ android {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0.1"
versionName "1.0.2"
}
buildTypes {
release {
Expand Down
38 changes: 26 additions & 12 deletions library/src/main/java/com/gigamole/library/ShadowLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
public class ShadowLayout extends FrameLayout {

// Default shadow values
private final static float DEFAULT_SHADOW_RADIUS = 30.0f;
private final static float DEFAULT_SHADOW_DISTANCE = 15.0f;
private final static float DEFAULT_SHADOW_ANGLE = 45.0f;
private final static float DEFAULT_SHADOW_RADIUS = 30.0F;
private final static float DEFAULT_SHADOW_DISTANCE = 15.0F;
private final static float DEFAULT_SHADOW_ANGLE = 45.0F;
private final static int DEFAULT_SHADOW_COLOR = Color.DKGRAY;

// Shadow bounds values
private final static float MAX_ANGLE = 360.0f;
private final static float MIN_RADIUS = 0.1f;
private final static float MIN_ANGLE = 0.0f;
private final static int MAX_ALPHA = 255;
private final static float MAX_ANGLE = 360.0F;
private final static float MIN_RADIUS = 0.1F;
private final static float MIN_ANGLE = 0.0F;
// Shadow paint
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG) {
{
Expand All @@ -53,9 +54,9 @@ public class ShadowLayout extends FrameLayout {
};
// Shadow bitmap and canvas
private Bitmap mBitmap;
private Canvas mCanvas = new Canvas();
private final Canvas mCanvas = new Canvas();
// View bounds
private Rect mBounds = new Rect();
private final Rect mBounds = new Rect();
// Check whether need to redraw shadow
private boolean mInvalidateShadow = true;

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

// Shadow variables
private int mShadowColor;
private int mShadowAlpha;
private float mShadowRadius;
private float mShadowDistance;
private float mShadowAngle;
Expand Down Expand Up @@ -170,8 +172,8 @@ public int getShadowColor() {

public void setShadowColor(final int shadowColor) {
mShadowColor = shadowColor;
mShadowAlpha = Color.alpha(shadowColor);

mPaint.setColor(shadowColor);
resetShadow();
}

Expand All @@ -186,15 +188,24 @@ public float getShadowDy() {
// Reset shadow layer
private void resetShadow() {
// Detect shadow axis offset
mShadowDx = (float) ((mShadowDistance) * Math.cos(mShadowAngle / 180.0f * Math.PI));
mShadowDy = (float) ((mShadowDistance) * Math.sin(mShadowAngle / 180.0f * Math.PI));
mShadowDx = (float) ((mShadowDistance) * Math.cos(mShadowAngle / 180.0F * Math.PI));
mShadowDy = (float) ((mShadowDistance) * Math.sin(mShadowAngle / 180.0F * Math.PI));

// Set padding for shadow bitmap
final int padding = (int) (mShadowDistance + mShadowRadius);
setPadding(padding, padding, padding, padding);
requestLayout();
}

private int adjustShadowAlpha(final boolean adjust) {
return Color.argb(
adjust ? MAX_ALPHA : mShadowAlpha,
Color.red(mShadowColor),
Color.green(mShadowColor),
Color.blue(mShadowColor)
);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Expand Down Expand Up @@ -241,6 +252,7 @@ protected void dispatchDraw(final Canvas canvas) {
mCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

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

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

// Reset alpha to draw child with full alpha
mPaint.setColor(adjustShadowAlpha(true));
// Draw shadow bitmap
if (mCanvas != null && mBitmap != null && !mBitmap.isRecycled())
canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
canvas.drawBitmap(mBitmap, 0.0F, 0.0F, mPaint);
}

// Draw child`s
Expand Down

0 comments on commit ae86c08

Please sign in to comment.