mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-14 16:25:05 +01:00
Improve orientation detection for Power management
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
90a099b04e
commit
2fb58e8cab
@ -74,6 +74,7 @@ import com.nextcloud.talk.utils.animations.PulseAnimation;
|
|||||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||||
|
import com.nextcloud.talk.utils.power.PowerManagerUtils;
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||||
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
||||||
import com.nextcloud.talk.webrtc.*;
|
import com.nextcloud.talk.webrtc.*;
|
||||||
@ -209,6 +210,8 @@ public class CallController extends BaseController {
|
|||||||
private boolean hasExternalSignalingServer;
|
private boolean hasExternalSignalingServer;
|
||||||
private String conversationPassword;
|
private String conversationPassword;
|
||||||
|
|
||||||
|
private PowerManagerUtils powerManagerUtils;
|
||||||
|
|
||||||
public CallController(Bundle args) {
|
public CallController(Bundle args) {
|
||||||
super(args);
|
super(args);
|
||||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||||
@ -228,6 +231,7 @@ public class CallController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isFromNotification = TextUtils.isEmpty(roomToken);
|
isFromNotification = TextUtils.isEmpty(roomToken);
|
||||||
|
powerManagerUtils = new PowerManagerUtils();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -717,7 +721,6 @@ public class CallController extends BaseController {
|
|||||||
if (localMediaStream != null && localMediaStream.videoTracks.size() > 0) {
|
if (localMediaStream != null && localMediaStream.videoTracks.size() > 0) {
|
||||||
localMediaStream.videoTracks.get(0).setEnabled(enable);
|
localMediaStream.videoTracks.get(0).setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
pipVideoView.setVisibility(View.VISIBLE);
|
pipVideoView.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
@ -1592,6 +1595,8 @@ public class CallController extends BaseController {
|
|||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onMessageEvent(ConfigurationChangeEvent configurationChangeEvent) {
|
public void onMessageEvent(ConfigurationChangeEvent configurationChangeEvent) {
|
||||||
|
powerManagerUtils.setOrientation(Objects.requireNonNull(getResources()).getConfiguration().orientation);
|
||||||
|
|
||||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
remoteRenderersLayout.setOrientation(LinearLayout.HORIZONTAL);
|
remoteRenderersLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
@ -25,6 +25,7 @@ package com.nextcloud.talk.utils.power;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
@ -50,6 +51,8 @@ public class PowerManagerUtils {
|
|||||||
private final boolean wifiLockEnforced;
|
private final boolean wifiLockEnforced;
|
||||||
private boolean proximityDisabled = false;
|
private boolean proximityDisabled = false;
|
||||||
|
|
||||||
|
private int orientation;
|
||||||
|
|
||||||
public enum PhoneState {
|
public enum PhoneState {
|
||||||
IDLE,
|
IDLE,
|
||||||
PROCESSING, //used when the phone is active but before the user should be alerted.
|
PROCESSING, //used when the phone is active but before the user should be alerted.
|
||||||
@ -65,6 +68,11 @@ public class PowerManagerUtils {
|
|||||||
PROXIMITY
|
PROXIMITY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOrientation(int newOrientation) {
|
||||||
|
orientation = newOrientation;
|
||||||
|
updateInCallWakeLockState();
|
||||||
|
}
|
||||||
|
|
||||||
public PowerManagerUtils() {
|
public PowerManagerUtils() {
|
||||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||||
|
|
||||||
@ -84,6 +92,7 @@ public class PowerManagerUtils {
|
|||||||
wifiLock.setReferenceCounted(false);
|
wifiLock.setReferenceCounted(false);
|
||||||
|
|
||||||
wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
|
wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
|
||||||
|
orientation = context.getResources().getConfiguration().orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePhoneState(PhoneState state) {
|
public void updatePhoneState(PhoneState state) {
|
||||||
@ -109,7 +118,7 @@ public class PowerManagerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateInCallWakeLockState() {
|
private void updateInCallWakeLockState() {
|
||||||
if (wifiLockEnforced && !proximityDisabled) {
|
if (orientation != Configuration.ORIENTATION_LANDSCAPE && wifiLockEnforced && !proximityDisabled) {
|
||||||
setWakeLockState(WakeLockState.PROXIMITY);
|
setWakeLockState(WakeLockState.PROXIMITY);
|
||||||
} else {
|
} else {
|
||||||
setWakeLockState(WakeLockState.FULL);
|
setWakeLockState(WakeLockState.FULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user