blob: af758effa32073593dc7112c4a0871e8f877afc8 [file] [log] [blame]
alision5cfc35d2013-07-11 15:11:39 -04001package com.savoirfairelinux.sflphone.fragments;
2
3import java.util.HashMap;
4
5import android.app.Activity;
6import android.app.AlertDialog;
7import android.app.Dialog;
8import android.app.Fragment;
9import android.content.DialogInterface;
10import android.content.Intent;
11import android.os.Bundle;
12import android.text.TextUtils;
13import android.view.LayoutInflater;
14import android.view.View;
15import android.view.ViewGroup;
16import android.widget.EditText;
alision5cfc35d2013-07-11 15:11:39 -040017
18import com.savoirfairelinux.sflphone.R;
19import com.savoirfairelinux.sflphone.account.AccountDetail;
20import com.savoirfairelinux.sflphone.account.AccountDetailAdvanced;
21import com.savoirfairelinux.sflphone.account.AccountDetailBasic;
22import com.savoirfairelinux.sflphone.account.AccountDetailSrtp;
23import com.savoirfairelinux.sflphone.account.AccountDetailTls;
24
25public class AccountCreationFragment extends Fragment {
26
27 // Values for email and password at the time of the login attempt.
28 private String mAlias;
29 private String mHostname;
30 private String mUsername;
31 private String mPassword;
32
33 // UI references.
34 private EditText mAliasView;
35 private EditText mHostnameView;
36 private EditText mUsernameView;
37 private EditText mPasswordView;
38
39 @Override
40 public void onCreate(Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
42 // mAdapter = new HistoryAdapter(getActivity(),new ArrayList<HashMap<String, String>>());
43 }
44
45 @Override
46 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
47 View inflatedView = inflater.inflate(R.layout.frag_account_creation, parent, false);
48
49 mAliasView = (EditText) inflatedView.findViewById(R.id.alias);
50 mHostnameView = (EditText) inflatedView.findViewById(R.id.hostname);
51 mUsernameView = (EditText) inflatedView.findViewById(R.id.username);
52 mPasswordView = (EditText) inflatedView.findViewById(R.id.password);
53 inflatedView.findViewById(R.id.create_button).setOnClickListener(new View.OnClickListener() {
54 @Override
55 public void onClick(View view) {
Alexandre Lisionf126dad2013-07-18 12:21:20 -040056 mAlias = mAliasView.getText().toString();
57 mHostname = mHostnameView.getText().toString();
58 mUsername = mUsernameView.getText().toString();
59 mPassword = mPasswordView.getText().toString();
alision5cfc35d2013-07-11 15:11:39 -040060 attemptCreation();
61 }
62 });
Alexandre Lisionf126dad2013-07-18 12:21:20 -040063
64
65 inflatedView.findViewById(R.id.dev_account).setOnClickListener(new View.OnClickListener() {
66 @Override
67 public void onClick(View view) {
68 createDevAccount();
69 }
70
71 private void createDevAccount() {
72 mUsername = mUsernameView.getText().toString();
73 if (TextUtils.isEmpty(mUsername)) {
74 mUsernameView.setError(getString(R.string.error_field_required));
75 mUsernameView.requestFocus();
76 return;
77 } else {
78 mAlias = mUsername;
79 mHostname = "192.95.9.63";
80 mPassword = "sfl_u"+mUsername;
81 attemptCreation();
82 }
83
84 }
85 });
alision5cfc35d2013-07-11 15:11:39 -040086
87 return inflatedView;
88 }
89
90 @Override
91 public void onResume() {
92 super.onResume();
93 }
94
95 @Override
96 public void onStart() {
97 super.onStart();
98
99 }
100
101 /**
102 * Attempts to sign in or register the account specified by the login form. If there are form errors (invalid email, missing fields, etc.), the
103 * errors are presented and no actual login attempt is made.
104 */
105 public void attemptCreation() {
106
107 // Reset errors.
108 mAliasView.setError(null);
109 mPasswordView.setError(null);
110
111 // Store values at the time of the login attempt.
Alexandre Lisionf126dad2013-07-18 12:21:20 -0400112
alision5cfc35d2013-07-11 15:11:39 -0400113
114 boolean cancel = false;
115 View focusView = null;
116
117 // Check for a valid password.
118 if (TextUtils.isEmpty(mPassword)) {
119 mPasswordView.setError(getString(R.string.error_field_required));
120 focusView = mPasswordView;
121 cancel = true;
122 }
123
124 if (TextUtils.isEmpty(mUsername)) {
125 mUsernameView.setError(getString(R.string.error_field_required));
126 focusView = mUsernameView;
127 cancel = true;
128 }
129
130 if (TextUtils.isEmpty(mHostname)) {
131 mHostnameView.setError(getString(R.string.error_field_required));
132 focusView = mHostnameView;
133 cancel = true;
134 }
135
136 // Check for a valid email address.
137 if (TextUtils.isEmpty(mAlias)) {
138 mAliasView.setError(getString(R.string.error_field_required));
139 focusView = mAliasView;
140 cancel = true;
141 }
142
143 if (cancel) {
144 // There was an error; don't attempt login and focus the first
145 // form field with an error.
146 focusView.requestFocus();
147 } else {
148 // Show a progress spinner, and kick off a background task to
149 // perform the user login attempt.
150 initCreation();
151
152 }
153 }
154
155 private void initCreation() {
156
157 HashMap<String, String> accountDetails = new HashMap<String, String>();
158
159 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_TYPE, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_TYPE);
160 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS, mAlias);
161 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME, mHostname);
162 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, mUsername);
163 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, mPassword);
164 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_ROUTESET, "");
165 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_REALM, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_REALM);
166 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_ENABLE, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_ENABLE);
167 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, mPassword);
168 accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_USERAGENT, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_USERAGENT);
169
170 accountDetails.put(AccountDetailAdvanced.CONFIG_LOCAL_PORT, AccountDetailAdvanced.CONFIG_DEFAULT_LOCAL_PORT);
171 accountDetails.put(AccountDetailAdvanced.CONFIG_LOCAL_INTERFACE, AccountDetailAdvanced.CONFIG_DEFAULT_INTERFACE);
172 accountDetails.put(AccountDetailAdvanced.CONFIG_PUBLISHED_PORT, AccountDetailAdvanced.CONFIG_DEFAULT_PUBLISHED_PORT);
173 accountDetails.put(AccountDetailAdvanced.CONFIG_PUBLISHED_ADDRESS, AccountDetailAdvanced.CONFIG_DEFAULT_ADDRESS);
174 accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_EXPIRE, AccountDetailAdvanced.CONFIG_DEFAULT_REGISTRATION_EXPIRE);
175 accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_SERVER, "");
176 accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATUS, "");
177 accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, "");
178 accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, "");
179 accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_AUTOANSWER, "");
180 accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_DTMF_TYPE, "");
181 accountDetails.put(AccountDetailAdvanced.CONFIG_KEEP_ALIVE_ENABLED, "");
182 accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_SERVER, "");
183 accountDetails.put(AccountDetailAdvanced.CONFIG_PUBLISHED_SAMEAS_LOCAL, AccountDetailAdvanced.CONFIG_DEFAULT_PUBLISHED_SAMEAS_LOCAL);
184 accountDetails.put(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED, "false");
185 accountDetails.put(AccountDetailAdvanced.CONFIG_RINGTONE_PATH, "");
186 accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_ENABLE, "false");
187
188 accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, "");
189 accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_RTP_FALLBACK, "");
190 accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_ENABLE, "");
191 accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, "");
192 accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS, "");
193 accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS_ONCE, "");
194 accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, "");
195 accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_HELLO_HASH, "");
196 accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_NOT_SUPP_WARNING, "");
197
198 accountDetails.put(AccountDetailTls.CONFIG_TLS_CIPHERS, "");
199 accountDetails.put(AccountDetailTls.CONFIG_TLS_LISTENER_PORT, "");
200 accountDetails.put(AccountDetailTls.CONFIG_TLS_METHOD, "");
201 accountDetails.put(AccountDetailTls.CONFIG_TLS_ENABLE, "");
202 accountDetails.put(AccountDetailTls.CONFIG_TLS_PASSWORD, "");
203 accountDetails.put(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE, "");
204
205 accountDetails.put(AccountDetailTls.CONFIG_TLS_SERVER_NAME, "");
206 accountDetails.put(AccountDetailTls.CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, "false");
207 accountDetails.put(AccountDetailTls.CONFIG_TLS_LISTENER_PORT, "");
208 accountDetails.put(AccountDetailTls.CONFIG_TLS_VERIFY_CLIENT, "");
209 accountDetails.put(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE, "");
210 accountDetails.put(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE, "");
211 accountDetails.put(AccountDetailTls.CONFIG_TLS_VERIFY_SERVER, "");
212
213 Bundle bundle = new Bundle();
214 bundle.putSerializable(AccountDetail.TAG, accountDetails);
215 Intent resultIntent = new Intent();
216 resultIntent.putExtras(bundle);
217
218 getActivity().setResult(Activity.RESULT_OK, resultIntent);
219 getActivity().finish();
220
221 }
222
alision5cfc35d2013-07-11 15:11:39 -0400223}