mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Fix NullPointerException on RingView
This commit is contained in:
@@ -27,6 +27,7 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffXfermode;
|
import android.graphics.PorterDuffXfermode;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -57,8 +58,10 @@ public class RingView extends View
|
|||||||
private float textSize;
|
private float textSize;
|
||||||
private boolean enableFontAwesome;
|
private boolean enableFontAwesome;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Bitmap drawingCache;
|
private Bitmap drawingCache;
|
||||||
private Canvas cacheCanvas;
|
private Canvas cacheCanvas;
|
||||||
|
|
||||||
private boolean isTransparencyEnabled;
|
private boolean isTransparencyEnabled;
|
||||||
|
|
||||||
public RingView(Context context)
|
public RingView(Context context)
|
||||||
@@ -175,12 +178,14 @@ public class RingView extends View
|
|||||||
{
|
{
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
|
||||||
if(isTransparencyEnabled)
|
if(isTransparencyEnabled) reallocateCache();
|
||||||
{
|
}
|
||||||
if (drawingCache != null) drawingCache.recycle();
|
|
||||||
drawingCache = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);
|
private void reallocateCache()
|
||||||
cacheCanvas = new Canvas(drawingCache);
|
{
|
||||||
}
|
if (drawingCache != null) drawingCache.recycle();
|
||||||
|
drawingCache = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);
|
||||||
|
cacheCanvas = new Canvas(drawingCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -191,6 +196,7 @@ public class RingView extends View
|
|||||||
|
|
||||||
if(isTransparencyEnabled)
|
if(isTransparencyEnabled)
|
||||||
{
|
{
|
||||||
|
if(drawingCache == null) reallocateCache();
|
||||||
activeCanvas = cacheCanvas;
|
activeCanvas = cacheCanvas;
|
||||||
drawingCache.eraseColor(Color.TRANSPARENT);
|
drawingCache.eraseColor(Color.TRANSPARENT);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user