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

Commit 9b120d5a authored by Evan Laird's avatar Evan Laird Committed by Android (Google) Code Review
Browse files

Merge "Fix wifi tile animating full-dark when slashing/unslashing" into oc-mr1-dev

parents d7122735 6026b057
Loading
Loading
Loading
Loading
+86 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.qs;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import com.android.systemui.qs.tileimpl.SlashImageView;


/**
 * Creates AlphaControlledSlashImageView instead of SlashImageView
 */
public class AlphaControlledSignalTileView extends SignalTileView {
    public AlphaControlledSignalTileView(Context context) {
        super(context);
    }

    @Override
    protected SlashImageView createSlashImageView(Context context) {
        return new AlphaControlledSlashImageView(context);
    }

    /**
     * Creates AlphaControlledSlashDrawable instead of regular SlashDrawables
     */
    public static class AlphaControlledSlashImageView extends SlashImageView {
        public AlphaControlledSlashImageView(Context context) {
            super(context);
        }

        public void setFinalImageTintList(ColorStateList tint) {
            super.setImageTintList(tint);
            final SlashDrawable slash = getSlash();
            if (slash != null) {
                ((AlphaControlledSlashDrawable)slash).setFinalTintList(tint);
            }
        }

        @Override
        protected void ensureSlashDrawable() {
            if (getSlash() == null) {
                final SlashDrawable slash = new AlphaControlledSlashDrawable(getDrawable());
                setSlash(slash);
                slash.setAnimationEnabled(getAnimationEnabled());
                setImageViewDrawable(slash);
            }
        }
    }

    /**
     * SlashDrawable that disobeys orders to change its drawable's tint except when you tell
     * it not to disobey. The slash still will animate its alpha.
     */
    public static class AlphaControlledSlashDrawable extends SlashDrawable {
        AlphaControlledSlashDrawable(Drawable d) {
            super(d);
        }

        @Override
        protected void setDrawableTintList(ColorStateList tint) {
        }

        /**
         * Set a target tint list instead of
         */
        public void setFinalTintList(ColorStateList tint) {
            super.setDrawableTintList(tint);
        }
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -63,13 +63,17 @@ public class SignalTileView extends QSIconViewImpl {
    @Override
    protected View createIcon() {
        mIconFrame = new FrameLayout(mContext);
        mSignal = new SlashImageView(mContext);
        mSignal = createSlashImageView(mContext);
        mIconFrame.addView(mSignal);
        mOverlay = new ImageView(mContext);
        mIconFrame.addView(mOverlay, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        return mIconFrame;
    }

    protected SlashImageView createSlashImageView(Context context) {
        return new SlashImageView(context);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+5 −1
Original line number Diff line number Diff line
@@ -197,11 +197,15 @@ public class SlashDrawable extends Drawable {
    public void setTintList(@Nullable ColorStateList tint) {
        mTintList = tint;
        super.setTintList(tint);
        mDrawable.setTintList(tint);
        setDrawableTintList(tint);
        mPaint.setColor(tint.getDefaultColor());
        invalidateSelf();
    }

    protected void setDrawableTintList(@Nullable ColorStateList tint) {
        mDrawable.setTintList(tint);
    }

    @Override
    public void setTintMode(@NonNull Mode tintMode) {
        mTintMode = tintMode;
+11 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.systemui.plugins.qs.QSIconView;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTile.State;

import com.android.systemui.qs.AlphaControlledSignalTileView.AlphaControlledSlashImageView;
import java.util.Objects;

public class QSIconViewImpl extends QSIconView {
@@ -137,8 +138,13 @@ public class QSIconViewImpl extends QSIconView {
            if (iv.isShown() && mTint != 0) {
                animateGrayScale(mTint, color, iv);
                mTint = color;
            } else {
                if (iv instanceof AlphaControlledSlashImageView) {
                    ((AlphaControlledSlashImageView)iv)
                            .setFinalImageTintList(ColorStateList.valueOf(color));
                } else {
                    setTint(iv, color);
                }
                mTint = color;
            }
        }
@@ -149,6 +155,10 @@ public class QSIconViewImpl extends QSIconView {
    }

    public static void animateGrayScale(int fromColor, int toColor, ImageView iv) {
        if (iv instanceof AlphaControlledSlashImageView) {
            ((AlphaControlledSlashImageView)iv)
                    .setFinalImageTintList(ColorStateList.valueOf(toColor));
        }
        if (ValueAnimator.areAnimatorsEnabled()) {
            final float fromAlpha = Color.alpha(fromColor);
            final float toAlpha = Color.alpha(toColor);
+17 −1
Original line number Diff line number Diff line
@@ -34,7 +34,15 @@ public class SlashImageView extends ImageView {
        super(context);
    }

    private void ensureSlashDrawable() {
    protected SlashDrawable getSlash() {
        return mSlash;
    }

    protected void setSlash(SlashDrawable slash) {
        mSlash = slash;
    }

    protected void ensureSlashDrawable() {
        if (mSlash == null) {
            mSlash = new SlashDrawable(getDrawable());
            mSlash.setAnimationEnabled(mAnimationEnabled);
@@ -56,10 +64,18 @@ public class SlashImageView extends ImageView {
        }
    }

    protected void setImageViewDrawable(SlashDrawable slash) {
        super.setImageDrawable(slash);
    }

    public void setAnimationEnabled(boolean enabled) {
        mAnimationEnabled = enabled;
    }

    public boolean getAnimationEnabled() {
        return mAnimationEnabled;
    }

    private void setSlashState(@NonNull SlashState slashState) {
        ensureSlashDrawable();
        mSlash.setRotation(slashState.rotation);
Loading