EditorColorBorder.java revision 49798939f1bc58eaf5842bbc8bc5424284ab7930
1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.gallery3d.filtershow.editors; 18 19import android.content.Context; 20import android.graphics.Bitmap; 21import android.graphics.BitmapFactory; 22import android.graphics.Color; 23import android.view.LayoutInflater; 24import android.view.MenuItem; 25import android.view.View; 26import android.view.View.OnClickListener; 27import android.view.ViewGroup; 28import android.widget.Button; 29import android.widget.FrameLayout; 30import android.widget.LinearLayout; 31import android.widget.PopupMenu; 32import android.widget.SeekBar; 33 34import com.android.gallery3d.R; 35import com.android.gallery3d.filtershow.controller.BitmapCaller; 36import com.android.gallery3d.filtershow.controller.ColorChooser; 37import com.android.gallery3d.filtershow.controller.FilterView; 38import com.android.gallery3d.filtershow.filters.FilterColorBorderRepresentation; 39import com.android.gallery3d.filtershow.filters.FilterRepresentation; 40import com.android.gallery3d.filtershow.filters.ImageFilterColorBorder; 41import com.android.gallery3d.filtershow.imageshow.ImageShow; 42 43public class EditorColorBorder extends ParametricEditor implements FilterView { 44 private static final String LOGTAG = "EditorColorBorder"; 45 public static final int ID = R.id.editorColorBorder; 46 47 int[] brushIcons = { 48 R.drawable.brush_flat, 49 R.drawable.brush_round, 50 R.drawable.brush_gauss, 51 R.drawable.brush_marker, 52 R.drawable.brush_spatter 53 }; 54 55 int[] mBasColors = { 56 FilterColorBorderRepresentation.DEFAULT_MENU_COLOR1, 57 FilterColorBorderRepresentation.DEFAULT_MENU_COLOR2, 58 FilterColorBorderRepresentation.DEFAULT_MENU_COLOR3, 59 FilterColorBorderRepresentation.DEFAULT_MENU_COLOR4, 60 FilterColorBorderRepresentation.DEFAULT_MENU_COLOR5, 61 }; 62 private EditorColorBorderTabletUI mTabletUI; 63 private String mParameterString; 64 private int mSelectedColorButton; 65 66 public EditorColorBorder() { 67 super(ID); 68 } 69 70 @Override 71 public String calculateUserMessage(Context context, String effectName, Object parameterValue) { 72 FilterColorBorderRepresentation rep = getColorBorderRep(); 73 if (rep == null) { 74 return ""; 75 } 76 if (mParameterString == null) { 77 mParameterString = ""; 78 } 79 String paramString; 80 String val = rep.getValueString(); 81 return mParameterString + val; 82 } 83 84 @Override 85 public void createEditor(Context context, FrameLayout frameLayout) { 86 mView = mImageShow = new ImageShow(context); 87 super.createEditor(context, frameLayout); 88 } 89 90 @Override 91 public void reflectCurrentFilter() { 92 super.reflectCurrentFilter(); 93 FilterRepresentation rep = getLocalRepresentation(); 94 if (rep != null && getLocalRepresentation() instanceof FilterColorBorderRepresentation) { 95 FilterColorBorderRepresentation cbRep = 96 (FilterColorBorderRepresentation) getLocalRepresentation(); 97 if (!ParametricEditor.useCompact(mContext)) { 98 if (mTabletUI != null) { 99 mTabletUI.setColorBorderRepresentation(cbRep); 100 } 101 return; 102 } 103 cbRep.setPramMode(FilterColorBorderRepresentation.PARAM_COLOR); 104 mParameterString = mContext.getString(R.string.color_border_color); 105 control(cbRep.getCurrentParam(), mEditControl); 106 } 107 } 108 109 @Override 110 public void openUtilityPanel(final LinearLayout accessoryViewList) { 111 Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect); 112 view.setText(mContext.getString(R.string.color_border_size)); 113 view.setOnClickListener(new OnClickListener() { 114 115 @Override 116 public void onClick(View arg0) { 117 showPopupMenu(accessoryViewList); 118 } 119 }); 120 } 121 122 @Override 123 public boolean showsSeekBar() { 124 return false; 125 } 126 127 private void showPopupMenu(LinearLayout accessoryViewList) { 128 final Button button = (Button) accessoryViewList.findViewById( 129 R.id.applyEffect); 130 if (button == null) { 131 return; 132 } 133 final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button); 134 popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_color_border, 135 popupMenu.getMenu()); 136 popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 137 138 @Override 139 public boolean onMenuItemClick(MenuItem item) { 140 selectMenuItem(item); 141 return true; 142 } 143 }); 144 popupMenu.show(); 145 } 146 147 protected void selectMenuItem(MenuItem item) { 148 ImageFilterColorBorder filter = (ImageFilterColorBorder) mImageShow.getCurrentFilter(); 149 FilterColorBorderRepresentation rep = getColorBorderRep(); 150 if (rep == null) { 151 return; 152 } 153 switch (item.getItemId()) { 154 case R.id.color_border_menu_clear: 155 clearFrame(); 156 break; 157 case R.id.color_border_menu_size: 158 rep.setPramMode(FilterColorBorderRepresentation.PARAM_SIZE); 159 break; 160 case R.id.color_border_menu_corner_size: 161 rep.setPramMode(FilterColorBorderRepresentation.PARAM_RADIUS); 162 break; 163 case R.id.color_border_menu_color: 164 rep.setPramMode(FilterColorBorderRepresentation.PARAM_COLOR); 165 break; 166 } 167 if (item.getItemId() != R.id.color_border_menu_clear) { 168 mParameterString = item.getTitle().toString(); 169 } 170 if (mControl instanceof ColorChooser) { 171 ColorChooser c = (ColorChooser) mControl; 172 mBasColors = c.getColorSet(); 173 } 174 control(rep.getCurrentParam(), mEditControl); 175 if (mControl instanceof ColorChooser) { 176 ColorChooser c = (ColorChooser) mControl; 177 c.setColorSet(mBasColors); 178 } 179 mControl.updateUI(); 180 mView.invalidate(); 181 } 182 183 public void clearFrame() { 184 commitLocalRepresentation(); 185 } 186 187 @Override 188 public void setUtilityPanelUI(View actionButton, View editControl) { 189 if (ParametricEditor.useCompact(mContext)) { 190 super.setUtilityPanelUI(actionButton, editControl); 191 return; 192 } 193 mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar); 194 if (mSeekBar != null) { 195 mSeekBar.setVisibility(View.GONE); 196 } 197 198 mTabletUI = new EditorColorBorderTabletUI(this, mContext, editControl); 199 200 } 201 202 FilterColorBorderRepresentation getColorBorderRep() { 203 FilterRepresentation rep = getLocalRepresentation(); 204 if (rep instanceof FilterColorBorderRepresentation) { 205 return (FilterColorBorderRepresentation) rep; 206 } 207 return null; 208 } 209 210 @Override 211 public void computeIcon(int index, BitmapCaller caller) { 212 Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), brushIcons[index]); 213 caller.available(bitmap); 214 } 215 216 public int getBrushIcon(int type) { 217 return brushIcons[type]; 218 } 219 220} 221