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.Log;
21 import com.android.gallery3d.filtershow.editors.BasicEditor;
23 public class FilterRepresentation implements Cloneable {
24 private static final String LOGTAG = "FilterRepresentation";
25 private static final boolean DEBUG = false;
27 private int mPriority = TYPE_NORMAL;
28 private Class<?> mFilterClass;
29 private boolean mSupportsPartialRendering = false;
30 private int mTextId = 0;
31 private int mEditorId = BasicEditor.ID;
32 private int mButtonId = 0;
33 private int mOverlayId = 0;
34 private boolean mOverlayOnly = false;
35 private boolean mShowParameterValue = true;
36 private String mSerializationName;
37 public static final byte TYPE_BORDER = 1;
38 public static final byte TYPE_FX = 2;
39 public static final byte TYPE_WBALANCE = 3;
40 public static final byte TYPE_VIGNETTE = 4;
41 public static final byte TYPE_NORMAL = 5;
42 public static final byte TYPE_TINYPLANET = 6;
44 private FilterRepresentation mTempRepresentation = null;
46 public FilterRepresentation(String name) {
51 public FilterRepresentation clone() throws CloneNotSupportedException {
52 FilterRepresentation representation = (FilterRepresentation) super.clone();
53 representation.setName(getName());
54 representation.setFilterClass(getFilterClass());
55 representation.setFilterType(getFilterType());
56 representation.setSupportsPartialRendering(supportsPartialRendering());
57 representation.setTextId(getTextId());
58 representation.setEditorId(getEditorId());
59 representation.setOverlayId(getOverlayId());
60 representation.setOverlayOnly(getOverlayOnly());
61 representation.setShowParameterValue(showParameterValue());
62 representation.mSerializationName = mSerializationName;
64 representation.mTempRepresentation =
65 mTempRepresentation != null ? mTempRepresentation.clone() : null;
67 Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
69 return representation;
72 public boolean equals(FilterRepresentation representation) {
73 if (representation == null) {
76 if (representation.mFilterClass == representation.mFilterClass
77 && representation.mName.equalsIgnoreCase(mName)
78 && representation.mPriority == mPriority
79 && representation.mSupportsPartialRendering == mSupportsPartialRendering
80 && representation.mTextId == mTextId
81 && representation.mEditorId == mEditorId
82 && representation.mButtonId == mButtonId
83 && representation.mOverlayId == mOverlayId
84 && representation.mOverlayOnly == mOverlayOnly
85 && representation.mShowParameterValue == mShowParameterValue) {
92 public String toString() {
96 public void setName(String name) {
100 public String getName() {
104 public void setSerializationName(String sname) {
105 mSerializationName = sname;
108 public String getSerializationName() {
109 return mSerializationName;
112 public void setFilterType(int priority) {
113 mPriority = priority;
116 public int getFilterType() {
120 public boolean isNil() {
124 public boolean supportsPartialRendering() {
125 return false && mSupportsPartialRendering; // disable for now
128 public void setSupportsPartialRendering(boolean value) {
129 mSupportsPartialRendering = value;
132 public void useParametersFrom(FilterRepresentation a) {
135 public void clearTempRepresentation() {
136 mTempRepresentation = null;
139 public synchronized void updateTempParametersFrom(FilterRepresentation representation) {
140 if (mTempRepresentation == null) {
142 mTempRepresentation = representation.clone();
143 } catch (CloneNotSupportedException e) {
147 mTempRepresentation.useParametersFrom(representation);
151 public synchronized void synchronizeRepresentation() {
152 if (mTempRepresentation != null) {
153 useParametersFrom(mTempRepresentation);
157 public boolean allowsMultipleInstances() {
161 public Class<?> getFilterClass() {
165 public void setFilterClass(Class<?> filterClass) {
166 mFilterClass = filterClass;
169 public boolean same(FilterRepresentation b) {
173 return getFilterClass() == b.getFilterClass();
176 public int getTextId() {
180 public void setTextId(int textId) {
184 public int getOverlayId() {
188 public void setOverlayId(int overlayId) {
189 mOverlayId = overlayId;
192 public boolean getOverlayOnly() {
196 public void setOverlayOnly(boolean value) {
197 mOverlayOnly = value;
200 final public int getEditorId() {
204 public int[] getEditorIds() {
209 public void setEditorId(int editorId) {
210 mEditorId = editorId;
213 public boolean showParameterValue() {
214 return mShowParameterValue;
217 public void setShowParameterValue(boolean showParameterValue) {
218 mShowParameterValue = showParameterValue;
221 public String getStateRepresentation() {
225 public String[][] serializeRepresentation() {
226 String[][] ret = { { "Name" , getName() }};
230 public void deSerializeRepresentation(String[][] rep) {
231 for (int i = 0; i < rep.length; i++) {
232 if ("Name".equals(rep[i][0])) {
239 // Override this in subclasses
240 public int getStyle() {