From e350a6ef58abb27f412af5aa05fd8e4d4ae96f57 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 15 Jun 2014 23:40:25 +0300 Subject: [PATCH] Remove Context field --- src/com/blundell/tut/LoaderImageView.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/com/blundell/tut/LoaderImageView.java b/src/com/blundell/tut/LoaderImageView.java index f62d843..31ec4b9 100644 --- a/src/com/blundell/tut/LoaderImageView.java +++ b/src/com/blundell/tut/LoaderImageView.java @@ -32,7 +32,6 @@ public final class LoaderImageView extends FrameLayout { private static final int FAILED = 1; private static final int PROGRESS = 2; - private Context mContext; private Drawable mDrawable; private ProgressWheel mProgressBar; private ImageView mImage; @@ -49,7 +48,7 @@ public final class LoaderImageView extends FrameLayout { public LoaderImageView(final Context context, final AttributeSet attrSet) { super(context, attrSet); final String url = attrSet.getAttributeValue(null, "image"); - instantiate(context, url); + instantiate(url); } /** @@ -61,19 +60,18 @@ public final class LoaderImageView extends FrameLayout { */ public LoaderImageView(final Context context, final String imageUrl) { super(context); - instantiate(context, imageUrl); + instantiate(imageUrl); } /** * This is used when creating the view programmatically * Once you have instantiated the view you can call * setImageDrawable(url) to change the image - * @param context the Activity context * @param imageUrl the Image URL you wish to load */ public LoaderImageView(final Context context) { super(context); - instantiate(context, null); + instantiate(null); } /** @@ -81,13 +79,11 @@ public final class LoaderImageView extends FrameLayout { * Sets up the LayoutParams of the view, you can change these to * get the required effects you want */ - private void instantiate(final Context context, final String imageUrl) { - mContext = context; - - mImage = new ImageView(mContext); + private void instantiate(final String imageUrl) { + mImage = new ImageView(getContext()); mImage.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - mProgressBar = new ProgressWheel(mContext); + mProgressBar = new ProgressWheel(getContext()); mProgressBar.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER)); @@ -197,7 +193,7 @@ public final class LoaderImageView extends FrameLayout { output = null; Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); data = null; - return new BitmapDrawable(mContext.getResources(), bitmap); + return new BitmapDrawable(getContext().getResources(), bitmap); } }