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.Dialog;
20 import android.content.Context;
21 import android.view.MenuItem;
22 import android.view.View;
23 import android.view.View.OnClickListener;
24 import android.view.WindowManager.LayoutParams;
25 import android.widget.Button;
26 import android.widget.FrameLayout;
27 import android.widget.LinearLayout;
28 import android.widget.PopupMenu;
29 import android.widget.SeekBar;
31 import com.android.gallery3d.R;
32 import com.android.gallery3d.filtershow.FilterShowActivity;
33 import com.android.gallery3d.filtershow.colorpicker.ColorGridDialog;
34 import com.android.gallery3d.filtershow.colorpicker.RGBListener;
35 import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation;
36 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
37 import com.android.gallery3d.filtershow.filters.ImageFilterDraw;
38 import com.android.gallery3d.filtershow.imageshow.ImageDraw;
40 public class EditorDraw extends Editor {
41 private static final String LOGTAG = "EditorDraw";
42 public static final int ID = R.id.editorDraw;
43 public ImageDraw mImageDraw;
50 public void createEditor(Context context, FrameLayout frameLayout) {
51 super.createEditor(context, frameLayout);
52 mView = mImageShow = mImageDraw = new ImageDraw(context);
53 mImageDraw.setEditor(this);
58 public void reflectCurrentFilter() {
59 super.reflectCurrentFilter();
60 FilterRepresentation rep = getLocalRepresentation();
62 if (rep != null && getLocalRepresentation() instanceof FilterDrawRepresentation) {
63 FilterDrawRepresentation drawRep = (FilterDrawRepresentation) getLocalRepresentation();
64 mImageDraw.setFilterDrawRepresentation(drawRep);
69 public void openUtilityPanel(final LinearLayout accessoryViewList) {
70 Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
71 view.setText(mContext.getString(R.string.draw_style));
72 view.setOnClickListener(new OnClickListener() {
75 public void onClick(View arg0) {
76 showPopupMenu(accessoryViewList);
81 private void showPopupMenu(LinearLayout accessoryViewList) {
82 final Button button = (Button) accessoryViewList.findViewById(
87 final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button);
88 popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_draw, popupMenu.getMenu());
89 popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
92 public boolean onMenuItemClick(MenuItem item) {
93 ImageFilterDraw filter = (ImageFilterDraw) mImageShow.getCurrentFilter();
94 if (item.getItemId() == R.id.draw_menu_color) {
96 } else if (item.getItemId() == R.id.draw_menu_size) {
98 } else if (item.getItemId() == R.id.draw_menu_style_brush_marker) {
99 ImageDraw idraw = (ImageDraw) mImageShow;
100 idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_MARKER);
101 } else if (item.getItemId() == R.id.draw_menu_style_brush_spatter) {
102 ImageDraw idraw = (ImageDraw) mImageShow;
103 idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_SPATTER);
104 } else if (item.getItemId() == R.id.draw_menu_style_line) {
105 ImageDraw idraw = (ImageDraw) mImageShow;
106 idraw.setStyle(ImageFilterDraw.SIMPLE_STYLE);
107 } else if (item.getItemId() == R.id.draw_menu_clear) {
108 ImageDraw idraw = (ImageDraw) mImageShow;
109 idraw.resetParameter();
110 commitLocalRepresentation();
119 public void showSizeDialog(final MenuItem item) {
120 FilterShowActivity ctx = mImageShow.getActivity();
121 final Dialog dialog = new Dialog(ctx);
122 dialog.setTitle(R.string.draw_size_title);
123 dialog.setContentView(R.layout.filtershow_draw_size);
124 final SeekBar bar = (SeekBar) dialog.findViewById(R.id.sizeSeekBar);
125 ImageDraw idraw = (ImageDraw) mImageShow;
126 bar.setProgress(idraw.getSize());
127 Button button = (Button) dialog.findViewById(R.id.sizeAcceptButton);
128 button.setOnClickListener(new OnClickListener() {
131 public void onClick(View arg0) {
132 int p = bar.getProgress();
133 ImageDraw idraw = (ImageDraw) mImageShow;
134 idraw.setSize(p + 1);
141 public void showColorGrid(final MenuItem item) {
142 RGBListener cl = new RGBListener() {
144 public void setColor(int rgb) {
145 ImageDraw idraw = (ImageDraw) mImageShow;
149 ColorGridDialog cpd = new ColorGridDialog(mImageShow.getActivity(), cl);
151 LayoutParams params = cpd.getWindow().getAttributes();