remove clone
Change-Id: Ia9f4c1778e06416018eeb07be657bcdd0af1496b
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
index 368e5c0..1eebdb5 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
@@ -48,18 +48,19 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterBasicRepresentation representation = (FilterBasicRepresentation) super.clone();
- representation.setMinimum(getMinimum());
- representation.setMaximum(getMaximum());
- representation.setValue(getValue());
- if (mLogVerbose) {
- Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
- }
+ public FilterRepresentation copy() {
+ FilterBasicRepresentation representation = new FilterBasicRepresentation(getName(),0,0,0);
+ copyAllParameters(representation);
return representation;
}
@Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
+ @Override
public void useParametersFrom(FilterRepresentation a) {
if (a instanceof FilterBasicRepresentation) {
FilterBasicRepresentation representation = (FilterBasicRepresentation) a;
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
index d9e2117..94eb206 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
@@ -40,16 +40,18 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- setFilterClass(ImageFilterParametricBorder.class);
- FilterColorBorderRepresentation representation = (FilterColorBorderRepresentation) super.clone();
- representation.setName(getName());
- representation.setColor(getColor());
- representation.setBorderSize(getBorderSize());
- representation.setBorderRadius(getBorderRadius());
+ public FilterRepresentation copy() {
+ FilterColorBorderRepresentation representation = new FilterColorBorderRepresentation(0,0,0);
+ copyAllParameters(representation);
return representation;
}
+ @Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
public void useParametersFrom(FilterRepresentation a) {
if (a instanceof FilterColorBorderRepresentation) {
FilterColorBorderRepresentation representation = (FilterColorBorderRepresentation) a;
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java
index 569ead9..a264f44 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java
@@ -33,10 +33,16 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterCurvesRepresentation rep = new FilterCurvesRepresentation();
- rep.useParametersFrom(this);
- return rep;
+ public FilterRepresentation copy() {
+ FilterCurvesRepresentation representation = new FilterCurvesRepresentation();
+ copyAllParameters(representation);
+ return representation;
+ }
+
+ @Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
}
@Override
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java
index 9c986a6..ac0cb74 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java
@@ -18,6 +18,19 @@
public class FilterDirectRepresentation extends FilterRepresentation {
+ @Override
+ public FilterRepresentation copy() {
+ FilterDirectRepresentation representation = new FilterDirectRepresentation(getName());
+ copyAllParameters(representation);
+ return representation;
+ }
+
+ @Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
public FilterDirectRepresentation(String name) {
super(name);
}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
index dcc325d..977dbea 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
@@ -74,12 +74,19 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterDrawRepresentation representation = (FilterDrawRepresentation) super.clone();
+ public FilterRepresentation copy() {
+ FilterDrawRepresentation representation = new FilterDrawRepresentation();
+ copyAllParameters(representation);
return representation;
}
@Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
+ @Override
public boolean isNil() {
return getDrawing().isEmpty();
}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java
index a7efbca..e5a6fdd 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java
@@ -43,15 +43,19 @@
}
@Override
- public synchronized FilterRepresentation clone() throws CloneNotSupportedException {
- FilterFxRepresentation representation = (FilterFxRepresentation) super.clone();
- representation.setName(getName());
- representation.setBitmapResource(getBitmapResource());
- representation.setNameResource(getNameResource());
+ public FilterRepresentation copy() {
+ FilterFxRepresentation representation = new FilterFxRepresentation(getName(),0,0);
+ copyAllParameters(representation);
return representation;
}
@Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
+ @Override
public synchronized void useParametersFrom(FilterRepresentation a) {
if (a instanceof FilterFxRepresentation) {
FilterFxRepresentation representation = (FilterFxRepresentation) a;
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
index c32f7cc..f310a2b 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
@@ -37,13 +37,19 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterImageBorderRepresentation representation = (FilterImageBorderRepresentation) super.clone();
- representation.setName(getName());
- representation.setDrawableResource(getDrawableResource());
+ public FilterRepresentation copy() {
+ FilterImageBorderRepresentation representation =
+ new FilterImageBorderRepresentation(mDrawableResource);
+ copyAllParameters(representation);
return representation;
}
+ @Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
public void useParametersFrom(FilterRepresentation a) {
if (a instanceof FilterImageBorderRepresentation) {
FilterImageBorderRepresentation representation = (FilterImageBorderRepresentation) a;
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java
index aa52893..9bd1699 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterPointRepresentation.java
@@ -31,11 +31,12 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterPointRepresentation representation = (FilterPointRepresentation) super
- .clone();
- representation.mCandidates = (Vector<FilterPoint>) mCandidates.clone();
- return representation;
+ public abstract FilterRepresentation copy();
+
+ @Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
}
public boolean hasCandidates() {
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java
index 8a87841..dd06a97 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java
@@ -34,6 +34,19 @@
setOverlayOnly(true);
}
+ @Override
+ public FilterRepresentation copy() {
+ FilterRedEyeRepresentation representation = new FilterRedEyeRepresentation();
+ copyAllParameters(representation);
+ return representation;
+ }
+
+ @Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
public void addRect(RectF rect, RectF bounds) {
Vector<RedEyeCandidate> intersects = new Vector<RedEyeCandidate>();
for (int i = 0; i < getCandidates().size(); i++) {
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
index e6018bb..ca9587c 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
@@ -25,7 +25,7 @@
import java.io.IOException;
import java.util.ArrayList;
-public class FilterRepresentation implements Cloneable {
+public class FilterRepresentation {
private static final String LOGTAG = "FilterRepresentation";
private static final boolean DEBUG = false;
private String mName;
@@ -51,9 +51,13 @@
mName = name;
}
- @Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterRepresentation representation = (FilterRepresentation) super.clone();
+ public FilterRepresentation copy(){
+ FilterRepresentation representation = new FilterRepresentation(mName);
+ representation.useParametersFrom(this);
+ return representation;
+ }
+
+ protected void copyAllParameters(FilterRepresentation representation) {
representation.setName(getName());
representation.setFilterClass(getFilterClass());
representation.setFilterType(getFilterType());
@@ -65,10 +69,6 @@
representation.setShowParameterValue(showParameterValue());
representation.mSerializationName = mSerializationName;
- if (DEBUG) {
- Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
- }
- return representation;
}
public boolean equals(FilterRepresentation representation) {
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java
index b03751e..be18129 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java
@@ -37,15 +37,19 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterTinyPlanetRepresentation representation = (FilterTinyPlanetRepresentation) super
- .clone();
- representation.mAngle = mAngle;
- representation.setZoom(getZoom());
+ public FilterRepresentation copy() {
+ FilterTinyPlanetRepresentation representation = new FilterTinyPlanetRepresentation();
+ copyAllParameters(representation);
return representation;
}
@Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
+ @Override
public void useParametersFrom(FilterRepresentation a) {
FilterTinyPlanetRepresentation representation = (FilterTinyPlanetRepresentation) a;
super.useParametersFrom(a);
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java
index 06a9953..b666e63 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java
@@ -51,16 +51,19 @@
}
@Override
- public FilterRepresentation clone() throws CloneNotSupportedException {
- FilterVignetteRepresentation representation = (FilterVignetteRepresentation) super
- .clone();
- representation.mCenterX = mCenterX;
- representation.mCenterY = mCenterY;
-
+ public FilterRepresentation copy() {
+ FilterVignetteRepresentation representation = new FilterVignetteRepresentation();
+ copyAllParameters(representation);
return representation;
}
@Override
+ protected void copyAllParameters(FilterRepresentation representation) {
+ super.copyAllParameters(representation);
+ representation.useParametersFrom(this);
+ }
+
+ @Override
public void setCenter(float centerX, float centerY) {
mCenterX = centerX;
mCenterY = centerY;
diff --git a/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java b/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java
index 2b9e370..cc4938c 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java
@@ -61,33 +61,28 @@
}
public ImagePreset(ImagePreset source) {
- try {
- for (int i = 0; i < source.mFilters.size(); i++) {
- FilterRepresentation representation = null;
- FilterRepresentation sourceRepresentation = source.mFilters.elementAt(i);
- if (sourceRepresentation instanceof GeometryMetadata) {
- GeometryMetadata geoData = new GeometryMetadata();
- GeometryMetadata srcGeo = (GeometryMetadata) sourceRepresentation;
- geoData.set(srcGeo);
- representation = geoData;
- } else {
- // TODO: get rid of clone()...
- representation = sourceRepresentation.clone();
- }
- addFilter(representation);
+
+ for (int i = 0; i < source.mFilters.size(); i++) {
+ FilterRepresentation representation = null;
+ FilterRepresentation sourceRepresentation = source.mFilters.elementAt(i);
+ if (sourceRepresentation instanceof GeometryMetadata) {
+ GeometryMetadata geoData = new GeometryMetadata();
+ GeometryMetadata srcGeo = (GeometryMetadata) sourceRepresentation;
+ geoData.set(srcGeo);
+ representation = geoData;
+ } else {
+ representation = sourceRepresentation.copy();
}
- } catch (java.lang.CloneNotSupportedException e) {
- Log.v(LOGTAG, "Exception trying to clone: " + e);
+ addFilter(representation);
}
+
}
public FilterRepresentation getFilterRepresentation(int position) {
FilterRepresentation representation = null;
- try {
- representation = mFilters.elementAt(position).clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
+
+ representation = mFilters.elementAt(position).copy();
+
return representation;
}
@@ -129,11 +124,7 @@
}
FilterRepresentation representation = mFilters.elementAt(position);
if (representation != null) {
- try {
- representation = representation.clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
+ representation = representation.copy();
}
return representation;
}