15f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang/* 25f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * Copyright (C) 2011 The Android Open Source Project 35f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * 45f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * Licensed under the Apache License, Version 2.0 (the "License"); 55f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * you may not use this file except in compliance with the License. 65f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * You may obtain a copy of the License at 75f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * 85f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * http://www.apache.org/licenses/LICENSE-2.0 95f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * 105f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * Unless required by applicable law or agreed to in writing, software 115f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * distributed under the License is distributed on an "AS IS" BASIS, 125f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * See the License for the specific language governing permissions and 145f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * limitations under the License. 155f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang */ 165f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 175f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wangpackage com.android.camera.ui; 185f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 195f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wangimport android.content.Context; 205f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wangimport android.view.View; 215f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 225f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wangimport java.util.ArrayList; 235f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wangimport java.util.HashMap; 245f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 255f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang/** 265f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * A manager which notifies the event of a new popup in order to dismiss the 275f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang * old popup if exists. 285f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang */ 295f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wangpublic class PopupManager { 305f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang private static HashMap<Context, PopupManager> sMap = 315f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang new HashMap<Context, PopupManager>(); 325f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 335f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang public interface OnOtherPopupShowedListener { 345f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang public void onOtherPopupShowed(); 355f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 365f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 375f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang private PopupManager() {} 385f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 39913f3784d368a5e11fee5d5db2c355ef832685daWu-cheng Li private ArrayList<OnOtherPopupShowedListener> mListeners = new ArrayList<OnOtherPopupShowedListener>(); 405f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 415f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang public void notifyShowPopup(View view) { 425f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang for (OnOtherPopupShowedListener listener : mListeners) { 435f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang if ((View) listener != view) { 445f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang listener.onOtherPopupShowed(); 455f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 465f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 475f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 485f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 495f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang public void setOnOtherPopupShowedListener(OnOtherPopupShowedListener listener) { 505f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang mListeners.add(listener); 515f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 525f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 535f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang public static PopupManager getInstance(Context context) { 545f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang PopupManager instance = sMap.get(context); 555f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang if (instance == null) { 565f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang instance = new PopupManager(); 575f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang sMap.put(context, instance); 585f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 595f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang return instance; 605f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 615f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang 625f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang public static void removeInstance(Context context) { 635f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang PopupManager instance = sMap.get(context); 645f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang sMap.remove(context); 655f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang } 665f6e354a6e2a77aa935fcefeb33a9baa67d48aafChung-yih Wang} 67