OSDN Git Service

abe69d110d914fac207524cdd3d2059617289b37
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / filters / FilterFxRepresentation.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 com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
20
21 public class FilterFxRepresentation extends FilterRepresentation {
22    private static final String LOGTAG = "FilterFxRepresentation";
23     // TODO: When implementing serialization, we should find a unique way of
24     // specifying bitmaps / names (the resource IDs being random)
25     private int mBitmapResource = 0;
26     private int mNameResource = 0;
27
28     public FilterFxRepresentation(String name, int bitmapResource, int nameResource) {
29         super(name);
30         setFilterClass(ImageFilterFx.class);
31         mBitmapResource = bitmapResource;
32         mNameResource = nameResource;
33         setFilterType(FilterRepresentation.TYPE_FX);
34         setTextId(nameResource);
35         setEditorId(ImageOnlyEditor.ID);
36         setShowParameterValue(false);
37         setSupportsPartialRendering(true);
38     }
39
40     @Override
41     public String toString() {
42         return "FilterFx: " + hashCode() + " : " + getName() + " bitmap rsc: " + mBitmapResource;
43     }
44
45     @Override
46     public synchronized FilterRepresentation clone() throws CloneNotSupportedException {
47         FilterFxRepresentation representation = (FilterFxRepresentation) super.clone();
48         representation.setName(getName());
49         representation.setBitmapResource(getBitmapResource());
50         representation.setNameResource(getNameResource());
51         return representation;
52     }
53
54     @Override
55     public synchronized void useParametersFrom(FilterRepresentation a) {
56         if (a instanceof FilterFxRepresentation) {
57             FilterFxRepresentation representation = (FilterFxRepresentation) a;
58             setName(representation.getName());
59             setSerializationName(representation.getSerializationName());
60             setBitmapResource(representation.getBitmapResource());
61             setNameResource(representation.getNameResource());
62         }
63     }
64
65     @Override
66     public boolean equals(FilterRepresentation representation) {
67         if (!super.equals(representation)) {
68             return false;
69         }
70         if (representation instanceof FilterFxRepresentation) {
71             FilterFxRepresentation fx = (FilterFxRepresentation) representation;
72             if (fx.mNameResource == mNameResource
73                     && fx.mBitmapResource == mBitmapResource) {
74                 return true;
75             }
76         }
77         return false;
78     }
79
80     @Override
81     public boolean same(FilterRepresentation representation) {
82         if (!super.same(representation)) {
83             return false;
84         }
85         return equals(representation);
86     }
87
88     @Override
89     public boolean allowsMultipleInstances() {
90         return true;
91     }
92
93     public int getNameResource() {
94         return mNameResource;
95     }
96
97     public void setNameResource(int nameResource) {
98         mNameResource = nameResource;
99     }
100
101     public int getBitmapResource() {
102         return mBitmapResource;
103     }
104
105     public void setBitmapResource(int bitmapResource) {
106         mBitmapResource = bitmapResource;
107     }
108 }