# HG changeset patch # User Da Risk # Date 1348886862 -7200 # Node ID 6318bee856fdc2c971eb3fb27843c98eb9f4cd9a # Parent 87c97dcb7136c943d1fbf14f50ca1e5ba923ed8a Display error messages when account creation failed. Improve the creation wizard and add a dummy script to fetch a list of xmpp services. diff -r 87c97dcb7136 -r 6318bee856fd res/layout/create_account.xml --- a/res/layout/create_account.xml Tue Sep 25 22:40:22 2012 +0200 +++ b/res/layout/create_account.xml Sat Sep 29 04:47:42 2012 +0200 @@ -12,16 +12,36 @@ android:layout_marginTop="15dp" android:layout_marginBottom="30dp" android:src="@drawable/logo"/> - + + - + + + + + @@ -38,7 +58,10 @@ android:inputType="textPassword" android:imeOptions="actionNext" android:singleLine="true" android:contentDescription="@string/create_account_confirm_password"/> - + diff -r 87c97dcb7136 -r 6318bee856fd res/layout/simple_combobox_item.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/simple_combobox_item.xml Sat Sep 29 04:47:42 2012 +0200 @@ -0,0 +1,9 @@ + + diff -r 87c97dcb7136 -r 6318bee856fd res/values-fr/strings.xml --- a/res/values-fr/strings.xml Tue Sep 25 22:40:22 2012 +0200 +++ b/res/values-fr/strings.xml Sat Sep 29 04:47:42 2012 +0200 @@ -199,11 +199,14 @@ + Entrez les informations nécéssaires pour créer votre compte Mauvais JabberID Les mots de passe ne correspondent pas Nom d\'utilisateur Mot de passe Confirmation du mot de passe + Ce compte est déjà utilisé. Essayez d\'en créer un autre + Le serveur choisi n\'est pas disponible. Essayez en un autre + Enter the required informations to create your account Bad JabberID Passwords do not match. Username Password Confirm password + This account is already used. Please try another one + The selected server is not available. Please try another one + Add a contact diff -r 87c97dcb7136 -r 6318bee856fd res/values/xmpp_server_list.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/values/xmpp_server_list.xml Sat Sep 29 04:47:42 2012 +0200 @@ -0,0 +1,138 @@ + + + + 0nl1ne.at + blah.at + blah.im + boese-ban.de + brauchen.info + chatme.im + chrome.pl + climm.org + coderollers.com + codingteam.net + comm.unicate.me + darkdna.net + deshalbfrei.org + draugr.de + einfachjabber.de + forumanalogue.fr + im.apinc.org + im.flosoft.biz + internet-exception.de + jabb3r.net + jabber-br.org + jabber-hosting.de + jabber.at + jabber.ccc.de + jabber.chaotic.de + jabber.co.nz + jabber.cz + jabber.de + jabber.earth.li + jabber.etighichat.com + jabber.fourecks.de + jabber.gate31.net + jabber.hot-chilli.net + jabber.i-pobox.net + jabber.iitsp.com + jabber.loudas.com + jabber.me + jabber.meta.net.nz + jabber.minus273.org + jabber.no-sense.net + jabber.no + jabber.rootbash.com + jabber.rueckgr.at + jabber.scha.de + jabber.schnied.net + jabber.second-home.de + jabber.smash-net.org + jabber.sow.as + jabber.theforest.us + jabber.tmkis.com + jabber.yeahnah.co.nz + jabberd.eu + jabberes.org + jabbim.com + jabbim.cz + jabbim.pl + jabbim.sk + jabin.org + jabme.de + jabster.pl + jaim.at + jappix.com + jisshi.com + labnote.org + lightwitch.org + limun.org + macjabber.de + mayplaces.com + na-di.de + neko.im + netmindz.net + njs.netlab.cz + palita.net + pandion.im + pidgin.su + programmer-art.org + prosody.de + richim.org + rkquery.de + sss.chaoslab.ru + sternenschweif.de + swissjabber.ch + swissjabber.de + swissjabber.eu + swissjabber.li + swissjabber.org + tcweb.org + tekst.me + thiessen.im + thiessen.it + thiessen.org + tigase.im + twattle.net + ubuntu-jabber.de + ubuntu-jabber.net + univers-libre.net + verdammung.org + wtfismyip.com + xabber.de + xmpp-hosting.de + xmpp.jp + xmppnet.de + zauris.ru + zsim.de + xmpp.kz + freamware.net + gabbler.de + gabbler.eu + gabbler.org + hot-chilli.net + igniterealtime.org + is-the-shit.com + jabberheaven.com + jabberheaven.de + jabber.rückgr.at + jabber.se + jabberus.kz + jabberzac.org + vrane.com + xmpp.ru.net + gojabber.org + jabbeng.in + jabber.gnubox.net + jabberid.org + jodo.im + jsmart.web.id + linuxlovers.at + n0g.at + totalueberwachung.de + jabber.kiev.ua + jabbir.org + j-talk.me + xmppres.com + + diff -r 87c97dcb7136 -r 6318bee856fd src/com/beem/project/beem/ui/wizard/AccountConfigureFragment.java --- a/src/com/beem/project/beem/ui/wizard/AccountConfigureFragment.java Tue Sep 25 22:40:22 2012 +0200 +++ b/src/com/beem/project/beem/ui/wizard/AccountConfigureFragment.java Sat Sep 29 04:47:42 2012 +0200 @@ -126,7 +126,7 @@ super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); setRetainInstance(true); - + settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); } @@ -158,34 +158,34 @@ @Override public void onStart() { - super.onStart(); - useSystemAccount = settings.getBoolean(BeemApplication.USE_SYSTEM_ACCOUNT_KEY, false); - // temporaly disable jid watcher - mAccountJID.removeTextChangedListener(mJidTextWatcher); - mAccountJID.setText(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "")); - if (useSystemAccount) { - mAccountPassword.setText("*******"); //dummy password - mAccountJID.setText(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "")); - mAccountPassword.setEnabled(false); - mNextButton.setEnabled(true); - } - mAccountJID.addTextChangedListener(mJidTextWatcher); + super.onStart(); + useSystemAccount = settings.getBoolean(BeemApplication.USE_SYSTEM_ACCOUNT_KEY, false); + // temporaly disable jid watcher + mAccountJID.removeTextChangedListener(mJidTextWatcher); + mAccountJID.setText(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "")); + if (useSystemAccount) { + mAccountPassword.setText("*******"); //dummy password + mAccountJID.setText(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "")); + mAccountPassword.setEnabled(false); + mNextButton.setEnabled(true); + } + mAccountJID.addTextChangedListener(mJidTextWatcher); } @TargetApi(14) @Override public void onClick(View v) { if (v == mNextButton) { - if (useSystemAccount) { - onDeviceAccountSelected(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, ""), - settings.getString(BeemApplication.ACCOUNT_SYSTEM_TYPE_KEY, "")); - } else { - String jid = mAccountJID.getText().toString(); - jid = StringUtils.parseBareAddress(jid); - String password = mAccountPassword.getText().toString(); - task = new ConnectionTestTask(); - task.execute(jid, password); - } + if (useSystemAccount) { + onDeviceAccountSelected(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, ""), + settings.getString(BeemApplication.ACCOUNT_SYSTEM_TYPE_KEY, "")); + } else { + String jid = mAccountJID.getText().toString(); + jid = StringUtils.parseBareAddress(jid); + String password = mAccountPassword.getText().toString(); + task = new ConnectionTestTask(); + task.execute(jid, password); + } } else if (v == mManualConfigButton) { onManualConfigurationSelected(); } else if (v == mSelectAccountButton) { @@ -214,7 +214,6 @@ mSelectedAccountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); onDeviceAccountSelected(mSelectedAccountName, mSelectedAccountType); } else if (requestCode == MANUAL_CONFIGURATION_CODE) { - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); String login = settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, ""); String password = settings.getString(BeemApplication.ACCOUNT_PASSWORD_KEY, ""); mAccountJID.setText(login); @@ -246,7 +245,6 @@ * */ private void onAccountConnectionFailed() { - //TODO display error mAccountPassword.setText(""); mErrorLabel.setVisibility(View.VISIBLE); } @@ -282,7 +280,7 @@ edit.putBoolean(BeemApplication.USE_SYSTEM_ACCOUNT_KEY, false); edit.commit(); } - + /** * Save the user credentials. * @@ -365,7 +363,7 @@ checkUsername(s.toString()); mNextButton.setEnabled(mValidJid && mValidPassword); if (useSystemAccount) { - mAccountPassword.setEnabled(true); + mAccountPassword.setEnabled(true); mAccountPassword.setText(""); } useSystemAccount = false; @@ -385,9 +383,9 @@ */ class ConnectionTestTask extends AsyncTask { - private ProgressFragment progress; - private ConnectionConfiguration config; - private XMPPException exception; + private ProgressFragment progress; + private ConnectionConfiguration config; + private XMPPException exception; private String jid; private String password; private String server; @@ -452,17 +450,17 @@ * @return the XMPPConnection prepared to connect */ private Connection prepareConnection(String jid, String server, int port) { - boolean useProxy = settings.getBoolean(BeemApplication.PROXY_USE_KEY, false); - ProxyInfo proxyinfo = ProxyInfo.forNoProxy(); - if (useProxy) { - String stype = settings.getString(BeemApplication.PROXY_TYPE_KEY, "HTTP"); - String phost = settings.getString(BeemApplication.PROXY_SERVER_KEY, ""); - String puser = settings.getString(BeemApplication.PROXY_USERNAME_KEY, ""); - String ppass = settings.getString(BeemApplication.PROXY_PASSWORD_KEY, ""); - int pport = Integer.parseInt(settings.getString(BeemApplication.PROXY_PORT_KEY, "1080")); - ProxyInfo.ProxyType type = ProxyType.valueOf(stype); - proxyinfo = new ProxyInfo(type, phost, pport, puser, ppass); - } + boolean useProxy = settings.getBoolean(BeemApplication.PROXY_USE_KEY, false); + ProxyInfo proxyinfo = ProxyInfo.forNoProxy(); + if (useProxy) { + String stype = settings.getString(BeemApplication.PROXY_TYPE_KEY, "HTTP"); + String phost = settings.getString(BeemApplication.PROXY_SERVER_KEY, ""); + String puser = settings.getString(BeemApplication.PROXY_USERNAME_KEY, ""); + String ppass = settings.getString(BeemApplication.PROXY_PASSWORD_KEY, ""); + int pport = Integer.parseInt(settings.getString(BeemApplication.PROXY_PORT_KEY, "1080")); + ProxyInfo.ProxyType type = ProxyType.valueOf(stype); + proxyinfo = new ProxyInfo(type, phost, pport, puser, ppass); + } String serviceName = StringUtils.parseServer(jid); if (port != -1 || !TextUtils.isEmpty(server)) { if (port == -1) @@ -473,6 +471,8 @@ } else { config = new ConnectionConfiguration(serviceName, proxyinfo); } + if (settings.getBoolean(BeemApplication.SMACK_DEBUG_KEY, false)) + config.setDebuggerEnabled(true); return new XMPPConnection(config); } } diff -r 87c97dcb7136 -r 6318bee856fd src/com/beem/project/beem/ui/wizard/CreateAccountFragment.java --- a/src/com/beem/project/beem/ui/wizard/CreateAccountFragment.java Tue Sep 25 22:40:22 2012 +0200 +++ b/src/com/beem/project/beem/ui/wizard/CreateAccountFragment.java Sat Sep 29 04:47:42 2012 +0200 @@ -44,8 +44,12 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; import android.widget.Button; +import android.widget.EditText; import android.widget.TextView; import com.beem.project.beem.BeemApplication; @@ -57,6 +61,7 @@ import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.proxy.ProxyInfo; import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType; import org.jivesoftware.smack.util.StringUtils; @@ -67,9 +72,11 @@ */ public class CreateAccountFragment extends Fragment implements android.view.View.OnClickListener { private static final String TAG = CreateAccountFragment.class.getSimpleName(); - private TextView username; - private TextView password; - private TextView confirmPassword; + private EditText username; + private EditText password; + private EditText confirmPassword; + private TextView errorText; + private AutoCompleteTextView serverEdit; private Button createButton; private CreateAccountTask task; private final NotEmptyTextWatcher mTextWatcher = new NotEmptyTextWatcher(); @@ -101,14 +108,29 @@ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.create_account, container, false); - username = (TextView) v.findViewById(R.id.create_account_username); + username = (EditText) v.findViewById(R.id.create_account_username); username.addTextChangedListener(mTextWatcher); - password = (TextView) v.findViewById(R.id.create_account_password); + password = (EditText) v.findViewById(R.id.create_account_password); password.addTextChangedListener(mTextWatcher); - confirmPassword = (TextView) v.findViewById(R.id.create_account_confirm_password); + confirmPassword = (EditText) v.findViewById(R.id.create_account_confirm_password); confirmPassword.addTextChangedListener(mTextWatcher); + errorText = (TextView) v.findViewById(R.id.error_label); createButton = (Button) v.findViewById(R.id.next); createButton.setOnClickListener(this); + serverEdit = (AutoCompleteTextView) v.findViewById(R.id.xmpp_server); + ArrayAdapter completeAdapter = ArrayAdapter.createFromResource( + getActivity(), R.array.xmpp_server_list, R.layout.simple_combobox_item); + + serverEdit.setAdapter(completeAdapter); + serverEdit.addTextChangedListener(mTextWatcher); + // show the list on second click on the text view + serverEdit.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + serverEdit.showDropDown(); + } + }); return v; } @@ -116,17 +138,21 @@ public void onClick(View v) { if (v == createButton) { boolean create = true; - if (!checkEmail()) { + if (!checkUserName()) { username.setError(getString(R.string.create_account_err_username)); create = false; } + if (TextUtils.isEmpty(serverEdit.getText())) { + serverEdit.setError("Choose a server"); + create = false; + } if (!checkPasswords()) { password.setError(getString(R.string.create_account_err_passwords)); confirmPassword.setError(getString(R.string.create_account_err_passwords)); create = false; } if (create) { - String jid = username.getText().toString(); + String jid = String.format("%s@%s", username.getText(), serverEdit.getText()); jid = StringUtils.parseBareAddress(jid); String pass = password.getText().toString(); task = new CreateAccountTask(); @@ -143,7 +169,6 @@ * */ private void saveCredential(String jid, String pass) { - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); SharedPreferences.Editor edit = settings.edit(); edit.putString(BeemApplication.ACCOUNT_USERNAME_KEY, jid); edit.putString(BeemApplication.ACCOUNT_PASSWORD_KEY, pass); @@ -174,7 +199,12 @@ * */ private void onAccountCreationFailed(XMPPException e) { - // TODO displayError + XMPPError error = e.getXMPPError(); + if (error != null && XMPPError.Condition.conflict.equals(error.getCondition())) + errorText.setText(R.string.create_account_err_conflict); + else + errorText.setText(R.string.create_account_err_connection); + Log.v(TAG, "Unable to create an account on xmpp server", e); } /** @@ -182,9 +212,9 @@ * * @return true if the email is valid. */ - private boolean checkEmail() { + private boolean checkUserName() { String email = username.getText().toString(); - return Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", email); + return Pattern.matches("[a-zA-Z0-9._%+-]+", email); } /** @@ -270,17 +300,17 @@ * @return the XMPPConnection prepared to connect */ private Connection prepareConnection(String jid, String server, int port) { - boolean useProxy = settings.getBoolean(BeemApplication.PROXY_USE_KEY, false); - ProxyInfo proxyinfo = ProxyInfo.forNoProxy(); - if (useProxy) { - String stype = settings.getString(BeemApplication.PROXY_TYPE_KEY, "HTTP"); - String phost = settings.getString(BeemApplication.PROXY_SERVER_KEY, ""); - String puser = settings.getString(BeemApplication.PROXY_USERNAME_KEY, ""); - String ppass = settings.getString(BeemApplication.PROXY_PASSWORD_KEY, ""); - int pport = Integer.parseInt(settings.getString(BeemApplication.PROXY_PORT_KEY, "1080")); - ProxyInfo.ProxyType type = ProxyType.valueOf(stype); - proxyinfo = new ProxyInfo(type, phost, pport, puser, ppass); - } + boolean useProxy = settings.getBoolean(BeemApplication.PROXY_USE_KEY, false); + ProxyInfo proxyinfo = ProxyInfo.forNoProxy(); + if (useProxy) { + String stype = settings.getString(BeemApplication.PROXY_TYPE_KEY, "HTTP"); + String phost = settings.getString(BeemApplication.PROXY_SERVER_KEY, ""); + String puser = settings.getString(BeemApplication.PROXY_USERNAME_KEY, ""); + String ppass = settings.getString(BeemApplication.PROXY_PASSWORD_KEY, ""); + int pport = Integer.parseInt(settings.getString(BeemApplication.PROXY_PORT_KEY, "1080")); + ProxyInfo.ProxyType type = ProxyType.valueOf(stype); + proxyinfo = new ProxyInfo(type, phost, pport, puser, ppass); + } String serviceName = StringUtils.parseServer(jid); if (port != -1 || !TextUtils.isEmpty(server)) { if (port == -1) @@ -291,6 +321,8 @@ } else { config = new ConnectionConfiguration(serviceName, proxyinfo); } + if (settings.getBoolean(BeemApplication.SMACK_DEBUG_KEY, false)) + config.setDebuggerEnabled(true); return new XMPPConnection(config); } } @@ -339,6 +371,7 @@ @Override public void afterTextChanged(Editable s) { boolean enable = !(TextUtils.isEmpty(username.getText()) + || TextUtils.isEmpty(serverEdit.getText()) || TextUtils.isEmpty(password.getText()) || TextUtils.isEmpty(confirmPassword.getText())); createButton.setEnabled(enable); diff -r 87c97dcb7136 -r 6318bee856fd tools/getFreeXmppServices.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/getFreeXmppServices.py Sat Sep 29 04:47:42 2012 +0200 @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import urllib.request +import argparse, sys +from xml.dom.minidom import parse, getDOMImplementation + + +def getJidsFromUrl(url): + f = urllib.request.urlopen(url) + indoc = parse(f) + jids = [] + query = indoc.documentElement + if query.localName == "query" : + for item in query.getElementsByTagName("item"): + jid = item.getAttribute("jid") + jids.append(jid) + return jids + +def createDocument(): + impl = getDOMImplementation() + return impl.createDocument(None, "resources", None) + + +def purge(elems): + res = [] + for i in elems: + if i not in res: + res.append(i) + return res + +def appendStringElem(doc, node, jids): + for i in jids: + item = doc.createElement("item") + text = doc.createTextNode(i) + item.appendChild(text) + node.appendChild(item) + + +parser = argparse.ArgumentParser(description='Collect some free xmpp services') +parser.add_argument('url', metavar="url", + default=['http://xmpp.net/services.xml', "https://list.jabber.at/api/?format=services.xml"] , nargs='*', + help='url to get the services') + +parser.add_argument('-o', metavar="FILE", type=argparse.FileType('bw'), + default = sys.stdout.buffer, + help='send output to FILE') + +args = parser.parse_args() + +# collect the servers jid +jids = [] +for url in args.url: + jids += getJidsFromUrl(url) + +jids = purge(jids) + +# create the xml output document +outdoc = createDocument() +res_element = outdoc.documentElement +string_array_elem = outdoc.createElement('string-array') +res_element.appendChild(string_array_elem) +string_array_elem.setAttribute("name", "xmpp_server_list") +appendStringElem(outdoc, string_array_elem, jids) + +# print result +f = args.o +f.write(outdoc.toprettyxml(encoding="utf-8")) +