|
|
@ -7,7 +7,9 @@ import android.graphics.Bitmap; |
|
|
|
import android.graphics.BitmapFactory; |
|
|
|
import android.graphics.BitmapFactory; |
|
|
|
import android.graphics.Matrix; |
|
|
|
import android.graphics.Matrix; |
|
|
|
import android.hardware.Camera; |
|
|
|
import android.hardware.Camera; |
|
|
|
|
|
|
|
import android.net.Uri; |
|
|
|
import android.os.Handler; |
|
|
|
import android.os.Handler; |
|
|
|
|
|
|
|
import android.os.ParcelFileDescriptor; |
|
|
|
|
|
|
|
|
|
|
|
import com.otaliastudios.cameraview.controls.Facing; |
|
|
|
import com.otaliastudios.cameraview.controls.Facing; |
|
|
|
import com.otaliastudios.cameraview.engine.mappers.Camera1Mapper; |
|
|
|
import com.otaliastudios.cameraview.engine.mappers.Camera1Mapper; |
|
|
@ -98,6 +100,23 @@ public class CameraUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
@WorkerThread |
|
|
|
|
|
|
|
@SuppressLint("NewApi") |
|
|
|
|
|
|
|
public static Uri writeToFile(Context context, @NonNull final byte[] data, @NonNull Uri file) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
ParcelFileDescriptor fd = context.getContentResolver().openFileDescriptor(file, "w"); |
|
|
|
|
|
|
|
OutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd); |
|
|
|
|
|
|
|
stream.write(data); |
|
|
|
|
|
|
|
stream.flush(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
return file; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes the given data to the given file in a background thread, returning on the |
|
|
|
* Writes the given data to the given file in a background thread, returning on the |
|
|
@ -128,6 +147,26 @@ public class CameraUtils { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
|
|
|
|
public static void writeToFile(final Context context, |
|
|
|
|
|
|
|
@NonNull final byte[] data, |
|
|
|
|
|
|
|
@NonNull final Uri file, |
|
|
|
|
|
|
|
@NonNull final FileUriCallback callback) { |
|
|
|
|
|
|
|
final Handler ui = new Handler(); |
|
|
|
|
|
|
|
WorkerHandler.execute(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
final Uri result = writeToFile(context, data, file); |
|
|
|
|
|
|
|
ui.post(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
callback.onFileReady(result); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Decodes an input byte array and outputs a Bitmap that is ready to be displayed. |
|
|
|
* Decodes an input byte array and outputs a Bitmap that is ready to be displayed. |
|
|
|
* The difference with {@link android.graphics.BitmapFactory#decodeByteArray(byte[], int, int)} |
|
|
|
* The difference with {@link android.graphics.BitmapFactory#decodeByteArray(byte[], int, int)} |
|
|
|