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;
//fromwww.java2s.comimport android.graphics.Bitmap;
import com.jaween.pixelart.ui.layer.Layer;
import com.jaween.pixelart.util.BitmapEncoder;
/**
* Created by ween on 11/29/14.
*/publicclass LayerUndoData {
publicstaticenum LayerOperation {
ADD, DELETE, MOVE, MERGE
}
publicstaticfinalint NULL_INDEX = -1;
privatestatic BitmapEncoder bitmapEncoder = new BitmapEncoder();
private LayerOperation type = null;
privateint frameIndex = NULL_INDEX;
privateint layerIndex = NULL_INDEX;
privateint fromIndex = NULL_INDEX;
privateint toIndex = NULL_INDEX;
privateInteger[] compressedLayer = null;
private String title = null;
privateboolean visibility;
privateboolean locked;
privateint layerWidth;
privateint 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;
}
publicint getFrameIndex() {
return frameIndex;
}
publicint getLayerIndex() {
return layerIndex;
}
publicint getFromIndex() {
return fromIndex;
}
publicint 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);
layer.setVisible(visibility);
layer.setLocked(locked);
return layer;
}
}