diff options
Diffstat (limited to 'src/com/android/gallery3d/filtershow/editors')
19 files changed, 2452 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/filtershow/editors/BasicEditor.java b/src/com/android/gallery3d/filtershow/editors/BasicEditor.java new file mode 100644 index 000000000..af694d811 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/BasicEditor.java @@ -0,0 +1,138 @@ +/* + * 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.editors; + +import android.content.Context; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.controller.Control; +import com.android.gallery3d.filtershow.controller.FilterView; +import com.android.gallery3d.filtershow.controller.Parameter; +import com.android.gallery3d.filtershow.controller.ParameterInteger; +import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; + + +/** + * The basic editor that all the one parameter filters + */ +public class BasicEditor extends ParametricEditor implements ParameterInteger { + public static int ID = R.id.basicEditor; + private final String LOGTAG = "BasicEditor"; + + public BasicEditor() { + super(ID, R.layout.filtershow_default_editor, R.id.basicEditor); + } + + protected BasicEditor(int id) { + super(id, R.layout.filtershow_default_editor, R.id.basicEditor); + } + + protected BasicEditor(int id, int layoutID, int viewID) { + super(id, layoutID, viewID); + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + if (getLocalRepresentation() != null && getLocalRepresentation() instanceof FilterBasicRepresentation) { + FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation(); + updateText(); + } + } + + private FilterBasicRepresentation getBasicRepresentation() { + FilterRepresentation tmpRep = getLocalRepresentation(); + if (tmpRep != null && tmpRep instanceof FilterBasicRepresentation) { + return (FilterBasicRepresentation) tmpRep; + + } + return null; + } + + @Override + public int getMaximum() { + FilterBasicRepresentation rep = getBasicRepresentation(); + if (rep == null) { + return 0; + } + return rep.getMaximum(); + } + + @Override + public int getMinimum() { + FilterBasicRepresentation rep = getBasicRepresentation(); + if (rep == null) { + return 0; + } + return rep.getMinimum(); + } + + @Override + public int getDefaultValue() { + return 0; + } + + @Override + public int getValue() { + FilterBasicRepresentation rep = getBasicRepresentation(); + if (rep == null) { + return 0; + } + return rep.getValue(); + } + + @Override + public String getValueString() { + return null; + } + + @Override + public void setValue(int value) { + FilterBasicRepresentation rep = getBasicRepresentation(); + if (rep == null) { + return; + } + rep.setValue(value); + commitLocalRepresentation(); + } + + @Override + public String getParameterName() { + FilterBasicRepresentation rep = getBasicRepresentation(); + return mContext.getString(rep.getTextId()); + } + + @Override + public String getParameterType() { + return sParameterType; + } + + @Override + public void setController(Control c) { + } + + @Override + public void setFilterView(FilterView editor) { + + } + + @Override + public void copyFrom(Parameter src) { + + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/Editor.java b/src/com/android/gallery3d/filtershow/editors/Editor.java new file mode 100644 index 000000000..a9e56e0c1 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/Editor.java @@ -0,0 +1,330 @@ +/* + * 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.editors; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.PopupMenu; +import android.widget.SeekBar; +import android.widget.SeekBar.OnSeekBarChangeListener; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.controller.Control; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageShow; +import com.android.gallery3d.filtershow.imageshow.MasterImage; +import com.android.gallery3d.filtershow.pipeline.ImagePreset; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Base class for Editors Must contain a mImageShow and a top level view + */ +public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonListener { + protected Context mContext; + protected View mView; + protected ImageShow mImageShow; + protected FrameLayout mFrameLayout; + protected SeekBar mSeekBar; + Button mEditTitle; + protected Button mFilterTitle; + protected int mID; + private final String LOGTAG = "Editor"; + protected boolean mChangesGeometry = false; + protected FilterRepresentation mLocalRepresentation = null; + protected byte mShowParameter = SHOW_VALUE_UNDEFINED; + private Button mButton; + public static byte SHOW_VALUE_UNDEFINED = -1; + public static byte SHOW_VALUE_OFF = 0; + public static byte SHOW_VALUE_INT = 1; + + public static void hackFixStrings(Menu menu) { + int count = menu.size(); + for (int i = 0; i < count; i++) { + MenuItem item = menu.getItem(i); + item.setTitle(item.getTitle().toString().toUpperCase()); + } + } + + public String calculateUserMessage(Context context, String effectName, Object parameterValue) { + return effectName.toUpperCase() + " " + parameterValue; + } + + protected Editor(int id) { + mID = id; + } + + public int getID() { + return mID; + } + + public byte showParameterValue() { + return mShowParameter; + } + + public boolean showsSeekBar() { + return true; + } + + public void setUpEditorUI(View actionButton, View editControl, + Button editTitle, Button stateButton) { + mEditTitle = editTitle; + mFilterTitle = stateButton; + mButton = editTitle; + setMenuIcon(true); + setUtilityPanelUI(actionButton, editControl); + } + + public boolean showsPopupIndicator() { + return true; + } + + /** + * @param actionButton the would be the area for menu etc + * @param editControl this is the black area for sliders etc + */ + public void setUtilityPanelUI(View actionButton, View editControl) { + + AttributeSet aset; + Context context = editControl.getContext(); + LayoutInflater inflater = + (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LinearLayout lp = (LinearLayout) inflater.inflate( + R.layout.filtershow_seekbar, (ViewGroup) editControl, true); + mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar); + mSeekBar.setOnSeekBarChangeListener(this); + + if (showsSeekBar()) { + mSeekBar.setOnSeekBarChangeListener(this); + mSeekBar.setVisibility(View.VISIBLE); + } else { + mSeekBar.setVisibility(View.INVISIBLE); + } + + if (mButton != null) { + if (showsPopupIndicator()) { + mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, + R.drawable.filtershow_menu_marker, 0); + } else { + mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0); + } + } + } + + @Override + public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { + + } + + public void setPanel() { + + } + + public void createEditor(Context context,FrameLayout frameLayout) { + mContext = context; + mFrameLayout = frameLayout; + mLocalRepresentation = null; + } + + protected void unpack(int viewid, int layoutid) { + + if (mView == null) { + mView = mFrameLayout.findViewById(viewid); + if (mView == null) { + LayoutInflater inflater = (LayoutInflater) mContext.getSystemService + (Context.LAYOUT_INFLATER_SERVICE); + mView = inflater.inflate(layoutid, mFrameLayout, false); + mFrameLayout.addView(mView, mView.getLayoutParams()); + } + } + mImageShow = findImageShow(mView); + } + + private ImageShow findImageShow(View view) { + if (view instanceof ImageShow) { + return (ImageShow) view; + } + if (!(view instanceof ViewGroup)) { + return null; + } + ViewGroup vg = (ViewGroup) view; + int n = vg.getChildCount(); + for (int i = 0; i < n; i++) { + View v = vg.getChildAt(i); + if (v instanceof ImageShow) { + return (ImageShow) v; + } else if (v instanceof ViewGroup) { + return findImageShow(v); + } + } + return null; + } + + public View getTopLevelView() { + return mView; + } + + public ImageShow getImageShow() { + return mImageShow; + } + + public void setVisibility(int visible) { + mView.setVisibility(visible); + } + + public FilterRepresentation getLocalRepresentation() { + if (mLocalRepresentation == null) { + ImagePreset preset = MasterImage.getImage().getPreset(); + FilterRepresentation filterRepresentation = MasterImage.getImage().getCurrentFilterRepresentation(); + mLocalRepresentation = preset.getFilterRepresentationCopyFrom(filterRepresentation); + if (mShowParameter == SHOW_VALUE_UNDEFINED && filterRepresentation != null) { + boolean show = filterRepresentation.showParameterValue(); + mShowParameter = show ? SHOW_VALUE_INT : SHOW_VALUE_OFF; + } + + } + return mLocalRepresentation; + } + + /** + * Call this to update the preset in MasterImage with the current representation + * returned by getLocalRepresentation. This causes the preview bitmap to be + * regenerated. + */ + public void commitLocalRepresentation() { + commitLocalRepresentation(getLocalRepresentation()); + } + + /** + * Call this to update the preset in MasterImage with a given representation. + * This causes the preview bitmap to be regenerated. + */ + public void commitLocalRepresentation(FilterRepresentation rep) { + ArrayList<FilterRepresentation> filter = new ArrayList<FilterRepresentation>(1); + filter.add(rep); + commitLocalRepresentation(filter); + } + + /** + * Call this to update the preset in MasterImage with a collection of FilterRepresnations. + * This causes the preview bitmap to be regenerated. + */ + public void commitLocalRepresentation(Collection<FilterRepresentation> reps) { + ImagePreset preset = MasterImage.getImage().getPreset(); + preset.updateFilterRepresentations(reps); + if (mButton != null) { + updateText(); + } + if (mChangesGeometry) { + // Regenerate both the filtered and the geometry-only bitmaps + MasterImage.getImage().updatePresets(true); + } else { + // Regenerate only the filtered bitmap. + MasterImage.getImage().invalidateFiltersOnly(); + } + preset.fillImageStateAdapter(MasterImage.getImage().getState()); + } + + /** + * This is called in response to a click to apply and leave the editor. + */ + public void finalApplyCalled() { + commitLocalRepresentation(); + } + + protected void updateText() { + String s = ""; + if (mLocalRepresentation != null) { + s = mContext.getString(mLocalRepresentation.getTextId()); + } + mButton.setText(calculateUserMessage(mContext, s, "")); + } + + /** + * called after the filter is set and the select is called + */ + public void reflectCurrentFilter() { + mLocalRepresentation = null; + FilterRepresentation representation = getLocalRepresentation(); + if (representation != null && mFilterTitle != null && representation.getTextId() != 0) { + String text = mContext.getString(representation.getTextId()).toUpperCase(); + mFilterTitle.setText(text); + updateText(); + } + } + + public boolean useUtilityPanel() { + return true; + } + + public void openUtilityPanel(LinearLayout mAccessoryViewList) { + setMenuIcon(false); + if (mImageShow != null) { + mImageShow.openUtilityPanel(mAccessoryViewList); + } + } + + protected void setMenuIcon(boolean on) { + mEditTitle.setCompoundDrawablesRelativeWithIntrinsicBounds( + 0, 0, on ? R.drawable.filtershow_menu_marker : 0, 0); + } + + protected void createMenu(int[] strId, View button) { + PopupMenu pmenu = new PopupMenu(mContext, button); + Menu menu = pmenu.getMenu(); + for (int i = 0; i < strId.length; i++) { + menu.add(Menu.NONE, Menu.FIRST + i, 0, mContext.getString(strId[i])); + } + setMenuIcon(true); + + } + + public Control[] getControls() { + return null; + } + @Override + public void onStartTrackingTouch(SeekBar arg0) { + + } + + @Override + public void onStopTrackingTouch(SeekBar arg0) { + + } + + @Override + public void swapLeft(MenuItem item) { + + } + + @Override + public void swapRight(MenuItem item) { + + } + + public void detach() { + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java b/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java new file mode 100644 index 000000000..7e31f09ae --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java @@ -0,0 +1,227 @@ +/* + * 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.editors; + +import android.content.Context; +import android.graphics.Bitmap; +import android.os.Handler; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.LinearLayout; +import android.widget.PopupMenu; +import android.widget.SeekBar.OnSeekBarChangeListener; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.controller.BasicParameterStyle; +import com.android.gallery3d.filtershow.controller.FilterView; +import com.android.gallery3d.filtershow.controller.Parameter; +import com.android.gallery3d.filtershow.filters.FilterChanSatRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.MasterImage; +import com.android.gallery3d.filtershow.pipeline.ImagePreset; +import com.android.gallery3d.filtershow.pipeline.RenderingRequest; +import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller; + +public class EditorChanSat extends ParametricEditor implements OnSeekBarChangeListener, FilterView { + public static final int ID = R.id.editorChanSat; + private final String LOGTAG = "EditorGrunge"; + private SwapButton mButton; + private final Handler mHandler = new Handler(); + + int[] mMenuStrings = { + R.string.editor_chan_sat_main, + R.string.editor_chan_sat_red, + R.string.editor_chan_sat_yellow, + R.string.editor_chan_sat_green, + R.string.editor_chan_sat_cyan, + R.string.editor_chan_sat_blue, + R.string.editor_chan_sat_magenta + }; + + String mCurrentlyEditing = null; + + public EditorChanSat() { + super(ID, R.layout.filtershow_default_editor, R.id.basicEditor); + } + + @Override + public String calculateUserMessage(Context context, String effectName, Object parameterValue) { + FilterRepresentation rep = getLocalRepresentation(); + if (rep == null || !(rep instanceof FilterChanSatRepresentation)) { + return ""; + } + FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep; + int mode = csrep.getParameterMode(); + String paramString; + + paramString = mContext.getString(mMenuStrings[mode]); + + int val = csrep.getCurrentParameter(); + return paramString + ((val > 0) ? " +" : " ") + val; + } + + @Override + public void openUtilityPanel(final LinearLayout accessoryViewList) { + mButton = (SwapButton) accessoryViewList.findViewById(R.id.applyEffect); + mButton.setText(mContext.getString(R.string.editor_chan_sat_main)); + + final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), mButton); + + popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_chan_sat, popupMenu.getMenu()); + + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + selectMenuItem(item); + return true; + } + }); + mButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + popupMenu.show(); + } + }); + mButton.setListener(this); + + FilterChanSatRepresentation csrep = getChanSatRep(); + String menuString = mContext.getString(mMenuStrings[0]); + switchToMode(csrep, FilterChanSatRepresentation.MODE_MASTER, menuString); + + } + + public int getParameterIndex(int id) { + switch (id) { + case R.id.editor_chan_sat_main: + return FilterChanSatRepresentation.MODE_MASTER; + case R.id.editor_chan_sat_red: + return FilterChanSatRepresentation.MODE_RED; + case R.id.editor_chan_sat_yellow: + return FilterChanSatRepresentation.MODE_YELLOW; + case R.id.editor_chan_sat_green: + return FilterChanSatRepresentation.MODE_GREEN; + case R.id.editor_chan_sat_cyan: + return FilterChanSatRepresentation.MODE_CYAN; + case R.id.editor_chan_sat_blue: + return FilterChanSatRepresentation.MODE_BLUE; + case R.id.editor_chan_sat_magenta: + return FilterChanSatRepresentation.MODE_MAGENTA; + } + return -1; + } + + @Override + public void detach() { + mButton.setListener(null); + mButton.setOnClickListener(null); + } + + private void updateSeekBar(FilterChanSatRepresentation rep) { + mControl.updateUI(); + } + + @Override + protected Parameter getParameterToEdit(FilterRepresentation rep) { + if (rep instanceof FilterChanSatRepresentation) { + FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep; + Parameter param = csrep.getFilterParameter(csrep.getParameterMode()); + if (param instanceof BasicParameterStyle) { + param.setFilterView(EditorChanSat.this); + } + return param; + } + return null; + } + + private FilterChanSatRepresentation getChanSatRep() { + FilterRepresentation rep = getLocalRepresentation(); + if (rep != null + && rep instanceof FilterChanSatRepresentation) { + FilterChanSatRepresentation csrep = (FilterChanSatRepresentation) rep; + return csrep; + } + return null; + } + + @Override + public void computeIcon(int n, RenderingRequestCaller caller) { + FilterChanSatRepresentation rep = getChanSatRep(); + if (rep == null) return; + rep = (FilterChanSatRepresentation) rep.copy(); + ImagePreset preset = new ImagePreset(); + preset.addFilter(rep); + Bitmap src = MasterImage.getImage().getThumbnailBitmap(); + RenderingRequest.post(null, src, preset, RenderingRequest.STYLE_ICON_RENDERING, + caller); + } + + protected void selectMenuItem(MenuItem item) { + if (getLocalRepresentation() != null + && getLocalRepresentation() instanceof FilterChanSatRepresentation) { + FilterChanSatRepresentation csrep = + (FilterChanSatRepresentation) getLocalRepresentation(); + + switchToMode(csrep, getParameterIndex(item.getItemId()), item.getTitle().toString()); + + } + } + + protected void switchToMode(FilterChanSatRepresentation csrep, int mode, String title) { + csrep.setParameterMode(mode); + mCurrentlyEditing = title; + mButton.setText(mCurrentlyEditing); + { + Parameter param = getParameterToEdit(csrep); + + control(param, mEditControl); + } + updateSeekBar(csrep); + mView.invalidate(); + } + + @Override + public void swapLeft(MenuItem item) { + super.swapLeft(item); + mButton.setTranslationX(0); + mButton.animate().translationX(mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION); + Runnable updateButton = new Runnable() { + @Override + public void run() { + mButton.animate().cancel(); + mButton.setTranslationX(0); + } + }; + mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION); + selectMenuItem(item); + } + + @Override + public void swapRight(MenuItem item) { + super.swapRight(item); + mButton.setTranslationX(0); + mButton.animate().translationX(-mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION); + Runnable updateButton = new Runnable() { + @Override + public void run() { + mButton.animate().cancel(); + mButton.setTranslationX(0); + } + }; + mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION); + selectMenuItem(item); + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorCrop.java b/src/com/android/gallery3d/filtershow/editors/EditorCrop.java new file mode 100644 index 000000000..511d4ff87 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorCrop.java @@ -0,0 +1,168 @@ +/* + * 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.editors; + +import android.content.Context; +import android.util.Log; +import android.util.SparseArray; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.PopupMenu; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterCropRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageCrop; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +public class EditorCrop extends Editor implements EditorInfo { + public static final String TAG = EditorCrop.class.getSimpleName(); + public static final int ID = R.id.editorCrop; + + // Holder for an aspect ratio it's string id + protected static final class AspectInfo { + int mAspectX; + int mAspectY; + int mStringId; + AspectInfo(int stringID, int x, int y) { + mStringId = stringID; + mAspectX = x; + mAspectY = y; + } + }; + + // Mapping from menu id to aspect ratio + protected static final SparseArray<AspectInfo> sAspects; + static { + sAspects = new SparseArray<AspectInfo>(); + sAspects.put(R.id.crop_menu_1to1, new AspectInfo(R.string.aspect1to1_effect, 1, 1)); + sAspects.put(R.id.crop_menu_4to3, new AspectInfo(R.string.aspect4to3_effect, 4, 3)); + sAspects.put(R.id.crop_menu_3to4, new AspectInfo(R.string.aspect3to4_effect, 3, 4)); + sAspects.put(R.id.crop_menu_5to7, new AspectInfo(R.string.aspect5to7_effect, 5, 7)); + sAspects.put(R.id.crop_menu_7to5, new AspectInfo(R.string.aspect7to5_effect, 7, 5)); + sAspects.put(R.id.crop_menu_none, new AspectInfo(R.string.aspectNone_effect, 0, 0)); + sAspects.put(R.id.crop_menu_original, new AspectInfo(R.string.aspectOriginal_effect, 0, 0)); + } + + protected ImageCrop mImageCrop; + private String mAspectString = ""; + + public EditorCrop() { + super(ID); + mChangesGeometry = true; + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + if (mImageCrop == null) { + mImageCrop = new ImageCrop(context); + } + mView = mImageShow = mImageCrop; + mImageCrop.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + MasterImage master = MasterImage.getImage(); + master.setCurrentFilterRepresentation(master.getPreset() + .getFilterWithSerializationName(FilterCropRepresentation.SERIALIZATION_NAME)); + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + if (rep == null || rep instanceof FilterCropRepresentation) { + mImageCrop.setFilterCropRepresentation((FilterCropRepresentation) rep); + } else { + Log.w(TAG, "Could not reflect current filter, not of type: " + + FilterCropRepresentation.class.getSimpleName()); + } + mImageCrop.invalidate(); + } + + @Override + public void finalApplyCalled() { + commitLocalRepresentation(mImageCrop.getFinalRepresentation()); + } + + @Override + public void openUtilityPanel(final LinearLayout accessoryViewList) { + Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); + view.setText(mContext.getString(R.string.crop)); + view.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + showPopupMenu(accessoryViewList); + } + }); + } + + private void changeCropAspect(int itemId) { + AspectInfo info = sAspects.get(itemId); + if (info == null) { + throw new IllegalArgumentException("Invalid resource ID: " + itemId); + } + if (itemId == R.id.crop_menu_original) { + mImageCrop.applyOriginalAspect(); + } else if (itemId == R.id.crop_menu_none) { + mImageCrop.applyFreeAspect(); + } else { + mImageCrop.applyAspect(info.mAspectX, info.mAspectY); + } + setAspectString(mContext.getString(info.mStringId)); + } + + private void showPopupMenu(LinearLayout accessoryViewList) { + final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect); + final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button); + popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_crop, popupMenu.getMenu()); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + changeCropAspect(item.getItemId()); + return true; + } + }); + popupMenu.show(); + } + + @Override + public boolean showsSeekBar() { + return false; + } + + @Override + public int getTextId() { + return R.string.crop; + } + + @Override + public int getOverlayId() { + return R.drawable.filtershow_button_geometry_crop; + } + + @Override + public boolean getOverlayOnly() { + return true; + } + + private void setAspectString(String s) { + mAspectString = s; + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorCurves.java b/src/com/android/gallery3d/filtershow/editors/EditorCurves.java new file mode 100644 index 000000000..83fbced79 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorCurves.java @@ -0,0 +1,56 @@ +/* + * 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.editors; + +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterCurvesRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageCurves; + +public class EditorCurves extends Editor { + public static final int ID = R.id.imageCurves; + ImageCurves mImageCurves; + + public EditorCurves() { + super(ID); + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mView = mImageShow = mImageCurves = new ImageCurves(context); + mImageCurves.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + if (rep != null && getLocalRepresentation() instanceof FilterCurvesRepresentation) { + FilterCurvesRepresentation drawRep = (FilterCurvesRepresentation) rep; + mImageCurves.setFilterDrawRepresentation(drawRep); + } + } + + @Override + public boolean showsSeekBar() { + return false; + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java new file mode 100644 index 000000000..4b09051e2 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java @@ -0,0 +1,158 @@ +/* + * 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.editors; + +import android.app.Dialog; +import android.content.Context; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.WindowManager.LayoutParams; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.PopupMenu; +import android.widget.SeekBar; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.colorpicker.ColorGridDialog; +import com.android.gallery3d.filtershow.colorpicker.RGBListener; +import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.filters.ImageFilterDraw; +import com.android.gallery3d.filtershow.imageshow.ImageDraw; + +public class EditorDraw extends Editor { + private static final String LOGTAG = "EditorDraw"; + public static final int ID = R.id.editorDraw; + public ImageDraw mImageDraw; + + public EditorDraw() { + super(ID); + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mView = mImageShow = mImageDraw = new ImageDraw(context); + mImageDraw.setEditor(this); + + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + + if (rep != null && getLocalRepresentation() instanceof FilterDrawRepresentation) { + FilterDrawRepresentation drawRep = (FilterDrawRepresentation) getLocalRepresentation(); + mImageDraw.setFilterDrawRepresentation(drawRep); + } + } + + @Override + public void openUtilityPanel(final LinearLayout accessoryViewList) { + Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); + view.setText(mContext.getString(R.string.draw_style)); + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View arg0) { + showPopupMenu(accessoryViewList); + } + }); + } + + @Override + public boolean showsSeekBar() { + return false; + } + + private void showPopupMenu(LinearLayout accessoryViewList) { + final Button button = (Button) accessoryViewList.findViewById( + R.id.applyEffect); + if (button == null) { + return; + } + final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button); + popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_draw, popupMenu.getMenu()); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + + @Override + public boolean onMenuItemClick(MenuItem item) { + ImageFilterDraw filter = (ImageFilterDraw) mImageShow.getCurrentFilter(); + if (item.getItemId() == R.id.draw_menu_color) { + showColorGrid(item); + } else if (item.getItemId() == R.id.draw_menu_size) { + showSizeDialog(item); + } else if (item.getItemId() == R.id.draw_menu_style_brush_marker) { + ImageDraw idraw = (ImageDraw) mImageShow; + idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_MARKER); + } else if (item.getItemId() == R.id.draw_menu_style_brush_spatter) { + ImageDraw idraw = (ImageDraw) mImageShow; + idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_SPATTER); + } else if (item.getItemId() == R.id.draw_menu_style_line) { + ImageDraw idraw = (ImageDraw) mImageShow; + idraw.setStyle(ImageFilterDraw.SIMPLE_STYLE); + } else if (item.getItemId() == R.id.draw_menu_clear) { + ImageDraw idraw = (ImageDraw) mImageShow; + idraw.resetParameter(); + commitLocalRepresentation(); + } + mView.invalidate(); + return true; + } + }); + popupMenu.show(); + } + + public void showSizeDialog(final MenuItem item) { + FilterShowActivity ctx = mImageShow.getActivity(); + final Dialog dialog = new Dialog(ctx); + dialog.setTitle(R.string.draw_size_title); + dialog.setContentView(R.layout.filtershow_draw_size); + final SeekBar bar = (SeekBar) dialog.findViewById(R.id.sizeSeekBar); + ImageDraw idraw = (ImageDraw) mImageShow; + bar.setProgress(idraw.getSize()); + Button button = (Button) dialog.findViewById(R.id.sizeAcceptButton); + button.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View arg0) { + int p = bar.getProgress(); + ImageDraw idraw = (ImageDraw) mImageShow; + idraw.setSize(p + 1); + dialog.dismiss(); + } + }); + dialog.show(); + } + + public void showColorGrid(final MenuItem item) { + RGBListener cl = new RGBListener() { + @Override + public void setColor(int rgb) { + ImageDraw idraw = (ImageDraw) mImageShow; + idraw.setColor(rgb); + } + }; + ColorGridDialog cpd = new ColorGridDialog(mImageShow.getActivity(), cl); + cpd.show(); + LayoutParams params = cpd.getWindow().getAttributes(); + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorGrad.java b/src/com/android/gallery3d/filtershow/editors/EditorGrad.java new file mode 100644 index 000000000..f427ccbd8 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorGrad.java @@ -0,0 +1,315 @@ +/* + * 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.editors; + +import android.content.Context; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.PopupMenu; +import android.widget.SeekBar; +import android.widget.SeekBar.OnSeekBarChangeListener; +import android.widget.ToggleButton; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.controller.Control; +import com.android.gallery3d.filtershow.controller.FilterView; +import com.android.gallery3d.filtershow.controller.Parameter; +import com.android.gallery3d.filtershow.controller.ParameterActionAndInt; +import com.android.gallery3d.filtershow.filters.FilterGradRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageGrad; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +public class EditorGrad extends ParametricEditor + implements OnSeekBarChangeListener, ParameterActionAndInt { + private static final String LOGTAG = "EditorGrad"; + public static final int ID = R.id.editorGrad; + PopupMenu mPopupMenu; + ToggleButton mAddModeButton; + String mEffectName = ""; + private static final int MODE_BRIGHTNESS = FilterGradRepresentation.PARAM_BRIGHTNESS; + private static final int MODE_SATURATION = FilterGradRepresentation.PARAM_SATURATION; + private static final int MODE_CONTRAST = FilterGradRepresentation.PARAM_CONTRAST; + private static final int ADD_ICON = R.drawable.ic_grad_add; + private static final int DEL_ICON = R.drawable.ic_grad_del; + private int mSliderMode = MODE_BRIGHTNESS; + ImageGrad mImageGrad; + + public EditorGrad() { + super(ID, R.layout.filtershow_grad_editor, R.id.gradEditor); + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mImageGrad = (ImageGrad) mImageShow; + mImageGrad.setEditor(this); + + } + + public void clearAddMode() { + mAddModeButton.setChecked(false); + FilterRepresentation tmpRep = getLocalRepresentation(); + if (tmpRep instanceof FilterGradRepresentation) { + updateMenuItems((FilterGradRepresentation) tmpRep); + } + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + FilterRepresentation tmpRep = getLocalRepresentation(); + if (tmpRep instanceof FilterGradRepresentation) { + FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; + boolean f = rep.showParameterValue(); + + mImageGrad.setRepresentation(rep); + } + } + + public void updateSeekBar(FilterGradRepresentation rep) { + mControl.updateUI(); + } + + @Override + public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { + FilterRepresentation tmpRep = getLocalRepresentation(); + if (tmpRep instanceof FilterGradRepresentation) { + FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; + int min = rep.getParameterMin(mSliderMode); + int value = progress + min; + rep.setParameter(mSliderMode, value); + mView.invalidate(); + commitLocalRepresentation(); + } + } + + @Override + public void openUtilityPanel(final LinearLayout accessoryViewList) { + Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); + view.setText(mContext.getString(R.string.editor_grad_brightness)); + view.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + showPopupMenu(accessoryViewList); + } + }); + + setUpPopupMenu(view); + setEffectName(); + } + + private void updateMenuItems(FilterGradRepresentation rep) { + int n = rep.getNumberOfBands(); + } + + public void setEffectName() { + if (mPopupMenu != null) { + MenuItem item = mPopupMenu.getMenu().findItem(R.id.editor_grad_brightness); + mEffectName = item.getTitle().toString(); + } + } + + private void showPopupMenu(LinearLayout accessoryViewList) { + Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect); + if (button == null) { + return; + } + + if (mPopupMenu == null) { + setUpPopupMenu(button); + } + mPopupMenu.show(); + } + + private void setUpPopupMenu(Button button) { + mPopupMenu = new PopupMenu(mImageShow.getActivity(), button); + mPopupMenu.getMenuInflater() + .inflate(R.menu.filtershow_menu_grad, mPopupMenu.getMenu()); + FilterGradRepresentation rep = (FilterGradRepresentation) getLocalRepresentation(); + if (rep == null) { + return; + } + updateMenuItems(rep); + hackFixStrings(mPopupMenu.getMenu()); + setEffectName(); + updateText(); + + mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + FilterRepresentation tmpRep = getLocalRepresentation(); + + if (tmpRep instanceof FilterGradRepresentation) { + FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; + int cmdID = item.getItemId(); + switch (cmdID) { + case R.id.editor_grad_brightness: + mSliderMode = MODE_BRIGHTNESS; + mEffectName = item.getTitle().toString(); + break; + case R.id.editor_grad_contrast: + mSliderMode = MODE_CONTRAST; + mEffectName = item.getTitle().toString(); + break; + case R.id.editor_grad_saturation: + mSliderMode = MODE_SATURATION; + mEffectName = item.getTitle().toString(); + break; + } + updateMenuItems(rep); + updateSeekBar(rep); + + commitLocalRepresentation(); + mView.invalidate(); + } + return true; + } + }); + } + + @Override + public String calculateUserMessage(Context context, String effectName, Object parameterValue) { + FilterGradRepresentation rep = getGradRepresentation(); + if (rep == null) { + return mEffectName; + } + int val = rep.getParameter(mSliderMode); + return mEffectName.toUpperCase() + ((val > 0) ? " +" : " ") + val; + } + + private FilterGradRepresentation getGradRepresentation() { + FilterRepresentation tmpRep = getLocalRepresentation(); + if (tmpRep instanceof FilterGradRepresentation) { + return (FilterGradRepresentation) tmpRep; + } + return null; + } + + @Override + public int getMaximum() { + FilterGradRepresentation rep = getGradRepresentation(); + if (rep == null) { + return 0; + } + return rep.getParameterMax(mSliderMode); + } + + @Override + public int getMinimum() { + FilterGradRepresentation rep = getGradRepresentation(); + if (rep == null) { + return 0; + } + return rep.getParameterMin(mSliderMode); + } + + @Override + public int getDefaultValue() { + return 0; + } + + @Override + public int getValue() { + FilterGradRepresentation rep = getGradRepresentation(); + if (rep == null) { + return 0; + } + return rep.getParameter(mSliderMode); + } + + @Override + public String getValueString() { + return null; + } + + @Override + public void setValue(int value) { + FilterGradRepresentation rep = getGradRepresentation(); + if (rep == null) { + return; + } + rep.setParameter(mSliderMode, value); + } + + @Override + public String getParameterName() { + return mEffectName; + } + + @Override + public String getParameterType() { + return sParameterType; + } + + @Override + public void setController(Control c) { + + } + + @Override + public void fireLeftAction() { + FilterGradRepresentation rep = getGradRepresentation(); + if (rep == null) { + return; + } + rep.addBand(MasterImage.getImage().getOriginalBounds()); + updateMenuItems(rep); + updateSeekBar(rep); + + commitLocalRepresentation(); + mView.invalidate(); + } + + @Override + public int getLeftIcon() { + return ADD_ICON; + } + + @Override + public void fireRightAction() { + FilterGradRepresentation rep = getGradRepresentation(); + if (rep == null) { + return; + } + rep.deleteCurrentBand(); + + updateMenuItems(rep); + updateSeekBar(rep); + commitLocalRepresentation(); + mView.invalidate(); + } + + @Override + public int getRightIcon() { + return DEL_ICON; + } + + @Override + public void setFilterView(FilterView editor) { + + } + + @Override + public void copyFrom(Parameter src) { + + } + +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorInfo.java b/src/com/android/gallery3d/filtershow/editors/EditorInfo.java new file mode 100644 index 000000000..75afe49c2 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorInfo.java @@ -0,0 +1,23 @@ +/* + * 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.editors; + +public interface EditorInfo { + public int getTextId(); + public int getOverlayId(); + public boolean getOverlayOnly(); +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorMirror.java b/src/com/android/gallery3d/filtershow/editors/EditorMirror.java new file mode 100644 index 000000000..d6d9ee75d --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorMirror.java @@ -0,0 +1,109 @@ +/* + * 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.editors; + +import android.content.Context; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.LinearLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageMirror; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +public class EditorMirror extends Editor implements EditorInfo { + public static final String TAG = EditorMirror.class.getSimpleName(); + public static final int ID = R.id.editorFlip; + ImageMirror mImageMirror; + + public EditorMirror() { + super(ID); + mChangesGeometry = true; + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + if (mImageMirror == null) { + mImageMirror = new ImageMirror(context); + } + mView = mImageShow = mImageMirror; + mImageMirror.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + MasterImage master = MasterImage.getImage(); + master.setCurrentFilterRepresentation(master.getPreset() + .getFilterWithSerializationName(FilterMirrorRepresentation.SERIALIZATION_NAME)); + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + if (rep == null || rep instanceof FilterMirrorRepresentation) { + mImageMirror.setFilterMirrorRepresentation((FilterMirrorRepresentation) rep); + } else { + Log.w(TAG, "Could not reflect current filter, not of type: " + + FilterMirrorRepresentation.class.getSimpleName()); + } + mImageMirror.invalidate(); + } + + @Override + public void openUtilityPanel(final LinearLayout accessoryViewList) { + final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect); + button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + mImageMirror.flip(); + } + }); + } + + @Override + public void finalApplyCalled() { + commitLocalRepresentation(mImageMirror.getFinalRepresentation()); + } + + @Override + public int getTextId() { + return R.string.mirror; + } + + @Override + public int getOverlayId() { + return R.drawable.filtershow_button_geometry_flip; + } + + @Override + public boolean getOverlayOnly() { + return true; + } + + @Override + public boolean showsSeekBar() { + return false; + } + + @Override + public boolean showsPopupIndicator() { + return false; + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java new file mode 100644 index 000000000..bc4ca6ab6 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java @@ -0,0 +1,143 @@ +/* + * 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.editors; + +import android.app.Activity; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +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.HistoryManager; +import com.android.gallery3d.filtershow.category.MainPanel; +import com.android.gallery3d.filtershow.imageshow.MasterImage; +import com.android.gallery3d.filtershow.state.StatePanel; + +public class EditorPanel extends Fragment { + + private static final String LOGTAG = "EditorPanel"; + + private LinearLayout mMainView; + private Editor mEditor; + private int mEditorID; + + public void setEditor(int editor) { + mEditorID = editor; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + FilterShowActivity filterShowActivity = (FilterShowActivity) activity; + mEditor = filterShowActivity.getEditor(mEditorID); + } + + public void cancelCurrentFilter() { + MasterImage masterImage = MasterImage.getImage(); + HistoryManager adapter = masterImage.getHistory(); + + int position = adapter.undo(); + masterImage.onHistoryItemClick(position); + ((FilterShowActivity)getActivity()).invalidateViews(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + FilterShowActivity activity = (FilterShowActivity) getActivity(); + if (mMainView != null) { + if (mMainView.getParent() != null) { + ViewGroup parent = (ViewGroup) mMainView.getParent(); + parent.removeView(mMainView); + } + showImageStatePanel(activity.isShowingImageStatePanel()); + return mMainView; + } + mMainView = (LinearLayout) inflater.inflate(R.layout.filtershow_editor_panel, null); + + View actionControl = mMainView.findViewById(R.id.panelAccessoryViewList); + View editControl = mMainView.findViewById(R.id.controlArea); + ImageButton cancelButton = (ImageButton) mMainView.findViewById(R.id.cancelFilter); + ImageButton applyButton = (ImageButton) mMainView.findViewById(R.id.applyFilter); + Button editTitle = (Button) mMainView.findViewById(R.id.applyEffect); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + cancelCurrentFilter(); + FilterShowActivity activity = (FilterShowActivity) getActivity(); + activity.backToMain(); + } + }); + + Button toggleState = (Button) mMainView.findViewById(R.id.toggle_state); + mEditor = activity.getEditor(mEditorID); + if (mEditor != null) { + mEditor.setUpEditorUI(actionControl, editControl, editTitle, toggleState); + mEditor.reflectCurrentFilter(); + if (mEditor.useUtilityPanel()) { + mEditor.openUtilityPanel((LinearLayout) actionControl); + } + } + applyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FilterShowActivity activity = (FilterShowActivity) getActivity(); + mEditor.finalApplyCalled(); + activity.backToMain(); + } + }); + + showImageStatePanel(activity.isShowingImageStatePanel()); + return mMainView; + } + + @Override + public void onDetach() { + if (mEditor != null) { + mEditor.detach(); + } + super.onDetach(); + } + + public void showImageStatePanel(boolean show) { + if (mMainView.findViewById(R.id.state_panel_container) == null) { + return; + } + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + Fragment panel = getActivity().getSupportFragmentManager().findFragmentByTag( + MainPanel.FRAGMENT_TAG); + if (panel == null || panel instanceof MainPanel) { + transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); + } + if (show) { + StatePanel statePanel = new StatePanel(); + transaction.replace(R.id.state_panel_container, statePanel, StatePanel.FRAGMENT_TAG); + } else { + Fragment statePanel = getChildFragmentManager().findFragmentByTag(StatePanel.FRAGMENT_TAG); + if (statePanel != null) { + transaction.remove(statePanel); + } + } + transaction.commit(); + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorRedEye.java b/src/com/android/gallery3d/filtershow/editors/EditorRedEye.java new file mode 100644 index 000000000..b0e88dd44 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorRedEye.java @@ -0,0 +1,65 @@ +/* + * 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.editors; + +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterRedEyeRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageRedEye; + +/** + * The editor with no slider for filters without UI + */ +public class EditorRedEye extends Editor { + public static int ID = R.id.editorRedEye; + private final String LOGTAG = "EditorRedEye"; + ImageRedEye mImageRedEyes; + + public EditorRedEye() { + super(ID); + } + + protected EditorRedEye(int id) { + super(id); + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mView = mImageShow = mImageRedEyes= new ImageRedEye(context); + mImageRedEyes.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + if (rep != null && getLocalRepresentation() instanceof FilterRedEyeRepresentation) { + FilterRedEyeRepresentation redEyeRep = (FilterRedEyeRepresentation) rep; + + mImageRedEyes.setRepresentation(redEyeRep); + } + } + + @Override + public boolean showsSeekBar() { + return false; + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorRotate.java b/src/com/android/gallery3d/filtershow/editors/EditorRotate.java new file mode 100644 index 000000000..9452bf0c0 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorRotate.java @@ -0,0 +1,112 @@ +/* + * 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.editors; + +import android.content.Context; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.LinearLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageRotate; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +public class EditorRotate extends Editor implements EditorInfo { + public static final String TAG = EditorRotate.class.getSimpleName(); + public static final int ID = R.id.editorRotate; + ImageRotate mImageRotate; + + public EditorRotate() { + super(ID); + mChangesGeometry = true; + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + if (mImageRotate == null) { + mImageRotate = new ImageRotate(context); + } + mView = mImageShow = mImageRotate; + mImageRotate.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + MasterImage master = MasterImage.getImage(); + master.setCurrentFilterRepresentation(master.getPreset() + .getFilterWithSerializationName(FilterRotateRepresentation.SERIALIZATION_NAME)); + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + if (rep == null || rep instanceof FilterRotateRepresentation) { + mImageRotate.setFilterRotateRepresentation((FilterRotateRepresentation) rep); + } else { + Log.w(TAG, "Could not reflect current filter, not of type: " + + FilterRotateRepresentation.class.getSimpleName()); + } + mImageRotate.invalidate(); + } + + @Override + public void openUtilityPanel(final LinearLayout accessoryViewList) { + final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect); + button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + mImageRotate.rotate(); + String displayVal = mContext.getString(getTextId()) + " " + + mImageRotate.getLocalValue(); + button.setText(displayVal); + } + }); + } + + @Override + public void finalApplyCalled() { + commitLocalRepresentation(mImageRotate.getFinalRepresentation()); + } + + @Override + public int getTextId() { + return R.string.rotate; + } + + @Override + public int getOverlayId() { + return R.drawable.filtershow_button_geometry_rotate; + } + + @Override + public boolean getOverlayOnly() { + return true; + } + + @Override + public boolean showsSeekBar() { + return false; + } + + @Override + public boolean showsPopupIndicator() { + return false; + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java b/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java new file mode 100644 index 000000000..ff84ba8f9 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java @@ -0,0 +1,103 @@ +/* + * 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.editors; + +import android.content.Context; +import android.util.Log; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageStraighten; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +public class EditorStraighten extends Editor implements EditorInfo { + public static final String TAG = EditorStraighten.class.getSimpleName(); + public static final int ID = R.id.editorStraighten; + ImageStraighten mImageStraighten; + + public EditorStraighten() { + super(ID); + mShowParameter = SHOW_VALUE_INT; + mChangesGeometry = true; + } + + @Override + public String calculateUserMessage(Context context, String effectName, Object parameterValue) { + String apply = context.getString(R.string.apply_effect); + apply += " " + effectName; + return apply.toUpperCase(); + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + if (mImageStraighten == null) { + mImageStraighten = new ImageStraighten(context); + } + mView = mImageShow = mImageStraighten; + mImageStraighten.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + MasterImage master = MasterImage.getImage(); + master.setCurrentFilterRepresentation(master.getPreset().getFilterWithSerializationName( + FilterStraightenRepresentation.SERIALIZATION_NAME)); + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + if (rep == null || rep instanceof FilterStraightenRepresentation) { + mImageStraighten + .setFilterStraightenRepresentation((FilterStraightenRepresentation) rep); + } else { + Log.w(TAG, "Could not reflect current filter, not of type: " + + FilterStraightenRepresentation.class.getSimpleName()); + } + mImageStraighten.invalidate(); + } + + @Override + public void finalApplyCalled() { + commitLocalRepresentation(mImageStraighten.getFinalRepresentation()); + } + + @Override + public int getTextId() { + return R.string.straighten; + } + + @Override + public int getOverlayId() { + return R.drawable.filtershow_button_geometry_straighten; + } + + @Override + public boolean getOverlayOnly() { + return true; + } + + @Override + public boolean showsSeekBar() { + return false; + } + + @Override + public boolean showsPopupIndicator() { + return false; + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java b/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java new file mode 100644 index 000000000..9376fbef0 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java @@ -0,0 +1,58 @@ +/* + * 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.editors; + +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.filters.FilterTinyPlanetRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageTinyPlanet; + +public class EditorTinyPlanet extends BasicEditor { + public static final int ID = R.id.tinyPlanetEditor; + private static final String LOGTAG = "EditorTinyPlanet"; + ImageTinyPlanet mImageTinyPlanet; + + public EditorTinyPlanet() { + super(ID, R.layout.filtershow_tiny_planet_editor, R.id.imageTinyPlanet); + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mImageTinyPlanet = (ImageTinyPlanet) mImageShow; + mImageTinyPlanet.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + FilterRepresentation rep = getLocalRepresentation(); + if (rep != null && rep instanceof FilterTinyPlanetRepresentation) { + FilterTinyPlanetRepresentation drawRep = (FilterTinyPlanetRepresentation) rep; + mImageTinyPlanet.setRepresentation(drawRep); + } + } + + public void updateUI() { + if (mControl != null) { + mControl.updateUI(); + } + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorVignette.java b/src/com/android/gallery3d/filtershow/editors/EditorVignette.java new file mode 100644 index 000000000..7127b2188 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorVignette.java @@ -0,0 +1,53 @@ +/* + * 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.editors; + +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.filters.FilterVignetteRepresentation; +import com.android.gallery3d.filtershow.imageshow.ImageVignette; + +public class EditorVignette extends ParametricEditor { + public static final int ID = R.id.vignetteEditor; + private static final String LOGTAG = "EditorVignettePlanet"; + ImageVignette mImageVignette; + + public EditorVignette() { + super(ID, R.layout.filtershow_vignette_editor, R.id.imageVignette); + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mImageVignette = (ImageVignette) mImageShow; + mImageVignette.setEditor(this); + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + + FilterRepresentation rep = getLocalRepresentation(); + if (rep != null && getLocalRepresentation() instanceof FilterVignetteRepresentation) { + FilterVignetteRepresentation drawRep = (FilterVignetteRepresentation) rep; + mImageVignette.setRepresentation(drawRep); + } + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorZoom.java b/src/com/android/gallery3d/filtershow/editors/EditorZoom.java new file mode 100644 index 000000000..ea8e3d140 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorZoom.java @@ -0,0 +1,27 @@ +/* + * 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.editors; + +import com.android.gallery3d.R; + +public class EditorZoom extends BasicEditor { + public static final int ID = R.id.imageZoom; + + public EditorZoom() { + super(ID, R.layout.filtershow_zoom_editor,R.id.imageZoom); + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/ImageOnlyEditor.java b/src/com/android/gallery3d/filtershow/editors/ImageOnlyEditor.java new file mode 100644 index 000000000..d4e66edf8 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/ImageOnlyEditor.java @@ -0,0 +1,50 @@ +/* + * 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.editors; + +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.imageshow.ImageShow; + +/** + * The editor with no slider for filters without UI + */ +public class ImageOnlyEditor extends Editor { + public final static int ID = R.id.imageOnlyEditor; + private final String LOGTAG = "ImageOnlyEditor"; + + public ImageOnlyEditor() { + super(ID); + } + + protected ImageOnlyEditor(int id) { + super(id); + } + + public boolean useUtilityPanel() { + return false; + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mView = mImageShow = new ImageShow(context); + } + +} diff --git a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java new file mode 100644 index 000000000..9ec858ca5 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java @@ -0,0 +1,206 @@ +/* + * 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.editors; + +import android.content.Context; +import android.graphics.Point; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; +import android.view.WindowManager; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.SeekBar; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.controller.ActionSlider; +import com.android.gallery3d.filtershow.controller.BasicSlider; +import com.android.gallery3d.filtershow.controller.Control; +import com.android.gallery3d.filtershow.controller.Parameter; +import com.android.gallery3d.filtershow.controller.ParameterActionAndInt; +import com.android.gallery3d.filtershow.controller.ParameterInteger; +import com.android.gallery3d.filtershow.controller.ParameterStyles; +import com.android.gallery3d.filtershow.controller.StyleChooser; +import com.android.gallery3d.filtershow.controller.TitledSlider; +import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; + +import java.lang.reflect.Constructor; +import java.util.HashMap; + +public class ParametricEditor extends Editor { + private int mLayoutID; + private int mViewID; + public static int ID = R.id.editorParametric; + private final String LOGTAG = "ParametricEditor"; + protected Control mControl; + public static final int MINIMUM_WIDTH = 600; + public static final int MINIMUM_HEIGHT = 800; + View mActionButton; + View mEditControl; + static HashMap<String, Class> portraitMap = new HashMap<String, Class>(); + static HashMap<String, Class> landscapeMap = new HashMap<String, Class>(); + static { + portraitMap.put(ParameterInteger.sParameterType, BasicSlider.class); + landscapeMap.put(ParameterInteger.sParameterType, TitledSlider.class); + portraitMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class); + landscapeMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class); + portraitMap.put(ParameterStyles.sParameterType, StyleChooser.class); + landscapeMap.put(ParameterStyles.sParameterType, StyleChooser.class); + } + + static Constructor getConstructor(Class cl) { + try { + return cl.getConstructor(Context.class, ViewGroup.class); + } catch (Exception e) { + return null; + } + } + + public ParametricEditor() { + super(ID); + } + + protected ParametricEditor(int id) { + super(id); + } + + protected ParametricEditor(int id, int layoutID, int viewID) { + super(id); + mLayoutID = layoutID; + mViewID = viewID; + } + + @Override + public String calculateUserMessage(Context context, String effectName, Object parameterValue) { + String apply = ""; + + if (mShowParameter == SHOW_VALUE_INT & useCompact(context)) { + if (getLocalRepresentation() instanceof FilterBasicRepresentation) { + FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation(); + apply += " " + effectName.toUpperCase() + " " + interval.getStateRepresentation(); + } else { + apply += " " + effectName.toUpperCase() + " " + parameterValue; + } + } else { + apply += " " + effectName.toUpperCase(); + } + return apply; + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + unpack(mViewID, mLayoutID); + } + + @Override + public void reflectCurrentFilter() { + super.reflectCurrentFilter(); + if (getLocalRepresentation() != null + && getLocalRepresentation() instanceof FilterBasicRepresentation) { + FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation(); + mControl.setPrameter(interval); + } + } + + @Override + public Control[] getControls() { + BasicSlider slider = new BasicSlider(); + return new Control[] { + slider + }; + } + + // TODO: need a better way to decide which representation + static boolean useCompact(Context context) { + WindowManager w = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)); + Point size = new Point(); + w.getDefaultDisplay().getSize(size); + if (size.x < size.y) { // if tall than wider + return true; + } + if (size.x < MINIMUM_WIDTH) { + return true; + } + if (size.y < MINIMUM_HEIGHT) { + return true; + } + return false; + } + + protected Parameter getParameterToEdit(FilterRepresentation rep) { + if (this instanceof Parameter) { + return (Parameter) this; + } else if (rep instanceof Parameter) { + return ((Parameter) rep); + } + return null; + } + + @Override + public void setUtilityPanelUI(View actionButton, View editControl) { + mActionButton = actionButton; + mEditControl = editControl; + FilterRepresentation rep = getLocalRepresentation(); + Parameter param = getParameterToEdit(rep); + if (param != null) { + control(param, editControl); + } else { + mSeekBar = new SeekBar(editControl.getContext()); + LayoutParams lp = new LinearLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + mSeekBar.setLayoutParams(lp); + ((LinearLayout) editControl).addView(mSeekBar); + mSeekBar.setOnSeekBarChangeListener(this); + } + } + + protected void control(Parameter p, View editControl) { + String pType = p.getParameterType(); + Context context = editControl.getContext(); + Class c = ((useCompact(context)) ? portraitMap : landscapeMap).get(pType); + + if (c != null) { + try { + mControl = (Control) c.newInstance(); + p.setController(mControl); + mControl.setUp((ViewGroup) editControl, p, this); + } catch (Exception e) { + Log.e(LOGTAG, "Error in loading Control ", e); + } + } else { + Log.e(LOGTAG, "Unable to find class for " + pType); + for (String string : portraitMap.keySet()) { + Log.e(LOGTAG, "for " + string + " use " + portraitMap.get(string)); + } + } + } + + @Override + public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { + } + + @Override + public void onStartTrackingTouch(SeekBar arg0) { + } + + @Override + public void onStopTrackingTouch(SeekBar arg0) { + } +} diff --git a/src/com/android/gallery3d/filtershow/editors/SwapButton.java b/src/com/android/gallery3d/filtershow/editors/SwapButton.java new file mode 100644 index 000000000..bb4432e28 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/SwapButton.java @@ -0,0 +1,111 @@ +/* + * 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.editors; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.GestureDetector; +import android.view.Menu; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.widget.Button; + +public class SwapButton extends Button implements GestureDetector.OnGestureListener { + + public static int ANIM_DURATION = 200; + + public interface SwapButtonListener { + public void swapLeft(MenuItem item); + public void swapRight(MenuItem item); + } + + private GestureDetector mDetector; + private SwapButtonListener mListener; + private Menu mMenu; + private int mCurrentMenuIndex; + + public SwapButton(Context context, AttributeSet attrs) { + super(context, attrs); + mDetector = new GestureDetector(context, this); + } + + public SwapButtonListener getListener() { + return mListener; + } + + public void setListener(SwapButtonListener listener) { + mListener = listener; + } + + public boolean onTouchEvent(MotionEvent me) { + if (!mDetector.onTouchEvent(me)) { + return super.onTouchEvent(me); + } + return true; + } + + @Override + public boolean onDown(MotionEvent e) { + return true; + } + + @Override + public void onShowPress(MotionEvent e) { + } + + @Override + public boolean onSingleTapUp(MotionEvent e) { + callOnClick(); + return true; + } + + @Override + public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + return false; + } + + @Override + public void onLongPress(MotionEvent e) { + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + if (mMenu == null) { + return false; + } + if (e1.getX() - e2.getX() > 0) { + // right to left + mCurrentMenuIndex++; + if (mCurrentMenuIndex == mMenu.size()) { + mCurrentMenuIndex = 0; + } + if (mListener != null) { + mListener.swapRight(mMenu.getItem(mCurrentMenuIndex)); + } + } else { + // left to right + mCurrentMenuIndex--; + if (mCurrentMenuIndex < 0) { + mCurrentMenuIndex = mMenu.size() - 1; + } + if (mListener != null) { + mListener.swapLeft(mMenu.getItem(mCurrentMenuIndex)); + } + } + return true; + } +} |