Skip to content

Commit b0bf2b5

Browse files
committed
Update 1.0.1
1 parent 52fab69 commit b0bf2b5

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
Or Gradle Maven Central:
3333

3434
```groovy
35-
compile 'com.github.devlight.shadowlayout:library:1.0.0'
35+
compile 'com.github.devlight.shadowlayout:library:1.0.1'
3636
```
3737

3838
Or Maven:
@@ -41,15 +41,15 @@ Or Maven:
4141
<dependency>
4242
<groupId>com.github.devlight.shadowlayout</groupId>
4343
<artifactId>library</artifactId>
44-
<version>1.0.0</version>
44+
<version>1.0.1</version>
4545
<type>aar</type>
4646
</dependency>
4747
```
4848

4949
Android SDK Version
5050
=========
5151

52-
ShadowLayout requires a minimum sdk version of 11.
52+
ShadowLayout requires a minimum SDK version of 11.
5353

5454
Sample
5555
========

library/build.gradle

Lines changed: 2 additions & 2 deletions
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.0"
22+
version = "1.0.1"
2323

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

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.Canvas;
2424
import android.graphics.Color;
2525
import android.graphics.Paint;
26+
import android.graphics.PorterDuff;
2627
import android.graphics.Rect;
2728
import android.support.annotation.FloatRange;
2829
import android.util.AttributeSet;
@@ -112,6 +113,16 @@ public ShadowLayout(final Context context, final AttributeSet attrs, final int d
112113
}
113114
}
114115

116+
@Override
117+
protected void onDetachedFromWindow() {
118+
super.onDetachedFromWindow();
119+
// Clear shadow bitmap
120+
if (mBitmap != null) {
121+
mBitmap.recycle();
122+
mBitmap = null;
123+
}
124+
}
125+
115126
public boolean isShadowed() {
116127
return mIsShadowed;
117128
}
@@ -224,17 +235,27 @@ protected void dispatchDraw(final Canvas canvas) {
224235
// paint does`t draw shadow, it draw another copy of bitmap
225236
super.dispatchDraw(mCanvas);
226237

227-
// Draw alpha chanel bitmap of our local canvas
228-
mCanvas.drawBitmap(mBitmap.extractAlpha(), mShadowDx, mShadowDy, mPaint);
238+
// Get the alpha bounds of bitmap
239+
final Bitmap extractedAlpha = mBitmap.extractAlpha();
240+
// Clear past content content to draw shadow
241+
mCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
242+
243+
// Draw extracted alpha bounds of our local canvas
244+
mCanvas.drawBitmap(extractedAlpha, mShadowDx, mShadowDy, mPaint);
245+
246+
// Recycle and clear extracted alpha
247+
extractedAlpha.recycle();
229248
} else {
230-
// Clear shadow bitmap
231-
mBitmap.recycle();
232-
mBitmap = null;
249+
// Create placeholder bitmap when size is zero and wait until new size coming up
250+
mBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
233251
}
234252
}
235253

236254
// Draw shadow bitmap
237-
if (mCanvas != null && mBitmap != null) canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
255+
if (mCanvas != null) {
256+
if (mBitmap != null && !mBitmap.isRecycled())
257+
canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
258+
}
238259
}
239260

240261
// Draw child`s

0 commit comments

Comments
 (0)