Merge "Move theme res logic to Themes static class. Bug: 131310726" into ub-launcher3-qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d960d4ec2b
@@ -36,6 +36,7 @@ import com.android.launcher3.model.AppLaunchTracker;
|
|||||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||||
import com.android.launcher3.uioverrides.DisplayRotationListener;
|
import com.android.launcher3.uioverrides.DisplayRotationListener;
|
||||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||||
|
import com.android.launcher3.util.Themes;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
|
|||||||
// Update theme
|
// Update theme
|
||||||
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
|
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
|
||||||
wallpaperColorInfo.addOnChangeListener(this);
|
wallpaperColorInfo.addOnChangeListener(this);
|
||||||
int themeRes = getThemeRes(wallpaperColorInfo);
|
int themeRes = Themes.getActivityThemeRes(this);
|
||||||
if (themeRes != mThemeRes) {
|
if (themeRes != mThemeRes) {
|
||||||
mThemeRes = themeRes;
|
mThemeRes = themeRes;
|
||||||
setTheme(themeRes);
|
setTheme(themeRes);
|
||||||
@@ -88,31 +89,11 @@ public abstract class BaseDraggingActivity extends BaseActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateTheme() {
|
private void updateTheme() {
|
||||||
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
|
if (mThemeRes != Themes.getActivityThemeRes(this)) {
|
||||||
if (mThemeRes != getThemeRes(wallpaperColorInfo)) {
|
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getThemeRes(WallpaperColorInfo wallpaperColorInfo) {
|
|
||||||
boolean darkTheme;
|
|
||||||
if (Utilities.ATLEAST_Q) {
|
|
||||||
Configuration configuration = getResources().getConfiguration();
|
|
||||||
int nightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
|
||||||
darkTheme = nightMode == Configuration.UI_MODE_NIGHT_YES;
|
|
||||||
} else {
|
|
||||||
darkTheme = wallpaperColorInfo.isDark();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (darkTheme) {
|
|
||||||
return wallpaperColorInfo.supportsDarkText() ?
|
|
||||||
R.style.AppTheme_Dark_DarkText : R.style.AppTheme_Dark;
|
|
||||||
} else {
|
|
||||||
return wallpaperColorInfo.supportsDarkText() ?
|
|
||||||
R.style.AppTheme_DarkText : R.style.AppTheme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActionModeStarted(ActionMode mode) {
|
public void onActionModeStarted(ActionMode mode) {
|
||||||
super.onActionModeStarted(mode);
|
super.onActionModeStarted(mode);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.launcher3.util;
|
package com.android.launcher3.util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.ColorMatrix;
|
import android.graphics.ColorMatrix;
|
||||||
@@ -26,12 +27,34 @@ import android.util.SparseArray;
|
|||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
|
||||||
import com.android.launcher3.R;
|
import com.android.launcher3.R;
|
||||||
|
import com.android.launcher3.Utilities;
|
||||||
|
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various utility methods associated with theming.
|
* Various utility methods associated with theming.
|
||||||
*/
|
*/
|
||||||
public class Themes {
|
public class Themes {
|
||||||
|
|
||||||
|
public static int getActivityThemeRes(Context context) {
|
||||||
|
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(context);
|
||||||
|
boolean darkTheme;
|
||||||
|
if (Utilities.ATLEAST_Q) {
|
||||||
|
Configuration configuration = context.getResources().getConfiguration();
|
||||||
|
int nightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||||
|
darkTheme = nightMode == Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
} else {
|
||||||
|
darkTheme = wallpaperColorInfo.isDark();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (darkTheme) {
|
||||||
|
return wallpaperColorInfo.supportsDarkText() ?
|
||||||
|
R.style.AppTheme_Dark_DarkText : R.style.AppTheme_Dark;
|
||||||
|
} else {
|
||||||
|
return wallpaperColorInfo.supportsDarkText() ?
|
||||||
|
R.style.AppTheme_DarkText : R.style.AppTheme;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getDefaultBodyFont(Context context) {
|
public static String getDefaultBodyFont(Context context) {
|
||||||
TypedArray ta = context.obtainStyledAttributes(android.R.style.TextAppearance_DeviceDefault,
|
TypedArray ta = context.obtainStyledAttributes(android.R.style.TextAppearance_DeviceDefault,
|
||||||
new int[]{android.R.attr.fontFamily});
|
new int[]{android.R.attr.fontFamily});
|
||||||
|
|||||||
Reference in New Issue
Block a user