1 /* 2 * Copyright (C) 2011 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.camera.ui; 18 19 import android.content.Context; 20 import android.view.View; 21 22 import java.util.ArrayList; 23 import java.util.HashMap; 24 25 /** 26 * A manager which notifies the event of a new popup in order to dismiss the 27 * old popup if exists. 28 */ 29 public class PopupManager { 30 private static HashMap<Context, PopupManager> sMap = 31 new HashMap<Context, PopupManager>(); 32 33 public interface OnOtherPopupShowedListener { onOtherPopupShowed()34 public void onOtherPopupShowed(); 35 } 36 PopupManager()37 private PopupManager() {} 38 39 private ArrayList<OnOtherPopupShowedListener> mListeners = new ArrayList(); 40 notifyShowPopup(View view)41 public void notifyShowPopup(View view) { 42 for (OnOtherPopupShowedListener listener : mListeners) { 43 if ((View) listener != view) { 44 listener.onOtherPopupShowed(); 45 } 46 } 47 } 48 setOnOtherPopupShowedListener(OnOtherPopupShowedListener listener)49 public void setOnOtherPopupShowedListener(OnOtherPopupShowedListener listener) { 50 mListeners.add(listener); 51 } 52 getInstance(Context context)53 public static PopupManager getInstance(Context context) { 54 PopupManager instance = sMap.get(context); 55 if (instance == null) { 56 instance = new PopupManager(); 57 sMap.put(context, instance); 58 } 59 return instance; 60 } 61 removeInstance(Context context)62 public static void removeInstance(Context context) { 63 PopupManager instance = sMap.get(context); 64 sMap.remove(context); 65 } 66 } 67