1e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford/* 2e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * Copyright (C) 2013 The Android Open Source Project 3e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * 4e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 5e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * you may not use this file except in compliance with the License. 6e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * You may obtain a copy of the License at 7e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * 8e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * http://www.apache.org/licenses/LICENSE-2.0 9e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * 10e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * Unless required by applicable law or agreed to in writing, software 11e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 12e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * See the License for the specific language governing permissions and 14e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford * limitations under the License. 15e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford */ 16e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordpackage com.android.gallery3d.filtershow.editors; 17e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 18e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.content.Context; 190b33ef03f2023a49d82cd608d79bb9b59c791e06John Hofordimport android.view.LayoutInflater; 20e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.view.MenuItem; 21e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.view.View; 22e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.view.View.OnClickListener; 230b33ef03f2023a49d82cd608d79bb9b59c791e06John Hofordimport android.view.ViewGroup; 24e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.widget.Button; 25e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.widget.FrameLayout; 26e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.widget.LinearLayout; 27e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.widget.PopupMenu; 28e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.widget.SeekBar; 29e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.widget.SeekBar.OnSeekBarChangeListener; 300b33ef03f2023a49d82cd608d79bb9b59c791e06John Hofordimport android.widget.TextView; 31e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport android.widget.ToggleButton; 32e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 33e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.R; 3464fc2ed005e2f1dc9ed0b34481c46a370c244b86John Hofordimport com.android.gallery3d.filtershow.FilterShowActivity; 35e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.controller.Control; 36e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.controller.FilterView; 37e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.controller.Parameter; 38e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.controller.ParameterActionAndInt; 39e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.filters.FilterGradRepresentation; 40e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.filters.FilterRepresentation; 41e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageGrad; 42e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordimport com.android.gallery3d.filtershow.imageshow.MasterImage; 43e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 44e162b032fe387eabbd69d367dae6fe7003e850a1John Hofordpublic class EditorGrad extends ParametricEditor 45e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford implements OnSeekBarChangeListener, ParameterActionAndInt { 46e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private static final String LOGTAG = "EditorGrad"; 47e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public static final int ID = R.id.editorGrad; 48e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford PopupMenu mPopupMenu; 49e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford ToggleButton mAddModeButton; 50e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford String mEffectName = ""; 51e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private static final int MODE_BRIGHTNESS = FilterGradRepresentation.PARAM_BRIGHTNESS; 52e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private static final int MODE_SATURATION = FilterGradRepresentation.PARAM_SATURATION; 53e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private static final int MODE_CONTRAST = FilterGradRepresentation.PARAM_CONTRAST; 54e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private static final int ADD_ICON = R.drawable.ic_grad_add; 55e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private static final int DEL_ICON = R.drawable.ic_grad_del; 56e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private int mSliderMode = MODE_BRIGHTNESS; 57e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford ImageGrad mImageGrad; 580b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford ParamAdapter []mAdapters = new ParamAdapter[3]; 59e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public EditorGrad() { 60e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford super(ID, R.layout.filtershow_grad_editor, R.id.gradEditor); 61e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 62e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 63e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 64e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void createEditor(Context context, FrameLayout frameLayout) { 65e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford super.createEditor(context, frameLayout); 66e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mImageGrad = (ImageGrad) mImageShow; 67e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mImageGrad.setEditor(this); 68e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 69e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 70e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 71e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void clearAddMode() { 72e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mAddModeButton.setChecked(false); 73e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterRepresentation tmpRep = getLocalRepresentation(); 74e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (tmpRep instanceof FilterGradRepresentation) { 75e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateMenuItems((FilterGradRepresentation) tmpRep); 76e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 77e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 78e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 79e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 80e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void reflectCurrentFilter() { 81e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford super.reflectCurrentFilter(); 82e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterRepresentation tmpRep = getLocalRepresentation(); 83e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (tmpRep instanceof FilterGradRepresentation) { 84e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; 85e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford boolean f = rep.showParameterValue(); 86e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 87e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mImageGrad.setRepresentation(rep); 88e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 89e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 90e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 91e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void updateSeekBar(FilterGradRepresentation rep) { 920b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford if (ParametricEditor.useCompact(mContext)) { 930b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mControl.updateUI(); 940b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } else { 950b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford updateParameters(); 960b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 97e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 98e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 99e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 100e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { 101e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterRepresentation tmpRep = getLocalRepresentation(); 102e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (tmpRep instanceof FilterGradRepresentation) { 103e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; 104e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford int min = rep.getParameterMin(mSliderMode); 105e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford int value = progress + min; 106e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford rep.setParameter(mSliderMode, value); 107e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mView.invalidate(); 108e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford commitLocalRepresentation(); 109e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 110e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 111e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 112e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 113e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void openUtilityPanel(final LinearLayout accessoryViewList) { 114e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); 1151304be5806124591d1d6c5c632700ca0361b1431John Hoford if (useCompact(mContext)) { 1161304be5806124591d1d6c5c632700ca0361b1431John Hoford view.setText(mContext.getString(R.string.editor_grad_brightness)); 1171304be5806124591d1d6c5c632700ca0361b1431John Hoford view.setOnClickListener(new OnClickListener() { 1181304be5806124591d1d6c5c632700ca0361b1431John Hoford @Override 1191304be5806124591d1d6c5c632700ca0361b1431John Hoford public void onClick(View arg0) { 1201304be5806124591d1d6c5c632700ca0361b1431John Hoford showPopupMenu(accessoryViewList); 1211304be5806124591d1d6c5c632700ca0361b1431John Hoford } 1221304be5806124591d1d6c5c632700ca0361b1431John Hoford }); 1231304be5806124591d1d6c5c632700ca0361b1431John Hoford 1241304be5806124591d1d6c5c632700ca0361b1431John Hoford setUpPopupMenu(view); 1251304be5806124591d1d6c5c632700ca0361b1431John Hoford setEffectName(); 1261304be5806124591d1d6c5c632700ca0361b1431John Hoford } else { 1271304be5806124591d1d6c5c632700ca0361b1431John Hoford view.setText(mContext.getString(R.string.grad)); 1281304be5806124591d1d6c5c632700ca0361b1431John Hoford } 129e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 130e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 131e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private void updateMenuItems(FilterGradRepresentation rep) { 132e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford int n = rep.getNumberOfBands(); 133e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 134e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 135e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void setEffectName() { 136e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (mPopupMenu != null) { 137e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford MenuItem item = mPopupMenu.getMenu().findItem(R.id.editor_grad_brightness); 138e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mEffectName = item.getTitle().toString(); 139e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 140e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 141e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 1420b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford @Override 1430b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void setUtilityPanelUI(View actionButton, View editControl) { 1440b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford if (ParametricEditor.useCompact(mContext)) { 1450b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford super.setUtilityPanelUI(actionButton, editControl); 1460b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford return; 1470b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 1480b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar); 1490b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford if (mSeekBar != null) { 1500b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mSeekBar.setVisibility(View.GONE); 1510b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 1520b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford LayoutInflater inflater = 1530b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 1540b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford LinearLayout lp = (LinearLayout) inflater.inflate( 1550b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford R.layout.filtershow_grad_ui, (ViewGroup) editControl, true); 1560b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 1570b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mAdapters[0] = new ParamAdapter(R.id.gradContrastSeekBar, R.id.gradContrastValue, 1580b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford lp, MODE_CONTRAST); 1590b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mAdapters[1] = new ParamAdapter(R.id.gradBrightnessSeekBar, R.id.gradBrightnessValue, 1600b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford lp, MODE_BRIGHTNESS); 1610b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mAdapters[2] = new ParamAdapter(R.id.gradSaturationSeekBar, R.id.gradSaturationValue, 1620b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford lp, MODE_SATURATION); 1630b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford lp.findViewById(R.id.gradAddButton).setOnClickListener(new OnClickListener() { 1640b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford @Override 1650b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void onClick(View view) { 1660b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford fireLeftAction(); 1670b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 1680b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford }); 1690b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford lp.findViewById(R.id.gradDelButton).setOnClickListener(new OnClickListener() { 1700b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford @Override 1710b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void onClick(View view) { 1720b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford fireRightAction(); 1730b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 1740b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford }); 1751304be5806124591d1d6c5c632700ca0361b1431John Hoford setMenuIcon(false); 1760b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 1770b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 1780b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void updateParameters() { 1790b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford FilterGradRepresentation rep = getGradRepresentation(); 1800b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford for (int i = 0; i < mAdapters.length; i++) { 1810b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mAdapters[i].updateValues(rep); 1820b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 1830b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 1840b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 1850b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford private class ParamAdapter implements OnSeekBarChangeListener { 1860b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford SeekBar mSlider; 1870b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford TextView mTextView; 1880b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford int mMin = -100; 1890b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford int mMax = 100; 1900b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford int mMode; 1910b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 1920b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public ParamAdapter(int seekId, int textId, LinearLayout layout, int mode) { 1930b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mSlider = (SeekBar) layout.findViewById(seekId); 1940b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mTextView = (TextView) layout.findViewById(textId); 1950b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mSlider.setMax(mMax - mMin); 1960b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mMode = mode; 1970b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford FilterGradRepresentation rep = getGradRepresentation(); 1980b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford if (rep != null){ 1990b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford updateValues(rep); 2000b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 2019029a469b47605420454e0c74d46adeccf4ef94aJohn Hoford mSlider.setOnSeekBarChangeListener(this); 2020b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 2030b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 2040b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void updateValues(FilterGradRepresentation rep) { 2050b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford int value = rep.getParameter(mMode); 2060b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mTextView.setText(Integer.toString(value)); 2070b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mSlider.setProgress(value - mMin); 2080b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 2090b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 2100b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford @Override 2110b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 2120b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford FilterGradRepresentation rep = getGradRepresentation(); 2130b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford int value = progress + mMin; 2140b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford rep.setParameter(mMode, value); 2151304be5806124591d1d6c5c632700ca0361b1431John Hoford if (mSliderMode != mMode) { 2161304be5806124591d1d6c5c632700ca0361b1431John Hoford mSliderMode = mMode; 2171304be5806124591d1d6c5c632700ca0361b1431John Hoford mEffectName = mContext.getResources().getString(getModeNameid(mMode)); 2181304be5806124591d1d6c5c632700ca0361b1431John Hoford mEffectName = mEffectName.toUpperCase(); 2191304be5806124591d1d6c5c632700ca0361b1431John Hoford } 2200b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mTextView.setText(Integer.toString(value)); 2210b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford mView.invalidate(); 2220b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford commitLocalRepresentation(); 2230b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 2240b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 2251304be5806124591d1d6c5c632700ca0361b1431John Hoford private int getModeNameid(int mode) { 2261304be5806124591d1d6c5c632700ca0361b1431John Hoford switch (mode) { 2271304be5806124591d1d6c5c632700ca0361b1431John Hoford case MODE_CONTRAST: 2281304be5806124591d1d6c5c632700ca0361b1431John Hoford return R.string.editor_grad_contrast; 2291304be5806124591d1d6c5c632700ca0361b1431John Hoford case MODE_BRIGHTNESS: 2301304be5806124591d1d6c5c632700ca0361b1431John Hoford return R.string.editor_grad_brightness; 2311304be5806124591d1d6c5c632700ca0361b1431John Hoford case MODE_SATURATION: 2321304be5806124591d1d6c5c632700ca0361b1431John Hoford return R.string.editor_grad_saturation; 2331304be5806124591d1d6c5c632700ca0361b1431John Hoford } 2341304be5806124591d1d6c5c632700ca0361b1431John Hoford return 0; 2351304be5806124591d1d6c5c632700ca0361b1431John Hoford } 2361304be5806124591d1d6c5c632700ca0361b1431John Hoford 2370b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford @Override 2380b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void onStartTrackingTouch(SeekBar seekBar) { 2390b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 2400b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 2410b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 2420b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford @Override 2430b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford public void onStopTrackingTouch(SeekBar seekBar) { 2440b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 2450b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 2460b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford } 2470b33ef03f2023a49d82cd608d79bb9b59c791e06John Hoford 248e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private void showPopupMenu(LinearLayout accessoryViewList) { 249e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect); 250e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (button == null) { 251e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return; 252e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 253e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 254e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (mPopupMenu == null) { 255e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford setUpPopupMenu(button); 256e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 257e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mPopupMenu.show(); 25864fc2ed005e2f1dc9ed0b34481c46a370c244b86John Hoford ((FilterShowActivity)mContext).onShowMenu(mPopupMenu); 259e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 260e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 261e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private void setUpPopupMenu(Button button) { 262e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mPopupMenu = new PopupMenu(mImageShow.getActivity(), button); 263e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mPopupMenu.getMenuInflater() 264e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford .inflate(R.menu.filtershow_menu_grad, mPopupMenu.getMenu()); 265e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = (FilterGradRepresentation) getLocalRepresentation(); 266e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 267e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return; 268e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 269e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateMenuItems(rep); 270e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford hackFixStrings(mPopupMenu.getMenu()); 271e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford setEffectName(); 272e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateText(); 273e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 274e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 275e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 276e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public boolean onMenuItemClick(MenuItem item) { 277e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterRepresentation tmpRep = getLocalRepresentation(); 278e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 279e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (tmpRep instanceof FilterGradRepresentation) { 280e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = (FilterGradRepresentation) tmpRep; 281e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford int cmdID = item.getItemId(); 282e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford switch (cmdID) { 283e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford case R.id.editor_grad_brightness: 284e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mSliderMode = MODE_BRIGHTNESS; 285e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mEffectName = item.getTitle().toString(); 286e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford break; 287e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford case R.id.editor_grad_contrast: 288e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mSliderMode = MODE_CONTRAST; 289e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mEffectName = item.getTitle().toString(); 290e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford break; 291e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford case R.id.editor_grad_saturation: 292e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mSliderMode = MODE_SATURATION; 293e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mEffectName = item.getTitle().toString(); 294e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford break; 295e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 296e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateMenuItems(rep); 297e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateSeekBar(rep); 298e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 299e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford commitLocalRepresentation(); 300e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mView.invalidate(); 301e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 302e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return true; 303e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 304e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford }); 305e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 306e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 307e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 308e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public String calculateUserMessage(Context context, String effectName, Object parameterValue) { 309e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = getGradRepresentation(); 310e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 311e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return mEffectName; 312e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 313e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford int val = rep.getParameter(mSliderMode); 314e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return mEffectName.toUpperCase() + ((val > 0) ? " +" : " ") + val; 315e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 316e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 317e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford private FilterGradRepresentation getGradRepresentation() { 318e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterRepresentation tmpRep = getLocalRepresentation(); 319e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (tmpRep instanceof FilterGradRepresentation) { 320e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return (FilterGradRepresentation) tmpRep; 321e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 322e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return null; 323e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 324e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 325e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 326e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public int getMaximum() { 327e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = getGradRepresentation(); 328e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 329e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return 0; 330e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 331e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return rep.getParameterMax(mSliderMode); 332e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 333e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 334e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 335e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public int getMinimum() { 336e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = getGradRepresentation(); 337e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 338e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return 0; 339e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 340e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return rep.getParameterMin(mSliderMode); 341e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 342e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 343e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 344e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public int getDefaultValue() { 345e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return 0; 346e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 347e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 348e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 349e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public int getValue() { 350e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = getGradRepresentation(); 351e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 352e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return 0; 353e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 354e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return rep.getParameter(mSliderMode); 355e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 356e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 357e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 358e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public String getValueString() { 359e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return null; 360e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 361e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 362e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 363e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void setValue(int value) { 364e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = getGradRepresentation(); 365e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 366e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return; 367e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 368e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford rep.setParameter(mSliderMode, value); 369e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 370e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 371e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 372e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public String getParameterName() { 373e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return mEffectName; 374e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 375e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 376e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 377e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public String getParameterType() { 378e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return sParameterType; 379e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 380e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 381e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 382e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void setController(Control c) { 383e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 384e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 385e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 386e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 387e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void fireLeftAction() { 388e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = getGradRepresentation(); 389e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 390e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return; 391e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 392e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford rep.addBand(MasterImage.getImage().getOriginalBounds()); 393e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateMenuItems(rep); 394e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateSeekBar(rep); 395e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 396e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford commitLocalRepresentation(); 397e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mView.invalidate(); 398e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 399e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 400e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 401e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public int getLeftIcon() { 402e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return ADD_ICON; 403e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 404e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 405e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 406e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void fireRightAction() { 407e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford FilterGradRepresentation rep = getGradRepresentation(); 408e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford if (rep == null) { 409e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return; 410e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 411e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford rep.deleteCurrentBand(); 412e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 413e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateMenuItems(rep); 414e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford updateSeekBar(rep); 415e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford commitLocalRepresentation(); 416e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford mView.invalidate(); 417e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 418e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 419e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 420e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public int getRightIcon() { 421e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford return DEL_ICON; 422e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 423e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 424e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 425e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void setFilterView(FilterView editor) { 426e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 427e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 428e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 429e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford @Override 430e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford public void copyFrom(Parameter src) { 431e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford 432e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford } 433e162b032fe387eabbd69d367dae6fe7003e850a1John Hoford} 434