Skip to content

Commit

Permalink
Merge pull request dmytrodanylyk#6 from MaciejCiemiega/dev
Browse files Browse the repository at this point in the history
1. Fixed issue #7 
2. Added `invalidateShadowBitmap` method to force shadow re-creation on user's reques
  • Loading branch information
dmytrodanylyk committed Mar 30, 2015
2 parents 1908f13 + 119d52a commit fa0516c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion library/src/main/java/com/dd/ShadowLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class ShadowLayout extends FrameLayout {
private float mDx;
private float mDy;

private boolean mInvalidateShadowOnSizeChanged = true;
private boolean mForceInvalidateShadow = false;

public ShadowLayout(Context context) {
super(context);
initView(context, null);
Expand All @@ -35,11 +38,21 @@ public ShadowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if(w > 0 && h > 0) {
if(w > 0 && h > 0 && (getBackground() == null || mInvalidateShadowOnSizeChanged || mForceInvalidateShadow)) {
mForceInvalidateShadow = false;
setBackgroundCompat(w, h);
}
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (mForceInvalidateShadow) {
mForceInvalidateShadow = false;
setBackgroundCompat(right-left, bottom-top);
}
}

private void initView(Context context, AttributeSet attrs) {
initAttributes(context, attrs);

Expand Down Expand Up @@ -122,4 +135,24 @@ private Bitmap createShadowBitmap(int shadowWidth, int shadowHeight, float corne

return output;
}

@Override
protected int getSuggestedMinimumWidth() {
return 0;
}

@Override
protected int getSuggestedMinimumHeight() {
return 0;
}

public void setInvalidateShadowOnSizeChanged(boolean invalidateShadowOnSizeChanged) {
this.mInvalidateShadowOnSizeChanged = invalidateShadowOnSizeChanged;
}

public void invalidateShadow() {
this.mForceInvalidateShadow = true;
requestLayout();
invalidate();
}
}

0 comments on commit fa0516c

Please sign in to comment.