summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2014-05-12 15:25:13 -0700
committerDoris Liu <tianliu@google.com>2014-05-13 15:43:45 -0700
commitdb8f97582d09cd36eee8cfe4ed43182bff63f8bd (patch)
treedf66aedf258ae5d1456cd1c76a1fbd9291ef90d7 /src/com
parentf56453afe262f1580eb4ebb501b7efe8fe8c2e3d (diff)
downloadandroid_packages_apps_Camera2-db8f97582d09cd36eee8cfe4ed43182bff63f8bd.tar.gz
android_packages_apps_Camera2-db8f97582d09cd36eee8cfe4ed43182bff63f8bd.tar.bz2
android_packages_apps_Camera2-db8f97582d09cd36eee8cfe4ed43182bff63f8bd.zip
Start up screen
This is the 2-step full screen popup: Step 1: (Only for new users) Choose whether geo-tagging should be on Step 2: For new users and upgraders to choose 4:3 or 16:9 preview resolution to take advantage of the screen size. Change-Id: Ibffe5a807cc622a3945b9fd869de1bf7dd660849
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/CameraActivity.java8
-rw-r--r--src/com/android/camera/PhotoModule.java177
-rw-r--r--src/com/android/camera/PhotoUI.java85
-rw-r--r--src/com/android/camera/settings/SettingsCache.java6
-rw-r--r--src/com/android/camera/settings/SettingsManager.java16
-rw-r--r--src/com/android/camera/widget/AspectRatioDialogLayout.java97
-rw-r--r--src/com/android/camera/widget/AspectRatioSelector.java88
-rw-r--r--src/com/android/camera/widget/LocationDialogLayout.java100
8 files changed, 562 insertions, 15 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 684463891..fbfd7eff4 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -1387,6 +1387,14 @@ public class CameraActivity extends Activity
|| MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) {
modeIndex = mSettingsManager.getInt(
SettingsManager.SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX);
+
+ // For upgraders who have not seen the aspect ratio selection screen,
+ // we need to drop them back in the photo module and have them select
+ // aspect ratio.
+ // TODO: Move this to SettingsManager as an upgrade procedure.
+ if (!mSettingsManager.getBoolean(SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO)) {
+ modeIndex = photoIndex;
+ }
} else {
// If the activity has not been started using an explicit intent,
// read the module index from the last time the user changed modes
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index b4b26f59f..4dc0cdbd4 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -21,6 +21,7 @@ import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.SurfaceTexture;
@@ -77,6 +78,7 @@ import com.android.camera.util.GcamHelper;
import com.android.camera.util.SessionStatsCollector;
import com.android.camera.util.Size;
import com.android.camera.util.UsageStatistics;
+import com.android.camera.widget.AspectRatioSelector;
import com.android.camera2.R;
import com.google.common.logging.eventprotos;
@@ -269,6 +271,48 @@ public class PhotoModule
}
};
+ /**
+ * This callback gets called when user select whether or not to
+ * turn on geo-tagging.
+ */
+ public interface LocationDialogCallback {
+ /**
+ * Gets called after user selected/unselected geo-tagging feature.
+ *
+ * @param selected whether or not geo-tagging feature is selected
+ */
+ public void onLocationTaggingSelected(boolean selected);
+ }
+
+ /**
+ * This callback defines the text that is shown in the aspect ratio selection
+ * dialog, provides the current aspect ratio, and gets notified when user changes
+ * aspect ratio selection in the dialog.
+ */
+ public interface AspectRatioDialogCallback {
+ /**
+ * Returns text to show for 4:3 aspect ratio.
+ */
+ public String get4x3AspectRatioText();
+
+ /**
+ * Returns text to show for 16:9 aspect ratio.
+ */
+ public String get16x9AspectRatioText();
+
+ /**
+ * Returns current aspect ratio that is being used to set as default.
+ */
+ public AspectRatioSelector.AspectRatio getCurrentAspectRatio();
+
+ /**
+ * Gets notified when user has made the aspect ratio selection.
+ *
+ * @param newAspectRatio aspect ratio that user has selected
+ */
+ public void onAspectRatioSelected(AspectRatioSelector.AspectRatio newAspectRatio);
+ }
+
private void checkDisplayRotation() {
// Set the display orientation if display rotation has changed.
// Sometimes this happens when the device is held upside
@@ -361,6 +405,13 @@ public class PhotoModule
SettingsManager settingsManager = mActivity.getSettingsManager();
mCameraId = Integer.parseInt(settingsManager.get(SettingsManager.SETTING_CAMERA_ID));
+ // TODO: Move this to SettingsManager as a part of upgrade procedure.
+ if (!settingsManager.getBoolean(SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO)) {
+ // Switch to back camera to set aspect ratio.
+ mCameraId = Integer.parseInt(settingsManager
+ .getDefaultCameraIdSetting(activity).getDefault());
+ }
+
mContentResolver = mActivity.getContentResolver();
// Surface texture is from camera screen nail and startPreview needs it.
@@ -390,27 +441,137 @@ public class PhotoModule
mAppController.onPreviewStarted();
setCameraState(IDLE);
startFaceDetection();
- locationFirstRun();
+ settingsFirstRun();
}
- // Prompt the user to pick to record location for the very first run of
- // camera only
- private void locationFirstRun() {
- SettingsManager settingsManager = mActivity.getSettingsManager();
+ /**
+ * Prompt the user to pick to record location and choose aspect ratio for the
+ * very first run of camera only.
+ */
+ private void settingsFirstRun() {
+ final SettingsManager settingsManager = mActivity.getSettingsManager();
- if (settingsManager.isSet(SettingsManager.SETTING_RECORD_LOCATION)) {
+ if (mActivity.isSecureCamera() || isImageCaptureIntent()) {
return;
}
- if (mActivity.isSecureCamera()) {
+
+ boolean locationPrompt = !settingsManager.isSet(SettingsManager.SETTING_RECORD_LOCATION);
+ boolean aspectRatioPrompt = !settingsManager.getBoolean(
+ SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO);
+ if (!locationPrompt && !aspectRatioPrompt) {
return;
}
+
// Check if the back camera exists
int backCameraId = mAppController.getCameraProvider().getFirstBackCameraId();
if (backCameraId == -1) {
// If there is no back camera, do not show the prompt.
return;
}
- mUI.showLocationDialog();
+
+ if (locationPrompt) {
+ // Show both location and aspect ratio selection dialog.
+ mUI.showLocationAndAspectRatioDialog(new LocationDialogCallback(){
+ public void onLocationTaggingSelected(boolean selected) {
+ settingsManager.setLocation(selected, mActivity.getLocationManager());
+ }
+ }, createAspectRatioDialogCallback());
+ } else {
+ // App upgrade. Only show aspect ratio selection.
+ mUI.showAspectRatioDialog(createAspectRatioDialogCallback());
+ }
+ }
+
+ private AspectRatioDialogCallback createAspectRatioDialogCallback() {
+ Size currentSize = new Size(mParameters.getPictureSize());
+ float aspectRatio = (float) currentSize.width() / (float) currentSize.height();
+ if (aspectRatio < 1f) {
+ aspectRatio = 1 / aspectRatio;
+ }
+ final AspectRatioSelector.AspectRatio currentAspectRatio;
+ if (Math.abs(aspectRatio - 4f / 3f) <= 0.1f) {
+ currentAspectRatio = AspectRatioSelector.AspectRatio.ASPECT_RATIO_4x3;
+ } else if (Math.abs(aspectRatio - 16f / 9f) <= 0.1f) {
+ currentAspectRatio = AspectRatioSelector.AspectRatio.ASPECT_RATIO_16x9;
+ } else {
+ // TODO: Log error and not show dialog.
+ return null;
+ }
+
+ List<Size> sizes = Size.buildListFromCameraSizes(mParameters.getSupportedPictureSizes());
+ List<Size> pictureSizes = ResolutionUtil
+ .getDisplayableSizesFromSupported(sizes, true);
+
+ // This logic below finds the largest resolution for each aspect ratio.
+ // TODO: Move this somewhere that can be shared with SettingsActivity
+ int aspectRatio4x3Resolution = 0;
+ int aspectRatio16x9Resolution = 0;
+ Size largestSize4x3 = new Size(0, 0);
+ Size largestSize16x9 = new Size(0, 0);
+ for (Size size : pictureSizes) {
+ float pictureAspectRatio = (float) size.width() / (float) size.height();
+ pictureAspectRatio = pictureAspectRatio < 1 ?
+ 1f / pictureAspectRatio : pictureAspectRatio;
+ int resolution = size.width() * size.height();
+ if (Math.abs(pictureAspectRatio - 4f / 3f) < 0.1f) {
+ if (resolution > aspectRatio4x3Resolution) {
+ aspectRatio4x3Resolution = resolution;
+ largestSize4x3 = size;
+ }
+ } else if (Math.abs(pictureAspectRatio - 16f / 9f) < 0.1f) {
+ if (resolution > aspectRatio16x9Resolution) {
+ aspectRatio16x9Resolution = resolution;
+ largestSize16x9 = size;
+ }
+ }
+ }
+ aspectRatio16x9Resolution /= 1000000;
+ aspectRatio4x3Resolution /= 1000000;
+
+ final String largestSize4x3Text = SettingsUtil.sizeToSetting(largestSize4x3);
+ final String largestSize16x9Text = SettingsUtil.sizeToSetting(largestSize16x9);
+
+ Resources res = mAppController.getAndroidContext().getResources();
+ final String aspectRatio4x3Text = res.getString(R.string.megapixel_text_for_4x3_aspect_ratio,
+ aspectRatio4x3Resolution);
+ final String aspectRatio16x9Text = res.getString(R.string.megapixel_text_for_16x9_aspect_ratio,
+ aspectRatio16x9Resolution);
+
+ AspectRatioDialogCallback callback = new AspectRatioDialogCallback() {
+ @Override
+ public String get4x3AspectRatioText() {
+ return aspectRatio4x3Text;
+ }
+
+ @Override
+ public String get16x9AspectRatioText() {
+ return aspectRatio16x9Text;
+ }
+
+ @Override
+ public AspectRatioSelector.AspectRatio getCurrentAspectRatio() {
+ return currentAspectRatio;
+ }
+
+ @Override
+ public void onAspectRatioSelected(AspectRatioSelector.AspectRatio newAspectRatio) {
+ if (newAspectRatio == AspectRatioSelector.AspectRatio.ASPECT_RATIO_4x3) {
+ mActivity.getSettingsManager().set(SettingsManager.SETTING_PICTURE_SIZE_BACK,
+ largestSize4x3Text);
+ } else if (newAspectRatio == AspectRatioSelector.AspectRatio.ASPECT_RATIO_16x9) {
+ mActivity.getSettingsManager().set(SettingsManager.SETTING_PICTURE_SIZE_BACK,
+ largestSize16x9Text);
+ }
+ mActivity.getSettingsManager().setBoolean(
+ SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO, true);
+ if (newAspectRatio != currentAspectRatio) {
+ // TODO: Need to re-introduce the mode cover here to avoid jank.
+ stopPreview();
+ startPreview();
+ }
+ }
+ };
+ return callback;
}
@Override
diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java
index 1de6d0428..1fbdced4b 100644
--- a/src/com/android/camera/PhotoUI.java
+++ b/src/com/android/camera/PhotoUI.java
@@ -16,7 +16,8 @@
package com.android.camera;
-import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
@@ -35,6 +36,9 @@ import com.android.camera.ui.FaceView;
import com.android.camera.ui.PreviewOverlay;
import com.android.camera.ui.PreviewStatusListener;
import com.android.camera.util.CameraUtil;
+import com.android.camera.widget.AspectRatioDialogLayout;
+import com.android.camera.widget.AspectRatioSelector;
+import com.android.camera.widget.LocationDialogLayout;
import com.android.camera2.R;
import java.util.List;
@@ -52,6 +56,7 @@ public class PhotoUI implements PreviewStatusListener,
private final PhotoController mController;
private final View mRootView;
+ private Dialog mDialog = null;
// TODO: Remove face view logic if UX does not bring it back within a month.
private FaceView mFaceView = null;
@@ -72,6 +77,13 @@ public class PhotoUI implements PreviewStatusListener,
return true;
}
};
+ private final DialogInterface.OnDismissListener mOnDismissListener
+ = new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ mDialog = null;
+ }
+ };
@Override
public GestureDetector.OnGestureListener getGestureListener() {
@@ -237,9 +249,71 @@ public class PhotoUI implements PreviewStatusListener,
// Removes pie menu.
}
- public void showLocationDialog() {
- AlertDialog alert = mActivity.getFirstTimeLocationAlert();
- alert.show();
+ public void showLocationAndAspectRatioDialog(
+ final PhotoModule.LocationDialogCallback locationCallback,
+ final PhotoModule.AspectRatioDialogCallback aspectRatioDialogCallback) {
+ setDialog(new Dialog(mActivity,
+ android.R.style.Theme_Black_NoTitleBar_Fullscreen));
+ final LocationDialogLayout locationDialogLayout = (LocationDialogLayout) mActivity
+ .getLayoutInflater().inflate(R.layout.location_dialog_layout, null);
+ locationDialogLayout.setLocationTaggingSelectionListener(
+ new LocationDialogLayout.LocationTaggingSelectionListener() {
+ @Override
+ public void onLocationTaggingSelected(boolean selected) {
+ // Update setting.
+ locationCallback.onLocationTaggingSelected(selected);
+ // Go to next page.
+ showAspectRatioDialog(aspectRatioDialogCallback, mDialog);
+ }
+ });
+ mDialog.setContentView(locationDialogLayout, new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ mDialog.show();
+ }
+
+ /**
+ * Dismisses previous dialog if any, sets current dialog to the given dialog,
+ * and set the on dismiss listener for the given dialog.
+ * @param dialog dialog to show
+ */
+ private void setDialog(Dialog dialog) {
+ if (mDialog != null) {
+ mDialog.setOnDismissListener(null);
+ mDialog.dismiss();
+ }
+ mDialog = dialog;
+ if (mDialog != null) {
+ mDialog.setOnDismissListener(mOnDismissListener);
+ }
+ }
+
+ public void showAspectRatioDialog(final PhotoModule.AspectRatioDialogCallback callback) {
+ setDialog(new Dialog(mActivity, android.R.style.Theme_Black_NoTitleBar_Fullscreen));
+ showAspectRatioDialog(callback, mDialog);
+ }
+
+ private void showAspectRatioDialog(final PhotoModule.AspectRatioDialogCallback callback,
+ final Dialog aspectRatioDialog) {
+ if (aspectRatioDialog == null) {
+ Log.e(TAG, "Dialog for aspect ratio is null.");
+ return;
+ }
+ final AspectRatioDialogLayout aspectRatioDialogLayout =
+ (AspectRatioDialogLayout) mActivity
+ .getLayoutInflater().inflate(R.layout.aspect_ratio_dialog_layout, null);
+ aspectRatioDialogLayout.initialize(
+ new AspectRatioDialogLayout.AspectRatioChangedListener() {
+ @Override
+ public void onAspectRatioChanged(AspectRatioSelector.AspectRatio aspectRatio) {
+ aspectRatioDialog.dismiss();
+ // callback to set picture size.
+ callback.onAspectRatioSelected(aspectRatio);
+ }
+ }, callback.get4x3AspectRatioText(), callback.get16x9AspectRatioText(),
+ callback.getCurrentAspectRatio());
+ aspectRatioDialog.setContentView(aspectRatioDialogLayout, new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ aspectRatioDialog.show();
}
public void initializeZoom(Camera.Parameters params) {
@@ -313,6 +387,9 @@ public class PhotoUI implements PreviewStatusListener,
public void onPause() {
if (mFaceView != null) mFaceView.clear();
+ if (mDialog != null) {
+ mDialog.dismiss();
+ }
}
public void clearFaces() {
diff --git a/src/com/android/camera/settings/SettingsCache.java b/src/com/android/camera/settings/SettingsCache.java
index b3a1e0e19..e89bbd02f 100644
--- a/src/com/android/camera/settings/SettingsCache.java
+++ b/src/com/android/camera/settings/SettingsCache.java
@@ -135,6 +135,8 @@ public class SettingsCache {
SettingsManager.SETTING_SHOULD_SHOW_REFOCUS_VIEWER_CLING);
mKeyMap.put(SettingsManager.KEY_EXPOSURE_COMPENSATION_ENABLED,
SettingsManager.SETTING_EXPOSURE_COMPENSATION_ENABLED);
+ mKeyMap.put(SettingsManager.KEY_USER_SELECTED_ASPECT_RATIO,
+ SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO);
}
/**
@@ -192,7 +194,7 @@ public class SettingsCache {
case SettingsManager.SETTING_VIDEO_EFFECT:
return SettingsManager.getVideoEffectSetting(mContext);
case SettingsManager.SETTING_CAMERA_ID:
- return SettingsManager.getDefaultCameraIdSetting(mContext, mCapabilities);
+ return SettingsManager.getDefaultCameraIdSetting(mContext);
case SettingsManager.SETTING_CAMERA_HDR:
return SettingsManager.getHdrSetting(mContext);
case SettingsManager.SETTING_CAMERA_HDR_PLUS:
@@ -221,6 +223,8 @@ public class SettingsCache {
return SettingsManager.getShouldShowRefocusViewerCling(mContext);
case SettingsManager.SETTING_EXPOSURE_COMPENSATION_ENABLED:
return SettingsManager.getManualExposureCompensationSetting(mContext);
+ case SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO:
+ return SettingsManager.getUserSelectedAspectRatioSetting(mContext);
default:
return mExtraSettings.settingFromId(id, mContext);
}
diff --git a/src/com/android/camera/settings/SettingsManager.java b/src/com/android/camera/settings/SettingsManager.java
index e92c2a7b4..288bc8622 100644
--- a/src/com/android/camera/settings/SettingsManager.java
+++ b/src/com/android/camera/settings/SettingsManager.java
@@ -393,6 +393,7 @@ public class SettingsManager {
public static final int SETTING_REQUEST_RETURN_HDR_PLUS = 30;
public static final int SETTING_SHOULD_SHOW_REFOCUS_VIEWER_CLING = 31;
public static final int SETTING_EXPOSURE_COMPENSATION_ENABLED = 32;
+ public static final int SETTING_USER_SELECTED_ASPECT_RATIO = 33;
// Shared preference keys.
public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key";
@@ -431,6 +432,7 @@ public class SettingsManager {
"pref_should_show_refocus_viewer_cling";
public static final String KEY_EXPOSURE_COMPENSATION_ENABLED =
"pref_camera_exposure_compensation_key";
+ public static final String KEY_USER_SELECTED_ASPECT_RATIO = "pref_user_selected_aspect_ratio";
public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
@@ -952,6 +954,13 @@ public class SettingsManager {
values, FLUSH_OFF);
}
+ public static Setting getUserSelectedAspectRatioSetting(Context context) {
+ String defaultValue = context.getString(R.string.setting_off_value);
+ String[] values = null;
+ return new Setting(SOURCE_DEFAULT, TYPE_BOOLEAN, defaultValue,
+ KEY_USER_SELECTED_ASPECT_RATIO, values, FLUSH_OFF);
+ }
+
public static Setting getManualExposureCompensationSetting(Context context) {
String defaultValue = context.getString(R.string.setting_off_value);
String[] values = null;
@@ -973,8 +982,7 @@ public class SettingsManager {
values, FLUSH_OFF);
}
- public static Setting getDefaultCameraIdSetting(Context context,
- SettingsCapabilities capabilities) {
+ public static Setting getDefaultCameraIdSetting(Context context) {
String defaultValue = context.getString(R.string.pref_camera_id_default);
String[] values = context.getResources().getStringArray(
R.array.camera_id_entryvalues);
@@ -1217,6 +1225,10 @@ public class SettingsManager {
locationManager.recordLocation(on);
}
+ public void setAspectRatioSelected() {
+ setBoolean(SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO, true);
+ }
+
public void setManualExposureCompensation(boolean on) {
setBoolean(SettingsManager.SETTING_EXPOSURE_COMPENSATION_ENABLED, on);
}
diff --git a/src/com/android/camera/widget/AspectRatioDialogLayout.java b/src/com/android/camera/widget/AspectRatioDialogLayout.java
new file mode 100644
index 000000000..04c086396
--- /dev/null
+++ b/src/com/android/camera/widget/AspectRatioDialogLayout.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2014 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.widget;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.FrameLayout;
+
+import com.android.camera2.R;
+
+public class AspectRatioDialogLayout extends FrameLayout {
+ private View mConfirmButton;
+ private AspectRatioSelector mAspectRatioSelector;
+ private int mLastOrientation;
+ private AspectRatioChangedListener mListener;
+ private String mText16x9;
+ private String mText4x3;
+ private boolean mInitialized;
+ private AspectRatioSelector.AspectRatio mAspectRatio;
+
+ public interface AspectRatioChangedListener {
+ public void onAspectRatioChanged(AspectRatioSelector.AspectRatio aspectRatio);
+ }
+
+ public AspectRatioDialogLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mLastOrientation = getResources().getConfiguration().orientation;
+ }
+
+ @Override
+ public void onFinishInflate() {
+ updateViewReference();
+ }
+
+ private void updateViewReference() {
+ mAspectRatioSelector = (AspectRatioSelector) findViewById(R.id.aspect_ratio_selector);
+ mConfirmButton = findViewById(R.id.confirm_button);
+ mConfirmButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mListener != null) {
+ mListener.onAspectRatioChanged(mAspectRatioSelector.getAspectRatio());
+ }
+ }
+ });
+ if (mInitialized) {
+ mAspectRatioSelector.setAspectRatio(mAspectRatio);
+ mAspectRatioSelector.setTexts(mText4x3, mText16x9);
+ }
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration config) {
+ super.onConfigurationChanged(config);
+ if (config.orientation == mLastOrientation) {
+ return;
+ }
+ mLastOrientation = config.orientation;
+ mAspectRatio = mAspectRatioSelector.getAspectRatio();
+ removeAllViews();
+ inflate(getContext(), R.layout.aspect_ratio_dialog_content, this);
+ updateViewReference();
+ }
+
+ public void setAspectRatio(AspectRatioSelector.AspectRatio aspectRatio) {
+ mAspectRatioSelector.setAspectRatio(aspectRatio);
+ }
+
+ public void initialize(AspectRatioChangedListener listener, String text4x3, String text16x9,
+ AspectRatioSelector.AspectRatio aspectRatio) {
+ mInitialized = true;
+ mListener = listener;
+ mText4x3 = text4x3;
+ mText16x9 = text16x9;
+ mAspectRatio = aspectRatio;
+ if (mAspectRatioSelector != null) {
+ mAspectRatioSelector.setAspectRatio(mAspectRatio);
+ mAspectRatioSelector.setTexts(mText4x3, mText16x9);
+ }
+ }
+}
diff --git a/src/com/android/camera/widget/AspectRatioSelector.java b/src/com/android/camera/widget/AspectRatioSelector.java
new file mode 100644
index 000000000..0366766ef
--- /dev/null
+++ b/src/com/android/camera/widget/AspectRatioSelector.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2014 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.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.camera2.R;
+
+public class AspectRatioSelector extends LinearLayout {
+ public static enum AspectRatio {
+ ASPECT_RATIO_4x3,
+ ASPECT_RATIO_16x9
+ };
+
+ private AspectRatio mAspectRatio = AspectRatio.ASPECT_RATIO_4x3;
+ private TextView mAspectRatio4x3Text;
+ private TextView mAspectRatio16x9Text;
+ private View mAspectRatio4x3Button;
+ private View mAspectRatio16x9Button;
+
+ public AspectRatioSelector(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void onFinishInflate() {
+ mAspectRatio4x3Button = findViewById(R.id.aspect_ratio_4x3_button);
+ mAspectRatio4x3Button.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setAspectRatio(AspectRatio.ASPECT_RATIO_4x3);
+ }
+ });
+ mAspectRatio16x9Button = findViewById(R.id.aspect_ratio_16x9_button);
+ mAspectRatio16x9Button.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setAspectRatio(AspectRatio.ASPECT_RATIO_16x9);
+ }
+ });
+ mAspectRatio4x3Text = (TextView) findViewById(R.id.text_4x3);
+ mAspectRatio16x9Text = (TextView) findViewById(R.id.text_16x9);
+ }
+
+ public void setAspectRatio(AspectRatio aspectRatio) {
+ if (aspectRatio == AspectRatio.ASPECT_RATIO_4x3) {
+ // Select 4x3 view.
+ mAspectRatio4x3Button.setSelected(true);
+ // Unselect 16x9 view.
+ mAspectRatio16x9Button.setSelected(false);
+ } else if (aspectRatio == AspectRatio.ASPECT_RATIO_16x9) {
+ // Select 16x9 view.
+ mAspectRatio16x9Button.setSelected(true);
+ // Unselect 4x3 view.
+ mAspectRatio4x3Button.setSelected(false);
+ } else {
+ // Log error.
+ return;
+ }
+ mAspectRatio = aspectRatio;
+ }
+
+ public AspectRatio getAspectRatio() {
+ return mAspectRatio;
+ }
+
+ public void setTexts(String text4x3, String text16x9) {
+ mAspectRatio4x3Text.setText(text4x3);
+ mAspectRatio16x9Text.setText(text16x9);
+ }
+}
diff --git a/src/com/android/camera/widget/LocationDialogLayout.java b/src/com/android/camera/widget/LocationDialogLayout.java
new file mode 100644
index 000000000..13b5984b7
--- /dev/null
+++ b/src/com/android/camera/widget/LocationDialogLayout.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2014 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.widget;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.FrameLayout;
+
+import com.android.camera2.R;
+
+public class LocationDialogLayout extends FrameLayout {
+
+ public interface LocationTaggingSelectionListener {
+ public void onLocationTaggingSelected(boolean selected);
+ }
+
+ private View mConfirmButton;
+ private CheckBox mCheckBox;
+ private int mLastOrientation;
+ private LocationTaggingSelectionListener mListener;
+ private boolean mCheckBoxChecked = true;
+
+ public LocationDialogLayout(Context context, AttributeSet attributeSet) {
+ super(context, attributeSet);
+ mLastOrientation = context.getResources().getConfiguration().orientation;
+ }
+
+ @Override
+ public void onFinishInflate() {
+ updateViewReference();
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration config) {
+ super.onConfigurationChanged(config);
+ // TODO: Extract the orientation checking logic in a super class as it
+ // is also used in the aspect ratio dialog.
+ if (config.orientation == mLastOrientation) {
+ return;
+ }
+ mLastOrientation = config.orientation;
+ removeAllViews();
+ inflate(getContext(), R.layout.location_dialog_content, this);
+ updateViewReference();
+ }
+
+ private void updateViewReference() {
+ mCheckBox = (CheckBox) findViewById(R.id.check_box);
+ mCheckBox.setChecked(mCheckBoxChecked);
+ mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ mCheckBoxChecked = isChecked;
+ }
+ });
+
+ View checkBoxTouchDelegate = findViewById(R.id.check_box_touch_delegate);
+ if (checkBoxTouchDelegate != null) {
+ checkBoxTouchDelegate.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // Toggle check box.
+ mCheckBox.setChecked(!mCheckBox.isChecked());
+ }
+ });
+ }
+ mConfirmButton = findViewById(R.id.confirm_button);
+ mConfirmButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mListener != null) {
+ mListener.onLocationTaggingSelected(mCheckBoxChecked);
+ }
+ }
+ });
+ }
+
+ public void setLocationTaggingSelectionListener(LocationTaggingSelectionListener listener) {
+ mListener = listener;
+ }
+
+}