From fbe393d3d3c888572524cd75125f154ad3fba6a3 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 9 Aug 2012 15:46:41 +0200 Subject: [PATCH] Improved settings for API > 14 + some changes on History new list --- res/drawable/list_selector.xml | 7 + res/layout/chat.xml | 1 + res/layout/chatlist.xml | 1 + res/layout/contact.xml | 3 +- res/layout/contacts_list.xml | 1 + res/layout/history.xml | 1 + res/layout/settings.xml | 2 + res/values/color.xml | 3 + res/values/non_localizable_strings.xml | 2 + res/values/strings.xml | 5 +- res/xml-v14/account_preferences.xml | 57 +++ res/xml-v14/preferences.xml | 331 ++++++++++++++++++ res/xml/account_preferences.xml | 47 ++- res/xml/preferences.xml | 18 +- .../linphone/AccountPreferencesActivity.java | 86 ++--- src/org/linphone/HistoryFragment.java | 22 +- src/org/linphone/StatusFragment.java | 2 +- .../linphone/compatibility/ApiFivePlus.java | 10 + .../compatibility/ApiFourteenPlus.java | 38 ++ .../linphone/compatibility/Compatibility.java | 17 + 20 files changed, 554 insertions(+), 100 deletions(-) create mode 100644 res/drawable/list_selector.xml create mode 100644 res/xml-v14/account_preferences.xml create mode 100644 res/xml-v14/preferences.xml create mode 100644 src/org/linphone/compatibility/ApiFourteenPlus.java diff --git a/res/drawable/list_selector.xml b/res/drawable/list_selector.xml new file mode 100644 index 000000000..6d70448b8 --- /dev/null +++ b/res/drawable/list_selector.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/res/layout/chat.xml b/res/layout/chat.xml index 4656fbee6..cdbc226b4 100644 --- a/res/layout/chat.xml +++ b/res/layout/chat.xml @@ -75,4 +75,5 @@ android:src="@drawable/chat_send_message" /> + \ No newline at end of file diff --git a/res/layout/chatlist.xml b/res/layout/chatlist.xml index 103f35762..c671c3a91 100644 --- a/res/layout/chatlist.xml +++ b/res/layout/chatlist.xml @@ -45,6 +45,7 @@ - + android:paddingTop="20dp"/> diff --git a/res/layout/contacts_list.xml b/res/layout/contacts_list.xml index 1495c7b85..b916fed57 100644 --- a/res/layout/contacts_list.xml +++ b/res/layout/contacts_list.xml @@ -48,6 +48,7 @@ diff --git a/res/values/color.xml b/res/values/color.xml index 7dd30f03e..54f5cbd7d 100644 --- a/res/values/color.xml +++ b/res/values/color.xml @@ -1,8 +1,11 @@ + #ffcf4c29 + #ffe4edf2 #ffd8d8d8 #ffb1bdc3 #ffcf4c29 + #00000000 \ No newline at end of file diff --git a/res/values/non_localizable_strings.xml b/res/values/non_localizable_strings.xml index 2e422e260..c427191b4 100644 --- a/res/values/non_localizable_strings.xml +++ b/res/values/non_localizable_strings.xml @@ -3,6 +3,8 @@ pref_disable_account_key + pref_nb_accounts_extra + pref_default_account pref_tunnel_key pref_tunnel_mode_key diff --git a/res/values/strings.xml b/res/values/strings.xml index 2e5d66e9f..736abc9d5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -117,7 +117,7 @@ Filter contacts %s\'s phone numbers Delete this account - Use as default + Use as default Echo canceller calibration Echo limiter Use front camera @@ -235,10 +235,7 @@ Accept video Deny video - pref_nb_accounts_extra - pref_default_account SIP Accounts - Use wifi only Use bluetooth headset Route incoming audio to bluetooth headset if available. diff --git a/res/xml-v14/account_preferences.xml b/res/xml-v14/account_preferences.xml new file mode 100644 index 000000000..756ad37f2 --- /dev/null +++ b/res/xml-v14/account_preferences.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml-v14/preferences.xml b/res/xml-v14/preferences.xml new file mode 100644 index 000000000..1c34388fb --- /dev/null +++ b/res/xml-v14/preferences.xml @@ -0,0 +1,331 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/account_preferences.xml b/res/xml/account_preferences.xml index 7bf2aa65d..bc09b9d3e 100644 --- a/res/xml/account_preferences.xml +++ b/res/xml/account_preferences.xml @@ -1,4 +1,49 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 260602314..a9a4ff37b 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -3,23 +3,7 @@ - - - + diff --git a/src/org/linphone/AccountPreferencesActivity.java b/src/org/linphone/AccountPreferencesActivity.java index 19be0a4ce..9583c525b 100644 --- a/src/org/linphone/AccountPreferencesActivity.java +++ b/src/org/linphone/AccountPreferencesActivity.java @@ -18,9 +18,10 @@ 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.compatibility.Compatibility; + import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; @@ -41,7 +42,7 @@ public class AccountPreferencesActivity extends LinphonePreferencesActivity { PreferenceScreen screen = getPreferenceScreen(); int n = getIntent().getExtras().getInt("Account", 1); - addExtraAccountPreferencesFields(screen, n); + manageAccountPreferencesFields(screen, n); } OnPreferenceChangeListener preferenceChangedListener = new OnPreferenceChangeListener() { @@ -52,50 +53,48 @@ public class AccountPreferencesActivity extends LinphonePreferencesActivity { } }; - private void addExtraAccountPreferencesFields(PreferenceScreen parent, final int n) { + private void manageAccountPreferencesFields(PreferenceScreen parent, final int n) { final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); - EditTextPreference username = new EditTextPreference(this); + PreferenceCategory account = (PreferenceCategory) getPreferenceScreen().getPreference(0); + EditTextPreference username = (EditTextPreference) account.getPreference(0); + username.setText(prefs.getString(getString(R.string.pref_username_key) + getAccountNumber(n), "")); username.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - username.setTitle(getString(R.string.pref_username)); - username.setPersistent(true); - username.setDialogMessage(getString(R.string.pref_help_username)); username.setKey(getString(R.string.pref_username_key) + getAccountNumber(n)); username.setOnPreferenceChangeListener(preferenceChangedListener); + username.setSummary(username.getText()); - EditTextPreference password = new EditTextPreference(this); + EditTextPreference password = (EditTextPreference) account.getPreference(1); + password.setText(prefs.getString(getString(R.string.pref_passwd_key) + getAccountNumber(n), "")); password.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - password.setTitle(getString(R.string.pref_passwd)); - password.setPersistent(true); password.setKey(getString(R.string.pref_passwd_key) + getAccountNumber(n)); - EditTextPreference domain = new EditTextPreference(this); + EditTextPreference domain = (EditTextPreference) account.getPreference(2); + domain.setText(prefs.getString(getString(R.string.pref_domain_key) + getAccountNumber(n), "")); domain.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - domain.setTitle(getString(R.string.pref_domain)); - domain.setPersistent(true); - domain.setDialogMessage(getString(R.string.pref_help_domain)); domain.setKey(getString(R.string.pref_domain_key) + getAccountNumber(n)); domain.setOnPreferenceChangeListener(preferenceChangedListener); - - EditTextPreference proxy = new EditTextPreference(this); + domain.setSummary(domain.getText()); + + PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen().getPreference(1); + EditTextPreference proxy = (EditTextPreference) advanced.getPreference(0); + proxy.setText(prefs.getString(getString(R.string.pref_proxy_key) + getAccountNumber(n), "")); proxy.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - proxy.setTitle(getString(R.string.pref_proxy)); - proxy.setPersistent(true); proxy.setKey(getString(R.string.pref_proxy_key) + getAccountNumber(n)); proxy.setOnPreferenceChangeListener(preferenceChangedListener); + proxy.setSummary("".equals(proxy.getText()) || (proxy.getText() == null) ? getString(R.string.pref_help_proxy) : proxy.getText()); - CheckBoxPreference outboundProxy = new CheckBoxPreference(this); - outboundProxy.setTitle(getString(R.string.pref_enable_outbound_proxy)); - outboundProxy.setPersistent(true); + Preference outboundProxy = advanced.getPreference(1); + Compatibility.setPreferenceChecked(outboundProxy, prefs.getBoolean(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(n), false)); outboundProxy.setKey(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(n)); - final CheckBoxPreference disable = new CheckBoxPreference(this); - disable.setTitle(getString(R.string.pref_disable_account)); - disable.setPersistent(true); + final Preference disable = advanced.getPreference(2); + disable.setEnabled(prefs.getInt(getString(R.string.pref_default_account), 0) != n); + Compatibility.setPreferenceChecked(outboundProxy, prefs.getBoolean(getString(R.string.pref_disable_account_key) + getAccountNumber(n), false)); disable.setKey(getString(R.string.pref_disable_account_key) + getAccountNumber(n)); - final Preference delete = new Preference(this); - delete.setTitle(R.string.pref_delete_account); + final Preference delete = advanced.getPreference(4); + delete.setEnabled(prefs.getInt(getString(R.string.pref_default_account), 0) != n); delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 1); @@ -130,48 +129,23 @@ public class AccountPreferencesActivity extends LinphonePreferencesActivity { } }); - CheckBoxPreference mainAccount = new CheckBoxPreference(this); - mainAccount.setTitle(R.string.pref_default_account_title); + Preference mainAccount = advanced.getPreference(3); + Compatibility.setPreferenceChecked(mainAccount, prefs.getInt(getString(R.string.pref_default_account), 0) == n); + mainAccount.setEnabled(!Compatibility.isPreferenceChecked(mainAccount)); mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(getString(R.string.pref_default_account), n); + editor.putInt(getString(R.string.pref_default_account_key), n); editor.commit(); delete.setEnabled(false); disable.setEnabled(false); - disable.setChecked(false); + Compatibility.setPreferenceChecked(disable, false); preference.setEnabled(false); return true; } }); - - mainAccount.setChecked(prefs.getInt(getString(R.string.pref_default_account), 0) == n); - mainAccount.setEnabled(!mainAccount.isChecked()); - delete.setEnabled(prefs.getInt(getString(R.string.pref_default_account), 0) != n); - disable.setEnabled(prefs.getInt(getString(R.string.pref_default_account), 0) != n); - - PreferenceCategory category = new PreferenceCategory(this); - category.setTitle(getString(R.string.pref_sipaccount)); - parent.addPreference(category); - category.addPreference(username); - category.addPreference(password); - category.addPreference(domain); - - category = new PreferenceCategory(this); - category.setTitle(getString(R.string.pref_advanced)); - parent.addPreference(category); - category.addPreference(proxy); - category.addPreference(outboundProxy); - category.addPreference(disable); - category.addPreference(mainAccount); - category.addPreference(delete); - - username.setSummary(username.getText()); - domain.setSummary(domain.getText()); - proxy.setSummary("".equals(proxy.getText()) || (proxy.getText() == null) ? getString(R.string.pref_help_proxy) : proxy.getText()); - outboundProxy.setSummary(getString(R.string.pref_help_outbound_proxy)); } private String getAccountNumber(int n) { diff --git a/src/org/linphone/HistoryFragment.java b/src/org/linphone/HistoryFragment.java index 153018387..101b63dc1 100644 --- a/src/org/linphone/HistoryFragment.java +++ b/src/org/linphone/HistoryFragment.java @@ -87,9 +87,9 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil if (LinphoneActivity.isInstanciated()) LinphoneActivity.instance().selectMenu(FragmentsAvailable.HISTORY); - List logs = Arrays.asList(LinphoneManager.getLc().getCallLogs()); - initLogsLists(logs); + initLogsLists(Arrays.asList(LinphoneManager.getLc().getCallLogs())); historyList.setAdapter(new CallHistoryAdapter(getActivity())); + expandAllGroups(); } private void initLogsLists(List logs) { @@ -131,19 +131,6 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil } } - private void collapseAllGroups() { - mHandler.post(new Runnable() { - @Override - public void run() { - for (int groupToCollapse = 0; groupToCollapse < historyList.getExpandableListAdapter().getGroupCount(); groupToCollapse++) { - if (historyList.isGroupExpanded(groupToCollapse)) { - historyList.collapseGroup(groupToCollapse); - } - } - } - }); - } - private void expandAllGroups() { mHandler.post(new Runnable() { @Override @@ -216,10 +203,7 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil } historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext())); - if (id == R.id.ok) { - collapseAllGroups(); - } - else if (id == R.id.edit) { + if (id != R.id.ok) { expandAllGroups(); } } diff --git a/src/org/linphone/StatusFragment.java b/src/org/linphone/StatusFragment.java index cc05b4d16..ab7db254e 100644 --- a/src/org/linphone/StatusFragment.java +++ b/src/org/linphone/StatusFragment.java @@ -382,7 +382,7 @@ public class StatusFragment extends Fragment { ImageView status = (ImageView) view.findViewById(R.id.State); TextView identity = (TextView) view.findViewById(R.id.Identity); - String sipAddress = lpc.getIdentity().startsWith("sip:") ? lpc.getIdentity().split("sip:")[1] : lpc.getIdentity(); + String sipAddress = (lpc.getIdentity() != null && lpc.getIdentity().startsWith("sip:")) ? lpc.getIdentity().split("sip:")[1] : lpc.getIdentity(); identity.setText(sipAddress); CheckBox isDefault = (CheckBox) view.findViewById(R.id.Default); diff --git a/src/org/linphone/compatibility/ApiFivePlus.java b/src/org/linphone/compatibility/ApiFivePlus.java index a93eefc0e..251143ae4 100644 --- a/src/org/linphone/compatibility/ApiFivePlus.java +++ b/src/org/linphone/compatibility/ApiFivePlus.java @@ -24,6 +24,8 @@ import android.database.Cursor; import android.database.MatrixCursor; import android.graphics.BitmapFactory; import android.net.Uri; +import android.preference.CheckBoxPreference; +import android.preference.Preference; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.CommonDataKinds.Phone; @@ -343,4 +345,12 @@ public class ApiFivePlus { public static void setNotificationLatestEventInfo(Notification notif, Context context, String title, String content, PendingIntent intent) { notif.setLatestEventInfo(context, title, content, intent); } + + public static void setPreferenceChecked(Preference preference, boolean checked) { + ((CheckBoxPreference) preference).setChecked(checked); + } + + public static boolean isPreferenceChecked(Preference preference) { + return ((CheckBoxPreference) preference).isChecked(); + } } diff --git a/src/org/linphone/compatibility/ApiFourteenPlus.java b/src/org/linphone/compatibility/ApiFourteenPlus.java new file mode 100644 index 000000000..3e1629f44 --- /dev/null +++ b/src/org/linphone/compatibility/ApiFourteenPlus.java @@ -0,0 +1,38 @@ +package org.linphone.compatibility; + +import android.annotation.TargetApi; +import android.preference.Preference; +import android.preference.SwitchPreference; + +/* +ApiFourteenPlus.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. +*/ +/** + * @author Sylvain Berfini + */ +@TargetApi(8) +public class ApiFourteenPlus { + + public static void setPreferenceChecked(Preference preference, boolean checked) { + ((SwitchPreference) preference).setChecked(checked); + } + + public static boolean isPreferenceChecked(Preference preference) { + return ((SwitchPreference) preference).isChecked(); + } +} diff --git a/src/org/linphone/compatibility/Compatibility.java b/src/org/linphone/compatibility/Compatibility.java index 5ee014e2d..55bc559b0 100644 --- a/src/org/linphone/compatibility/Compatibility.java +++ b/src/org/linphone/compatibility/Compatibility.java @@ -34,6 +34,7 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.media.AudioManager; import android.net.Uri; +import android.preference.Preference; import android.view.Display; /** * @author Sylvain Berfini @@ -185,4 +186,20 @@ public class Compatibility { } return false; } + + public static void setPreferenceChecked(Preference preference, boolean checked) { + if (Version.sdkAboveOrEqual(8)) { + ApiFourteenPlus.setPreferenceChecked(preference, checked); + } else { + ApiFivePlus.setPreferenceChecked(preference, checked); + } + } + + public static boolean isPreferenceChecked(Preference preference) { + if (Version.sdkAboveOrEqual(8)) { + return ApiFourteenPlus.isPreferenceChecked(preference); + } else { + return ApiFivePlus.isPreferenceChecked(preference); + } + } }