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.graphics.drawable.Drawable;
21 import android.text.Html;
22 import android.view.LayoutInflater;
23 import android.view.Menu;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.*;
27 import android.widget.SeekBar.OnSeekBarChangeListener;
29 import com.android.gallery3d.R;
30 import com.android.gallery3d.filtershow.PanelController;
31 import com.android.gallery3d.filtershow.cache.ImageLoader;
32 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
33 import com.android.gallery3d.filtershow.imageshow.ImageShow;
34 import com.android.gallery3d.filtershow.imageshow.MasterImage;
35 import com.android.gallery3d.filtershow.presets.ImagePreset;
38 * Base class for Editors Must contain a mImageShow and a top level view
40 public class Editor implements OnSeekBarChangeListener {
41 protected Context mContext;
43 protected ImageShow mImageShow;
44 protected FrameLayout mFrameLayout;
45 protected SeekBar mSeekBar;
46 protected PanelController mPanelController;
48 private final String LOGTAG = "Editor";
49 protected FilterRepresentation mLocalRepresentation = null;
50 protected byte mShowParameter = SHOW_VALUE_UNDEFINED;
51 public static byte SHOW_VALUE_UNDEFINED = -1;
52 public static byte SHOW_VALUE_OFF = 0;
53 public static byte SHOW_VALUE_INT = 1;
55 public void setPanelController(PanelController panelController) {
56 this.mPanelController = panelController;
59 public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
60 String apply = context.getString(R.string.apply_effect);
61 if (mShowParameter == SHOW_VALUE_INT) {
62 apply += " " + effectName + " " + parameterValue;
64 apply += " " + effectName;
69 protected Editor(int id) {
78 public byte showParameterValue() {
79 return mShowParameter;
82 public boolean showsSeekBar() {
86 public boolean showsPopupIndicator() {
91 * @param actionButton the would be the area for menu etc
92 * @param editControl this is the black area for sliders etc
94 public void setUtilityPanelUI(View actionButton, View editControl) {
95 mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar);
97 mSeekBar.setOnSeekBarChangeListener(this);
98 mSeekBar.setVisibility(View.VISIBLE);
100 mSeekBar.setVisibility(View.INVISIBLE);
102 Button button = (Button) actionButton.findViewById(R.id.applyEffect);
103 if (button != null) {
104 if (showsPopupIndicator()) {
105 button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.filtershow_menu_marker, 0);
107 button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
113 public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
117 public void setPanel() {
121 public void createEditor(Context context,FrameLayout frameLayout) {
123 mFrameLayout = frameLayout;
124 mLocalRepresentation = null;
127 protected void unpack(int viewid, int layoutid) {
130 mView = mFrameLayout.findViewById(viewid);
132 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService
133 (Context.LAYOUT_INFLATER_SERVICE);
134 mView = inflater.inflate(layoutid, mFrameLayout, false);
135 mFrameLayout.addView(mView, mView.getLayoutParams());
138 mImageShow = findImageShow(mView);
141 private ImageShow findImageShow(View view) {
142 if (view instanceof ImageShow) {
143 return (ImageShow) view;
145 if (!(view instanceof ViewGroup)) {
148 ViewGroup vg = (ViewGroup) view;
149 int n = vg.getChildCount();
150 for (int i = 0; i < n; i++) {
151 View v = vg.getChildAt(i);
152 if (v instanceof ImageShow) {
153 return (ImageShow) v;
154 } else if (v instanceof ViewGroup) {
155 return findImageShow(v);
161 public View getTopLevelView() {
165 public ImageShow getImageShow() {
169 public void setImageLoader(ImageLoader imageLoader) {
170 mImageShow.setImageLoader(imageLoader);
173 public void setVisibility(int visible) {
174 mView.setVisibility(visible);
177 public FilterRepresentation getLocalRepresentation() {
178 if (mLocalRepresentation == null) {
179 ImagePreset preset = MasterImage.getImage().getPreset();
180 FilterRepresentation filterRepresentation = MasterImage.getImage().getCurrentFilterRepresentation();
181 mLocalRepresentation = preset.getFilterRepresentationCopyFrom(filterRepresentation);
182 if (mShowParameter == SHOW_VALUE_UNDEFINED) {
183 boolean show = filterRepresentation.showParameterValue();
184 mShowParameter = show ? SHOW_VALUE_INT : SHOW_VALUE_OFF;
188 return mLocalRepresentation;
191 public void commitLocalRepresentation() {
192 ImagePreset preset = MasterImage.getImage().getPreset();
193 preset.updateFilterRepresentation(getLocalRepresentation());
197 * called after the filter is set and the select is called
199 public void reflectCurrentFilter() {
200 mLocalRepresentation = null;
203 public boolean useUtilityPanel() {
207 public void openUtilityPanel(LinearLayout mAccessoryViewList) {
208 if (mImageShow != null) {
209 mImageShow.openUtilityPanel(mAccessoryViewList);
213 protected void createMenu(int[] strId, View button) {
214 PopupMenu pmenu = new PopupMenu(mContext, button);
215 Menu menu = pmenu.getMenu();
216 for (int i = 0; i < strId.length; i++) {
217 menu.add(Menu.NONE, Menu.FIRST + i, 0, mContext.getString(strId[i]));
222 public void onStartTrackingTouch(SeekBar arg0) {
227 public void onStopTrackingTouch(SeekBar arg0) {