|
|
@ -551,12 +551,7 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A {@link Handler} for showing {@link Toast}s on the UI thread.
|
|
|
|
* A {@link Handler} for showing {@link Toast}s on the UI thread.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private final Handler mMessageHandler = new Handler(Looper.getMainLooper()) {
|
|
|
|
private final Handler mMessageHandler = new Handler(Looper.getMainLooper());
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void handleMessage(Message msg) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -584,19 +579,15 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
mCameraId = Integer.toString(intent.getIntExtra("cameraId", 0));
|
|
|
|
mCameraId = Integer.toString(intent.getIntExtra("cameraId", 0));
|
|
|
|
mOrientation = intent.getIntExtra("orientation", -1);
|
|
|
|
mOrientation = intent.getIntExtra("orientation", -1);
|
|
|
|
|
|
|
|
|
|
|
|
int width = intent.getIntExtra("width", 0);
|
|
|
|
int width = intent.getIntExtra("width", MAX_PREVIEW_WIDTH);
|
|
|
|
int height = intent.getIntExtra("height", 0);
|
|
|
|
int height = intent.getIntExtra("height", MAX_PREVIEW_HEIGHT);
|
|
|
|
|
|
|
|
|
|
|
|
mImageSize = new Size(width, height);
|
|
|
|
mImageSize = new Size(width, height);
|
|
|
|
|
|
|
|
|
|
|
|
mPhotoId = intent.getLongExtra("videoId", 0);
|
|
|
|
mPhotoId = intent.getLongExtra("videoId", 0);
|
|
|
|
|
|
|
|
|
|
|
|
mMessageHandler.postDelayed(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
mTextureView.setAspectRatio(width, height);
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
takePicture();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 400);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -618,6 +609,13 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
if (mOrientationListener != null && mOrientationListener.canDetectOrientation()) {
|
|
|
|
if (mOrientationListener != null && mOrientationListener.canDetectOrientation()) {
|
|
|
|
mOrientationListener.enable();
|
|
|
|
mOrientationListener.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mMessageHandler.postDelayed(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
takePicture();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -641,33 +639,27 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String[] cameraIds = manager.getCameraIdList();
|
|
|
|
|
|
|
|
// Find a CameraDevice that supports RAW captures, and configure state.
|
|
|
|
|
|
|
|
for (String cameraId : cameraIds) {
|
|
|
|
|
|
|
|
CameraCharacteristics characteristics
|
|
|
|
CameraCharacteristics characteristics
|
|
|
|
= manager.getCameraCharacteristics(cameraId);
|
|
|
|
= manager.getCameraCharacteristics(mCameraId);
|
|
|
|
|
|
|
|
|
|
|
|
int[] capabilities = characteristics.get(
|
|
|
|
int[] capabilities = characteristics.get(
|
|
|
|
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
|
|
|
|
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
|
|
|
|
// We only use a camera that supports RAW in this sample.
|
|
|
|
// We only use a camera that supports RAW in this sample.
|
|
|
|
if (!contains(capabilities,
|
|
|
|
if (!contains(capabilities,
|
|
|
|
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) {
|
|
|
|
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) {
|
|
|
|
continue;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
|
|
|
|
|
|
|
|
if (facing != CameraMetadata.LENS_FACING_FRONT) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StreamConfigurationMap map = characteristics.get(
|
|
|
|
StreamConfigurationMap map = characteristics.get(
|
|
|
|
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
|
|
|
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
|
|
|
|
|
|
|
|
|
|
|
// For still image captures, we use the largest available size.
|
|
|
|
// For still image captures, we use the largest available size.
|
|
|
|
|
|
|
|
Size[] outputSizes = map.getOutputSizes(ImageFormat.JPEG);
|
|
|
|
Size largestJpeg = Collections.max(
|
|
|
|
Size largestJpeg = Collections.max(
|
|
|
|
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
|
|
|
|
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
|
|
|
|
new CompareSizesByArea());
|
|
|
|
new CompareSizesByArea());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outputSizes = map.getOutputSizes(ImageFormat.RAW_SENSOR);
|
|
|
|
Size largestRaw = Collections.max(
|
|
|
|
Size largestRaw = Collections.max(
|
|
|
|
Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)),
|
|
|
|
Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)),
|
|
|
|
new CompareSizesByArea());
|
|
|
|
new CompareSizesByArea());
|
|
|
@ -678,25 +670,24 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
// using them are finished.
|
|
|
|
// using them are finished.
|
|
|
|
if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) {
|
|
|
|
if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) {
|
|
|
|
mJpegImageReader = new RefCountedAutoCloseable<>(
|
|
|
|
mJpegImageReader = new RefCountedAutoCloseable<>(
|
|
|
|
ImageReader.newInstance(largestJpeg.getWidth(),
|
|
|
|
ImageReader.newInstance(mImageSize.getWidth(),
|
|
|
|
largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
|
|
|
|
mImageSize.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mJpegImageReader.get().setOnImageAvailableListener(
|
|
|
|
mJpegImageReader.get().setOnImageAvailableListener(
|
|
|
|
mOnJpegImageAvailableListener, mBackgroundHandler);
|
|
|
|
mOnJpegImageAvailableListener, mBackgroundHandler);
|
|
|
|
|
|
|
|
|
|
|
|
if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) {
|
|
|
|
if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) {
|
|
|
|
mRawImageReader = new RefCountedAutoCloseable<>(
|
|
|
|
mRawImageReader = new RefCountedAutoCloseable<>(
|
|
|
|
ImageReader.newInstance(largestRaw.getWidth(),
|
|
|
|
ImageReader.newInstance(mImageSize.getWidth(),
|
|
|
|
largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
|
|
|
|
mImageSize.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mRawImageReader.get().setOnImageAvailableListener(
|
|
|
|
mRawImageReader.get().setOnImageAvailableListener(
|
|
|
|
mOnRawImageAvailableListener, mBackgroundHandler);
|
|
|
|
mOnRawImageAvailableListener, mBackgroundHandler);
|
|
|
|
|
|
|
|
|
|
|
|
mCharacteristics = characteristics;
|
|
|
|
mCharacteristics = characteristics;
|
|
|
|
mCameraId = cameraId;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (CameraAccessException e) {
|
|
|
|
} catch (CameraAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -854,6 +845,7 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
|
|
|
|
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
|
|
|
|
// showToast("Failed to configure camera.");
|
|
|
|
// showToast("Failed to configure camera.");
|
|
|
|
|
|
|
|
int aa = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, mBackgroundHandler
|
|
|
|
}, mBackgroundHandler
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -941,6 +933,9 @@ public class RawActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
// Find the rotation of the device relative to the native device orientation.
|
|
|
|
// Find the rotation of the device relative to the native device orientation.
|
|
|
|
int deviceRotation = getWindowManager().getDefaultDisplay().getRotation();
|
|
|
|
int deviceRotation = getWindowManager().getDefaultDisplay().getRotation();
|
|
|
|
|
|
|
|
if (mOrientation > 0) {
|
|
|
|
|
|
|
|
deviceRotation = mOrientation - 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
Point displaySize = new Point();
|
|
|
|
Point displaySize = new Point();
|
|
|
|
getWindowManager().getDefaultDisplay().getSize(displaySize);
|
|
|
|
getWindowManager().getDefaultDisplay().getSize(displaySize);
|
|
|
|
|
|
|
|
|
|
|
|