diff options
18 files changed, 231 insertions, 205 deletions
diff --git a/res/layout-xlarge/attach_camera_control.xml b/res/layout-xlarge/attach_camera_control.xml index 0eab2e6..b33085b 100644 --- a/res/layout-xlarge/attach_camera_control.xml +++ b/res/layout-xlarge/attach_camera_control.xml @@ -22,8 +22,7 @@ android:layout_marginTop="20dp" android:layout_marginBottom="20dp" android:layout_marginLeft="10dp" - android:layout_marginRight="10dp" - android:layout_alignParentRight="true"> + android:layout_marginRight="10dp"> <LinearLayout android:orientation="vertical" android:gravity="top|center_horizontal" android:layout_alignParentTop="true" diff --git a/res/layout-xlarge/basic_setting_picker.xml b/res/layout-xlarge/basic_setting_picker.xml deleted file mode 100644 index 88b03ef..0000000 --- a/res/layout-xlarge/basic_setting_picker.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -** -** Copyright 2010, 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. -*/ ---> - -<com.android.camera.ui.BasicSettingPicker xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="96dp" - android:layout_height="match_parent" - android:gravity="center" - android:orientation="vertical" - android:layout_alignParentTop="true" - android:layout_alignParentBottom="true" - android:layout_alignParentLeft="true" - android:layout_marginLeft="10dp" - android:layout_marginRight="10dp" - android:dividerHeight="6dp" > - - <Button android:id="@+id/setting_exit" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginTop="10dp" - android:gravity="center" - android:text="@string/camera_setting_picker_exit" /> -</com.android.camera.ui.BasicSettingPicker> diff --git a/res/layout-xlarge/setting_image_item.xml b/res/layout-xlarge/basic_setting_popup.xml index a928cc7..862533c 100644 --- a/res/layout-xlarge/setting_image_item.xml +++ b/res/layout-xlarge/basic_setting_popup.xml @@ -16,11 +16,12 @@ ** limitations under the License. */ --> -<ImageView xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginTop="10dp" - android:gravity="center" - android:scaleType="fitCenter" - android:adjustViewBounds="true" /> + +<com.android.camera.ui.BasicSettingPopup xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerVertical="true" + android:layout_alignParentRight="true" + android:background="@drawable/menu_popup" + android:orientation="vertical" /> diff --git a/res/layout-xlarge/in_line_setting_picker.xml b/res/layout-xlarge/in_line_setting_picker.xml index a2387ae..1f95d30 100644 --- a/res/layout-xlarge/in_line_setting_picker.xml +++ b/res/layout-xlarge/in_line_setting_picker.xml @@ -19,7 +19,7 @@ <merge xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:id="@+id/decrement" - android:layout_width="24dp" + android:layout_width="48dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:gravity="center" @@ -39,7 +39,7 @@ android:textSize="20dp" /> <Button android:id="@+id/increment" - android:layout_width="24dp" + android:layout_width="48dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:gravity="center" diff --git a/res/layout-xlarge/other_setting_popup.xml b/res/layout-xlarge/other_setting_popup.xml index 9d5ccfe..6244044 100644 --- a/res/layout-xlarge/other_setting_popup.xml +++ b/res/layout-xlarge/other_setting_popup.xml @@ -17,10 +17,13 @@ */ --> -<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" +<com.android.camera.ui.OtherSettingsPopup xmlns:android="http://schemas.android.com/apk/res/android" xmlns:camera="http://schemas.android.com/apk/res/com.android.camera" android:layout_width="wrap_content" - android:layout_height="wrap_content" > + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@drawable/menu_popup"> <TableRow style="@style/OtherSettingTableRow"> <TextView android:text="@string/pref_camera_recordlocation_title" @@ -63,4 +66,4 @@ <com.android.camera.ui.InLineSettingPicker camera:prefKey="pref_camera_scenemode_key" /> </TableRow> -</TableLayout> +</com.android.camera.ui.OtherSettingsPopup> diff --git a/res/layout-xlarge/setting_item.xml b/res/layout-xlarge/setting_item.xml new file mode 100644 index 0000000..3ac8375 --- /dev/null +++ b/res/layout-xlarge/setting_item.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +** +** Copyright 2010, 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. +*/ +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="horizontal" + android:layout_width="wrap_content" + android:layout_height="35dp" + android:paddingLeft="14dp" + android:paddingRight="14dp" + style="@style/OtherSettingTableRow"> + + <TextView android:id="@+id/text" + style="@style/SettingPickerText" + android:layout_height="wrap_content" + android:gravity="left" + android:singleLine="true" + android:textColor="@drawable/btn_setting_picker" /> + <ImageView android:id="@+id/image" + android:layout_width="35dp" + android:layout_height="35dp" + android:gravity="center" + android:scaleType="fitCenter" + android:adjustViewBounds="true" /> +</LinearLayout> diff --git a/res/layout-xlarge/setting_text_item.xml b/res/layout-xlarge/setting_text_item.xml deleted file mode 100644 index 63085b3..0000000 --- a/res/layout-xlarge/setting_text_item.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -** -** Copyright 2010, 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. -*/ ---> -<TextView xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:gravity="center" - android:singleLine="true" - android:textColor="@drawable/btn_setting_picker" - android:textSize="16dp" /> diff --git a/res/layout-xlarge/video_camera.xml b/res/layout-xlarge/video_camera.xml index d20a9b3..296eaf2 100644 --- a/res/layout-xlarge/video_camera.xml +++ b/res/layout-xlarge/video_camera.xml @@ -25,7 +25,7 @@ android:layout_height="match_parent" android:layout_marginLeft="2dip" android:layout_weight="1"> - <FrameLayout android:id="@+id/frame" + <RelativeLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/border_view_finder"> @@ -36,6 +36,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" /> - </FrameLayout> + </RelativeLayout> </com.android.camera.PreviewFrameLayout> </LinearLayout> diff --git a/res/layout/camera.xml b/res/layout/camera.xml index 182084a..a68fa84 100644 --- a/res/layout/camera.xml +++ b/res/layout/camera.xml @@ -25,17 +25,17 @@ android:layout_height="match_parent" android:layout_marginLeft="2dp" android:layout_weight="1"> - <FrameLayout android:id="@+id/frame" - android:layout_width="match_parent" + <RelativeLayout android:id="@+id/frame" + android:layout_width="wrap_content" android:layout_height="match_parent" - android:background="@drawable/border_view_finder"> + android:background="@drawable/border_view_finder" > <SurfaceView android:id="@+id/camera_preview" android:layout_width="match_parent" - android:layout_height="match_parent"/> + android:layout_height="match_parent" /> <com.android.camera.FocusRectangle android:id="@+id/focus_rectangle" android:layout_width="match_parent" - android:layout_height="match_parent"/> - </FrameLayout> + android:layout_height="match_parent" /> + </RelativeLayout> </com.android.camera.PreviewFrameLayout> </LinearLayout> diff --git a/res/layout/camera_control.xml b/res/layout/camera_control.xml index 2744f32..0f6f22a 100644 --- a/res/layout/camera_control.xml +++ b/res/layout/camera_control.xml @@ -20,8 +20,7 @@ android:layout_height="match_parent" android:layout_width="76dp" android:layout_marginTop="13dp" - android:layout_marginBottom="10dp" - android:layout_alignParentRight="true"> + android:layout_marginBottom="10dp"> <com.android.camera.RotateImageView android:id="@+id/review_thumbnail" diff --git a/res/layout/video_camera.xml b/res/layout/video_camera.xml index 8130971..00a990d 100644 --- a/res/layout/video_camera.xml +++ b/res/layout/video_camera.xml @@ -25,7 +25,7 @@ android:layout_height="match_parent" android:layout_marginLeft="2dip" android:layout_weight="1"> - <FrameLayout android:id="@+id/frame" + <RelativeLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/border_view_finder"> @@ -50,6 +50,6 @@ android:layout_marginLeft="17dp" android:paddingRight="2dp" android:visibility="gone" /> - </FrameLayout> + </RelativeLayout> </com.android.camera.PreviewFrameLayout> </LinearLayout> diff --git a/res/values/styles.xml b/res/values/styles.xml index 7f65fdd..e4636fa 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -72,7 +72,7 @@ <item name="android:textStyle">bold</item> </style> <style name="SettingPickerText"> - <item name="android:textSize">20dp</item> + <item name="android:textSize">22dp</item> <item name="android:gravity">left|center_vertical</item> <item name="android:layout_marginLeft">12dp</item> <item name="android:layout_width">190dp</item> 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); } } } |