package fr.tvbarthel.apps.cameracolorpicker.data;

/**
 * A simple data class representing a color.
 */
public class ColorItem {

    /**
     * The id of the color.
     */
    protected final long mId;

    /**
     * An int representing the value of the color.
     */
    protected int mColor;

    /**
     * A long representing the creation time of the color. (In milliseconds).
     */
    protected final long mCreationTime;

    /**
     * A human readable string representation of the hexadecimal value of the color.
     */
    protected transient String mHexString;

    /**
     * Create a new {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem} with an id and a color.
     *
     * @param id    the id of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}. Should be unique.
     * @param color the color value.
     */
    public ColorItem(long id, int color) {
        mId = id;
        mColor = color;
        mCreationTime = System.currentTimeMillis();
    }

    /**
     * Create a new {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem} with a color.
     * <p/>
     * The {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem#mId} is set to the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem#mCreationTime}.
     *
     * @param color the color value.
     */
    public ColorItem(int color) {
        mId = mCreationTime = System.currentTimeMillis();
        mColor = color;
    }

    /**
     * Get the id of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     *
     * @return the id of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     */
    public long getId() {
        return mId;
    }

    /**
     * Get the value of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     *
     * @return an integer representing the color value of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     */
    public int getColor() {
        return mColor;
    }

    /**
     * Set the color valur of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     *
     * @param color an integer representing the new color value of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     */
    public void setColor(int color) {
        if (mColor != color) {
            mColor = color;
            mHexString = makeHexString(mColor);
        }
    }

    /**
     * Get the creation time of the {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     *
     * @return a long representing the creation time in milliseconds.
     */
    public long getCreationTime() {
        return mCreationTime;
    }

    /**
     * Get a human readable representation of the hexadecimal value of the color.
     *
     * @return a human readable representation of the hexadecimal value.
     */
    public String getHexString() {
        if (mHexString == null) {
            mHexString = makeHexString(mColor);
        }
        return mHexString;
    }

    /**
     * Make a human readable representation of the hexadecimal value of a color.
     *
     * @param value the integer representation the color.
     * @return a human readable representation of the hexadecimal value.
     */
    public static String makeHexString(int value) {
        return "#" + Integer.toHexString(value).substring(2);
    }

}

@@ -44,16 +44,73 @@
 .data;%0A%0A
+import android.os.Parcel;%0Aimport android.os.Parcelable;%0A%0A
 /**%0A * A
@@ -177,16 +177,38 @@
 lorItem 
+implements Parcelable 
 %7B%0A%0A    /
@@ -1062,32 +1062,498 @@
 illis();%0A    %7D%0A%0A
+    /**%0A     * Create a new %7B@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem%7D from a %7B@link android.os.Parcel%7D.%0A     * %3Cp/%3E%0A     * Used by the parcelable creator.%0A     * %7B@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem#CREATOR%7D.%0A     *%0A     * @param in the %7B@link android.os.Parcel%7D.%0A     */%0A    private ColorItem(Parcel in) %7B%0A        this.mId = in.readLong();%0A        this.mColor = in.readInt();%0A        this.mCreationTime = in.readLong();%0A    %7D%0A%0A
     /**%0A     * C
@@ -3894,10 +3894,741 @@
 %0A    %7D%0A%0A
+%0A    @Override%0A    public int describeContents() %7B%0A        return 0;%0A    %7D%0A%0A    @Override%0A    public void writeToParcel(Parcel dest, int flags) %7B%0A        dest.writeLong(this.mId);%0A        dest.writeInt(this.mColor);%0A        dest.writeLong(this.mCreationTime);%0A    %7D%0A%0A    /**%0A     * A %7B@link android.os.Parcelable.Creator%7D for creating %7B@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem%7D from %7B@link android.os.Parcel%7D.%0A     */%0A    public static final Creator%3CColorItem%3E CREATOR = new Creator%3CColorItem%3E() %7B%0A        public ColorItem createFromParcel(Parcel source) %7B%0A            return new ColorItem(source);%0A        %7D%0A%0A        public ColorItem%5B%5D newArray(int size) %7B%0A            return new ColorItem%5Bsize%5D;%0A        %7D%0A    %7D;%0A
 %7D%0A

Make ColorItem parcelable