1a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford/*
2a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * Copyright (C) 2012 The Android Open Source Project
3a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford *
4a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * Licensed under the Apache License, Version 2.0 (the "License");
5a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * you may not use this file except in compliance with the License.
6a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * You may obtain a copy of the License at
7a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford *
8a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford *      http://www.apache.org/licenses/LICENSE-2.0
9a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford *
10a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * Unless required by applicable law or agreed to in writing, software
11a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * distributed under the License is distributed on an "AS IS" BASIS,
12a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * See the License for the specific language governing permissions and
14a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * limitations under the License.
15a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford */
16a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
17a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordpackage com.android.gallery3d.filtershow.editors;
18a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
19a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.content.Context;
2037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.os.Handler;
2137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.view.LayoutInflater;
2237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.view.MenuItem;
2337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.view.View;
2437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.view.ViewGroup;
25a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.widget.FrameLayout;
2637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.widget.LinearLayout;
2737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.widget.PopupMenu;
2837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.widget.SeekBar;
2937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.widget.TextView;
30a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
31a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport com.android.gallery3d.R;
3264fc2ed005e2f1dc9ed0b34481c46a370c244b86John Hofordimport com.android.gallery3d.filtershow.FilterShowActivity;
3337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport com.android.gallery3d.filtershow.controller.BasicParameterInt;
3437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport com.android.gallery3d.filtershow.controller.Parameter;
35a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport com.android.gallery3d.filtershow.filters.FilterVignetteRepresentation;
3637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport com.android.gallery3d.filtershow.filters.FilterRepresentation;
37a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageVignette;
38a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
39235d2179374bec14040f20af91dc753e38ea3639John Hofordpublic class EditorVignette extends ParametricEditor {
40a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    public static final int ID = R.id.vignetteEditor;
41a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    private static final String LOGTAG = "EditorVignettePlanet";
42a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    ImageVignette mImageVignette;
43a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
4437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private SeekBar mVignetteBar;
4537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private SeekBar mExposureBar;
4637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private SeekBar mSaturationBar;
4737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private SeekBar mContrastBar;
4837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private SeekBar mFalloffBar;
4937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
5037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
5137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private TextView mVignetteValue;
5237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private TextView mExposureValue;
5337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private TextView mSaturationValue;
5437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private TextView mContrastValue;
5537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private TextView mFalloffValue;
5637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
5737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private SwapButton mButton;
5837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private final Handler mHandler = new Handler();
5937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
6037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    int[] mMenuStrings = {
6137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            R.string.vignette_main,
6237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            R.string.vignette_exposure,
6337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            R.string.vignette_saturation,
6437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            R.string.vignette_contrast,
6537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            R.string.vignette_falloff,
6637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    };
6737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
6837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    String mCurrentlyEditing = null;
6937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
7037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
71a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    public EditorVignette() {
72a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        super(ID, R.layout.filtershow_vignette_editor, R.id.imageVignette);
73a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    }
74a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
75a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    @Override
76a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    public void createEditor(Context context, FrameLayout frameLayout) {
77a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        super.createEditor(context, frameLayout);
78a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        mImageVignette = (ImageVignette) mImageShow;
79a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        mImageVignette.setEditor(this);
80a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    }
81a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
82a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    @Override
83a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    public void reflectCurrentFilter() {
8437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (useCompact(mContext)) {
8537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            super.reflectCurrentFilter();
86a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
8737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            FilterRepresentation rep = getLocalRepresentation();
8837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            if (rep != null && getLocalRepresentation() instanceof FilterVignetteRepresentation) {
8937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                FilterVignetteRepresentation drawRep = (FilterVignetteRepresentation) rep;
9037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mImageVignette.setRepresentation(drawRep);
9137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            }
9237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            updateText();
9337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            return;
9437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
9537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mLocalRepresentation = null;
9637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (getLocalRepresentation() != null
9737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                && getLocalRepresentation() instanceof FilterVignetteRepresentation) {
9837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            FilterVignetteRepresentation rep =
9937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    (FilterVignetteRepresentation) getLocalRepresentation();
10037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            int min;
10137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            int []mode = {
10237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    FilterVignetteRepresentation.MODE_VIGNETTE,
10337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    FilterVignetteRepresentation.MODE_EXPOSURE,
10437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    FilterVignetteRepresentation.MODE_SATURATION,
10537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    FilterVignetteRepresentation.MODE_CONTRAST,
10637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    FilterVignetteRepresentation.MODE_FALLOFF
10737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            };
10837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            SeekBar []sliders = {
10937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mVignetteBar,
11037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mExposureBar,
11137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mSaturationBar,
11237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mContrastBar,
11337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mFalloffBar
11437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            };
11537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            TextView []label = {
11637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mVignetteValue,
11737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mExposureValue,
11837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mSaturationValue,
11937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mContrastValue,
12037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    mFalloffValue
12137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            };
12237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            for (int i = 0; i < mode.length; i++) {
12337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                BasicParameterInt p = (BasicParameterInt) rep.getFilterParameter(mode[i]);
12437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                int value = p.getValue();
12537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                sliders[i].setMax(p.getMaximum() - p.getMinimum());
12637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                sliders[i].setProgress(value - p.getMinimum());
12737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                label[i].setText("" + value);
12837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            }
12937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
13037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            mImageVignette.setRepresentation(rep);
13137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            String text = mContext.getString(rep.getTextId()).toUpperCase();
13237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            mFilterTitle.setText(text);
13337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            updateText();
13437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
13537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
13637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
13737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
13837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
13937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
14037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
141a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        FilterRepresentation rep = getLocalRepresentation();
14237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (rep == null || !(rep instanceof FilterVignetteRepresentation)) {
14337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            return "";
14437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
14537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        FilterVignetteRepresentation csrep = (FilterVignetteRepresentation) rep;
14637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        int mode = csrep.getParameterMode();
14737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        String paramString;
14837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
14937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        paramString = mContext.getString(mMenuStrings[mode]);
15037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
15137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        int val = csrep.getCurrentParameter();
15237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        return paramString + ((val > 0) ? " +" : " ") + val;
15337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
15437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
15537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
15637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public void openUtilityPanel(final LinearLayout accessoryViewList) {
15737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton = (SwapButton) accessoryViewList.findViewById(R.id.applyEffect);
15837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.setText(mContext.getString(R.string.vignette_main));
15937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
16037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (useCompact(mContext)) {
16137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), mButton);
16237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
16337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_vignette,
16437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    popupMenu.getMenu());
16537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
16637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
16737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                @Override
16837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                public boolean onMenuItemClick(MenuItem item) {
16937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    selectMenuItem(item);
17037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    return true;
17137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                }
17237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            });
17337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            mButton.setOnClickListener(new View.OnClickListener() {
17437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                @Override
17537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                public void onClick(View arg0) {
17637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    popupMenu.show();
17764fc2ed005e2f1dc9ed0b34481c46a370c244b86John Hoford                    ((FilterShowActivity)mContext).onShowMenu(popupMenu);
17837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                }
17937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            });
18037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            mButton.setListener(this);
18137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
18237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            FilterVignetteRepresentation csrep = getVignetteRep();
18337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            String menuString = mContext.getString(mMenuStrings[0]);
18437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            switchToMode(csrep, FilterVignetteRepresentation.MODE_VIGNETTE, menuString);
18537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        } else {
18637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            mButton.setText(mContext.getString(R.string.vignette_main));
18737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
18837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
18937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
19037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
19137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public void setUtilityPanelUI(View actionButton, View editControl) {
19237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (useCompact(mContext)) {
19337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            super.setUtilityPanelUI(actionButton, editControl);
19437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            return;
19537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
19637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mActionButton = actionButton;
19737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mEditControl = editControl;
19837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mEditTitle.setCompoundDrawables(null, null, null, null);
19937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        LinearLayout group = (LinearLayout) editControl;
20037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        LayoutInflater inflater =
20137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
20237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        LinearLayout controls = (LinearLayout) inflater.inflate(
20337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                R.layout.filtershow_vignette_controls, group, false);
20437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        ViewGroup.LayoutParams lp = new LinearLayout.LayoutParams(
20537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
20637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        controls.setLayoutParams(lp);
20737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        group.removeAllViews();
20837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        group.addView(controls);
20937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
21037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mVignetteBar = (SeekBar) controls.findViewById(R.id.mainVignetteSeekbar);
21137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mVignetteBar.setMax(200);
21237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mVignetteBar.setOnSeekBarChangeListener(this);
21337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mVignetteValue = (TextView) controls.findViewById(R.id.mainVignetteValue);
21437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mExposureBar = (SeekBar) controls.findViewById(R.id.exposureSeekBar);
21537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mExposureBar.setMax(200);
21637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mExposureBar.setOnSeekBarChangeListener(this);
21737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mExposureValue = (TextView) controls.findViewById(R.id.exposureValue);
21837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mSaturationBar = (SeekBar) controls.findViewById(R.id.saturationSeekBar);
21937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mSaturationBar.setMax(200);
22037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mSaturationBar.setOnSeekBarChangeListener(this);
22137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mSaturationValue = (TextView) controls.findViewById(R.id.saturationValue);
22237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mContrastBar = (SeekBar) controls.findViewById(R.id.contrastSeekBar);
22337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mContrastBar.setMax(200);
22437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mContrastBar.setOnSeekBarChangeListener(this);
22537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mContrastValue = (TextView) controls.findViewById(R.id.contrastValue);
22637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mFalloffBar = (SeekBar) controls.findViewById(R.id.falloffSeekBar);
22737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mFalloffBar.setMax(200);
22837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mFalloffBar.setOnSeekBarChangeListener(this);
22937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mFalloffValue = (TextView) controls.findViewById(R.id.falloffValue);
23037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
23137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
23237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public int getParameterIndex(int id) {
23337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        switch (id) {
23437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.editor_vignette_main:
23537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                return FilterVignetteRepresentation.MODE_VIGNETTE;
23637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.editor_vignette_saturation:
23737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                return FilterVignetteRepresentation.MODE_SATURATION;
23837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.editor_vignette_contrast:
23937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                return FilterVignetteRepresentation.MODE_CONTRAST;
24037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.editor_vignette_exposure:
24137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                return FilterVignetteRepresentation.MODE_EXPOSURE;
24237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.editor_vignette_falloff:
24337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                return FilterVignetteRepresentation.MODE_FALLOFF;
244a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        }
24537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        return -1;
24637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
24737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
24837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
24937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public void detach() {
25037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (mButton == null) {
25137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            return;
25237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
25337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.setListener(null);
25437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.setOnClickListener(null);
25537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
25637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
25737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private void updateSeekBar(FilterVignetteRepresentation rep) {
25837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mControl.updateUI();
25937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
26037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
26137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
26237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    protected Parameter getParameterToEdit(FilterRepresentation rep) {
26337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (rep instanceof FilterVignetteRepresentation) {
26437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            FilterVignetteRepresentation csrep = (FilterVignetteRepresentation) rep;
26537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            Parameter param = csrep.getFilterParameter(csrep.getParameterMode());
26637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
26737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            return param;
26837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
26937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        return null;
27037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
27137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
27237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    private FilterVignetteRepresentation getVignetteRep() {
27337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        FilterRepresentation rep = getLocalRepresentation();
27437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (rep != null
27537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                && rep instanceof FilterVignetteRepresentation) {
27637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            FilterVignetteRepresentation csrep = (FilterVignetteRepresentation) rep;
27737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            return csrep;
27837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
27937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        return null;
28037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
28137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
28237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    protected void selectMenuItem(MenuItem item) {
28337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (getLocalRepresentation() != null
28437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                && getLocalRepresentation() instanceof FilterVignetteRepresentation) {
28537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            FilterVignetteRepresentation csrep =
28637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                    (FilterVignetteRepresentation) getLocalRepresentation();
28737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
28837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            switchToMode(csrep, getParameterIndex(item.getItemId()), item.getTitle().toString());
28937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
29037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
29137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
29237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    protected void switchToMode(FilterVignetteRepresentation csrep, int mode, String title) {
29337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        if (csrep == null) {
29437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            return;
29537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
29637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        csrep.setParameterMode(mode);
29737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mCurrentlyEditing = title;
29837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.setText(mCurrentlyEditing);
29937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        {
30037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            Parameter param = getParameterToEdit(csrep);
30137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
30237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            control(param, mEditControl);
30337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
30437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        updateSeekBar(csrep);
30537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mView.invalidate();
30637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
30737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
30837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
30937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
31037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        FilterVignetteRepresentation rep = getVignetteRep();
31137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        int value = progress;
31237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        BasicParameterInt  p;
31337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        switch (sbar.getId()) {
31437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.mainVignetteSeekbar:
31537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                rep.setParameterMode(FilterVignetteRepresentation.MODE_VIGNETTE);
31637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                p = rep.getFilterParameter(rep.getParameterMode());
31737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                value += p.getMinimum();
31837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mVignetteValue.setText("" + value);
31937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                break;
32037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.exposureSeekBar:
32137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                rep.setParameterMode(FilterVignetteRepresentation.MODE_EXPOSURE);
32237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                p = rep.getFilterParameter(rep.getParameterMode());
32337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                value += p.getMinimum();
32437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mExposureValue.setText("" + value);
32537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                break;
32637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.saturationSeekBar:
32737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                rep.setParameterMode(FilterVignetteRepresentation.MODE_SATURATION);
32837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                p = rep.getFilterParameter(rep.getParameterMode());
32937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                value += p.getMinimum();
33037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mSaturationValue.setText("" + value);
33137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                break;
33237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.contrastSeekBar:
33337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                rep.setParameterMode(FilterVignetteRepresentation.MODE_CONTRAST);
33437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                p = rep.getFilterParameter(rep.getParameterMode());
33537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                value += p.getMinimum();
33637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mContrastValue.setText("" + value);
33737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                break;
33837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            case R.id.falloffSeekBar:
33937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                rep.setParameterMode(FilterVignetteRepresentation.MODE_FALLOFF);
34037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                p = rep.getFilterParameter(rep.getParameterMode());
34137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                value += p.getMinimum();
34237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mFalloffValue.setText("" + value);
34337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                break;
34437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        }
34537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        rep.setCurrentParameter(value);
34637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        commitLocalRepresentation();
34737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
34837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
34937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
35037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public void swapLeft(MenuItem item) {
35137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        super.swapLeft(item);
35237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.setTranslationX(0);
35337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.animate().translationX(mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION);
35437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        Runnable updateButton = new Runnable() {
35537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            @Override
35637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            public void run() {
35737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mButton.animate().cancel();
35837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mButton.setTranslationX(0);
35937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            }
36037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        };
36137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION);
36237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        selectMenuItem(item);
36337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    }
36437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford
36537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    @Override
36637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford    public void swapRight(MenuItem item) {
36737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        super.swapRight(item);
36837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.setTranslationX(0);
36937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mButton.animate().translationX(-mButton.getWidth()).setDuration(SwapButton.ANIM_DURATION);
37037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        Runnable updateButton = new Runnable() {
37137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            @Override
37237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            public void run() {
37337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mButton.animate().cancel();
37437f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford                mButton.setTranslationX(0);
37537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford            }
37637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        };
37737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        mHandler.postDelayed(updateButton, SwapButton.ANIM_DURATION);
37837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford        selectMenuItem(item);
379a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford    }
380a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford}
381