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