blob: 9dfd3c9c7874db5fa5ae797c0caf557d5ba01356 [file] [log] [blame]
Alexandre Savard2b370f02012-09-06 16:06:01 -04001/*
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
32package com.savoirfairelinux.sflphone.client;
33
Alexandre Savard9a93f062012-09-11 10:42:43 -040034import android.app.Activity;
35import android.preference.EditTextPreference;
36import android.preference.Preference;
37import android.preference.PreferenceCategory;
38import android.preference.PreferenceFragment;
39import android.preference.PreferenceScreen;
Alexandre Savard70982012012-09-27 17:15:50 -040040import android.preference.ListPreference;
Alexandre Savard2b370f02012-09-06 16:06:01 -040041import android.os.Bundle;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040042import android.os.RemoteException;
Alexandre Savard2b370f02012-09-06 16:06:01 -040043import android.util.Log;
Alexandre Savard2b370f02012-09-06 16:06:01 -040044import android.view.View;
Alexandre Savard9a93f062012-09-11 10:42:43 -040045import android.widget.ArrayAdapter;
46import android.widget.ListView;
47import java.util.HashMap;
Alexandre Savard52a72522012-09-27 16:40:13 -040048import java.util.ArrayList;
Alexandre Savard2b370f02012-09-06 16:06:01 -040049
50import com.savoirfairelinux.sflphone.R;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040051import com.savoirfairelinux.sflphone.service.ISipService;
52import com.savoirfairelinux.sflphone.service.SipService;
53import com.savoirfairelinux.sflphone.service.ServiceConstants;
Alexandre Savard2b370f02012-09-06 16:06:01 -040054
Alexandre Savard9a93f062012-09-11 10:42:43 -040055public class AccountManagementFragment extends PreferenceFragment
Alexandre Savard2b370f02012-09-06 16:06:01 -040056{
57 static final String TAG = "AccountManagementFragment";
Alexandre Savarda6c0d992012-09-28 09:24:13 -040058 static final String CURRENT_VALUE = "Current value:: ";
59 static final String DEFAULT_ACCOUNT_ID = "IP2IP";
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040060 private ISipService service;
Alexandre Savarda6c0d992012-09-28 09:24:13 -040061 HashMap<String, String> mAccountDetails = null;
Alexandre Savard70982012012-09-27 17:15:50 -040062 ArrayList<String> mAccountList = null;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040063
64 public AccountManagementFragment(ISipService s)
65 {
66 service = s;
67 }
Alexandre Savard2b370f02012-09-06 16:06:01 -040068
69 @Override
70 public void onCreate(Bundle savedInstanceState)
71 {
72 super.onCreate(savedInstanceState);
73
Alexandre Savard9a93f062012-09-11 10:42:43 -040074 Log.i(TAG, "Create Account Management Fragment");
Alexandre Savard2b370f02012-09-06 16:06:01 -040075
Alexandre Savard70982012012-09-27 17:15:50 -040076 // setPreferenceScreen(getAccountPreferenceScreen());
77 setPreferenceScreen(getAccountListPreferenceScreen());
Alexandre Savard2b370f02012-09-06 16:06:01 -040078 }
79
Alexandre Savard9a93f062012-09-11 10:42:43 -040080 boolean onTextEditPreferenceChange(Preference preference, Object newValue)
Alexandre Savard2b370f02012-09-06 16:06:01 -040081 {
Alexandre Savard9a93f062012-09-11 10:42:43 -040082 Log.i(TAG, "Account Preference Changed " + preference.getTitle());
Alexandre Savard2b370f02012-09-06 16:06:01 -040083
Alexandre Savard9a93f062012-09-11 10:42:43 -040084 preference.setSummary(CURRENT_VALUE + (CharSequence)newValue);
85
86 return true;
87 }
88
89 Preference.OnPreferenceChangeListener changeTextEditListener = new Preference.OnPreferenceChangeListener() {
90 public boolean onPreferenceChange(Preference preference, Object newValue) {
91 preference.setSummary(CURRENT_VALUE + (CharSequence)newValue);
92 return true;
93 }
94 };
95
96
97 Preference.OnPreferenceClickListener preferenceClick = new Preference.OnPreferenceClickListener() {
98 public boolean onPreferenceClick(Preference preference) {
99 return false;
100 }
101 };
102
Alexandre Savard52a72522012-09-27 16:40:13 -0400103 ArrayList<String> getAccountList()
104 {
105 ArrayList<String> accountList = null;
106 try {
107 accountList = (ArrayList) service.getAccountList();
108 } catch (RemoteException e) {
109 Log.e(TAG, "Cannot call service method", e);
110 }
111
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400112 // Remove the default account from list
113 accountList.remove(DEFAULT_ACCOUNT_ID);
114
Alexandre Savard52a72522012-09-27 16:40:13 -0400115 return accountList;
116 }
117
Alexandre Savard70982012012-09-27 17:15:50 -0400118 HashMap getAccountDetails(String accountID)
Alexandre Savard9a93f062012-09-11 10:42:43 -0400119 {
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400120 HashMap accountDetails = null;
121 try {
Alexandre Savard70982012012-09-27 17:15:50 -0400122 accountDetails = (HashMap) service.getAccountDetails(accountID);
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400123 } catch (RemoteException e) {
124 Log.e(TAG, "Cannot call service method", e);
125 }
Alexandre Savard9a93f062012-09-11 10:42:43 -0400126
127 return accountDetails;
128 }
129
Alexandre Savard70982012012-09-27 17:15:50 -0400130 public PreferenceScreen getAccountListPreferenceScreen()
Alexandre Savard9a93f062012-09-11 10:42:43 -0400131 {
Alexandre Savard9a93f062012-09-11 10:42:43 -0400132 Activity currentContext = getActivity();
Alexandre Savard52a72522012-09-27 16:40:13 -0400133
134 mAccountList = getAccountList();
135 Log.i(TAG, "GetAccountList: " + mAccountList);
136
Alexandre Savard70982012012-09-27 17:15:50 -0400137 PreferenceScreen root = getPreferenceManager().createPreferenceScreen(currentContext);
138
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400139 // Default account category
Alexandre Savard70982012012-09-27 17:15:50 -0400140 PreferenceCategory defaultAccountCat = new PreferenceCategory(currentContext);
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400141 defaultAccountCat.setTitle(R.string.default_account_category);
Alexandre Savard70982012012-09-27 17:15:50 -0400142 root.addPreference(defaultAccountCat);
143
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400144 root.addPreference(getAccountPreferenceScreen(DEFAULT_ACCOUNT_ID));
Alexandre Savard70982012012-09-27 17:15:50 -0400145
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400146 // Account list category
Alexandre Savard70982012012-09-27 17:15:50 -0400147 PreferenceCategory accountListCat = new PreferenceCategory(currentContext);
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400148 accountListCat.setTitle(R.string.default_account_category);
Alexandre Savard70982012012-09-27 17:15:50 -0400149 root.addPreference(accountListCat);
150
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400151 for(String s : mAccountList)
152 root.addPreference(getAccountPreferenceScreen(s));
Alexandre Savard70982012012-09-27 17:15:50 -0400153
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400154 return root;
Alexandre Savard70982012012-09-27 17:15:50 -0400155 }
156
157 public PreferenceScreen getAccountPreferenceScreen(String accountID)
158 {
159 Activity currentContext = getActivity();
160
161 mAccountDetails = getAccountDetails(accountID);
Alexandre Savard52a72522012-09-27 16:40:13 -0400162 Log.i(TAG, "GetAccountDetails: " + mAccountDetails.size());
Alexandre Savard9a93f062012-09-11 10:42:43 -0400163
164 PreferenceScreen root = getPreferenceManager().createPreferenceScreen(currentContext);
165
Alexandre Savarda6c0d992012-09-28 09:24:13 -0400166 root.setTitle(mAccountDetails.get(ServiceConstants.CONFIG_ACCOUNT_ALIAS));
Alexandre Savard70982012012-09-27 17:15:50 -0400167
Alexandre Savard9a93f062012-09-11 10:42:43 -0400168 // Inline preference
169 PreferenceCategory accountPrefCat = new PreferenceCategory(currentContext);
170 accountPrefCat.setTitle(R.string.account_preferences);
171 root.addPreference(accountPrefCat);
172
173 // Alias
174 EditTextPreference accountAliasPref = new EditTextPreference(currentContext);
175 accountAliasPref.setDialogTitle(R.string.dialogtitle_account_alias_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400176 accountAliasPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400177 accountAliasPref.setTitle(R.string.title_account_alias_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400178 accountAliasPref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_ACCOUNT_ALIAS));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400179 accountAliasPref.setOnPreferenceChangeListener(changeTextEditListener);
180 accountPrefCat.addPreference(accountAliasPref);
181
182 // Hostname
183 EditTextPreference accountHostnamePref = new EditTextPreference(currentContext);
184 accountHostnamePref.setDialogTitle(R.string.dialogtitle_account_hostname_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400185 accountHostnamePref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400186 accountHostnamePref.setTitle(R.string.title_account_hostname_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400187 accountHostnamePref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_ACCOUNT_HOSTNAME));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400188 accountHostnamePref.setOnPreferenceChangeListener(changeTextEditListener);
189 accountPrefCat.addPreference(accountHostnamePref);
190
191 // Username
192 EditTextPreference accountUsernamePref = new EditTextPreference(currentContext);
193 accountUsernamePref.setDialogTitle(R.string.dialogtitle_account_username_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400194 accountUsernamePref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400195 accountUsernamePref.setTitle(R.string.title_account_username_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400196 accountUsernamePref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_ACCOUNT_USERNAME));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400197 accountUsernamePref.setOnPreferenceChangeListener(changeTextEditListener);
198 accountPrefCat.addPreference(accountUsernamePref);
199
200 // Proxy
201 EditTextPreference accountProxyPref = new EditTextPreference(currentContext);
202 accountProxyPref.setDialogTitle(R.string.dialogtitle_account_proxy_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400203 accountProxyPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400204 accountProxyPref.setTitle(R.string.title_account_proxy_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400205 accountProxyPref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_ACCOUNT_ROUTESET));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400206 accountProxyPref.setOnPreferenceChangeListener(changeTextEditListener);
207 accountPrefCat.addPreference(accountProxyPref);
208
209 // Registration Timeout
210 EditTextPreference accountRegistrationPref = new EditTextPreference(currentContext);
211 accountRegistrationPref.setDialogTitle(R.string.dialogtitle_account_registration_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400212 accountRegistrationPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400213 accountRegistrationPref.setTitle(R.string.title_account_registration_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400214 accountRegistrationPref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_ACCOUNT_REGISTRATION_EXPIRE));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400215 accountRegistrationPref.setOnPreferenceChangeListener(changeTextEditListener);
216 accountPrefCat.addPreference(accountRegistrationPref);
217
218 // Netowrk interface
219 EditTextPreference accountNetworkPref = new EditTextPreference(currentContext);
220 accountNetworkPref.setDialogTitle(R.string.dialogtitle_account_network_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400221 accountNetworkPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400222 accountNetworkPref.setTitle(R.string.title_account_network_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400223 accountNetworkPref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_LOCAL_INTERFACE));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400224 accountNetworkPref.setOnPreferenceChangeListener(changeTextEditListener);
225 accountPrefCat.addPreference(accountNetworkPref);
226
227 // Account stun server
228 EditTextPreference accountSecurityPref = new EditTextPreference(currentContext);
229 accountSecurityPref.setDialogTitle(R.string.dialogtitle_account_security_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400230 accountSecurityPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400231 accountSecurityPref.setTitle(R.string.title_account_security_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400232 accountSecurityPref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_STUN_SERVER));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400233 accountSecurityPref.setOnPreferenceChangeListener(changeTextEditListener);
234 accountPrefCat.addPreference(accountSecurityPref);
235
236 // Account tls feature
237 EditTextPreference accountTlsPref = new EditTextPreference(currentContext);
238 accountTlsPref.setDialogTitle(R.string.dialogtitle_account_tls_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400239 accountTlsPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400240 accountTlsPref.setTitle(R.string.title_account_tls_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400241 accountTlsPref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_TLS_ENABLE));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400242 accountTlsPref.setOnPreferenceChangeListener(changeTextEditListener);
243 accountPrefCat.addPreference(accountTlsPref);
244
245 // Account srtp feature
246 EditTextPreference accountSrtpPref = new EditTextPreference(currentContext);
247 accountSrtpPref.setDialogTitle(R.string.dialogtitle_account_srtp_field);
Alexandre Savard700c1942012-09-11 15:30:38 -0400248 accountSrtpPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400249 accountSrtpPref.setTitle(R.string.title_account_srtp_field);
Alexandre Savard52a72522012-09-27 16:40:13 -0400250 accountSrtpPref.setSummary(CURRENT_VALUE + mAccountDetails.get(ServiceConstants.CONFIG_SRTP_ENABLE));
Alexandre Savard9a93f062012-09-11 10:42:43 -0400251 accountSrtpPref.setOnPreferenceChangeListener(changeTextEditListener);
252 accountPrefCat.addPreference(accountSrtpPref);
253
254 return root;
255 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400256}