blob: 68d765bc31a32692b73d34bc0a7c2cacfe351218 [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 Savard2b370f02012-09-06 16:06:01 -040040import android.os.Bundle;
41import android.util.Log;
Alexandre Savard2b370f02012-09-06 16:06:01 -040042import android.view.View;
Alexandre Savard9a93f062012-09-11 10:42:43 -040043import android.widget.ArrayAdapter;
44import android.widget.ListView;
45import java.util.HashMap;
Alexandre Savard2b370f02012-09-06 16:06:01 -040046
47import com.savoirfairelinux.sflphone.R;
48
Alexandre Savard9a93f062012-09-11 10:42:43 -040049public class AccountManagementFragment extends PreferenceFragment
Alexandre Savard2b370f02012-09-06 16:06:01 -040050{
51 static final String TAG = "AccountManagementFragment";
Alexandre Savard9a93f062012-09-11 10:42:43 -040052 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 Savard2b370f02012-09-06 16:06:01 -040062
63 @Override
64 public void onCreate(Bundle savedInstanceState)
65 {
66 super.onCreate(savedInstanceState);
67
Alexandre Savard9a93f062012-09-11 10:42:43 -040068 Log.i(TAG, "Create Account Management Fragment");
Alexandre Savard2b370f02012-09-06 16:06:01 -040069
Alexandre Savard9a93f062012-09-11 10:42:43 -040070 setPreferenceScreen(getAccountPreferenceScreen());
Alexandre Savard2b370f02012-09-06 16:06:01 -040071 }
72
Alexandre Savard9a93f062012-09-11 10:42:43 -040073 boolean onTextEditPreferenceChange(Preference preference, Object newValue)
Alexandre Savard2b370f02012-09-06 16:06:01 -040074 {
Alexandre Savard9a93f062012-09-11 10:42:43 -040075 Log.i(TAG, "Account Preference Changed " + preference.getTitle());
Alexandre Savard2b370f02012-09-06 16:06:01 -040076
Alexandre Savard9a93f062012-09-11 10:42:43 -040077 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 Savard9a93f062012-09-11 10:42:43 -0400115 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 Savard700c1942012-09-11 15:30:38 -0400128 accountAliasPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400129 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 Savard700c1942012-09-11 15:30:38 -0400137 accountHostnamePref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400138 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 Savard700c1942012-09-11 15:30:38 -0400146 accountUsernamePref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400147 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 Savard700c1942012-09-11 15:30:38 -0400155 accountProxyPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400156 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 Savard700c1942012-09-11 15:30:38 -0400164 accountRegistrationPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400165 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 Savard700c1942012-09-11 15:30:38 -0400173 accountNetworkPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400174 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 Savard700c1942012-09-11 15:30:38 -0400182 accountSecurityPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400183 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 Savard700c1942012-09-11 15:30:38 -0400191 accountTlsPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400192 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 Savard700c1942012-09-11 15:30:38 -0400200 accountSrtpPref.setPersistent(false);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400201 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 Savard2b370f02012-09-06 16:06:01 -0400208}