EditorColorBorder.java revision 49798939f1bc58eaf5842bbc8bc5424284ab7930
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; 2349798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.LayoutInflater; 2449798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.MenuItem; 2549798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.View; 2649798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.View.OnClickListener; 2749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.ViewGroup; 2849798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.Button; 2949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.FrameLayout; 3049798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.LinearLayout; 3149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.PopupMenu; 3249798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.SeekBar; 3349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 3449798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.R; 3549798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.BitmapCaller; 3649798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.ColorChooser; 3749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.FilterView; 3849798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.filters.FilterColorBorderRepresentation; 3949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.filters.FilterRepresentation; 4049798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterColorBorder; 4149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.imageshow.ImageShow; 4249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 4349798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordpublic class EditorColorBorder extends ParametricEditor implements FilterView { 4449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private static final String LOGTAG = "EditorColorBorder"; 4549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public static final int ID = R.id.editorColorBorder; 4649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 4749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford int[] brushIcons = { 4849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford R.drawable.brush_flat, 4949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford R.drawable.brush_round, 5049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford R.drawable.brush_gauss, 5149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford R.drawable.brush_marker, 5249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford R.drawable.brush_spatter 5349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford }; 5449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 5549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford int[] mBasColors = { 5649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR1, 5749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR2, 5849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR3, 5949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR4, 6049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation.DEFAULT_MENU_COLOR5, 6149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford }; 6249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private EditorColorBorderTabletUI mTabletUI; 6349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private String mParameterString; 6449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private int mSelectedColorButton; 6549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 6649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public EditorColorBorder() { 6749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford super(ID); 6849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 6949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 7049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 7149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public String calculateUserMessage(Context context, String effectName, Object parameterValue) { 7249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation rep = getColorBorderRep(); 7349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (rep == null) { 7449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return ""; 7549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 7649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mParameterString == null) { 7749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mParameterString = ""; 7849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 7949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford String paramString; 8049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford String val = rep.getValueString(); 8149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return mParameterString + val; 8249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 8349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 8449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 8549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void createEditor(Context context, FrameLayout frameLayout) { 8649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mView = mImageShow = new ImageShow(context); 8749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford super.createEditor(context, frameLayout); 8849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 8949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 9049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 9149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void reflectCurrentFilter() { 9249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford super.reflectCurrentFilter(); 9349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterRepresentation rep = getLocalRepresentation(); 9449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (rep != null && getLocalRepresentation() instanceof FilterColorBorderRepresentation) { 9549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation cbRep = 9649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford (FilterColorBorderRepresentation) getLocalRepresentation(); 9749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (!ParametricEditor.useCompact(mContext)) { 9849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mTabletUI != null) { 9949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mTabletUI.setColorBorderRepresentation(cbRep); 10049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 10149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return; 10249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 10349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford cbRep.setPramMode(FilterColorBorderRepresentation.PARAM_COLOR); 10449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mParameterString = mContext.getString(R.string.color_border_color); 10549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford control(cbRep.getCurrentParam(), mEditControl); 10649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 10749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 10849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 10949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 11049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void openUtilityPanel(final LinearLayout accessoryViewList) { 11149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); 11249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford view.setText(mContext.getString(R.string.color_border_size)); 11349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford view.setOnClickListener(new OnClickListener() { 11449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 11549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 11649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void onClick(View arg0) { 11749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford showPopupMenu(accessoryViewList); 11849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 11949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford }); 12049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 12149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 12249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 12349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public boolean showsSeekBar() { 12449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return false; 12549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 12649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 12749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford private void showPopupMenu(LinearLayout accessoryViewList) { 12849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford final Button button = (Button) accessoryViewList.findViewById( 12949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford R.id.applyEffect); 13049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (button == null) { 13149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return; 13249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 13349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button); 13449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_color_border, 13549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.getMenu()); 13649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 13749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 13849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford @Override 13949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public boolean onMenuItemClick(MenuItem item) { 14049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford selectMenuItem(item); 14149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return true; 14249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 14349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford }); 14449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford popupMenu.show(); 14549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 14649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 14749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford protected void selectMenuItem(MenuItem item) { 14849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford ImageFilterColorBorder filter = (ImageFilterColorBorder) mImageShow.getCurrentFilter(); 14949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford FilterColorBorderRepresentation rep = getColorBorderRep(); 15049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (rep == null) { 15149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return; 15249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 15349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford switch (item.getItemId()) { 15449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_clear: 15549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford clearFrame(); 15649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 15749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_size: 15849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford rep.setPramMode(FilterColorBorderRepresentation.PARAM_SIZE); 15949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 16049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_corner_size: 16149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford rep.setPramMode(FilterColorBorderRepresentation.PARAM_RADIUS); 16249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 16349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford case R.id.color_border_menu_color: 16449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford rep.setPramMode(FilterColorBorderRepresentation.PARAM_COLOR); 16549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford break; 16649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 16749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (item.getItemId() != R.id.color_border_menu_clear) { 16849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mParameterString = item.getTitle().toString(); 16949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 17049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mControl instanceof ColorChooser) { 17149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford ColorChooser c = (ColorChooser) mControl; 17249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford mBasColors = c.getColorSet(); 17349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 17449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford control(rep.getCurrentParam(), mEditControl); 17549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford if (mControl instanceof ColorChooser) { 17649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford ColorChooser c = (ColorChooser) mControl; 17749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford c.setColorSet(mBasColors); 17849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 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 @Override 21149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public void computeIcon(int index, BitmapCaller caller) { 21249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), brushIcons[index]); 21349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford caller.available(bitmap); 21449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 21549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 21649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford public int getBrushIcon(int type) { 21749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford return brushIcons[type]; 21849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford } 21949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford 22049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford} 221