Skip to content

Commit

Permalink
Apply aspect ratio to vr views
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexodessa authored Dec 14, 2024
1 parent 7e66365 commit f162be8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public void onStopTrackingTouch(SeekBar distanceSeekBar) { }
vrItem.setOnMenuItemClickListener(item -> {
isVRMode = !getVRSetting();
setVRSetting(isVRMode);
vrItem.setTitle(isVRMode ? "On" : "Off");
vrItem.setTitle(isVRMode ? "Off" : "On");
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(this));
resetApp();
Expand Down Expand Up @@ -836,11 +836,22 @@ public void onVideoRatioChanged(final int videoW, final int videoH) {
lastVideoH = videoH;

Log.d(TAG, "Set resolution: " + videoW + "x" + videoH);
View mSurface = findViewById(R.id.mainVideo);
ConstraintLayout.LayoutParams params =
(ConstraintLayout.LayoutParams) mSurface.getLayoutParams();
params.dimensionRatio = videoW + ":" + videoH;
runOnUiThread(() -> mSurface.setLayoutParams(params));

updateViewRatio(R.id.mainVideo, videoW, videoH);
updateViewRatio(R.id.surfaceViewLeft, videoW, videoH);
updateViewRatio(R.id.surfaceViewRight, videoW, videoH);
}

private void updateViewRatio(int viewId, int videoW, int videoH) {
View view = findViewById(viewId);
if (view != null) {
ConstraintLayout.LayoutParams params =
(ConstraintLayout.LayoutParams) view.getLayoutParams();
params.dimensionRatio = videoW + ":" + videoH;
runOnUiThread(() -> view.setLayoutParams(params));
} else {
Log.w(TAG, "View with ID " + viewId + " not found.");
}
}

@Override
Expand Down

0 comments on commit f162be8

Please sign in to comment.