You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.8 KiB
Java
90 lines
2.8 KiB
Java
3 months ago
|
package com.xypower.camera2raw;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.hardware.camera2.CameraCharacteristics;
|
||
|
import android.hardware.camera2.CaptureResult;
|
||
|
import android.media.Image;
|
||
|
import android.media.ImageReader;
|
||
|
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.util.ArrayList;
|
||
|
|
||
|
public class ImageSaverBuilder {
|
||
|
public Image mImage;
|
||
|
public File mFile;
|
||
|
public CaptureResult mCaptureResult;
|
||
|
public CameraCharacteristics mCharacteristics;
|
||
|
public Context mContext;
|
||
|
public Camera2RawFragment.RefCountedAutoCloseable<ImageReader> mReader;
|
||
|
public ImageSaver.ImagePair mImagePair;
|
||
|
|
||
|
private CompleteCallback mCallback;
|
||
|
|
||
|
/**
|
||
|
* Construct a new ImageSaverBuilder using the given {@link Context}.
|
||
|
*
|
||
|
* @param context a {@link Context} to for accessing the
|
||
|
* {@link android.provider.MediaStore}.
|
||
|
*/
|
||
|
public ImageSaverBuilder(final Context context) {
|
||
|
mContext = context;
|
||
|
}
|
||
|
|
||
|
public synchronized ImageSaverBuilder setRefCountedReader(Camera2RawFragment.RefCountedAutoCloseable<ImageReader> reader) {
|
||
|
if (reader == null) throw new NullPointerException();
|
||
|
|
||
|
mReader = reader;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public synchronized ImageSaverBuilder setImage(final Image image) {
|
||
|
if (image == null) throw new NullPointerException();
|
||
|
mImage = image;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public synchronized ImageSaverBuilder setImagePair(final ImageSaver.ImagePair imagePair) {
|
||
|
if (imagePair == null) throw new NullPointerException();
|
||
|
mImagePair = imagePair;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public synchronized ImageSaverBuilder setFile(final File file) {
|
||
|
if (file == null) throw new NullPointerException();
|
||
|
mFile = file;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public synchronized ImageSaverBuilder setResult(final CaptureResult result) {
|
||
|
if (result == null) throw new NullPointerException();
|
||
|
mCaptureResult = result;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
|
||
|
public synchronized ImageSaverBuilder setCharacteristics(final CameraCharacteristics characteristics) {
|
||
|
if (characteristics == null) throw new NullPointerException();
|
||
|
mCharacteristics = characteristics;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public synchronized ImageSaverBuilder setCallback(CompleteCallback callback) {
|
||
|
mCallback = callback;
|
||
|
return this;
|
||
|
}
|
||
|
public synchronized ImageSaver buildIfComplete() {
|
||
|
if (!isComplete()) {
|
||
|
return null;
|
||
|
}
|
||
|
return new ImageSaver(mImage, mFile, mCaptureResult, mCharacteristics, mReader, mCallback, mImagePair);
|
||
|
}
|
||
|
|
||
|
public synchronized String getSaveLocation() {
|
||
|
return (mFile == null) ? "Unknown" : mFile.toString();
|
||
|
}
|
||
|
|
||
|
private boolean isComplete() {
|
||
|
return mImage != null && mFile != null && mCaptureResult != null && mCharacteristics != null;
|
||
|
}
|
||
|
}
|