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

Commit a9459755 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Fix UserAvatarView.setDisabled method.

Currently, we grey out the icon only when setDisabled method is called
and the icon is not already disabled. This would be a problem, if the
drawable is updated again. Updated to change the disabled state of the
icon in onDraw.

Bug: 26737161
Change-Id: Id166c05c3be3b1ebd9320b8f75f25a5a5cd12210
parent 9ef46c26
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -174,6 +174,7 @@ public class UserAvatarView extends View {
        float halfW = getWidth() / 2f;
        float halfW = getWidth() / 2f;
        float halfH = getHeight() / 2f;
        float halfH = getHeight() / 2f;
        float halfSW = Math.min(halfH, halfW);
        float halfSW = Math.min(halfH, halfW);
        updateDrawableIfDisabled();
        if (mBitmap != null && mScale > 0) {
        if (mBitmap != null && mScale > 0) {
            int saveCount = canvas.getSaveCount();
            int saveCount = canvas.getSaveCount();
            canvas.save();
            canvas.save();
@@ -249,22 +250,25 @@ public class UserAvatarView extends View {
            return;
            return;
        }
        }
        mIsDisabled = disabled;
        mIsDisabled = disabled;
        invalidate();
    }

    private void updateDrawableIfDisabled() {
        int disabledColor = getContext().getColor(R.color.qs_tile_disabled_color);
        int disabledColor = getContext().getColor(R.color.qs_tile_disabled_color);
        PorterDuffColorFilter filter = new PorterDuffColorFilter(disabledColor,
        PorterDuffColorFilter filter = new PorterDuffColorFilter(disabledColor,
                PorterDuff.Mode.SRC_ATOP);
                PorterDuff.Mode.SRC_ATOP);
        if (mBitmap != null) {
        if (mBitmap != null) {
            if (disabled) {
            if (mIsDisabled) {
                mBitmapPaint.setColorFilter(filter);
                mBitmapPaint.setColorFilter(filter);
            } else {
            } else {
                mBitmapPaint.setColorFilter(null);
                mBitmapPaint.setColorFilter(null);
            }
            }
        } else if (mDrawable != null) {
        } else if (mDrawable != null) {
            if (disabled) {
            if (mIsDisabled) {
                mDrawable.setColorFilter(filter);
                mDrawable.setColorFilter(filter);
            } else {
            } else {
                mDrawable.setColorFilter(null);
                mDrawable.setColorFilter(null);
            }
            }
        }
        }
        invalidate();
    }
    }
}
}