OSDN Git Service

Hides seekbar in 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.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;
30
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;
38
39 /**
40  * Base class for Editors Must contain a mImageShow and a top level view
41  */
42 public class Editor implements OnSeekBarChangeListener {
43     protected Context mContext;
44     protected View mView;
45     protected ImageShow mImageShow;
46     protected FrameLayout mFrameLayout;
47     protected SeekBar mSeekBar;
48     protected PanelController mPanelController;
49     protected int mID;
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;
56
57     public void setPanelController(PanelController panelController) {
58         this.mPanelController = panelController;
59     }
60
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;
65         } else {
66             apply += " " + effectName;
67         }
68         return apply;
69     }
70
71     protected Editor(int id) {
72         mID = id;
73     }
74
75     public int getID() {
76         return mID;
77     }
78
79
80     public byte showParameterValue() {
81         return mShowParameter;
82     }
83
84     public boolean showsSeekBar() {
85         return true;
86     }
87
88     /**
89      * @param actionButton the would be the area for menu etc
90      * @param editControl this is the black area for sliders etc
91      */
92     public void setUtilityPanelUI(View actionButton, View editControl) {
93         mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar);
94         if (showsSeekBar()) {
95             mSeekBar.setOnSeekBarChangeListener(this);
96             mSeekBar.setVisibility(View.VISIBLE);
97         } else {
98             mSeekBar.setVisibility(View.INVISIBLE);
99         }
100     }
101
102     @Override
103     public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
104
105     }
106
107     public void setPanel() {
108
109     }
110
111     public void createEditor(Context context,FrameLayout frameLayout) {
112         mContext = context;
113         mFrameLayout = frameLayout;
114         mLocalRepresentation = null;
115     }
116
117     protected void unpack(int viewid, int layoutid) {
118
119         if (mView == null) {
120             mView = mFrameLayout.findViewById(viewid);
121             if (mView == null) {
122                 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService
123                         (Context.LAYOUT_INFLATER_SERVICE);
124                 mView = inflater.inflate(layoutid, mFrameLayout, false);
125                 mFrameLayout.addView(mView, mView.getLayoutParams());
126             }
127         }
128         mImageShow = findImageShow(mView);
129     }
130
131     private ImageShow findImageShow(View view) {
132         if (view instanceof ImageShow) {
133             return (ImageShow) view;
134         }
135         if (!(view instanceof ViewGroup)) {
136             return null;
137         }
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);
146             }
147         }
148         return null;
149     }
150
151     public View getTopLevelView() {
152         return mView;
153     }
154
155     public ImageShow getImageShow() {
156         return mImageShow;
157     }
158
159     public void setImageLoader(ImageLoader imageLoader) {
160         mImageShow.setImageLoader(imageLoader);
161     }
162
163     public void setVisibility(int visible) {
164         mView.setVisibility(visible);
165     }
166
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;
175             }
176         }
177
178         return mLocalRepresentation;
179     }
180
181     public void commitLocalRepresentation() {
182         ImagePreset preset = MasterImage.getImage().getPreset();
183         preset.updateFilterRepresentation(getLocalRepresentation());
184     }
185
186     /**
187      * called after the filter is set and the select is called
188      */
189     public void reflectCurrentFilter() {
190         mLocalRepresentation = null;
191     }
192
193     public boolean useUtilityPanel() {
194         return true;
195     }
196
197     public void openUtilityPanel(LinearLayout mAccessoryViewList) {
198         if (mImageShow != null) {
199             mImageShow.openUtilityPanel(mAccessoryViewList);
200         }
201     }
202
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]));
208         }
209     }
210
211     @Override
212     public void onStartTrackingTouch(SeekBar arg0) {
213
214     }
215
216     @Override
217     public void onStopTrackingTouch(SeekBar arg0) {
218
219     }
220
221 }