Editor.java revision 5aa08941bda0cfbcfba522c53937dd66867f890d
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 17package com.android.gallery3d.filtershow.editors; 18 19import android.content.Context; 20import android.view.LayoutInflater; 21import android.view.View; 22import android.view.ViewGroup; 23import android.widget.FrameLayout; 24import android.widget.LinearLayout; 25 26import com.android.gallery3d.filtershow.PanelController; 27import com.android.gallery3d.filtershow.cache.ImageLoader; 28import com.android.gallery3d.filtershow.imageshow.ImageShow; 29 30/** 31 * Base class for Editors Must contain a mImageShow and a top level view 32 */ 33public class Editor { 34 protected Context mContext; 35 protected View mView; 36 protected ImageShow mImageShow; 37 protected FrameLayout mFrameLayout; 38 protected PanelController mPanelController; 39 protected int mID; 40 private final String LOGTAG = "Editor"; 41 42 public void setPanelController(PanelController panelController) { 43 this.mPanelController = panelController; 44 } 45 46 protected Editor(int id) { 47 mID = id; 48 } 49 public int getID() { 50 return mID; 51 } 52 53 public void createEditor(Context context,FrameLayout frameLayout) { 54 mContext = context; 55 mFrameLayout = frameLayout; 56 } 57 58 protected void unpack(int viewid, int layoutid) { 59 60 if (mView == null) { 61 mView = mFrameLayout.findViewById(viewid); 62 if (mView == null) { 63 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService 64 (Context.LAYOUT_INFLATER_SERVICE); 65 mView = inflater.inflate(layoutid, mFrameLayout, false); 66 mFrameLayout.addView(mView, mView.getLayoutParams()); 67 } 68 } 69 mImageShow = findImageShow(mView); 70 } 71 72 private ImageShow findImageShow(View view) { 73 if (view instanceof ImageShow) { 74 return (ImageShow) view; 75 } 76 if (!(view instanceof ViewGroup)) { 77 return null; 78 } 79 ViewGroup vg = (ViewGroup) view; 80 int n = vg.getChildCount(); 81 for (int i = 0; i < n; i++) { 82 View v = vg.getChildAt(i); 83 if (v instanceof ImageShow) { 84 return (ImageShow) v; 85 } else if (v instanceof ViewGroup) { 86 return findImageShow(v); 87 } 88 } 89 return null; 90 } 91 92 public View getTopLevelView() { 93 return mView; 94 } 95 96 public ImageShow getImageShow() { 97 return mImageShow; 98 } 99 100 public void setImageLoader(ImageLoader imageLoader) { 101 mImageShow.setImageLoader(imageLoader); 102 } 103 104 public void setVisibility(int visible) { 105 mView.setVisibility(visible); 106 } 107 108 /** 109 * called after the filter is set and the select is called 110 */ 111 public void reflectCurrentFilter() { 112 } 113 114 public boolean useUtilityPanel() { 115 if (mImageShow != null) { 116 return mImageShow.useUtilityPanel(); 117 } 118 return false; 119 } 120 121 public void openUtilityPanel(LinearLayout mAccessoryViewList) { 122 if (mImageShow != null) { 123 mImageShow.openUtilityPanel(mAccessoryViewList); 124 } 125 } 126 127} 128