From b0bf2b56cec7773b52c0c72a7ffa359935475cc9 Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Sat, 14 May 2016 12:46:00 +0300 Subject: [PATCH] Update 1.0.1 --- README.md | 6 ++-- library/build.gradle | 4 +-- .../com/gigamole/library/ShadowLayout.java | 33 +++++++++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 03197d6..b2a69c8 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ dependencies { Or Gradle Maven Central: ```groovy -compile 'com.github.devlight.shadowlayout:library:1.0.0' +compile 'com.github.devlight.shadowlayout:library:1.0.1' ``` Or Maven: @@ -41,7 +41,7 @@ Or Maven: com.github.devlight.shadowlayout library - 1.0.0 + 1.0.1 aar ``` @@ -49,7 +49,7 @@ Or Maven: Android SDK Version ========= -ShadowLayout requires a minimum sdk version of 11. +ShadowLayout requires a minimum SDK version of 11. Sample ======== diff --git a/library/build.gradle b/library/build.gradle index 2aafd88..9abcdef 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray" apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'maven' -version = "1.0.0" +version = "1.0.1" android { compileSdkVersion 23 @@ -29,7 +29,7 @@ android { minSdkVersion 11 targetSdkVersion 23 versionCode 1 - versionName "1.0.0" + versionName "1.0.1" } buildTypes { release { diff --git a/library/src/main/java/com/gigamole/library/ShadowLayout.java b/library/src/main/java/com/gigamole/library/ShadowLayout.java index 567d747..eff84ce 100644 --- a/library/src/main/java/com/gigamole/library/ShadowLayout.java +++ b/library/src/main/java/com/gigamole/library/ShadowLayout.java @@ -23,6 +23,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.support.annotation.FloatRange; import android.util.AttributeSet; @@ -112,6 +113,16 @@ public ShadowLayout(final Context context, final AttributeSet attrs, final int d } } + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + // Clear shadow bitmap + if (mBitmap != null) { + mBitmap.recycle(); + mBitmap = null; + } + } + public boolean isShadowed() { return mIsShadowed; } @@ -224,17 +235,27 @@ protected void dispatchDraw(final Canvas canvas) { // paint does`t draw shadow, it draw another copy of bitmap super.dispatchDraw(mCanvas); - // Draw alpha chanel bitmap of our local canvas - mCanvas.drawBitmap(mBitmap.extractAlpha(), mShadowDx, mShadowDy, mPaint); + // Get the alpha bounds of bitmap + final Bitmap extractedAlpha = mBitmap.extractAlpha(); + // Clear past content content to draw shadow + mCanvas.drawColor(0, PorterDuff.Mode.CLEAR); + + // Draw extracted alpha bounds of our local canvas + mCanvas.drawBitmap(extractedAlpha, mShadowDx, mShadowDy, mPaint); + + // Recycle and clear extracted alpha + extractedAlpha.recycle(); } else { - // Clear shadow bitmap - mBitmap.recycle(); - mBitmap = null; + // Create placeholder bitmap when size is zero and wait until new size coming up + mBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); } } // Draw shadow bitmap - if (mCanvas != null && mBitmap != null) canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null); + if (mCanvas != null) { + if (mBitmap != null && !mBitmap.isRecycled()) + canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null); + } } // Draw child`s