aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
Diffstat (limited to 'src/github')
-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);
}