|
|
@ -7,6 +7,8 @@ import android.os.Bundle; |
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior; |
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.util.Log; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewTreeObserver; |
|
|
|
import android.view.ViewTreeObserver; |
|
|
@ -17,6 +19,8 @@ import com.otaliastudios.cameraview.CameraListener; |
|
|
|
import com.otaliastudios.cameraview.CameraLogger; |
|
|
|
import com.otaliastudios.cameraview.CameraLogger; |
|
|
|
import com.otaliastudios.cameraview.CameraOptions; |
|
|
|
import com.otaliastudios.cameraview.CameraOptions; |
|
|
|
import com.otaliastudios.cameraview.CameraView; |
|
|
|
import com.otaliastudios.cameraview.CameraView; |
|
|
|
|
|
|
|
import com.otaliastudios.cameraview.Frame; |
|
|
|
|
|
|
|
import com.otaliastudios.cameraview.FrameProcessor; |
|
|
|
import com.otaliastudios.cameraview.PictureResult; |
|
|
|
import com.otaliastudios.cameraview.PictureResult; |
|
|
|
import com.otaliastudios.cameraview.Mode; |
|
|
|
import com.otaliastudios.cameraview.Mode; |
|
|
|
import com.otaliastudios.cameraview.VideoResult; |
|
|
|
import com.otaliastudios.cameraview.VideoResult; |
|
|
@ -40,14 +44,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis |
|
|
|
|
|
|
|
|
|
|
|
camera = findViewById(R.id.camera); |
|
|
|
camera = findViewById(R.id.camera); |
|
|
|
camera.setLifecycleOwner(this); |
|
|
|
camera.setLifecycleOwner(this); |
|
|
|
camera.addCameraListener(new CameraListener() { |
|
|
|
camera.addCameraListener(new Listener()); |
|
|
|
public void onCameraOpened(@NonNull CameraOptions options) { onOpened(options); } |
|
|
|
|
|
|
|
public void onPictureTaken(@NonNull PictureResult result) { onPicture(result); } |
|
|
|
|
|
|
|
public void onVideoTaken(@NonNull VideoResult result) { onVideo(result); } |
|
|
|
|
|
|
|
public void onCameraError(@NonNull CameraException exception) { |
|
|
|
|
|
|
|
onError(exception); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.edit).setOnClickListener(this); |
|
|
|
findViewById(R.id.edit).setOnClickListener(this); |
|
|
|
findViewById(R.id.capturePicture).setOnClickListener(this); |
|
|
|
findViewById(R.id.capturePicture).setOnClickListener(this); |
|
|
@ -80,38 +77,48 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis |
|
|
|
Toast.makeText(this, content, length).show(); |
|
|
|
Toast.makeText(this, content, length).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onOpened(CameraOptions options) { |
|
|
|
private class Listener extends CameraListener { |
|
|
|
ViewGroup group = (ViewGroup) controlPanel.getChildAt(0); |
|
|
|
|
|
|
|
for (int i = 0; i < group.getChildCount(); i++) { |
|
|
|
|
|
|
|
ControlView view = (ControlView) group.getChildAt(i); |
|
|
|
|
|
|
|
view.onCameraOpened(camera, options); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onError(@NonNull CameraException exception) { |
|
|
|
@Override |
|
|
|
message("Got CameraException #" + exception.getReason(), true); |
|
|
|
public void onCameraOpened(@NonNull CameraOptions options) { |
|
|
|
} |
|
|
|
ViewGroup group = (ViewGroup) controlPanel.getChildAt(0); |
|
|
|
|
|
|
|
for (int i = 0; i < group.getChildCount(); i++) { |
|
|
|
|
|
|
|
ControlView view = (ControlView) group.getChildAt(i); |
|
|
|
|
|
|
|
view.onCameraOpened(camera, options); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onPicture(PictureResult result) { |
|
|
|
@Override |
|
|
|
if (camera.isTakingVideo()) { |
|
|
|
public void onCameraError(@NonNull CameraException exception) { |
|
|
|
message("Captured while taking video. Size=" + result.getSize(), false); |
|
|
|
super.onCameraError(exception); |
|
|
|
return; |
|
|
|
message("Got CameraException #" + exception.getReason(), true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// This can happen if picture was taken with a gesture.
|
|
|
|
@Override |
|
|
|
long callbackTime = System.currentTimeMillis(); |
|
|
|
public void onPictureTaken(@NonNull PictureResult result) { |
|
|
|
if (mCaptureTime == 0) mCaptureTime = callbackTime - 300; |
|
|
|
super.onPictureTaken(result); |
|
|
|
PicturePreviewActivity.setPictureResult(result); |
|
|
|
if (camera.isTakingVideo()) { |
|
|
|
Intent intent = new Intent(CameraActivity.this, PicturePreviewActivity.class); |
|
|
|
message("Captured while taking video. Size=" + result.getSize(), false); |
|
|
|
intent.putExtra("delay", callbackTime - mCaptureTime); |
|
|
|
return; |
|
|
|
startActivity(intent); |
|
|
|
} |
|
|
|
mCaptureTime = 0; |
|
|
|
|
|
|
|
} |
|
|
|
// This can happen if picture was taken with a gesture.
|
|
|
|
|
|
|
|
long callbackTime = System.currentTimeMillis(); |
|
|
|
|
|
|
|
if (mCaptureTime == 0) mCaptureTime = callbackTime - 300; |
|
|
|
|
|
|
|
PicturePreviewActivity.setPictureResult(result); |
|
|
|
|
|
|
|
Intent intent = new Intent(CameraActivity.this, PicturePreviewActivity.class); |
|
|
|
|
|
|
|
intent.putExtra("delay", callbackTime - mCaptureTime); |
|
|
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
|
|
mCaptureTime = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onVideo(VideoResult video) { |
|
|
|
@Override |
|
|
|
VideoPreviewActivity.setVideoResult(video); |
|
|
|
public void onVideoTaken(@NonNull VideoResult result) { |
|
|
|
Intent intent = new Intent(CameraActivity.this, VideoPreviewActivity.class); |
|
|
|
super.onVideoTaken(result); |
|
|
|
startActivity(intent); |
|
|
|
VideoPreviewActivity.setVideoResult(result); |
|
|
|
|
|
|
|
Intent intent = new Intent(CameraActivity.this, VideoPreviewActivity.class); |
|
|
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|