Fixed preview orientation issue upon device rotation
This commit is contained in:
parent
b16d3ba9f0
commit
76df95c9fb
2 changed files with 64 additions and 0 deletions
|
@ -48,6 +48,7 @@ import org.linphone.notifications.NotificationsManager;
|
||||||
import org.linphone.receivers.BluetoothManager;
|
import org.linphone.receivers.BluetoothManager;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
import org.linphone.utils.ActivityMonitor;
|
import org.linphone.utils.ActivityMonitor;
|
||||||
|
import org.linphone.utils.DeviceOrientationEventListener;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
import org.linphone.utils.LinphoneUtils;
|
||||||
import org.linphone.views.LinphoneGL2JNIViewOverlay;
|
import org.linphone.views.LinphoneGL2JNIViewOverlay;
|
||||||
import org.linphone.views.LinphoneOverlay;
|
import org.linphone.views.LinphoneOverlay;
|
||||||
|
@ -103,6 +104,7 @@ public final class LinphoneService extends Service {
|
||||||
private LinphoneManager mLinphoneManager;
|
private LinphoneManager mLinphoneManager;
|
||||||
private ContactsManager mContactsManager;
|
private ContactsManager mContactsManager;
|
||||||
private BluetoothManager mBluetoothManager;
|
private BluetoothManager mBluetoothManager;
|
||||||
|
private DeviceOrientationEventListener mOrientationHelper;
|
||||||
|
|
||||||
private Class<? extends Activity> mIncomingReceivedActivity = CallIncomingActivity.class;
|
private Class<? extends Activity> mIncomingReceivedActivity = CallIncomingActivity.class;
|
||||||
|
|
||||||
|
@ -138,6 +140,7 @@ public final class LinphoneService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||||
|
mOrientationHelper = new DeviceOrientationEventListener(this);
|
||||||
|
|
||||||
mListener =
|
mListener =
|
||||||
new CoreListenerStub() {
|
new CoreListenerStub() {
|
||||||
|
@ -213,6 +216,7 @@ public final class LinphoneService extends Service {
|
||||||
mBluetoothManager = new BluetoothManager();
|
mBluetoothManager = new BluetoothManager();
|
||||||
|
|
||||||
Compatibility.createChatShortcuts(this);
|
Compatibility.createChatShortcuts(this);
|
||||||
|
mOrientationHelper.enable();
|
||||||
|
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
@ -246,6 +250,7 @@ public final class LinphoneService extends Service {
|
||||||
mActivityCallbacks = null;
|
mActivityCallbacks = null;
|
||||||
}
|
}
|
||||||
destroyOverlay();
|
destroyOverlay();
|
||||||
|
mOrientationHelper.disable();
|
||||||
|
|
||||||
Core core = LinphoneManager.getCore();
|
Core core = LinphoneManager.getCore();
|
||||||
if (core != null) {
|
if (core != null) {
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
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);
|
||||||
|
|
||||||
|
int rotation = (360 - degrees) % 360;
|
||||||
|
Core core = LinphoneManager.getCore();
|
||||||
|
if (core != null) {
|
||||||
|
core.setDeviceRotation(rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue