1 package com.android.gallery3d.filtershow;
2 
3 import android.view.View;
4 import android.view.ViewParent;
5 import android.widget.FrameLayout;
6 
7 import com.android.gallery3d.filtershow.cache.ImageLoader;
8 import com.android.gallery3d.filtershow.editors.Editor;
9 import com.android.gallery3d.filtershow.imageshow.ImageShow;
10 
11 import java.util.HashMap;
12 import java.util.Vector;
13 
14 public class EditorPlaceHolder {
15     private static final String LOGTAG = "EditorPlaceHolder";
16 
17     private FilterShowActivity mActivity = null;
18     private FrameLayout mContainer = null;
19     private HashMap<Integer, Editor> mEditors = new HashMap<Integer, Editor>();
20     private Vector<ImageShow> mOldViews = new Vector<ImageShow>();
21 
EditorPlaceHolder(FilterShowActivity activity)22     public EditorPlaceHolder(FilterShowActivity activity) {
23         mActivity = activity;
24     }
25 
setContainer(FrameLayout container)26     public void setContainer(FrameLayout container) {
27         mContainer = container;
28     }
29 
addEditor(Editor c)30     public void addEditor(Editor c) {
31         mEditors.put(c.getID(), c);
32     }
33 
contains(int type)34     public boolean contains(int type) {
35         if (mEditors.get(type) != null) {
36             return true;
37         }
38         return false;
39     }
40 
showEditor(int type)41     public Editor showEditor(int type) {
42         Editor editor = mEditors.get(type);
43         if (editor == null) {
44             return null;
45         }
46 
47         editor.createEditor(mActivity, mContainer);
48         editor.getImageShow().attach();
49         mContainer.setVisibility(View.VISIBLE);
50         mContainer.removeAllViews();
51         View eview = editor.getTopLevelView();
52         ViewParent parent = eview.getParent();
53 
54         if (parent != null && parent instanceof FrameLayout) {
55             ((FrameLayout) parent).removeAllViews();
56         }
57 
58         mContainer.addView(eview);
59         hideOldViews();
60         editor.setVisibility(View.VISIBLE);
61         return editor;
62     }
63 
setOldViews(Vector<ImageShow> views)64     public void setOldViews(Vector<ImageShow> views) {
65         mOldViews = views;
66     }
67 
hide()68     public void hide() {
69         mContainer.setVisibility(View.GONE);
70     }
71 
hideOldViews()72     public void hideOldViews() {
73         for (View view : mOldViews) {
74             view.setVisibility(View.GONE);
75         }
76     }
77 
getEditor(int editorId)78     public Editor getEditor(int editorId) {
79         return mEditors.get(editorId);
80     }
81 
82 }
83