diff --git a/src/org/linphone/ConferenceActivity.java b/src/org/linphone/ConferenceActivity.java index 20fc2e9f7..7ee40cef1 100644 --- a/src/org/linphone/ConferenceActivity.java +++ b/src/org/linphone/ConferenceActivity.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.linphone.LinphoneManagerWaitHelper.LinphoneManagerReadyListener; import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener; import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCore; @@ -58,6 +59,7 @@ import android.widget.ToggleButton; * @author Guillaume Beraudo */ public class ConferenceActivity extends ListActivity implements + LinphoneManagerReadyListener, LinphoneOnCallStateChangedListener, Comparator, OnClickListener { @@ -90,6 +92,7 @@ public class ConferenceActivity extends ListActivity implements private static final int ID_TRANSFER_CALL = 2; + private void workaroundStatusBarBug() { getWindow().setFlags( WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, @@ -102,6 +105,7 @@ public class ConferenceActivity extends ListActivity implements lc().leaveConference(); } + private LinphoneManagerWaitHelper waitHelper; @Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.conferencing); @@ -119,9 +123,22 @@ public class ConferenceActivity extends ListActivity implements findViewById(R.id.toggleMuteMic).setOnClickListener(this); findViewById(R.id.toggleSpeaker).setOnClickListener(this); + waitHelper = new LinphoneManagerWaitHelper(this, this); + waitHelper.doManagerDependentOnCreate(); + workaroundStatusBarBug(); + } + + @Override + public void onCreateWhenManagerReady() { List calls = getInitialCalls(); setListAdapter(new CalleeListAdapter(calls)); - workaroundStatusBarBug(); + } + @Override + public void onResumeWhenManagerReady() { + registerLinphoneListener(true); + updateConfState(); + boolean showSimpleActions = lc().getConferenceSize() == 0 && lc().getCallsNb() == 2; + findViewById(R.id.conf_simple_merge).setVisibility(showSimpleActions ? VISIBLE : GONE); } @Override @@ -136,13 +153,12 @@ public class ConferenceActivity extends ListActivity implements LinphoneManager.getInstance().removeListener(this); } + + @Override protected void onResume() { active=true; - registerLinphoneListener(true); - updateConfState(); - boolean showSimpleActions = lc().getConferenceSize() == 0 && lc().getCallsNb() == 2; - findViewById(R.id.conf_simple_merge).setVisibility(showSimpleActions ? VISIBLE : GONE); + waitHelper.doManagerDependentOnResume(); super.onResume(); } @@ -589,6 +605,7 @@ public class ConferenceActivity extends ListActivity implements throw new RuntimeException("unhandled request code " + requestCode); } } + /* * public int compare(LinphoneCall c1, LinphoneCall c2) { if (c1 == c2) diff --git a/src/org/linphone/DialerActivity.java b/src/org/linphone/DialerActivity.java index 9d6013d0d..b025baf2a 100644 --- a/src/org/linphone/DialerActivity.java +++ b/src/org/linphone/DialerActivity.java @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package org.linphone; import org.linphone.LinphoneManager.NewOutgoingCallUiListener; +import org.linphone.LinphoneManagerWaitHelper.LinphoneManagerReadyListener; import org.linphone.LinphoneService.LinphoneGuiListener; import org.linphone.core.CallDirection; import org.linphone.core.LinphoneAddress; @@ -63,7 +64,7 @@ import android.widget.Toast; * * */ -public class DialerActivity extends LinphoneManagerWaitActivity implements LinphoneGuiListener, NewOutgoingCallUiListener, OnClickListener { +public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiListener, LinphoneManagerReadyListener, NewOutgoingCallUiListener, OnClickListener { private TextView mStatus; private View mHangup; @@ -101,7 +102,7 @@ public class DialerActivity extends LinphoneManagerWaitActivity implements Linph return instance; } - + private LinphoneManagerWaitHelper waitHelper; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialer); @@ -151,11 +152,13 @@ public class DialerActivity extends LinphoneManagerWaitActivity implements Linph checkIfOutgoingCallIntentReceived(); + waitHelper = new LinphoneManagerWaitHelper(this, this); + waitHelper.doManagerDependentOnCreate(); instance = this; } @Override - protected void onLinphoneManagerAvailable(LinphoneManager m) { + public void onCreateWhenManagerReady() { LinphoneCore lc = LinphoneManager.getLc(); if (lc.isIncall()) { if(lc.isInComingInvitePending()) { @@ -344,8 +347,6 @@ public class DialerActivity extends LinphoneManagerWaitActivity implements Linph @Override protected Dialog onCreateDialog(int id) { if (id == incomingCallDialogId) { - LinphoneAddress address = LinphoneManager.getLc().getRemoteAddress(); - String from = LinphoneManager.extractIncomingRemoteName(getResources(), address); View incomingCallView = getLayoutInflater().inflate(R.layout.incoming_call, null); final Dialog dialog = new AlertDialog.Builder(this) @@ -375,6 +376,8 @@ public class DialerActivity extends LinphoneManagerWaitActivity implements Linph }); return dialog; + } else if (id == LinphoneManagerWaitHelper.DIALOG_ID) { + return waitHelper.createWaitDialog(); } else { return super.onCreateDialog(id); } @@ -502,7 +505,7 @@ public class DialerActivity extends LinphoneManagerWaitActivity implements Linph } @Override - protected void onResume() { + public void onResumeWhenManagerReady() { updateCallControlRow(); // When coming back from a video call, if the phone orientation is different @@ -511,9 +514,12 @@ public class DialerActivity extends LinphoneManagerWaitActivity implements Linph // and set to the to be destroyed Dialer. // Note1: We wait as long as possible before setting the last message. // Note2: Linphone service is in charge of instantiating LinphoneManager - if (LinphoneService.isReady()) { - mStatus.setText(LinphoneManager.getInstance().getLastLcStatusMessage()); - } + mStatus.setText(LinphoneManager.getInstance().getLastLcStatusMessage()); + } + + @Override + protected void onResume() { + waitHelper.doManagerDependentOnResume(); super.onResume(); } diff --git a/src/org/linphone/LinphoneManagerWaitActivity.java b/src/org/linphone/LinphoneManagerWaitActivity.java deleted file mode 100644 index 3899aefb3..000000000 --- a/src/org/linphone/LinphoneManagerWaitActivity.java +++ /dev/null @@ -1,103 +0,0 @@ -/* -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(); - } - } - -}