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 FilterFxRepresentation(String name, int bitmapResource, int nameResource)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 toString()41 public String toString() { 42 return "FilterFx: " + hashCode() + " : " + getName() + " bitmap rsc: " + mBitmapResource; 43 } 44 45 @Override copy()46 public FilterRepresentation copy() { 47 FilterFxRepresentation representation = new FilterFxRepresentation(getName(),0,0); 48 copyAllParameters(representation); 49 return representation; 50 } 51 52 @Override copyAllParameters(FilterRepresentation representation)53 protected void copyAllParameters(FilterRepresentation representation) { 54 super.copyAllParameters(representation); 55 representation.useParametersFrom(this); 56 } 57 58 @Override useParametersFrom(FilterRepresentation a)59 public synchronized void useParametersFrom(FilterRepresentation a) { 60 if (a instanceof FilterFxRepresentation) { 61 FilterFxRepresentation representation = (FilterFxRepresentation) a; 62 setName(representation.getName()); 63 setSerializationName(representation.getSerializationName()); 64 setBitmapResource(representation.getBitmapResource()); 65 setNameResource(representation.getNameResource()); 66 } 67 } 68 69 @Override equals(FilterRepresentation representation)70 public boolean equals(FilterRepresentation representation) { 71 if (!super.equals(representation)) { 72 return false; 73 } 74 if (representation instanceof FilterFxRepresentation) { 75 FilterFxRepresentation fx = (FilterFxRepresentation) representation; 76 if (fx.mNameResource == mNameResource 77 && fx.mBitmapResource == mBitmapResource) { 78 return true; 79 } 80 } 81 return false; 82 } 83 84 @Override same(FilterRepresentation representation)85 public boolean same(FilterRepresentation representation) { 86 if (!super.same(representation)) { 87 return false; 88 } 89 return equals(representation); 90 } 91 92 @Override allowsSingleInstanceOnly()93 public boolean allowsSingleInstanceOnly() { 94 return true; 95 } 96 getNameResource()97 public int getNameResource() { 98 return mNameResource; 99 } 100 setNameResource(int nameResource)101 public void setNameResource(int nameResource) { 102 mNameResource = nameResource; 103 } 104 getBitmapResource()105 public int getBitmapResource() { 106 return mBitmapResource; 107 } 108 setBitmapResource(int bitmapResource)109 public void setBitmapResource(int bitmapResource) { 110 mBitmapResource = bitmapResource; 111 } 112 } 113