diff options
author | Chung-yih Wang <cywang@google.com> | 2011-09-29 11:05:38 +0800 |
---|---|---|
committer | Chung-yih Wang <cywang@google.com> | 2011-09-30 15:02:45 +0800 |
commit | 5f6e354a6e2a77aa935fcefeb33a9baa67d48aaf (patch) | |
tree | 824996158940ae6faf7e64423cf65d4f27bd2ac9 /src/com/android/camera | |
parent | a11e8424441d555994e76fb27c9b34f8b75fa46e (diff) | |
download | LegacyCamera-5f6e354a6e2a77aa935fcefeb33a9baa67d48aaf.zip LegacyCamera-5f6e354a6e2a77aa935fcefeb33a9baa67d48aaf.tar.gz LegacyCamera-5f6e354a6e2a77aa935fcefeb33a9baa67d48aaf.tar.bz2 |
Fix the single popup issue.
bug:5169941
Popups should not persist when another is opened.
+Rename the confusing PopupChange listener.
Change-Id: Idca3218c090c8d9d176dbb97d8077dcc27409368
Diffstat (limited to 'src/com/android/camera')
-rw-r--r-- | src/com/android/camera/ActivityBase.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/ModePicker.java | 14 | ||||
-rw-r--r-- | src/com/android/camera/panorama/PanoramaActivity.java | 3 | ||||
-rw-r--r-- | src/com/android/camera/ui/AbstractIndicatorButton.java | 31 | ||||
-rw-r--r-- | src/com/android/camera/ui/PopupManager.java | 66 | ||||
-rw-r--r-- | src/com/android/camera/ui/SecondLevelIndicatorControlBar.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/ui/SharePopup.java | 7 |
7 files changed, 119 insertions, 18 deletions
diff --git a/src/com/android/camera/ActivityBase.java b/src/com/android/camera/ActivityBase.java index 5839668..96d7331 100644 --- a/src/com/android/camera/ActivityBase.java +++ b/src/com/android/camera/ActivityBase.java @@ -16,6 +16,8 @@ package com.android.camera; +import com.android.camera.ui.PopupManager; + import android.app.Activity; import android.view.KeyEvent; import android.content.Intent; @@ -61,4 +63,10 @@ public class ActivityBase extends Activity { public Intent getResultData() { return mResultDataForTesting; } + + @Override + protected void onDestroy() { + PopupManager.removeInstance(this); + super.onDestroy(); + } } diff --git a/src/com/android/camera/ModePicker.java b/src/com/android/camera/ModePicker.java index 62ee51e..528bc3d 100644 --- a/src/com/android/camera/ModePicker.java +++ b/src/com/android/camera/ModePicker.java @@ -16,6 +16,7 @@ package com.android.camera; +import com.android.camera.ui.PopupManager; import com.android.camera.ui.RotateImageView; import android.content.Context; @@ -34,7 +35,8 @@ import android.widget.RelativeLayout; * A widget that includes three mode selections {@code RotateImageView}'s and * a current mode indicator. */ -public class ModePicker extends RelativeLayout implements View.OnClickListener { +public class ModePicker extends RelativeLayout implements View.OnClickListener, + PopupManager.OnOtherPopupShowedListener { public static final int MODE_CAMERA = 0; public static final int MODE_VIDEO = 1; public static final int MODE_PANORAMA = 2; @@ -58,6 +60,8 @@ public class ModePicker extends RelativeLayout implements View.OnClickListener { private View mCurrentModeFrame; private RotateImageView mCurrentModeIcon[]; private View mCurrentModeBar; + private boolean mSelectionEnabled; + private int mCurrentMode = 0; private Animation mFadeIn, mFadeOut; @@ -71,6 +75,7 @@ public class ModePicker extends RelativeLayout implements View.OnClickListener { mFadeOut = AnimationUtils.loadAnimation( context, R.anim.mode_selection_fade_out); mFadeOut.setAnimationListener(mAnimationListener); + PopupManager.getInstance(context).setOnOtherPopupShowedListener(this); } protected void onFinishInflate() { @@ -109,6 +114,11 @@ public class ModePicker extends RelativeLayout implements View.OnClickListener { } } + @Override + public void onOtherPopupShowed() { + if (mSelectionEnabled) enableModeSelection(false); + } + private AnimationListener mAnimationListener = new AnimationListener() { public void onAnimationEnd(Animation animation) { changeToSelectedMode(); @@ -125,6 +135,7 @@ public class ModePicker extends RelativeLayout implements View.OnClickListener { private void enableModeSelection(boolean enabled) { if (mCurrentModeFrame != null) { + mSelectionEnabled = enabled; // Animation Effect is applied on Phone UI only. mModeSelectionFrame.startAnimation(enabled ? mFadeIn : mFadeOut); if (enabled) { @@ -145,6 +156,7 @@ public class ModePicker extends RelativeLayout implements View.OnClickListener { public void onClick(View view) { if (view == mCurrentModeFrame) { + PopupManager.getInstance(getContext()).notifyShowPopup(this); enableModeSelection(true); } else { // Set the selected mode as the current one and switch to it. diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java index b410c29..fcd47e6 100644 --- a/src/com/android/camera/panorama/PanoramaActivity.java +++ b/src/com/android/camera/panorama/PanoramaActivity.java @@ -16,6 +16,7 @@ package com.android.camera.panorama; +import com.android.camera.ActivityBase; import com.android.camera.CameraDisabledException; import com.android.camera.CameraHardwareException; import com.android.camera.CameraHolder; @@ -75,7 +76,7 @@ import java.util.List; /** * Activity to handle panorama capturing. */ -public class PanoramaActivity extends Activity implements +public class PanoramaActivity extends ActivityBase implements ModePicker.OnModeChangeListener, SurfaceTexture.OnFrameAvailableListener, ShutterButton.OnShutterButtonListener, MosaicRendererSurfaceViewRenderer.MosaicSurfaceCreateListener { 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: |