From edf4b095a1d904df6c02d49e3ec575c5c3c9c749 Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Fri, 13 Sep 2013 16:37:43 -0700 Subject: Fix various UX bugs - boolean filters (invert) working - default value for vignette - swappable views un-broken (use same mechanism as categories views) Change-Id: I65818c1febbf2c862e97542c8134a1188daf5d62 --- .../gallery3d/filtershow/FilterShowActivity.java | 23 +++++++ .../gallery3d/filtershow/category/Action.java | 13 ++++ .../filtershow/category/CategoryView.java | 15 ++++- .../filtershow/filters/FilterRepresentation.java | 14 +++- .../filters/FilterVignetteRepresentation.java | 2 +- .../filtershow/filters/ImageFilterNegative.java | 1 + .../filtershow/filters/ImageFilterWBalance.java | 1 + .../gallery3d/filtershow/state/StateView.java | 77 ++++++++++++++++------ 8 files changed, 123 insertions(+), 23 deletions(-) (limited to 'src/com') diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index e17fda5a4..74e2f9c91 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -90,6 +90,7 @@ import com.android.gallery3d.filtershow.editors.EditorRotate; import com.android.gallery3d.filtershow.editors.EditorStraighten; import com.android.gallery3d.filtershow.editors.EditorTinyPlanet; import com.android.gallery3d.filtershow.editors.ImageOnlyEditor; +import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation; import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation; @@ -473,8 +474,18 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL mCategoryGeometryAdapter.clear(); } mCategoryGeometryAdapter = new CategoryAdapter(this); + boolean found = false; for (FilterRepresentation representation : filtersRepresentations) { mCategoryGeometryAdapter.add(new Action(this, representation)); + if (representation instanceof FilterDrawRepresentation) { + found = true; + } + } + if (!found) { + FilterRepresentation representation = new FilterDrawRepresentation(); + Action action = new Action(this, representation); + action.setIsDoubleAction(true); + mCategoryGeometryAdapter.add(action); } } @@ -656,6 +667,18 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL FilterMirrorRepresentation r = (FilterMirrorRepresentation) representation; r.cycle(); } + if (representation.isBooleanFilter()) { + ImagePreset preset = MasterImage.getImage().getPreset(); + if (preset.getRepresentation(representation) != null) { + // remove + ImagePreset copy = new ImagePreset(preset); + copy.removeFilter(representation); + FilterRepresentation filterRepresentation = representation.copy(); + MasterImage.getImage().setPreset(copy, filterRepresentation, true); + MasterImage.getImage().setCurrentFilterRepresentation(null); + return; + } + } useFilterRepresentation(representation); // show representation diff --git a/src/com/android/gallery3d/filtershow/category/Action.java b/src/com/android/gallery3d/filtershow/category/Action.java index b3f35dab9..ef13ea53b 100644 --- a/src/com/android/gallery3d/filtershow/category/Action.java +++ b/src/com/android/gallery3d/filtershow/category/Action.java @@ -30,6 +30,7 @@ import android.widget.ListAdapter; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation; import com.android.gallery3d.filtershow.pipeline.RenderingRequest; import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller; @@ -55,6 +56,7 @@ public class Action implements RenderingRequestCaller { private FilterShowActivity mContext; private boolean mCanBeRemoved = false; private int mTextSize = 32; + private boolean mIsDoubleAction = false; public Action(FilterShowActivity context, FilterRepresentation representation, int type, boolean canBeRemoved) { @@ -79,6 +81,14 @@ public class Action implements RenderingRequestCaller { this(context, representation, CROP_VIEW); } + public boolean isDoubleAction() { + return mIsDoubleAction; + } + + public void setIsDoubleAction(boolean value) { + mIsDoubleAction = value; + } + public boolean canBeRemoved() { return mCanBeRemoved; } @@ -94,6 +104,9 @@ public class Action implements RenderingRequestCaller { public void setRepresentation(FilterRepresentation representation) { mRepresentation = representation; mName = representation.getName(); + if (mRepresentation instanceof FilterDrawRepresentation) { + setIsDoubleAction(true); + } } public String getName() { diff --git a/src/com/android/gallery3d/filtershow/category/CategoryView.java b/src/com/android/gallery3d/filtershow/category/CategoryView.java index 22c50fd96..8dfe92f49 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryView.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryView.java @@ -49,6 +49,8 @@ public class CategoryView extends IconView private int mSelectionColor = Color.WHITE; private int mSpacerColor = Color.WHITE; private boolean mCanBeRemoved = false; + private long mDoubleActionLast = 0; + private long mDoubleTapDelay = 150; public CategoryView(Context context) { super(context); @@ -109,6 +111,9 @@ public class CategoryView extends IconView drawSpacer(canvas); return; } + if (mAction.isDoubleAction()) { + return; + } mAction.setImageFrame(new Rect(0, 0, getWidth(), getHeight()), getOrientation()); if (mAction.getImage() != null) { setBitmap(mAction.getImage()); @@ -145,7 +150,15 @@ public class CategoryView extends IconView if (mAction.getType() == Action.ADD_ACTION) { activity.addNewPreset(); } else if (mAction.getType() != Action.SPACER) { - activity.showRepresentation(mAction.getRepresentation()); + if (mAction.isDoubleAction()) { + long current = System.currentTimeMillis() - mDoubleActionLast; + if (current < mDoubleTapDelay) { + activity.showRepresentation(mAction.getRepresentation()); + } + mDoubleActionLast = System.currentTimeMillis(); + } else { + activity.showRepresentation(mAction.getRepresentation()); + } mAdapter.setSelected(this); } } diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java index cc7ec881e..fc83e4f8c 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java @@ -38,6 +38,7 @@ public class FilterRepresentation { private int mOverlayId = 0; private boolean mOverlayOnly = false; private boolean mShowParameterValue = true; + private boolean mIsBooleanFilter = false; private String mSerializationName; public static final byte TYPE_BORDER = 1; public static final byte TYPE_FX = 2; @@ -69,7 +70,7 @@ public class FilterRepresentation { representation.setOverlayOnly(getOverlayOnly()); representation.setShowParameterValue(showParameterValue()); representation.mSerializationName = mSerializationName; - + representation.setIsBooleanFilter(isBooleanFilter()); } public boolean equals(FilterRepresentation representation) { @@ -87,12 +88,21 @@ public class FilterRepresentation { && representation.mButtonId == mButtonId && representation.mOverlayId == mOverlayId && representation.mOverlayOnly == mOverlayOnly - && representation.mShowParameterValue == mShowParameterValue) { + && representation.mShowParameterValue == mShowParameterValue + && representation.mIsBooleanFilter == mIsBooleanFilter) { return true; } return false; } + public boolean isBooleanFilter() { + return mIsBooleanFilter; + } + + public void setIsBooleanFilter(boolean value) { + mIsBooleanFilter = value; + } + @Override public String toString() { return mName; diff --git a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java index 2e362f8b5..d316adeed 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java @@ -43,7 +43,7 @@ public class FilterVignetteRepresentation extends FilterRepresentation implement private static int MAX = 100; private static int MAXFALLOF = 200; - private BasicParameterInt mParamVignette = new BasicParameterInt(MODE_VIGNETTE, 0, MIN, MAX); + private BasicParameterInt mParamVignette = new BasicParameterInt(MODE_VIGNETTE, 50, MIN, MAX); private BasicParameterInt mParamExposure = new BasicParameterInt(MODE_EXPOSURE, 0, MIN, MAX); private BasicParameterInt mParamSaturation = new BasicParameterInt(MODE_SATURATION, 0, MIN, MAX); private BasicParameterInt mParamContrast = new BasicParameterInt(MODE_CONTRAST, 0, MIN, MAX); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java index 98497596b..9a1a84030 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java @@ -19,6 +19,7 @@ public class ImageFilterNegative extends ImageFilter { representation.setShowParameterValue(false); representation.setEditorId(ImageOnlyEditor.ID); representation.setSupportsPartialRendering(true); + representation.setIsBooleanFilter(true); return representation; } diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java index 6bb88ec21..7aa19a4a9 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java @@ -38,6 +38,7 @@ public class ImageFilterWBalance extends ImageFilter { representation.setShowParameterValue(false); representation.setEditorId(ImageOnlyEditor.ID); representation.setSupportsPartialRendering(true); + representation.setIsBooleanFilter(true); return representation; } diff --git a/src/com/android/gallery3d/filtershow/state/StateView.java b/src/com/android/gallery3d/filtershow/state/StateView.java index 73d57846a..7d209ba89 100644 --- a/src/com/android/gallery3d/filtershow/state/StateView.java +++ b/src/com/android/gallery3d/filtershow/state/StateView.java @@ -27,9 +27,12 @@ import android.view.ViewParent; import android.widget.LinearLayout; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.category.SwipableView; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.imageshow.MasterImage; +import com.android.gallery3d.filtershow.pipeline.ImagePreset; -public class StateView extends View { +public class StateView extends View implements SwipableView { private static final String LOGTAG = "StateView"; private Path mPath = new Path(); @@ -51,6 +54,10 @@ public class StateView extends View { private static int sMargin = 16; private static int sArrowHeight = 16; private static int sArrowWidth = 8; + private float mStartTouchX = 0; + private float mStartTouchY = 0; + private float mDeleteSlope = 20; + private int mOrientation = LinearLayout.VERTICAL; private int mDirection = DOWN; private boolean mDuplicateButton; @@ -104,24 +111,6 @@ public class StateView extends View { invalidate(); } - @Override - public boolean onTouchEvent(MotionEvent event) { - if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { - ViewParent parent = getParent(); - if (parent instanceof PanelTrack) { - ((PanelTrack) getParent()).onTouch(event, this); - } - if (mType == BEGIN) { - MasterImage.getImage().setShowsOriginal(true); - } - } - if (event.getActionMasked() == MotionEvent.ACTION_UP - || event.getActionMasked() == MotionEvent.ACTION_CANCEL) { - MasterImage.getImage().setShowsOriginal(false); - } - return true; - } - public void drawText(Canvas canvas) { if (mText == null) { return; @@ -288,4 +277,54 @@ public class StateView extends View { public boolean isDraggable() { return mState.isDraggable(); } + + @Override + public void delete() { + FilterShowActivity activity = (FilterShowActivity) getContext(); + FilterRepresentation representation = getState().getFilterRepresentation(); + activity.removeFilterRepresentation(representation); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + boolean ret = super.onTouchEvent(event); + FilterShowActivity activity = (FilterShowActivity) getContext(); + + if (event.getActionMasked() == MotionEvent.ACTION_UP) { + activity.startTouchAnimation(this, event.getX(), event.getY()); + } + if (mType == BEGIN) { + return ret; + } + if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { + mStartTouchY = event.getY(); + mStartTouchX = event.getX(); + if (mType == BEGIN) { + MasterImage.getImage().setShowsOriginal(true); + } + } + if (event.getActionMasked() == MotionEvent.ACTION_UP) { + setTranslationX(0); + setTranslationY(0); + MasterImage.getImage().setShowsOriginal(false); + setSelected(true); + FilterRepresentation representation = getState().getFilterRepresentation(); + MasterImage image = MasterImage.getImage(); + ImagePreset preset = image != null ? image.getCurrentPreset() : null; + if (getTranslationY() == 0 + && image != null && preset != null + && representation != image.getCurrentFilterRepresentation() + && preset.getRepresentation(representation) != null) { + activity.showRepresentation(representation); + setSelected(false); + } + } + if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { + float delta = event.getY() - mStartTouchY; + if (Math.abs(delta) > mDeleteSlope) { + activity.setHandlesSwipeForView(this, mStartTouchX, mStartTouchY); + } + } + return true; + } } -- cgit v1.2.3