Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6aa92d1c authored by Alan Viverette's avatar Alan Viverette
Browse files

Clean up ImageView

Refactors ImageView to use LOG_TAG constant, fixes indentation, trailing
whitespace, uses of final. No functional changes.

Change-Id: I9e67d9a152e1c6d646719afa5010c45868db9c6f
parent fa0f7cdd
Loading
Loading
Loading
Loading
+92 −99
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ import java.io.InputStream;
 */
@RemoteView
public class ImageView extends View {
    private static final String LOG_TAG = "ImageView";

    // settable by the client
    private Uri mUri;
    private int mResource = 0;
@@ -87,7 +89,7 @@ public class ImageView extends View {
    private boolean mHasColorFilter = false;
    private Xfermode mXfermode;
    private int mAlpha = 255;
    private int mViewAlphaScale = 256;
    private final int mViewAlphaScale = 256;
    private boolean mColorMod = false;

    private Drawable mDrawable = null;
@@ -105,8 +107,8 @@ public class ImageView extends View {
    private Matrix mDrawMatrix = null;

    // Avoid allocations...
    private RectF mTempSrc = new RectF();
    private RectF mTempDst = new RectF();
    private final RectF mTempSrc = new RectF();
    private final RectF mTempDst = new RectF();

    private boolean mCropToPadding;

@@ -147,30 +149,21 @@ public class ImageView extends View {
        initImageView();

        final TypedArray a = context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.ImageView, defStyleAttr, defStyleRes);
                attrs, R.styleable.ImageView, defStyleAttr, defStyleRes);

        Drawable d = a.getDrawable(com.android.internal.R.styleable.ImageView_src);
        final Drawable d = a.getDrawable(R.styleable.ImageView_src);
        if (d != null) {
            setImageDrawable(d);
        }

        mBaselineAlignBottom = a.getBoolean(
                com.android.internal.R.styleable.ImageView_baselineAlignBottom, false);

        mBaseline = a.getDimensionPixelSize(
                com.android.internal.R.styleable.ImageView_baseline, -1);

        setAdjustViewBounds(
            a.getBoolean(com.android.internal.R.styleable.ImageView_adjustViewBounds,
            false));

        setMaxWidth(a.getDimensionPixelSize(
                com.android.internal.R.styleable.ImageView_maxWidth, Integer.MAX_VALUE));
        mBaselineAlignBottom = a.getBoolean(R.styleable.ImageView_baselineAlignBottom, false);
        mBaseline = a.getDimensionPixelSize(R.styleable.ImageView_baseline, -1);

        setMaxHeight(a.getDimensionPixelSize(
                com.android.internal.R.styleable.ImageView_maxHeight, Integer.MAX_VALUE));
        setAdjustViewBounds(a.getBoolean(R.styleable.ImageView_adjustViewBounds, false));
        setMaxWidth(a.getDimensionPixelSize(R.styleable.ImageView_maxWidth, Integer.MAX_VALUE));
        setMaxHeight(a.getDimensionPixelSize(R.styleable.ImageView_maxHeight, Integer.MAX_VALUE));

        final int index = a.getInt(com.android.internal.R.styleable.ImageView_scaleType, -1);
        final int index = a.getInt(R.styleable.ImageView_scaleType, -1);
        if (index >= 0) {
            setScaleType(sScaleTypeArray[index]);
        }
@@ -193,13 +186,13 @@ public class ImageView extends View {

        applyImageTint();

        final int alpha = a.getInt(com.android.internal.R.styleable.ImageView_drawableAlpha, 255);
        final int alpha = a.getInt(R.styleable.ImageView_drawableAlpha, 255);
        if (alpha != 255) {
            setAlpha(alpha);
            setImageAlpha(alpha);
        }

        mCropToPadding = a.getBoolean(
                com.android.internal.R.styleable.ImageView_cropToPadding, false);
                R.styleable.ImageView_cropToPadding, false);

        a.recycle();

@@ -209,8 +202,8 @@ public class ImageView extends View {
    private void initImageView() {
        mMatrix = new Matrix();
        mScaleType = ScaleType.FIT_CENTER;
        mAdjustViewBoundsCompat = mContext.getApplicationInfo().targetSdkVersion <=
                Build.VERSION_CODES.JELLY_BEAN_MR1;
        mAdjustViewBoundsCompat = mContext.getApplicationInfo().targetSdkVersion
                <= Build.VERSION_CODES.JELLY_BEAN_MR1;
    }

    @Override
@@ -258,7 +251,8 @@ public class ImageView extends View {
    @Override
    public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
        super.onPopulateAccessibilityEventInternal(event);
        CharSequence contentDescription = getContentDescription();

        final CharSequence contentDescription = getContentDescription();
        if (!TextUtils.isEmpty(contentDescription)) {
            event.getText().add(contentDescription);
        }
@@ -269,7 +263,7 @@ public class ImageView extends View {
     * to preserve the aspect ratio of its drawable
     *
     * @return whether to adjust the bounds of this view
     * to presrve the original aspect ratio of the drawable
     * to preserve the original aspect ratio of the drawable
     *
     * @see #setAdjustViewBounds(boolean)
     *
@@ -436,9 +430,7 @@ public class ImageView extends View {
     */
    @android.view.RemotableViewMethod
    public void setImageURI(@Nullable Uri uri) {
        if (mResource != 0 ||
                (mUri != uri &&
                 (uri == null || mUri == null || !uri.equals(mUri)))) {
        if (mResource != 0 || (mUri != uri && (uri == null || mUri == null || !uri.equals(mUri)))) {
            updateDrawable(null);
            mResource = 0;
            mUri = uri;
@@ -787,8 +779,8 @@ public class ImageView extends View {
            return;
        }

        Resources rsrc = getResources();
        if (rsrc == null) {
        final Resources res = getResources();
        if (res == null) {
            return;
        }

@@ -798,12 +790,12 @@ public class ImageView extends View {
            try {
                d = mContext.getDrawable(mResource);
            } catch (Exception e) {
                Log.w("ImageView", "Unable to find resource: " + mResource, e);
                Log.w(LOG_TAG, "Unable to find resource: " + mResource, e);
                // Don't try again.
                mUri = null;
            }
        } else if (mUri != null) {
            String scheme = mUri.getScheme();
            final String scheme = mUri.getScheme();
            if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)) {
                try {
                    // Load drawable through Resources, to get the source density information
@@ -811,7 +803,7 @@ public class ImageView extends View {
                            mContext.getContentResolver().getResourceId(mUri);
                    d = r.r.getDrawable(r.id, mContext.getTheme());
                } catch (Exception e) {
                    Log.w("ImageView", "Unable to open content: " + mUri, e);
                    Log.w(LOG_TAG, "Unable to open content: " + mUri, e);
                }
            } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)
                    || ContentResolver.SCHEME_FILE.equals(scheme)) {
@@ -820,13 +812,13 @@ public class ImageView extends View {
                    stream = mContext.getContentResolver().openInputStream(mUri);
                    d = Drawable.createFromStream(stream, null);
                } catch (Exception e) {
                    Log.w("ImageView", "Unable to open content: " + mUri, e);
                    Log.w(LOG_TAG, "Unable to open content: " + mUri, e);
                } finally {
                    if (stream != null) {
                        try {
                            stream.close();
                        } catch (IOException e) {
                            Log.w("ImageView", "Unable to close content: " + mUri, e);
                            Log.w(LOG_TAG, "Unable to close content: " + mUri, e);
                        }
                    }
                }
@@ -835,7 +827,7 @@ public class ImageView extends View {
            }

            if (d == null) {
                System.out.println("resolveUri failed on bad bitmap uri: " + mUri);
                Log.w(LOG_TAG, "resolveUri failed on bad bitmap uri: " + mUri);
                // Don't try again.
                mUri = null;
            }
@@ -890,7 +882,7 @@ public class ImageView extends View {
    }

    private void resizeFromDrawable() {
        Drawable d = mDrawable;
        final Drawable d = mDrawable;
        if (d != null) {
            int w = d.getIntrinsicWidth();
            if (w < 0) w = mDrawableWidth;
@@ -964,10 +956,10 @@ public class ImageView extends View {
            }
        }

        int pleft = mPaddingLeft;
        int pright = mPaddingRight;
        int ptop = mPaddingTop;
        int pbottom = mPaddingBottom;
        final int pleft = mPaddingLeft;
        final int pright = mPaddingRight;
        final int ptop = mPaddingTop;
        final int pbottom = mPaddingBottom;

        int widthSize;
        int heightSize;
@@ -986,7 +978,7 @@ public class ImageView extends View {

            if (desiredAspect != 0.0f) {
                // See what our actual aspect ratio is
                float actualAspect = (float)(widthSize - pleft - pright) /
                final float actualAspect = (float)(widthSize - pleft - pright) /
                                        (heightSize - ptop - pbottom);

                if (Math.abs(actualAspect - desiredAspect) > 0.0000001) {
@@ -1047,8 +1039,8 @@ public class ImageView extends View {
    private int resolveAdjustedSize(int desiredSize, int maxSize,
                                   int measureSpec) {
        int result = desiredSize;
        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize =  MeasureSpec.getSize(measureSpec);
        final int specMode = MeasureSpec.getMode(measureSpec);
        final int specSize =  MeasureSpec.getSize(measureSpec);
        switch (specMode) {
            case MeasureSpec.UNSPECIFIED:
                /* Parent says we can be as big as we want. Just don't be larger
@@ -1072,7 +1064,7 @@ public class ImageView extends View {

    @Override
    protected boolean setFrame(int l, int t, int r, int b) {
        boolean changed = super.setFrame(l, t, r, b);
        final boolean changed = super.setFrame(l, t, r, b);
        mHaveFrame = true;
        configureBounds();
        return changed;
@@ -1083,14 +1075,14 @@ public class ImageView extends View {
            return;
        }

        int dwidth = mDrawableWidth;
        int dheight = mDrawableHeight;
        final int dwidth = mDrawableWidth;
        final int dheight = mDrawableHeight;

        int vwidth = getWidth() - mPaddingLeft - mPaddingRight;
        int vheight = getHeight() - mPaddingTop - mPaddingBottom;
        final int vwidth = getWidth() - mPaddingLeft - mPaddingRight;
        final int vheight = getHeight() - mPaddingTop - mPaddingBottom;

        boolean fits = (dwidth < 0 || vwidth == dwidth) &&
                       (dheight < 0 || vheight == dheight);
        final boolean fits = (dwidth < 0 || vwidth == dwidth)
                && (dheight < 0 || vheight == dheight);

        if (dwidth <= 0 || dheight <= 0 || ScaleType.FIT_XY == mScaleType) {
            /* If the drawable has no intrinsic size, or we're told to
@@ -1166,7 +1158,8 @@ public class ImageView extends View {
    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        Drawable d = mDrawable;

        final Drawable d = mDrawable;
        if (d != null && d.isStateful()) {
            d.setState(getDrawableState());
        }
@@ -1213,7 +1206,7 @@ public class ImageView extends View {
        if (mDrawMatrix == null && mPaddingTop == 0 && mPaddingLeft == 0) {
            mDrawable.draw(canvas);
        } else {
            int saveCount = canvas.getSaveCount();
            final int saveCount = canvas.getSaveCount();
            canvas.save();

            if (mCropToPadding) {