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

Commit 2f3c8d07 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Load device default theme mapping from resources"

parents 334f959b 0810b637
Loading
Loading
Loading
Loading
+215 −207

File changed.

Preview size limit exceeded, changes collapsed.

+6 −6
Original line number Diff line number Diff line
@@ -473,14 +473,14 @@ class ContextImpl extends Context {
        registerService(NOTIFICATION_SERVICE, new ServiceFetcher() {
                public Object createService(ContextImpl ctx) {
                    final Context outerContext = ctx.getOuterContext();
                    // TODO: Why are we not just using the theme attribute
                    // that defines the dialog theme?
                    return new NotificationManager(
                        new ContextThemeWrapper(outerContext,
                                Resources.selectSystemTheme(0,
                                outerContext.getResources().selectSystemTheme(0,
                                        outerContext.getApplicationInfo().targetSdkVersion,
                                        com.android.internal.R.style.Theme_Dialog,
                                        com.android.internal.R.style.Theme_Holo_Dialog,
                                        com.android.internal.R.style.Theme_DeviceDefault_Dialog,
                                        com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog)),
                                        com.android.internal.R.array.system_theme_sdks,
                                        com.android.internal.R.array.system_theme_dialog_styles)),
                        ctx.mMainThread.getHandler());
                }});

@@ -731,7 +731,7 @@ class ContextImpl extends Context {
    @Override
    public Resources.Theme getTheme() {
        if (mTheme == null) {
            mThemeResource = Resources.selectDefaultTheme(mThemeResource,
            mThemeResource = mResources.selectDefaultTheme(mThemeResource,
                    getOuterContext().getApplicationInfo().targetSdkVersion);
            mTheme = mResources.newTheme();
            mTheme.applyStyle(mThemeResource, true);
+28 −25
Original line number Diff line number Diff line
@@ -137,42 +137,45 @@ public class Resources {

    /**
     * Returns the most appropriate default theme for the specified target SDK version.
     * <ul>
     * <li>Below API 11: Gingerbread
     * <li>APIs 11 thru 14: Holo
     * <li>APIs 14 thru XX: Device default dark
     * <li>API XX and above: Device default light with dark action bar
     * </ul>
     *
     * @param curTheme The current theme, or 0 if not specified.
     * @param targetSdkVersion The target SDK version.
     * @return A theme resource identifier
     * @hide
     */
    public static int selectDefaultTheme(int curTheme, int targetSdkVersion) {
    public int selectDefaultTheme(int curTheme, int targetSdkVersion) {
        return selectSystemTheme(curTheme, targetSdkVersion,
                com.android.internal.R.style.Theme,
                com.android.internal.R.style.Theme_Holo,
                com.android.internal.R.style.Theme_DeviceDefault,
                com.android.internal.R.style.Theme_DeviceDefault_Light_DarkActionBar);
                com.android.internal.R.array.system_theme_sdks,
                com.android.internal.R.array.system_theme_styles);
    }

    /** @hide */
    public static int selectSystemTheme(int curTheme, int targetSdkVersion, int orig, int holo,
            int dark, int deviceDefault) {
    /**
     * Returns the most appropriate default theme for the specified target SDK version.
     *
     * @param curTheme The current theme, or 0 if not specified.
     * @param targetSdkVersion The target SDK version.
     * @param sdkArrayId Identifier for integer array resource containing
     *        sorted minimum SDK versions. First entry must be 0.
     * @param themeArrayId Identifier for array resource containing the
     *        default themes that map to SDK versions.
     * @return A theme resource identifier
     * @hide
     */
    public int selectSystemTheme(
            int curTheme, int targetSdkVersion, int sdkArrayId, int themeArrayId) {
        if (curTheme != 0) {
            return curTheme;
        }
        if (targetSdkVersion < Build.VERSION_CODES.HONEYCOMB) {
            return orig;
        }
        if (targetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            return holo;

        final int[] targetSdks = getIntArray(sdkArrayId);
        final TypedArray defaultThemes = obtainTypedArray(themeArrayId);
        for (int i = targetSdks.length - 1; i > 0; i--) {
            if (targetSdkVersion >= targetSdks[i]) {
                return defaultThemes.getResourceId(i, 0);
            }
        if (targetSdkVersion < Build.VERSION_CODES.CUR_DEVELOPMENT) {
            return dark;
        }
        return deviceDefault;

        return defaultThemes.getResourceId(0, 0);
    }

    /**
@@ -2308,8 +2311,8 @@ public class Resources {
     */
    private Drawable loadDrawableForCookie(TypedValue value, int id, Theme theme) {
        if (value.string == null) {
            throw new NotFoundException(
                    "Resource is not a Drawable (color or path): " + value);
            throw new NotFoundException("Resource \"" + getResourceName(id) + "\" ("
                    + Integer.toHexString(id) + ")  is not a Drawable (color or path): " + value);
        }

        final String file = value.string.toString();
+5 −7
Original line number Diff line number Diff line
@@ -654,13 +654,11 @@ public class InputMethodService extends AbstractInputMethodService {
        return false;
    }

    @Override public void onCreate() {
        mTheme = Resources.selectSystemTheme(mTheme,
                getApplicationInfo().targetSdkVersion,
                android.R.style.Theme_InputMethod,
                android.R.style.Theme_Holo_InputMethod,
                android.R.style.Theme_DeviceDefault_InputMethod,
                android.R.style.Theme_DeviceDefault_InputMethod);
    @Override
    public void onCreate() {
        mTheme = getResources().selectSystemTheme(mTheme, getApplicationInfo().targetSdkVersion,
                com.android.internal.R.array.system_theme_sdks,
                com.android.internal.R.array.system_theme_ime_styles);
        super.setTheme(mTheme);
        super.onCreate();
        mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public class ContextThemeWrapper extends ContextWrapper {
            return mTheme;
        }

        mThemeResource = Resources.selectDefaultTheme(mThemeResource,
        mThemeResource = getResources().selectDefaultTheme(mThemeResource,
                getApplicationInfo().targetSdkVersion);
        initializeTheme();

Loading