Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
rename CameraxView to CameraView & add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yueyuzhao committed Aug 2, 2021
1 parent 8d17a76 commit d8760f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions android/ScratchJr/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ android {
}
}

// The camera-view dependency contains Java 8 bytecode,
// we need to support java 8 to dex.
// See https://developer.android.com/studio/write/java8-support.html for details.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.CameraInfoUnavailableException;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ExperimentalUseCaseGroup;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.Preview;
import androidx.camera.lifecycle.ProcessCameraProvider;
Expand All @@ -36,7 +37,7 @@
import com.google.common.util.concurrent.ListenableFuture;

@SuppressLint("ViewConstructor")
public class CameraxView extends RelativeLayout {
public class CameraView extends RelativeLayout {
private static final String LOG_TAG = "ScratchJr.CameraxView";

private final RectF _rect;
Expand All @@ -52,7 +53,7 @@ public class CameraxView extends RelativeLayout {
private final DisplayManager _displayManager;
private int _displayId;

public CameraxView(AppCompatActivity context, RectF rect, float scale, boolean facingFront) {
public CameraView(AppCompatActivity context, RectF rect, float scale, boolean facingFront) {
super(context);
_activity = context;
_currentFacingFront = facingFront;
Expand Down Expand Up @@ -94,7 +95,9 @@ public void onDisplayAdded(int displayId) {
public void onDisplayRemoved(int displayId) {
}

@SuppressLint("UnsafeOptInUsageError")
// The androidx.camera.core.Preview.setTargetRotation declaration is opt-in
// and its usage should be marked with @androidx.camera.core.ExperimentalUseCaseGroup
@ExperimentalUseCaseGroup
@Override
public void onDisplayChanged(int displayId) {
if (displayId == _displayId) {
Expand Down Expand Up @@ -238,7 +241,7 @@ private Bitmap cropResizeAndRotate(Bitmap image, int exifRotation) {
// flip bitmap horizontally since front-facing camera is mirrored
m.preScale(-1.0f, 1.0f);
}
int rotation = CameraxView.findDisplayRotation(getContext(), _currentFacingFront);
int rotation = CameraView.findDisplayRotation(getContext(), _currentFacingFront);
if (rotation == 180) {
m.preScale(-1.0f, -1.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class JavaScriptDirectInterface {
private final ScratchJrActivity _activity;

/** Current camera view, if active */
private CameraxView _cameraView;
private CameraView _cameraView;

/** Current camera mask, if active */
private ImageView _cameraMask;
Expand Down Expand Up @@ -505,7 +505,7 @@ public void run() {
scaleRectFromCenter(maskRect, scale);
RelativeLayout container = _activity.getContainer();

_cameraView = new CameraxView(_activity, rect, scale * devicePixelRatio, true); // always start with front-facing camera
_cameraView = new CameraView(_activity, rect, scale * devicePixelRatio, true); // always start with front-facing camera
container.addView(_cameraView, new RelativeLayout.LayoutParams((int) (rect.width()), (int) (rect.height())));
_cameraView.setX(rect.left);
_cameraView.setY(rect.top);
Expand Down

0 comments on commit d8760f6

Please sign in to comment.