Android Open Source - pixel-art Frame Adapter






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.animation;
/*www  .  j av  a 2s .c om*/
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.jaween.pixelart.R;

import java.util.LinkedList;

/**
 * Created by ween on 12/6/14.
 */
public class FrameAdapter extends BaseAdapter implements View.OnClickListener {

    private LinkedList<Frame> data;
    private LayoutInflater inflater;

    private BitmapDrawable checkerboardTile;

    private int currentFrameIndex = 0;

    private FrameListItemListener frameListItemListener = null;

    public FrameAdapter(Context context, LinkedList<Frame> data, BitmapDrawable checkerboardTile) {
        inflater = LayoutInflater.from(context);
        this.data = data;
        this.checkerboardTile = checkerboardTile;
    }

    public void setCurrentFrameIndex(int currentFrameIndex) {
        this.currentFrameIndex = currentFrameIndex;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.frame_item, null);

            holder = new ViewHolder();
            holder.frameImage = (ImageView) convertView.findViewById(R.id.iv_frame_image);
            //holder.frameDragHandle = (ImageView) recycledView.findViewById(R.id.iv_frame_drag_handle);
            holder.frameDelete = (ImageView) convertView.findViewById(R.id.iv_frame_delete);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // Initialises views
        holder.frameImage.setBackgroundDrawable(checkerboardTile);
        holder.frameImage.setImageBitmap(data.get(position).getCompositeBitmap());

        // Highlights the selected frame
        if (position == currentFrameIndex) {
            convertView.setBackgroundResource(R.color.highlight);
        } else {
            convertView.setBackgroundResource(0);
        }

        // Pre-Jellybean doesn't have setBackground()
        int sdk = Build.VERSION.SDK_INT;
        if (sdk < Build.VERSION_CODES.JELLY_BEAN) {
            holder.frameImage.setBackgroundDrawable(checkerboardTile);
        } else {
            holder.frameImage.setBackground(checkerboardTile);
        }

        holder.frameDelete.setOnClickListener(this);

        // Stores this view's position in the list within the View tag (for use with onClick())
        holder.frameDelete.setTag(position);

        return convertView;
    }

    @Override
    public void onClick(View view) {
        // Determines which row this view belongs to
        int position;
        if (view.getTag() != null) {
            position = (Integer) view.getTag();
        } else {
            return;
        }

        switch(view.getId()) {
            case R.id.iv_frame_delete:
                if (data.size() > 1) {
                    // Deletion occurs in the Fragment to avoid accidentally deleting two items,
                    // once from this adapter and once from AnimationFragment.deleteFrame()
                    if (frameListItemListener != null) {
                        frameListItemListener.onDeleteFrameFromList(position);
                    }
                }
        }
    }

    private class ViewHolder {
        ImageView frameImage;
        //ImageView frameDragHandle;
        ImageView frameDelete;
    }


    public void setFrameListItemListener(FrameListItemListener frameListItemListener) {
        this.frameListItemListener = frameListItemListener;
    }

    public interface FrameListItemListener {
        public void onDeleteFrameFromList(int i);
    }
}




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