2 * Copyright (C) 2012 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.content.Context;
20 import android.util.AttributeSet;
21 import android.util.Log;
22 import android.view.LayoutInflater;
23 import android.view.Menu;
24 import android.view.MenuItem;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.Button;
28 import android.widget.FrameLayout;
29 import android.widget.LinearLayout;
30 import android.widget.PopupMenu;
31 import android.widget.SeekBar;
32 import android.widget.SeekBar.OnSeekBarChangeListener;
34 import com.android.gallery3d.R;
35 import com.android.gallery3d.filtershow.PanelController;
36 import com.android.gallery3d.filtershow.cache.ImageLoader;
37 import com.android.gallery3d.filtershow.controller.Control;
38 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
39 import com.android.gallery3d.filtershow.imageshow.ImageShow;
40 import com.android.gallery3d.filtershow.imageshow.MasterImage;
41 import com.android.gallery3d.filtershow.presets.ImagePreset;
44 * Base class for Editors Must contain a mImageShow and a top level view
46 public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonListener {
47 protected Context mContext;
49 protected ImageShow mImageShow;
50 protected FrameLayout mFrameLayout;
51 protected SeekBar mSeekBar;
53 protected PanelController mPanelController;
55 private final String LOGTAG = "Editor";
56 protected FilterRepresentation mLocalRepresentation = null;
57 protected byte mShowParameter = SHOW_VALUE_UNDEFINED;
58 public static byte SHOW_VALUE_UNDEFINED = -1;
59 public static byte SHOW_VALUE_OFF = 0;
60 public static byte SHOW_VALUE_INT = 1;
62 public void setPanelController(PanelController panelController) {
63 this.mPanelController = panelController;
66 public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
68 if (mShowParameter == SHOW_VALUE_INT) {
69 apply += " " + effectName + " " + parameterValue;
71 apply += " " + effectName;
76 protected Editor(int id) {
84 public byte showParameterValue() {
85 return mShowParameter;
88 public boolean showsSeekBar() {
92 public void setUpEditorUI(View actionButton, View editControl, Button editTitle) {
93 this.mEditTitle = editTitle;
95 setUtilityPanelUI(actionButton, editControl);
98 public boolean showsPopupIndicator() {
103 * @param actionButton the would be the area for menu etc
104 * @param editControl this is the black area for sliders etc
106 public void setUtilityPanelUI(View actionButton, View editControl) {
109 Context context = editControl.getContext();
110 LayoutInflater inflater =
111 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
112 LinearLayout lp = (LinearLayout) inflater.inflate(
113 R.layout.filtershow_seekbar, (ViewGroup) editControl, true);
114 mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar);
115 mSeekBar.setOnSeekBarChangeListener(this);
117 if (showsSeekBar()) {
118 mSeekBar.setOnSeekBarChangeListener(this);
119 mSeekBar.setVisibility(View.VISIBLE);
121 mSeekBar.setVisibility(View.INVISIBLE);
124 Button button = (Button) actionButton.findViewById(R.id.applyEffect);
125 if (button != null) {
126 if (showsPopupIndicator()) {
127 button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0,
128 R.drawable.filtershow_menu_marker, 0);
130 button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
136 public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
140 public void setPanel() {
144 public void createEditor(Context context,FrameLayout frameLayout) {
146 mFrameLayout = frameLayout;
147 mLocalRepresentation = null;
150 protected void unpack(int viewid, int layoutid) {
153 mView = mFrameLayout.findViewById(viewid);
155 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService
156 (Context.LAYOUT_INFLATER_SERVICE);
157 mView = inflater.inflate(layoutid, mFrameLayout, false);
158 mFrameLayout.addView(mView, mView.getLayoutParams());
161 mImageShow = findImageShow(mView);
164 private ImageShow findImageShow(View view) {
165 if (view instanceof ImageShow) {
166 return (ImageShow) view;
168 if (!(view instanceof ViewGroup)) {
171 ViewGroup vg = (ViewGroup) view;
172 int n = vg.getChildCount();
173 for (int i = 0; i < n; i++) {
174 View v = vg.getChildAt(i);
175 if (v instanceof ImageShow) {
176 return (ImageShow) v;
177 } else if (v instanceof ViewGroup) {
178 return findImageShow(v);
184 public View getTopLevelView() {
188 public ImageShow getImageShow() {
192 public void setImageLoader(ImageLoader imageLoader) {
193 mImageShow.setImageLoader(imageLoader);
196 public void setVisibility(int visible) {
197 mView.setVisibility(visible);
200 public FilterRepresentation getLocalRepresentation() {
201 if (mLocalRepresentation == null) {
202 ImagePreset preset = MasterImage.getImage().getPreset();
203 FilterRepresentation filterRepresentation = MasterImage.getImage().getCurrentFilterRepresentation();
204 mLocalRepresentation = preset.getFilterRepresentationCopyFrom(filterRepresentation);
205 if (mShowParameter == SHOW_VALUE_UNDEFINED) {
206 boolean show = filterRepresentation.showParameterValue();
207 mShowParameter = show ? SHOW_VALUE_INT : SHOW_VALUE_OFF;
211 return mLocalRepresentation;
214 public void commitLocalRepresentation() {
215 ImagePreset preset = MasterImage.getImage().getPreset();
216 preset.updateFilterRepresentation(getLocalRepresentation());
217 mPanelController.onNewValue(-1);
221 * called after the filter is set and the select is called
223 public void reflectCurrentFilter() {
224 mLocalRepresentation = null;
227 public boolean useUtilityPanel() {
231 public void openUtilityPanel(LinearLayout mAccessoryViewList) {
233 if (mImageShow != null) {
234 mImageShow.openUtilityPanel(mAccessoryViewList);
238 protected void setMenuIcon(boolean on) {
239 mEditTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
240 0, 0, on ? R.drawable.filtershow_menu_marker : 0, 0);
242 protected void createMenu(int[] strId, View button) {
243 PopupMenu pmenu = new PopupMenu(mContext, button);
244 Menu menu = pmenu.getMenu();
245 for (int i = 0; i < strId.length; i++) {
246 menu.add(Menu.NONE, Menu.FIRST + i, 0, mContext.getString(strId[i]));
252 public Control[] getControls() {
256 public void onStartTrackingTouch(SeekBar arg0) {
261 public void onStopTrackingTouch(SeekBar arg0) {
266 public void swapLeft(MenuItem item) {
271 public void swapRight(MenuItem item) {
275 public void detach() {