diff options
Diffstat (limited to 'src/com/android/camera/ui')
4 files changed, 96 insertions, 16 deletions
diff --git a/src/com/android/camera/ui/AbstractIndicatorButton.java b/src/com/android/camera/ui/AbstractIndicatorButton.java index 503d21e..037a273 100644 --- a/src/com/android/camera/ui/AbstractIndicatorButton.java +++ b/src/com/android/camera/ui/AbstractIndicatorButton.java @@ -28,30 +28,36 @@ import android.view.animation.AnimationUtils; import android.widget.ImageView; // This is an indicator button and pressing it opens a popup window. Ex: flash or other settings. -public abstract class AbstractIndicatorButton extends RotateImageView { +public abstract class AbstractIndicatorButton extends RotateImageView implements + PopupManager.OnOtherPopupShowedListener { private final String TAG = "AbstractIndicatorButton"; - protected Context mContext; protected Animation mFadeIn, mFadeOut; protected final int HIGHLIGHT_COLOR; protected AbstractSettingPopup mPopup; protected Handler mHandler = new MainHandler(); private final int MSG_DISMISS_POPUP = 0; - private PopupChangeListener mListener; + private IndicatorChangeListener mListener; - public static interface PopupChangeListener { - public void onShowPopup(View view, boolean showed); + + public static interface IndicatorChangeListener { + public void onShowIndicator(View view, boolean showed); } public AbstractIndicatorButton(Context context) { super(context); - mContext = context; - mFadeIn = AnimationUtils.loadAnimation(mContext, R.anim.grow_fade_in_from_right); - mFadeOut = AnimationUtils.loadAnimation(mContext, R.anim.shrink_fade_out_from_right); - HIGHLIGHT_COLOR = mContext.getResources().getColor(R.color.review_control_pressed_color); + mFadeIn = AnimationUtils.loadAnimation(context, R.anim.grow_fade_in_from_right); + mFadeOut = AnimationUtils.loadAnimation(context, R.anim.shrink_fade_out_from_right); + HIGHLIGHT_COLOR = context.getResources().getColor(R.color.review_control_pressed_color); setScaleType(ImageView.ScaleType.CENTER); + PopupManager.getInstance(context).setOnOtherPopupShowedListener(this); + } + + @Override + public void onOtherPopupShowed() { + dismissPopup(); } - public void setPopupChangeListener(PopupChangeListener listener) { + public void setIndicatorChangeListener(IndicatorChangeListener listener) { mListener = listener; } @@ -71,6 +77,7 @@ public abstract class AbstractIndicatorButton extends RotateImageView { if (action == MotionEvent.ACTION_DOWN && !isOverridden()) { if (mPopup == null || mPopup.getVisibility() != View.VISIBLE) { showPopup(); + PopupManager.getInstance(getContext()).notifyShowPopup(this); } else { dismissPopup(); } @@ -114,7 +121,7 @@ public abstract class AbstractIndicatorButton extends RotateImageView { mPopup.setOrientation(getDegree()); mPopup.clearAnimation(); mPopup.startAnimation(mFadeIn); - if (mListener != null) mListener.onShowPopup(this, true); + if (mListener != null) mListener.onShowIndicator(this, true); } public boolean dismissPopup() { @@ -123,7 +130,7 @@ public abstract class AbstractIndicatorButton extends RotateImageView { mPopup.clearAnimation(); mPopup.startAnimation(mFadeOut); mPopup.setVisibility(View.GONE); - if (mListener != null) mListener.onShowPopup(this, false); + if (mListener != null) mListener.onShowIndicator(this, false); invalidate(); // Indicator wheel needs to update the highlight indicator if this // is dismissed by MSG_DISMISS_POPUP. diff --git a/src/com/android/camera/ui/PopupManager.java b/src/com/android/camera/ui/PopupManager.java new file mode 100644 index 0000000..24f7667 --- /dev/null +++ b/src/com/android/camera/ui/PopupManager.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera.ui; + +import android.content.Context; +import android.view.View; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * A manager which notifies the event of a new popup in order to dismiss the + * old popup if exists. + */ +public class PopupManager { + private static HashMap<Context, PopupManager> sMap = + new HashMap<Context, PopupManager>(); + + public interface OnOtherPopupShowedListener { + public void onOtherPopupShowed(); + } + + private PopupManager() {} + + private ArrayList<OnOtherPopupShowedListener> mListeners = new ArrayList(); + + public void notifyShowPopup(View view) { + for (OnOtherPopupShowedListener listener : mListeners) { + if ((View) listener != view) { + listener.onOtherPopupShowed(); + } + } + } + + public void setOnOtherPopupShowedListener(OnOtherPopupShowedListener listener) { + mListeners.add(listener); + } + + public static PopupManager getInstance(Context context) { + PopupManager instance = sMap.get(context); + if (instance == null) { + instance = new PopupManager(); + sMap.put(context, instance); + } + return instance; + } + + public static void removeInstance(Context context) { + PopupManager instance = sMap.get(context); + sMap.remove(context); + } +} diff --git a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java index 9434df8..f3e5247 100644 --- a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java +++ b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java @@ -32,7 +32,7 @@ import android.widget.ImageView; * vertical bar in preview frame. */ public class SecondLevelIndicatorControlBar extends IndicatorControl implements - View.OnClickListener, AbstractIndicatorButton.PopupChangeListener { + View.OnClickListener, AbstractIndicatorButton.IndicatorChangeListener { private static final String TAG = "SecondLevelIndicatorControlBar"; private static int ICON_SPACING = Util.dpToPixel(24); private ImageView mCloseIcon; @@ -131,7 +131,7 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements @Override public IndicatorButton addIndicator(Context context, IconListPreference pref) { IndicatorButton b = super.addIndicator(context, pref); - b.setPopupChangeListener(this); + b.setIndicatorChangeListener(this); return b; } @@ -140,12 +140,12 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements int resId, String[] keys) { OtherSettingIndicatorButton b = super.addOtherSettingIndicator(context, resId, keys); - b.setPopupChangeListener(this); + b.setIndicatorChangeListener(this); return b; } @Override - public void onShowPopup(View view, boolean showed) { + public void onShowIndicator(View view, boolean showed) { // Ignore those events if not current popup. if (!showed && (mPopupedIndicator != view)) return; mPopupedIndicator = (showed ? view : null); diff --git a/src/com/android/camera/ui/SharePopup.java b/src/com/android/camera/ui/SharePopup.java index 9397591..c3934c5 100644 --- a/src/com/android/camera/ui/SharePopup.java +++ b/src/com/android/camera/ui/SharePopup.java @@ -199,6 +199,13 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, } @Override + public void showAtLocation(View parent, int gravity, int x, int y) { + super.showAtLocation(parent, gravity, x, y); + // Inform other popup to dismiss if exit + PopupManager.getInstance(mContext).notifyShowPopup(null); + } + + @Override public void onClick(View v) { switch (v.getId()) { case R.id.share_view: |