Update icon tint color when the user toggles Dark theme
- Reload theme in slice provider when Dark theme mode changes for slices - Reload theme in onCreate of Panel activity for its non-slice header - Remove applyTheme from individual slices Test: robotest Fixes: 153700819 Change-Id: I40a7d2817c4b9100d7b2f2962a69c8a9ce6f7906
This commit is contained in:
@@ -20,6 +20,8 @@ package com.android.settings.slices;
|
||||
import static android.content.ContentResolver.SCHEME_CONTENT;
|
||||
import static android.content.pm.PackageManager.PERMISSION_DENIED;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.content.res.Configuration.UI_MODE_NIGHT_NO;
|
||||
import static android.content.res.Configuration.UI_MODE_NIGHT_YES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -39,6 +41,7 @@ import android.app.slice.SliceManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.Settings;
|
||||
@@ -96,7 +99,8 @@ import java.util.Set;
|
||||
@Config(shadows = {ShadowUserManager.class, ShadowUtils.class,
|
||||
SlicesDatabaseAccessorTest.ShadowApplicationPackageManager.class,
|
||||
ShadowBluetoothAdapter.class, ShadowLockPatternUtils.class,
|
||||
SettingsSliceProviderTest.ShadowWifiScanWorker.class})
|
||||
SettingsSliceProviderTest.ShadowWifiScanWorker.class,
|
||||
SettingsSliceProviderTest.ShadowTheme.class})
|
||||
public class SettingsSliceProviderTest {
|
||||
|
||||
private static final String KEY = "KEY";
|
||||
@@ -162,6 +166,7 @@ public class SettingsSliceProviderTest {
|
||||
@After
|
||||
public void cleanUp() {
|
||||
ShadowThreadUtils.reset();
|
||||
ShadowTheme.reset();
|
||||
DatabaseTestUtils.clearDb(mContext);
|
||||
}
|
||||
|
||||
@@ -263,6 +268,28 @@ public class SettingsSliceProviderTest {
|
||||
assertThat(slice).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindSlice_nightModeChanged_shouldReloadTheme() {
|
||||
mContext.getResources().getConfiguration().uiMode = UI_MODE_NIGHT_YES;
|
||||
|
||||
final SliceData data = getDummyData();
|
||||
mProvider.mSliceWeakDataCache.put(data.getUri(), data);
|
||||
mProvider.onBindSlice(data.getUri());
|
||||
|
||||
assertThat(ShadowTheme.isThemeRebased()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindSlice_nightModeNotChanged_shouldNotReloadTheme() {
|
||||
mContext.getResources().getConfiguration().uiMode = UI_MODE_NIGHT_NO;
|
||||
|
||||
SliceData data = getDummyData();
|
||||
mProvider.mSliceWeakDataCache.put(data.getUri(), data);
|
||||
mProvider.onBindSlice(data.getUri());
|
||||
|
||||
assertThat(ShadowTheme.isThemeRebased()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_fullActionUri_returnsSelf() {
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(ACTION_SLICE_URI);
|
||||
@@ -722,4 +749,23 @@ public class SettingsSliceProviderTest {
|
||||
return sSetThreadPolicyCount != 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Implements(Theme.class)
|
||||
public static class ShadowTheme {
|
||||
private static boolean sThemeRebased;
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sThemeRebased = false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public void rebase() {
|
||||
sThemeRebased = true;
|
||||
}
|
||||
|
||||
static boolean isThemeRebased() {
|
||||
return sThemeRebased;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user