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

Commit 06cc9ae5 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

Theme image attributes now expected to be drawables.

Also performed a little bit of housekeeping around the ThemeInfo class,
including converting the numerous INDEX integers to an enum for
readability sake.

Change-Id: I3c6414534d1052756f9e1f842f06c61112e5027a
parent 04d2d830
Loading
Loading
Loading
Loading
+11 −83
Original line number Diff line number Diff line
@@ -28,33 +28,11 @@ import android.content.res.Resources;
public class BaseThemeInfo implements Parcelable {

    /**
     * The name of the wallpaper image file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     * Wallpaper drawable.
     *
     * @see wallpaperImage attribute
     */
    public String wallpaperImageName;

    /**
     * The name of the favorites background image file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     *
     * @see favesBackground attribute
     *
     */
    public String favesImageName;

    /**
     * The name of the favorite apps background image file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     *
     * @see favesAppBackground attribute
     *
     */
    public String favesAppImageName;
    public int wallpaperResourceId;

    /**
     * The resource id of theme thumbnail.
@@ -63,7 +41,7 @@ public class BaseThemeInfo implements Parcelable {
     * @see thumbnail attribute
     *
     */
    public String thumbnail;
    public int thumbnailResourceId;

    /**
     * The theme id, which does not change when the theme is modified.
@@ -159,26 +137,11 @@ public class BaseThemeInfo implements Parcelable {
    public String themeStyleName;

    /**
     * The filename of the preview image.
     * Specifies a theme preview image resource as a path into the assets
     * subfolder.
     * Preview image drawable.
     *
     * @see preview attribute
     */
    public String preview;

    /**
     * {@hide}
     */
    public enum InfoObjectType {
        TYPE_THEME,
        TYPE_SOUNDPACK, /** Currently not supported. */
    }

    /**
     * {@hide}
     */
    public InfoObjectType type;
    public int previewResourceId;

    /**
     * The name of a sound pack.
@@ -214,11 +177,8 @@ public class BaseThemeInfo implements Parcelable {
     * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
     */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(objectTypeToInt(type));
        dest.writeString(wallpaperImageName);
        dest.writeString(favesImageName);
        dest.writeString(favesAppImageName);
        dest.writeString(thumbnail);
        dest.writeInt(wallpaperResourceId);
        dest.writeInt(thumbnailResourceId);
        dest.writeString(themeId);
        dest.writeInt(styleResourceId);
        dest.writeString(name);
@@ -231,7 +191,7 @@ public class BaseThemeInfo implements Parcelable {
        dest.writeInt(isDrmProtected? 1 : 0);
        dest.writeString(soundPackName);
        dest.writeString(themeStyleName);
        dest.writeString(preview);
        dest.writeInt(previewResourceId);
    }

    /** @hide */
@@ -259,11 +219,8 @@ public class BaseThemeInfo implements Parcelable {
    }

    protected BaseThemeInfo(Parcel source) {
        type = intToInfoObjectType(source.readInt());
        wallpaperImageName = source.readString();
        favesImageName = source.readString();
        favesAppImageName = source.readString();
        thumbnail = source.readString();
        wallpaperResourceId = source.readInt();
        thumbnailResourceId = source.readInt();
        themeId = source.readString();
        styleResourceId = source.readInt();
        name = source.readString();
@@ -276,7 +233,7 @@ public class BaseThemeInfo implements Parcelable {
        isDrmProtected = (source.readInt() != 0);
        soundPackName = source.readString();
        themeStyleName = source.readString();
        preview = source.readString();
        previewResourceId = source.readInt();
    }

    protected void changeDrmFlagIfNeeded(String resourcePath) {
@@ -284,33 +241,4 @@ public class BaseThemeInfo implements Parcelable {
            isDrmProtected = true;
        }
    }

    private int objectTypeToInt(InfoObjectType type) {
        switch (type) {
            case TYPE_THEME:
                return 0;

            case TYPE_SOUNDPACK:
                return 1;

            default:
                Log.e("BaseThemeInfo", "unknown type " + type.toString());
                return 0;
        }
    }

    private InfoObjectType intToInfoObjectType(int value) {
        switch (value) {
            case 0:
                return InfoObjectType.TYPE_THEME;

            case 1:
                return InfoObjectType.TYPE_SOUNDPACK;

            default:
                Log.e("BaseThemeInfo", "unknown value " + value);
                return InfoObjectType.TYPE_THEME;
        }
    }

}
+34 −148
Original line number Diff line number Diff line
@@ -34,121 +34,39 @@ import android.content.res.Resources;
 * Below is an example of theme tag
 *    <theme
 *        pluto:name="Pluto Default"
 *        pluto:thumbnail="media/images/app_thumbnail.png"
 *        pluto:preview="media/images/preview.png"
 *        pluto:preview="@drawable/preview"
 *        pluto:author="John Doe"
 *        pluto:ringtoneFileName="media/audio/ringtone.mp3"
 *        pluto:notificationRingtoneFileName="media/audio/locked/notification.mp3"
 *        pluto:copyright="T-Mobile, 2009"
 *        pluto:wallpaperImage="media/images/wallpaper.jpg"
 *        pluto:favesBackground="media/images/locked/background.jpg"
 *        pluto:soundpackName="<package_name>/<sound_pack_name>"
 *    />
 *
 * @hide
 */
public final class ThemeInfo extends BaseThemeInfo {

    /**
     * {@link #name}
     *
     */
    private static final int THEME_PACKAGE_INDEX = 0;

    /**
     * {@link #thumbnail}
     *
     */
    private static final int THUMBNAIL_INDEX = 1;

    /**
     * {@link #preview}
     *
     */
    private static final int PREVIEW_INDEX = 2;

    /**
     * {@link #author}
     *
     */
    private static final int AUTHOR_INDEX = 3;

    /**
     * {@link #themeId}
     *
     */
    private static final int THEME_INDEX = 4;

    /**
     * {@link #themeStyleName}
     *
     */
    private static final int THEME_STYLE_NAME_INDEX = 5;

    /**
     * {@link #ringtoneName}
     *
     */
    private static final int RINGTONE_FILE_NAME_INDEX = 6;

    /**
     * {@link #notificationRingtoneName}
     *
     */
    private static final int NOTIFICATION_RINGTONE_FILE_NAME_INDEX = 7;

    /**
     * {@link #favesImageName}
     *
     */
    private static final int FAVES_IMAGE_NAME_INDEX = 8;

    /**
     * {@link #favesAppImageName}
     *
     */
    private static final int FAVES_APP_IMAGE_NAME_INDEX = 9;

    /**
     * {@link #wallpaperImageName}
     *
     */
    private static final int WALLPAPER_IMAGE_NAME_INDEX = 10;

    /**
     * {@link #copyright}
     *
     */
    private static final int COPYRIGHT_INDEX = 11;

    /**
     * {@link #ringtoneName}
     *
     */
    private static final int RINGTONE_NAME_INDEX = 12;

    /**
     * {@link #notificationRingtoneName}
     *
     */
    private static final int NOTIFICATION_RINGTONE_NAME_INDEX = 13;

    /**
     * {@link #soundPackName}
     *
     */
    private static final int SOUNDPACK_NAME_INDEX = 14;

    /**
     * {@link #styleResourceId}
     *
     */
    private static final int STYLE_INDEX = 15;

    private enum AttributeIndex {
        THEME_PACKAGE_INDEX,
        PREVIEW_INDEX,
        AUTHOR_INDEX,
        THEME_INDEX,
        THEME_STYLE_NAME_INDEX,
        THUMBNAIL_INDEX,
        RINGTONE_FILE_NAME_INDEX,
        NOTIFICATION_RINGTONE_FILE_NAME_INDEX,
        WALLPAPER_IMAGE_INDEX,
        COPYRIGHT_INDEX,
        RINGTONE_NAME_INDEX,
        NOTIFICATION_RINGTONE_NAME_INDEX,
        STYLE_INDEX;

        public static AttributeIndex get(int ordinal) {
            return values()[ordinal];
        }
    };

    private static final String [] compulsoryAttributes = new String [] {
        "name",
        "thumbnail",
        "preview",
        "author",
        "themeId",
@@ -156,36 +74,35 @@ public final class ThemeInfo extends BaseThemeInfo {
    };

    private static final String [] optionalAttributes = new String [] {
        "thumbnail",
        "ringtoneFileName",
        "notificationRingtoneFileName",
        "favesBackground",
        "favesAppsBackground",
        "wallpaperImage",
        "copyright",
        "ringtoneName",
        "notificationRingtoneName",
        "soundpackName",
        "styleId",
    };

    private static Map<String, Integer> attributesLookupTable;
    private static final Map<String, AttributeIndex> sAttributesLookupTable;

    static {
        attributesLookupTable = new HashMap<String, Integer>();
        sAttributesLookupTable = new HashMap<String, AttributeIndex>();
        for (int i = 0; i < compulsoryAttributes.length; i++) {
            attributesLookupTable.put(compulsoryAttributes[i], i);
            sAttributesLookupTable.put(compulsoryAttributes[i], AttributeIndex.get(i));
        }

        for (int i = 0; i < optionalAttributes.length; i++) {
            attributesLookupTable.put(optionalAttributes[i], compulsoryAttributes.length + i);
            sAttributesLookupTable.put(optionalAttributes[i],
                    AttributeIndex.get(compulsoryAttributes.length + i));
        }
    }

    public ThemeInfo(XmlPullParser parser, Resources res, AttributeSet attrs) throws XmlPullParserException {
        super();

        type = InfoObjectType.TYPE_THEME;
        Map<String, Integer> tempMap = new HashMap<String, Integer>(attributesLookupTable);
        Map<String, AttributeIndex> tempMap =
                new HashMap<String, AttributeIndex>(sAttributesLookupTable);
        int numberOfCompulsoryAttributes = 0;
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            if (!ApplicationInfo.isPlutoNamespace(parser.getAttributeNamespace(i))) {
@@ -193,10 +110,10 @@ public final class ThemeInfo extends BaseThemeInfo {
            }
            String key = attrs.getAttributeName(i);
            if (tempMap.containsKey(key)) {
                int index = tempMap.get(key);
                AttributeIndex index = tempMap.get(key);
                tempMap.remove(key);

                if (index < compulsoryAttributes.length) {
                if (index.ordinal() < compulsoryAttributes.length) {
                    numberOfCompulsoryAttributes++;
                }
                switch (index) {
@@ -207,7 +124,7 @@ public final class ThemeInfo extends BaseThemeInfo {

                    case THUMBNAIL_INDEX:
                        // theme thumbprint
                        thumbnail = attrs.getAttributeValue(i);
                        thumbnailResourceId = attrs.getAttributeResourceValue(i, 0);
                        break;

                    case AUTHOR_INDEX:
@@ -236,22 +153,9 @@ public final class ThemeInfo extends BaseThemeInfo {
                        changeDrmFlagIfNeeded(notificationRingtoneFileName);
                        break;

                    case FAVES_IMAGE_NAME_INDEX:
                        // faves background
                        favesImageName = attrs.getAttributeValue(i);
                        changeDrmFlagIfNeeded(favesImageName);
                        break;

                    case FAVES_APP_IMAGE_NAME_INDEX:
                        // favesAppBackground attribute
                        favesAppImageName = attrs.getAttributeValue(i);
                        changeDrmFlagIfNeeded(favesAppImageName);
                        break;

                    case WALLPAPER_IMAGE_NAME_INDEX:
                    case WALLPAPER_IMAGE_INDEX:
                        // wallpaperImage attribute
                        wallpaperImageName = attrs.getAttributeValue(i);
                        changeDrmFlagIfNeeded(wallpaperImageName);
                        wallpaperResourceId = attrs.getAttributeResourceValue(i, 0);
                        break;

                    case COPYRIGHT_INDEX:
@@ -269,17 +173,13 @@ public final class ThemeInfo extends BaseThemeInfo {
                        notificationRingtoneName = attrs.getAttributeValue(i);
                        break;

                    case SOUNDPACK_NAME_INDEX:
                        soundPackName = attrs.getAttributeValue(i);
                        break;

                    case STYLE_INDEX:
                        styleResourceId = attrs.getAttributeResourceValue(i, 0);
                        break;

                    case PREVIEW_INDEX:
                        // theme thumbprint
                        preview = attrs.getAttributeValue(i);
                        previewResourceId = attrs.getAttributeResourceValue(i, 0);
                        break;
                }
            }
@@ -289,19 +189,6 @@ public final class ThemeInfo extends BaseThemeInfo {
        }
    }

    /*
     * Flatten this object in to a Parcel.
     *
     * @param dest The Parcel in which the object should be written.
     * @param flags Additional flags about how the object should be written.
     * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
     *
     * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
     */
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
    }

    public static final Parcelable.Creator<ThemeInfo> CREATOR
            = new Parcelable.Creator<ThemeInfo>() {
        public ThemeInfo createFromParcel(Parcel source) {
@@ -316,5 +203,4 @@ public final class ThemeInfo extends BaseThemeInfo {
    private ThemeInfo(Parcel source) {
        super(source);
    }

}