diff --git a/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java b/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java index e76a2d8ab1d37212afb68daad2f6a35d88beda32..0257397a249fa10e2bc689bcf1067f7fe67a048a 100644 --- a/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java +++ b/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java @@ -27,6 +27,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.PixelFormat; @@ -162,6 +163,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta private MenuItem addContactBtn = null; private MenuItem flipCameraBtn = null; private MenuItem dialPadBtn = null; + private MenuItem changeScreenOrientationBtn = null; @BindView(R.id.camera_preview_surface) SurfaceView videoPreview = null; @@ -409,6 +411,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta addContactBtn = m.findItem(R.id.menuitem_addcontact); flipCameraBtn = m.findItem(R.id.menuitem_camera_flip); dialPadBtn = m.findItem(R.id.menuitem_dialpad); + changeScreenOrientationBtn = m.findItem(R.id.menuitem_change_screen_orientation); } @Override @@ -430,6 +433,9 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta if (dialPadBtn != null) { dialPadBtn.setVisible(ongoingCall && getConference() != null && !getConference().isIncoming()); } + if (changeScreenOrientationBtn != null) { + changeScreenOrientationBtn.setVisible(mVideoSurface.getVisibility() == View.VISIBLE); + } } @Override @@ -476,6 +482,9 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta mNumeralDialEditText, InputMethodManager.SHOW_IMPLICIT); break; + case R.id.menuitem_change_screen_orientation: + changeScreenOrientation(); + break; } return true; } @@ -807,6 +816,7 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta contactBubbleLayout.setVisibility(View.GONE); Conference c = getConference(); application.videoSurfaces.put(c.getId(), new WeakReference<>(holder)); + blockSensorScreenRotation(); try { mCallbacks.getRemoteService().videoSurfaceAdded(c.getId()); } catch (RemoteException e) { @@ -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 * diff --git a/ring-android/app/src/main/res/drawable/ic_screen_rotation_white.xml b/ring-android/app/src/main/res/drawable/ic_screen_rotation_white.xml new file mode 100644 index 0000000000000000000000000000000000000000..606a280ff22d48dd57272a110f7d1457dc15ae51 --- /dev/null +++ b/ring-android/app/src/main/res/drawable/ic_screen_rotation_white.xml @@ -0,0 +1,9 @@ +<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> diff --git a/ring-android/app/src/main/res/menu/ac_call.xml b/ring-android/app/src/main/res/menu/ac_call.xml index c9b3358835b3a0f014add16bd90b0c73136e083b..22197fbbf61a24971eeb5d39f5848c09cf727bc8 100644 --- a/ring-android/app/src/main/res/menu/ac_call.xml +++ b/ring-android/app/src/main/res/menu/ac_call.xml @@ -33,4 +33,10 @@ app:showAsAction="ifRoom" android:icon="@drawable/ic_dialpad_white" 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> \ No newline at end of file diff --git a/ring-android/app/src/main/res/values/strings.xml b/ring-android/app/src/main/res/values/strings.xml index 8257fd44b7dc142d721524797f721c3a4b44594d..50bcee05615f288cff5b3fc01135dc57b35c80e2 100644 --- a/ring-android/app/src/main/res/values/strings.xml +++ b/ring-android/app/src/main/res/values/strings.xml @@ -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_audio_call">Audio 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="write_a_message">Write a message</string> <string name="scan_qr">Scan QR Code</string>