OSDN Git Service

Hides popup indicator on some editors
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / editors / Editor.java
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.gallery3d.filtershow.editors;
18
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;
28
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;
36
37 /**
38  * Base class for Editors Must contain a mImageShow and a top level view
39  */
40 public class Editor implements OnSeekBarChangeListener {
41     protected Context mContext;
42     protected View mView;
43     protected ImageShow mImageShow;
44     protected FrameLayout mFrameLayout;
45     protected SeekBar mSeekBar;
46     protected PanelController mPanelController;
47     protected int mID;
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;
54
55     public void setPanelController(PanelController panelController) {
56         this.mPanelController = panelController;
57     }
58
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;
63         } else {
64             apply += " " + effectName;
65         }
66         return apply;
67     }
68
69     protected Editor(int id) {
70         mID = id;
71     }
72
73     public int getID() {
74         return mID;
75     }
76
77
78     public byte showParameterValue() {
79         return mShowParameter;
80     }
81
82     public boolean showsSeekBar() {
83         return true;
84     }
85
86     public boolean showsPopupIndicator() {
87         return true;
88     }
89
90     /**
91      * @param actionButton the would be the area for menu etc
92      * @param editControl this is the black area for sliders etc
93      */
94     public void setUtilityPanelUI(View actionButton, View editControl) {
95         mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar);
96         if (showsSeekBar()) {
97             mSeekBar.setOnSeekBarChangeListener(this);
98             mSeekBar.setVisibility(View.VISIBLE);
99         } else {
100             mSeekBar.setVisibility(View.INVISIBLE);
101         }
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);
106             } else {
107                 button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
108             }
109         }
110     }
111
112     @Override
113     public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
114
115     }
116
117     public void setPanel() {
118
119     }
120
121     public void createEditor(Context context,FrameLayout frameLayout) {
122         mContext = context;
123         mFrameLayout = frameLayout;
124         mLocalRepresentation = null;
125     }
126
127     protected void unpack(int viewid, int layoutid) {
128
129         if (mView == null) {
130             mView = mFrameLayout.findViewById(viewid);
131             if (mView == null) {
132                 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService
133                         (Context.LAYOUT_INFLATER_SERVICE);
134                 mView = inflater.inflate(layoutid, mFrameLayout, false);
135                 mFrameLayout.addView(mView, mView.getLayoutParams());
136             }
137         }
138         mImageShow = findImageShow(mView);
139     }
140
141     private ImageShow findImageShow(View view) {
142         if (view instanceof ImageShow) {
143             return (ImageShow) view;
144         }
145         if (!(view instanceof ViewGroup)) {
146             return null;
147         }
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);
156             }
157         }
158         return null;
159     }
160
161     public View getTopLevelView() {
162         return mView;
163     }
164
165     public ImageShow getImageShow() {
166         return mImageShow;
167     }
168
169     public void setImageLoader(ImageLoader imageLoader) {
170         mImageShow.setImageLoader(imageLoader);
171     }
172
173     public void setVisibility(int visible) {
174         mView.setVisibility(visible);
175     }
176
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;
185             }
186         }
187
188         return mLocalRepresentation;
189     }
190
191     public void commitLocalRepresentation() {
192         ImagePreset preset = MasterImage.getImage().getPreset();
193         preset.updateFilterRepresentation(getLocalRepresentation());
194     }
195
196     /**
197      * called after the filter is set and the select is called
198      */
199     public void reflectCurrentFilter() {
200         mLocalRepresentation = null;
201     }
202
203     public boolean useUtilityPanel() {
204         return true;
205     }
206
207     public void openUtilityPanel(LinearLayout mAccessoryViewList) {
208         if (mImageShow != null) {
209             mImageShow.openUtilityPanel(mAccessoryViewList);
210         }
211     }
212
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]));
218         }
219     }
220
221     @Override
222     public void onStartTrackingTouch(SeekBar arg0) {
223
224     }
225
226     @Override
227     public void onStopTrackingTouch(SeekBar arg0) {
228
229     }
230
231 }