Display registration state of all accounts in status bar's slider

This commit is contained in:
Sylvain Berfini 2012-07-19 17:25:35 +02:00
parent a3931bf307
commit dfc8d92965
3 changed files with 96 additions and 19 deletions

20
res/layout/accounts.xml Normal file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="horizontal"
android:gravity="center" android:layout_height="fill_parent">
<ImageView
android:id="@+id/State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/Identity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@android:color/white"
android:layout_weight="4"/>
</LinearLayout>

View file

@ -9,7 +9,7 @@
<org.linphone.ui.SlidingDrawer
android:id="@+id/statusBar"
linphone:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="80dp"
linphone:handle="@+id/handle"
linphone:content="@+id/content">

View file

@ -17,9 +17,14 @@ 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.
*/
import java.util.ArrayList;
import java.util.HashMap;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.MediaEncryption;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.ui.SlidingDrawer;
import android.app.Activity;
@ -30,7 +35,13 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.SimpleAdapter;
import android.widget.TextView;
/**
@ -42,6 +53,7 @@ public class StatusFragment extends Fragment {
private Handler refreshHandler = new Handler();
private TextView statusText, exit;
private ImageView statusLed, callQuality, encryption;
private RelativeLayout sliderContent;
private SlidingDrawer drawer;
private Runnable mCallQualityUpdater;
private boolean isInCall, isAttached = false;
@ -58,6 +70,7 @@ public class StatusFragment extends Fragment {
encryption = (ImageView) view.findViewById(R.id.encryption);
drawer = (SlidingDrawer) view.findViewById(R.id.statusBar);
sliderContent = (RelativeLayout) view.findViewById(R.id.content);
exit = (TextView) view.findViewById(R.id.exit);
exit.setOnClickListener(new OnClickListener() {
@Override
@ -100,7 +113,8 @@ public class StatusFragment extends Fragment {
if (getResources().getBoolean(R.bool.lock_statusbar)) {
return;
}
populateSliderContent();
if (getResources().getBoolean(R.bool.disable_animations)) {
drawer.toggle();
} else {
@ -108,6 +122,28 @@ public class StatusFragment extends Fragment {
}
}
private void populateSliderContent() {
sliderContent.removeAllViews();
ListView accounts = new ListView(getActivity());
accounts.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
accounts.setDividerHeight(0);
ArrayList<HashMap<String,String>> hashMapAccountsStateList = new ArrayList<HashMap<String,String>>();
for (LinphoneProxyConfig lpc : LinphoneManager.getLc().getProxyConfigList()) {
HashMap<String, String> entitiesHashMap = new HashMap<String, String>();
entitiesHashMap.put("Identity", lpc.getIdentity().split("sip:")[1]);
entitiesHashMap.put("State", Integer.toString(getStatusIconResource(lpc.getState())));
hashMapAccountsStateList.add(entitiesHashMap);
}
Adapter adapterForList = new SimpleAdapter(getActivity(), hashMapAccountsStateList, R.layout.accounts,
new String[] {"Identity", "State"},
new int[] { R.id.Identity, R.id.State });
accounts.setAdapter((ListAdapter) adapterForList);
sliderContent.addView(accounts);
}
public void registrationStateChanged(final RegistrationState state) {
if (!isAttached)
return;
@ -115,27 +151,48 @@ public class StatusFragment extends Fragment {
mHandler.post(new Runnable() {
@Override
public void run() {
try {
if (state == RegistrationState.RegistrationOk && LinphoneManager.getLc().getDefaultProxyConfig().isRegistered()) {
statusLed.setImageResource(R.drawable.led_connected);
statusText.setText(getString(R.string.status_connected));
} else if (state == RegistrationState.RegistrationProgress) {
statusLed.setImageResource(R.drawable.led_inprogress);
statusText.setText(getString(R.string.status_in_progress));
} else if (state == RegistrationState.RegistrationFailed) {
statusLed.setImageResource(R.drawable.led_error);
statusText.setText(getString(R.string.status_error));
} else {
statusLed.setImageResource(R.drawable.led_disconnected);
statusText.setText(getString(R.string.status_not_connected));
}
} catch (Exception e) {
e.printStackTrace();
}
statusLed.setImageResource(getStatusIconResource(state));
statusText.setText(getStatusIconText(state));
}
});
}
private int getStatusIconResource(LinphoneCore.RegistrationState state) {
try {
if (state == RegistrationState.RegistrationOk && LinphoneManager.getLc().getDefaultProxyConfig().isRegistered()) {
return R.drawable.led_connected;
} else if (state == RegistrationState.RegistrationProgress) {
return R.drawable.led_inprogress;
} else if (state == RegistrationState.RegistrationFailed) {
return R.drawable.led_error;
} else {
return R.drawable.led_disconnected;
}
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
private String getStatusIconText(LinphoneCore.RegistrationState state) {
try {
if (state == RegistrationState.RegistrationOk && LinphoneManager.getLc().getDefaultProxyConfig().isRegistered()) {
return getString(R.string.status_connected);
} else if (state == RegistrationState.RegistrationProgress) {
return getString(R.string.status_in_progress);
} else if (state == RegistrationState.RegistrationFailed) {
return getString(R.string.status_error);
} else {
return getString(R.string.status_not_connected);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private void startCallQuality() {
callQuality.setVisibility(View.VISIBLE);
refreshHandler.postDelayed(mCallQualityUpdater = new Runnable() {