# HG changeset patch # User nikita@nikita-rack # Date 1240333712 -7200 # Node ID 61946568269796a56c7b4cf4ebc32b342b9383c1 # Parent fc47ca00ad95cfff8d3e6cfc478ccbdf14be88d8 ajout de la creation de compte, il faut encore rendre le message un peu plus verbose en cas d'echec. Il faudrait aussi faire une connection auto peut etre. diff -r fc47ca00ad95 -r 619465682697 res/layout/accountcreation.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/accountcreation.xml Tue Apr 21 19:08:32 2009 +0200 @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r fc47ca00ad95 -r 619465682697 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Tue Apr 21 16:38:50 2009 +0200 +++ b/src/com/beem/project/beem/BeemService.java Tue Apr 21 19:08:32 2009 +0200 @@ -72,6 +72,7 @@ */ @Override public void onCreate() { + super.onCreate(); mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE); mLogin = mSettings.getString(getString(R.string.PreferenceLoginKey), ""); @@ -182,6 +183,7 @@ } + @Override public void onConnect() throws RemoteException { // TODO Auto-generated method stub diff -r fc47ca00ad95 -r 619465682697 src/com/beem/project/beem/ui/AccountCreation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/AccountCreation.java Tue Apr 21 19:08:32 2009 +0200 @@ -0,0 +1,111 @@ +/** + * + */ +package com.beem.project.beem.ui; + +import java.util.HashMap; +import java.util.Map; + +import org.jivesoftware.smack.AccountManager; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; + +import com.beem.project.beem.R; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +/** + * @author nikita + * + */ +public class AccountCreation extends Activity { + + protected static final String TAG = "AccountCreation"; + private SharedPreferences mSettings; + Map mAttributes = new HashMap(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.accountcreation); + Button ok = (Button) findViewById(R.id.ok); + mSettings = getSharedPreferences( + getString(R.string.PreferenceFileName), MODE_PRIVATE); + //mAccountManager = new AccountManager(); + ok.setOnClickListener(mOkListener); + } + + private OnClickListener mOkListener = new OnClickListener() { + + @Override + public void onClick(View v) { + boolean valid = true; + if (getWidgetText(R.id.login).length() == 0) { + Log.d(TAG, "login pas ok"); + valid = false; + } else { + mAttributes.put("login", getWidgetText(R.id.login)); + mAttributes.put("name", getWidgetText(R.id.login)); + } + if (getWidgetText(R.id.password).length() == 0 || !getWidgetText(R.id.password).contains(getWidgetText(R.id.password2))) { + valid = false; + + } else { + mAttributes.put("password", getWidgetText(R.id.password)); + } + if (getWidgetText(R.id.email).length() == 0) { + valid = false; + } else { + mAttributes.put("email", getWidgetText(R.id.email)); + } + + if (valid) { + setResult(RESULT_OK); + try { + createAccount(); + Toast.makeText(AccountCreation.this, "Account created", + Toast.LENGTH_SHORT).show(); + finish(); + } catch (XMPPException e) { + Log.e(TAG, "Account creation failed", e); + Toast.makeText(AccountCreation.this, e.getMessage(), + Toast.LENGTH_SHORT).show(); + e.printStackTrace(); + } + } else { + Toast.makeText(AccountCreation.this, "Form error", + Toast.LENGTH_SHORT).show(); + setResult(RESULT_CANCELED); + } + + } + }; + + protected void createAccount() throws XMPPException { + String mHost = mSettings.getString(getString(R.string.PreferenceHostKey), ""); + XMPPConnection xmmpCo = new XMPPConnection(new ConnectionConfiguration(mHost)); + xmmpCo.connect(); + AccountManager accM = new AccountManager(xmmpCo); + accM.createAccount(mAttributes.get("login"), mAttributes.get("password"), mAttributes); + + SharedPreferences.Editor editor = mSettings.edit(); + + editor.putString(getString(R.string.PreferenceLoginKey), mAttributes.get("login")); + editor.putString(getString(R.string.PreferencePasswordKey), mAttributes.get("password")); + editor.commit(); + } + + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } +} \ No newline at end of file