ImagePreset oldPreset = MasterImage.getImage().getPreset();
ImagePreset copy = new ImagePreset(oldPreset);
copy.removeFilter(filterRepresentation);
- MasterImage.getImage().setPreset(copy, true);
+ MasterImage.getImage().setPreset(copy, copy.getLastRepresentation(), true);
if (MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) {
FilterRepresentation lastRepresentation = copy.getLastRepresentation();
MasterImage.getImage().setCurrentFilterRepresentation(lastRepresentation);
} else {
if (filterRepresentation.allowsSingleInstanceOnly()) {
representation.updateTempParametersFrom(filterRepresentation);
- copy.setHistoryName(filterRepresentation.getName());
representation.synchronizeRepresentation();
}
filterRepresentation = representation;
}
- MasterImage.getImage().setPreset(copy, true);
+ MasterImage.getImage().setPreset(copy, filterRepresentation, true);
MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation);
}
mLoadBitmapTask = null;
if (mOriginalPreset != null) {
- MasterImage.getImage().setPreset(mOriginalPreset, true);
+ MasterImage.getImage().setPreset(mOriginalPreset,
+ mOriginalPreset.getLastRepresentation(), true);
mOriginalPreset = null;
}
public void setDefaultPreset() {
// Default preset (original)
- ImagePreset preset = new ImagePreset(getString(R.string.history_original)); // empty
+ ImagePreset preset = new ImagePreset(); // empty
preset.setImageLoader(mImageLoader);
- mMasterImage.setPreset(preset, true);
+ mMasterImage.setPreset(preset, preset.getLastRepresentation(), true);
}
// //////////////////////////////////////////////////////////////////////////////
void resetHistory() {
HistoryAdapter adapter = mMasterImage.getHistory();
adapter.reset();
- ImagePreset original = new ImagePreset(adapter.getItem(0));
- mMasterImage.setPreset(original, true);
+ HistoryItem historyItem = adapter.getItem(0);
+ ImagePreset original = new ImagePreset(historyItem.getImagePreset());
+ mMasterImage.setPreset(original, historyItem.getFilterRepresentation(), true);
invalidateViews();
backToMain();
}
import java.util.Vector;
-public class HistoryAdapter extends ArrayAdapter<ImagePreset> {
+public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
private static final String LOGTAG = "HistoryAdapter";
private int mCurrentPresetPosition = 0;
private String mBorders = null;
if (getCount() == 0) {
return;
}
- ImagePreset first = getItem(getCount() - 1);
+ HistoryItem first = getItem(getCount() - 1);
clear();
addHistoryItem(first);
updateMenuItems();
}
- public ImagePreset getLast() {
+ public HistoryItem getLast() {
if (getCount() == 0) {
return null;
}
return getItem(0);
}
- public ImagePreset getCurrent() {
+ public HistoryItem getCurrent() {
return getItem(mCurrentPresetPosition);
}
- public void addHistoryItem(ImagePreset preset) {
+ public void addHistoryItem(HistoryItem preset) {
insert(preset, 0);
updateMenuItems();
}
@Override
- public void insert(ImagePreset preset, int position) {
+ public void insert(HistoryItem preset, int position) {
if (mCurrentPresetPosition != 0) {
// in this case, let's discount the presets before the current one
- Vector<ImagePreset> oldItems = new Vector<ImagePreset>();
+ Vector<HistoryItem> oldItems = new Vector<HistoryItem>();
for (int i = mCurrentPresetPosition; i < getCount(); i++) {
oldItems.add(getItem(i));
}
view = inflater.inflate(R.layout.filtershow_history_operation_row, null);
}
- ImagePreset item = getItem(position);
+ HistoryItem historyItem = getItem(position);
+ ImagePreset item = historyItem.getImagePreset();
if (item != null) {
TextView itemView = (TextView) view.findViewById(R.id.rowTextView);
- if (itemView != null) {
- itemView.setText(item.historyName());
+ if (itemView != null && historyItem.getFilterRepresentation() != null) {
+ itemView.setText(historyItem.getFilterRepresentation().getName());
}
ImageView preview = (ImageView) view.findViewById(R.id.preview);
- Bitmap bmp = item.getPreviewImage();
+ Bitmap bmp = historyItem.getPreviewImage();
if (position == getCount()-1 && mOriginalBitmap != null) {
bmp = mOriginalBitmap;
}
--- /dev/null
+/*
+ * 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;
+
+import android.graphics.Bitmap;
+import android.util.Log;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.presets.ImagePreset;
+
+public class HistoryItem {
+ private static final String LOGTAG = "HistoryItem";
+ private ImagePreset mImagePreset;
+ private FilterRepresentation mFilterRepresentation;
+ private Bitmap mPreviewImage;
+
+ public HistoryItem(ImagePreset preset, FilterRepresentation representation) {
+ mImagePreset = new ImagePreset(preset);
+ try {
+ if (representation != null) {
+ mFilterRepresentation = representation.clone();
+ }
+ } catch (CloneNotSupportedException e) {
+ Log.e(LOGTAG, "clone not supported", e);
+ }
+ }
+
+ public ImagePreset getImagePreset() {
+ return mImagePreset;
+ }
+
+ public FilterRepresentation getFilterRepresentation() {
+ return mFilterRepresentation;
+ }
+
+ public Bitmap getPreviewImage() {
+ return mPreviewImage;
+ }
+
+ public void setPreviewImage(Bitmap previewImage) {
+ mPreviewImage = previewImage;
+ }
+
+}
if (request.getType() == RenderingRequest.ICON_RENDERING) {
mEnvironment.setQuality(FilterEnvironment.QUALITY_ICON);
- } else if (request.getType() == RenderingRequest.STYLE_ICON_RENDERING) {
- mEnvironment.setQuality(ImagePreset.STYLE_ICON);
} else {
mEnvironment.setQuality(FilterEnvironment.QUALITY_PREVIEW);
}
public void initializeSelection(int category) {
mCategory = category;
- if (category == MainPanel.LOOKS || category == MainPanel.BORDERS) {
- ImagePreset preset = MasterImage.getImage().getPreset();
- if (preset != null) {
- for (int i = 0; i < getCount(); i++) {
- if (preset.historyName().equals(getItem(i).getRepresentation().getName())) {
- mSelectedPosition = i;
- }
- }
- }
- } else {
- mSelectedPosition = -1;
- }
+ // TODO: fix this
+ mSelectedPosition = -1;
}
@Override
indicatorSize = (int) resources.getDimension(R.dimen.crop_indicator_size);
}
- @Override
- public String getName() {
- return getContext().getString(R.string.crop);
- }
-
private void swapAspect() {
if (mDoingCropIntentAction) {
return;
}
@Override
- public String getName() {
- return getContext().getString(R.string.mirror);
- }
-
- @Override
protected void setActionDown(float x, float y) {
super.setActionDown(x, y);
}
import android.view.MotionEvent;
import android.view.View;
+import com.android.gallery3d.filtershow.HistoryItem;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata.FLIP;
import com.android.gallery3d.filtershow.presets.ImagePreset;
mMode = MODES.NONE;
}
- public String getName() {
- return "Geometry";
- }
-
public void saveAndSetPreset() {
- ImagePreset lastHistoryItem = MasterImage.getImage().getHistory().getLast();
- if (lastHistoryItem != null && lastHistoryItem.historyName().equalsIgnoreCase(getName())) {
+ FilterRepresentation lastAction = null;
+ HistoryItem historyItem = MasterImage.getImage().getHistory().getLast();
+ if (historyItem != null) {
+ lastAction = historyItem.getFilterRepresentation();
+ }
+
+ if (lastAction != null
+ && lastAction.getSerializationName().equalsIgnoreCase(
+ GeometryMetadata.SERIALIZATION_NAME)) {
getImagePreset().setGeometry(mLocalGeometry);
resetImageCaches(this);
} else {
if (mLocalGeometry.hasModifications()) {
ImagePreset copy = new ImagePreset(getImagePreset());
copy.setGeometry(mLocalGeometry);
- copy.setHistoryName(getName());
- copy.setIsFx(false);
- MasterImage.getImage().setPreset(copy, true);
+ // TODO: we should have multiple filter representations for each
+ // of the different geometry operations we have, otherwise we cannot
+ // differentiate them in the history/state
+ MasterImage.getImage().setPreset(copy, copy.getGeometry(), true);
}
}
MasterImage.getImage().notifyGeometryChange();
super(context);
}
- @Override
- public String getName() {
- return getContext().getString(R.string.rotate);
- }
-
private static final Paint gPaint = new Paint();
private void computeValue() {
}
@Override
- public String getName() {
- return getContext().getString(R.string.straighten);
- }
-
- @Override
protected void setActionDown(float x, float y) {
super.setActionDown(x, y);
mBaseAngle = mAngle = getLocalStraighten();
import android.util.Log;
import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.HistoryAdapter;
+import com.android.gallery3d.filtershow.HistoryItem;
import com.android.gallery3d.filtershow.cache.*;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.ImageFilter;
return mFiltersOnlyPreset;
}
- public synchronized void setPreset(ImagePreset preset, boolean addToHistory) {
+ public synchronized void setPreset(ImagePreset preset,
+ FilterRepresentation change,
+ boolean addToHistory) {
if (DEBUG) {
preset.showFilters();
}
setGeometry();
mPreset.fillImageStateAdapter(mState);
if (addToHistory) {
- mHistory.addHistoryItem(mPreset);
+ HistoryItem historyItem = new HistoryItem(mPreset, change);
+ mHistory.addHistoryItem(historyItem);
}
updatePresets(true);
GeometryMetadata geo = mPreset.getGeometry();
mPreviousGeometry = new GeometryMetadata(geo);
}
- private void renderHistoryPreview() {
- ImagePreset historyPreset = mPreset;
- if (historyPreset != null) {
- Bitmap preview = mLoader.getOriginalBitmapSmall();
- if (preview != null) {
- float s = Math.min(preview.getWidth(), preview.getHeight());
- float f = sHistoryPreviewSize / s;
- int w = (int) (preview.getWidth() * f);
- int h = (int) (preview.getHeight() * f);
- Bitmap historyPreview = Bitmap.createScaledBitmap(preview, w, h, true);
- historyPreset.setPreviewImage(historyPreview);
- RenderingRequest.post(historyPreview,
- historyPreset, RenderingRequest.ICON_RENDERING, this);
- }
- }
- }
-
private void setGeometry() {
Bitmap image = mLoader.getOriginalBitmapLarge();
if (image == null) {
}
public void onHistoryItemClick(int position) {
- setPreset(new ImagePreset(mHistory.getItem(position)), false);
+ HistoryItem historyItem = mHistory.getItem(position);
// We need a copy from the history
+ ImagePreset newPreset = new ImagePreset(historyItem.getImagePreset());
+ // don't need to add it to the history
+ setPreset(newPreset, historyItem.getFilterRepresentation(), false);
mHistory.setCurrentPreset(position);
}
mHighresBitmap = request.getBitmap();
notifyObservers();
}
-
- if (request.getType() == RenderingRequest.ICON_RENDERING) {
- // History preview images
- ImagePreset preset = request.getOriginalImagePreset();
- preset.setPreviewImage(request.getBitmap());
- mHistory.notifyDataSetChanged();
- }
}
public static void reset() {
private static final String LOGTAG = "ImagePreset";
- public static final int STYLE_ICON = 3;
- public static final String PRESET_NAME = "PresetName";
-
private ImageLoader mImageLoader = null;
private Vector<FilterRepresentation> mFilters = new Vector<FilterRepresentation>();
- protected String mName = "Original";
- private String mHistoryName = "Original";
- protected boolean mIsFxPreset = false;
-
private boolean mDoApplyGeometry = true;
private boolean mDoApplyFilters = true;
private boolean mPartialRendering = false;
private Rect mPartialRenderingBounds;
private static final boolean DEBUG = false;
- private Bitmap mPreviewImage;
public ImagePreset() {
}
- public ImagePreset(String historyName) {
- setHistoryName(historyName);
- }
-
- public ImagePreset(ImagePreset source, String historyName) {
- this(source);
- if (historyName != null) {
- setHistoryName(historyName);
- }
- }
-
public ImagePreset(ImagePreset source) {
try {
for (int i = 0; i < source.mFilters.size(); i++) {
} catch (java.lang.CloneNotSupportedException e) {
Log.v(LOGTAG, "Exception trying to clone: " + e);
}
- mName = source.name();
- mHistoryName = source.name();
- mIsFxPreset = source.isFx();
mImageLoader = source.getImageLoader();
- mPreviewImage = source.getPreviewImage();
}
public FilterRepresentation getFilterRepresentation(int position) {
}
}
- public boolean isFx() {
- return mIsFxPreset;
- }
-
- public void setIsFx(boolean value) {
- mIsFxPreset = value;
- }
-
- public void setName(String name) {
- mName = name;
- mHistoryName = name;
- }
-
- public void setHistoryName(String name) {
- mHistoryName = name;
- }
-
public ImageLoader getImageLoader() {
return mImageLoader;
}
return false;
}
- if (!mName.equalsIgnoreCase(preset.name())) {
- return false;
- }
-
if (mDoApplyGeometry != preset.mDoApplyGeometry) {
return false;
}
return preset.mFilters.size();
}
- public String name() {
- return mName;
- }
-
- public String historyName() {
- return mHistoryName;
- }
-
public void showFilters() {
Log.v(LOGTAG, "\\\\\\ showFilters -- " + mFilters.size() + " filters");
int n = 0;
}
}
}
- setHistoryName("Remove");
}
public void addFilter(FilterRepresentation representation) {
if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
removeFilter(representation);
mFilters.add(representation);
- setHistoryName(representation.getName());
} else if (representation.getFilterType() == FilterRepresentation.TYPE_FX) {
boolean found = false;
for (int i = 0; i < mFilters.size(); i++) {
if (type == FilterRepresentation.TYPE_FX) {
mFilters.remove(i);
mFilters.add(i, representation);
- setHistoryName(representation.getName());
found = true;
}
}
if (!found) {
mFilters.add(representation);
- setHistoryName(representation.getName());
}
} else {
mFilters.add(representation);
- setHistoryName(representation.getName());
}
}
return mPartialRenderingBounds;
}
- public Bitmap getPreviewImage() {
- return mPreviewImage;
- }
-
- public void setPreviewImage(Bitmap previewImage) {
- mPreviewImage = previewImage;
- }
-
public Vector<ImageFilter> getUsedFilters(BaseFiltersManager filtersManager) {
Vector<ImageFilter> usedFilters = new Vector<ImageFilter>();
for (int i = 0; i < mFilters.size(); i++) {
int numFilters = mFilters.size();
try {
writer.beginObject();
- writer.name(PRESET_NAME).value(name);
GeometryMetadata geoData = getGeometry();
writer.name(geoData.getSerializationName());
writer.beginObject();
*/
public boolean readJson(JsonReader sreader) throws IOException {
sreader.beginObject();
- sreader.nextName();
- mName = sreader.nextString();
while (sreader.hasNext()) {
String name = sreader.nextName();