diff options
author | nicolasroard <nicolasroard@google.com> | 2013-02-12 12:19:19 -0800 |
---|---|---|
committer | nicolasroard <nicolasroard@google.com> | 2013-02-12 12:36:32 -0800 |
commit | f60760478ec7c78446be0e0c6bc5502d1557974c (patch) | |
tree | 4021390076dcb05b7c4e80eb5bb60246dd987c37 /src/com/android/gallery3d/filtershow/filters | |
parent | 99baf61387ab1ef15bb9db5fa3b2b55591e87059 (diff) | |
download | android_packages_apps_Gallery2-f60760478ec7c78446be0e0c6bc5502d1557974c.tar.gz android_packages_apps_Gallery2-f60760478ec7c78446be0e0c6bc5502d1557974c.tar.bz2 android_packages_apps_Gallery2-f60760478ec7c78446be0e0c6bc5502d1557974c.zip |
Refactor FiltersManager
Change-Id: I4c42ddb90e65e90af873eb8dbe065f4fa3de69ef
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters')
7 files changed, 119 insertions, 15 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java new file mode 100644 index 000000000..43660d6a0 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.gallery3d.filtershow.filters; + +import com.android.gallery3d.filtershow.cache.ImageLoader; + +import java.util.HashMap; +import java.util.Vector; + +public class BaseFiltersManager { + + private static final String LOGTAG = "BaseFiltersManager"; + private static HashMap<Class, ImageFilter> mFilters = new HashMap<Class, ImageFilter>(); + + protected BaseFiltersManager() { + Vector<ImageFilter> filters = new Vector<ImageFilter>(); + addFilters(filters); + for (ImageFilter filter : filters) { + mFilters.put(filter.getClass(), filter); + } + } + + protected void addFilters(Vector<ImageFilter> filters) { + filters.add(new ImageFilterTinyPlanet()); + filters.add(new ImageFilterRedEye()); + filters.add(new ImageFilterWBalance()); + filters.add(new ImageFilterExposure()); + filters.add(new ImageFilterVignette()); + filters.add(new ImageFilterContrast()); + filters.add(new ImageFilterShadows()); + filters.add(new ImageFilterVibrance()); + filters.add(new ImageFilterSharpen()); + filters.add(new ImageFilterCurves()); + filters.add(new ImageFilterDraw()); + filters.add(new ImageFilterHue()); + filters.add(new ImageFilterSaturated()); + filters.add(new ImageFilterBwFilter()); + filters.add(new ImageFilterNegative()); + filters.add(new ImageFilterEdge()); + filters.add(new ImageFilterKMeans()); + filters.add(new ImageFilterFx()); + filters.add(new ImageFilterBorder()); + filters.add(new ImageFilterParametricBorder()); + } + + public ImageFilter getFilter(Class c) { + return mFilters.get(c); + } + + public ImageFilter getFilterForRepresentation(FilterRepresentation representation) { + return mFilters.get(representation.getFilterClass()); + } + + public void addFilter(Class filterClass, ImageFilter filter) { + mFilters.put(filterClass, filter); + } + + public FilterRepresentation getRepresentation(Class c) { + ImageFilter filter = mFilters.get(c); + if (filter != null) { + return filter.getDefaultRepresentation(); + } + return null; + } + + public void addLooks(Vector<FilterRepresentation> representations) { + // subclass can add representations + } + + public void addEffects(Vector<FilterRepresentation> representations) { + representations.add(getRepresentation(ImageFilterTinyPlanet.class)); + representations.add(getRepresentation(ImageFilterRedEye.class)); + representations.add(getRepresentation(ImageFilterWBalance.class)); + representations.add(getRepresentation(ImageFilterExposure.class)); + representations.add(getRepresentation(ImageFilterVignette.class)); + representations.add(getRepresentation(ImageFilterContrast.class)); + representations.add(getRepresentation(ImageFilterShadows.class)); + representations.add(getRepresentation(ImageFilterVibrance.class)); + representations.add(getRepresentation(ImageFilterSharpen.class)); + representations.add(getRepresentation(ImageFilterCurves.class)); + representations.add(getRepresentation(ImageFilterDraw.class)); + representations.add(getRepresentation(ImageFilterHue.class)); + representations.add(getRepresentation(ImageFilterSaturated.class)); + representations.add(getRepresentation(ImageFilterBwFilter.class)); + representations.add(getRepresentation(ImageFilterNegative.class)); + representations.add(getRepresentation(ImageFilterEdge.class)); + representations.add(getRepresentation(ImageFilterKMeans.class)); + } + + public void resetBitmapsRS() { + for (Class c : mFilters.keySet()) { + ImageFilter filter = mFilters.get(c); + if (filter instanceof ImageFilterRS) { + ImageFilterRS filterRS = (ImageFilterRS) filter; + filterRS.resetBitmap(); + } + } + } +} diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java index b2e1ed39b..89ea5ccc5 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java @@ -50,7 +50,7 @@ public class FilterDrawRepresentation extends FilterRepresentation { public FilterDrawRepresentation() { super("Draw"); setFilterClass(ImageFilterDraw.class); - setFilterType(FilterRepresentation.TYPE_VIGNETTE); + setPriority(FilterRepresentation.TYPE_VIGNETTE); setTextId(R.string.imageDraw); setButtonId(R.id.drawOnImageButton); setEditorId(EditorDraw.ID); diff --git a/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java index fa3fe720b..859bf327c 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterFxRepresentation.java @@ -31,7 +31,7 @@ public class FilterFxRepresentation extends FilterRepresentation { mBitmapResource = bitmapResource; mNameResource = nameResource; setFilterClass(ImageFilterFx.class); - setFilterType(FilterRepresentation.TYPE_FX); + setPriority(FilterRepresentation.TYPE_FX); setTextId(nameResource); setEditorId(ImageOnlyEditor.ID); setShowEditingControls(false); diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java index 38d3a696f..2667cc8e9 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterRedEyeRepresentation.java @@ -31,7 +31,7 @@ public class FilterRedEyeRepresentation extends FilterRepresentation { public FilterRedEyeRepresentation() { super("RedEye"); setFilterClass(ImageFilterRedEye.class); - setFilterType(FilterRepresentation.TYPE_NORMAL); + setPriority(FilterRepresentation.TYPE_NORMAL); setButtonId(R.id.redEyeButton); setTextId(R.string.redeye); setEditorId(EditorRedEye.ID); diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java index f282d2966..2b6c3fe7d 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java @@ -23,7 +23,7 @@ import com.android.gallery3d.filtershow.presets.ImagePreset; public class FilterRepresentation implements Cloneable { private static final String LOGTAG = "FilterRepresentation"; private String mName; - private int mPriority; + private int mPriority = TYPE_NORMAL; private ImagePreset mPreset; private Class mFilterClass; private int mTextId = 0; @@ -40,7 +40,6 @@ public class FilterRepresentation implements Cloneable { public static final byte TYPE_VIGNETTE = 4; public static final byte TYPE_NORMAL = 5; public static final byte TYPE_TINYPLANET = 6; - private byte filterType = TYPE_NORMAL; public FilterRepresentation(String name) { mName = name; @@ -86,14 +85,6 @@ public class FilterRepresentation implements Cloneable { return mName; } - public byte getFilterType() { - return filterType; - } - - protected void setFilterType(byte type) { - filterType = type; - } - public void setName(String name) { mName = name; } diff --git a/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java index 9bf2f0bf3..7b69ce9e0 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java @@ -27,7 +27,7 @@ public class FilterTinyPlanetRepresentation extends FilterBasicRepresentation { super("TinyPlanet", 0, 50, 100); setShowParameterValue(true); setFilterClass(ImageFilterTinyPlanet.class); - setFilterType(FilterRepresentation.TYPE_TINYPLANET); + setPriority(FilterRepresentation.TYPE_TINYPLANET); setTextId(R.string.tinyplanet); setButtonId(R.id.tinyplanetButton); setEditorId(EditorTinyPlanet.ID); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java index e0bcfba56..8b6dd5426 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java @@ -30,7 +30,7 @@ public class ImageFilterWBalance extends ImageFilter { public FilterRepresentation getDefaultRepresentation() { FilterRepresentation representation = new FilterDirectRepresentation("WBalance"); representation.setFilterClass(ImageFilterWBalance.class); - representation.setFilterType(FilterRepresentation.TYPE_WBALANCE); + representation.setPriority(FilterRepresentation.TYPE_WBALANCE); representation.setTextId(R.string.wbalance); representation.setButtonId(R.id.wbalanceButton); representation.setShowEditingControls(false); |