149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford/* 249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * Copyright (C) 2013 The Android Open Source Project 349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * 449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * you may not use this file except in compliance with the License. 649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * You may obtain a copy of the License at 749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * 849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * http://www.apache.org/licenses/LICENSE-2.0 949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * 1049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * Unless required by applicable law or agreed to in writing, software 1149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 1249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * See the License for the specific language governing permissions and 1449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * limitations under the License. 1549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford */ 1649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 1749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordpackage com.android.gallery3d.filtershow.editors; 1849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 1949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.content.Context; 2049798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.graphics.Bitmap; 2149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.graphics.BitmapFactory; 2249798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.graphics.Color; 23ae068f80895d7d075064a5ded59069425b72271fJohn Hofordimport android.util.Log; 2449798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.LayoutInflater; 2549798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.MenuItem; 2649798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.View; 2749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.View.OnClickListener; 2849798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.ViewGroup; 2949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.Button; 3049798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.FrameLayout; 3149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.LinearLayout; 3249798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.PopupMenu; 3349798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.SeekBar; 3449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 3549798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.R; 3664fc2ed005e2f1dc9ed0b34481c46a370c244b86John Hofordimport com.android.gallery3d.filtershow.FilterShowActivity; 3749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.BitmapCaller; 3849798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.ColorChooser; 3949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.FilterView; 4049798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.filters.FilterColorBorderRepresentation; 4149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.filters.FilterRepresentation; 4249798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterColorBorder; 4349798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageShow; 4449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 45ae068f80895d7d075064a5ded59069425b72271fJohn Hofordpublic class EditorColorBorder extends ParametricEditor { 4649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private static final String LOGTAG = "EditorColorBorder"; 4749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public static final int ID = R.id.editorColorBorder; 4849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 4949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford int[] mBasColors = { 5049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR1, 5149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR2, 5249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR3, 5349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR4, 5449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR5, 5549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford }; 5649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private EditorColorBorderTabletUI mTabletUI; 5749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private String mParameterString; 5849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private int mSelectedColorButton; 5949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 6049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public EditorColorBorder() { 6149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford super(ID); 6249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 6349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 6449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 6549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public String calculateUserMessage(Context context, String effectName, Object parameterValue) { 6649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation rep = getColorBorderRep(); 6749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (rep == null) { 6849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return ""; 6949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 7049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mParameterString == null) { 7149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mParameterString = ""; 7249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 7349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford String paramString; 7449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford String val = rep.getValueString(); 7549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return mParameterString + val; 7649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 7749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 7849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 7949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void createEditor(Context context, FrameLayout frameLayout) { 8049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mView = mImageShow = new ImageShow(context); 8149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford super.createEditor(context, frameLayout); 8249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 8349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 8449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 8549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void reflectCurrentFilter() { 8649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford super.reflectCurrentFilter(); 8749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterRepresentation rep = getLocalRepresentation(); 8849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (rep != null && getLocalRepresentation() instanceof FilterColorBorderRepresentation) { 8949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation cbRep = 9049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford (FilterColorBorderRepresentation) getLocalRepresentation(); 9149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (!ParametricEditor.useCompact(mContext)) { 9249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mTabletUI != null) { 9349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mTabletUI.setColorBorderRepresentation(cbRep); 9449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 95ae068f80895d7d075064a5ded59069425b72271fJohn Hoford 96ae068f80895d7d075064a5ded59069425b72271fJohn Hoford } 97ae068f80895d7d075064a5ded59069425b72271fJohn Hoford cbRep.setPramMode(FilterColorBorderRepresentation.PARAM_SIZE); 98ae068f80895d7d075064a5ded59069425b72271fJohn Hoford mParameterString = mContext.getString(R.string.color_border_size); 99ae068f80895d7d075064a5ded59069425b72271fJohn Hoford if (mEditControl != null) { 100ae068f80895d7d075064a5ded59069425b72271fJohn Hoford control(cbRep.getCurrentParam(), mEditControl); 10149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 10249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 10349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 10449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 10549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 10649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void openUtilityPanel(final LinearLayout accessoryViewList) { 10749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); 10849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford view.setText(mContext.getString(R.string.color_border_size)); 10949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford view.setOnClickListener(new OnClickListener() { 11049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 11149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 11249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void onClick(View arg0) { 11349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford showPopupMenu(accessoryViewList); 11449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 11549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford }); 11649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 11749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 11849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 11949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public boolean showsSeekBar() { 12049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return false; 12149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 12249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 12349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private void showPopupMenu(LinearLayout accessoryViewList) { 12449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford final Button button = (Button) accessoryViewList.findViewById( 12549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford R.id.applyEffect); 12649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (button == null) { 12749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return; 12849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 12949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button); 13049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_color_border, 13149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.getMenu()); 13249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 13349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 13449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 13549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public boolean onMenuItemClick(MenuItem item) { 13649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford selectMenuItem(item); 13749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return true; 13849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 13949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford }); 14049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.show(); 14164fc2ed005e2f1dc9ed0b34481c46a370c244b86John Hoford ((FilterShowActivity)mContext).onShowMenu(popupMenu); 14249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 14349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 14449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford protected void selectMenuItem(MenuItem item) { 14549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford ImageFilterColorBorder filter = (ImageFilterColorBorder) mImageShow.getCurrentFilter(); 14649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation rep = getColorBorderRep(); 14749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (rep == null) { 14849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return; 14949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 15049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford switch (item.getItemId()) { 15149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_clear: 15249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford clearFrame(); 15349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 15449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_size: 15549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford rep.setPramMode(FilterColorBorderRepresentation.PARAM_SIZE); 15649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 15749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_corner_size: 15849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford rep.setPramMode(FilterColorBorderRepresentation.PARAM_RADIUS); 15949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 16049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_color: 16149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford rep.setPramMode(FilterColorBorderRepresentation.PARAM_COLOR); 16249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 16349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 16449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (item.getItemId() != R.id.color_border_menu_clear) { 16549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mParameterString = item.getTitle().toString(); 16649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 16749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mControl instanceof ColorChooser) { 16849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford ColorChooser c = (ColorChooser) mControl; 16949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mBasColors = c.getColorSet(); 17049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 1717c25883d177ded2555b907258203bef0fda41487nicolasroard if (mEditControl != null) { 1727c25883d177ded2555b907258203bef0fda41487nicolasroard control(rep.getCurrentParam(), mEditControl); 1737c25883d177ded2555b907258203bef0fda41487nicolasroard } 17449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mControl instanceof ColorChooser) { 17549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford ColorChooser c = (ColorChooser) mControl; 17649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford c.setColorSet(mBasColors); 17749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 178ae068f80895d7d075064a5ded59069425b72271fJohn Hoford updateText(); 17949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mControl.updateUI(); 18049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mView.invalidate(); 18149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 18249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 18349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void clearFrame() { 18449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford commitLocalRepresentation(); 18549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 18649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 18749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 18849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void setUtilityPanelUI(View actionButton, View editControl) { 18949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (ParametricEditor.useCompact(mContext)) { 19049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford super.setUtilityPanelUI(actionButton, editControl); 19149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return; 19249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 19349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar); 19449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mSeekBar != null) { 19549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mSeekBar.setVisibility(View.GONE); 19649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 19749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 19849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mTabletUI = new EditorColorBorderTabletUI(this, mContext, editControl); 19949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 20049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 20149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 20249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation getColorBorderRep() { 20349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterRepresentation rep = getLocalRepresentation(); 20449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (rep instanceof FilterColorBorderRepresentation) { 20549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return (FilterColorBorderRepresentation) rep; 20649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 20749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return null; 20849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 20949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 21049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 21149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford} 212