Android Open Source - pixel-art Frame 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   w  w w  .  ja  v  a  2s.  co  m
import android.graphics.Bitmap;

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

import java.util.LinkedList;

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

    public static enum FrameOperation {
        ADD, DELETE, MOVE
    }

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

    private FrameOperation type = null;
    private int frameIndex = NULL_INDEX;
    private int fromIndex = NULL_INDEX;
    private int toIndex = NULL_INDEX;

    private LinkedList<Integer[]> compressedLayers = null;
    private Integer[] compressedCompositeBitmap = null;
    private int currentLayerIndex;
    private LinkedList<String> titles = null;
    private LinkedList<Boolean> visibilities;
    private LinkedList<Boolean> lockList;

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

    /**
     * Used when adding or deleting a Frame. Stores the Frame's Layers in compressed form.
     * @param type Use either FrameOperaiton.ADD or FrameOperation.DELETE
     * @param frameIndex The index of the frame
     * @param frame The Frame being added or deleted
     */
    public FrameUndoData(FrameOperation type, int frameIndex, Frame frame) {
        this.type = type;
        this.frameIndex = frameIndex;

        // Gets the properties of the layers
        layerWidth = frame.getLayers().get(0).getImage().getWidth();
        layerHeight = frame.getLayers().get(0).getImage().getHeight();
        config = frame.getLayers().get(0).getImage().getConfig();

        compressedLayers = new LinkedList<>();
        titles = new LinkedList<>();
        visibilities = new LinkedList<>();
        lockList = new LinkedList<>();
        bitmapEncoder.setBitmapDimensions(layerWidth, layerHeight);

        // Decomposes the layers and compresses the layer images
        for (int i = 0; i < frame.getLayers().size(); i++) {
            Layer layer = frame.getLayers().get(i);
            Integer[] compressedBitmap = bitmapEncoder.encodeRunLength(layer.getImage());
            compressedLayers.add(compressedBitmap);
            titles.add(layer.getTitile());
            visibilities.add(layer.isVisible());
            lockList.add(layer.isLocked());
        }
        compressedCompositeBitmap = bitmapEncoder.encodeRunLength(frame.getCompositeBitmap());
        currentLayerIndex = frame.getCurrentLayerIndex();
    }

    /**
     * Used when repositioning a Frame in the Frame list. Implicitly of type FrameOperation.MOVE.
     * @param fromIndex The index in the list that the Frame is coming from
     * @param toIndex The index in the list that the Frame is moving to
     */
    public FrameUndoData(int fromIndex, int toIndex) {
        this.type = FrameOperation.MOVE;
        this.fromIndex = fromIndex;
        this.toIndex = toIndex;
    }

    public FrameOperation getType() {
        return type;
    }

    public int getFrameIndex() {
        return frameIndex;
    }

    public int getFromIndex() {
        return fromIndex;
    }

    public int getToIndex() {
        return toIndex;
    }

    /**
     * Retrieves the Frame object with the Layers in their decompressed state.
     * @return The recomposed Frame instance
     */
    public Frame getFrame() {
        LinkedList<Layer> layers = new LinkedList<Layer>();
        for (int i = 0; i < compressedLayers.size(); i++) {
            Bitmap layerImage = Bitmap.createBitmap(layerWidth, layerHeight, config);
            bitmapEncoder.decodeRunLength(compressedLayers.get(i), layerImage);

            String title = titles.get(i);
            boolean visibility = visibilities.get(i);
            boolean locked = lockList.get(i);

            // Recreates the layer object
            Layer layer = new Layer(layerImage, title);
            layer.setVisible(visibility);
            layer.setLocked(locked);

            layers.add(layer);
        }
        Bitmap compositeBitmap = Bitmap.createBitmap(layerWidth, layerHeight, config);
        bitmapEncoder.decodeRunLength(compressedCompositeBitmap, compositeBitmap);

        Frame frame = new Frame(layers, compositeBitmap, currentLayerIndex);
        return frame;
    }
}




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