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

Commit e47f497d authored by Andy Mast's avatar Andy Mast Committed by Gerrit Code Review
Browse files

Themes: Add method to "apply all" a theme

Change-Id: Ic8feaeade6c52707e6b5b17921b1b577b94ec8cf
parent a0c3610e
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.os.FileUtils;
import android.os.SystemProperties;
import android.provider.MediaStore;
import android.provider.Settings;
import android.provider.ThemesContract;
import android.provider.ThemesContract.ThemesColumns;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -44,6 +46,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -556,4 +560,46 @@ public class ThemeUtils {
            return mPackageName;
        }
    }

    // Returns a mutable list of all theme components
    public static List<String> getAllComponents() {
        List<String> components = new ArrayList<String>(9);
        components.add(ThemesColumns.MODIFIES_FONTS);
        components.add(ThemesColumns.MODIFIES_LAUNCHER);
        components.add(ThemesColumns.MODIFIES_ALARMS);
        components.add(ThemesColumns.MODIFIES_BOOT_ANIM);
        components.add(ThemesColumns.MODIFIES_ICONS);
        components.add(ThemesColumns.MODIFIES_LOCKSCREEN);
        components.add(ThemesColumns.MODIFIES_NOTIFICATIONS);
        components.add(ThemesColumns.MODIFIES_OVERLAYS);
        components.add(ThemesColumns.MODIFIES_RINGTONES);
        components.add(ThemesColumns.MODIFIES_STATUS_BAR);
        components.add(ThemesColumns.MODIFIES_NAVIGATION_BAR);
        return components;
    }

    /**
     *  Returns a mutable list of all the theme components supported by a given package
     *  NOTE: This queries the themes content provider. If there isn't a provider installed
     *  or if it is too early in the boot process this method will not work.
     */
    public static List<String> getSupportedComponents(Context context, String pkgName) {
        List<String> supportedComponents = new ArrayList<String>();

        String selection = ThemesContract.ThemesColumns.PKG_NAME + "= ?";
        String[] selectionArgs = new String[]{ pkgName };
        Cursor c = context.getContentResolver().query(ThemesContract.ThemesColumns.CONTENT_URI,
                null, selection, selectionArgs, null);

        if (c != null && c.moveToFirst()) {
            List<String> allComponents = getAllComponents();
            for(String component : allComponents) {
                int index = c.getColumnIndex(component);
                if (c.getInt(index) == 1) {
                    supportedComponents.add(component);
                }
            }
        }
        return supportedComponents;
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.content.res;

import android.content.Context;
import android.content.pm.ThemeUtils;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
@@ -115,6 +116,18 @@ public class ThemeManager {
        removeClient(pkgName);
    }

    /**
     * Convenience method. Applies the entire theme.
     */
    public void requestThemeChange(String pkgName) {
        try {
            List<String> components = ThemeUtils.getSupportedComponents(mContext, pkgName);
            mService.requestThemeChange(pkgName, components);
        } catch (RemoteException e) {
            Log.w(TAG, "Unable to access ThemeService", e);
        }
    }

    public void requestThemeChange(String pkgName, List<String> components) {
        try {
            mService.requestThemeChange(pkgName, components);
+1 −10
Original line number Diff line number Diff line
@@ -239,16 +239,7 @@ public class ThemeService extends IThemeService.Stub {
                    Settings.Secure.DEFAULT_THEME_COMPONENTS);
            List<String> components;
            if (TextUtils.isEmpty(defaultThemeComponents)) {
                components = new ArrayList<String>(9);
                components.add(ThemesContract.ThemesColumns.MODIFIES_FONTS);
                components.add(ThemesContract.ThemesColumns.MODIFIES_LAUNCHER);
                components.add(ThemesContract.ThemesColumns.MODIFIES_ALARMS);
                components.add(ThemesContract.ThemesColumns.MODIFIES_BOOT_ANIM);
                components.add(ThemesContract.ThemesColumns.MODIFIES_ICONS);
                components.add(ThemesContract.ThemesColumns.MODIFIES_LOCKSCREEN);
                components.add(ThemesContract.ThemesColumns.MODIFIES_NOTIFICATIONS);
                components.add(ThemesContract.ThemesColumns.MODIFIES_OVERLAYS);
                components.add(ThemesContract.ThemesColumns.MODIFIES_RINGTONES);
                components = ThemeUtils.getAllComponents();
            } else {
                components = new ArrayList<String>(
                        Arrays.asList(defaultThemeComponents.split("\\|")));