Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 1 | package org.sflphone.fragments; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 2 | |
| 3 | import java.util.HashMap; |
| 4 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 5 | import org.sflphone.R; |
| 6 | import org.sflphone.account.AccountDetail; |
| 7 | import org.sflphone.account.AccountDetailAdvanced; |
| 8 | import org.sflphone.account.AccountDetailBasic; |
| 9 | import org.sflphone.account.AccountDetailSrtp; |
| 10 | import org.sflphone.account.AccountDetailTls; |
| 11 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 12 | import android.app.Activity; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 13 | import android.app.Fragment; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 14 | import android.content.Intent; |
| 15 | import android.os.Bundle; |
| 16 | import android.text.TextUtils; |
| 17 | import android.view.LayoutInflater; |
| 18 | import android.view.View; |
| 19 | import android.view.ViewGroup; |
| 20 | import android.widget.EditText; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 21 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 22 | public 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 Lision | f126dad | 2013-07-18 12:21:20 -0400 | [diff] [blame] | 53 | mAlias = mAliasView.getText().toString(); |
| 54 | mHostname = mHostnameView.getText().toString(); |
| 55 | mUsername = mUsernameView.getText().toString(); |
| 56 | mPassword = mPasswordView.getText().toString(); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 57 | attemptCreation(); |
| 58 | } |
| 59 | }); |
Alexandre Lision | f126dad | 2013-07-18 12:21:20 -0400 | [diff] [blame] | 60 | |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 61 | // inflatedView.findViewById(R.id.dev_account).setVisibility(View.GONE); // Hide this button in release apk |
Alexandre Lision | f126dad | 2013-07-18 12:21:20 -0400 | [diff] [blame] | 62 | 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 | }); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 83 | |
| 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 Lision | f126dad | 2013-07-18 12:21:20 -0400 | [diff] [blame] | 109 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 110 | |
| 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 Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 176 | 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); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 179 | accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_SERVER, ""); |
| 180 | accountDetails.put(AccountDetailAdvanced.CONFIG_PUBLISHED_SAMEAS_LOCAL, AccountDetailAdvanced.CONFIG_DEFAULT_PUBLISHED_SAMEAS_LOCAL); |
Alexandre Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 181 | accountDetails.put(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED, AccountDetailAdvanced.FALSE_STR); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 182 | accountDetails.put(AccountDetailAdvanced.CONFIG_RINGTONE_PATH, ""); |
Alexandre Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 183 | accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_ENABLE, AccountDetailAdvanced.FALSE_STR); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 184 | |
| 185 | accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, ""); |
| 186 | accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_RTP_FALLBACK, ""); |
Alexandre Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 187 | accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_ENABLE, AccountDetailAdvanced.FALSE_STR); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 188 | 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 Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 198 | accountDetails.put(AccountDetailTls.CONFIG_TLS_ENABLE, AccountDetailAdvanced.FALSE_STR); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 199 | 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 Lision | 80f0a7e | 2013-09-26 12:27:51 -0400 | [diff] [blame] | 203 | accountDetails.put(AccountDetailTls.CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, AccountDetailAdvanced.FALSE_STR); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 204 | 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 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 220 | } |