From 83b16cf2b02773370e00d3659e201efff20d788d Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Thu, 27 Jun 2013 14:12:17 -0700 Subject: Move history classes to their own package Change-Id: Ib4f50c56b445788cad3b973673008d8a89244867 --- .../gallery3d/filtershow/FilterShowActivity.java | 2 + .../gallery3d/filtershow/HistoryAdapter.java | 220 -------------------- .../android/gallery3d/filtershow/HistoryItem.java | 57 ------ .../gallery3d/filtershow/cache/ImageLoader.java | 2 +- .../gallery3d/filtershow/editors/EditorPanel.java | 2 +- .../filtershow/history/HistoryAdapter.java | 222 +++++++++++++++++++++ .../gallery3d/filtershow/history/HistoryItem.java | 57 ++++++ .../filtershow/imageshow/ImageGeometry.java | 2 +- .../filtershow/imageshow/MasterImage.java | 4 +- 9 files changed, 286 insertions(+), 282 deletions(-) delete mode 100644 src/com/android/gallery3d/filtershow/HistoryAdapter.java delete mode 100644 src/com/android/gallery3d/filtershow/HistoryItem.java create mode 100644 src/com/android/gallery3d/filtershow/history/HistoryAdapter.java create mode 100644 src/com/android/gallery3d/filtershow/history/HistoryItem.java diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index 863d2cb4f..89565711f 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -79,6 +79,8 @@ import com.android.gallery3d.filtershow.filters.FilterImageBorderRepresentation; import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.filters.FiltersManager; import com.android.gallery3d.filtershow.filters.ImageFilter; +import com.android.gallery3d.filtershow.history.HistoryAdapter; +import com.android.gallery3d.filtershow.history.HistoryItem; import com.android.gallery3d.filtershow.imageshow.GeometryMetadata; import com.android.gallery3d.filtershow.imageshow.ImageCrop; import com.android.gallery3d.filtershow.imageshow.ImageShow; diff --git a/src/com/android/gallery3d/filtershow/HistoryAdapter.java b/src/com/android/gallery3d/filtershow/HistoryAdapter.java deleted file mode 100644 index a6cd1a92c..000000000 --- a/src/com/android/gallery3d/filtershow/HistoryAdapter.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) 2012 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.content.Context; -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.drawable.Drawable; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; - -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.presets.ImagePreset; - -import java.util.Vector; - -public class HistoryAdapter extends ArrayAdapter { - private static final String LOGTAG = "HistoryAdapter"; - private int mCurrentPresetPosition = 0; - private String mBorders = null; - private String mCrop = null; - private String mRotate = null; - private String mStraighten = null; - private String mMirror = null; - private MenuItem mUndoMenuItem = null; - private MenuItem mRedoMenuItem = null; - private MenuItem mResetMenuItem = null; - - private Bitmap mOriginalBitmap = null; - - public HistoryAdapter(Context context, int resource, int textViewResourceId) { - super(context, resource, textViewResourceId); - FilterShowActivity activity = (FilterShowActivity) context; - mBorders = context.getString(R.string.borders); - mCrop = context.getString(R.string.crop); - mRotate = context.getString(R.string.rotate); - mStraighten = context.getString(R.string.straighten); - mMirror = context.getString(R.string.mirror); - } - - public void setMenuItems(MenuItem undoItem, MenuItem redoItem, MenuItem resetItem) { - mUndoMenuItem = undoItem; - mRedoMenuItem = redoItem; - mResetMenuItem = resetItem; - updateMenuItems(); - } - - public boolean canReset() { - if (getCount() <= 1) { - return false; - } - return true; - } - - public boolean canUndo() { - if (mCurrentPresetPosition == getCount() - 1) { - return false; - } - return true; - } - - public boolean canRedo() { - if (mCurrentPresetPosition == 0) { - return false; - } - return true; - } - - public void updateMenuItems() { - if (mUndoMenuItem != null) { - setEnabled(mUndoMenuItem, canUndo()); - } - if (mRedoMenuItem != null) { - setEnabled(mRedoMenuItem, canRedo()); - } - if (mResetMenuItem != null) { - setEnabled(mResetMenuItem, canReset()); - } - } - - private void setEnabled(MenuItem item, boolean enabled) { - item.setEnabled(enabled); - Drawable drawable = item.getIcon(); - if (drawable != null) { - drawable.setAlpha(enabled ? 255 : 80); - } - } - - public void setCurrentPreset(int n) { - mCurrentPresetPosition = n; - updateMenuItems(); - this.notifyDataSetChanged(); - } - - public void reset() { - if (getCount() == 0) { - return; - } - HistoryItem first = getItem(getCount() - 1); - clear(); - addHistoryItem(first); - updateMenuItems(); - } - - public HistoryItem getLast() { - if (getCount() == 0) { - return null; - } - return getItem(0); - } - - public HistoryItem getCurrent() { - return getItem(mCurrentPresetPosition); - } - - public void addHistoryItem(HistoryItem preset) { - insert(preset, 0); - updateMenuItems(); - } - - @Override - public void insert(HistoryItem preset, int position) { - if (mCurrentPresetPosition != 0) { - // in this case, let's discount the presets before the current one - Vector oldItems = new Vector(); - for (int i = mCurrentPresetPosition; i < getCount(); i++) { - oldItems.add(getItem(i)); - } - clear(); - for (int i = 0; i < oldItems.size(); i++) { - add(oldItems.elementAt(i)); - } - mCurrentPresetPosition = position; - this.notifyDataSetChanged(); - } - super.insert(preset, position); - mCurrentPresetPosition = position; - this.notifyDataSetChanged(); - } - - public int redo() { - mCurrentPresetPosition--; - if (mCurrentPresetPosition < 0) { - mCurrentPresetPosition = 0; - } - this.notifyDataSetChanged(); - updateMenuItems(); - return mCurrentPresetPosition; - } - - public int undo() { - mCurrentPresetPosition++; - if (mCurrentPresetPosition >= getCount()) { - mCurrentPresetPosition = getCount() - 1; - } - this.notifyDataSetChanged(); - updateMenuItems(); - return mCurrentPresetPosition; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View view = convertView; - if (view == null) { - LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.filtershow_history_operation_row, null); - } - - HistoryItem historyItem = getItem(position); - ImagePreset item = historyItem.getImagePreset(); - if (item != null) { - TextView itemView = (TextView) view.findViewById(R.id.rowTextView); - if (itemView != null && historyItem.getFilterRepresentation() != null) { - itemView.setText(historyItem.getFilterRepresentation().getName()); - } - ImageView preview = (ImageView) view.findViewById(R.id.preview); - Bitmap bmp = historyItem.getPreviewImage(); - if (position == getCount()-1 && mOriginalBitmap != null) { - bmp = mOriginalBitmap; - } - if (bmp != null) { - preview.setImageBitmap(bmp); - } else { - preview.setImageResource(android.R.color.transparent); - } - if (position == mCurrentPresetPosition) { - view.setBackgroundColor(Color.WHITE); - } else { - view.setBackgroundResource(R.color.background_main_toolbar); - } - } - - return view; - } - - - public void setOriginalBitmap(Bitmap originalBitmap) { - mOriginalBitmap = originalBitmap; - } -} diff --git a/src/com/android/gallery3d/filtershow/HistoryItem.java b/src/com/android/gallery3d/filtershow/HistoryItem.java deleted file mode 100644 index 7b1860903..000000000 --- a/src/com/android/gallery3d/filtershow/HistoryItem.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - } - -} diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java index 491340e0d..cf2cb908a 100644 --- a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java +++ b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java @@ -36,7 +36,7 @@ import com.android.gallery3d.R; import com.android.gallery3d.common.Utils; import com.android.gallery3d.exif.ExifInterface; import com.android.gallery3d.filtershow.FilterShowActivity; -import com.android.gallery3d.filtershow.HistoryAdapter; +import com.android.gallery3d.filtershow.history.HistoryAdapter; import com.android.gallery3d.filtershow.imageshow.ImageShow; import com.android.gallery3d.filtershow.imageshow.MasterImage; import com.android.gallery3d.filtershow.presets.ImagePreset; diff --git a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java index d06f30fe8..82e8aa220 100644 --- a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java +++ b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java @@ -28,7 +28,7 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; -import com.android.gallery3d.filtershow.HistoryAdapter; +import com.android.gallery3d.filtershow.history.HistoryAdapter; import com.android.gallery3d.filtershow.category.MainPanel; import com.android.gallery3d.filtershow.imageshow.MasterImage; import com.android.gallery3d.filtershow.state.StatePanel; diff --git a/src/com/android/gallery3d/filtershow/history/HistoryAdapter.java b/src/com/android/gallery3d/filtershow/history/HistoryAdapter.java new file mode 100644 index 000000000..81963a6a0 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/history/HistoryAdapter.java @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2012 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.history; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Color; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.history.HistoryItem; +import com.android.gallery3d.filtershow.presets.ImagePreset; + +import java.util.Vector; + +public class HistoryAdapter extends ArrayAdapter { + private static final String LOGTAG = "HistoryAdapter"; + private int mCurrentPresetPosition = 0; + private String mBorders = null; + private String mCrop = null; + private String mRotate = null; + private String mStraighten = null; + private String mMirror = null; + private MenuItem mUndoMenuItem = null; + private MenuItem mRedoMenuItem = null; + private MenuItem mResetMenuItem = null; + + private Bitmap mOriginalBitmap = null; + + public HistoryAdapter(Context context, int resource, int textViewResourceId) { + super(context, resource, textViewResourceId); + FilterShowActivity activity = (FilterShowActivity) context; + mBorders = context.getString(R.string.borders); + mCrop = context.getString(R.string.crop); + mRotate = context.getString(R.string.rotate); + mStraighten = context.getString(R.string.straighten); + mMirror = context.getString(R.string.mirror); + } + + public void setMenuItems(MenuItem undoItem, MenuItem redoItem, MenuItem resetItem) { + mUndoMenuItem = undoItem; + mRedoMenuItem = redoItem; + mResetMenuItem = resetItem; + updateMenuItems(); + } + + public boolean canReset() { + if (getCount() <= 1) { + return false; + } + return true; + } + + public boolean canUndo() { + if (mCurrentPresetPosition == getCount() - 1) { + return false; + } + return true; + } + + public boolean canRedo() { + if (mCurrentPresetPosition == 0) { + return false; + } + return true; + } + + public void updateMenuItems() { + if (mUndoMenuItem != null) { + setEnabled(mUndoMenuItem, canUndo()); + } + if (mRedoMenuItem != null) { + setEnabled(mRedoMenuItem, canRedo()); + } + if (mResetMenuItem != null) { + setEnabled(mResetMenuItem, canReset()); + } + } + + private void setEnabled(MenuItem item, boolean enabled) { + item.setEnabled(enabled); + Drawable drawable = item.getIcon(); + if (drawable != null) { + drawable.setAlpha(enabled ? 255 : 80); + } + } + + public void setCurrentPreset(int n) { + mCurrentPresetPosition = n; + updateMenuItems(); + this.notifyDataSetChanged(); + } + + public void reset() { + if (getCount() == 0) { + return; + } + HistoryItem first = getItem(getCount() - 1); + clear(); + addHistoryItem(first); + updateMenuItems(); + } + + public HistoryItem getLast() { + if (getCount() == 0) { + return null; + } + return getItem(0); + } + + public HistoryItem getCurrent() { + return getItem(mCurrentPresetPosition); + } + + public void addHistoryItem(HistoryItem preset) { + insert(preset, 0); + updateMenuItems(); + } + + @Override + public void insert(HistoryItem preset, int position) { + if (mCurrentPresetPosition != 0) { + // in this case, let's discount the presets before the current one + Vector oldItems = new Vector(); + for (int i = mCurrentPresetPosition; i < getCount(); i++) { + oldItems.add(getItem(i)); + } + clear(); + for (int i = 0; i < oldItems.size(); i++) { + add(oldItems.elementAt(i)); + } + mCurrentPresetPosition = position; + this.notifyDataSetChanged(); + } + super.insert(preset, position); + mCurrentPresetPosition = position; + this.notifyDataSetChanged(); + } + + public int redo() { + mCurrentPresetPosition--; + if (mCurrentPresetPosition < 0) { + mCurrentPresetPosition = 0; + } + this.notifyDataSetChanged(); + updateMenuItems(); + return mCurrentPresetPosition; + } + + public int undo() { + mCurrentPresetPosition++; + if (mCurrentPresetPosition >= getCount()) { + mCurrentPresetPosition = getCount() - 1; + } + this.notifyDataSetChanged(); + updateMenuItems(); + return mCurrentPresetPosition; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view = convertView; + if (view == null) { + LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( + Context.LAYOUT_INFLATER_SERVICE); + view = inflater.inflate(R.layout.filtershow_history_operation_row, null); + } + + HistoryItem historyItem = getItem(position); + ImagePreset item = historyItem.getImagePreset(); + if (item != null) { + TextView itemView = (TextView) view.findViewById(R.id.rowTextView); + if (itemView != null && historyItem.getFilterRepresentation() != null) { + itemView.setText(historyItem.getFilterRepresentation().getName()); + } + ImageView preview = (ImageView) view.findViewById(R.id.preview); + Bitmap bmp = historyItem.getPreviewImage(); + if (position == getCount()-1 && mOriginalBitmap != null) { + bmp = mOriginalBitmap; + } + if (bmp != null) { + preview.setImageBitmap(bmp); + } else { + preview.setImageResource(android.R.color.transparent); + } + if (position == mCurrentPresetPosition) { + view.setBackgroundColor(Color.WHITE); + } else { + view.setBackgroundResource(R.color.background_main_toolbar); + } + } + + return view; + } + + + public void setOriginalBitmap(Bitmap originalBitmap) { + mOriginalBitmap = originalBitmap; + } +} diff --git a/src/com/android/gallery3d/filtershow/history/HistoryItem.java b/src/com/android/gallery3d/filtershow/history/HistoryItem.java new file mode 100644 index 000000000..ed550985d --- /dev/null +++ b/src/com/android/gallery3d/filtershow/history/HistoryItem.java @@ -0,0 +1,57 @@ +/* + * 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.history; + +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; + } + +} diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java b/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java index 666186d81..15609139b 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java @@ -29,7 +29,7 @@ import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import com.android.gallery3d.filtershow.HistoryItem; +import com.android.gallery3d.filtershow.history.HistoryItem; import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.imageshow.GeometryMetadata.FLIP; import com.android.gallery3d.filtershow.presets.ImagePreset; diff --git a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java index c0d4601bc..3dc8302df 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java +++ b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java @@ -22,8 +22,8 @@ import android.os.Message; 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.history.HistoryAdapter; +import com.android.gallery3d.filtershow.history.HistoryItem; import com.android.gallery3d.filtershow.cache.*; import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.filters.ImageFilter; -- cgit v1.2.3