Preview rotate in video call

This commit is contained in:
Sylvain Berfini 2012-08-01 17:47:04 +02:00
parent 094ca2dc20
commit 35aa663567
6 changed files with 129 additions and 1 deletions

20
res/layout-land/video.xml Normal file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.linphone.mediastream.video.display.GL2JNIView
android:visibility="visible"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/videoSurface" />
<SurfaceView
android:id="@+id/videoCaptureSurface"
android:layout_width="145dp"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

View file

@ -35,6 +35,7 @@ import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCallLog;
import org.linphone.core.LinphoneCallLog.CallStatus;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.Log;
@ -43,6 +44,7 @@ import org.linphone.setup.SetupActivity;
import org.linphone.ui.AddressText;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
@ -56,6 +58,7 @@ import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
@ -89,6 +92,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
private Handler mHandler = new Handler();
private List<Contact> contactList, sipContactList;
private Cursor contactCursor, sipContactCursor;
private OrientationEventListener mOrientationHelper;
static final boolean isInstanciated() {
return instance != null;
@ -135,6 +139,16 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
displayMissedCalls(missedCalls);
int rotation = Compatibility.getRotation(getWindowManager().getDefaultDisplay());
// Inverse landscape rotation to initiate linphoneCore correctly
if (rotation == 270)
rotation = 90;
else if (rotation == 90)
rotation = 270;
LinphoneManager.getLc().setDeviceRotation(rotation);
mAlwaysChangingPhoneAngle = rotation;
instance = this;
}
@ -604,6 +618,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
public void startVideoActivity(LinphoneCall currentCall) {
Intent intent = new Intent(this, InCallActivity.class);
intent.putExtra("VideoEnabled", true);
startOrientationSensor();
startActivityForResult(intent, callActivity);
}
@ -612,6 +627,46 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
intent.putExtra("VideoEnabled", false);
startActivityForResult(intent, callActivity);
}
/**
* Register a sensor to track phoneOrientation changes
*/
private synchronized void startOrientationSensor() {
if (mOrientationHelper == null) {
mOrientationHelper = new LocalOrientationEventListener(this);
}
mOrientationHelper.enable();
}
private int mAlwaysChangingPhoneAngle = -1;
private class LocalOrientationEventListener extends OrientationEventListener {
public LocalOrientationEventListener(Context context) {
super(context);
}
@Override
public void onOrientationChanged(final int o) {
if (o == OrientationEventListener.ORIENTATION_UNKNOWN) return;
int degrees=270;
if (o < 45 || o >315) degrees=0;
else if (o<135) degrees=90;
else if (o<225) degrees=180;
if (mAlwaysChangingPhoneAngle == degrees) return;
mAlwaysChangingPhoneAngle = degrees;
Log.d("Phone orientation changed to ", degrees);
int rotation = (360 - degrees) % 360;
LinphoneCore lc=LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc!=null){
lc.setDeviceRotation(rotation);
LinphoneCall currentCall = lc.getCurrentCall();
if (currentCall != null && currentCall.cameraEnabled() && currentCall.getCurrentParamsCopy().getVideoEnabled()) {
lc.updateCall(currentCall, null);
}
}
}
}
public void showPreferenceErrorDialog(String message) {

View file

@ -138,6 +138,9 @@ public class VideoCallFragment extends Fragment implements OnGestureListener, On
}
}
private void rotatePreviewIfNeeded() {
}
@Override
public void onResume() {
super.onResume();
@ -151,9 +154,11 @@ public class VideoCallFragment extends Fragment implements OnGestureListener, On
}
}
rotatePreviewIfNeeded();
mWakeLock.acquire();
}
@Override
public void onPause() {
synchronized (androidVideoWindowImpl) {

View file

@ -0,0 +1,33 @@
package org.linphone.compatibility;
import android.annotation.TargetApi;
import android.view.Display;
/*
ApiEightPlus.java
Copyright (C) 2012 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* @author Sylvain Berfini
*/
@TargetApi(8)
public class ApiEightPlus {
public static int getRotation(Display display) {
return display.getRotation();
}
}

View file

@ -27,6 +27,7 @@ import android.provider.ContactsContract.CommonDataKinds.SipAddress;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Intents.Insert;
import android.view.Display;
/*
ApiFivePlus.java
@ -275,4 +276,9 @@ public class ApiFivePlus {
}
return null;
}
@SuppressWarnings("deprecation")
public static int getRotation(Display display) {
return display.getOrientation();
}
}

View file

@ -34,6 +34,7 @@ import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.Display;
/**
* @author Sylvain Berfini
*/
@ -176,4 +177,12 @@ public class Compatibility {
}
return null;
}
public static int getRotation(Display display) {
if (Version.sdkStrictlyBelow(8)) {
return ApiFivePlus.getRotation(display);
} else {
return ApiEightPlus.getRotation(display);
}
}
}