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,7 +75,10 @@ public class ForegroundColorView extends View implements IForegroundView {
@Override @Override
public Drawable getForeground() { public Drawable getForeground() {
return mForegroundViewHelper.getForeground(); if (mForegroundViewHelper != null) {
return mForegroundViewHelper.getForeground();
}
return null;
} }
/** /**
@ -89,7 +92,9 @@ public class ForegroundColorView extends View implements IForegroundView {
*/ */
@Override @Override
public void setForeground(final Drawable drawable) { public void setForeground(final Drawable drawable) {
mForegroundViewHelper.setForeground(drawable); if (mForegroundViewHelper != null) {
mForegroundViewHelper.setForeground(drawable);
}
} }
/** /**
@ -100,7 +105,9 @@ public class ForegroundColorView extends View implements IForegroundView {
*/ */
@Override @Override
public void setForegroundGravity(final int foregroundGravity) { public void setForegroundGravity(final int foregroundGravity) {
mForegroundViewHelper.setForegroundGravity(foregroundGravity); if (mForegroundViewHelper != null) {
mForegroundViewHelper.setForegroundGravity(foregroundGravity);
}
} }
public void setAlphaPatternEnable(final boolean alphaPattern) { public void setAlphaPatternEnable(final boolean alphaPattern) {
@ -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);
mForegroundViewHelper.dispatchOnSizeChanged(w, h, oldw, oldh); if (mForegroundViewHelper != null) {
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,37 +131,47 @@ 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);
mForegroundViewHelper.dispatchOnDraw(canvas); if (mForegroundViewHelper != null) {
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) {
mForegroundViewHelper.dispatchOnLayout(changed, left, top, right, bottom); if (mForegroundViewHelper != null) {
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();
mForegroundViewHelper.drawableStateChanged(); if (mForegroundViewHelper != null) {
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);
mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y); if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y);
}
} }
@Override @Override
public void jumpDrawablesToCurrentState() { public void jumpDrawablesToCurrentState() {
super.jumpDrawablesToCurrentState(); super.jumpDrawablesToCurrentState();
mForegroundViewHelper.jumpDrawablesToCurrentState(); if (mForegroundViewHelper != null) {
mForegroundViewHelper.jumpDrawablesToCurrentState();
}
} }
private void drawAlphaPattern(final Canvas canvas) { private void drawAlphaPattern(final Canvas canvas) {

View File

@ -49,7 +49,10 @@ public class ForegroundImageView extends ImageView implements IForegroundView {
@Override @Override
public Drawable getForeground() { public Drawable getForeground() {
return mForegroundViewHelper.getForeground(); if (mForegroundViewHelper != null) {
return mForegroundViewHelper.getForeground();
}
return null;
} }
/** /**
@ -63,7 +66,9 @@ public class ForegroundImageView extends ImageView implements IForegroundView {
*/ */
@Override @Override
public void setForeground(final Drawable drawable) { public void setForeground(final Drawable drawable) {
mForegroundViewHelper.setForeground(drawable); if (mForegroundViewHelper != null) {
mForegroundViewHelper.setForeground(drawable);
}
} }
/** /**
@ -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) {
mForegroundViewHelper.setForegroundGravity(foregroundGravity); if (mForegroundViewHelper != null) {
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);
mForegroundViewHelper.dispatchOnSizeChanged(w, h, oldw, oldh); if (mForegroundViewHelper != null) {
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) {
mForegroundViewHelper.dispatchOnLayout(changed, left, top, right, bottom); if (mForegroundViewHelper != null) {
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();
mForegroundViewHelper.jumpDrawablesToCurrentState(); if (mForegroundViewHelper != null) {
mForegroundViewHelper.jumpDrawablesToCurrentState();
}
} }
@Override @Override
protected void drawableStateChanged() { protected void drawableStateChanged() {
super.drawableStateChanged(); super.drawableStateChanged();
mForegroundViewHelper.drawableStateChanged(); if (mForegroundViewHelper != null) {
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);
mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y); if (mForegroundViewHelper != null) {
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);
mForegroundViewHelper.dispatchOnDraw(canvas); if (mForegroundViewHelper != null) {
mForegroundViewHelper.dispatchOnDraw(canvas);
}
} }
} }

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ 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