Linphone service waiting activity.
This commit is contained in:
parent
45da67aa1c
commit
08e025a07e
5 changed files with 168 additions and 45 deletions
8
res/layout/wait_service_dialog.xml
Normal file
8
res/layout/wait_service_dialog.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent">
|
||||||
|
<ProgressBar android:layout_height="wrap_content" android:layout_width="wrap_content"/>
|
||||||
|
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="waiting"/>
|
||||||
|
</LinearLayout>
|
|
@ -62,7 +62,7 @@ import android.widget.Toast;
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiListener, NewOutgoingCallUiListener {
|
public class DialerActivity extends LinphoneManagerWaitActivity implements LinphoneGuiListener, NewOutgoingCallUiListener {
|
||||||
|
|
||||||
private TextView mStatus;
|
private TextView mStatus;
|
||||||
private View mHangup;
|
private View mHangup;
|
||||||
|
@ -89,7 +89,7 @@ public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiLis
|
||||||
private static final String CURRENT_ADDRESS = "org.linphone.current-address";
|
private static final String CURRENT_ADDRESS = "org.linphone.current-address";
|
||||||
private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
|
private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
|
||||||
|
|
||||||
private static final int INCOMING_CALL_DIALOG_ID = 1;
|
private static final int incomingCallDialogId = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null if not ready yet
|
* @return null if not ready yet
|
||||||
|
@ -146,19 +146,20 @@ public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiLis
|
||||||
|
|
||||||
checkIfOutgoingCallIntentReceived();
|
checkIfOutgoingCallIntentReceived();
|
||||||
|
|
||||||
if (LinphoneService.isReady()) {
|
|
||||||
LinphoneCore lc = LinphoneManager.getLc();
|
|
||||||
if (lc.isIncall()) {
|
|
||||||
if(lc.isInComingInvitePending()) {
|
|
||||||
callPending(lc.getCurrentCall());
|
|
||||||
} else {
|
|
||||||
enterIncallMode(lc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLinphoneManagerAvailable(LinphoneManager m) {
|
||||||
|
LinphoneCore lc = LinphoneManager.getLc();
|
||||||
|
if (lc.isIncall()) {
|
||||||
|
if(lc.isInComingInvitePending()) {
|
||||||
|
callPending(lc.getCurrentCall());
|
||||||
|
} else {
|
||||||
|
enterIncallMode(lc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -268,7 +269,7 @@ public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiLis
|
||||||
private void exitCallMode() {
|
private void exitCallMode() {
|
||||||
// Remove dialog if existing
|
// Remove dialog if existing
|
||||||
try {
|
try {
|
||||||
dismissDialog(INCOMING_CALL_DIALOG_ID);
|
dismissDialog(incomingCallDialogId);
|
||||||
} catch (Throwable e) {/* Exception if never created */}
|
} catch (Throwable e) {/* Exception if never created */}
|
||||||
|
|
||||||
if (useIncallActivity) {
|
if (useIncallActivity) {
|
||||||
|
@ -301,50 +302,57 @@ public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiLis
|
||||||
|
|
||||||
|
|
||||||
private void callPending(final LinphoneCall call) {
|
private void callPending(final LinphoneCall call) {
|
||||||
showDialog(INCOMING_CALL_DIALOG_ID);
|
showDialog(incomingCallDialogId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialog(int id, Dialog dialog) {
|
protected void onPrepareDialog(int id, Dialog dialog) {
|
||||||
|
if (id == incomingCallDialogId) {
|
||||||
String from = LinphoneManager.getInstance().extractIncomingRemoteName();
|
String from = LinphoneManager.getInstance().extractIncomingRemoteName();
|
||||||
String msg = String.format(getString(R.string.incoming_call_dialog_title), from);
|
String msg = String.format(getString(R.string.incoming_call_dialog_title), from);
|
||||||
((AlertDialog) dialog).setMessage(msg);
|
((AlertDialog) dialog).setMessage(msg);
|
||||||
|
} else {
|
||||||
super.onPrepareDialog(id, dialog);
|
super.onPrepareDialog(id, dialog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
View incomingCallView = getLayoutInflater().inflate(R.layout.incoming_call, null);
|
if (id == incomingCallDialogId) {
|
||||||
|
View incomingCallView = getLayoutInflater().inflate(R.layout.incoming_call, null);
|
||||||
|
|
||||||
final Dialog dialog = new AlertDialog.Builder(this)
|
final Dialog dialog = new AlertDialog.Builder(this)
|
||||||
.setMessage("")
|
.setMessage("")
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setView(incomingCallView).create();
|
.setView(incomingCallView).create();
|
||||||
|
|
||||||
|
|
||||||
((CallButton) incomingCallView.findViewById(R.id.Call)).setExternalClickListener(new OnClickListener() {
|
((CallButton) incomingCallView.findViewById(R.id.Call)).setExternalClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
if (Version.isVideoCapable()) {
|
if (Version.isVideoCapable()) {
|
||||||
LinphoneManager.getInstance().resetCameraFromPreferences();
|
LinphoneManager.getInstance().resetCameraFromPreferences();
|
||||||
|
|
||||||
// Privacy setting to not share the user camera by default
|
// Privacy setting to not share the user camera by default
|
||||||
boolean prefVideoEnable = LinphoneManager.getInstance().isVideoEnabled();
|
boolean prefVideoEnable = LinphoneManager.getInstance().isVideoEnabled();
|
||||||
int key = R.string.pref_video_automatically_share_my_video_key;
|
int key = R.string.pref_video_automatically_share_my_video_key;
|
||||||
boolean prefAutoShareMyCamera = mPref.getBoolean(getString(key), false);
|
boolean prefAutoShareMyCamera = mPref.getBoolean(getString(key), false);
|
||||||
boolean videoMuted = !(prefVideoEnable && prefAutoShareMyCamera);
|
boolean videoMuted = !(prefVideoEnable && prefAutoShareMyCamera);
|
||||||
|
|
||||||
LinphoneManager.getLc().getCurrentCall().enableCamera(prefAutoShareMyCamera);
|
LinphoneManager.getLc().getCurrentCall().enableCamera(prefAutoShareMyCamera);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
((HangCallButton) incomingCallView.findViewById(R.id.Decline)).setExternalClickListener(new OnClickListener() {
|
||||||
((HangCallButton) incomingCallView.findViewById(R.id.Decline)).setExternalClickListener(new OnClickListener() {
|
public void onClick(View v) {dialog.dismiss();}
|
||||||
public void onClick(View v) {dialog.dismiss();}
|
});
|
||||||
});
|
|
||||||
|
return dialog;
|
||||||
return dialog;
|
} else {
|
||||||
|
return super.onCreateDialog(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void newOutgoingCall(Intent intent) {
|
public void newOutgoingCall(Intent intent) {
|
||||||
|
|
103
src/org/linphone/LinphoneManagerWaitActivity.java
Normal file
103
src/org/linphone/LinphoneManagerWaitActivity.java
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
LinphoneManagerWaitActivity.java
|
||||||
|
Copyright (C) 2011 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.
|
||||||
|
*/
|
||||||
|
package org.linphone;
|
||||||
|
|
||||||
|
import org.linphone.core.Log;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity requiring access to LinphoneManager should inherit from this class.
|
||||||
|
*
|
||||||
|
* @author Guillaume Beraudo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class LinphoneManagerWaitActivity extends SoftVolumeActivity {
|
||||||
|
|
||||||
|
private final int waitServiceDialogId = 314159265;
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (LinphoneService.isReady()) {
|
||||||
|
onLinphoneManagerAvailable(LinphoneManager.getInstance());
|
||||||
|
} else {
|
||||||
|
showDialog(waitServiceDialogId);
|
||||||
|
thread = new ServiceWaitThread();
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServiceWaitThread thread;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if (thread != null) thread.interrupt();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dialog onCreateDialog(int id) {
|
||||||
|
if (id == waitServiceDialogId) {
|
||||||
|
View v = getLayoutInflater().inflate((R.layout.wait_service_dialog), null);
|
||||||
|
return new AlertDialog.Builder(this).setView(v).setCancelable(false).create();
|
||||||
|
}
|
||||||
|
return super.onCreateDialog(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void onLinphoneManagerAvailable(LinphoneManager m);
|
||||||
|
|
||||||
|
private void dismissDialogFromThread(final int id) {
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
dismissDialog(id);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// Discarding exception which may be thrown if the dialog wasn't showing.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ServiceWaitThread extends Thread {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (!LinphoneService.isReady()) {
|
||||||
|
try {
|
||||||
|
sleep(30);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.e("waiting thread sleep() has been interrupted, exiting as requested");
|
||||||
|
dismissDialogFromThread(waitServiceDialogId); // FIXME, may not be the best thing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onLinphoneManagerAvailable(LinphoneManager.getInstance());
|
||||||
|
dismissDialogFromThread(waitServiceDialogId);
|
||||||
|
super.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -99,7 +99,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
instance = this;
|
|
||||||
|
|
||||||
// In case restart after a crash. Main in LinphoneActivity
|
// In case restart after a crash. Main in LinphoneActivity
|
||||||
LinphonePreferenceManager.getInstance(this);
|
LinphonePreferenceManager.getInstance(this);
|
||||||
|
@ -127,6 +126,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
||||||
|
|
||||||
|
|
||||||
LinphoneManager.createAndStart(this, this);
|
LinphoneManager.createAndStart(this, this);
|
||||||
|
instance = this; // instance is ready once linphone manager has been created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
|
import org.linphone.core.Log;
|
||||||
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -35,9 +36,12 @@ public class SoftVolumeActivity extends Activity {
|
||||||
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
|
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
|
||||||
&& (Hacks.needSoftvolume() || LinphonePreferenceManager.getInstance().useSoftvolume())) {
|
&& (Hacks.needSoftvolume() || LinphonePreferenceManager.getInstance(this).useSoftvolume())) {
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
if (!LinphoneService.isReady()) {
|
||||||
|
Log.i("Couldn't change softvolume has service is not running");
|
||||||
|
return true;
|
||||||
|
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||||
LinphoneManager.getInstance().adjustSoftwareVolume(1);
|
LinphoneManager.getInstance().adjustSoftwareVolume(1);
|
||||||
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||||
LinphoneManager.getInstance().adjustSoftwareVolume(-1);
|
LinphoneManager.getInstance().adjustSoftwareVolume(-1);
|
||||||
|
|
Loading…
Reference in a new issue