Loading packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java +2 −0 Original line number Diff line number Diff line Loading @@ -58,5 +58,7 @@ public interface BcSmartspaceDataPlugin extends Plugin { /** View to which this plugin can be registered, in order to get updates. */ interface SmartspaceView { void registerDataProvider(BcSmartspaceDataPlugin plugin); void setPrimaryTextColor(int color); } } packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +56 −1 Original line number Diff line number Diff line Loading @@ -26,14 +26,18 @@ import android.app.smartspace.SmartspaceSession; import android.content.ContentResolver; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.text.TextUtils; import android.text.format.DateFormat; import android.view.View; import android.widget.FrameLayout; import android.widget.RelativeLayout; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.colorextraction.ColorExtractor; import com.android.internal.graphics.ColorUtils; import com.android.keyguard.clock.ClockManager; import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.colorextraction.SysuiColorExtractor; Loading @@ -50,6 +54,7 @@ import com.android.systemui.statusbar.notification.stack.AnimationProperties; import com.android.systemui.statusbar.phone.NotificationIconAreaController; import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.ViewController; import java.util.Locale; Loading Loading @@ -87,6 +92,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private Executor mUiExecutor; private SmartspaceSession mSmartspaceSession; private SmartspaceSession.Callback mSmartspaceCallback; private float mDozeAmount; private int mWallpaperTextColor; private int mDozeColor = Color.WHITE; private ConfigurationController mConfigurationController; /** * Listener for changes to the color palette. Loading @@ -103,8 +112,25 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } }; private final ConfigurationController.ConfigurationListener mConfigurationListener = new ConfigurationController.ConfigurationListener() { @Override public void onThemeChanged() { updateWallpaperColor(); } }; private ClockManager.ClockChangedListener mClockChangedListener = this::setClockPlugin; private final StatusBarStateController.StateListener mStatusBarStateListener = new StatusBarStateController.StateListener() { @Override public void onDozeAmountChanged(float linear, float eased) { mDozeAmount = eased; updateSmartspaceColor(); } }; // If set, will replace keyguard_status_area private BcSmartspaceDataPlugin.SmartspaceView mSmartspaceView; Loading @@ -121,7 +147,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS PluginManager pluginManager, FeatureFlags featureFlags, @Main Executor uiExecutor, BatteryController batteryController) { BatteryController batteryController, ConfigurationController configurationController) { super(keyguardClockSwitch); mResources = resources; mStatusBarStateController = statusBarStateController; Loading @@ -134,6 +161,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mIsSmartspaceEnabled = featureFlags.isSmartspaceEnabled(); mUiExecutor = uiExecutor; mBatteryController = batteryController; mConfigurationController = configurationController; } /** Loading Loading @@ -172,6 +200,12 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mBatteryController); mLargeClockViewController.init(); mDozeAmount = mStatusBarStateController.getDozeAmount(); updateWallpaperColor(); mStatusBarStateController.addCallback(mStatusBarStateListener); mConfigurationController.addCallback(mConfigurationListener); // If a smartspace plugin is detected, replace the existing smartspace // (keyguard_status_area), and initialize a new session mPluginListener = new PluginListener<BcSmartspaceDataPlugin>() { Loading @@ -186,6 +220,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mSmartspaceView = plugin.getView(mView); mSmartspaceView.registerDataProvider(plugin); updateSmartspaceColor(); View asView = (View) mSmartspaceView; // Place plugin view below normal clock... Loading Loading @@ -242,6 +277,19 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mPluginManager.addPluginListener(mPluginListener, BcSmartspaceDataPlugin.class, false); } private void updateWallpaperColor() { mWallpaperTextColor = Utils.getColorAttrDefaultColor(getContext(), R.attr.wallpaperTextColor); updateSmartspaceColor(); } private void updateSmartspaceColor() { if (mSmartspaceView != null) { int color = ColorUtils.blendARGB(mWallpaperTextColor, mDozeColor, mDozeAmount); mSmartspaceView.setPrimaryTextColor(color); } } @Override protected void onViewDetached() { if (CUSTOM_CLOCKS_ENABLED) { Loading @@ -256,6 +304,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mSmartspaceSession = null; } mPluginManager.removePluginListener(mPluginListener); mStatusBarStateController.removeCallback(mStatusBarStateListener); mConfigurationController.removeCallback(mConfigurationListener); } /** Loading Loading @@ -399,4 +449,9 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private int getCurrentLayoutDirection() { return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()); } @VisibleForTesting ConfigurationController.ConfigurationListener getConfigurationListener() { return mConfigurationListener; } } packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +31 −16 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -49,6 +50,7 @@ import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.phone.NotificationIconAreaController; import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.ConfigurationController; import org.junit.Before; import org.junit.Test; Loading Loading @@ -102,8 +104,11 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { private FrameLayout mLargeClockFrame; @Mock BatteryController mBatteryController; @Mock ConfigurationController mConfigurationController; private KeyguardClockSwitchController mController; private View mStatusArea; @Before public void setup() { Loading @@ -111,6 +116,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { when(mView.findViewById(R.id.left_aligned_notification_icon_container)) .thenReturn(mNotificationIcons); when(mNotificationIcons.getLayoutParams()).thenReturn( mock(RelativeLayout.LayoutParams.class)); when(mView.getContext()).thenReturn(getContext()); when(mView.findViewById(R.id.animatable_clock_view)).thenReturn(mClockView); Loading @@ -135,10 +142,15 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { mPluginManager, mFeatureFlags, mExecutor, mBatteryController); mBatteryController, mConfigurationController); when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE); when(mColorExtractor.getColors(anyInt())).thenReturn(mGradientColors); mStatusArea = mock(View.class); when(mView.findViewById(R.id.keyguard_status_area)).thenReturn(mStatusArea); } @Test Loading Loading @@ -201,39 +213,40 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { public void testSmartspacePluginConnectedRemovesKeyguardStatusArea() { mController.init(); View statusArea = mock(View.class); when(mView.findViewById(R.id.keyguard_status_area)).thenReturn(statusArea); View nic = mock(View.class); when(mView.findViewById(R.id.left_aligned_notification_icon_container)).thenReturn(nic); when(nic.getLayoutParams()).thenReturn(mock(RelativeLayout.LayoutParams.class)); BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class); TestView view = mock(TestView.class); when(plugin.getView(any())).thenReturn(view); mController.mPluginListener.onPluginConnected(plugin, mContext); verify(statusArea).setVisibility(View.GONE); verify(mStatusArea).setVisibility(View.GONE); } @Test public void testSmartspacePluginDisconnectedShowsKeyguardStatusArea() { mController.init(); View statusArea = mock(View.class); when(mView.findViewById(R.id.keyguard_status_area)).thenReturn(statusArea); BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class); TestView view = mock(TestView.class); when(plugin.getView(any())).thenReturn(view); View nic = mock(View.class); when(mView.findViewById(R.id.left_aligned_notification_icon_container)).thenReturn(nic); when(nic.getLayoutParams()).thenReturn(mock(RelativeLayout.LayoutParams.class)); mController.mPluginListener.onPluginConnected(plugin, mContext); mController.mPluginListener.onPluginDisconnected(plugin); verify(mStatusArea).setVisibility(View.VISIBLE); } @Test public void testThemeChangeNotifiesSmartspace() { mController.init(); BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class); TestView view = mock(TestView.class); when(plugin.getView(any())).thenReturn(view); mController.mPluginListener.onPluginConnected(plugin, mContext); mController.mPluginListener.onPluginDisconnected(plugin); verify(statusArea).setVisibility(View.VISIBLE); reset(view); mController.getConfigurationListener().onThemeChanged(); verify(view).setPrimaryTextColor(anyInt()); } private void verifyAttachment(VerificationMode times) { Loading @@ -250,5 +263,7 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { } public void registerDataProvider(BcSmartspaceDataPlugin plugin) { } public void setPrimaryTextColor(int color) { } } } Loading
packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java +2 −0 Original line number Diff line number Diff line Loading @@ -58,5 +58,7 @@ public interface BcSmartspaceDataPlugin extends Plugin { /** View to which this plugin can be registered, in order to get updates. */ interface SmartspaceView { void registerDataProvider(BcSmartspaceDataPlugin plugin); void setPrimaryTextColor(int color); } }
packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +56 −1 Original line number Diff line number Diff line Loading @@ -26,14 +26,18 @@ import android.app.smartspace.SmartspaceSession; import android.content.ContentResolver; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.text.TextUtils; import android.text.format.DateFormat; import android.view.View; import android.widget.FrameLayout; import android.widget.RelativeLayout; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.colorextraction.ColorExtractor; import com.android.internal.graphics.ColorUtils; import com.android.keyguard.clock.ClockManager; import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.colorextraction.SysuiColorExtractor; Loading @@ -50,6 +54,7 @@ import com.android.systemui.statusbar.notification.stack.AnimationProperties; import com.android.systemui.statusbar.phone.NotificationIconAreaController; import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.ViewController; import java.util.Locale; Loading Loading @@ -87,6 +92,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private Executor mUiExecutor; private SmartspaceSession mSmartspaceSession; private SmartspaceSession.Callback mSmartspaceCallback; private float mDozeAmount; private int mWallpaperTextColor; private int mDozeColor = Color.WHITE; private ConfigurationController mConfigurationController; /** * Listener for changes to the color palette. Loading @@ -103,8 +112,25 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } }; private final ConfigurationController.ConfigurationListener mConfigurationListener = new ConfigurationController.ConfigurationListener() { @Override public void onThemeChanged() { updateWallpaperColor(); } }; private ClockManager.ClockChangedListener mClockChangedListener = this::setClockPlugin; private final StatusBarStateController.StateListener mStatusBarStateListener = new StatusBarStateController.StateListener() { @Override public void onDozeAmountChanged(float linear, float eased) { mDozeAmount = eased; updateSmartspaceColor(); } }; // If set, will replace keyguard_status_area private BcSmartspaceDataPlugin.SmartspaceView mSmartspaceView; Loading @@ -121,7 +147,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS PluginManager pluginManager, FeatureFlags featureFlags, @Main Executor uiExecutor, BatteryController batteryController) { BatteryController batteryController, ConfigurationController configurationController) { super(keyguardClockSwitch); mResources = resources; mStatusBarStateController = statusBarStateController; Loading @@ -134,6 +161,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mIsSmartspaceEnabled = featureFlags.isSmartspaceEnabled(); mUiExecutor = uiExecutor; mBatteryController = batteryController; mConfigurationController = configurationController; } /** Loading Loading @@ -172,6 +200,12 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mBatteryController); mLargeClockViewController.init(); mDozeAmount = mStatusBarStateController.getDozeAmount(); updateWallpaperColor(); mStatusBarStateController.addCallback(mStatusBarStateListener); mConfigurationController.addCallback(mConfigurationListener); // If a smartspace plugin is detected, replace the existing smartspace // (keyguard_status_area), and initialize a new session mPluginListener = new PluginListener<BcSmartspaceDataPlugin>() { Loading @@ -186,6 +220,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mSmartspaceView = plugin.getView(mView); mSmartspaceView.registerDataProvider(plugin); updateSmartspaceColor(); View asView = (View) mSmartspaceView; // Place plugin view below normal clock... Loading Loading @@ -242,6 +277,19 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mPluginManager.addPluginListener(mPluginListener, BcSmartspaceDataPlugin.class, false); } private void updateWallpaperColor() { mWallpaperTextColor = Utils.getColorAttrDefaultColor(getContext(), R.attr.wallpaperTextColor); updateSmartspaceColor(); } private void updateSmartspaceColor() { if (mSmartspaceView != null) { int color = ColorUtils.blendARGB(mWallpaperTextColor, mDozeColor, mDozeAmount); mSmartspaceView.setPrimaryTextColor(color); } } @Override protected void onViewDetached() { if (CUSTOM_CLOCKS_ENABLED) { Loading @@ -256,6 +304,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mSmartspaceSession = null; } mPluginManager.removePluginListener(mPluginListener); mStatusBarStateController.removeCallback(mStatusBarStateListener); mConfigurationController.removeCallback(mConfigurationListener); } /** Loading Loading @@ -399,4 +449,9 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private int getCurrentLayoutDirection() { return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()); } @VisibleForTesting ConfigurationController.ConfigurationListener getConfigurationListener() { return mConfigurationListener; } }
packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +31 −16 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -49,6 +50,7 @@ import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.phone.NotificationIconAreaController; import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.ConfigurationController; import org.junit.Before; import org.junit.Test; Loading Loading @@ -102,8 +104,11 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { private FrameLayout mLargeClockFrame; @Mock BatteryController mBatteryController; @Mock ConfigurationController mConfigurationController; private KeyguardClockSwitchController mController; private View mStatusArea; @Before public void setup() { Loading @@ -111,6 +116,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { when(mView.findViewById(R.id.left_aligned_notification_icon_container)) .thenReturn(mNotificationIcons); when(mNotificationIcons.getLayoutParams()).thenReturn( mock(RelativeLayout.LayoutParams.class)); when(mView.getContext()).thenReturn(getContext()); when(mView.findViewById(R.id.animatable_clock_view)).thenReturn(mClockView); Loading @@ -135,10 +142,15 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { mPluginManager, mFeatureFlags, mExecutor, mBatteryController); mBatteryController, mConfigurationController); when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE); when(mColorExtractor.getColors(anyInt())).thenReturn(mGradientColors); mStatusArea = mock(View.class); when(mView.findViewById(R.id.keyguard_status_area)).thenReturn(mStatusArea); } @Test Loading Loading @@ -201,39 +213,40 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { public void testSmartspacePluginConnectedRemovesKeyguardStatusArea() { mController.init(); View statusArea = mock(View.class); when(mView.findViewById(R.id.keyguard_status_area)).thenReturn(statusArea); View nic = mock(View.class); when(mView.findViewById(R.id.left_aligned_notification_icon_container)).thenReturn(nic); when(nic.getLayoutParams()).thenReturn(mock(RelativeLayout.LayoutParams.class)); BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class); TestView view = mock(TestView.class); when(plugin.getView(any())).thenReturn(view); mController.mPluginListener.onPluginConnected(plugin, mContext); verify(statusArea).setVisibility(View.GONE); verify(mStatusArea).setVisibility(View.GONE); } @Test public void testSmartspacePluginDisconnectedShowsKeyguardStatusArea() { mController.init(); View statusArea = mock(View.class); when(mView.findViewById(R.id.keyguard_status_area)).thenReturn(statusArea); BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class); TestView view = mock(TestView.class); when(plugin.getView(any())).thenReturn(view); View nic = mock(View.class); when(mView.findViewById(R.id.left_aligned_notification_icon_container)).thenReturn(nic); when(nic.getLayoutParams()).thenReturn(mock(RelativeLayout.LayoutParams.class)); mController.mPluginListener.onPluginConnected(plugin, mContext); mController.mPluginListener.onPluginDisconnected(plugin); verify(mStatusArea).setVisibility(View.VISIBLE); } @Test public void testThemeChangeNotifiesSmartspace() { mController.init(); BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class); TestView view = mock(TestView.class); when(plugin.getView(any())).thenReturn(view); mController.mPluginListener.onPluginConnected(plugin, mContext); mController.mPluginListener.onPluginDisconnected(plugin); verify(statusArea).setVisibility(View.VISIBLE); reset(view); mController.getConfigurationListener().onThemeChanged(); verify(view).setPrimaryTextColor(anyInt()); } private void verifyAttachment(VerificationMode times) { Loading @@ -250,5 +263,7 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { } public void registerDataProvider(BcSmartspaceDataPlugin plugin) { } public void setPrimaryTextColor(int color) { } } }