diff options
Diffstat (limited to 'src/com/android/camera/app/FirstRunDialog.java')
-rw-r--r-- | src/com/android/camera/app/FirstRunDialog.java | 191 |
1 files changed, 61 insertions, 130 deletions
diff --git a/src/com/android/camera/app/FirstRunDialog.java b/src/com/android/camera/app/FirstRunDialog.java index 8011e6f21..08c22e77f 100644 --- a/src/com/android/camera/app/FirstRunDialog.java +++ b/src/com/android/camera/app/FirstRunDialog.java @@ -17,52 +17,51 @@ package com.android.camera.app; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; -import android.graphics.ImageFormat; import android.view.ViewGroup; -import com.android.camera.debug.Log; import com.android.camera.exif.Rational; import com.android.camera.one.OneCamera; import com.android.camera.one.OneCameraAccessException; -import com.android.camera.one.OneCameraCharacteristics; -import com.android.camera.one.OneCameraManager; import com.android.camera.settings.Keys; +import com.android.camera.settings.ResolutionSetting; import com.android.camera.settings.ResolutionUtil; import com.android.camera.settings.SettingsManager; -import com.android.camera.settings.SettingsUtil; import com.android.camera.util.ApiHelper; -import com.android.camera.util.Size; import com.android.camera.widget.AspectRatioDialogLayout; import com.android.camera.widget.LocationDialogLayout; -import java.util.List; - /** * The dialog to show when users open the app for the first time. */ public class FirstRunDialog { public interface FirstRunDialogListener { - - public void onLocationPreferenceConfirmed(boolean locationRecordingEnabled); - - public void onAspectRatioPreferenceConfirmed(Rational chosenAspectRatio); + public void onFirstRunStateReady(); + public void onCameraAccessException(); } - private static final Log.Tag TAG = new Log.Tag("FirstRunDialog"); - /** The default preference of aspect ratio. */ private static final Rational DEFAULT_ASPECT_RATIO = ResolutionUtil.ASPECT_RATIO_4x3; /** The default preference of whether enabling location recording. */ private static final boolean DEFAULT_LOCATION_RECORDING_ENABLED = true; + /** Listener to receive events. */ + private final FirstRunDialogListener mListener; + /** The app controller. */ private final AppController mAppController; - /** The camera manager used to query camera characteristics. */ - private final OneCameraManager mCameraManager; + /** The app context. */ + private final Context mContext; + + /** The resolution settings. */ + private final ResolutionSetting mResolutionSetting; + + /** The settings manager. */ + private final SettingsManager mSettingsManager; /** Aspect ratio preference dialog */ private Dialog mAspectRatioPreferenceDialog; @@ -70,55 +69,30 @@ public class FirstRunDialog { /** Location preference dialog */ private Dialog mLocationPreferenceDialog; - /** Listener to receive events. */ - private FirstRunDialogListener mListener; - /** * Constructs a first run dialog. * * @param appController The app controller. - * @param cameraManager The camera manager used to query supported aspect - * ratio by camera devices. */ - public FirstRunDialog(AppController appController, OneCameraManager cameraManager) { - mAppController = appController; - mCameraManager = cameraManager; - } - - /** - * Set a dialog listener. - * - * @param listener The dialog listener to be set. - */ - public void setListener(FirstRunDialogListener listener) { + public FirstRunDialog(AppController appController, FirstRunDialogListener listener) { mListener = listener; - } - - /** - * Whether first run dialogs should be presented to the user. - * - * @return Whether first run dialogs should be presented to the user. - */ - public boolean shouldShow() { - return shouldShowAspectRatioPreferenceDialog() || shouldShowLocationPreferenceDialog(); + mAppController = appController; + mContext = mAppController.getAndroidContext(); + mResolutionSetting = mAppController.getResolutionSetting(); + mSettingsManager = mAppController.getSettingsManager(); } /** * Shows first run dialogs if necessary. - * - * @return Whether first run dialogs are shown. */ - public boolean show() { - // When people open the app for the first time, prompt two dialogs to - // ask preferences about - // location and aspect ratio. - if (promptLocationPreferenceDialog()) { - return true; + public void showIfNecessary() { + if (shouldShow()) { + // When people open the app for the first time, prompt two dialogs to + // ask preferences about location and aspect ratio. The first dialog is + // location reference. + promptLocationPreferenceDialog(); } else { - // This should be a rare case because location and aspect ratio - // preferences usually got - // set at the same time when people open the app for the first time. - return promptAspectRatioPreferenceDialog(); + mListener.onFirstRunStateReady(); } } @@ -135,76 +109,54 @@ public class FirstRunDialog { } /** - * Whether a aspect ratio dialog should be presented to the user. + * Whether first run dialogs should be presented to the user. * - * @return Whether a aspect ratio dialog should be presented to the user. + * @return Whether first run dialogs should be presented to the user. */ - private boolean shouldShowAspectRatioPreferenceDialog() { - final SettingsManager settingsManager = mAppController.getSettingsManager(); - final boolean isAspectRatioPreferenceSet = settingsManager.getBoolean( + private boolean shouldShow() { + final boolean isAspectRatioPreferenceSet = mSettingsManager.getBoolean( SettingsManager.SCOPE_GLOBAL, Keys.KEY_USER_SELECTED_ASPECT_RATIO); - return ApiHelper.shouldShowAspectRatioDialog() && !isAspectRatioPreferenceSet; + final boolean isAspectRatioDevice = + ApiHelper.IS_NEXUS_4 || ApiHelper.IS_NEXUS_5 || ApiHelper.IS_NEXUS_6; + final boolean shouldShowAspectRatioDialog = + isAspectRatioDevice && !isAspectRatioPreferenceSet; + final boolean shouldShowLocationDialog = + !mSettingsManager.isSet(SettingsManager.SCOPE_GLOBAL, Keys.KEY_RECORD_LOCATION); + return shouldShowAspectRatioDialog || shouldShowLocationDialog; } /** * Prompts a dialog to allow people to choose aspect ratio preference when * people open the app for the first time. If the preference has been set, * this will return false. - * - * @return Whether the dialog will be prompted or not. */ - private boolean promptAspectRatioPreferenceDialog() { - // Do nothing if the preference is already set. - if (!shouldShowAspectRatioPreferenceDialog()) { - return false; - } - + private void promptAspectRatioPreferenceDialog() { // Create a content view for the dialog. final AspectRatioDialogLayout dialogLayout = new AspectRatioDialogLayout( - mAppController.getAndroidContext(), DEFAULT_ASPECT_RATIO); + mContext, DEFAULT_ASPECT_RATIO); dialogLayout.setListener(new AspectRatioDialogLayout.AspectRatioDialogListener() { @Override public void onConfirm(Rational aspectRatio) { + // Change resolution setting based on the chosen aspect ratio. try { - final SettingsManager settingsManager = - mAppController.getSettingsManager(); - - // Save the picture size setting for back camera. - OneCameraCharacteristics backCameraChars = - mCameraManager.getCameraCharacteristics(OneCamera.Facing.BACK); - List<Size> backCameraPictureSizes = - backCameraChars.getSupportedPictureSizes(ImageFormat.JPEG); - Size backCameraChosenPictureSize = - ResolutionUtil.getLargestPictureSize( - aspectRatio, backCameraPictureSizes); - settingsManager.set( - SettingsManager.SCOPE_GLOBAL, - Keys.KEY_PICTURE_SIZE_BACK, - SettingsUtil.sizeToSettingString(backCameraChosenPictureSize)); - - // Save the picture size setting for front camera. - OneCameraCharacteristics frontCameraChars = - mCameraManager.getCameraCharacteristics(OneCamera.Facing.FRONT); - List<Size> frontCameraPictureSizes = - frontCameraChars.getSupportedPictureSizes(ImageFormat.JPEG); - Size frontCameraChosenPictureSize = - ResolutionUtil.getLargestPictureSize( - aspectRatio, frontCameraPictureSizes); - settingsManager.set( - SettingsManager.SCOPE_GLOBAL, - Keys.KEY_PICTURE_SIZE_FRONT, - SettingsUtil.sizeToSettingString(frontCameraChosenPictureSize)); - - // Indicate the aspect ratio is selected. - settingsManager.set( - SettingsManager.SCOPE_GLOBAL, - Keys.KEY_USER_SELECTED_ASPECT_RATIO, - true); + mResolutionSetting.setPictureAspectRatio(OneCamera.Facing.BACK, aspectRatio); + mResolutionSetting.setPictureAspectRatio(OneCamera.Facing.FRONT, aspectRatio); } catch (OneCameraAccessException ex) { - throw new RuntimeException(ex); + mListener.onCameraAccessException(); + return; } - mListener.onAspectRatioPreferenceConfirmed(aspectRatio); + // Mark that user has made the choice. + mSettingsManager.set( + SettingsManager.SCOPE_GLOBAL, + Keys.KEY_USER_SELECTED_ASPECT_RATIO, + true); + + // Dismiss all dialogs. + dismiss(); + + // Notify that the app is ready to go. + mListener.onFirstRunStateReady(); } }); @@ -221,47 +173,27 @@ public class FirstRunDialog { // Show the dialog. mAspectRatioPreferenceDialog.show(); - return true; - } - - /** - * Whether a location dialog should be presented to the user. - * - * @return Whether a location dialog should be presented to the user. - */ - private boolean shouldShowLocationPreferenceDialog() { - final SettingsManager settingsManager = mAppController.getSettingsManager(); - return !settingsManager.isSet(SettingsManager.SCOPE_GLOBAL, Keys.KEY_RECORD_LOCATION); } /** * Prompts a dialog to allow people to choose location preference when * people open the app for the first time. If the preference has been set, * this will return false. - * - * @return Whether the dialog will be prompted or not. */ - private boolean promptLocationPreferenceDialog() { - // Do nothing if the preference is already set. - if (!shouldShowLocationPreferenceDialog()) { - return false; - } - + private void promptLocationPreferenceDialog() { // Create a content view for the dialog. final LocationDialogLayout dialogLayout = new LocationDialogLayout( - mAppController.getAndroidContext(), DEFAULT_LOCATION_RECORDING_ENABLED); + mContext, DEFAULT_LOCATION_RECORDING_ENABLED); dialogLayout.setListener(new LocationDialogLayout.LocationDialogListener() { @Override public void onConfirm(boolean locationRecordingEnabled) { - mAppController.getSettingsManager().set( + // Change the location preference setting. + mSettingsManager.set( SettingsManager.SCOPE_GLOBAL, Keys.KEY_RECORD_LOCATION, locationRecordingEnabled); - mAppController.getLocationManager().recordLocation( - locationRecordingEnabled); - - mListener.onLocationPreferenceConfirmed(locationRecordingEnabled); + // Prompt the second dialog about aspect ratio preference. promptAspectRatioPreferenceDialog(); } }); @@ -279,6 +211,5 @@ public class FirstRunDialog { // Show the dialog. mLocationPreferenceDialog.show(); - return true; } } |