Colored led for account status in preferences
This commit is contained in:
parent
57141d63ad
commit
edf44abd56
6 changed files with 93 additions and 22 deletions
2
README
2
README
|
@ -2,7 +2,7 @@
|
||||||
****************************
|
****************************
|
||||||
|
|
||||||
To build liblinphone for Android, you must:
|
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.
|
1) download the Android ndk (>=r5c) from google.
|
||||||
2) install the autotools: autoconf, automake, aclocal, libtoolize pkgconfig
|
2) install the autotools: autoconf, automake, aclocal, libtoolize pkgconfig
|
||||||
2bis) on some 64 bits systems you'll need the ia32-libs package
|
2bis) on some 64 bits systems you'll need the ia32-libs package
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ImageView
|
<ImageView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/led"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="right|center_vertical"
|
android:layout_gravity="right|center_vertical"
|
||||||
android:src="@drawable/led_connected"
|
android:src="@drawable/led_disconnected"
|
||||||
/>
|
/>
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<ImageView
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="right|center_vertical"
|
|
||||||
android:src="@drawable/led_error"
|
|
||||||
/>
|
|
|
@ -25,13 +25,13 @@
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@id/handle"
|
android:id="@id/handle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="20dp"
|
||||||
android:paddingBottom="10dp">
|
android:layout_marginBottom="10dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/background"
|
android:id="@+id/background"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="20dp"
|
android:layout_height="match_parent"
|
||||||
android:scaleType="fitXY"
|
android:scaleType="fitXY"
|
||||||
android:src="@drawable/statebar_background"/>
|
android:src="@drawable/statebar_background"/>
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
||||||
android:id="@+id/statusLed"
|
android:id="@+id/statusLed"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
android:src="@drawable/led_error"
|
android:src="@drawable/led_error"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@
|
||||||
android:text="@string/status_not_connected"
|
android:text="@string/status_not_connected"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toRightOf="@id/statusLed" />
|
android:layout_toRightOf="@id/statusLed" />
|
||||||
|
@ -63,8 +65,9 @@
|
||||||
android:contentDescription="@string/content_description_call_quality"
|
android:contentDescription="@string/content_description_call_quality"
|
||||||
android:id="@+id/callQuality"
|
android:id="@+id/callQuality"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="20dp"
|
android:layout_height="match_parent"
|
||||||
android:src="@drawable/call_quality_indicator_0"
|
android:src="@drawable/call_quality_indicator_0"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
@ -72,8 +75,9 @@
|
||||||
android:contentDescription="@string/content_description_encryption"
|
android:contentDescription="@string/content_description_encryption"
|
||||||
android:id="@+id/encryption"
|
android:id="@+id/encryption"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="20dp"
|
android:layout_height="match_parent"
|
||||||
android:src="@drawable/security_pending"
|
android:src="@drawable/security_pending"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_alignParentRight="true" />
|
android:layout_alignParentRight="true" />
|
||||||
|
|
||||||
|
@ -81,6 +85,7 @@
|
||||||
android:id="@+id/exit"
|
android:id="@+id/exit"
|
||||||
android:text="@string/menu_exit"
|
android:text="@string/menu_exit"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
|
|
@ -37,11 +37,13 @@ import org.linphone.core.LinphoneCore;
|
||||||
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
||||||
import org.linphone.core.LinphoneCore.MediaEncryption;
|
import org.linphone.core.LinphoneCore.MediaEncryption;
|
||||||
import org.linphone.core.LinphoneCoreException;
|
import org.linphone.core.LinphoneCoreException;
|
||||||
|
import org.linphone.core.LinphoneProxyConfig;
|
||||||
import org.linphone.core.Log;
|
import org.linphone.core.Log;
|
||||||
import org.linphone.mediastream.Version;
|
import org.linphone.mediastream.Version;
|
||||||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||||
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||||
import org.linphone.setup.SetupActivity;
|
import org.linphone.setup.SetupActivity;
|
||||||
|
import org.linphone.ui.LedPreference;
|
||||||
import org.linphone.ui.PreferencesListFragment;
|
import org.linphone.ui.PreferencesListFragment;
|
||||||
|
|
||||||
import android.content.Context;
|
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) {
|
private void addExtraAccountPreferencesButton(PreferenceCategory parent, final int n, boolean isNewAccount) {
|
||||||
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
||||||
if (isNewAccount) {
|
if (isNewAccount) {
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putInt(getString(R.string.pref_extra_accounts), n+1);
|
editor.putInt(getString(R.string.pref_extra_accounts), n+1);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Preference me = new Preference(mContext);
|
final LedPreference me = new LedPreference(mContext);
|
||||||
String keyUsername = getString(R.string.pref_username_key);
|
String keyUsername = getString(R.string.pref_username_key);
|
||||||
String keyDomain = getString(R.string.pref_domain_key);
|
String keyDomain = getString(R.string.pref_domain_key);
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
keyUsername += n + "";
|
keyUsername += n + "";
|
||||||
keyDomain += 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));
|
me.setTitle(getString(R.string.pref_sipaccount));
|
||||||
} else {
|
} else {
|
||||||
me.setTitle(prefs.getString(keyUsername, "") + "@" + prefs.getString(keyDomain, ""));
|
me.setTitle(username + "@" + domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
me.setOnPreferenceClickListener(new OnPreferenceClickListener()
|
me.setOnPreferenceClickListener(new OnPreferenceClickListener()
|
||||||
|
@ -375,11 +380,23 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
updateAccountLed(me, username, domain);
|
||||||
parent.addPreference(me);
|
parent.addPreference(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
private void updateAccountLed(LedPreference me, String username, String domain) {
|
||||||
createDynamicAccountsPreferences();
|
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() {
|
private void addWizardPreferenceButton() {
|
||||||
|
@ -444,6 +461,6 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
createDynamicAccountsPreferences();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
56
src/org/linphone/ui/LedPreference.java
Normal file
56
src/org/linphone/ui/LedPreference.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue