Merge "Update dozing state on clock view attached" into sc-qpr1-dev
This commit is contained in:
@@ -20,12 +20,16 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.icu.text.NumberFormat;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.statusbar.phone.KeyguardBypassController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
@@ -67,20 +71,20 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
BatteryController batteryController,
|
||||
KeyguardUpdateMonitor keyguardUpdateMonitor,
|
||||
KeyguardBypassController bypassController) {
|
||||
KeyguardBypassController bypassController,
|
||||
@Main Resources resources
|
||||
) {
|
||||
super(view);
|
||||
mStatusBarStateController = statusBarStateController;
|
||||
mIsDozing = mStatusBarStateController.isDozing();
|
||||
mDozeAmount = mStatusBarStateController.getDozeAmount();
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
mBypassController = bypassController;
|
||||
mBatteryController = batteryController;
|
||||
|
||||
mBurmeseNumerals = mBurmeseNf.format(FORMAT_NUMBER);
|
||||
mBurmeseLineSpacing = getContext().getResources().getFloat(
|
||||
mBurmeseLineSpacing = resources.getFloat(
|
||||
R.dimen.keyguard_clock_line_spacing_scale_burmese);
|
||||
mDefaultLineSpacing = getContext().getResources().getFloat(
|
||||
mDefaultLineSpacing = resources.getFloat(
|
||||
R.dimen.keyguard_clock_line_spacing_scale);
|
||||
}
|
||||
|
||||
@@ -106,7 +110,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
|
||||
}
|
||||
};
|
||||
|
||||
private final StatusBarStateController.StateListener mStatusBarStatePersistentListener =
|
||||
private final StatusBarStateController.StateListener mStatusBarStateListener =
|
||||
new StatusBarStateController.StateListener() {
|
||||
@Override
|
||||
public void onDozeAmountChanged(float linear, float eased) {
|
||||
@@ -144,11 +148,11 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
|
||||
mBroadcastDispatcher.registerReceiver(mLocaleBroadcastReceiver,
|
||||
new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
|
||||
mDozeAmount = mStatusBarStateController.getDozeAmount();
|
||||
mIsDozing = mStatusBarStateController.isDozing() || mDozeAmount != 0;
|
||||
mBatteryController.addCallback(mBatteryCallback);
|
||||
mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);
|
||||
|
||||
mStatusBarStateController.removeCallback(mStatusBarStatePersistentListener);
|
||||
mStatusBarStateController.addCallback(mStatusBarStatePersistentListener);
|
||||
mStatusBarStateController.addCallback(mStatusBarStateListener);
|
||||
|
||||
refreshTime();
|
||||
initColors();
|
||||
@@ -160,7 +164,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
|
||||
mBroadcastDispatcher.unregisterReceiver(mLocaleBroadcastReceiver);
|
||||
mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateMonitorCallback);
|
||||
mBatteryController.removeCallback(mBatteryCallback);
|
||||
mStatusBarStateController.removeCallback(mStatusBarStatePersistentListener);
|
||||
mStatusBarStateController.removeCallback(mStatusBarStateListener);
|
||||
}
|
||||
|
||||
/** Animate the clock appearance */
|
||||
@@ -189,6 +193,14 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
|
||||
mView.refreshFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return locallly stored dozing state.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public boolean isDozing() {
|
||||
return mIsDozing;
|
||||
}
|
||||
|
||||
private void updateLocale() {
|
||||
Locale currLocale = Locale.getDefault();
|
||||
if (!Objects.equals(currLocale, mLocale)) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.res.Resources;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -30,6 +31,7 @@ import com.android.keyguard.clock.ClockManager;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.colorextraction.SysuiColorExtractor;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
|
||||
import com.android.systemui.plugins.ClockPlugin;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
@@ -65,6 +67,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final BatteryController mBatteryController;
|
||||
private final LockscreenSmartspaceController mSmartspaceController;
|
||||
private final Resources mResources;
|
||||
|
||||
/**
|
||||
* Clock for both small and large sizes
|
||||
@@ -116,7 +119,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
KeyguardBypassController bypassController,
|
||||
LockscreenSmartspaceController smartspaceController,
|
||||
KeyguardUnlockAnimationController keyguardUnlockAnimationController,
|
||||
SmartspaceTransitionController smartspaceTransitionController) {
|
||||
SmartspaceTransitionController smartspaceTransitionController,
|
||||
@Main Resources resources) {
|
||||
super(keyguardClockSwitch);
|
||||
mStatusBarStateController = statusBarStateController;
|
||||
mColorExtractor = colorExtractor;
|
||||
@@ -128,6 +132,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
mBypassController = bypassController;
|
||||
mSmartspaceController = smartspaceController;
|
||||
mResources = resources;
|
||||
|
||||
mKeyguardUnlockAnimationController = keyguardUnlockAnimationController;
|
||||
mSmartspaceTransitionController = smartspaceTransitionController;
|
||||
@@ -157,7 +162,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
mBroadcastDispatcher,
|
||||
mBatteryController,
|
||||
mKeyguardUpdateMonitor,
|
||||
mBypassController);
|
||||
mBypassController,
|
||||
mResources);
|
||||
mClockViewController.init();
|
||||
|
||||
mLargeClockViewController =
|
||||
@@ -167,7 +173,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
mBroadcastDispatcher,
|
||||
mBatteryController,
|
||||
mKeyguardUpdateMonitor,
|
||||
mBypassController);
|
||||
mBypassController,
|
||||
mResources);
|
||||
mLargeClockViewController.init();
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
|
||||
mBypassController,
|
||||
mSmartspaceController,
|
||||
mKeyguardUnlockAnimationController,
|
||||
mSmartSpaceTransitionController
|
||||
mSmartSpaceTransitionController,
|
||||
mResources
|
||||
);
|
||||
|
||||
when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE);
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.keyguard;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyObject;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.keyguard.AnimatableClockController;
|
||||
import com.android.keyguard.AnimatableClockView;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.statusbar.phone.KeyguardBypassController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.MockitoSession;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper
|
||||
public class AnimatableClockControllerTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private AnimatableClockView mClockView;
|
||||
@Mock
|
||||
private StatusBarStateController mStatusBarStateController;
|
||||
@Mock
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@Mock
|
||||
private BatteryController mBatteryController;
|
||||
@Mock
|
||||
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
@Mock
|
||||
private KeyguardBypassController mBypassController;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
|
||||
private MockitoSession mStaticMockSession;
|
||||
private AnimatableClockController mAnimatableClockController;
|
||||
|
||||
// Capture listeners so that they can be used to send events
|
||||
@Captor private ArgumentCaptor<View.OnAttachStateChangeListener> mAttachCaptor =
|
||||
ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class);
|
||||
private View.OnAttachStateChangeListener mAttachListener;
|
||||
|
||||
@Captor private ArgumentCaptor<StatusBarStateController.StateListener> mStatusBarStateCaptor;
|
||||
private StatusBarStateController.StateListener mStatusBarStateCallback;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mStaticMockSession = mockitoSession()
|
||||
.mockStatic(Utils.class)
|
||||
.strictness(Strictness.LENIENT) // it's ok if mocked classes aren't used
|
||||
.startMocking();
|
||||
when(Utils.getColorAttrDefaultColor(anyObject(), anyInt())).thenReturn(0);
|
||||
|
||||
mAnimatableClockController = new AnimatableClockController(
|
||||
mClockView,
|
||||
mStatusBarStateController,
|
||||
mBroadcastDispatcher,
|
||||
mBatteryController,
|
||||
mKeyguardUpdateMonitor,
|
||||
mBypassController,
|
||||
mResources
|
||||
);
|
||||
mAnimatableClockController.init();
|
||||
captureAttachListener();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mStaticMockSession.finishMocking();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnAttachedUpdatesDozeStateToTrue() {
|
||||
// GIVEN dozing
|
||||
when(mStatusBarStateController.isDozing()).thenReturn(true);
|
||||
when(mStatusBarStateController.getDozeAmount()).thenReturn(1f);
|
||||
|
||||
// WHEN the clock view gets attached
|
||||
mAttachListener.onViewAttachedToWindow(mClockView);
|
||||
|
||||
// THEN the clock controller updated its dozing state to true
|
||||
assertTrue(mAnimatableClockController.isDozing());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnAttachedUpdatesDozeStateToFalse() {
|
||||
// GIVEN not dozing
|
||||
when(mStatusBarStateController.isDozing()).thenReturn(false);
|
||||
when(mStatusBarStateController.getDozeAmount()).thenReturn(0f);
|
||||
|
||||
// WHEN the clock view gets attached
|
||||
mAttachListener.onViewAttachedToWindow(mClockView);
|
||||
|
||||
// THEN the clock controller updated its dozing state to false
|
||||
assertFalse(mAnimatableClockController.isDozing());
|
||||
}
|
||||
|
||||
private void captureAttachListener() {
|
||||
verify(mClockView).addOnAttachStateChangeListener(mAttachCaptor.capture());
|
||||
mAttachListener = mAttachCaptor.getValue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user