Skip to content

Commit

Permalink
opentok#86 - Added offset when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochum van der Ploeg committed Apr 26, 2018
1 parent f3a7532 commit 9bf0af3
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/android/OpenTokAndroidPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,30 @@ public void setPosition(int xPos, int yPos, int width, int height) {
this.width = width;
this.height = height;

DisplayMetrics metrics = new DisplayMetrics();
cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

int videoWidth = metrics.widthPixels;
int videoHeight = metrics.heightPixels;
int videoWidth = getWidth();
int videoHeight = getHeight();
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
videoWidth = metrics.heightPixels;
videoHeight = metrics.widthPixels;
videoWidth = getHeight();
videoHeight = getWidth();
}

float videoRatio = (videoHeight / videoWidth);
float containerRatio = (height / width);

float scale = Math.max((float) width / videoWidth, (float) height / videoHeight);

Matrix matrix = new Matrix();
this.view.getTransform(matrix);
matrix.setScale(scale, scale);

float scaledWidth = width * scale;
float scaledHeight = height * scale;
float scaledWidth = videoWidth * scale;
float scaledHeight = videoHeight * scale;
if((int) scaledWidth != width) {
xPos -= (int) ((scaledWidth - width) / 2);
}
if((int) scaledHeight != height) {
yPos -= (int) ((scaledHeight - height) / 2);
}

matrix.postTranslate(xPos, yPos);
this.view.setTransform(matrix);
}
Expand Down

0 comments on commit 9bf0af3

Please sign in to comment.