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