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.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.FrameLayout;
24 import android.widget.LinearLayout;
26 import com.android.gallery3d.filtershow.PanelController;
27 import com.android.gallery3d.filtershow.cache.ImageLoader;
28 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
29 import com.android.gallery3d.filtershow.imageshow.ImageShow;
30 import com.android.gallery3d.filtershow.imageshow.MasterImage;
31 import com.android.gallery3d.filtershow.presets.ImagePreset;
34 * Base class for Editors Must contain a mImageShow and a top level view
37 protected Context mContext;
39 protected ImageShow mImageShow;
40 protected FrameLayout mFrameLayout;
41 protected PanelController mPanelController;
43 private final String LOGTAG = "Editor";
44 protected FilterRepresentation mLocalRepresentation = null;
46 public void setPanelController(PanelController panelController) {
47 this.mPanelController = panelController;
50 protected Editor(int id) {
57 public void createEditor(Context context,FrameLayout frameLayout) {
59 mFrameLayout = frameLayout;
60 mLocalRepresentation = null;
63 protected void unpack(int viewid, int layoutid) {
66 mView = mFrameLayout.findViewById(viewid);
68 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService
69 (Context.LAYOUT_INFLATER_SERVICE);
70 mView = inflater.inflate(layoutid, mFrameLayout, false);
71 mFrameLayout.addView(mView, mView.getLayoutParams());
74 mImageShow = findImageShow(mView);
77 private ImageShow findImageShow(View view) {
78 if (view instanceof ImageShow) {
79 return (ImageShow) view;
81 if (!(view instanceof ViewGroup)) {
84 ViewGroup vg = (ViewGroup) view;
85 int n = vg.getChildCount();
86 for (int i = 0; i < n; i++) {
87 View v = vg.getChildAt(i);
88 if (v instanceof ImageShow) {
90 } else if (v instanceof ViewGroup) {
91 return findImageShow(v);
97 public View getTopLevelView() {
101 public ImageShow getImageShow() {
105 public void setImageLoader(ImageLoader imageLoader) {
106 mImageShow.setImageLoader(imageLoader);
109 public void setVisibility(int visible) {
110 mView.setVisibility(visible);
113 public FilterRepresentation getLocalRepresentation() {
114 if (mLocalRepresentation == null) {
115 ImagePreset preset = MasterImage.getImage().getPreset();
116 FilterRepresentation filterRepresentation = MasterImage.getImage().getCurrentFilterRepresentation();
117 mLocalRepresentation = preset.getFilterRepresentationCopyFrom(filterRepresentation);
119 return mLocalRepresentation;
122 public void commitLocalRepresentation() {
123 ImagePreset preset = MasterImage.getImage().getPreset();
124 preset.updateFilterRepresentation(getLocalRepresentation());
128 * called after the filter is set and the select is called
130 public void reflectCurrentFilter() {
131 mLocalRepresentation = null;
134 public boolean useUtilityPanel() {
135 if (mImageShow != null) {
136 return mImageShow.useUtilityPanel();
141 public void openUtilityPanel(LinearLayout mAccessoryViewList) {
142 if (mImageShow != null) {
143 mImageShow.openUtilityPanel(mAccessoryViewList);