import android.content.Context;
import android.view.LayoutInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
public class HistoryAdapter extends ArrayAdapter<ImagePreset> {
private static final String LOGTAG = "HistoryAdapter";
private int mCurrentPresetPosition = 0;
+ private MenuItem mUndoMenuItem = null;
+ private MenuItem mRedoMenuItem = null;
+ private MenuItem mResetMenuItem = null;
+
+ public HistoryAdapter(Context context, int resource, int textViewResourceId) {
+ super(context, resource, textViewResourceId);
+ FilterShowActivity activity = (FilterShowActivity) context;
+ }
+
+ 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) {
+ mUndoMenuItem.setEnabled(canUndo());
+ }
+ if (mRedoMenuItem != null) {
+ mRedoMenuItem.setEnabled(canRedo());
+ }
+ if (mResetMenuItem != null) {
+ mResetMenuItem.setEnabled(canReset());
+ }
+ }
public void setCurrentPreset(int n) {
mCurrentPresetPosition = n;
+ updateMenuItems();
this.notifyDataSetChanged();
}
- public HistoryAdapter(Context context, int resource, int textViewResourceId) {
- super(context, resource, textViewResourceId);
- }
-
public void reset() {
if (getCount() == 0) {
return;
ImagePreset first = getItem(getCount() - 1);
clear();
addHistoryItem(first);
+ updateMenuItems();
}
public ImagePreset getLast() {
public void addHistoryItem(ImagePreset preset) {
if (canAddHistoryItem(preset)) {
insert(preset, 0);
+ updateMenuItems();
}
}
mCurrentPresetPosition = 0;
}
this.notifyDataSetChanged();
+ updateMenuItems();
return mCurrentPresetPosition;
}
mCurrentPresetPosition = getCount() - 1;
}
this.notifyDataSetChanged();
+ updateMenuItems();
return mCurrentPresetPosition;
}