summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-06-27 14:41:58 -0700
committernicolasroard <nicolasroard@google.com>2013-06-27 15:26:51 -0700
commit39f4ad6d7e663778d74a47c8b25768c4f221fbdc (patch)
tree2bf08c5779e234202265e8e0a15977fabc6ac0a7 /src
parentdfaf4c5b5b901dbbd4904fd86995b71f4acfd47c (diff)
downloadandroid_packages_apps_Snap-39f4ad6d7e663778d74a47c8b25768c4f221fbdc.zip
android_packages_apps_Snap-39f4ad6d7e663778d74a47c8b25768c4f221fbdc.tar.gz
android_packages_apps_Snap-39f4ad6d7e663778d74a47c8b25768c4f221fbdc.tar.bz2
Refactor HistoryAdapter
- Remove the adapter part - Rename into HistoryManager Change-Id: I58de5661770f8796882ff4a633aec700bd8bc1a5
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java17
-rw-r--r--src/com/android/gallery3d/filtershow/cache/ImageLoader.java12
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorPanel.java4
-rw-r--r--src/com/android/gallery3d/filtershow/history/HistoryManager.java (renamed from src/com/android/gallery3d/filtershow/history/HistoryAdapter.java)114
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/MasterImage.java8
5 files changed, 51 insertions, 104 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index cab1af3..f87df71 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -79,7 +79,7 @@ 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.HistoryManager;
import com.android.gallery3d.filtershow.history.HistoryItem;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
import com.android.gallery3d.filtershow.imageshow.ImageCrop;
@@ -262,7 +262,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
public void setupStatePanel() {
- mImageLoader.setAdapter(mMasterImage.getHistory());
+ mImageLoader.setHistoryManager(mMasterImage.getHistory());
}
private void fillFilters() {
@@ -772,7 +772,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.undoButton: {
- HistoryAdapter adapter = mMasterImage.getHistory();
+ HistoryManager adapter = mMasterImage.getHistory();
int position = adapter.undo();
mMasterImage.onHistoryItemClick(position);
backToMain();
@@ -782,7 +782,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
return true;
}
case R.id.redoButton: {
- HistoryAdapter adapter = mMasterImage.getHistory();
+ HistoryManager adapter = mMasterImage.getHistory();
int position = adapter.redo();
mMasterImage.onHistoryItemClick(position);
invalidateViews();
@@ -894,14 +894,11 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
public void setupMasterImage() {
mImageLoader = new ImageLoader(this, getApplicationContext());
- HistoryAdapter mHistoryAdapter = new HistoryAdapter(
- this, R.layout.filtershow_history_operation_row,
- R.id.rowTextView);
-
+ HistoryManager mHistoryManager = new HistoryManager();
StateAdapter mImageStateAdapter = new StateAdapter(this, 0);
MasterImage.reset();
mMasterImage = MasterImage.getImage();
- mMasterImage.setHistoryAdapter(mHistoryAdapter);
+ mMasterImage.setHistoryManager(mHistoryManager);
mMasterImage.setStateAdapter(mImageStateAdapter);
mMasterImage.setActivity(this);
mMasterImage.setImageLoader(mImageLoader);
@@ -914,7 +911,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
void resetHistory() {
- HistoryAdapter adapter = mMasterImage.getHistory();
+ HistoryManager adapter = mMasterImage.getHistory();
adapter.reset();
HistoryItem historyItem = adapter.getItem(0);
ImagePreset original = new ImagePreset(historyItem.getImagePreset());
diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
index cf2cb90..8513b1c 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.history.HistoryAdapter;
+import com.android.gallery3d.filtershow.history.HistoryManager;
import com.android.gallery3d.filtershow.imageshow.ImageShow;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
import com.android.gallery3d.filtershow.presets.ImagePreset;
@@ -62,7 +62,7 @@ public class ImageLoader {
private Bitmap mBackgroundBitmap = null;
private int mOrientation = 0;
- private HistoryAdapter mAdapter = null;
+ private HistoryManager mHistoryManager = null;
private FilterShowActivity mActivity = null;
@@ -501,12 +501,12 @@ public class ImageLoader {
return bmap;
}
- public void setAdapter(HistoryAdapter adapter) {
- mAdapter = adapter;
+ public void setHistoryManager(HistoryManager historyManager) {
+ mHistoryManager = historyManager;
}
- public HistoryAdapter getHistory() {
- return mAdapter;
+ public HistoryManager getHistory() {
+ return mHistoryManager;
}
public XMPMeta getXmpObject() {
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java
index 82e8aa2..40dfccd 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.history.HistoryAdapter;
+import com.android.gallery3d.filtershow.history.HistoryManager;
import com.android.gallery3d.filtershow.category.MainPanel;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
import com.android.gallery3d.filtershow.state.StatePanel;
@@ -54,7 +54,7 @@ public class EditorPanel extends Fragment {
public void cancelCurrentFilter() {
MasterImage masterImage = MasterImage.getImage();
- HistoryAdapter adapter = masterImage.getHistory();
+ HistoryManager adapter = masterImage.getHistory();
int position = adapter.undo();
masterImage.onHistoryItemClick(position);
diff --git a/src/com/android/gallery3d/filtershow/history/HistoryAdapter.java b/src/com/android/gallery3d/filtershow/history/HistoryManager.java
index 81963a6..755e2ea 100644
--- a/src/com/android/gallery3d/filtershow/history/HistoryAdapter.java
+++ b/src/com/android/gallery3d/filtershow/history/HistoryManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 The Android Open Source Project
+ * 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.
@@ -16,49 +16,20 @@
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<HistoryItem> {
- private static final String LOGTAG = "HistoryAdapter";
+public class HistoryManager {
+ private static final String LOGTAG = "HistoryManager";
+
+ private Vector<HistoryItem> mHistoryItems = new Vector<HistoryItem>();
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;
@@ -66,6 +37,26 @@ public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
updateMenuItems();
}
+ private int getCount() {
+ return mHistoryItems.size();
+ }
+
+ public HistoryItem getItem(int position) {
+ return mHistoryItems.elementAt(position);
+ }
+
+ private void clear() {
+ mHistoryItems.clear();
+ }
+
+ private void add(HistoryItem item) {
+ mHistoryItems.add(item);
+ }
+
+ private void notifyDataSetChanged() {
+ // TODO
+ }
+
public boolean canReset() {
if (getCount() <= 1) {
return false;
@@ -110,7 +101,7 @@ public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
public void setCurrentPreset(int n) {
mCurrentPresetPosition = n;
updateMenuItems();
- this.notifyDataSetChanged();
+ notifyDataSetChanged();
}
public void reset() {
@@ -139,8 +130,7 @@ public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
updateMenuItems();
}
- @Override
- public void insert(HistoryItem preset, int position) {
+ private void insert(HistoryItem preset, int position) {
if (mCurrentPresetPosition != 0) {
// in this case, let's discount the presets before the current one
Vector<HistoryItem> oldItems = new Vector<HistoryItem>();
@@ -152,11 +142,11 @@ public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
add(oldItems.elementAt(i));
}
mCurrentPresetPosition = position;
- this.notifyDataSetChanged();
+ notifyDataSetChanged();
}
- super.insert(preset, position);
+ mHistoryItems.insertElementAt(preset, position);
mCurrentPresetPosition = position;
- this.notifyDataSetChanged();
+ notifyDataSetChanged();
}
public int redo() {
@@ -164,7 +154,7 @@ public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
if (mCurrentPresetPosition < 0) {
mCurrentPresetPosition = 0;
}
- this.notifyDataSetChanged();
+ notifyDataSetChanged();
updateMenuItems();
return mCurrentPresetPosition;
}
@@ -174,49 +164,9 @@ public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
if (mCurrentPresetPosition >= getCount()) {
mCurrentPresetPosition = getCount() - 1;
}
- this.notifyDataSetChanged();
+ 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/imageshow/MasterImage.java b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
index 53e38f4..56c4a62 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
@@ -25,7 +25,7 @@ import android.os.Handler;
import android.os.Message;
import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.history.HistoryAdapter;
+import com.android.gallery3d.filtershow.history.HistoryManager;
import com.android.gallery3d.filtershow.history.HistoryItem;
import com.android.gallery3d.filtershow.cache.FilteringPipeline;
import com.android.gallery3d.filtershow.cache.ImageLoader;
@@ -64,7 +64,7 @@ public class MasterImage implements RenderingRequestCaller {
private Bitmap mHighresBitmap = null;
private ImageLoader mLoader = null;
- private HistoryAdapter mHistory = null;
+ private HistoryManager mHistory = null;
private StateAdapter mState = null;
private FilterShowActivity mActivity = null;
@@ -198,7 +198,7 @@ public class MasterImage implements RenderingRequestCaller {
mHistory.setCurrentPreset(position);
}
- public HistoryAdapter getHistory() {
+ public HistoryManager getHistory() {
return mHistory;
}
@@ -206,7 +206,7 @@ public class MasterImage implements RenderingRequestCaller {
return mState;
}
- public void setHistoryAdapter(HistoryAdapter adapter) {
+ public void setHistoryManager(HistoryManager adapter) {
mHistory = adapter;
}