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.util.JsonReader;
20 import android.util.JsonWriter;
21 import android.util.Log;
23 import com.android.gallery3d.filtershow.editors.BasicEditor;
25 import java.io.IOException;
26 import java.util.ArrayList;
28 public class FilterRepresentation implements Cloneable {
29 private static final String LOGTAG = "FilterRepresentation";
30 private static final boolean DEBUG = false;
32 private int mPriority = TYPE_NORMAL;
33 private Class<?> mFilterClass;
34 private boolean mSupportsPartialRendering = false;
35 private int mTextId = 0;
36 private int mEditorId = BasicEditor.ID;
37 private int mButtonId = 0;
38 private int mOverlayId = 0;
39 private boolean mOverlayOnly = false;
40 private boolean mShowParameterValue = true;
41 private String mSerializationName;
42 public static final byte TYPE_BORDER = 1;
43 public static final byte TYPE_FX = 2;
44 public static final byte TYPE_WBALANCE = 3;
45 public static final byte TYPE_VIGNETTE = 4;
46 public static final byte TYPE_NORMAL = 5;
47 public static final byte TYPE_TINYPLANET = 6;
48 protected static final String NAME_TAG = "Name";
50 public FilterRepresentation(String name) {
55 public FilterRepresentation clone() throws CloneNotSupportedException {
56 FilterRepresentation representation = (FilterRepresentation) super.clone();
57 representation.setName(getName());
58 representation.setFilterClass(getFilterClass());
59 representation.setFilterType(getFilterType());
60 representation.setSupportsPartialRendering(supportsPartialRendering());
61 representation.setTextId(getTextId());
62 representation.setEditorId(getEditorId());
63 representation.setOverlayId(getOverlayId());
64 representation.setOverlayOnly(getOverlayOnly());
65 representation.setShowParameterValue(showParameterValue());
66 representation.mSerializationName = mSerializationName;
69 Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
71 return representation;
74 public boolean equals(FilterRepresentation representation) {
75 if (representation == null) {
78 if (representation.mFilterClass == mFilterClass
79 && representation.mName.equalsIgnoreCase(mName)
80 && representation.mPriority == mPriority
81 // TODO: After we enable partial rendering, we can switch back
82 // to use member variable here.
83 && representation.supportsPartialRendering() == supportsPartialRendering()
84 && representation.mTextId == mTextId
85 && representation.mEditorId == mEditorId
86 && representation.mButtonId == mButtonId
87 && representation.mOverlayId == mOverlayId
88 && representation.mOverlayOnly == mOverlayOnly
89 && representation.mShowParameterValue == mShowParameterValue) {
96 public String toString() {
100 public void setName(String name) {
104 public String getName() {
108 public void setSerializationName(String sname) {
109 mSerializationName = sname;
112 public String getSerializationName() {
113 return mSerializationName;
116 public void setFilterType(int priority) {
117 mPriority = priority;
120 public int getFilterType() {
124 public boolean isNil() {
128 public boolean supportsPartialRendering() {
129 return false && mSupportsPartialRendering; // disable for now
132 public void setSupportsPartialRendering(boolean value) {
133 mSupportsPartialRendering = value;
136 public void useParametersFrom(FilterRepresentation a) {
139 public boolean allowsSingleInstanceOnly() {
143 public Class<?> getFilterClass() {
147 public void setFilterClass(Class<?> filterClass) {
148 mFilterClass = filterClass;
151 // This same() function is different from equals(), basically it checks
152 // whether 2 FilterRepresentations are the same type. It doesn't care about
154 public boolean same(FilterRepresentation b) {
158 return getFilterClass() == b.getFilterClass();
161 public int getTextId() {
165 public void setTextId(int textId) {
169 public int getOverlayId() {
173 public void setOverlayId(int overlayId) {
174 mOverlayId = overlayId;
177 public boolean getOverlayOnly() {
181 public void setOverlayOnly(boolean value) {
182 mOverlayOnly = value;
185 final public int getEditorId() {
189 public int[] getEditorIds() {
194 public void setEditorId(int editorId) {
195 mEditorId = editorId;
198 public boolean showParameterValue() {
199 return mShowParameterValue;
202 public void setShowParameterValue(boolean showParameterValue) {
203 mShowParameterValue = showParameterValue;
206 public String getStateRepresentation() {
211 * Method must "beginObject()" add its info and "endObject()"
213 * @throws IOException
215 public void serializeRepresentation(JsonWriter writer) throws IOException {
216 writer.beginObject();
218 String[][] rep = serializeRepresentation();
219 for (int k = 0; k < rep.length; k++) {
220 writer.name(rep[k][0]);
221 writer.value(rep[k][1]);
227 // this is the old way of doing this and will be removed soon
228 public String[][] serializeRepresentation() {
229 String[][] ret = {{NAME_TAG, getName()}};
233 public void deSerializeRepresentation(JsonReader reader) throws IOException {
234 ArrayList<String[]> al = new ArrayList<String[]>();
235 reader.beginObject();
236 while (reader.hasNext()) {
237 String[] kv = {reader.nextName(), reader.nextString()};
242 String[][] oldFormat = al.toArray(new String[al.size()][]);
244 deSerializeRepresentation(oldFormat);
247 // this is the old way of doing this and will be removed soon
248 public void deSerializeRepresentation(String[][] rep) {
249 for (int i = 0; i < rep.length; i++) {
250 if (NAME_TAG.equals(rep[i][0])) {
257 // Override this in subclasses
258 public int getStyle() {