2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.filtershow.editors;
19 import android.app.ActionBar;
20 import android.content.Context;
21 import android.content.res.Resources;
22 import android.graphics.Bitmap;
23 import android.graphics.BitmapFactory;
24 import android.graphics.Color;
25 import android.graphics.drawable.GradientDrawable;
26 import android.view.LayoutInflater;
27 import android.view.MenuItem;
28 import android.view.View;
29 import android.view.View.OnClickListener;
30 import android.view.ViewGroup;
31 import android.widget.Button;
32 import android.widget.FrameLayout;
33 import android.widget.ImageButton;
34 import android.widget.ImageView;
35 import android.widget.LinearLayout;
36 import android.widget.PopupMenu;
37 import android.widget.SeekBar;
39 import com.android.gallery3d.R;
40 import com.android.gallery3d.filtershow.colorpicker.ColorHueView;
41 import com.android.gallery3d.filtershow.colorpicker.ColorListener;
42 import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
43 import com.android.gallery3d.filtershow.colorpicker.ColorSVRectView;
44 import com.android.gallery3d.filtershow.controller.BitmapCaller;
45 import com.android.gallery3d.filtershow.controller.ColorChooser;
46 import com.android.gallery3d.filtershow.controller.FilterView;
47 import com.android.gallery3d.filtershow.controller.ParameterColor;
48 import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation;
49 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
50 import com.android.gallery3d.filtershow.filters.ImageFilterDraw;
51 import com.android.gallery3d.filtershow.imageshow.ImageDraw;
53 public class EditorDraw extends ParametricEditor implements FilterView {
54 private static final String LOGTAG = "EditorDraw";
55 public static final int ID = R.id.editorDraw;
56 public ImageDraw mImageDraw;
57 private static final int MODE_SIZE = FilterDrawRepresentation.PARAM_SIZE;
58 private static final int MODE_SIZEE = FilterDrawRepresentation.PARAM_SIZE;
59 private static final int MODE_STYLE = FilterDrawRepresentation.PARAM_STYLE;
60 private static final int MODE_COLOR = FilterDrawRepresentation.PARAM_COLOR;
62 R.drawable.brush_flat,
63 R.drawable.brush_round,
64 R.drawable.brush_gauss,
65 R.drawable.brush_marker,
66 R.drawable.brush_spatter
70 FilterDrawRepresentation.DEFAULT_MENU_COLOR1,
71 FilterDrawRepresentation.DEFAULT_MENU_COLOR2,
72 FilterDrawRepresentation.DEFAULT_MENU_COLOR3,
73 FilterDrawRepresentation.DEFAULT_MENU_COLOR4,
74 FilterDrawRepresentation.DEFAULT_MENU_COLOR5,
76 private EditorDrawTabletUI mTabletUI;
77 private String mParameterString;
78 private int mSelectedColorButton;
85 public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
86 FilterDrawRepresentation rep = getDrawRep();
90 if (mParameterString == null) {
91 mParameterString = "";
94 String val = rep.getValueString();
96 mImageDraw.displayDrawLook();
97 return mParameterString + val;
101 public void createEditor(Context context, FrameLayout frameLayout) {
102 mView = mImageShow = mImageDraw = new ImageDraw(context);
103 super.createEditor(context, frameLayout);
104 mImageDraw.setEditor(this);
109 public void reflectCurrentFilter() {
110 super.reflectCurrentFilter();
111 FilterRepresentation rep = getLocalRepresentation();
112 if (rep != null && getLocalRepresentation() instanceof FilterDrawRepresentation) {
113 FilterDrawRepresentation drawRep = (FilterDrawRepresentation) getLocalRepresentation();
114 mImageDraw.setFilterDrawRepresentation(drawRep);
115 if (!ParametricEditor.useCompact(mContext)) {
116 if (mTabletUI != null) {
118 mTabletUI.setDrawRepresentation(drawRep);
123 drawRep.getParam(FilterDrawRepresentation.PARAM_STYLE).setFilterView(this);
124 drawRep.setPramMode(FilterDrawRepresentation.PARAM_COLOR);
125 mParameterString = mContext.getString(R.string.draw_hue);
126 control(drawRep.getCurrentParam(), mEditControl);
131 public void openUtilityPanel(final LinearLayout accessoryViewList) {
132 Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
133 view.setText(mContext.getString(R.string.draw_hue));
134 view.setOnClickListener(new OnClickListener() {
137 public void onClick(View arg0) {
138 showPopupMenu(accessoryViewList);
144 public boolean showsSeekBar() {
148 private void showPopupMenu(LinearLayout accessoryViewList) {
149 final Button button = (Button) accessoryViewList.findViewById(
151 if (button == null) {
154 final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button);
155 popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_draw, popupMenu.getMenu());
156 popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
159 public boolean onMenuItemClick(MenuItem item) {
160 selectMenuItem(item);
168 protected void selectMenuItem(MenuItem item) {
169 ImageFilterDraw filter = (ImageFilterDraw) mImageShow.getCurrentFilter();
170 FilterDrawRepresentation rep = getDrawRep();
175 switch (item.getItemId()) {
176 case R.id.draw_menu_clear:
179 case R.id.draw_menu_size:
180 rep.setPramMode(FilterDrawRepresentation.PARAM_SIZE);
182 case R.id.draw_menu_style:
183 rep.setPramMode(FilterDrawRepresentation.PARAM_STYLE);
185 case R.id.draw_menu_color:
186 rep.setPramMode(FilterDrawRepresentation.PARAM_COLOR);
189 if (item.getItemId() != R.id.draw_menu_clear) {
190 mParameterString = item.getTitle().toString();
192 if (mControl instanceof ColorChooser) {
193 ColorChooser c = (ColorChooser) mControl;
194 mBasColors = c.getColorSet();
196 control(rep.getCurrentParam(), mEditControl);
197 if (mControl instanceof ColorChooser) {
198 ColorChooser c = (ColorChooser) mControl;
199 c.setColorSet(mBasColors);
205 public void clearDrawing(){
206 ImageDraw idraw = (ImageDraw) mImageShow;
207 idraw.resetParameter();
208 commitLocalRepresentation();
212 public void setUtilityPanelUI(View actionButton, View editControl) {
213 if (ParametricEditor.useCompact(mContext)) {
214 super.setUtilityPanelUI(actionButton, editControl);
217 mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar);
218 if (mSeekBar != null) {
219 mSeekBar.setVisibility(View.GONE);
221 LayoutInflater inflater =
222 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
223 LinearLayout lp = (LinearLayout) inflater.inflate(
224 R.layout.filtershow_draw_ui, (ViewGroup) editControl, true);
226 mTabletUI = new EditorDrawTabletUI(this, mContext, lp);
230 FilterDrawRepresentation getDrawRep() {
231 FilterRepresentation rep = getLocalRepresentation();
232 if (rep instanceof FilterDrawRepresentation) {
233 return (FilterDrawRepresentation) rep;
239 public void computeIcon(int index, BitmapCaller caller) {
240 Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), brushIcons[index]);
241 caller.available(bitmap);
244 public int getBrushIcon(int type) {
245 return brushIcons[type];