Skip to content

Commit

Permalink
Changes to camera activity (see #121)
Browse files Browse the repository at this point in the history
  • Loading branch information
tasota committed Aug 10, 2022
1 parent ca0218e commit 76325c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 72 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" />
<activity
android:name=".activities.teacher_section.students.CameraActivity"
android:screenOrientation="userLandscape"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" />
<activity
android:name=".activities.teacher_section.CopingSkillIndexActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,82 +217,13 @@ protected void onResume() {

final FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview);

updateCameraLayoutSizes();
//updateCameraLayoutSizes();

cameraPreview.addView(this.mPreview);
}
}


private void updateCameraLayoutSizes() {
final FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview);
final RelativeLayout layoutCameraPreview = (RelativeLayout) findViewById(R.id.layout_camera_preview);
final LinearLayout layoutCameraButtons = (LinearLayout) findViewById(R.id.layout_camera_buttons);

final ViewTreeObserver cameraPreviewViewTreeObserver = cameraPreview.getViewTreeObserver();
cameraPreviewViewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
try {
RelativeLayout.LayoutParams lp;

if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT) {
lp = new RelativeLayout.LayoutParams(cameraPreview.getWidth(), cameraPreview.getWidth() * 4 / 3);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
cameraPreview.setLayoutParams(lp);
} else {
//for some reason, the layout params have to instantiated every time or they do not work
lp = new RelativeLayout.LayoutParams(cameraPreview.getHeight() * 4 / 3, cameraPreview.getHeight());
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
cameraPreview.setLayoutParams(lp);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
});

if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
final ViewTreeObserver layoutCameraPreviewViewTreeObserver = layoutCameraPreview.getViewTreeObserver();
layoutCameraPreviewViewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
try {
RelativeLayout.LayoutParams lp;

//for some reason, the layout params have to instantiated every time or they do not work
lp = new RelativeLayout.LayoutParams(layoutCameraPreview.getHeight() * 4 / 3, layoutCameraPreview.getHeight());
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
layoutCameraPreview.setLayoutParams(lp);
}
catch (Exception e) {
e.printStackTrace();
}
}
});

final ViewTreeObserver layoutCameraButtonsViewTreeObserver = layoutCameraButtons.getViewTreeObserver();
layoutCameraButtonsViewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
try {
RelativeLayout.LayoutParams lp;

//for some reason, the layout params have to instantiated every time or they do not work
lp = new RelativeLayout.LayoutParams(layoutCameraButtons.getHeight() * 4 / 3, layoutCameraButtons.getHeight());
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
layoutCameraButtons.setLayoutParams(lp);
}
catch (Exception e) {
e.printStackTrace();
}
}
});
}
}


@Override
public void onPause() {
super.onPause();
Expand Down Expand Up @@ -345,6 +276,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
photoNo.setImageResource(R.mipmap.photo_no);
photoYes.setImageResource(R.mipmap.photo_yes);
findViewById(R.id.take_picture).setVisibility(View.INVISIBLE);
findViewById(R.id.load_image).setVisibility(View.INVISIBLE);
findViewById(R.id.flip_camera).setVisibility(View.INVISIBLE);

break;
}
Expand All @@ -364,6 +297,8 @@ public void onPictureTaken(byte[] bytes, Camera camera) {
photoNo.setImageResource(R.mipmap.photo_no);
photoYes.setImageResource(R.mipmap.photo_yes);
findViewById(R.id.take_picture).setVisibility(View.INVISIBLE);
findViewById(R.id.load_image).setVisibility(View.INVISIBLE);
findViewById(R.id.flip_camera).setVisibility(View.INVISIBLE);
possiblePhoto = bytes;

final FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview);
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/layout/activity_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
android:id="@+id/layout_camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
android:layout_centerInParent="true">


<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:screenOrientation="portrait" />

<ImageView
Expand Down

0 comments on commit 76325c3

Please sign in to comment.