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.text.Html;
21 import android.view.LayoutInflater;
22 import android.view.Menu;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.FrameLayout;
26 import android.widget.LinearLayout;
27 import android.widget.PopupMenu;
28 import android.widget.SeekBar;
29 import android.widget.SeekBar.OnSeekBarChangeListener;
31 import com.android.gallery3d.R;
32 import com.android.gallery3d.filtershow.PanelController;
33 import com.android.gallery3d.filtershow.cache.ImageLoader;
34 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
35 import com.android.gallery3d.filtershow.imageshow.ImageShow;
36 import com.android.gallery3d.filtershow.imageshow.MasterImage;
37 import com.android.gallery3d.filtershow.presets.ImagePreset;
40 * Base class for Editors Must contain a mImageShow and a top level view
42 public class Editor implements OnSeekBarChangeListener {
43 protected Context mContext;
45 protected ImageShow mImageShow;
46 protected FrameLayout mFrameLayout;
47 protected SeekBar mSeekBar;
48 protected PanelController mPanelController;
50 private final String LOGTAG = "Editor";
51 protected FilterRepresentation mLocalRepresentation = null;
52 protected byte mShowParameter = SHOW_VALUE_UNDEFINED;
53 public static byte SHOW_VALUE_UNDEFINED = -1;
54 public static byte SHOW_VALUE_OFF = 0;
55 public static byte SHOW_VALUE_INT = 1;
57 public void setPanelController(PanelController panelController) {
58 this.mPanelController = panelController;
61 public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
62 String apply = context.getString(R.string.apply_effect);
63 if (mShowParameter == SHOW_VALUE_INT) {
64 apply += " " + effectName + " " + parameterValue;
66 apply += " " + effectName;
71 protected Editor(int id) {
80 public byte showParameterValue() {
81 return mShowParameter;
84 public boolean showsSeekBar() {
89 * @param actionButton the would be the area for menu etc
90 * @param editControl this is the black area for sliders etc
92 public void setUtilityPanelUI(View actionButton, View editControl) {
93 mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar);
95 mSeekBar.setOnSeekBarChangeListener(this);
96 mSeekBar.setVisibility(View.VISIBLE);
98 mSeekBar.setVisibility(View.INVISIBLE);
103 public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
107 public void setPanel() {
111 public void createEditor(Context context,FrameLayout frameLayout) {
113 mFrameLayout = frameLayout;
114 mLocalRepresentation = null;
117 protected void unpack(int viewid, int layoutid) {
120 mView = mFrameLayout.findViewById(viewid);
122 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService
123 (Context.LAYOUT_INFLATER_SERVICE);
124 mView = inflater.inflate(layoutid, mFrameLayout, false);
125 mFrameLayout.addView(mView, mView.getLayoutParams());
128 mImageShow = findImageShow(mView);
131 private ImageShow findImageShow(View view) {
132 if (view instanceof ImageShow) {
133 return (ImageShow) view;
135 if (!(view instanceof ViewGroup)) {
138 ViewGroup vg = (ViewGroup) view;
139 int n = vg.getChildCount();
140 for (int i = 0; i < n; i++) {
141 View v = vg.getChildAt(i);
142 if (v instanceof ImageShow) {
143 return (ImageShow) v;
144 } else if (v instanceof ViewGroup) {
145 return findImageShow(v);
151 public View getTopLevelView() {
155 public ImageShow getImageShow() {
159 public void setImageLoader(ImageLoader imageLoader) {
160 mImageShow.setImageLoader(imageLoader);
163 public void setVisibility(int visible) {
164 mView.setVisibility(visible);
167 public FilterRepresentation getLocalRepresentation() {
168 if (mLocalRepresentation == null) {
169 ImagePreset preset = MasterImage.getImage().getPreset();
170 FilterRepresentation filterRepresentation = MasterImage.getImage().getCurrentFilterRepresentation();
171 mLocalRepresentation = preset.getFilterRepresentationCopyFrom(filterRepresentation);
172 if (mShowParameter == SHOW_VALUE_UNDEFINED) {
173 boolean show = filterRepresentation.showParameterValue();
174 mShowParameter = show ? SHOW_VALUE_INT : SHOW_VALUE_OFF;
178 return mLocalRepresentation;
181 public void commitLocalRepresentation() {
182 ImagePreset preset = MasterImage.getImage().getPreset();
183 preset.updateFilterRepresentation(getLocalRepresentation());
187 * called after the filter is set and the select is called
189 public void reflectCurrentFilter() {
190 mLocalRepresentation = null;
193 public boolean useUtilityPanel() {
197 public void openUtilityPanel(LinearLayout mAccessoryViewList) {
198 if (mImageShow != null) {
199 mImageShow.openUtilityPanel(mAccessoryViewList);
203 protected void createMenu(int[] strId, View button) {
204 PopupMenu pmenu = new PopupMenu(mContext, button);
205 Menu menu = pmenu.getMenu();
206 for (int i = 0; i < strId.length; i++) {
207 menu.add(Menu.NONE, Menu.FIRST + i, 0, mContext.getString(strId[i]));
212 public void onStartTrackingTouch(SeekBar arg0) {
217 public void onStopTrackingTouch(SeekBar arg0) {