Chronometer, abstract callee activity.

This commit is contained in:
Guillaume Beraudo 2011-11-23 12:37:17 +01:00
parent e82587ae94
commit db02aec518
11 changed files with 394 additions and 403 deletions

View file

@ -80,7 +80,8 @@
</intent-filter>
</activity>
<activity android:name="org.linphone.ConferenceDetailsActivity"
android:theme="@android:style/Theme.NoTitleBar">
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="60sp"
android:minHeight="60sp" android:background="@drawable/conf_callee_bg"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<ImageView android:id="@+id/picture" android:layout_width="wrap_content"
@ -35,8 +35,12 @@
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_centerVertical="true">
<TextView android:id="@+id/name" style="@style/callee_name" />
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<Chronometer android:id="@+id/callee_duration" style="@style/callee_address"
android:paddingRight="10sp"/>
<TextView android:id="@+id/address" style="@style/callee_address" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View file

@ -1,6 +1,7 @@
<?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="48px" >
android:layout_width="fill_parent" android:layout_height="48px"
android:background="@drawable/conf_callee_bg">
<ImageView android:id="@+id/picture" android:layout_width="48px"
android:src="@drawable/unknown_person" android:layout_height="48px"
@ -8,9 +9,14 @@
<LinearLayout android:id="@+id/callee_block" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="48px">
android:layout_toRightOf="@id/picture" android:layout_toLeftOf="@id/callee_statuses"
android:layout_width="fill_parent" android:layout_height="48px">
<TextView android:id="@+id/name" style="@style/callee_name" />
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<Chronometer android:id="@+id/callee_duration" style="@style/callee_address"
android:paddingRight="10sp"/>
<TextView android:id="@+id/address" style="@style/callee_address" />
</LinearLayout>
</LinearLayout>
<View android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1"/>

View file

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="60sp"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/conf_callee_bg">
<ImageView android:id="@+id/picture" android:layout_width="wrap_content"
android:src="@drawable/unknown_person" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:paddingRight="3sp"/>
<LinearLayout android:id="@+id/callee_statuses" android:layout_alignParentRight="true"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:layout_centerVertical="true">
<TextView android:id="@+id/status_label" style="@style/callee_status" />
<ImageView android:id="@+id/callee_status_paused" style="@style/callee_status" android:src="@drawable/conf_status_paused" android:visibility="gone"/>
<ImageView android:id="@+id/callee_status_secured" style="@style/callee_status" android:src="@drawable/conf_secured" android:visibility="gone"/>
<ImageView android:id="@+id/callee_status_maybe_secured" style="@style/callee_status" android:src="@drawable/conf_maybe_secured" android:visibility="gone"/>
<ImageView android:id="@+id/callee_status_not_secured" style="@style/callee_status" android:src="@drawable/conf_not_secured" android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:id="@+id/callee_buttons"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" >
<ImageButton
android:id="@+id/remove_from_conference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/conf_remove"
android:visibility="gone" />
</LinearLayout>
<LinearLayout android:id="@+id/callee_block" android:orientation="vertical"
android:layout_toRightOf="@id/picture" android:layout_toLeftOf="@id/callee_buttons"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_centerVertical="true">
<TextView android:id="@+id/name" style="@style/callee_name" />
<TextView android:id="@+id/address" style="@style/callee_address"/>
<org.linphone.ui.IncallTimer android:id="@+id/callee_duration" style="@style/callee_name"/>
</LinearLayout>
</RelativeLayout>

View file

@ -52,6 +52,9 @@
<LinearLayout android:id="@+id/conf_advanced_buttons"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_above="@id/conf_terminate_row">
<Button android:id="@+id/conf_simple_video" style="@style/conf_icon_text_button"
android:drawableTop="@drawable/conf_video"
android:text="@string/conf_simple_video_bt_txt"/>
<Button android:id="@+id/conf_simple_merge" style="@style/conf_icon_text_button"
android:drawableTop="@drawable/conf_merge"
android:text="@string/conf_simple_merge_bt_txt"/>
@ -67,6 +70,7 @@
android:layout_centerInParent="true"
android:layout_gravity="center" android:scaleType="fitCenter"
android:minWidth="192px" android:minHeight="192px"
android:paddingBottom="60px"
/>
<ListView android:id="@android:id/list"

View file

@ -31,6 +31,7 @@
<string name="state_streams_running"></string>
<string name="state_incoming_received">incoming</string>
<string name="state_outgoing_ringing">ringing</string>
<string name="state_outgoing_progress">calling</string>
<string name="mutemic_button_txt">Mute</string>
<string name="speaker_button_txt">Speaker</string>
@ -54,12 +55,11 @@
<string name="conf_choice_terminate">Terminate</string>
<string name="hangup">Hang up</string>
<string name="conf_simple_resume_bt_txt">Resume</string>
<string name="conf_simple_merge_bt_txt">Merge</string>
<string name="conf_simple_transfer_bt_txt">Transfer</string>
<string name="conf_simple_permute_bt_txt">Permute</string>
<string name="conf_simple_video_bt_txt">Add video</string>
<string name="conf_simple_no_current_call">No active call</string>
<string name="show_send_dtmfs_button">DTMFs</string>
<string name="show_send_dtmfs_button">Dialpad</string>
<string name="conf_conference">Conference</string>
<string name="in_conf">You are part of it</string>

View file

@ -0,0 +1,225 @@
/*
ConferenceActivity.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 java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCall.State;
import android.app.ListActivity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Chronometer;
import android.widget.ImageView;
import android.widget.ToggleButton;
/**
* @author Guillaume Beraudo
*
*/
public abstract class AbstractCalleesActivity extends ListActivity implements LinphoneOnCallStateChangedListener, OnClickListener, LinphoneOnAudioChangedListener {
private CalleeListAdapter mListAdapter;
private List<LinphoneCall> mSpecificCalls = Collections.emptyList();
private Handler mHandler = new Handler();
private ToggleButton mMuteMicButton;
private ToggleButton mSpeakerButton;
protected abstract boolean isActive();
protected abstract void setActive(boolean active);
protected abstract List<LinphoneCall> updateSpecificCallsList();
private Set<Chronometer> mChronometers = new HashSet<Chronometer>();
@Override
/**
* Called by the child classes AFTER their own onCreate.
*/
protected void onCreate(Bundle savedInstanceState) {
setListAdapter(mListAdapter = createCalleeListAdapter());
mMuteMicButton = (ToggleButton) findViewById(R.id.toggleMuteMic);
mMuteMicButton.setOnClickListener(this);
mSpeakerButton = (ToggleButton) findViewById(R.id.toggleSpeaker);
mSpeakerButton.setOnClickListener(this);
super.onCreate(savedInstanceState);
}
protected abstract CalleeListAdapter createCalleeListAdapter();
@Override
protected void onResume() {
mSpecificCalls = updateSpecificCallsList();
if (!finishOnEmptySpecificCallsWhileResuming() || mSpecificCalls.size() != 0) {
setActive(true);
updateUI();
mSpeakerButton.setChecked(LinphoneManager.getInstance().isSpeakerOn());
mMuteMicButton.setChecked(LinphoneManager.getLc().isMicMuted());
LinphoneManager.addListener(this);
LinphoneManager.startProximitySensorForActivity(this);
} else {
finish();
}
super.onResume();
}
protected boolean finishOnEmptySpecificCallsWhileResuming() {
return false;
}
@Override
protected void onPause() {
LinphoneManager.removeListener(this);
LinphoneManager.stopProximitySensorForActivity(this);
setActive(false);
if (isFinishing()) {
stopChronometers();
}
super.onPause();
}
@Override
public void onCallStateChanged(LinphoneCall c, State s, String m) {
mHandler.post(new Runnable() {
public void run() {
mSpecificCalls = updateSpecificCallsList();
updateUI();
}
});
}
protected LinphoneCore lc() {
return LinphoneManager.getLc();
}
private void stopChronometers() {
for (Chronometer chrono : mChronometers) {
chrono.stop();
}
mChronometers.clear();
}
protected void updateUI() {
stopChronometers();
mListAdapter.notifyDataSetChanged();
}
protected void enableView(View root, int id, OnClickListener l, boolean enable) {
LinphoneUtils.enableView(root, id, l, enable);
}
protected String getCalleeDisplayOrUserName(LinphoneAddress address) {
if (!TextUtils.isEmpty(address.getDisplayName())) {
return address.getDisplayName();
} else {
return address.getUserName();
}
}
protected void setCalleePicture(ImageView pictureView, LinphoneAddress address) {
// May be greatly sped up using a drawable cache
Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getContentResolver());
LinphoneUtils.setImagePictureFromUri(AbstractCalleesActivity.this, pictureView, uri, R.drawable.unknown_person);
}
protected void setVisibility(View v, int id, boolean visible) {
LinphoneUtils.setVisibility(v, id, visible);
}
protected void setVisibility(View v, boolean visible) {
LinphoneUtils.setVisibility(v, visible);
}
protected abstract class CalleeListAdapter extends BaseAdapter {
protected final List<LinphoneCall> getSpecificCalls() {
return mSpecificCalls;
}
public int getCount() {
return mSpecificCalls.size();
}
public LinphoneCall getItem(int position) {
return mSpecificCalls.get(position);
}
public long getItemId(int position) {
return position;
}
protected final void registerCallDurationTimer(View v, LinphoneCall call) {
Chronometer timer = (Chronometer) v.findViewById(R.id.callee_duration);
if (timer == null) throw new IllegalArgumentException("no callee_duration view found");
timer.setBase(SystemClock.elapsedRealtime() - 1000 * call.getDuration());
timer.start();
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.toggleMuteMic:
lc().muteMic(((ToggleButton) v).isChecked());
break;
case R.id.toggleSpeaker:
if (((ToggleButton) v).isChecked()) {
LinphoneManager.getInstance().routeAudioToSpeaker();
} else {
LinphoneManager.getInstance().routeAudioToReceiver();
}
break;
default:
break;
}
}
@Override
public void onAudioStateChanged(final AudioState state) {
mSpeakerButton.post(new Runnable() {
@Override
public void run() {
switch (state) {
case SPEAKER:
mSpeakerButton.setChecked(true);
break;
case EARPIECE:
mSpeakerButton.setChecked(false);
break;
default:
throw new RuntimeException("Unknown audio state " + state);
}
}
});
}
}

View file

@ -18,34 +18,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore;
import org.linphone.core.Log;
import org.linphone.core.LinphoneCall.State;
import org.linphone.mediastream.Version;
import org.linphone.ui.IncallTimer;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
/**
* List participants of a conference call.
@ -53,130 +39,43 @@ import android.widget.ToggleButton;
* @author Guillaume Beraudo
*
*/
public class ConferenceDetailsActivity extends ListActivity implements LinphoneOnCallStateChangedListener, OnClickListener {
public class ConferenceDetailsActivity extends AbstractCalleesActivity {
private ConfListAdapter mListAdapter;
private List<LinphoneCall> mLinphoneCalls = Collections.emptyList();
private Handler mHandler = new Handler();
public static boolean active;
private ToggleButton mMuteMicButton;
private ToggleButton mSpeakerButton;
private Runnable mDurationUpdateRunnable;
@Override protected void setActive(boolean a) {active = a;}
@Override protected boolean isActive() {return active;}
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.conference_details_layout);
setListAdapter(mListAdapter = new ConfListAdapter());
mMuteMicButton = (ToggleButton) findViewById(R.id.toggleMuteMic);
mMuteMicButton.setOnClickListener(this);
mSpeakerButton = (ToggleButton) findViewById(R.id.toggleSpeaker);
mSpeakerButton.setOnClickListener(this);
mDurationUpdateRunnable = new Runnable() {
@Override
public void run() {
updateCallDurations();
}
};
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
mLinphoneCalls = LinphoneUtils.getLinphoneCallsInConf(lc());
if (mLinphoneCalls.size() != 0) {
active = true;
updateUI();
mSpeakerButton.setChecked(LinphoneManager.getInstance().isSpeakerOn());
mMuteMicButton.setChecked(LinphoneManager.getLc().isMicMuted());
LinphoneManager.addListener(this);
LinphoneManager.startProximitySensorForActivity(this);
mHandler.post(mDurationUpdateRunnable);
} else {
finish();
}
super.onResume();
protected CalleeListAdapter createCalleeListAdapter() {
return new ConfListAdapter();
}
@Override
protected void onPause() {
LinphoneManager.removeListener(this);
LinphoneManager.stopProximitySensorForActivity(this);
active = false;
super.onPause();
}
@Override
public void onCallStateChanged(LinphoneCall c, State s, String m) {
mHandler.post(new Runnable() {
public void run() {
mLinphoneCalls = LinphoneUtils.getLinphoneCallsInConf(lc());
updateUI();
}
});
}
private LinphoneCore lc() {
return LinphoneManager.getLc();
}
private void updateUI() {
mCallDurationsMap.clear();
mListAdapter.notifyDataSetChanged();
}
private Map<LinphoneCall, IncallTimer> mCallDurationsMap = new HashMap<LinphoneCall, IncallTimer>();
private void updateCallDurations() {
for (LinphoneCall call : mCallDurationsMap.keySet()) {
IncallTimer timer = mCallDurationsMap.get(call);
timer.setDuration(call.getDuration());
}
if (active) mHandler.postDelayed(mDurationUpdateRunnable, 1000);
}
private class ConfListAdapter extends BaseAdapter {
public int getCount() {
return mLinphoneCalls.size();
}
public Object getItem(int position) {
return mLinphoneCalls.get(position);
}
public long getItemId(int position) {
return position;
protected boolean finishOnEmptySpecificCallsWhileResuming() {
return true;
}
private class ConfListAdapter extends CalleeListAdapter {
@Override
public View getView(int position, View v, ViewGroup parent) {
Log.i("IncallActivity.getView(",position,") out of ", mLinphoneCalls.size());
if (v == null) {
if (Version.sdkAboveOrEqual(Version.API06_ECLAIR_201)) {
v = getLayoutInflater().inflate(R.layout.conf_details_participant, null);
v = getLayoutInflater().inflate(R.layout.conf_callee, null);
} else {
throw new RuntimeException("to implement");
// v = getLayoutInflater().inflate(R.layout.conf_callee_older_devices, null);
v = getLayoutInflater().inflate(R.layout.conf_callee_older_devices, null);
}
}
final LinphoneCall call = mLinphoneCalls.get(position);
final LinphoneCall call = getItem(position);
LinphoneAddress address = call.getRemoteAddress();
String mainText = address.getDisplayName();
String complText = address.getUserName();
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)
&& getResources().getBoolean(R.bool.show_full_remote_address_on_incoming_call)) {
complText += "@" + address.getDomain();
}
TextView mainTextView = (TextView) v.findViewById(R.id.name);
TextView complTextView = (TextView) v.findViewById(R.id.address);
if (TextUtils.isEmpty(mainText)) {
mainTextView.setText(complText);
complTextView.setVisibility(View.GONE);
} else {
mainTextView.setText(mainText);
complTextView.setText(complText);
complTextView.setVisibility(View.VISIBLE);
}
final String mainText = getCalleeDisplayOrUserName(address);
((TextView) v.findViewById(R.id.name)).setText(mainText);
((TextView) v.findViewById(R.id.address)).setText("");
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
@ -190,18 +89,13 @@ public class ConferenceDetailsActivity extends ListActivity implements LinphoneO
enableView(content, R.id.terminate_call, l, true);
dialog.show();
}
private void enableView(View root, int id, OnClickListener l, boolean enable) {
LinphoneUtils.enableView(root, id, l, enable);
}
});
ImageView pictureView = (ImageView) v.findViewById(R.id.picture);
// May be greatly sped up using a drawable cache
Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getContentResolver());
LinphoneUtils.setImagePictureFromUri(ConferenceDetailsActivity.this, pictureView, uri, R.drawable.unknown_person);
ImageView pictureView = (ImageView) v.findViewById(R.id.picture);
setCalleePicture(pictureView, address);
mCallDurationsMap.put(call, (IncallTimer) findViewById(R.id.callee_duration));
registerCallDurationTimer(v, call);
return v;
}
@ -232,21 +126,10 @@ public class ConferenceDetailsActivity extends ListActivity implements LinphoneO
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.toggleMuteMic:
lc().muteMic(((ToggleButton) v).isChecked());
break;
case R.id.toggleSpeaker:
if (((ToggleButton) v).isChecked()) {
LinphoneManager.getInstance().routeAudioToSpeaker();
} else {
LinphoneManager.getInstance().routeAudioToReceiver();
}
break;
default:
break;
}
protected List<LinphoneCall> updateSpecificCallsList() {
return LinphoneUtils.getLinphoneCallsInConf(lc());
}
}

View file

@ -22,16 +22,13 @@ import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallEncryptionChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.Log;
import org.linphone.core.LinphoneCall.State;
@ -40,11 +37,9 @@ import org.linphone.ui.Numpad;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
@ -54,7 +49,6 @@ import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
@ -64,29 +58,22 @@ import android.widget.ToggleButton;
/**
* @author Guillaume Beraudo
*/
public class IncallActivity extends ListActivity implements
public class IncallActivity extends AbstractCalleesActivity implements
LinphoneOnAudioChangedListener,
LinphoneOnCallStateChangedListener,
LinphoneOnCallEncryptionChangedListener,
Comparator<LinphoneCall>,
OnLongClickListener,
OnClickListener {
static boolean active;
private boolean mUnMuteOnReturnFromUriPicker;
// Start Override to test block
protected LinphoneCore lc() {
return LinphoneManager.getLc();
}
// End override to test block
private static final int numpad_dialog_id = 1;
private static final int ID_ADD_CALL = 1;
private static final int ID_TRANSFER_CALL = 2;
private static final int numpadDialogId = 1;
private static final int addCallId = 1;
private static final int transferCallId = 2;
public static boolean active;
@Override protected void setActive(boolean a) {active = a;}
@Override protected boolean isActive() {return active;}
private void pauseCurrentCallOrLeaveConference() {
@ -95,13 +82,9 @@ public class IncallActivity extends ListActivity implements
lc().leaveConference();
}
private ToggleButton mMuteMicButton;
private ToggleButton mSpeakerButton;
private View mConferenceVirtualCallee;
private int mMultipleCallsLimit;
private boolean mAllowTransfers;
private List<LinphoneCall> mNotInConfCalls = Collections.emptyList();
private CalleeListAdapter mListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -119,23 +102,39 @@ public class IncallActivity extends ListActivity implements
transferView.setVisibility(View.GONE);
}
mMuteMicButton = (ToggleButton) findViewById(R.id.toggleMuteMic);
mMuteMicButton.setOnClickListener(this);
mSpeakerButton = (ToggleButton) findViewById(R.id.toggleSpeaker);
mSpeakerButton.setOnClickListener(this);
setListAdapter(mListAdapter = new CalleeListAdapter());
findViewById(R.id.incallHang).setOnClickListener(this);
mMultipleCallsLimit = lc().getMaxCalls();
mConferenceVirtualCallee = findViewById(R.id.conf_header);
mConferenceVirtualCallee.setOnClickListener(this);
mConferenceVirtualCallee.setOnLongClickListener(this);
// workaroundStatusBarBug();
boolean mMayDoVideo = Version.isVideoCapable()
&& LinphoneManager.getInstance().isVideoEnabled();
if (mMayDoVideo) {
findViewById(R.id.conf_simple_video).setOnClickListener(this);
} else {
findViewById(R.id.conf_simple_video).setVisibility(GONE);
}
super.onCreate(savedInstanceState);
}
@Override
protected CalleeListAdapter createCalleeListAdapter() {
return new IncallListAdapter();
}
@Override
protected List<LinphoneCall> updateSpecificCallsList() {
return LinphoneUtils.getLinphoneCallsNotInConf(lc());
}
private void updateSoundLock() {
boolean locked = lc().soundResourcesLocked();
findViewById(R.id.addCall).setEnabled(!locked);
@ -149,35 +148,10 @@ public class IncallActivity extends ListActivity implements
findViewById(R.id.addCall).setVisibility(limitReached? View.INVISIBLE : VISIBLE);
}
private void updateDtmfButton() {
private void updateNumpadButton() {
LinphoneCall currentCall = lc().getCurrentCall();
boolean enableDtmf = currentCall != null && currentCall.getState() == State.StreamsRunning;
findViewById(R.id.incallNumpadShow).setEnabled(enableDtmf);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
@Override
protected void onResume() {
active=true;
mNotInConfCalls = LinphoneUtils.getLinphoneCallsNotInConf(lc());
LinphoneManager.addListener(this);
LinphoneManager.startProximitySensorForActivity(this);
mSpeakerButton.setChecked(LinphoneManager.getInstance().isSpeakerOn());
mMuteMicButton.setChecked(LinphoneManager.getLc().isMicMuted());
recreateActivity();
super.onResume();
}
@Override
protected void onPause() {
active=false;
LinphoneManager.removeListener(this);
LinphoneManager.stopProximitySensorForActivity(this);
super.onPause();
boolean enable = currentCall != null && currentCall.getState() == State.StreamsRunning;
findViewById(R.id.incallNumpadShow).setEnabled(enable);
}
private void updateCalleeImage() {
@ -189,20 +163,22 @@ public class IncallActivity extends ListActivity implements
return;
}
Uri picture = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(
currentCall.getRemoteAddress(), getContentResolver());
LinphoneUtils.setImagePictureFromUri(this, view, picture, R.drawable.unknown_person);
setCalleePicture(view, currentCall.getRemoteAddress());
view.setVisibility(VISIBLE);
if (Version.sdkStrictlyBelow(Version.API06_ECLAIR_201)) {
// Fix really big image on older devices
ViewGroup.LayoutParams layout = view.getLayoutParams();
layout.height = 96;
layout.width = 96;
view.setLayoutParams(layout);
}
}
private void enableView(View root, int id, OnClickListener l, boolean enable) {
LinphoneUtils.enableView(root, id, l, enable);
}
@Override
protected Dialog onCreateDialog(final int id) {
switch (id) {
case numpad_dialog_id:
case numpadDialogId:
Numpad numpad = new Numpad(this, true);
return new AlertDialog.Builder(this).setView(numpad)
// .setIcon(R.drawable.logo_linphone_57x57)
@ -216,20 +192,19 @@ public class IncallActivity extends ListActivity implements
})
.create();
default:
throw new RuntimeException("unkown dialog id " + id);
throw new IllegalArgumentException("unkown dialog id " + id);
}
}
}
private LinphoneCall activateCallOnReturnFromUriPicker;
private boolean enterConferenceOnReturnFromUriPicker;
private LinphoneCall mActivateCallOnReturnFromUriPicker;
private boolean mEnterConferenceOnReturnFromUriPicker;
private void openUriPicker(String pickerType, int requestCode) {
if (lc().soundResourcesLocked()) {
Toast.makeText(this, R.string.not_ready_to_make_new_call, Toast.LENGTH_LONG).show();
return;
}
activateCallOnReturnFromUriPicker = lc().getCurrentCall();
enterConferenceOnReturnFromUriPicker = lc().isInConference();
mActivateCallOnReturnFromUriPicker = lc().getCurrentCall();
mEnterConferenceOnReturnFromUriPicker = lc().isInConference();
pauseCurrentCallOrLeaveConference();
Intent intent = new Intent().setClass(this, UriPickerActivity.class);
intent.putExtra(UriPickerActivity.EXTRA_PICKER_TYPE, pickerType);
@ -244,21 +219,14 @@ public class IncallActivity extends ListActivity implements
@Override
public boolean onLongClick(View v) {
switch (v.getId()) {
case R.id.conf_header:
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
if (v.getId() == R.id.conf_header) {
LinphoneActivity.instance().startConferenceDetailsActivity();
} else {
Log.i("conference details disabled for older phones");
}
break;
default:
break;
return true;
}
return false;
}
private void enterConferenceAndUpdateUI(boolean enterConf) {
private void enterConferenceAndVirtualConfView(boolean enterConf) {
if (enterConf) {
boolean success = lc().enterConference();
if (success) {
@ -280,25 +248,23 @@ public class IncallActivity extends ListActivity implements
lc().terminateAllCalls();
}
// activity should be closed automatically by LinphoneActivity when no more calls exist
// setResult(RESULT_OK);
// finish();
// activity wille be closed automatically by LinphoneActivity when no more calls exist
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.addCall:
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_ADD, ID_ADD_CALL);
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_ADD, addCallId);
break;
case R.id.incallHang:
terminateCurrentCallOrConferenceOrAll();
break;
case R.id.conf_header:
boolean enterConf = !lc().isInConference();
enterConferenceAndUpdateUI(enterConf);
enterConferenceAndVirtualConfView(enterConf);
break;
case R.id.incallNumpadShow:
showDialog(numpad_dialog_id);
showDialog(numpadDialogId);
break;
case R.id.conf_simple_merge:
lc().addAllToConference();
@ -311,28 +277,30 @@ public class IncallActivity extends ListActivity implements
Toast.makeText(this, R.string.conf_simple_no_current_call, Toast.LENGTH_SHORT).show();
}
break;
case R.id.toggleMuteMic:
lc().muteMic(((ToggleButton) v).isChecked());
break;
case R.id.toggleSpeaker:
if (((ToggleButton) v).isChecked()) {
LinphoneManager.getInstance().routeAudioToSpeaker();
case R.id.conf_simple_video:
LinphoneCall vCall = lc().getCurrentCall();
if (vCall != null) {
if (!LinphoneManager.getInstance().addVideo()) {
LinphoneActivity.instance().startVideoActivity(vCall, 0);
}
} else {
LinphoneManager.getInstance().routeAudioToReceiver();
Toast.makeText(this, R.string.conf_simple_no_current_call, Toast.LENGTH_SHORT).show();
}
break;
default:
break;
// mic, speaker
super.onClick(v);
}
}
private void prepareForTransferingExistingOrNewCall(final LinphoneCall call) {
// Include inconf calls
final List<LinphoneCall> existingCalls = LinphoneUtils.getLinphoneCalls(lc());
if (existingCalls.size() == 1) {
// Only possible choice is transfer to new call: doing it directly.
mCallToTransfer = call;
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_TRANSFER, ID_TRANSFER_CALL);
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_TRANSFER, transferCallId);
return;
}
existingCalls.remove(call);
@ -348,7 +316,7 @@ public class IncallActivity extends ListActivity implements
if (which == numbers.size() -1) {
// Last one is transfer to new call
mCallToTransfer = call;
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_TRANSFER, ID_TRANSFER_CALL);
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_TRANSFER, transferCallId);
} else {
lc().transferCallToAnother(call, existingCalls.get(which));
}
@ -379,7 +347,7 @@ public class IncallActivity extends ListActivity implements
prepareForTransferingExistingOrNewCall(call);
break;
case R.id.transfer_new:
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_TRANSFER, ID_TRANSFER_CALL);
openUriPicker(UriPickerActivity.EXTRA_PICKER_TYPE_TRANSFER, transferCallId);
mCallToTransfer = call;
break;
case R.id.addVideo:
@ -402,25 +370,14 @@ public class IncallActivity extends ListActivity implements
if (dialog != null) dialog.dismiss();
}
}
private class CalleeListAdapter extends BaseAdapter {
public int getCount() {
return mNotInConfCalls.size();
}
public Object getItem(int position) {
return mNotInConfCalls.get(position);
}
public long getItemId(int position) {
return position;
}
private class IncallListAdapter extends CalleeListAdapter {
private boolean aConferenceIsPossible() {
if (lc().getCallsNb() < 2) {
return false;
}
int count = 0;
for (LinphoneCall call : mNotInConfCalls) {
for (LinphoneCall call : getSpecificCalls()) {
final LinphoneCall.State state = call.getState();
boolean connectionEstablished = state == State.StreamsRunning
|| state == State.Paused
@ -433,17 +390,6 @@ public class IncallActivity extends ListActivity implements
return false;
}
private void setVisibility(View v, int id, boolean visible) {
LinphoneUtils.setVisibility(v, id, visible);
}
private void setVisibility(View v, boolean visible) {
LinphoneUtils.setVisibility(v, visible);
}
private void setStatusLabel(View v, State state, boolean activeOne) {
String statusLabel = getStateText(state);
((TextView) v.findViewById(R.id.status_label)).setText(statusLabel);
}
private boolean highlightCall(LinphoneCall call) {
final State state = call.getState();
return state == State.StreamsRunning
@ -455,7 +401,6 @@ public class IncallActivity extends ListActivity implements
}
public View getView(int position, View v, ViewGroup parent) {
Log.i("IncallActivity.getView(",position,") out of ", mNotInConfCalls.size());
if (v == null) {
if (Version.sdkAboveOrEqual(Version.API06_ECLAIR_201)) {
v = getLayoutInflater().inflate(R.layout.conf_callee, null);
@ -464,26 +409,21 @@ public class IncallActivity extends ListActivity implements
}
}
final LinphoneCall call = mNotInConfCalls.get(position);
final LinphoneCall call = getItem(position);
final LinphoneCall.State state = call.getState();
LinphoneAddress address = call.getRemoteAddress();
String mainText = address.getDisplayName();
String complText = address.getUserName();
TextView mainTextView = (TextView) v.findViewById(R.id.name);
TextView complTextView = (TextView) v.findViewById(R.id.address);
if (TextUtils.isEmpty(mainText)) {
mainTextView.setText(complText);
complTextView.setVisibility(View.GONE);
if (!TextUtils.isEmpty(address.getDisplayName())) {
mainTextView.setText(address.getDisplayName());
} else {
mainTextView.setText(mainText);
complTextView.setText(complText);
complTextView.setVisibility(View.VISIBLE);
mainTextView.setText(address.getUserName());
}
String statusLabel = getStateText(state);
((TextView) v.findViewById(R.id.address)).setText(statusLabel);
boolean highlighted = highlightCall(call);
setStatusLabel(v, state, highlighted);
int bgDrawableId = R.drawable.conf_callee_selector_normal;
if (state == State.IncomingReceived) {
@ -500,19 +440,13 @@ public class IncallActivity extends ListActivity implements
final boolean showMergeToConf = connectionEstablished && aConferenceIsPossible();
setVisibility(confButton, false);
final int numberOfCalls = mNotInConfCalls.size();
boolean showAddVideo = State.StreamsRunning == state
&& Version.isVideoCapable()
&& LinphoneManager.getInstance().isVideoEnabled();
View addVideoButton = v.findViewById(R.id.addVideo);
setVisibility(addVideoButton, showAddVideo);
final int numberOfCalls = getSpecificCalls().size();
boolean statusPaused = state== State.Paused || state == State.PausedByRemote;
setVisibility(v, R.id.callee_status_paused, statusPaused);
final OnClickListener l = new CallActionListener(call);
confButton.setOnClickListener(l);
addVideoButton.setOnClickListener(l);
String mediaEncryption = call.getCurrentParamsCopy().getMediaEncryption();
if ("none".equals(mediaEncryption)) {
@ -580,13 +514,12 @@ public class IncallActivity extends ListActivity implements
ImageView pictureView = (ImageView) v.findViewById(R.id.picture);
if (numberOfCalls != 1) {
// May be greatly sped up using a drawable cache
Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getContentResolver());
LinphoneUtils.setImagePictureFromUri(IncallActivity.this, pictureView, uri, R.drawable.unknown_person);
pictureView.setVisibility(VISIBLE);
setCalleePicture(pictureView, address);
} else {
pictureView.setVisibility(GONE);
}
registerCallDurationTimer(v, call);
return v;
}
@ -604,36 +537,38 @@ public class IncallActivity extends ListActivity implements
id=R.string.state_incoming_received;
} else if (state == State.OutgoingRinging) {
id=R.string.state_outgoing_ringing;
} else if (state == State.OutgoingProgress) {
id=R.string.state_outgoing_progress;
} else {
return "";
}
return getString(id);
}
private Handler mHandler = new Handler();
private void updateAdvancedButtons() {
LinphoneCall activeCall = lc().getCurrentCall();
View bar = findViewById(R.id.conf_advanced_buttons);
if (activeCall == null) {
bar.setVisibility(GONE);
return;
}
int nonConfCallsNb = LinphoneUtils.countNonConferenceCalls(lc());
// in this part, we know nonConfCallsNb > 0 as the active call cannot be a conf call
View merge = bar.findViewById(R.id.conf_simple_merge);
boolean showMerge = nonConfCallsNb >=2
|| (lc().getConferenceSize() > 0 && nonConfCallsNb > 0);
merge.setEnabled(showMerge);
boolean enableMerge = nonConfCallsNb >=2 || lc().getConferenceSize() > 0;
enableMerge = true;
merge.setEnabled(enableMerge);
View transfer = bar.findViewById(R.id.conf_simple_transfer);
boolean showTransfer = mAllowTransfers && activeCall != null;
transfer.setEnabled(showTransfer);
}
boolean enableTransfer = mAllowTransfers && activeCall != null;
transfer.setEnabled(enableTransfer);
public void onCallStateChanged(final LinphoneCall c, final State s, String m) {
mHandler.post(new Runnable() {
public void run() {
mNotInConfCalls = LinphoneUtils.getLinphoneCallsNotInConf(lc());
recreateActivity();
}
});
// video always enabled when a call active (though may not be shown)
bar.setVisibility(VISIBLE);
}
private void updateConfItem() {
@ -650,15 +585,15 @@ public class IncallActivity extends ListActivity implements
}
}
private void recreateActivity() {
protected void updateUI() {
updateAdvancedButtons();
updateCalleeImage();
updateSoundLock();
updateAddCallButton();
updateDtmfButton();
updateNumpadButton();
updateConfItem();
mListAdapter.notifyDataSetChanged();
super.updateUI();
}
public int compare(LinphoneCall c1, LinphoneCall c2) {
@ -726,7 +661,7 @@ public class IncallActivity extends ListActivity implements
}
switch (requestCode) {
case ID_ADD_CALL:
case addCallId:
try {
lc().invite(uri);
eventuallyResumeConfOrCallOnPickerReturn(false);
@ -735,12 +670,12 @@ public class IncallActivity extends ListActivity implements
Toast.makeText(this, R.string.error_adding_new_call, Toast.LENGTH_LONG).show();
}
break;
case ID_TRANSFER_CALL:
case transferCallId:
lc().transferCall(mCallToTransfer, uri);
// don't re-enter conference if call to transfer from conference
boolean doResume = !mCallToTransfer.isInConference();
// don't resume call if it is the call to transfer
doResume &= activateCallOnReturnFromUriPicker != mCallToTransfer;
doResume &= mActivateCallOnReturnFromUriPicker != mCallToTransfer;
eventuallyResumeConfOrCallOnPickerReturn(doResume);
Toast.makeText(this, R.string.transfer_started, Toast.LENGTH_LONG).show();
break;
@ -751,14 +686,14 @@ public class IncallActivity extends ListActivity implements
private void eventuallyResumeConfOrCallOnPickerReturn(boolean doCallConfResuming) {
if (doCallConfResuming) {
if (activateCallOnReturnFromUriPicker != null) {
lc().resumeCall(activateCallOnReturnFromUriPicker);
} else if (enterConferenceOnReturnFromUriPicker) {
enterConferenceAndUpdateUI(true);
if (mActivateCallOnReturnFromUriPicker != null) {
lc().resumeCall(mActivateCallOnReturnFromUriPicker);
} else if (mEnterConferenceOnReturnFromUriPicker) {
enterConferenceAndVirtualConfView(true);
}
}
activateCallOnReturnFromUriPicker = null;
enterConferenceOnReturnFromUriPicker = false;
mActivateCallOnReturnFromUriPicker = null;
mEnterConferenceOnReturnFromUriPicker = false;
}
@Override
@ -768,31 +703,14 @@ public class IncallActivity extends ListActivity implements
return super.onKeyDown(keyCode, event);
}
@Override
public void onAudioStateChanged(final AudioState state) {
mSpeakerButton.post(new Runnable() {
@Override
public void run() {
switch (state) {
case SPEAKER:
mSpeakerButton.setChecked(true);
break;
case EARPIECE:
mSpeakerButton.setChecked(false);
break;
default:
throw new RuntimeException("Unknown audio state " + state);
}
}
});
}
private Handler mHandler = new Handler();
@Override
public void onCallEncryptionChanged(LinphoneCall call, boolean encrypted,
String authenticationToken) {
mHandler.post(new Runnable() {
public void run() {
recreateActivity();
updateUI();
}
});
}

View file

@ -503,19 +503,16 @@ public class LinphoneActivity extends TabActivity implements
if (state==State.Error){
showToast(R.string.call_error, message);
}
if (state==State.Error || state==State.CallEnd) {
if (lc.getCallsNb() == 0){
exitIncallActivity();
}
}else if (state==State.CallEnd){
if (lc.getCallsNb() == 0){
exitIncallActivity();
}
}
if (ConferenceDetailsActivity.active && lc.getConferenceSize() == 0) {
finishActivity(conferenceDetailsActivity);
}
}
}
private void showToast(int id, String txt) {
final String msg = String.format(getString(id), txt);

View file

@ -59,7 +59,7 @@ public class IncallTimer extends TextView {
int hours = seconds / 3600;
if (hours != 0) {
return hours + " - " + time;
return hours + ":" + time;
} else {
return time;
}