Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ private void saveImage(Size imageDimension, File ImageFile) {
uri = Utils.broadcastNewPicture(mActivity.getApplicationContext(), mCurrentPictureValues);

ic_camera.setCurrentUri(uri);
ic_camera.setImagePath(ImageFile.getAbsolutePath());

ic_camera.setCurrentFileInfo(mCurrentPictureValues);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public class FullScreenActivity extends AppCompatActivity {
MultiCamera mCameraInst;
private TextView mRecordingTimeView;
private boolean mIsRecordingVideo;
private CameraBase mCameraBack;
private CameraBase mCameraFront;
private CameraBase mCamera;
private RoundedThumbnailView mRoundedThumbnailView;
private BroadcastReceiver mUsbReceiver;

Expand Down Expand Up @@ -103,7 +102,7 @@ protected void onCreate(Bundle savedInstanceState) {

checkPermissions();

openBackCamera();
OpenCamera();
try {
final IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
Expand Down Expand Up @@ -174,14 +173,26 @@ public void onClick(View v) {
mLastClickTime = SystemClock.elapsedRealtime();
MultiCamera ic_camera = MultiCamera.getInstance();
if (ic_camera.getWhichCamera() == 0) {
openFrontCamera();
mCameraInst.setOpenCameraId(1);
ic_camera.setWhichCamera(1);
Log.i(TAG,"Opened front camera");
closeCamera();

unregisterReceiver(mUsbReceiver);
startActivity(new Intent(getApplicationContext(), FullScreenActivity.class));
ic_camera.setWhichCamera(1);
finishAffinity();
}
else {
openBackCamera();
mCameraInst.setOpenCameraId(0);
ic_camera.setWhichCamera(0);

Log.i(TAG,"Opened back camera");
closeCamera();
unregisterReceiver(mUsbReceiver);
startActivity(new Intent(getApplicationContext(), FullScreenActivity.class));
ic_camera.setWhichCamera(0);
finishAffinity();
}

}
Expand Down Expand Up @@ -231,12 +242,7 @@ public void onClick(View v) {
mCameraPicture.setVisibility(View.VISIBLE);
mCameraSwitch.setVisibility(View.VISIBLE);
mCameraSplit.setVisibility(View.VISIBLE);
if (ic_camera.getWhichCamera() == 1) {
mCameraFront.createCameraPreview();
}
else {
mCameraBack.createCameraPreview();
}
mCamera.createCameraPreview();
}
});

Expand All @@ -245,6 +251,7 @@ public void onClick(View v) {
public void onClick(View v) {
MultiCamera ic_camera = MultiCamera.getInstance();
ic_camera.setIsCameraOrSurveillance(1);
unregisterReceiver(mUsbReceiver);
Intent intent = new Intent(FullScreenActivity.this, MultiViewActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Expand All @@ -260,14 +267,10 @@ public void onClick(View v) {
return;
}
mLastClickTime = SystemClock.elapsedRealtime();
if (MultiCamera.getInstance().getWhichCamera() == 1) {
if (mCameraFront != null)
mCameraFront.takePicture();
}
else {
if (mCameraBack != null)
mCameraBack.takePicture();
}

if (mCamera != null)
mCamera.takePicture();

}
});

Expand All @@ -282,16 +285,11 @@ public void onClick(View view) {
try {
if (mIsRecordingVideo) {
mIsRecordingVideo = false;
if (mCameraInst.getWhichCamera() == 0) {
mCameraBack.getmRecord().stopRecordingVideo();
mCameraBack.getmRecord().showRecordingUI(false);
mCameraBack.getmPhoto().showVideoThumbnail();
}
else {
mCameraFront.getmRecord().stopRecordingVideo();
mCameraFront.getmRecord().showRecordingUI(false);
mCameraFront.getmPhoto().showVideoThumbnail();
}

mCamera.getmRecord().stopRecordingVideo();
mCamera.getmRecord().showRecordingUI(false);
mCamera.getmPhoto().showVideoThumbnail();


if (numOfCameras > 1) {
mCameraSwitch.setVisibility(View.VISIBLE);
Expand All @@ -303,14 +301,10 @@ public void onClick(View view) {
mSettings.setVisibility(View.VISIBLE);
} else {
mIsRecordingVideo =true;
if (mCameraInst.getWhichCamera() == 0) {
mCameraBack.getmRecord().startRecordingVideo();
mCameraBack.getmRecord().showRecordingUI(true);
}
else {
mCameraFront.getmRecord().startRecordingVideo();
mCameraFront.getmRecord().showRecordingUI(true);
}

mCamera.getmRecord().startRecordingVideo();
mCamera.getmRecord().showRecordingUI(true);

mSettings.setVisibility(View.GONE);
mCameraSwitch.setVisibility(View.GONE);
mCameraPicture.setVisibility(View.GONE);
Expand All @@ -324,7 +318,7 @@ public void onClick(View view) {
});
}

public void openBackCamera() {
public void OpenCamera() {
closeCamera();

GetCameraCnt();
Expand All @@ -340,47 +334,14 @@ public void openBackCamera() {

updateStorageSpace(null);

OpenOnlyBackCamera();
Open_Camera();
}

public void openFrontCamera() {
closeCamera();

GetCameraCnt();
updateStorageSpace(null);

OpenOnlyFrontCamera();
}

private void OpenOnlyFrontCamera() {

mCamera_FrontView = findViewById(R.id.textureview);
if (mCamera_FrontView == null) {
Log.e(TAG, "fail to get surface for front view");
return;
}
if (mCameraFront == null) {
Open_FrontCamera();
}

if (mCamera_FrontView.isAvailable()) {
mCameraFront.textureListener.onSurfaceTextureAvailable(
mCamera_FrontView.getSurfaceTexture(),
mCamera_FrontView.getWidth(), mCamera_FrontView.getHeight());
} else {
mCamera_FrontView.setSurfaceTextureListener(mCameraFront.textureListener);
}
}
private void closeCamera() {

if (null != mCameraBack) {
mCameraBack.closeCamera();
mCameraBack = null;
}

if (null != mCameraFront) {
mCameraFront.closeCamera();
mCameraFront = null;
if (null != mCamera) {
mCamera.closeCamera();
mCamera = null;
}
}

Expand All @@ -401,50 +362,37 @@ public void GetCameraCnt() {
}
}

private void OpenOnlyBackCamera() {
private void Open_Camera() {
mCamera_BackView = findViewById(R.id.textureview);
if (mCamera_BackView == null) {
Log.e(TAG, "fail to find surface for back camera");
return;
}
if (mCameraBack == null) {
Open_BackCamera();
if (mCamera == null) {
Open_Camera_ById();
}
if (mCamera_BackView.isAvailable()) {
mCameraBack.textureListener.onSurfaceTextureAvailable(
mCamera.textureListener.onSurfaceTextureAvailable(
mCamera_BackView.getSurfaceTexture(), mCamera_BackView.getWidth(),
mCamera_BackView.getHeight());
} else {
mCamera_BackView.setSurfaceTextureListener(mCameraBack.textureListener);
mCamera_BackView.setSurfaceTextureListener(mCamera.textureListener);
}
}

public void Open_BackCamera() {
public void Open_Camera_ById() {
String[] Data = new String[5];

Data[0] = "BackCamera";
Data[1] = CameraIds[0];
Data[1] = CameraIds[mCameraInst.getOpenCameraId()];
Data[2] = "capture_list";
Data[3] = "video_list";
Data[4] = "pref_resolution_1";

mCameraBack = new CameraBase(this, mCamera_BackView, null, mRecordingTimeView,
mCamera = new CameraBase(this, mCamera_BackView, null, mRecordingTimeView,
Data, mRoundedThumbnailView);
}


public void Open_FrontCamera() {
String[] Data = new String[5];

Data[0] = "FrontCamera";
Data[1] = CameraIds[1];
Data[2] = "capture_list_1";
Data[3] = "video_list";
Data[4] = "pref_resolution_1";

mCameraFront = new CameraBase(this, mCamera_FrontView, null, mRecordingTimeView,
Data, mRoundedThumbnailView);
}
/**
* Checks if any of the needed Android runtime permissions are missing.
* If they are, then launch the permissions activity under one of the following conditions:
Expand Down Expand Up @@ -491,10 +439,8 @@ protected void onResume() {
Log.e(TAG, "onResume");
MultiCamera ic_cam = MultiCamera.getInstance();
ic_cam.setIsCameraOrSurveillance(0);
if (ic_cam.getWhichCamera() == 0) {
openBackCamera();
} else {
openFrontCamera();
}

Open_Camera();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public class MultiCamera {
private Uri mCurrentUri;
private ContentValues mCurrentFileInfo;

private String imagePath;
MultiCamera() {
mWhichCamera = 0;
mIsCameraOrSurveillance = 0;
mOpenCameraId = -1;
mOpenCameraId = 0;
}
public static MultiCamera getInstance() {
if (ic_instance == null) {
Expand Down Expand Up @@ -124,4 +125,12 @@ public void setOpenCameraId(int openCameraId) {
public static int getUsbCamDeviceClass() {
return usb_dev_id;
}

public String getImagePath() {
return imagePath;
}

public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ public void onClick(View v) {
ic_camera.setOpenCameraId(0);
closeCamera();
ic_camera.setIsCameraOrSurveillance(0);
unregisterReceiver(mUsbReceiver);
Intent intent = new Intent(MultiViewActivity.this, SingleCameraActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Expand Down Expand Up @@ -376,6 +377,7 @@ public void onClick(View v) {
ic_camera.setOpenCameraId(1);
closeCamera();
ic_camera.setIsCameraOrSurveillance(0);
unregisterReceiver(mUsbReceiver);
Intent intent = new Intent(MultiViewActivity.this, SingleCameraActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Expand Down Expand Up @@ -421,6 +423,7 @@ public void Open_BotmLeftCam() {
public void onClick(View v) {
ic_camera.setOpenCameraId(2);
closeCamera();
unregisterReceiver(mUsbReceiver);
Intent intent = new Intent(MultiViewActivity.this, SingleCameraActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Expand Down Expand Up @@ -468,6 +471,7 @@ public void Open_BotmRightCam() {
public void onClick(View v) {
ic_camera.setOpenCameraId(3);
closeCamera();
unregisterReceiver(mUsbReceiver);
Intent intent = new Intent(MultiViewActivity.this, SingleCameraActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Expand Down Expand Up @@ -1281,7 +1285,7 @@ public void enterFullScreen(View view) {
}

closeCamera();

unregisterReceiver(mUsbReceiver);
Intent intent = new Intent(MultiViewActivity.this, SingleCameraActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void onClick(View v) {
preView = mActivity.findViewById(R.id.preview);

Uri uri = ic_camera.getCurrentUri();
File file = new File(Utils.getRealPathFromURI(mActivity, uri));
File file = new File(ic_camera.getImagePath());
if (file.exists()) {
Log.v(TAG, " Thumbnail Preview File Deleted ");
file.delete();
Expand Down Expand Up @@ -150,8 +150,9 @@ private void showDetailsDialog(ContentValues info) {
}

private void VideoPreview(ImageButton playButton, ImageView preView) {
final Uri videoUri = Uri.fromFile(new File(ic_camera.getImagePath()));
final Optional<Bitmap> bitmap =
Utils.getVideoThumbnail(mActivity.getContentResolver(), ic_camera.getCurrentUri());
Utils.getVideoThumbnail(mActivity.getContentResolver(), videoUri);
if (bitmap.isPresent()) {
playButton.setVisibility(View.VISIBLE);

Expand All @@ -175,7 +176,8 @@ private void photoPreview(ImageButton playButton, ImageView preView) {

preView.setVisibility(View.VISIBLE);
playButton.setVisibility(View.GONE);
preView.setImageURI(PhotoUri);

preView.setImageURI(Uri.fromFile(new File(ic_camera.getImagePath())));
}

public void showImageThumbnail(File ImageFile) {
Expand Down Expand Up @@ -215,10 +217,11 @@ private int getOrientation(int rotation) {


public void showVideoThumbnail() {
final Uri videoUri = Uri.fromFile(new File(ic_camera.getImagePath()));
mRoundedThumbnailView.startRevealThumbnailAnimation("Video taken");

final Optional<Bitmap> bitmap =
Utils.getVideoThumbnail(mActivity.getContentResolver(), ic_camera.getCurrentUri());
Utils.getVideoThumbnail(mActivity.getContentResolver(), videoUri);

if (bitmap.isPresent()) {
mRoundedThumbnailView.setThumbnail(bitmap.get(), 0);
Expand Down
Loading