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.tools;
/*www.java2s.com*/import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import com.jaween.pixelart.tools.attributes.ToolAttributes;
/**
* To make a Tool:
* 1) Subclass Tool implementing 'onStart()', 'onMove()', 'onEnd()', draw with canvas.setBitmap(bitmap)
* 2) Give the tool a unique ID in the call to the super constructor
* 3) If the tool has user configurable attributes, implement a subclass of ToolAttributes and
* create a corresponding XML layout. Subclass ToolOptionsView and linkup the UI.
* 4) In the constructor of the tool, set the 'toolAttributes' variable to an instance of ToolAttributes
* 5) In ToolboxFragment, create an instance of your tool, options, attributes and ImageButton.
* 6) In initialiseViews() of ToolboxFragment, call tool.setToolAttributes(attributes). Done!
*/publicabstractclass Tool implements Command {
// User interface
protectedfinal String name;
protectedfinal Drawable icon;
// Used to retrieve the tool on config change
protectedfinalint toolId;
// Drawing
protected Canvas canvas = new Canvas();
protected ToolAttributes toolAttributes;
protected ToolReport toolReport;
protectedboolean cancelled = false;
public Tool(String name, Drawable icon, int toolId) {
this.name = name;
this.icon = icon;
this.toolId = toolId;
toolReport = new ToolReport();
}
public String getName() {
return name;
}
public Drawable getIcon() {
return icon;
}
publicint getToolId() {
return toolId;
}
@Override
publicfinal ToolReport start(Bitmap bitmap, PointF event) {
cancelled = false;
toolReport.getPath().reset();
toolReport.getPath().moveTo(event.x, event.y);
onStart(bitmap, event);
return toolReport;
}
@Override
publicfinal ToolReport move(Bitmap bitmap, PointF event) {
if (!cancelled) {
toolReport.getPath().lineTo(event.x, event.y);
onMove(bitmap, event);
return toolReport;
}
return toolReport;
}
@Override
publicfinal ToolReport end(Bitmap bitmap, PointF event) {
if (!cancelled) {
toolReport.getPath().lineTo(event.x, event.y);
onEnd(bitmap, event);
return toolReport;
}
return toolReport;
}
@Override
publicfinalvoid cancel() {
cancelled = true;
toolReport.reset();
}
protectedabstractvoid onStart(Bitmap bitmap, PointF event);
protectedabstractvoid onMove(Bitmap bitmap, PointF event);
protectedabstractvoid onEnd(Bitmap bitmap, PointF event);
protectedstaticboolean isInBounds(Bitmap bitmap, PointF point) {
if (point.x >= 0 && point.x < bitmap.getWidth()) {
if (point.y >= 0 && point.y < bitmap.getHeight()) {
return true;
}
}
return false;
}
public ToolAttributes getToolAttributes() {
return toolAttributes;
}
}