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

View File

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

View File

@ -2,7 +2,7 @@
<!--
~ 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
~ it under the terms of the GNU General Public License as published by