Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
| 32 | package com.savoirfairelinux.sflphone.client; |
| 33 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 34 | import android.app.Activity; |
| 35 | import android.preference.EditTextPreference; |
| 36 | import android.preference.Preference; |
| 37 | import android.preference.PreferenceCategory; |
| 38 | import android.preference.PreferenceFragment; |
| 39 | import android.preference.PreferenceScreen; |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 40 | import android.os.Bundle; |
| 41 | import android.util.Log; |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 42 | import android.view.View; |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 43 | import android.widget.ArrayAdapter; |
| 44 | import android.widget.ListView; |
| 45 | import java.util.HashMap; |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 46 | |
| 47 | import com.savoirfairelinux.sflphone.R; |
| 48 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 49 | public class AccountManagementFragment extends PreferenceFragment |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 50 | { |
| 51 | static final String TAG = "AccountManagementFragment"; |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 52 | static final String CURRENT_VALUE = "Current value:: "; |
| 53 | static final String ALIAS_KEY = "ALIAS"; |
| 54 | static final String HOSTNAME_KEY = "HOSTNAME"; |
| 55 | static final String USERNAME_KEY = "USERNAME"; |
| 56 | static final String PROXY_KEY = "PROXY"; |
| 57 | static final String REGISTRATION_KEY = "REGISTRATION"; |
| 58 | static final String NETWORK_KEY = "NETWORK"; |
| 59 | static final String SECURITY_KEY = "SECURITY"; |
| 60 | static final String TLS_KEY = "TLS"; |
| 61 | static final String SRTP_KEY = "SRTP"; |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 62 | |
| 63 | @Override |
| 64 | public void onCreate(Bundle savedInstanceState) |
| 65 | { |
| 66 | super.onCreate(savedInstanceState); |
| 67 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 68 | Log.i(TAG, "Create Account Management Fragment"); |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 69 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 70 | setPreferenceScreen(getAccountPreferenceScreen()); |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 73 | boolean onTextEditPreferenceChange(Preference preference, Object newValue) |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 74 | { |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 75 | Log.i(TAG, "Account Preference Changed " + preference.getTitle()); |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 76 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 77 | preference.setSummary(CURRENT_VALUE + (CharSequence)newValue); |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | Preference.OnPreferenceChangeListener changeTextEditListener = new Preference.OnPreferenceChangeListener() { |
| 83 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 84 | preference.setSummary(CURRENT_VALUE + (CharSequence)newValue); |
| 85 | return true; |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | |
| 90 | Preference.OnPreferenceClickListener preferenceClick = new Preference.OnPreferenceClickListener() { |
| 91 | public boolean onPreferenceClick(Preference preference) { |
| 92 | return false; |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | HashMap getAccountDetails() |
| 97 | { |
| 98 | HashMap accountDetails = new HashMap(); |
| 99 | |
| 100 | accountDetails.put(ALIAS_KEY, "Test-Account"); |
| 101 | accountDetails.put(HOSTNAME_KEY, "office.srv.com"); |
| 102 | accountDetails.put(USERNAME_KEY, "181"); |
| 103 | accountDetails.put(PROXY_KEY, "none"); |
| 104 | accountDetails.put(REGISTRATION_KEY, "500"); |
| 105 | accountDetails.put(NETWORK_KEY, "eth0"); |
| 106 | accountDetails.put(SECURITY_KEY, "disabled"); |
| 107 | accountDetails.put(TLS_KEY, "disabled"); |
| 108 | accountDetails.put(SRTP_KEY, "disabled"); |
| 109 | |
| 110 | return accountDetails; |
| 111 | } |
| 112 | |
| 113 | public PreferenceScreen getAccountPreferenceScreen() |
| 114 | { |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 115 | Activity currentContext = getActivity(); |
| 116 | HashMap accountDetails = getAccountDetails(); |
| 117 | |
| 118 | PreferenceScreen root = getPreferenceManager().createPreferenceScreen(currentContext); |
| 119 | |
| 120 | // Inline preference |
| 121 | PreferenceCategory accountPrefCat = new PreferenceCategory(currentContext); |
| 122 | accountPrefCat.setTitle(R.string.account_preferences); |
| 123 | root.addPreference(accountPrefCat); |
| 124 | |
| 125 | // Alias |
| 126 | EditTextPreference accountAliasPref = new EditTextPreference(currentContext); |
| 127 | accountAliasPref.setDialogTitle(R.string.dialogtitle_account_alias_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 128 | accountAliasPref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 129 | accountAliasPref.setTitle(R.string.title_account_alias_field); |
| 130 | accountAliasPref.setSummary(CURRENT_VALUE + accountDetails.get(ALIAS_KEY)); |
| 131 | accountAliasPref.setOnPreferenceChangeListener(changeTextEditListener); |
| 132 | accountPrefCat.addPreference(accountAliasPref); |
| 133 | |
| 134 | // Hostname |
| 135 | EditTextPreference accountHostnamePref = new EditTextPreference(currentContext); |
| 136 | accountHostnamePref.setDialogTitle(R.string.dialogtitle_account_hostname_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 137 | accountHostnamePref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 138 | accountHostnamePref.setTitle(R.string.title_account_hostname_field); |
| 139 | accountHostnamePref.setSummary(CURRENT_VALUE + accountDetails.get(HOSTNAME_KEY)); |
| 140 | accountHostnamePref.setOnPreferenceChangeListener(changeTextEditListener); |
| 141 | accountPrefCat.addPreference(accountHostnamePref); |
| 142 | |
| 143 | // Username |
| 144 | EditTextPreference accountUsernamePref = new EditTextPreference(currentContext); |
| 145 | accountUsernamePref.setDialogTitle(R.string.dialogtitle_account_username_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 146 | accountUsernamePref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 147 | accountUsernamePref.setTitle(R.string.title_account_username_field); |
| 148 | accountUsernamePref.setSummary(CURRENT_VALUE + accountDetails.get(USERNAME_KEY)); |
| 149 | accountUsernamePref.setOnPreferenceChangeListener(changeTextEditListener); |
| 150 | accountPrefCat.addPreference(accountUsernamePref); |
| 151 | |
| 152 | // Proxy |
| 153 | EditTextPreference accountProxyPref = new EditTextPreference(currentContext); |
| 154 | accountProxyPref.setDialogTitle(R.string.dialogtitle_account_proxy_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 155 | accountProxyPref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 156 | accountProxyPref.setTitle(R.string.title_account_proxy_field); |
| 157 | accountProxyPref.setSummary(CURRENT_VALUE + accountDetails.get(PROXY_KEY)); |
| 158 | accountProxyPref.setOnPreferenceChangeListener(changeTextEditListener); |
| 159 | accountPrefCat.addPreference(accountProxyPref); |
| 160 | |
| 161 | // Registration Timeout |
| 162 | EditTextPreference accountRegistrationPref = new EditTextPreference(currentContext); |
| 163 | accountRegistrationPref.setDialogTitle(R.string.dialogtitle_account_registration_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 164 | accountRegistrationPref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 165 | accountRegistrationPref.setTitle(R.string.title_account_registration_field); |
| 166 | accountRegistrationPref.setSummary(CURRENT_VALUE + accountDetails.get(REGISTRATION_KEY)); |
| 167 | accountRegistrationPref.setOnPreferenceChangeListener(changeTextEditListener); |
| 168 | accountPrefCat.addPreference(accountRegistrationPref); |
| 169 | |
| 170 | // Netowrk interface |
| 171 | EditTextPreference accountNetworkPref = new EditTextPreference(currentContext); |
| 172 | accountNetworkPref.setDialogTitle(R.string.dialogtitle_account_network_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 173 | accountNetworkPref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 174 | accountNetworkPref.setTitle(R.string.title_account_network_field); |
| 175 | accountNetworkPref.setSummary(CURRENT_VALUE + accountDetails.get(NETWORK_KEY)); |
| 176 | accountNetworkPref.setOnPreferenceChangeListener(changeTextEditListener); |
| 177 | accountPrefCat.addPreference(accountNetworkPref); |
| 178 | |
| 179 | // Account stun server |
| 180 | EditTextPreference accountSecurityPref = new EditTextPreference(currentContext); |
| 181 | accountSecurityPref.setDialogTitle(R.string.dialogtitle_account_security_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 182 | accountSecurityPref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 183 | accountSecurityPref.setTitle(R.string.title_account_security_field); |
| 184 | accountSecurityPref.setSummary(CURRENT_VALUE + accountDetails.get(SECURITY_KEY)); |
| 185 | accountSecurityPref.setOnPreferenceChangeListener(changeTextEditListener); |
| 186 | accountPrefCat.addPreference(accountSecurityPref); |
| 187 | |
| 188 | // Account tls feature |
| 189 | EditTextPreference accountTlsPref = new EditTextPreference(currentContext); |
| 190 | accountTlsPref.setDialogTitle(R.string.dialogtitle_account_tls_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 191 | accountTlsPref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 192 | accountTlsPref.setTitle(R.string.title_account_tls_field); |
| 193 | accountTlsPref.setSummary(CURRENT_VALUE + accountDetails.get(TLS_KEY)); |
| 194 | accountTlsPref.setOnPreferenceChangeListener(changeTextEditListener); |
| 195 | accountPrefCat.addPreference(accountTlsPref); |
| 196 | |
| 197 | // Account srtp feature |
| 198 | EditTextPreference accountSrtpPref = new EditTextPreference(currentContext); |
| 199 | accountSrtpPref.setDialogTitle(R.string.dialogtitle_account_srtp_field); |
Alexandre Savard | 700c194 | 2012-09-11 15:30:38 -0400 | [diff] [blame] | 200 | accountSrtpPref.setPersistent(false); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 201 | accountSrtpPref.setTitle(R.string.title_account_srtp_field); |
| 202 | accountSrtpPref.setSummary(CURRENT_VALUE + accountDetails.get(SRTP_KEY)); |
| 203 | accountSrtpPref.setOnPreferenceChangeListener(changeTextEditListener); |
| 204 | accountPrefCat.addPreference(accountSrtpPref); |
| 205 | |
| 206 | return root; |
| 207 | } |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 208 | } |