summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByunghun Jeon <bjeon@codeaurora.org>2016-02-25 11:24:16 -0800
committerSteve Kondik <steve@cyngn.com>2016-08-21 18:45:51 -0700
commitd5a9d34ba133880916803fe8cfa84e5868f8197d (patch)
tree2769e942c75e043483067e2713907bb10c12371a
parent2e1de0b787020d6901d5b08d0ba615793f7e98a7 (diff)
downloadandroid_packages_apps_Snap-d5a9d34ba133880916803fe8cfa84e5868f8197d.zip
android_packages_apps_Snap-d5a9d34ba133880916803fe8cfa84e5868f8197d.tar.gz
android_packages_apps_Snap-d5a9d34ba133880916803fe8cfa84e5868f8197d.tar.bz2
SnapdragonCamera: Camera2 add flash, jpeg quality, white balance
Add flash, jpeg quality, and white balance setting menus to Camera2 CRs-Fixed: 989750 Change-Id: I288e1d4378c5e9f471b2b48a6c11ef434a9bac47
-rw-r--r--src/com/android/camera/CaptureMenu.java12
-rw-r--r--src/com/android/camera/CaptureModule.java485
-rw-r--r--src/com/android/camera/CaptureUI.java17
3 files changed, 391 insertions, 123 deletions
diff --git a/src/com/android/camera/CaptureMenu.java b/src/com/android/camera/CaptureMenu.java
index 2c5fed1..99f919a 100644
--- a/src/com/android/camera/CaptureMenu.java
+++ b/src/com/android/camera/CaptureMenu.java
@@ -92,13 +92,21 @@ public class CaptureMenu extends MenuController
mOtherKeys1 = new String[]{
CameraSettings.KEY_FLASH_MODE,
+ CameraSettings.KEY_RECORD_LOCATION,
+ CameraSettings.KEY_JPEG_QUALITY,
+ CameraSettings.KEY_CAMERA_SAVEPATH,
+ CameraSettings.KEY_WHITE_BALANCE,
CameraSettings.KEY_CAMERA2,
- CameraSettings.KEY_DUAL_CAMERA,
- CameraSettings.KEY_MONO_PREVIEW
+ CameraSettings.KEY_DUAL_CAMERA
};
+ //Todo: 2nd string to contain only developer settings
mOtherKeys2 = new String[]{
CameraSettings.KEY_FLASH_MODE,
+ CameraSettings.KEY_RECORD_LOCATION,
+ CameraSettings.KEY_JPEG_QUALITY,
+ CameraSettings.KEY_CAMERA_SAVEPATH,
+ CameraSettings.KEY_WHITE_BALANCE,
CameraSettings.KEY_CAMERA2,
CameraSettings.KEY_DUAL_CAMERA,
CameraSettings.KEY_MONO_PREVIEW
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 555c2e3..699f661 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -37,6 +37,7 @@ import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.StreamConfigurationMap;
+import android.media.CameraProfile;
import android.media.Image;
import android.media.ImageReader;
import android.net.Uri;
@@ -48,26 +49,32 @@ import android.util.Log;
import android.util.Size;
import android.util.SparseIntArray;
import android.view.KeyEvent;
+import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.View;
+import android.widget.Toast;
import com.android.camera.PhotoModule.NamedImages;
import com.android.camera.PhotoModule.NamedImages.NamedEntity;
+import com.android.camera.ui.RotateTextToast;
+import com.android.camera.util.CameraUtil;
import org.codeaurora.snapcam.R;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-public class CaptureModule implements CameraModule, PhotoController {
+public class CaptureModule implements CameraModule, PhotoController,
+ MediaSaveService.Listener {
public static final int DUAL_MODE = 0;
public static final int BAYER_MODE = 1;
public static final int MONO_MODE = 2;
@@ -110,8 +117,14 @@ public class CaptureModule implements CameraModule, PhotoController {
ORIENTATIONS.append(Surface.ROTATION_270, 180);
}
+ // The degrees of the device rotated clockwise from its natural orientation.
+ private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
+ private int mJpegQuality;
+ private Map<String, String> mSettings = new HashMap<String, String>();
+ private boolean mFirstTimeInitialized;
private boolean mInitialized = false;
private long mCaptureStartTime;
+ private boolean mPaused = true;
private boolean mSurfaceReady = false;
private boolean[] mCameraOpened = new boolean[MAX_NUM_CAM];
private CameraDevice[] mCameraDevice = new CameraDevice[MAX_NUM_CAM];
@@ -120,31 +133,8 @@ public class CaptureModule implements CameraModule, PhotoController {
private CameraActivity mActivity;
private PreferenceGroup mPreferenceGroup;
private ComboPreferences mPreferences;
- private CaptureRequest.Builder[] mCaptureBuilder = new CaptureRequest.Builder[MAX_NUM_CAM];
- private final CameraPreference.OnPreferenceChangedListener prefListener = new
- CameraPreference.OnPreferenceChangedListener() {
- @Override
- public void onSharedPreferenceChanged(ListPreference pref) {
- applyPreference(0, pref);
- mUI.overrideSettings(pref.getKey(), null);
- }
-
- @Override
- public void onSharedPreferenceChanged() {
- }
- @Override
- public void onRestorePreferencesClicked() {
- }
-
- @Override
- public void onOverriddenPreferencesClicked() {
- }
-
- @Override
- public void onCameraPickerClicked(int cameraId) {
- }
- };
+ private LocationManager mLocationManager;
/**
* A {@link CameraCaptureSession } for camera preview.
*/
@@ -210,10 +200,6 @@ public class CaptureModule implements CameraModule, PhotoController {
*/
private CaptureRequest.Builder[] mPreviewRequestBuilder = new CaptureRequest.Builder[MAX_NUM_CAM];
/**
- * {@link CaptureRequest} generated by {@link #mPreviewRequestBuilder}
- */
- private CaptureRequest[] mPreviewRequest = new CaptureRequest[MAX_NUM_CAM];
- /**
* The current state of camera state for taking pictures.
*
* @see #mCaptureCallback
@@ -232,6 +218,7 @@ public class CaptureModule implements CameraModule, PhotoController {
private void process(CaptureResult result) {
int id = (int) result.getRequest().getTag();
+
switch (mState[id]) {
case STATE_PREVIEW: {
break;
@@ -239,14 +226,15 @@ public class CaptureModule implements CameraModule, PhotoController {
case STATE_WAITING_LOCK: {
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
- if (afState == null) {
- captureStillPicture(id);
- } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
- CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
+ Log.d(TAG, "STATE_WAITING_LOCK afState:" + afState + " aeState:" + aeState);
+ // AF_PASSIVE is added for continous auto focus mode
+ if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
+ CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState ||
+ CaptureRequest.CONTROL_AF_STATE_PASSIVE_FOCUSED == afState ||
+ CaptureResult.CONTROL_AF_STATE_PASSIVE_UNFOCUSED == afState) {
// CONTROL_AE_STATE can be null on some devices
-
- if (aeState == null ||
- aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
+ if (aeState == null || (aeState == CaptureResult
+ .CONTROL_AE_STATE_CONVERGED) && isFlashOff()) {
mState[id] = STATE_PICTURE_TAKEN;
captureStillPicture(id);
} else {
@@ -291,6 +279,52 @@ public class CaptureModule implements CameraModule, PhotoController {
process(result);
}
};
+ private final CameraPreference.OnPreferenceChangedListener prefListener = new
+ CameraPreference.OnPreferenceChangedListener() {
+ @Override
+ public void onSharedPreferenceChanged(ListPreference pref) {
+ if (mPaused) return;
+ if (CameraSettings.KEY_CAMERA_SAVEPATH.equals(pref.getKey())) {
+ Storage.setSaveSDCard(
+ mPreferences.getString(CameraSettings.KEY_CAMERA_SAVEPATH, "0")
+ .equals("1"));
+ mActivity.updateStorageSpaceAndHint();
+ }
+
+ switch (MODE) {
+ case BAYER_MODE:
+ applyPreference(0, pref);
+ break;
+ case MONO_MODE:
+ applyPreference(1, pref);
+ break;
+ case DUAL_MODE:
+ applyPreference(0, pref);
+ applyPreference(1, pref);
+ }
+ mUI.overrideSettings(pref.getKey(), null);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged() {
+ if (mPaused) return;
+ boolean recordLocation = RecordLocationPreference.get(
+ mPreferences, mContentResolver);
+ mLocationManager.recordLocation(recordLocation);
+ }
+
+ @Override
+ public void onRestorePreferencesClicked() {
+ }
+
+ @Override
+ public void onOverriddenPreferencesClicked() {
+ }
+
+ @Override
+ public void onCameraPickerClicked(int cameraId) {
+ }
+ };
private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
@Override
@@ -298,6 +332,9 @@ public class CaptureModule implements CameraModule, PhotoController {
int id = Integer.parseInt(cameraDevice.getId());
Log.d(TAG, "onOpened " + id);
mCameraOpenCloseLock.release();
+ if (mPaused) {
+ return;
+ }
if (MODE == DUAL_MODE && id == BAYER_ID) {
Message msg = Message.obtain();
msg.what = OPEN_CAMERA;
@@ -368,8 +405,71 @@ public class CaptureModule implements CameraModule, PhotoController {
return true;
}
+ public static int getQualityNumber(String jpegQuality) {
+ try {
+ int qualityPercentile = Integer.parseInt(jpegQuality);
+ if (qualityPercentile >= 0 && qualityPercentile <= 100)
+ return qualityPercentile;
+ else
+ return 85;
+ } catch (NumberFormatException nfe) {
+ //chosen quality is not a number, continue
+ }
+ int value = 0;
+ switch (jpegQuality) {
+ case "superfine":
+ value = CameraProfile.QUALITY_HIGH;
+ break;
+ case "fine":
+ value = CameraProfile.QUALITY_MEDIUM;
+ break;
+ case "normal":
+ value = CameraProfile.QUALITY_LOW;
+ break;
+ default:
+ return 85;
+ }
+ return CameraProfile.getJpegEncodingQualityParameter(value);
+ }
+
+ private void initializeFirstTime() {
+ if (mFirstTimeInitialized || mPaused) {
+ return;
+ }
+
+ //Todo: test record location. Jack to provide instructions
+ // Initialize location service.
+ boolean recordLocation = RecordLocationPreference.get(
+ mPreferences, mContentResolver);
+ mLocationManager.recordLocation(recordLocation);
+
+ mUI.initializeFirstTime();
+ MediaSaveService s = mActivity.getMediaSaveService();
+ // We set the listener only when both service and shutterbutton
+ // are initialized.
+ if (s != null) {
+ s.setListener(this);
+ }
+
+ mNamedImages = new NamedImages();
+ mFirstTimeInitialized = true;
+ }
+
+ private void initializeSecondTime() {
+ // Start location update if needed.
+ boolean recordLocation = RecordLocationPreference.get(
+ mPreferences, mContentResolver);
+ mLocationManager.recordLocation(recordLocation);
+ MediaSaveService s = mActivity.getMediaSaveService();
+ if (s != null) {
+ s.setListener(this);
+ }
+ mNamedImages = new NamedImages();
+ mUI.initializeSecondTime();
+ }
+
private void createSession(final int id) {
- if (!mCameraOpened[id] || !mSurfaceReady) return;
+ if (mPaused || !mCameraOpened[id] || !mSurfaceReady) return;
List<Surface> list = new LinkedList<Surface>();
mUI.hidePreviewCover();
try {
@@ -390,25 +490,8 @@ public class CaptureModule implements CameraModule, PhotoController {
// We set up a CaptureRequest.Builder with the output Surface.
mPreviewRequestBuilder[id] = mCameraDevice[id].createCaptureRequest(CameraDevice
.TEMPLATE_PREVIEW);
- mPreviewRequestBuilder[id].addTarget(surface);
- // Auto focus should be continuous for camera preview.
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_MODE,
- CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
- // Flash is automatically enabled when necessary.
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_MODE,
- CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
mPreviewRequestBuilder[id].setTag(id);
-
- // This is the CaptureRequest.Builder that we use to take a picture.
- mCaptureBuilder[id] =
- mCameraDevice[id].createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
- mCaptureBuilder[id].addTarget(mImageReader[id].getSurface());
-
- // Use the same AE and AF modes as the preview.
- mCaptureBuilder[id].set(CaptureRequest.CONTROL_AF_MODE,
- CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
- mCaptureBuilder[id].set(CaptureRequest.CONTROL_AE_MODE,
- CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
+ mPreviewRequestBuilder[id].addTarget(surface);
list.add(surface);
list.add(mImageReader[id].getSurface());
@@ -419,16 +502,16 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onConfigured(CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
- if (null == mCameraDevice[id]) {
+ if (mPaused || null == mCameraDevice[id]) {
return;
}
// When the session is ready, we start displaying the preview.
mCaptureSession[id] = cameraCaptureSession;
+ initializePreviewConfiguration(id);
try {
// Finally, we start displaying the camera preview.
- mPreviewRequest[id] = mPreviewRequestBuilder[id].build();
- mCaptureSession[id].setRepeatingRequest(mPreviewRequest[id],
- mCaptureCallback, mCameraHandler);
+ mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id]
+ .build(), mCaptureCallback, mCameraHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
@@ -474,7 +557,9 @@ public class CaptureModule implements CameraModule, PhotoController {
mContentResolver = mActivity.getContentResolver();
mUI = new CaptureUI(activity, this, parent);
mUI.initializeControlByIntent();
- mNamedImages = new NamedImages();
+ mLocationManager = new LocationManager(mActivity, mUI);
+ Storage.setSaveSDCard(
+ mPreferences.getString(CameraSettings.KEY_CAMERA_SAVEPATH, "0").equals("1"));
}
/**
@@ -502,13 +587,17 @@ public class CaptureModule implements CameraModule, PhotoController {
private void lockFocus(int id) {
Log.d(TAG, "lockFocus " + id);
try {
- // This is how to tell the camera to lock focus.
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_TRIGGER,
- CameraMetadata.CONTROL_AF_TRIGGER_START);
- // Tell #mCaptureCallback to wait for the lock.
+ CaptureRequest.Builder builder = mCameraDevice[id].createCaptureRequest(CameraDevice
+ .TEMPLATE_PREVIEW);
+ builder.setTag(id);
+ builder.addTarget(getPreviewSurface(id));
+
+ builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
+ builder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO);
+ builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
+ applyWhiteBalance(builder);
mState[id] = STATE_WAITING_LOCK;
- mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback,
- mCameraHandler);
+ mCaptureSession[id].capture(builder.build(), mCaptureCallback, mCameraHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
@@ -521,18 +610,23 @@ public class CaptureModule implements CameraModule, PhotoController {
private void captureStillPicture(final int id) {
Log.d(TAG, "captureStillPicture " + id);
try {
- if (null == mActivity || null == mCameraDevice) {
+ if (null == mActivity || null == mCameraDevice[id]) {
return;
}
+ CaptureRequest.Builder captureBuilder =
+ mCameraDevice[id].createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
+
+ captureBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
+ captureBuilder.addTarget(getPreviewSurface(id));
+ captureBuilder.addTarget(mImageReader[id].getSurface());
+ captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
+ captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest
+ .CONTROL_AF_TRIGGER_IDLE);
+ applyCaptureSettings(captureBuilder);
// Orientation
int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
- mCaptureBuilder[id].set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
- List<CaptureRequest> burstList = new ArrayList<CaptureRequest>();
-
- for (int i = 0; i < 1; i++) {
- burstList.add(mCaptureBuilder[id].build());
- }
+ captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
@@ -550,9 +644,9 @@ public class CaptureModule implements CameraModule, PhotoController {
Log.d(TAG, "captureStillPicture onCaptureSequenceCompleted");
unlockFocus(id);
}
-
};
- mCaptureSession[id].captureBurst(burstList, CaptureCallback, mCallbackHandler);
+ mCaptureSession[id].stopRepeating();
+ mCaptureSession[id].capture(captureBuilder.build(), CaptureCallback, mCallbackHandler);
} catch (CameraAccessException e) {
Log.d(TAG, "Capture still picture has failed");
e.printStackTrace();
@@ -564,14 +658,20 @@ public class CaptureModule implements CameraModule, PhotoController {
* we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
*/
private void runPrecaptureSequence(int id) {
+ Log.d(TAG, "runPrecaptureSequence");
try {
- // This is how to tell the camera to trigger.
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
+ CaptureRequest.Builder builder = mCameraDevice[id].createCaptureRequest(CameraDevice
+ .TEMPLATE_PREVIEW);
+ builder.setTag(id);
+ builder.addTarget(getPreviewSurface(id));
+ builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
+ builder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
- // Tell #mCaptureCallback to wait for the precapture sequence to be set.
+ // Applying flash only to capture does not work. Need to apply flash here.
+ applyFlash(builder);
+ applyWhiteBalance(builder);
mState[id] = STATE_WAITING_PRECAPTURE;
- mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback,
- mCameraHandler);
+ mCaptureSession[id].capture(builder.build(), mCaptureCallback, mCameraHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
@@ -599,7 +699,8 @@ public class CaptureModule implements CameraModule, PhotoController {
if (map == null) {
continue;
}
-
+ Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
+ Log.d(TAG, "flash : " + (available == null ? false : available));
// For still image captures, we use the largest available size.
Size largest = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
@@ -624,22 +725,28 @@ public class CaptureModule implements CameraModule, PhotoController {
private void unlockFocus(int id) {
Log.d(TAG, "unlockFocus " + id);
try {
- // Reset the auto-focus trigger
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_TRIGGER,
- CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_MODE,
- CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
- mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback,
- mCameraHandler);
- // After this, the camera will go back to the normal state of preview.
+ CaptureRequest.Builder builder = mCameraDevice[id].createCaptureRequest(CameraDevice
+ .TEMPLATE_PREVIEW);
+ builder.setTag(id);
+ builder.addTarget(getPreviewSurface(id));
+ builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest
+ .CONTROL_MODE_AUTO);
+ builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest
+ .CONTROL_AF_MODE_AUTO);
+ builder.set(CaptureRequest.CONTROL_AF_TRIGGER,
+ CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
+ //Todo: Create applyCommonSettings function for settings applied everytime
+ applyWhiteBalance(builder);
+ mCaptureSession[id].capture(builder.build(), mCaptureCallback, mCameraHandler);
mState[id] = STATE_PREVIEW;
- mCaptureSession[id].setRepeatingRequest(mPreviewRequest[id], mCaptureCallback,
- mCameraHandler);
+ mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id].build(),
+ mCaptureCallback, mCameraHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
+
/**
* Closes the current {@link CameraDevice}.
*/
@@ -719,6 +826,9 @@ public class CaptureModule implements CameraModule, PhotoController {
}
private void openCamera(int id) {
+ if (mPaused) {
+ return;
+ }
Log.d(TAG, "openCamera " + id);
CameraManager manager;
try {
@@ -743,13 +853,14 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onPauseBeforeSuper() {
-
+ mPaused = true;
}
@Override
public void onPauseAfterSuper() {
Log.d(TAG, "onPause");
mUI.showPreviewCover();
+ if (mLocationManager != null) mLocationManager.recordLocation(false);
stopBackgroundThread();
closeCamera();
mUI.onPause();
@@ -757,13 +868,14 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onResumeBeforeSuper() {
-
+ mPaused = false;
}
@Override
public void onResumeAfterSuper() {
Log.d(TAG, "onResume " + MODE);
setUpCameraOutputs();
+ readInitialValues();
startBackgroundThread();
Message msg = Message.obtain();
msg.what = OPEN_CAMERA;
@@ -779,9 +891,13 @@ public class CaptureModule implements CameraModule, PhotoController {
mCameraHandler.sendMessage(msg);
break;
}
+ if (!mFirstTimeInitialized) {
+ initializeFirstTime();
+ } else {
+ initializeSecondTime();
+ }
mUI.hidePreviewCover();
mUI.enableShutter(true);
- mUI.initializeFirstTime();
}
@Override
@@ -891,11 +1007,23 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void enableRecordingLocation(boolean enable) {
+ Log.d(TAG, "CaptureModule enableRecordingLocation " + enable);
+ setLocationPreference(enable ? RecordLocationPreference.VALUE_ON
+ : RecordLocationPreference.VALUE_OFF);
+ }
+ private void setLocationPreference(String value) {
+ mPreferences.edit()
+ .putString(CameraSettings.KEY_RECORD_LOCATION, value)
+ .apply();
+ prefListener.onSharedPreferenceChanged();
}
@Override
public void onPreviewUIReady() {
+ if (mPaused) {
+ return;
+ }
Log.d(TAG, "onPreviewUIReady");
mSurfaceReady = true;
switch (MODE) {
@@ -939,7 +1067,15 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onOrientationChanged(int orientation) {
-
+ // We keep the last known orientation. So if the user first orient
+ // the camera then point the camera to floor or sky, we still have
+ // the correct orientation.
+ if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
+ int oldOrientation = mOrientation;
+ mOrientation = CameraUtil.roundOrientation(orientation, mOrientation);
+ if (oldOrientation != mOrientation) {
+ mUI.setOrientation(mOrientation, true);
+ }
}
@Override
@@ -949,7 +1085,9 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onMediaSaveServiceConnected(MediaSaveService s) {
-
+ if (mFirstTimeInitialized) {
+ s.setListener(this);
+ }
}
@Override
@@ -964,7 +1102,15 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onSwitchSavePath() {
-
+ if (mUI.mMenuInitialized) {
+ mUI.setPreference(CameraSettings.KEY_CAMERA_SAVEPATH, "1");
+ } else {
+ mPreferences.edit()
+ .putString(CameraSettings.KEY_CAMERA_SAVEPATH, "1")
+ .apply();
+ }
+ RotateTextToast.makeText(mActivity, R.string.on_switch_save_path_to_sdcard,
+ Toast.LENGTH_SHORT).show();
}
@Override
@@ -982,27 +1128,142 @@ public class CaptureModule implements CameraModule, PhotoController {
}
+ private boolean isFlashOff() {
+ return readSetting(CameraSettings.KEY_FLASH_MODE).equals("off");
+ }
+
+ private void initializePreviewConfiguration(int id) {
+ mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_MODE, CaptureRequest
+ .CONTROL_MODE_AUTO);
+ mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest
+ .CONTROL_AF_MODE_CONTINUOUS_PICTURE);
+ mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest
+ .CONTROL_AF_TRIGGER_IDLE);
+ mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest
+ .CONTROL_AE_MODE_ON);
+ mPreviewRequestBuilder[id].set(CaptureRequest.FLASH_MODE, CaptureRequest
+ .FLASH_MODE_OFF);
+ applyWhiteBalance(mPreviewRequestBuilder[id]);
+ }
+
+ private void readInitialValues() {
+ for (int i = 0; i < mPreferenceGroup.size(); i++) {
+ CameraPreference pref = mPreferenceGroup.get(i);
+ if (pref instanceof ListPreference) {
+ ListPreference listPref = (ListPreference) pref;
+ storeSetting(listPref.getKey(), listPref.getValue());
+ }
+ }
+ }
+
+ private void applyCaptureSettings(CaptureRequest.Builder request) {
+ applyFlash(request);
+ applyWhiteBalance(request);
+ applyJpegQuality(request);
+ }
+
private void applyPreference(int cameraId, ListPreference pref) {
+ boolean updatePreview = false;
String key = pref.getKey();
String value = pref.getValue();
- if (key.equals(CameraSettings.KEY_FLASH_MODE)) {
- if (value.equals("on")) {
- mCaptureBuilder[cameraId].set(CaptureRequest.CONTROL_AE_MODE,
- CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
- } else if (value.equals("auto")) {
- mCaptureBuilder[cameraId].set(CaptureRequest.CONTROL_AE_MODE,
- CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
- } else if (value.equals("off")) {
- mCaptureBuilder[cameraId].set(CaptureRequest.CONTROL_AE_MODE,
- CaptureRequest.CONTROL_AE_MODE_ON);
- }
- } else if (key.equals(CameraSettings.KEY_MONO_PREVIEW)) {
- if (value.equals("on")) {
- } else if (value.equals("off")) {
+ storeSetting(key, value);
+ switch (key) {
+ //Todo: CreateUISettings file and add UI preference settings to there
+ case CameraSettings.KEY_JPEG_QUALITY:
+ mJpegQuality = getQualityNumber(value);
+ break;
+ case CameraSettings.KEY_WHITE_BALANCE:
+ updatePreview = true;
+ applyWhiteBalance(mPreviewRequestBuilder[cameraId]);
+ break;
+ }
+ if (updatePreview) {
+ try {
+ mCaptureSession[cameraId].setRepeatingRequest(mPreviewRequestBuilder[cameraId]
+ .build(), mCaptureCallback, mCameraHandler);
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
}
}
}
+ private void storeSetting(String key, String value) {
+ mSettings.put(key, value);
+ }
+
+ private String readSetting(String key) {
+ return mSettings.get(key);
+ }
+
+ private void applyJpegQuality(CaptureRequest.Builder request) {
+ request.set(CaptureRequest.JPEG_QUALITY, (byte) mJpegQuality);
+ }
+
+ private void applyWhiteBalance(CaptureRequest.Builder request) {
+ String value = readSetting(CameraSettings.KEY_WHITE_BALANCE);
+ switch (value) {
+ case "incandescent":
+ request.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest
+ .CONTROL_AWB_MODE_INCANDESCENT);
+ break;
+ case "fluorescent":
+ request.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest
+ .CONTROL_AWB_MODE_FLUORESCENT);
+ break;
+ case "auto":
+ request.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest
+ .CONTROL_AWB_MODE_AUTO);
+ break;
+ case "daylight":
+ request.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest
+ .CONTROL_AWB_MODE_DAYLIGHT);
+ break;
+ case "cloudy-daylight":
+ request.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest
+ .CONTROL_AWB_MODE_CLOUDY_DAYLIGHT);
+ break;
+ }
+ }
+
+ private Surface getPreviewSurface(int id) {
+ if (MODE == DUAL_MODE && id == MONO_ID) {
+ return mUI.getSurfaceHolder2().getSurface();
+ } else {
+ return mUI.getSurfaceHolder().getSurface();
+ }
+ }
+
+ private void applyFlash(CaptureRequest.Builder request, String value) {
+ switch (value) {
+ case "on":
+ request.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest
+ .CONTROL_AE_MODE_ON_ALWAYS_FLASH);
+ request.set(CaptureRequest.FLASH_MODE, CaptureRequest
+ .FLASH_MODE_SINGLE);
+ break;
+ case "auto":
+ request.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest
+ .CONTROL_AE_MODE_ON_AUTO_FLASH);
+ break;
+ case "off":
+ request.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest
+ .CONTROL_AE_MODE_ON);
+ request.set(CaptureRequest.FLASH_MODE, CaptureRequest
+ .FLASH_MODE_OFF);
+ break;
+ }
+ }
+
+ private void applyFlash(CaptureRequest.Builder request) {
+ String value = readSetting(CameraSettings.KEY_FLASH_MODE);
+ applyFlash(request, value);
+ }
+
+ @Override
+ public void onQueueStatus(boolean full) {
+ mUI.enableShutter(!full);
+ }
+
/**
* Compares two {@code Size}s based on their areas.
*/
diff --git a/src/com/android/camera/CaptureUI.java b/src/com/android/camera/CaptureUI.java
index 97db3ac..ed10207 100644
--- a/src/com/android/camera/CaptureUI.java
+++ b/src/com/android/camera/CaptureUI.java
@@ -70,7 +70,7 @@ public class CaptureUI implements PieListener,
CameraManager.CameraFaceDetectionCallback {
private static final String TAG = "SnapCam_CaptureUI";
- private boolean mMenuInitialized = false;
+ public boolean mMenuInitialized = false;
private boolean surface1created = false;
private boolean surface2created = false;
private CameraActivity mActivity;
@@ -351,20 +351,19 @@ public class CaptureUI implements PieListener,
mShutterButton.setVisibility(View.VISIBLE);
}
- public void doShutterAnimation() {
- AnimationDrawable frameAnimation = (AnimationDrawable) mShutterButton.getDrawable();
- frameAnimation.stop();
- frameAnimation.start();
- }
-
// called from onResume every other time
- public void initializeSecondTime(Camera.Parameters params) {
- initializeZoom(params);
+ public void initializeSecondTime() {
if (mMenu != null) {
mMenu.reloadPreferences();
}
}
+ public void doShutterAnimation() {
+ AnimationDrawable frameAnimation = (AnimationDrawable) mShutterButton.getDrawable();
+ frameAnimation.stop();
+ frameAnimation.start();
+ }
+
public void initializeZoom(Camera.Parameters params) {
if ((params == null) || !params.isZoomSupported()
|| (mZoomRenderer == null)) return;