Android Open Source - pixel-art Layer Undo Data

From Project

Back to project page pixel-art.


The source code is released under:

Apache License

If you think the Android project pixel-art listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jaween.pixelart.ui.undo;
//from ww  w  . j a  va 2  s. com

import com.jaween.pixelart.ui.layer.Layer;
import com.jaween.pixelart.util.BitmapEncoder;

 * Created by ween on 11/29/14.
public class LayerUndoData {

    public static enum LayerOperation {

    public static final int NULL_INDEX = -1;
    private static BitmapEncoder bitmapEncoder = new BitmapEncoder();

    private LayerOperation type = null;
    private int frameIndex = NULL_INDEX;
    private int layerIndex = NULL_INDEX;
    private int fromIndex = NULL_INDEX;
    private int toIndex = NULL_INDEX;

    private Integer[] compressedLayer = null;
    private String title = null;
    private boolean visibility;
    private boolean locked;

    private int layerWidth;
    private int layerHeight;
    private Bitmap.Config config;

     * Used when adding or deleting a layer. Stores the layer's bitmap in a compressed form.
     * @param type Use either LayerOperaiton.ADD or LayerOperation.DELETE
     * @param frameIndex The index of the frame
     * @param layerIndex The index of the layer
     * @param layer The layer being added or deleted
    public LayerUndoData(LayerOperation type, int frameIndex, int layerIndex, Layer layer) {
        this.type = type;
        this.layerIndex = layerIndex;
        this.frameIndex = frameIndex;

        // Gets the properties of the layer image
        layerWidth = layer.getImage().getWidth();
        layerHeight = layer.getImage().getHeight();
        config = layer.getImage().getConfig();

        // Compresses the layer image and decomposes the rest of the layer
        bitmapEncoder.setBitmapDimensions(layerWidth, layerHeight);
        compressedLayer = bitmapEncoder.encodeRunLength(layer.getImage());
        title = layer.getTitile();
        visibility = layer.isVisible();
        locked = layer.isLocked();

     * Used when repositioning a layer in the layer list. Implicitly of type LayerOperation.MOVE.
     * @param frameIndex The index of the frame that this operation is taking place
     * @param fromIndex The index in the list that the layer is coming from
     * @param toIndex The index in the list that the layer is moving to
    public LayerUndoData(int frameIndex, int fromIndex, int toIndex) {
        this.type = LayerOperation.MOVE;
        this.frameIndex = frameIndex;
        this.fromIndex = fromIndex;
        this.toIndex = toIndex;

    public LayerOperation getType() {
        return type;

    public int getFrameIndex() {
        return frameIndex;

    public int getLayerIndex() {
        return layerIndex;

    public int getFromIndex() {
        return fromIndex;

    public int getToIndex() {
        return toIndex;

     * Retrieves the Layer object with the bitmap its decompressed state.
     * @return The recomposed Layer instance
    public Layer getLayer() {
        // Decompresses the bitmap
        Bitmap layerImage = Bitmap.createBitmap(layerWidth, layerHeight, config);
        bitmapEncoder.decodeRunLength(compressedLayer, layerImage);

        // Recreates the layer object
        Layer layer = new Layer(layerImage, title);

        return layer;


Java Source Code List