Skip to content
Open
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 @@ -542,6 +542,19 @@ private void setupPreviewView() {
}
}

/**
* Compute layout parameters for the camera preview container based on the current session configuration,
* device screen size, WebView/parent geometry, and optional aspect-ratio centering.
*
* The returned FrameLayout.LayoutParams contains width, height, leftMargin (x) and topMargin (y)
* for placing the preview. When an aspect ratio is specified and sessionConfig is in centered mode,
* the preview size is scaled to the largest area that fits the aspect ratio within the screen and
* any axis with a coordinate equal to -1 is auto-centered for that axis; axes explicitly provided
* in sessionConfig are preserved. Coordinates supplied by sessionConfig are assumed to already
* include WebView insets.
*
* @return a FrameLayout.LayoutParams configured with the computed preview width, height, leftMargin and topMargin
*/
private FrameLayout.LayoutParams calculatePreviewLayoutParams() {
// sessionConfig already contains pixel-converted coordinates with webview offsets applied
int x = sessionConfig.getX();
Expand Down Expand Up @@ -663,9 +676,13 @@ private FrameLayout.LayoutParams calculatePreviewLayoutParams() {
Log.d(TAG, "Width-limited sizing: " + width + "x" + height);
}

// Center the preview
x = (screenWidthPx - width) / 2;
y = (screenHeightPx - height) / 2;
// Center the preview only overwrite what was not explicitly set
if (sessionConfig.getX() == -1){
x = (screenWidthPx - width) / 2;
}
if (sessionConfig.getY() == -1){
y = (screenHeightPx - height) / 2;
}

Log.d(TAG, "Auto-centered position: x=" + x + ", y=" + y);
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -3519,4 +3536,4 @@ private void handleRecordingFinalized(VideoRecordEvent.Finalize finalizeEvent) {
currentVideoFile = null;
currentVideoCallback = null;
}
}
}
Loading