Skip to content
Snippets Groups Projects
Commit cea7119d authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by gerrit2
Browse files

call: lock screen rotation

Block screen rotation when video starts to avoid destroying view and
as result displaying black square.

Change-Id: I4391235808cb29189316ec67894af23fde0c3121
parent d67977bd
Branches
Tags
No related merge requests found
...@@ -27,6 +27,7 @@ import android.content.BroadcastReceiver; ...@@ -27,6 +27,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
...@@ -162,6 +163,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta ...@@ -162,6 +163,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta
private MenuItem addContactBtn = null; private MenuItem addContactBtn = null;
private MenuItem flipCameraBtn = null; private MenuItem flipCameraBtn = null;
private MenuItem dialPadBtn = null; private MenuItem dialPadBtn = null;
private MenuItem changeScreenOrientationBtn = null;
@BindView(R.id.camera_preview_surface) @BindView(R.id.camera_preview_surface)
SurfaceView videoPreview = null; SurfaceView videoPreview = null;
...@@ -409,6 +411,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta ...@@ -409,6 +411,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta
addContactBtn = m.findItem(R.id.menuitem_addcontact); addContactBtn = m.findItem(R.id.menuitem_addcontact);
flipCameraBtn = m.findItem(R.id.menuitem_camera_flip); flipCameraBtn = m.findItem(R.id.menuitem_camera_flip);
dialPadBtn = m.findItem(R.id.menuitem_dialpad); dialPadBtn = m.findItem(R.id.menuitem_dialpad);
changeScreenOrientationBtn = m.findItem(R.id.menuitem_change_screen_orientation);
} }
@Override @Override
...@@ -430,6 +433,9 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta ...@@ -430,6 +433,9 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta
if (dialPadBtn != null) { if (dialPadBtn != null) {
dialPadBtn.setVisible(ongoingCall && getConference() != null && !getConference().isIncoming()); dialPadBtn.setVisible(ongoingCall && getConference() != null && !getConference().isIncoming());
} }
if (changeScreenOrientationBtn != null) {
changeScreenOrientationBtn.setVisible(mVideoSurface.getVisibility() == View.VISIBLE);
}
} }
@Override @Override
...@@ -476,6 +482,9 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta ...@@ -476,6 +482,9 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta
mNumeralDialEditText, mNumeralDialEditText,
InputMethodManager.SHOW_IMPLICIT); InputMethodManager.SHOW_IMPLICIT);
break; break;
case R.id.menuitem_change_screen_orientation:
changeScreenOrientation();
break;
} }
return true; return true;
} }
...@@ -807,6 +816,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta ...@@ -807,6 +816,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta
contactBubbleLayout.setVisibility(View.GONE); contactBubbleLayout.setVisibility(View.GONE);
Conference c = getConference(); Conference c = getConference();
application.videoSurfaces.put(c.getId(), new WeakReference<>(holder)); application.videoSurfaces.put(c.getId(), new WeakReference<>(holder));
blockSensorScreenRotation();
try { try {
mCallbacks.getRemoteService().videoSurfaceAdded(c.getId()); mCallbacks.getRemoteService().videoSurfaceAdded(c.getId());
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -1113,6 +1123,29 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta ...@@ -1113,6 +1123,29 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta
} }
} }
public void changeScreenOrientation() {
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
private void blockSensorScreenRotation() {
changeScreenOrientationBtn.setVisible(true);
int currentOrientation = getResources().getConfiguration().orientation;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
return;
}
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
/** /**
* Helper accessor that check nullity or emptiness of components to access first call participant * Helper accessor that check nullity or emptiness of components to access first call participant
* *
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M16.48,2.52c3.27,1.55 5.61,4.72 5.97,8.48h1.5C23.44,4.84 18.29,0 12,0l-0.66,0.03 3.81,3.81 1.33,-1.32zM10.23,1.75c-0.59,-0.59 -1.54,-0.59 -2.12,0L1.75,8.11c-0.59,0.59 -0.59,1.54 0,2.12l12.02,12.02c0.59,0.59 1.54,0.59 2.12,0l6.36,-6.36c0.59,-0.59 0.59,-1.54 0,-2.12L10.23,1.75zM14.83,21.19L2.81,9.17l6.36,-6.36 12.02,12.02 -6.36,6.36zM7.52,21.48C4.25,19.94 1.91,16.76 1.55,13L0.05,13C0.56,19.16 5.71,24 12,24l0.66,-0.03 -3.81,-3.81 -1.33,1.32z"
android:fillColor="#FFFFFF"/>
</vector>
...@@ -33,4 +33,10 @@ ...@@ -33,4 +33,10 @@
app:showAsAction="ifRoom" app:showAsAction="ifRoom"
android:icon="@drawable/ic_dialpad_white" android:icon="@drawable/ic_dialpad_white"
android:title="@string/dial_numeric_pad"/> android:title="@string/dial_numeric_pad"/>
<item
android:id="@+id/menuitem_change_screen_orientation"
app:showAsAction="always"
android:icon="@drawable/ic_screen_rotation_white"
android:title="@string/ab_action_change_screen_orientation" />
</menu> </menu>
\ No newline at end of file
...@@ -120,6 +120,7 @@ along with this program; if not, write to the Free Software ...@@ -120,6 +120,7 @@ along with this program; if not, write to the Free Software
<string name="ab_action_contact_add_question">Add to contacts ?</string> <string name="ab_action_contact_add_question">Add to contacts ?</string>
<string name="ab_action_audio_call">Audio call</string> <string name="ab_action_audio_call">Audio call</string>
<string name="ab_action_video_call">Video call</string> <string name="ab_action_video_call">Video call</string>
<string name="ab_action_change_screen_orientation">Change screen orientation</string>
<string name="share_via">Share via</string> <string name="share_via">Share via</string>
<string name="write_a_message">Write a message</string> <string name="write_a_message">Write a message</string>
<string name="scan_qr">Scan QR Code</string> <string name="scan_qr">Scan QR Code</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment