diff --git a/app/src/main/java/org/linphone/LinphoneService.java b/app/src/main/java/org/linphone/LinphoneService.java
index c05fc4eed..76a386e7c 100644
--- a/app/src/main/java/org/linphone/LinphoneService.java
+++ b/app/src/main/java/org/linphone/LinphoneService.java
@@ -47,7 +47,6 @@ import org.linphone.mediastream.Version;
import org.linphone.notifications.NotificationsManager;
import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.ActivityMonitor;
-import org.linphone.utils.DeviceOrientationEventListener;
import org.linphone.utils.LinphoneUtils;
import org.linphone.views.LinphoneGL2JNIViewOverlay;
import org.linphone.views.LinphoneOverlay;
@@ -102,7 +101,6 @@ public final class LinphoneService extends Service {
private NotificationsManager mNotificationManager;
private LinphoneManager mLinphoneManager;
private ContactsManager mContactsManager;
- private DeviceOrientationEventListener mOrientationHelper;
private Class extends Activity> mIncomingReceivedActivity = CallIncomingActivity.class;
@@ -138,7 +136,6 @@ public final class LinphoneService extends Service {
}
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
- mOrientationHelper = new DeviceOrientationEventListener(this);
mListener =
new CoreListenerStub() {
@@ -219,7 +216,6 @@ public final class LinphoneService extends Service {
ContactsManager.getInstance().initializeContactManager();
Compatibility.createChatShortcuts(this);
- mOrientationHelper.enable();
return START_STICKY;
}
@@ -253,7 +249,6 @@ public final class LinphoneService extends Service {
mActivityCallbacks = null;
}
destroyOverlay();
- mOrientationHelper.disable();
Core core = LinphoneManager.getCore();
if (core != null) {
diff --git a/app/src/main/java/org/linphone/activities/LinphoneGenericActivity.java b/app/src/main/java/org/linphone/activities/LinphoneGenericActivity.java
index 5bfacebf2..81dfaf9b0 100644
--- a/app/src/main/java/org/linphone/activities/LinphoneGenericActivity.java
+++ b/app/src/main/java/org/linphone/activities/LinphoneGenericActivity.java
@@ -20,7 +20,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.os.Bundle;
+import android.view.Surface;
+import org.linphone.LinphoneManager;
import org.linphone.LinphoneService;
+import org.linphone.core.Core;
+import org.linphone.core.tools.Log;
public abstract class LinphoneGenericActivity extends ThemeableActivity {
protected boolean mAbortCreation;
@@ -37,4 +41,41 @@ public abstract class LinphoneGenericActivity extends ThemeableActivity {
finish();
}
}
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ if (LinphoneService.isReady()) {
+ int degrees = 270;
+ int orientation = getWindowManager().getDefaultDisplay().getRotation();
+ switch (orientation) {
+ case Surface.ROTATION_0:
+ degrees = 0;
+ break;
+ case Surface.ROTATION_90:
+ degrees = 270;
+ break;
+ case Surface.ROTATION_180:
+ degrees = 180;
+ break;
+ case Surface.ROTATION_270:
+ degrees = 90;
+ break;
+ }
+
+ Log.i(
+ "[Generic Activity] Device orientation is "
+ + degrees
+ + " (raw value is "
+ + orientation
+ + ")");
+
+ int rotation = (360 - degrees) % 360;
+ Core core = LinphoneManager.getCore();
+ if (core != null) {
+ core.setDeviceRotation(rotation);
+ }
+ }
+ }
}
diff --git a/app/src/main/java/org/linphone/call/CallActivity.java b/app/src/main/java/org/linphone/call/CallActivity.java
index 016d75514..7344c3218 100644
--- a/app/src/main/java/org/linphone/call/CallActivity.java
+++ b/app/src/main/java/org/linphone/call/CallActivity.java
@@ -30,7 +30,6 @@ import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.SystemClock;
-import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -66,7 +65,6 @@ import org.linphone.core.ChatRoom;
import org.linphone.core.Core;
import org.linphone.core.CoreListener;
import org.linphone.core.CoreListenerStub;
-import org.linphone.core.VideoDefinition;
import org.linphone.core.tools.Log;
import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.AndroidAudioManager;
@@ -766,48 +764,9 @@ public class CallActivity extends LinphoneGenericActivity
if (videoEnabled) {
mAudioManager.routeAudioToSpeaker();
mSpeaker.setSelected(true);
- resizePreview(call);
}
}
- private void resizePreview(Call call) {
- if (call == null) return;
-
- DisplayMetrics metrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(metrics);
- int screenHeight = metrics.heightPixels;
- int maxHeight =
- screenHeight / 4; // Let's take at most 1/4 of the screen for the camera preview
-
- VideoDefinition videoSize =
- call.getCurrentParams()
- .getSentVideoDefinition(); // It already takes care of rotation
- if (videoSize.getWidth() == 0 || videoSize.getHeight() == 0) {
- Log.w(
- "[Call Activity] [Video] Couldn't get sent video definition, using default video definition");
- videoSize = call.getCore().getPreferredVideoDefinition();
- }
- int width = videoSize.getWidth();
- int height = videoSize.getHeight();
-
- Log.d("[Call Activity] [Video] Video height is " + height + ", width is " + width);
- width = width * maxHeight / height;
- height = maxHeight;
-
- if (mLocalPreview == null) {
- Log.e("[Call Activity] [Video] mCaptureView is null !");
- return;
- }
-
- RelativeLayout.LayoutParams newLp = new RelativeLayout.LayoutParams(width, height);
- newLp.addRule(
- RelativeLayout.ALIGN_PARENT_BOTTOM,
- 1); // Clears the rule, as there is no removeRule until API 17.
- newLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 1);
- mLocalPreview.setLayoutParams(newLp);
- Log.d("[Call Activity] [Video] Video preview size set to " + width + "x" + height);
- }
-
private void moveLocalPreview(MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
@@ -817,15 +776,15 @@ public class CallActivity extends LinphoneGenericActivity
case MotionEvent.ACTION_MOVE:
int x = (int) motionEvent.getX();
int y = (int) motionEvent.getY();
+
RelativeLayout.LayoutParams lp =
(RelativeLayout.LayoutParams) mLocalPreview.getLayoutParams();
- lp.addRule(
- RelativeLayout.ALIGN_PARENT_BOTTOM,
- 0); // Clears the rule, as there is no removeRule until API
- // 17.
- lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
+ lp.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
+ lp.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+
int left = lp.leftMargin + (x - mPreviewX);
int top = lp.topMargin + (y - mPreviewY);
+
lp.leftMargin = left;
lp.topMargin = top;
mLocalPreview.setLayoutParams(lp);
diff --git a/app/src/main/java/org/linphone/utils/DeviceOrientationEventListener.java b/app/src/main/java/org/linphone/utils/DeviceOrientationEventListener.java
deleted file mode 100644
index ff065ebdf..000000000
--- a/app/src/main/java/org/linphone/utils/DeviceOrientationEventListener.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package org.linphone.utils;
-
-/*
-DeviceOrientationEventListener.java
-Copyright (C) 2019 Belledonne Communications, Grenoble, France
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-import android.content.Context;
-import android.view.OrientationEventListener;
-import org.linphone.LinphoneManager;
-import org.linphone.core.Core;
-import org.linphone.core.tools.Log;
-
-public class DeviceOrientationEventListener extends OrientationEventListener {
- private int mAlwaysChangingPhoneAngle;
-
- public DeviceOrientationEventListener(Context context) {
- super(context);
- mAlwaysChangingPhoneAngle = -1;
- }
-
- @Override
- public void onOrientationChanged(final int orientation) {
- if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
- return;
- }
-
- int degrees = 270;
- if (orientation < 45 || orientation > 315) degrees = 0;
- else if (orientation < 135) degrees = 90;
- else if (orientation < 225) degrees = 180;
-
- if (mAlwaysChangingPhoneAngle == degrees) {
- return;
- }
-
- mAlwaysChangingPhoneAngle = degrees;
- Log.i(
- "[Orientation Helper] Device orientation changed to "
- + degrees
- + " (raw value is "
- + orientation
- + ")");
-
- int rotation = (360 - degrees) % 360;
- Core core = LinphoneManager.getCore();
- if (core != null) {
- core.setDeviceRotation(rotation);
- }
- }
-}
diff --git a/app/src/main/res/layout-land/call.xml b/app/src/main/res/layout-land/call.xml
index 2fbc05b52..6687ed344 100644
--- a/app/src/main/res/layout-land/call.xml
+++ b/app/src/main/res/layout-land/call.xml
@@ -21,8 +21,8 @@
diff --git a/app/src/main/res/layout/call.xml b/app/src/main/res/layout/call.xml
index 32ea83df2..d5eb3cb3b 100644
--- a/app/src/main/res/layout/call.xml
+++ b/app/src/main/res/layout/call.xml
@@ -21,7 +21,7 @@
diff --git a/app/src/main/res/raw/linphonerc_factory b/app/src/main/res/raw/linphonerc_factory
index c9cd5ae23..85a96a979 100644
--- a/app/src/main/res/raw/linphonerc_factory
+++ b/app/src/main/res/raw/linphonerc_factory
@@ -23,6 +23,7 @@ ec_calibrator_cool_tones=1
[video]
displaytype=MSAndroidTextureDisplay
+auto_resize_preview_to_keep_ratio=1
[misc]
enable_basic_to_client_group_chat_room_migration=0