|
|
|
@ -12,6 +12,7 @@ import android.os.Build;
|
|
|
|
|
import android.os.Looper;
|
|
|
|
|
import android.os.Message;
|
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.view.OrientationEventListener;
|
|
|
|
|
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
@ -155,6 +156,18 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
*/
|
|
|
|
|
private static final int STATE_WAITING_FOR_3A_CONVERGENCE = 3;
|
|
|
|
|
|
|
|
|
|
private Runnable mTakePictureRunner = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
mMessageHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
takePicture();
|
|
|
|
|
}
|
|
|
|
|
}, 400);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An {@link OrientationEventListener} used to determine when device rotation has occurred.
|
|
|
|
|
* This is mainly necessary for when the device is rotated by 180 degrees, in which case
|
|
|
|
@ -181,12 +194,8 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
if (!mTaken) {
|
|
|
|
|
mTaken = true;
|
|
|
|
|
|
|
|
|
|
mMessageHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
takePicture();
|
|
|
|
|
}
|
|
|
|
|
}, 400);
|
|
|
|
|
mMessageHandler.removeCallbacks(mTakePictureRunner);
|
|
|
|
|
mMessageHandler.postDelayed(mTakePictureRunner, 400);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -199,12 +208,8 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
if (!mTaken) {
|
|
|
|
|
mTaken = true;
|
|
|
|
|
|
|
|
|
|
mMessageHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
takePicture();
|
|
|
|
|
}
|
|
|
|
|
}, 400);
|
|
|
|
|
mMessageHandler.removeCallbacks(mTakePictureRunner);
|
|
|
|
|
mMessageHandler.postDelayed(mTakePictureRunner, 400);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -357,6 +362,9 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
public void onOpened(CameraDevice cameraDevice) {
|
|
|
|
|
// This method is called when the camera is opened. We start camera preview here if
|
|
|
|
|
// the TextureView displaying this has been set up.
|
|
|
|
|
|
|
|
|
|
MicroPhotoService.infoLog("RawActivity onOpened PHOTOID=" + Long.toString(mPhotoId));
|
|
|
|
|
|
|
|
|
|
synchronized (mCameraStateLock) {
|
|
|
|
|
mState = STATE_OPENED;
|
|
|
|
|
mCameraOpenCloseLock.release();
|
|
|
|
@ -381,16 +389,29 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(CameraDevice cameraDevice, int error) {
|
|
|
|
|
Log.e(TAG, "Received camera device error: " + error);
|
|
|
|
|
MicroPhotoService.infoLog("RawActivity Received camera device error: " + Integer.toString(error) + " PHOTOID=" + Long.toString(mPhotoId));
|
|
|
|
|
synchronized (mCameraStateLock) {
|
|
|
|
|
mState = STATE_CLOSED;
|
|
|
|
|
mCameraOpenCloseLock.release();
|
|
|
|
|
cameraDevice.close();
|
|
|
|
|
mCameraDevice = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
broadcastPhotoFile(false, "");
|
|
|
|
|
|
|
|
|
|
mMessageHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -582,6 +603,17 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
*/
|
|
|
|
|
private final Handler mMessageHandler = new Handler(Looper.getMainLooper());
|
|
|
|
|
|
|
|
|
|
private int getDeviceRotation() {
|
|
|
|
|
int deviceRotation = getWindowManager().getDefaultDisplay().getRotation();
|
|
|
|
|
/*
|
|
|
|
|
if (mOrientation > 0) {
|
|
|
|
|
deviceRotation = mOrientation / 90;
|
|
|
|
|
} else {
|
|
|
|
|
deviceRotation = 0;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return deviceRotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
@ -723,11 +755,13 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
Size largestJpeg = Collections.max(
|
|
|
|
|
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
|
|
|
|
|
new CompareSizesByArea());
|
|
|
|
|
largestJpeg = mImageSize;
|
|
|
|
|
|
|
|
|
|
outputSizes = map.getOutputSizes(ImageFormat.RAW_SENSOR);
|
|
|
|
|
Size largestRaw = Collections.max(
|
|
|
|
|
Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)),
|
|
|
|
|
new CompareSizesByArea());
|
|
|
|
|
largestRaw = mImageSize;
|
|
|
|
|
|
|
|
|
|
synchronized (mCameraStateLock) {
|
|
|
|
|
// Set up ImageReaders for JPEG and RAW outputs. Place these in a reference
|
|
|
|
@ -735,16 +769,16 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
// using them are finished.
|
|
|
|
|
if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) {
|
|
|
|
|
mJpegImageReader = new RefCountedAutoCloseable<>(
|
|
|
|
|
ImageReader.newInstance(mImageSize.getWidth(),
|
|
|
|
|
mImageSize.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
|
|
|
|
|
ImageReader.newInstance(largestJpeg.getWidth(),
|
|
|
|
|
largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
|
|
|
|
|
}
|
|
|
|
|
mJpegImageReader.get().setOnImageAvailableListener(
|
|
|
|
|
mOnJpegImageAvailableListener, mBackgroundHandler);
|
|
|
|
|
|
|
|
|
|
if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) {
|
|
|
|
|
mRawImageReader = new RefCountedAutoCloseable<>(
|
|
|
|
|
ImageReader.newInstance(mImageSize.getWidth(),
|
|
|
|
|
mImageSize.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
|
|
|
|
|
ImageReader.newInstance(largestRaw.getWidth(),
|
|
|
|
|
largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
|
|
|
|
|
}
|
|
|
|
|
mRawImageReader.get().setOnImageAvailableListener(
|
|
|
|
|
mOnRawImageAvailableListener, mBackgroundHandler);
|
|
|
|
@ -997,10 +1031,7 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
new CompareSizesByArea());
|
|
|
|
|
|
|
|
|
|
// Find the rotation of the device relative to the native device orientation.
|
|
|
|
|
int deviceRotation = getWindowManager().getDefaultDisplay().getRotation();
|
|
|
|
|
if (mOrientation > 0) {
|
|
|
|
|
deviceRotation = mOrientation - 1;
|
|
|
|
|
}
|
|
|
|
|
int deviceRotation = getDeviceRotation();
|
|
|
|
|
Point displaySize = new Point();
|
|
|
|
|
getWindowManager().getDefaultDisplay().getSize(displaySize);
|
|
|
|
|
|
|
|
|
@ -1106,6 +1137,8 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
* auto-white-balance to converge.
|
|
|
|
|
*/
|
|
|
|
|
private void takePicture() {
|
|
|
|
|
|
|
|
|
|
MicroPhotoService.infoLog("RawActivity takePicture PHOTOID=" + Long.toString(mPhotoId));
|
|
|
|
|
synchronized (mCameraStateLock) {
|
|
|
|
|
mPendingUserCaptures++;
|
|
|
|
|
|
|
|
|
@ -1169,7 +1202,7 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
setup3AControlsLocked(captureBuilder);
|
|
|
|
|
|
|
|
|
|
// Set orientation.
|
|
|
|
|
int rotation = getWindowManager().getDefaultDisplay().getRotation();
|
|
|
|
|
int rotation = getDeviceRotation();
|
|
|
|
|
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
|
|
|
|
|
sensorToDeviceRotation(mCharacteristics, rotation));
|
|
|
|
|
|
|
|
|
@ -1354,13 +1387,15 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
closeOutput(output);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
mImage.close();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ImageFormat.RAW_SENSOR: {
|
|
|
|
|
DngCreator dngCreator = new DngCreator(mCharacteristics, mCaptureResult);
|
|
|
|
|
FileOutputStream output = null;
|
|
|
|
|
try {
|
|
|
|
|
MicroPhotoService.infoLog("RawActivity Image Size=" + Integer.toString(mImage.getWidth()) + "," + Integer.toString(mImage.getHeight()));
|
|
|
|
|
String log = "RawActivity Image Size=" + Integer.toString(mImage.getWidth()) + "," + Integer.toString(mImage.getHeight());
|
|
|
|
|
MicroPhotoService.infoLog(log);
|
|
|
|
|
output = new FileOutputStream(mFile);
|
|
|
|
|
dngCreator.writeImage(output, mImage);
|
|
|
|
|
mResult = true;
|
|
|
|
@ -1770,7 +1805,9 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
// intent.setPackage(packageName);
|
|
|
|
|
intent.putExtra("photoOrVideo", true);
|
|
|
|
|
intent.putExtra("result", result);
|
|
|
|
|
if (!TextUtils.isEmpty(path)) {
|
|
|
|
|
intent.putExtra("path", path);
|
|
|
|
|
}
|
|
|
|
|
intent.putExtra("videoId", mPhotoId);
|
|
|
|
|
|
|
|
|
|
// intent.setComponent(new ComponentName(packageName, receiverName));
|
|
|
|
|