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.
91 lines
2.9 KiB
Java
91 lines
2.9 KiB
Java
package com.xypower.mppreview;
|
|
|
|
import android.content.Context;
|
|
import android.hardware.camera2.CameraCharacteristics;
|
|
import android.hardware.camera2.CaptureResult;
|
|
import android.media.Image;
|
|
import android.media.ImageReader;
|
|
|
|
import com.xypower.mppreview.bean.PngPhotoBean;
|
|
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ImageSaverBuilder {
|
|
public Image mImage;
|
|
public File mFile;
|
|
public CaptureResult mCaptureResult;
|
|
public CameraCharacteristics mCharacteristics;
|
|
public Context mContext;
|
|
public Camera2RawFragment.RefCountedAutoCloseable<ImageReader> mReader;
|
|
|
|
private ArrayList<PngPhotoBean> mlist;
|
|
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 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 setList(ArrayList<PngPhotoBean> list) {
|
|
if (list == null) throw new NullPointerException();
|
|
mlist = list;
|
|
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, mContext, mReader, mlist,mCallback);
|
|
}
|
|
|
|
public synchronized String getSaveLocation() {
|
|
return (mFile == null) ? "Unknown" : mFile.toString();
|
|
}
|
|
|
|
private boolean isComplete() {
|
|
return mImage != null && mFile != null && mCaptureResult != null && mCharacteristics != null;
|
|
}
|
|
} |