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.Color;
21 import com.android.gallery3d.R;
22 import com.android.gallery3d.filtershow.controller.BasicParameterInt;
23 import com.android.gallery3d.filtershow.controller.BasicParameterStyle;
24 import com.android.gallery3d.filtershow.controller.Parameter;
25 import com.android.gallery3d.filtershow.controller.ParameterColor;
26 import com.android.gallery3d.filtershow.editors.EditorColorBorder;
27 import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
29 public class FilterColorBorderRepresentation extends FilterRepresentation {
30 private static final String LOGTAG = "FilterColorBorderRepresentation";
31 private static final String SERIALIZATION_NAME = "COLORBORDER";
33 public static final int PARAM_SIZE = 0;
34 public static final int PARAM_RADIUS = 1;
35 public static final int PARAM_COLOR = 2;
36 public static int DEFAULT_MENU_COLOR1 = Color.WHITE;
37 public static int DEFAULT_MENU_COLOR2 = Color.BLACK;
38 public static int DEFAULT_MENU_COLOR3 = Color.GRAY;
39 public static int DEFAULT_MENU_COLOR4 = 0xFFFFCCAA;
40 public static int DEFAULT_MENU_COLOR5 = 0xFFAAAAAA;
41 private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 20, 2, 300);
42 private BasicParameterInt mParamRadius = new BasicParameterInt(PARAM_RADIUS, 4, 2, 300);
43 private ParameterColor mParamColor = new ParameterColor(PARAM_COLOR, DEFAULT_MENU_COLOR1);
45 private Parameter[] mAllParam = {
50 private int mPramMode;
52 public FilterColorBorderRepresentation(int color, int size, int radius) {
54 setSerializationName(SERIALIZATION_NAME);
55 setFilterType(FilterRepresentation.TYPE_BORDER);
56 setTextId(R.string.borders);
57 setEditorId(EditorColorBorder.ID);
58 setShowParameterValue(false);
59 setFilterClass(ImageFilterColorBorder.class);
60 mParamColor.setValue(color);
61 mParamSize.setValue(size);
62 mParamColor.setValue(radius);
65 public String toString() {
66 return "FilterBorder: " + getName();
70 public FilterRepresentation copy() {
71 FilterColorBorderRepresentation representation =
72 new FilterColorBorderRepresentation(0, 0, 0);
73 copyAllParameters(representation);
74 return representation;
78 protected void copyAllParameters(FilterRepresentation representation) {
79 super.copyAllParameters(representation);
80 representation.useParametersFrom(this);
83 public void useParametersFrom(FilterRepresentation a) {
84 if (a instanceof FilterColorBorderRepresentation) {
85 FilterColorBorderRepresentation representation = (FilterColorBorderRepresentation) a;
86 setName(representation.getName());
87 setColor(representation.getColor());
88 setBorderSize(representation.getBorderSize());
89 setBorderRadius(representation.getBorderRadius());
94 public boolean equals(FilterRepresentation representation) {
95 if (!super.equals(representation)) {
98 if (representation instanceof FilterColorBorderRepresentation) {
99 FilterColorBorderRepresentation border = (FilterColorBorderRepresentation) representation;
100 if (border.mParamColor.getValue() == mParamColor.getValue()
101 && border.mParamRadius.getValue() == mParamRadius.getValue()
102 && border.mParamSize.getValue() == mParamSize.getValue()) {
110 public boolean allowsSingleInstanceOnly() {
114 public Parameter getParam(int mode) {
115 return mAllParam[mode];
119 public int getTextId() {
120 return R.string.borders;
123 public int getColor() {
124 return mParamColor.getValue();
127 public void setColor(int color) {
128 mParamColor.setValue(color);
131 public int getBorderSize() {
132 return mParamSize.getValue();
135 public void setBorderSize(int borderSize) {
136 mParamSize.setValue(borderSize);
139 public int getBorderRadius() {
140 return mParamRadius.getValue();
143 public void setBorderRadius(int borderRadius) {
144 mParamRadius.setValue(borderRadius);
147 public void setPramMode(int pramMode) {
148 this.mPramMode = pramMode;
151 public Parameter getCurrentParam() {
152 return mAllParam[mPramMode];
155 public String getValueString() {