diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/Camera.java | 44 | ||||
-rw-r--r-- | src/com/android/camera/PreviewFrameLayout.java | 3 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 44 | ||||
-rw-r--r-- | src/com/android/camera/ui/BasicSettingPopup.java (renamed from src/com/android/camera/ui/BasicSettingPicker.java) | 53 | ||||
-rw-r--r-- | src/com/android/camera/ui/ControlPanel.java | 115 | ||||
-rw-r--r-- | src/com/android/camera/ui/OtherSettingsPopup.java | 19 |
6 files changed, 163 insertions, 115 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index f99407c..10253f2 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -18,7 +18,6 @@ package com.android.camera; import com.android.camera.gallery.IImage; import com.android.camera.gallery.IImageList; -import com.android.camera.ui.BasicSettingPicker; import com.android.camera.ui.CameraHeadUpDisplay; import com.android.camera.ui.GLRootView; import com.android.camera.ui.HeadUpDisplay; @@ -164,7 +163,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private ShutterButton mShutterButton; private FocusRectangle mFocusRectangle; private ToneGenerator mFocusToneGenerator; - private GestureDetector mGestureDetector; + private GestureDetector mPopupGestureDetector; + private GestureDetector mZoomGestureDetector; private Switcher mSwitcher; private boolean mStartPreviewFail = false; @@ -512,7 +512,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, mZoomMax = mParameters.getMaxZoom(); mSmoothZoomSupported = mParameters.isSmoothZoomSupported(); - mGestureDetector = new GestureDetector(this, new ZoomGestureListener()); + mZoomGestureDetector = new GestureDetector(this, new ZoomGestureListener()); if (mZoomPicker != null) { mZoomPicker.setZoomRatios(getZoomRatios()); mZoomPicker.setOnZoomChangeListener( @@ -592,12 +592,40 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, } } + private int mPopupLocations[] = new int[2]; + private class PopupGestureListener extends + GestureDetector.SimpleOnGestureListener { + public boolean onDown(MotionEvent e) { + int x = Math.round(e.getX()); + int y = Math.round(e.getY()); + + // Check if the popup window is visible. + View v = mControlPanel.getActivePopupWindow(); + if (v == null) return false; + + // Dismiss the popup window if users touch on the outside. + v.getLocationOnScreen(mPopupLocations); + if (x < mPopupLocations[0] || x > mPopupLocations[0] + v.getWidth() + || y < mPopupLocations[1] || y > mPopupLocations[1] + v.getHeight()) { + mControlPanel.dismissSettingPopup(); + return true; + } + return false; + } + } + @Override public boolean dispatchTouchEvent(MotionEvent m) { - if (!super.dispatchTouchEvent(m) && mGestureDetector != null) { - return mGestureDetector.onTouchEvent(m); + // Check if the popup window should be dismissed first. + if (mPopupGestureDetector != null && mPopupGestureDetector.onTouchEvent(m)) { + return true; } - return true; + + if (!super.dispatchTouchEvent(m) && mZoomGestureDetector != null) { + return mZoomGestureDetector.onTouchEvent(m); + } + + return false; } LocationListener [] mLocationListeners = new LocationListener[] { @@ -1163,6 +1191,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, mPreferenceGroup = settings.getPreferenceGroup(R.xml.camera_preferences); mControlPanel.initialize(this, mPreferenceGroup, keys, true); mControlPanel.setListener(new MyControlPanelListener()); + mPopupGestureDetector = new GestureDetector(this, + new PopupGestureListener()); } } @@ -1209,7 +1239,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, if (mHeadUpDisplay != null && mHeadUpDisplay.collapse()) { return true; } - if (mControlPanel != null && mControlPanel.hideSettingPicker()) { + if (mControlPanel != null && mControlPanel.dismissSettingPopup()) { return true; } return false; diff --git a/src/com/android/camera/PreviewFrameLayout.java b/src/com/android/camera/PreviewFrameLayout.java index f60c93b..385bbcc 100644 --- a/src/com/android/camera/PreviewFrameLayout.java +++ b/src/com/android/camera/PreviewFrameLayout.java @@ -24,8 +24,7 @@ import android.view.View; import android.view.ViewGroup; /** - * A layout which handles the preview aspect ratio and the position of - * the gripper. + * A layout which handles the preview aspect ratio. */ public class PreviewFrameLayout extends ViewGroup { private static final int MIN_HORIZONTAL_MARGIN = 10; // 10dp diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 6ce1641..28f9546 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -58,10 +58,12 @@ import android.provider.MediaStore.Video.Media; import android.provider.Settings; import android.util.Log; import android.view.Display; +import android.view.GestureDetector; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; @@ -205,6 +207,8 @@ public class VideoCamera extends NoSearchActivity private int mNumberOfCameras; private int mCameraId; + private GestureDetector mPopupGestureDetector; + // This Handler is used to post message back onto the main thread of the // application private class MainHandler extends Handler { @@ -435,7 +439,7 @@ public class VideoCamera extends NoSearchActivity } private void attachHeadUpDisplay() { - FrameLayout frame = (FrameLayout) findViewById(R.id.frame); + ViewGroup frame = (ViewGroup) findViewById(R.id.frame); mGLRootView = new GLRootView(this); frame.addView(mGLRootView); mGLRootView.setContentPane(mHeadUpDisplay); @@ -460,6 +464,8 @@ public class VideoCamera extends NoSearchActivity settings.getPreferenceGroup(R.xml.video_preferences), keys, false); mControlPanel.setListener(new MyControlPanelListener()); + mPopupGestureDetector = new GestureDetector(this, + new PopupGestureListener()); } } @@ -526,7 +532,7 @@ public class VideoCamera extends NoSearchActivity switch (button.getId()) { case R.id.shutter_button: if (mHeadUpDisplay.collapse()) return; - if (mControlPanel != null) mControlPanel.hideSettingPicker(); + if (mControlPanel != null) mControlPanel.dismissSettingPopup(); if (mMediaRecorderRecording) { onStopVideoRecording(true); @@ -789,7 +795,7 @@ public class VideoCamera extends NoSearchActivity mPausing = true; changeHeadUpDisplayState(); - if (mControlPanel != null) mControlPanel.hideSettingPicker(); + if (mControlPanel != null) mControlPanel.dismissSettingPopup(); // Hide the preview now. Otherwise, the preview may be rotated during // onPause and it is annoying to users. @@ -1857,4 +1863,36 @@ public class VideoCamera extends NoSearchActivity VideoCamera.this.onSharedPreferenceChanged(); } } + + @Override + public boolean dispatchTouchEvent(MotionEvent m) { + // Check if the popup window should be dismissed first. + if (mPopupGestureDetector != null && mPopupGestureDetector.onTouchEvent(m)) { + return true; + } + + return super.dispatchTouchEvent(m); + } + + private int mPopupLocations[] = new int[2]; + private class PopupGestureListener extends + GestureDetector.SimpleOnGestureListener { + public boolean onDown(MotionEvent e) { + int x = Math.round(e.getX()); + int y = Math.round(e.getY()); + + // Check if the popup window is visible. + View v = mControlPanel.getActivePopupWindow(); + if (v == null) return false; + + // Dismiss the popup window if users touch on the outside. + v.getLocationOnScreen(mPopupLocations); + if (x < mPopupLocations[0] || x > mPopupLocations[0] + v.getWidth() + || y < mPopupLocations[1] || y > mPopupLocations[1] + v.getHeight()) { + mControlPanel.dismissSettingPopup(); + return true; + } + return false; + } + } } diff --git a/src/com/android/camera/ui/BasicSettingPicker.java b/src/com/android/camera/ui/BasicSettingPopup.java index 4f2011d..6f1a834 100644 --- a/src/com/android/camera/ui/BasicSettingPicker.java +++ b/src/com/android/camera/ui/BasicSettingPopup.java @@ -25,6 +25,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.PopupWindow; import android.widget.TextView; import com.android.camera.IconListPreference; @@ -32,8 +33,8 @@ import com.android.camera.R; import com.android.camera.Util; import com.android.camera.ui.GLListView.OnItemSelectedListener; -public class BasicSettingPicker extends LinearLayout { - private static final String TAG = "BasicSettingPicker"; +public class BasicSettingPopup extends LinearLayout { + private static final String TAG = "BasicSettingPopup"; private IconListPreference mPreference; private final Context mContext; private Listener mListener; @@ -42,7 +43,7 @@ public class BasicSettingPicker extends LinearLayout { public void onSettingChanged(); } - public BasicSettingPicker(Context context, AttributeSet attrs) { + public BasicSettingPopup(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; } @@ -58,30 +59,21 @@ public class BasicSettingPicker extends LinearLayout { int pos = 0; for (int i = 0, n = entries.length; i < n; ++i) { - // Add the image. - ImageView image; - Drawable drawable = mContext.getResources().getDrawable(imageIds[i]); - // Sacle the image if it is too small. - if (drawable.getIntrinsicWidth() >= getLayoutParams().width) { - image = (ImageView) inflater.inflate( - R.layout.setting_image_item, null); - } else { - image = (ImageView) inflater.inflate( - R.layout.setting_scale_image_item, null); - } - image.setImageDrawable(drawable); - image.setClickable(false); - addView(image, pos++); - - // Add the text. - TextView text = (TextView) inflater.inflate( - R.layout.setting_text_item, null); + LinearLayout row = (LinearLayout) inflater.inflate( + R.layout.setting_item, this, false); + // Initialize the text. + TextView text = (TextView) row.findViewById(R.id.text); text.setText(entries[i].toString()); text.setClickable(false); if (index == i) text.setPressed(true); - addView(text, pos++); + + // Initialize the image. + Drawable drawable = mContext.getResources().getDrawable(imageIds[i]); + ImageView image = (ImageView) row.findViewById(R.id.image); + image.setImageDrawable(drawable); + image.setClickable(false); + addView(row); } - requestLayout(); } public void setSettingChangedListener(Listener listener) { @@ -95,18 +87,15 @@ public class BasicSettingPicker extends LinearLayout { || action == MotionEvent.ACTION_DOWN) { int y = (int) event.getY(); // Check which child is pressed. - for (int i = 0; i < getChildCount() - 1; i++) { + for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); if (y >= v.getTop() && y <= v.getBottom()) { - int index = i / 2; - CharSequence[] values = mPreference.getEntryValues(); int oldIndex = mPreference.findIndexOfValue(mPreference.getValue()); - if (oldIndex != index) { - View oldText = getChildAt(oldIndex * 2 + 1); - oldText.setPressed(false); - View text = getChildAt(index * 2 + 1); - text.setPressed(true); - mPreference.setValueIndex(index); + if (oldIndex != i) { + View oldRow = getChildAt(oldIndex); + oldRow.findViewById(R.id.text).setPressed(false); + v.findViewById(R.id.text).setPressed(true); + mPreference.setValueIndex(i); if (mListener != null) { mListener.onSettingChanged(); } diff --git a/src/com/android/camera/ui/ControlPanel.java b/src/com/android/camera/ui/ControlPanel.java index cdd00d9..9718074 100644 --- a/src/com/android/camera/ui/ControlPanel.java +++ b/src/com/android/camera/ui/ControlPanel.java @@ -30,15 +30,16 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.KeyEvent; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.RelativeLayout; public class ControlPanel extends RelativeLayout - implements BasicSettingPicker.Listener, IndicatorWheel.Listener, - View.OnClickListener, OtherSettingsPopup.Listener, - PopupWindow.OnDismissListener { + implements BasicSettingPopup.Listener, IndicatorWheel.Listener, + OtherSettingsPopup.Listener, PopupWindow.OnDismissListener { private static final String TAG = "ControlPanel"; private Context mContext; private ComboPreferences mSharedPrefs; @@ -46,11 +47,10 @@ public class ControlPanel extends RelativeLayout private String[] mPreferenceKeys; private Listener mListener; private IndicatorWheel mIndicatorWheel; - private BasicSettingPicker[] mSettingPickers; + private BasicSettingPopup[] mBasicSettingPopups; private OtherSettingsPopup mOtherSettingsPopup; private int mActiveIndicator = -1; private boolean mEnabled = true; - private ListView mThumbnailList; static public interface Listener { @@ -84,19 +84,18 @@ public class ControlPanel extends RelativeLayout public void initialize(Context context, PreferenceGroup group, String[] keys, boolean enableOtherSettings) { // Reset the variables and states. - hideSettingPicker(); + dismissSettingPopup(); if (mIndicatorWheel != null) { // The first view is the shutter button. mIndicatorWheel.removeViews(1, mIndicatorWheel.getChildCount() - 1); } mOtherSettingsPopup = null; - mSettingPickers = null; mActiveIndicator = -1; // Initialize all variables and icons. mPreferenceGroup = group; mPreferenceKeys = keys; - mSettingPickers = new BasicSettingPicker[mPreferenceKeys.length]; + mBasicSettingPopups = new BasicSettingPopup[mPreferenceKeys.length]; mIndicatorWheel = (IndicatorWheel) findViewById(R.id.indicator_wheel); mThumbnailList = (ListView) findViewById(R.id.thumbnail_list); mSharedPrefs = ComboPreferences.get(context); @@ -123,84 +122,66 @@ public class ControlPanel extends RelativeLayout } } - @Override - public void onClick(View v) { - if (!mEnabled) return; - switch (v.getId()) { - case R.id.setting_exit: - hideSettingPicker(); - break; - } - } - public void onIndicatorClicked(int index) { if (!mEnabled) return; - if (index < mSettingPickers.length) { - if (mSettingPickers[index] == null) { - initializeSettingPicker(index); + if (index < mBasicSettingPopups.length) { + if (mBasicSettingPopups[index] == null) { + initializeSettingPopup(index); } } else if (mOtherSettingsPopup == null) { - initializeOtherSettingPicker(); - } - if (!showSettingPicker(index)) { - hideSettingPicker(); + initializeOtherSettingPopup(); } + showSettingPopup(index); } - private void initializeSettingPicker(int index) { + private void initializeSettingPopup(int index) { IconListPreference pref = (IconListPreference) mPreferenceGroup.findPreference(mPreferenceKeys[index]); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.basic_setting_picker, this); - mSettingPickers[index] = (BasicSettingPicker) getChildAt( - getChildCount() - 1); - mSettingPickers[index].setSettingChangedListener(this); - mSettingPickers[index].initialize(pref); - View v = mSettingPickers[index].findViewById(R.id.setting_exit); - v.setOnClickListener(this); - } - - private void initializeOtherSettingPicker() { + ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.frame); + BasicSettingPopup popup = (BasicSettingPopup) inflater.inflate( + R.layout.basic_setting_popup, root, false); + mBasicSettingPopups[index] = popup; + popup.setSettingChangedListener(this); + popup.initialize(pref); + RelativeLayout.LayoutParams params = + (RelativeLayout.LayoutParams) popup.getLayoutParams(); + params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + params.addRule(RelativeLayout.CENTER_VERTICAL); + popup.setLayoutParams(params); + root.addView(popup); + } + + private void initializeOtherSettingPopup() { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(R.layout.other_setting_popup, null); - // Framework has a bug so WRAP_CONTENT does not work. Hardcode the - // dimension for now. - mOtherSettingsPopup = new OtherSettingsPopup(view, 420, 410, true); - Drawable border = getResources().getDrawable(R.drawable.menu_popup); - mOtherSettingsPopup.setBackgroundDrawable(border); + ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.frame); + mOtherSettingsPopup = (OtherSettingsPopup) inflater.inflate( + R.layout.other_setting_popup, root, false); mOtherSettingsPopup.setOtherSettingChangedListener(this); - mOtherSettingsPopup.setOnDismissListener(this); - mOtherSettingsPopup.setFocusable(true); mOtherSettingsPopup.initialize(mPreferenceGroup); + root.addView(mOtherSettingsPopup); } - private boolean showSettingPicker(int index) { - for (int i = 0; i < mSettingPickers.length; i++) { - if (i != index && mSettingPickers[i] != null) { - mSettingPickers[i].setVisibility(View.INVISIBLE); - } - } - if (index == mSettingPickers.length) { - mOtherSettingsPopup.showAtLocation(this, Gravity.CENTER, 0, 0); - mThumbnailList.setVisibility(View.VISIBLE); + private void showSettingPopup(int index) { + if (mActiveIndicator == index) return; + dismissSettingPopup(); + if (index == mBasicSettingPopups.length) { + mOtherSettingsPopup.setVisibility(View.VISIBLE); } else { - mSettingPickers[index].setVisibility(View.VISIBLE); - mThumbnailList.setVisibility(View.INVISIBLE); + mBasicSettingPopups[index].setVisibility(View.VISIBLE); } mActiveIndicator = index; - return true; } - public boolean hideSettingPicker() { + public boolean dismissSettingPopup() { if (mActiveIndicator >= 0) { - if (mActiveIndicator == mSettingPickers.length) { - mOtherSettingsPopup.dismiss(); + if (mActiveIndicator == mBasicSettingPopups.length) { + mOtherSettingsPopup.setVisibility(View.INVISIBLE); } else { - mSettingPickers[mActiveIndicator].setVisibility(View.INVISIBLE); - mThumbnailList.setVisibility(View.VISIBLE); + mBasicSettingPopups[mActiveIndicator].setVisibility(View.INVISIBLE); } mActiveIndicator = -1; return true; @@ -217,4 +198,16 @@ public class ControlPanel extends RelativeLayout public void onDismiss() { mActiveIndicator = -1; } + + public View getActivePopupWindow() { + if (mActiveIndicator >= 0) { + if (mActiveIndicator == mBasicSettingPopups.length) { + return mOtherSettingsPopup; + } else { + return mBasicSettingPopups[mActiveIndicator]; + } + } else { + return null; + } + } } diff --git a/src/com/android/camera/ui/OtherSettingsPopup.java b/src/com/android/camera/ui/OtherSettingsPopup.java index feacb6b..862645e 100644 --- a/src/com/android/camera/ui/OtherSettingsPopup.java +++ b/src/com/android/camera/ui/OtherSettingsPopup.java @@ -19,14 +19,15 @@ package com.android.camera.ui; import com.android.camera.ListPreference; import com.android.camera.PreferenceGroup; +import android.content.Context; +import android.util.AttributeSet; import android.util.Log; import android.view.View; -import android.widget.PopupWindow; +import android.view.ViewGroup; import android.widget.TableLayout; -import android.widget.TableRow; /* A popup window that contains several camera settings. */ -public class OtherSettingsPopup extends PopupWindow +public class OtherSettingsPopup extends TableLayout implements InLineSettingPicker.Listener { private static final String TAG = "OtherSettingsPopup"; private Listener mListener; @@ -39,23 +40,21 @@ public class OtherSettingsPopup extends PopupWindow mListener = listener; } - public OtherSettingsPopup(View contentView, int width, int height, - boolean focusable) { - super(contentView, width, height, focusable); + public OtherSettingsPopup(Context context, AttributeSet attrs) { + super(context, attrs); } public void initialize(PreferenceGroup group) { - TableLayout table = (TableLayout) getContentView(); // Initialize each camera setting. - for (int i = table.getChildCount() - 1; i >= 0 ; i--) { - TableRow row = (TableRow) table.getChildAt(i); + for (int i = getChildCount() - 1; i >= 0 ; i--) { + ViewGroup row = (ViewGroup) getChildAt(i); InLineSettingPicker picker = (InLineSettingPicker) row.getChildAt(1); ListPreference pref = group.findPreference(picker.getKey()); if (pref != null) { picker.setSettingChangedListener(this); picker.initialize(pref); } else { // remove the row if the preference is not supported - table.removeViewAt(i); + removeViewAt(i); } } } |