aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-03-08 17:28:19 -0700
committerScott Jackson <daneren2005@gmail.com>2015-03-08 17:28:19 -0700
commitb2ea0d0f28a9c583234fc1d83115b514db7c049f (patch)
treeeb3dc8707ac5fa55a9f96f26d8d39607a9432948 /src
parentb71b8726238c30a16dfbdd525cc68dfc52ceb36e (diff)
downloaddsub-b2ea0d0f28a9c583234fc1d83115b514db7c049f.tar.gz
dsub-b2ea0d0f28a9c583234fc1d83115b514db7c049f.tar.bz2
dsub-b2ea0d0f28a9c583234fc1d83115b514db7c049f.zip
Get around the random recycled bitmap errors from calling onDraw after a bitmap had been recycled to make room for a new one. This isn't the ideal fix since it will show a blank image, but it is better than just crashing.
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/view/RecyclingImageView.java57
-rw-r--r--src/github/daneren2005/dsub/view/SquareImageView.java2
2 files changed, 58 insertions, 1 deletions
diff --git a/src/github/daneren2005/dsub/view/RecyclingImageView.java b/src/github/daneren2005/dsub/view/RecyclingImageView.java
new file mode 100644
index 00000000..c4fc7f0a
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/RecyclingImageView.java
@@ -0,0 +1,57 @@
+/*
+ This file is part of Subsonic.
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+ Copyright 2015 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.view;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+public class RecyclingImageView extends ImageView {
+ public RecyclingImageView(Context context) {
+ super(context);
+ }
+
+ public RecyclingImageView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public RecyclingImageView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public RecyclingImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ Drawable drawable = this.getDrawable();
+ if(drawable != null && drawable instanceof BitmapDrawable) {
+ BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
+ if(bitmapDrawable.getBitmap() != null && bitmapDrawable.getBitmap().isRecycled()) {
+ this.setImageDrawable(null);
+ }
+ }
+
+ super.onDraw(canvas);
+ }
+}
diff --git a/src/github/daneren2005/dsub/view/SquareImageView.java b/src/github/daneren2005/dsub/view/SquareImageView.java
index 77ca50db..44a74e16 100644
--- a/src/github/daneren2005/dsub/view/SquareImageView.java
+++ b/src/github/daneren2005/dsub/view/SquareImageView.java
@@ -19,7 +19,7 @@ import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
-public class SquareImageView extends ImageView {
+public class SquareImageView extends RecyclingImageView {
public SquareImageView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}