• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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;
18 
19 import android.view.View;
20 import android.view.ViewParent;
21 import android.widget.FrameLayout;
22 
23 import com.android.gallery3d.filtershow.cache.ImageLoader;
24 import com.android.gallery3d.filtershow.editors.Editor;
25 import com.android.gallery3d.filtershow.imageshow.ImageShow;
26 
27 import java.util.HashMap;
28 import java.util.Vector;
29 
30 public class EditorPlaceHolder {
31     private static final String LOGTAG = "EditorPlaceHolder";
32 
33     private FilterShowActivity mActivity = null;
34     private FrameLayout mContainer = null;
35     private HashMap<Integer, Editor> mEditors = new HashMap<Integer, Editor>();
36     private Vector<ImageShow> mOldViews = new Vector<ImageShow>();
37 
EditorPlaceHolder(FilterShowActivity activity)38     public EditorPlaceHolder(FilterShowActivity activity) {
39         mActivity = activity;
40     }
41 
setContainer(FrameLayout container)42     public void setContainer(FrameLayout container) {
43         mContainer = container;
44     }
45 
addEditor(Editor c)46     public void addEditor(Editor c) {
47         mEditors.put(c.getID(), c);
48     }
49 
contains(int type)50     public boolean contains(int type) {
51         if (mEditors.get(type) != null) {
52             return true;
53         }
54         return false;
55     }
56 
showEditor(int type)57     public Editor showEditor(int type) {
58         Editor editor = mEditors.get(type);
59         if (editor == null) {
60             return null;
61         }
62 
63         editor.createEditor(mActivity, mContainer);
64         editor.getImageShow().attach();
65         mContainer.setVisibility(View.VISIBLE);
66         mContainer.removeAllViews();
67         View eview = editor.getTopLevelView();
68         ViewParent parent = eview.getParent();
69 
70         if (parent != null && parent instanceof FrameLayout) {
71             ((FrameLayout) parent).removeAllViews();
72         }
73 
74         mContainer.addView(eview);
75         hideOldViews();
76         editor.setVisibility(View.VISIBLE);
77         return editor;
78     }
79 
setOldViews(Vector<ImageShow> views)80     public void setOldViews(Vector<ImageShow> views) {
81         mOldViews = views;
82     }
83 
hide()84     public void hide() {
85         mContainer.setVisibility(View.GONE);
86     }
87 
hideOldViews()88     public void hideOldViews() {
89         for (View view : mOldViews) {
90             view.setVisibility(View.GONE);
91         }
92     }
93 
getEditor(int editorId)94     public Editor getEditor(int editorId) {
95         return mEditors.get(editorId);
96     }
97 
98 }
99