OSDN Git Service

merge in klp-release history after reset to klp-dev
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / filters / FilterColorBorderRepresentation.java
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.gallery3d.filtershow.filters;
18
19 import android.graphics.Color;
20
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;
28
29 public class FilterColorBorderRepresentation extends FilterRepresentation {
30     private static final String LOGTAG = "FilterColorBorderRepresentation";
31     private static final String SERIALIZATION_NAME = "COLORBORDER";
32
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);
44
45     private Parameter[] mAllParam = {
46             mParamSize,
47             mParamRadius,
48             mParamColor
49     };
50     private int mPramMode;
51
52     public FilterColorBorderRepresentation(int color, int size, int radius) {
53         super("ColorBorder");
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);
63     }
64
65     public String toString() {
66         return "FilterBorder: " + getName();
67     }
68
69     @Override
70     public FilterRepresentation copy() {
71         FilterColorBorderRepresentation representation =
72                 new FilterColorBorderRepresentation(0, 0, 0);
73         copyAllParameters(representation);
74         return representation;
75     }
76
77     @Override
78     protected void copyAllParameters(FilterRepresentation representation) {
79         super.copyAllParameters(representation);
80         representation.useParametersFrom(this);
81     }
82
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());
90         }
91     }
92
93     @Override
94     public boolean equals(FilterRepresentation representation) {
95         if (!super.equals(representation)) {
96             return false;
97         }
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()) {
103
104                 return true;
105             }
106         }
107         return false;
108     }
109
110     public boolean allowsSingleInstanceOnly() {
111         return true;
112     }
113
114     public Parameter getParam(int mode) {
115         return mAllParam[mode];
116     }
117
118     @Override
119     public int getTextId() {
120         return R.string.borders;
121     }
122
123     public int getColor() {
124         return mParamColor.getValue();
125     }
126
127     public void setColor(int color) {
128         mParamColor.setValue(color);
129     }
130
131     public int getBorderSize() {
132         return mParamSize.getValue();
133     }
134
135     public void setBorderSize(int borderSize) {
136         mParamSize.setValue(borderSize);
137     }
138
139     public int getBorderRadius() {
140         return mParamRadius.getValue();
141     }
142
143     public void setBorderRadius(int borderRadius) {
144         mParamRadius.setValue(borderRadius);
145     }
146
147     public void setPramMode(int pramMode) {
148         this.mPramMode = pramMode;
149     }
150
151     public Parameter getCurrentParam() {
152         return mAllParam[mPramMode];
153     }
154
155     public String getValueString() {
156         return "";
157     }
158 }