2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.gallery3d.filtershow.filters;
19 import android.graphics.Path;
20 import android.util.Log;
22 import com.android.gallery3d.R;
23 import com.android.gallery3d.filtershow.editors.EditorDraw;
25 import java.util.Vector;
27 public class FilterDrawRepresentation extends FilterRepresentation {
28 private static final String LOGTAG = "FilterDrawRepresentation";
30 public static class StrokeData implements Cloneable {
35 public int noPoints = 0;
37 public String toString() {
38 return "stroke(" + mType + ", path(" + (mPath) + "), " + mRadius + " , "
39 + Integer.toHexString(mColor) + ")";
42 public StrokeData clone() throws CloneNotSupportedException {
43 return (StrokeData) super.clone();
47 private Vector<StrokeData> mDrawing = new Vector<StrokeData>();
48 private StrokeData mCurrent; // used in the currently drawing style
50 public FilterDrawRepresentation() {
52 setFilterClass(ImageFilterDraw.class);
53 setSerializationName("DRAW");
54 setFilterType(FilterRepresentation.TYPE_VIGNETTE);
55 setTextId(R.string.imageDraw);
56 setEditorId(EditorDraw.ID);
57 setOverlayId(R.drawable.filtershow_drawing);
62 public String toString() {
63 return getName() + " : strokes=" + mDrawing.size()
64 + ((mCurrent == null) ? " no current "
65 : ("draw=" + mCurrent.mType + " " + mCurrent.noPoints));
68 public Vector<StrokeData> getDrawing() {
72 public StrokeData getCurrentDrawing() {
77 public FilterRepresentation copy() {
78 FilterDrawRepresentation representation = new FilterDrawRepresentation();
79 copyAllParameters(representation);
80 return representation;
84 protected void copyAllParameters(FilterRepresentation representation) {
85 super.copyAllParameters(representation);
86 representation.useParametersFrom(this);
90 public boolean isNil() {
91 return getDrawing().isEmpty();
95 public void useParametersFrom(FilterRepresentation a) {
96 if (a instanceof FilterDrawRepresentation) {
97 FilterDrawRepresentation representation = (FilterDrawRepresentation) a;
99 if (representation.mCurrent != null) {
100 mCurrent = (StrokeData) representation.mCurrent.clone();
104 if (representation.mDrawing != null) {
105 mDrawing = (Vector<StrokeData>) representation.mDrawing.clone();
110 } catch (CloneNotSupportedException e) {
114 Log.v(LOGTAG, "cannot use parameters from " + a);
119 public boolean equals(FilterRepresentation representation) {
120 if (!super.equals(representation)) {
123 if (representation instanceof FilterDrawRepresentation) {
124 FilterDrawRepresentation fdRep = (FilterDrawRepresentation) representation;
125 if (fdRep.mDrawing.size() != mDrawing.size())
127 if (fdRep.mCurrent == null && mCurrent.mPath == null) {
130 if (fdRep.mCurrent != null && mCurrent.mPath != null) {
131 if (fdRep.mCurrent.noPoints == mCurrent.noPoints) {
140 public void startNewSection(byte type, int color, float size, float x, float y) {
141 mCurrent = new StrokeData();
142 mCurrent.mColor = color;
143 mCurrent.mRadius = size;
144 mCurrent.mType = type;
145 mCurrent.mPath = new Path();
146 mCurrent.mPath.moveTo(x, y);
147 mCurrent.noPoints = 0;
150 public void addPoint(float x, float y) {
152 mCurrent.mPath.lineTo(x, y);
155 public void endSection(float x, float y) {
156 mCurrent.mPath.lineTo(x, y);
158 mDrawing.add(mCurrent);
162 public void clearCurrentSection() {
166 public void clear() {