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

Commit 82b33a27 authored by Selim Cinek's avatar Selim Cinek
Browse files

Removing unused invert helpers

In AOD the notifications aren't actually inverted
anymore and it was creating problems as in bordercases
it would still be invoked.

Test: add group, normal notification on aod, normal layout
Change-Id: Id01b7624162ff17d0e4cad6479d486683f7e5b33
Fixes: 77024183
parent 4b70190a
Loading
Loading
Loading
Loading
+0 −126
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.view.View;

import java.util.ArrayList;

/**
 * Helper to invert the colors of views and fade between the states.
 */
public class ViewInvertHelper {

    private final Paint mDarkPaint = new Paint();
    private final ColorMatrix mMatrix = new ColorMatrix();
    private final ColorMatrix mGrayscaleMatrix = new ColorMatrix();
    private final long mFadeDuration;
    private final ArrayList<View> mTargets = new ArrayList<>();

    public ViewInvertHelper(View v, long fadeDuration) {
        this(v.getContext(), fadeDuration);
        addTarget(v);
    }
    public ViewInvertHelper(Context context, long fadeDuration) {
        mFadeDuration = fadeDuration;
    }

    private static ArrayList<View> constructArray(View target) {
        final ArrayList<View> views = new ArrayList<>();
        views.add(target);
        return views;
    }

    public void clearTargets() {
        mTargets.clear();
    }

    public void addTarget(View target) {
        mTargets.add(target);
    }

    public void fade(final boolean invert, long delay) {
        float startIntensity = invert ? 0f : 1f;
        float endIntensity = invert ? 1f : 0f;
        ValueAnimator animator = ValueAnimator.ofFloat(startIntensity, endIntensity);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                updateInvertPaint((Float) animation.getAnimatedValue());
                for (int i = 0; i < mTargets.size(); i++) {
                    mTargets.get(i).setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
                }
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (!invert) {
                    for (int i = 0; i < mTargets.size(); i++) {
                        mTargets.get(i).setLayerType(View.LAYER_TYPE_NONE, null);
                    }
                }
            }
        });
        animator.setDuration(mFadeDuration);
        animator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
        animator.setStartDelay(delay);
        animator.start();
    }

    public void update(boolean invert) {
        if (invert) {
            updateInvertPaint(1f);
            for (int i = 0; i < mTargets.size(); i++) {
                mTargets.get(i).setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
            }
        } else {
            for (int i = 0; i < mTargets.size(); i++) {
                mTargets.get(i).setLayerType(View.LAYER_TYPE_NONE, null);
            }
        }
    }

    private void updateInvertPaint(float intensity) {
        float components = 1 - 2 * intensity;
        final float[] invert = {
                components, 0f,         0f,         0f, 255f * intensity,
                0f,         components, 0f,         0f, 255f * intensity,
                0f,         0f,         components, 0f, 255f * intensity,
                0f,         0f,         0f,         1f, 0f
        };
        mMatrix.set(invert);
        mGrayscaleMatrix.setSaturation(1 - intensity);
        mMatrix.preConcat(mGrayscaleMatrix);
        mDarkPaint.setColorFilter(new ColorMatrixColorFilter(mMatrix));
    }

    public void setInverted(boolean invert, boolean fade, long delay) {
        if (fade) {
            fade(invert, delay);
        } else {
            update(invert);
        }
    }
}
 No newline at end of file
+0 −13
Original line number Diff line number Diff line
@@ -422,7 +422,6 @@ public class NotificationContentView extends FrameLayout {
        mContractedChild = child;
        mContractedWrapper = NotificationViewWrapper.wrap(getContext(), child,
                mContainingNotification);
        mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */);
    }

    private NotificationViewWrapper getWrapperForView(View child) {
@@ -1106,18 +1105,6 @@ public class NotificationContentView extends FrameLayout {
            return;
        }
        mDark = dark;
        if (mVisibleType == VISIBLE_TYPE_CONTRACTED || !dark) {
            mContractedWrapper.setDark(dark, fade, delay);
        }
        if (mVisibleType == VISIBLE_TYPE_EXPANDED || (mExpandedChild != null && !dark)) {
            mExpandedWrapper.setDark(dark, fade, delay);
        }
        if (mVisibleType == VISIBLE_TYPE_HEADSUP || (mHeadsUpChild != null && !dark)) {
            mHeadsUpWrapper.setDark(dark, fade, delay);
        }
        if (mSingleLineView != null && (mVisibleType == VISIBLE_TYPE_SINGLELINE || !dark)) {
            mSingleLineView.setDark(dark, fade, delay);
        }
        selectLayout(!dark && fade /* animate */, false /* force */);
    }

+0 −5
Original line number Diff line number Diff line
@@ -33,10 +33,8 @@ import android.view.accessibility.AccessibilityNodeInfo;

import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.phone.NotificationIconContainer;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import com.android.systemui.statusbar.stack.AmbientState;
import com.android.systemui.statusbar.stack.AnimationProperties;
import com.android.systemui.statusbar.stack.ExpandableViewState;
@@ -60,7 +58,6 @@ public class NotificationShelf extends ActivatableNotificationView implements
    private static final String TAG = "NotificationShelf";
    private static final long SHELF_IN_TRANSLATION_DURATION = 200;

    private ViewInvertHelper mViewInvertHelper;
    private boolean mDark;
    private NotificationIconContainer mShelfIcons;
    private ShelfState mShelfState;
@@ -105,8 +102,6 @@ public class NotificationShelf extends ActivatableNotificationView implements
        setClipChildren(false);
        setClipToPadding(false);
        mShelfIcons.setIsStaticLayout(false);
        mViewInvertHelper = new ViewInvertHelper(mShelfIcons,
                NotificationPanelView.DOZE_ANIMATION_DURATION);
        mShelfState = new ShelfState();
        setBottomRoundness(1.0f, false /* animate */);
        initDimens();
+0 −8
Original line number Diff line number Diff line
@@ -25,11 +25,9 @@ import android.widget.TextView;

import com.android.keyguard.AlphaOptimizedLinearLayout;
import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.CrossFadeHelper;
import com.android.systemui.statusbar.TransformableView;
import com.android.systemui.statusbar.ViewTransformationHelper;
import com.android.systemui.statusbar.phone.NotificationPanelView;

/**
 * A hybrid view which may contain information about one ore more notifications.
@@ -41,7 +39,6 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout

    protected TextView mTitleView;
    protected TextView mTextView;
    private ViewInvertHelper mInvertHelper;

    public HybridNotificationView(Context context) {
        this(context, null);
@@ -73,7 +70,6 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout
        super.onFinishInflate();
        mTitleView = (TextView) findViewById(R.id.notification_title);
        mTextView = (TextView) findViewById(R.id.notification_text);
        mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION);
        mTransformationHelper = new ViewTransformationHelper();
        mTransformationHelper.setCustomTransformation(
                new ViewTransformationHelper.CustomTransformation() {
@@ -126,10 +122,6 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout
        requestLayout();
    }

    public void setDark(boolean dark, boolean fade, long delay) {
        mInvertHelper.setInverted(dark, fade, delay);
    }

    @Override
    public TransformState getCurrentState(int fadingView) {
        return mTransformationHelper.getCurrentState(fadingView);
+0 −56
Original line number Diff line number Diff line
@@ -16,81 +16,25 @@

package com.android.systemui.statusbar.notification;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.view.View;

import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.phone.NotificationPanelView;

/**
 * Wraps a notification containing a custom view.
 */
public class NotificationCustomViewWrapper extends NotificationViewWrapper {

    private final ViewInvertHelper mInvertHelper;
    private final Paint mGreyPaint = new Paint();
    private boolean mIsLegacy;
    private int mLegacyColor;

    protected NotificationCustomViewWrapper(Context ctx, View view, ExpandableNotificationRow row) {
        super(ctx, view, row);
        mInvertHelper = new ViewInvertHelper(view, NotificationPanelView.DOZE_ANIMATION_DURATION);
        mLegacyColor = row.getContext().getColor(R.color.notification_legacy_background_color);
    }

    @Override
    public void setDark(boolean dark, boolean fade, long delay) {
        if (dark == mDark && mDarkInitialized) {
            return;
        }
        super.setDark(dark, fade, delay);
        if (!mIsLegacy && mShouldInvertDark) {
            if (fade) {
                mInvertHelper.fade(dark, delay);
            } else {
                mInvertHelper.update(dark);
            }
        } else {
            mView.setLayerType(dark ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
            if (fade) {
                fadeGrayscale(dark, delay);
            } else {
                updateGrayscale(dark);
            }
        }
    }

    protected void fadeGrayscale(final boolean dark, long delay) {
        getDozer().startIntensityAnimation(animation -> {
            getDozer().updateGrayscaleMatrix((float) animation.getAnimatedValue());
            mGreyPaint.setColorFilter(
                    new ColorMatrixColorFilter(getDozer().getGrayscaleColorMatrix()));
            mView.setLayerPaint(mGreyPaint);
        }, dark, delay, new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (!dark) {
                    mView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
            }
        });
    }

    protected void updateGrayscale(boolean dark) {
        if (dark) {
            getDozer().updateGrayscaleMatrix(1f);
            mGreyPaint.setColorFilter(
                    new ColorMatrixColorFilter(getDozer().getGrayscaleColorMatrix()));
            mView.setLayerPaint(mGreyPaint);
        }
    }

    @Override
    public void setVisible(boolean visible) {
        super.setVisible(visible);
Loading