Android Open Source - pixel-art Layer Undo Data






From Project

Back to project page pixel-art.

License

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 android.graphics.Bitmap;

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 {
        ADD, DELETE, MOVE, MERGE
    }

    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);
        layer.setVisible(visibility);
        layer.setLocked(locked);

        return layer;
    }

}




Java Source Code List

com.jaween.pixelart.ContainerActivity.java
com.jaween.pixelart.ContainerFragment.java
com.jaween.pixelart.PanelManagerFragment.java
com.jaween.pixelart.io.AnimationFile.java
com.jaween.pixelart.io.FileAdapter.java
com.jaween.pixelart.io.ImportExport.java
com.jaween.pixelart.io.LoadFileDialog.java
com.jaween.pixelart.tools.Command.java
com.jaween.pixelart.tools.Dropper.java
com.jaween.pixelart.tools.Eraser.java
com.jaween.pixelart.tools.FloodFill.java
com.jaween.pixelart.tools.FreeSelect.java
com.jaween.pixelart.tools.MagicWand.java
com.jaween.pixelart.tools.Oval.java
com.jaween.pixelart.tools.Pen.java
com.jaween.pixelart.tools.RectSelect.java
com.jaween.pixelart.tools.Rect.java
com.jaween.pixelart.tools.Selection.java
com.jaween.pixelart.tools.ToolReport.java
com.jaween.pixelart.tools.Tool.java
com.jaween.pixelart.tools.attributes.EraserToolAttributes.java
com.jaween.pixelart.tools.attributes.MagicWandToolAttributes.java
com.jaween.pixelart.tools.attributes.OvalToolAttributes.java
com.jaween.pixelart.tools.attributes.PenToolAttributes.java
com.jaween.pixelart.tools.attributes.RectToolAttributes.java
com.jaween.pixelart.tools.attributes.ToolAttributes.java
com.jaween.pixelart.tools.options.EraserOptionsView.java
com.jaween.pixelart.tools.options.MagicWandOptionsView.java
com.jaween.pixelart.tools.options.OvalOptionsView.java
com.jaween.pixelart.tools.options.PenOptionsView.java
com.jaween.pixelart.tools.options.RectOptionsView.java
com.jaween.pixelart.tools.options.ToolOptionsView.java
com.jaween.pixelart.ui.ColourButton.java
com.jaween.pixelart.ui.ColourSelector.java
com.jaween.pixelart.ui.DrawingFragment.java
com.jaween.pixelart.ui.DrawingSurface.java
com.jaween.pixelart.ui.PaletteFragment.java
com.jaween.pixelart.ui.PanelFragment.java
com.jaween.pixelart.ui.PixelGrid.java
com.jaween.pixelart.ui.Thumbnail.java
com.jaween.pixelart.ui.ToolButton.java
com.jaween.pixelart.ui.ToolboxFragment.java
com.jaween.pixelart.ui.TransparencyCheckerboard.java
com.jaween.pixelart.ui.animation.AnimationFragment.java
com.jaween.pixelart.ui.animation.FrameAdapter.java
com.jaween.pixelart.ui.animation.Frame.java
com.jaween.pixelart.ui.colourpicker.ColourPickerDialog.java
com.jaween.pixelart.ui.colourpicker.ColourPickerFragment.java
com.jaween.pixelart.ui.colourpicker.ColourPickerView.java
com.jaween.pixelart.ui.layer.LayerAdapter.java
com.jaween.pixelart.ui.layer.LayerFragment.java
com.jaween.pixelart.ui.layer.Layer.java
com.jaween.pixelart.ui.undo.DrawOpManager.java
com.jaween.pixelart.ui.undo.DrawOpUndoData.java
com.jaween.pixelart.ui.undo.FrameUndoData.java
com.jaween.pixelart.ui.undo.LayerUndoData.java
com.jaween.pixelart.ui.undo.UndoItem.java
com.jaween.pixelart.ui.undo.UndoManager.java
com.jaween.pixelart.util.AbsVerticalSeekBar.java
com.jaween.pixelart.util.AnimatedGifEncoder.java
com.jaween.pixelart.util.AutoSaver.java
com.jaween.pixelart.util.BitmapEncoder.java
com.jaween.pixelart.util.Color.java
com.jaween.pixelart.util.ConfigChangeFragment.java
com.jaween.pixelart.util.Debug.java
com.jaween.pixelart.util.MarchingAnts.java
com.jaween.pixelart.util.PreferenceManager.java
com.jaween.pixelart.util.ScaleListener.java
com.jaween.pixelart.util.SlideAnimator.java
com.jaween.pixelart.util.SlidingLinearLayout.java
com.jaween.pixelart.util.VerticalProgressBar.java
com.tokaracamara.android.verticalslidevar.VerticalSeekBar.java