From edf44abd565ef0c10e4d7bca7bdece803946cd12 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 4 Sep 2012 09:43:59 +0200 Subject: [PATCH] Colored led for account status in preferences --- README | 2 +- ...e_led_connected.xml => preference_led.xml} | 3 +- res/layout/preference_led_not_connected.xml | 8 --- res/layout/status.xml | 15 +++-- src/org/linphone/PreferencesFragment.java | 31 +++++++--- src/org/linphone/ui/LedPreference.java | 56 +++++++++++++++++++ 6 files changed, 93 insertions(+), 22 deletions(-) rename res/layout/{preference_led_connected.xml => preference_led.xml} (77%) delete mode 100644 res/layout/preference_led_not_connected.xml create mode 100644 src/org/linphone/ui/LedPreference.java diff --git a/README b/README index 8dc002a29..863baf2ae 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ **************************** To build liblinphone for Android, you must: -0) download the Android sdk with platform-tools >= 13, tools >= 20 and sdk platform >= 16 +0) download the Android sdk with platform-tools >= 13, tools >= 20 (20.0.3 for linux) and sdk platform >= 16 1) download the Android ndk (>=r5c) from google. 2) install the autotools: autoconf, automake, aclocal, libtoolize pkgconfig 2bis) on some 64 bits systems you'll need the ia32-libs package diff --git a/res/layout/preference_led_connected.xml b/res/layout/preference_led.xml similarity index 77% rename from res/layout/preference_led_connected.xml rename to res/layout/preference_led.xml index 3223c046b..d8a542a2d 100644 --- a/res/layout/preference_led_connected.xml +++ b/res/layout/preference_led.xml @@ -1,8 +1,9 @@ \ No newline at end of file diff --git a/res/layout/preference_led_not_connected.xml b/res/layout/preference_led_not_connected.xml deleted file mode 100644 index 8403e1564..000000000 --- a/res/layout/preference_led_not_connected.xml +++ /dev/null @@ -1,8 +0,0 @@ - - \ No newline at end of file diff --git a/res/layout/status.xml b/res/layout/status.xml index fe006a037..34bee476e 100644 --- a/res/layout/status.xml +++ b/res/layout/status.xml @@ -25,13 +25,13 @@ + android:layout_height="20dp" + android:layout_marginBottom="10dp"> @@ -40,6 +40,7 @@ android:id="@+id/statusLed" android:paddingLeft="5dp" android:src="@drawable/led_error" + android:adjustViewBounds="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> @@ -48,6 +49,7 @@ android:text="@string/status_not_connected" android:textColor="@android:color/white" android:paddingLeft="5dp" + android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/statusLed" /> @@ -63,8 +65,9 @@ android:contentDescription="@string/content_description_call_quality" android:id="@+id/callQuality" android:layout_width="wrap_content" - android:layout_height="20dp" + android:layout_height="match_parent" android:src="@drawable/call_quality_indicator_0" + android:adjustViewBounds="true" android:layout_centerHorizontal="true" android:visibility="gone" /> @@ -72,8 +75,9 @@ android:contentDescription="@string/content_description_encryption" android:id="@+id/encryption" android:layout_width="wrap_content" - android:layout_height="20dp" + android:layout_height="match_parent" android:src="@drawable/security_pending" + android:adjustViewBounds="true" android:visibility="gone" android:layout_alignParentRight="true" /> @@ -81,6 +85,7 @@ android:id="@+id/exit" android:text="@string/menu_exit" android:textColor="@android:color/white" + android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" diff --git a/src/org/linphone/PreferencesFragment.java b/src/org/linphone/PreferencesFragment.java index a7f2dda13..c837903f9 100644 --- a/src/org/linphone/PreferencesFragment.java +++ b/src/org/linphone/PreferencesFragment.java @@ -37,11 +37,13 @@ import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore.EcCalibratorStatus; import org.linphone.core.LinphoneCore.MediaEncryption; import org.linphone.core.LinphoneCoreException; +import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.Log; import org.linphone.mediastream.Version; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.Hacks; import org.linphone.setup.SetupActivity; +import org.linphone.ui.LedPreference; import org.linphone.ui.PreferencesListFragment; import android.content.Context; @@ -347,24 +349,27 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa } private void addExtraAccountPreferencesButton(PreferenceCategory parent, final int n, boolean isNewAccount) { - final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); + SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); if (isNewAccount) { SharedPreferences.Editor editor = prefs.edit(); editor.putInt(getString(R.string.pref_extra_accounts), n+1); editor.commit(); } - final Preference me = new Preference(mContext); + final LedPreference me = new LedPreference(mContext); String keyUsername = getString(R.string.pref_username_key); String keyDomain = getString(R.string.pref_domain_key); if (n > 0) { keyUsername += n + ""; keyDomain += n + ""; } - if (prefs.getString(keyUsername, null) == null) { + + String username = prefs.getString(keyUsername, ""); + String domain = prefs.getString(keyDomain, ""); + if (username == null) { me.setTitle(getString(R.string.pref_sipaccount)); } else { - me.setTitle(prefs.getString(keyUsername, "") + "@" + prefs.getString(keyDomain, "")); + me.setTitle(username + "@" + domain); } me.setOnPreferenceClickListener(new OnPreferenceClickListener() @@ -375,11 +380,23 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa } }); + updateAccountLed(me, username, domain); parent.addPreference(me); } - public void refresh() { - createDynamicAccountsPreferences(); + private void updateAccountLed(LedPreference me, String username, String domain) { + for (LinphoneProxyConfig lpc : LinphoneManager.getLc().getProxyConfigList()) { + if (lpc.getIdentity().contains(username) && lpc.getIdentity().contains(domain)) { + if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationOk) { + me.setLed(R.drawable.led_connected); + } else if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationFailed) { + me.setLed(R.drawable.led_error); + } else { + me.setLed(R.drawable.led_disconnected); + } + break; + } + } } private void addWizardPreferenceButton() { @@ -444,6 +461,6 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS); } - refresh(); + createDynamicAccountsPreferences(); } } diff --git a/src/org/linphone/ui/LedPreference.java b/src/org/linphone/ui/LedPreference.java new file mode 100644 index 000000000..8962b0547 --- /dev/null +++ b/src/org/linphone/ui/LedPreference.java @@ -0,0 +1,56 @@ +package org.linphone.ui; + +/* +LedPreference.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. +*/ + +import org.linphone.R; + +import android.content.Context; +import android.preference.Preference; +import android.view.View; +import android.widget.ImageView; + +/** + * @author Sylvain Berfini + */ +public class LedPreference extends Preference +{ + private int ledDrawable; + + public LedPreference(Context context) { + super(context); + ledDrawable = R.drawable.led_disconnected; + this.setWidgetLayoutResource(R.layout.preference_led); + } + + @Override + protected void onBindView(final View view) { + super.onBindView(view); + + final ImageView imageView = (ImageView) view.findViewById(R.id.led); + if (imageView != null) { + imageView.setImageResource(ledDrawable); + } + } + + public void setLed(int led) { + ledDrawable = led; + notifyChanged(); + } +}