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

Commit 0e693bf2 authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Fix notification icon visibility on AOD"

parents 332849b5 51d24e02
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.util.MathUtils;
import android.util.TimeUtils;

import com.android.systemui.Dependency;
@@ -29,6 +30,7 @@ import com.android.systemui.Interpolators;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.CommandQueue.Callbacks;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.policy.KeyguardMonitor;

import java.io.FileDescriptor;
@@ -37,7 +39,8 @@ import java.io.PrintWriter;
/**
 * Class to control all aspects about light bar changes.
 */
public class LightBarTransitionsController implements Dumpable, Callbacks {
public class LightBarTransitionsController implements Dumpable, Callbacks,
        StatusBarStateController.StateListener {

    public static final long DEFAULT_TINT_ANIMATION_DURATION = 120;
    private static final String EXTRA_DARK_INTENSITY = "dark_intensity";
@@ -45,6 +48,7 @@ public class LightBarTransitionsController implements Dumpable, Callbacks {
    private final Handler mHandler;
    private final DarkIntensityApplier mApplier;
    private final KeyguardMonitor mKeyguardMonitor;
    private final StatusBarStateController mStatusBarStateController;

    private boolean mTransitionDeferring;
    private long mTransitionDeferringStartTime;
@@ -55,6 +59,7 @@ public class LightBarTransitionsController implements Dumpable, Callbacks {
    private ValueAnimator mTintAnimator;
    private float mDarkIntensity;
    private float mNextDarkIntensity;
    private float mDozeAmount;
    private final Runnable mTransitionDeferringDoneRunnable = new Runnable() {
        @Override
        public void run() {
@@ -66,13 +71,17 @@ public class LightBarTransitionsController implements Dumpable, Callbacks {
        mApplier = applier;
        mHandler = new Handler();
        mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
        mStatusBarStateController = Dependency.get(StatusBarStateController.class);
        SysUiServiceProvider.getComponent(context, CommandQueue.class)
                .addCallbacks(this);
        mStatusBarStateController.addListener(this);
        mDozeAmount = mStatusBarStateController.getDozeAmount();
    }

    public void destroy(Context context) {
        SysUiServiceProvider.getComponent(context, CommandQueue.class)
                .removeCallbacks(this);
        mStatusBarStateController.removeListener(this);
    }

    public void saveState(Bundle outState) {
@@ -173,7 +182,11 @@ public class LightBarTransitionsController implements Dumpable, Callbacks {

    private void setIconTintInternal(float darkIntensity) {
        mDarkIntensity = darkIntensity;
        mApplier.applyDarkIntensity(darkIntensity);
        dispatchDark();
    }

    private void dispatchDark() {
        mApplier.applyDarkIntensity(MathUtils.lerp(mDarkIntensity, 0f, mDozeAmount));
    }

    @Override
@@ -196,6 +209,15 @@ public class LightBarTransitionsController implements Dumpable, Callbacks {
        pw.print(" mNextDarkIntensity="); pw.println(mNextDarkIntensity);
    }

    @Override
    public void onStateChanged(int newState) { }

    @Override
    public void onDozeAmountChanged(float linear, float eased) {
        mDozeAmount = eased;
        dispatchDark();
    }

    /**
     * Interface to apply a specific dark intensity.
     */
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.statusbar.phone;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.LightBarTransitionsController.DarkIntensityApplier;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class LightBarTransitionsControllerTest extends SysuiTestCase {

    @Mock
    private DarkIntensityApplier mApplier;
    private LightBarTransitionsController mLightBarTransitionsController;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
        mLightBarTransitionsController = new LightBarTransitionsController(mContext, mApplier);
    }

    @Test
    public void setIconsDark_lightAndDark() {
        mLightBarTransitionsController.setIconsDark(true /* dark */, false /* animate */);
        verify(mApplier).applyDarkIntensity(eq(1f));

        mLightBarTransitionsController.setIconsDark(false /* dark */, false /* animate */);
        verify(mApplier).applyDarkIntensity(eq(0f));
    }

    @Test
    public void onDozeAmountChanged_lightWhenDozing() {
        mLightBarTransitionsController.onDozeAmountChanged(1f /* linear */, 1f /* eased */);
        mLightBarTransitionsController.setIconsDark(true /* dark */, false /* animate */);
        verify(mApplier, times(2)).applyDarkIntensity(eq(0f));

        reset(mApplier);
        mLightBarTransitionsController.setIconsDark(false /* dark */, false /* animate */);
        verify(mApplier).applyDarkIntensity(eq(0f));
    }

}