fixed crashes

This commit is contained in:
Mariotaku Lee 2015-06-26 19:28:01 +08:00
parent 0aa8f1052a
commit 909a01f0a1
3 changed files with 60 additions and 22 deletions

View File

@ -75,8 +75,11 @@ public class ForegroundColorView extends View implements IForegroundView {
@Override @Override
public Drawable getForeground() { public Drawable getForeground() {
if (mForegroundViewHelper != null) {
return mForegroundViewHelper.getForeground(); return mForegroundViewHelper.getForeground();
} }
return null;
}
/** /**
* Supply a Drawable that is to be rendered on top of all of the child views * Supply a Drawable that is to be rendered on top of all of the child views
@ -89,8 +92,10 @@ public class ForegroundColorView extends View implements IForegroundView {
*/ */
@Override @Override
public void setForeground(final Drawable drawable) { public void setForeground(final Drawable drawable) {
if (mForegroundViewHelper != null) {
mForegroundViewHelper.setForeground(drawable); mForegroundViewHelper.setForeground(drawable);
} }
}
/** /**
* Describes how the foreground is positioned. Defaults to START and TOP. * Describes how the foreground is positioned. Defaults to START and TOP.
@ -100,8 +105,10 @@ public class ForegroundColorView extends View implements IForegroundView {
*/ */
@Override @Override
public void setForegroundGravity(final int foregroundGravity) { public void setForegroundGravity(final int foregroundGravity) {
if (mForegroundViewHelper != null) {
mForegroundViewHelper.setForegroundGravity(foregroundGravity); mForegroundViewHelper.setForegroundGravity(foregroundGravity);
} }
}
public void setAlphaPatternEnable(final boolean alphaPattern) { public void setAlphaPatternEnable(final boolean alphaPattern) {
if (mAlphaPattern == alphaPattern) return; if (mAlphaPattern == alphaPattern) return;
@ -112,7 +119,9 @@ public class ForegroundColorView extends View implements IForegroundView {
@Override @Override
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) { protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchOnSizeChanged(w, h, oldw, oldh); mForegroundViewHelper.dispatchOnSizeChanged(w, h, oldw, oldh);
}
mColorRect.set(getPaddingLeft(), getPaddingTop(), w - getPaddingRight(), h - getPaddingBottom()); mColorRect.set(getPaddingLeft(), getPaddingTop(), w - getPaddingRight(), h - getPaddingBottom());
mNumRectanglesHorizontal = (int) Math.ceil(w / mAlphaPatternSize); mNumRectanglesHorizontal = (int) Math.ceil(w / mAlphaPatternSize);
mNumRectanglesVertical = (int) Math.ceil(h / mAlphaPatternSize); mNumRectanglesVertical = (int) Math.ceil(h / mAlphaPatternSize);
@ -122,38 +131,48 @@ public class ForegroundColorView extends View implements IForegroundView {
protected void onDraw(final Canvas canvas) { protected void onDraw(final Canvas canvas) {
drawAlphaPattern(canvas); drawAlphaPattern(canvas);
canvas.drawRect(mColorRect, mPaint); canvas.drawRect(mColorRect, mPaint);
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchOnDraw(canvas); mForegroundViewHelper.dispatchOnDraw(canvas);
} }
}
@Override @Override
protected void onLayout(final boolean changed, final int left, final int top, final int right, final int bottom) { protected void onLayout(final boolean changed, final int left, final int top, final int right, final int bottom) {
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchOnLayout(changed, left, top, right, bottom); mForegroundViewHelper.dispatchOnLayout(changed, left, top, right, bottom);
}
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
} }
@Override @Override
protected boolean verifyDrawable(final Drawable who) { protected boolean verifyDrawable(final Drawable who) {
return super.verifyDrawable(who) || mForegroundViewHelper.verifyDrawable(who); return super.verifyDrawable(who) || (mForegroundViewHelper != null && mForegroundViewHelper.verifyDrawable(who));
} }
@Override @Override
protected void drawableStateChanged() { protected void drawableStateChanged() {
super.drawableStateChanged(); super.drawableStateChanged();
if (mForegroundViewHelper != null) {
mForegroundViewHelper.drawableStateChanged(); mForegroundViewHelper.drawableStateChanged();
} }
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override @Override
public void drawableHotspotChanged(float x, float y) { public void drawableHotspotChanged(float x, float y) {
super.drawableHotspotChanged(x, y); super.drawableHotspotChanged(x, y);
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y); mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y);
} }
}
@Override @Override
public void jumpDrawablesToCurrentState() { public void jumpDrawablesToCurrentState() {
super.jumpDrawablesToCurrentState(); super.jumpDrawablesToCurrentState();
if (mForegroundViewHelper != null) {
mForegroundViewHelper.jumpDrawablesToCurrentState(); mForegroundViewHelper.jumpDrawablesToCurrentState();
} }
}
private void drawAlphaPattern(final Canvas canvas) { private void drawAlphaPattern(final Canvas canvas) {
if (!mAlphaPattern) return; if (!mAlphaPattern) return;

View File

@ -49,8 +49,11 @@ public class ForegroundImageView extends ImageView implements IForegroundView {
@Override @Override
public Drawable getForeground() { public Drawable getForeground() {
if (mForegroundViewHelper != null) {
return mForegroundViewHelper.getForeground(); return mForegroundViewHelper.getForeground();
} }
return null;
}
/** /**
* Supply a Drawable that is to be rendered on top of all of the child views * Supply a Drawable that is to be rendered on top of all of the child views
@ -63,8 +66,10 @@ public class ForegroundImageView extends ImageView implements IForegroundView {
*/ */
@Override @Override
public void setForeground(final Drawable drawable) { public void setForeground(final Drawable drawable) {
if (mForegroundViewHelper != null) {
mForegroundViewHelper.setForeground(drawable); mForegroundViewHelper.setForeground(drawable);
} }
}
/** /**
* Describes how the foreground is positioned. Defaults to START and TOP. * Describes how the foreground is positioned. Defaults to START and TOP.
@ -74,49 +79,63 @@ public class ForegroundImageView extends ImageView implements IForegroundView {
*/ */
@Override @Override
public void setForegroundGravity(final int foregroundGravity) { public void setForegroundGravity(final int foregroundGravity) {
if (mForegroundViewHelper != null) {
mForegroundViewHelper.setForegroundGravity(foregroundGravity); mForegroundViewHelper.setForegroundGravity(foregroundGravity);
} }
}
@Override @Override
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) { protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchOnSizeChanged(w, h, oldw, oldh); mForegroundViewHelper.dispatchOnSizeChanged(w, h, oldw, oldh);
} }
}
@Override @Override
protected void onLayout(final boolean changed, final int left, final int top, final int right, final int bottom) { protected void onLayout(final boolean changed, final int left, final int top, final int right, final int bottom) {
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchOnLayout(changed, left, top, right, bottom); mForegroundViewHelper.dispatchOnLayout(changed, left, top, right, bottom);
}
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
} }
@Override @Override
protected boolean verifyDrawable(final Drawable who) { protected boolean verifyDrawable(final Drawable who) {
return super.verifyDrawable(who) || mForegroundViewHelper.verifyDrawable(who); return super.verifyDrawable(who) || (mForegroundViewHelper != null && mForegroundViewHelper.verifyDrawable(who));
} }
@Override @Override
public void jumpDrawablesToCurrentState() { public void jumpDrawablesToCurrentState() {
super.jumpDrawablesToCurrentState(); super.jumpDrawablesToCurrentState();
if (mForegroundViewHelper != null) {
mForegroundViewHelper.jumpDrawablesToCurrentState(); mForegroundViewHelper.jumpDrawablesToCurrentState();
} }
}
@Override @Override
protected void drawableStateChanged() { protected void drawableStateChanged() {
super.drawableStateChanged(); super.drawableStateChanged();
if (mForegroundViewHelper != null) {
mForegroundViewHelper.drawableStateChanged(); mForegroundViewHelper.drawableStateChanged();
} }
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override @Override
public void drawableHotspotChanged(float x, float y) { public void drawableHotspotChanged(float x, float y) {
super.drawableHotspotChanged(x, y); super.drawableHotspotChanged(x, y);
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y); mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y);
} }
}
@Override @Override
protected void onDraw(@NonNull final Canvas canvas) { protected void onDraw(@NonNull final Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchOnDraw(canvas); mForegroundViewHelper.dispatchOnDraw(canvas);
} }
}
} }

View File

@ -2,7 +2,7 @@
<!-- <!--
~ Twidere - Twitter client for Android ~ Twidere - Twitter client for Android
~ ~
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com> ~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
~ ~
~ This program is free software: you can redistribute it and/or modify ~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by ~ it under the terms of the GNU General Public License as published by