# HG changeset patch # User Vincent Veronis # Date 1259800667 -3600 # Node ID 5a2e5cf7c8c1ce00f6b916cbac9270ed62466f2b # Parent 443a5937ad7a087c4fb368661a4d0f2682e0894d Changement fichier login diff -r 443a5937ad7a -r 5a2e5cf7c8c1 src/com/beem/project/beem/ui/Login.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/Login.java Thu Dec 03 01:37:47 2009 +0100 @@ -0,0 +1,128 @@ +package com.beem.project.beem.ui; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.widget.TextView; +import android.widget.Toast; + +import com.beem.project.beem.R; + +/** + * This class is the main Activity for the Beem project. + * @author Da Risk + */ +public class Login extends Activity { + + private static final String TAG = "Login2"; + private SharedPreferences mSettings; + private TextView mTextView; + private boolean mIsConfigured; + private boolean mIsResult; + + /** + * Constructor. + */ + public Login() { + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.login); + mTextView = (TextView)findViewById(R.id.log_as_msg); + mSettings = PreferenceManager.getDefaultSharedPreferences(this); + } + + @Override + protected void onStart() { + super.onStart(); + mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false); + // TODO utiliser une options des preference plutot. + if (mIsConfigured && !mIsResult) { + mTextView.setText(""); + Intent i = new Intent(this, LoginAnim.class); + startActivityForResult(i, 42); + mIsResult = false; + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == 42) { + mIsResult = true; + if (resultCode == Activity.RESULT_OK) { + Log.d(TAG, "Connected !!! Launch contact list"); + startActivity(new Intent(this, ContactList.class)); + finish(); + } else if (resultCode == Activity.RESULT_CANCELED) { // or error ? + // Set an intent with data in like the error msg + Log.d(TAG, "NOT Connected !!!"); + if (data != null) { + String tmp = data.getExtras().getString("message"); + Log.d(TAG, tmp); + Toast.makeText(Login.this, tmp, Toast.LENGTH_SHORT).show(); + mTextView.setText(tmp); + } + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.login, menu); + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.login_menu_settings: + mTextView.setText(""); + startActivity(new Intent(Login.this, Settings.class)); + return true; + case R.id.login_menu_about: + createAboutDialog(); + return true; + case R.id.login_menu_login: + Intent i = new Intent(this, LoginAnim.class); + startActivityForResult(i, 42); + return true; + default: + return false; + } + } + + /** + * Create an about "BEEM" dialog. + */ + private void createAboutDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.login_about_title).setMessage(R.string.login_about_msg).setCancelable(false); + builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int whichButton) { + dialog.cancel(); + } + }); + AlertDialog aboutDialog = builder.create(); + aboutDialog.show(); + } + +} diff -r 443a5937ad7a -r 5a2e5cf7c8c1 src/com/beem/project/beem/ui/Login2.java --- a/src/com/beem/project/beem/ui/Login2.java Thu Dec 03 01:37:08 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -package com.beem.project.beem.ui; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.util.Log; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.widget.TextView; -import android.widget.Toast; - -import com.beem.project.beem.R; - -/** - * This class is the main Activity for the Beem project. - * @author Da Risk - */ -public class Login extends Activity { - - private static final String TAG = "Login2"; - private SharedPreferences mSettings; - private TextView mTextView; - private boolean mIsConfigured; - private boolean mIsResult; - - /** - * Constructor. - */ - public Login() { - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.login); - mTextView = (TextView)findViewById(R.id.log_as_msg); - mSettings = PreferenceManager.getDefaultSharedPreferences(this); - } - - @Override - protected void onStart() { - super.onStart(); - mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false); - // TODO utiliser une options des preference plutot. - if (mIsConfigured && !mIsResult) { - mTextView.setText(""); - Intent i = new Intent(this, LoginAnim.class); - startActivityForResult(i, 42); - mIsResult = false; - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == 42) { - mIsResult = true; - if (resultCode == Activity.RESULT_OK) { - Log.d(TAG, "Connected !!! Launch contact list"); - startActivity(new Intent(this, ContactList.class)); - finish(); - } else if (resultCode == Activity.RESULT_CANCELED) { // or error ? - // Set an intent with data in like the error msg - Log.d(TAG, "NOT Connected !!!"); - if (data != null) { - String tmp = data.getExtras().getString("message"); - Log.d(TAG, tmp); - Toast.makeText(Login.this, tmp, Toast.LENGTH_SHORT).show(); - mTextView.setText(tmp); - } - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.login, menu); - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public final boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.login_menu_settings: - mTextView.setText(""); - startActivity(new Intent(Login.this, Settings.class)); - return true; - case R.id.login_menu_about: - createAboutDialog(); - return true; - case R.id.login_menu_login: - Intent i = new Intent(this, LoginAnim.class); - startActivityForResult(i, 42); - return true; - default: - return false; - } - } - - /** - * Create an about "BEEM" dialog. - */ - private void createAboutDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.login_about_title).setMessage(R.string.login_about_msg).setCancelable(false); - builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int whichButton) { - dialog.cancel(); - } - }); - AlertDialog aboutDialog = builder.create(); - aboutDialog.show(); - } - -}