|
|
@@ -1,781 +0,0 @@
|
|
|
-package com.usai.redant.raimage;
|
|
|
-
|
|
|
-import android.animation.Animator;
|
|
|
-import android.animation.AnimatorListenerAdapter;
|
|
|
-import android.annotation.TargetApi;
|
|
|
-import android.app.Activity;
|
|
|
-import android.content.Intent;
|
|
|
-import android.database.Cursor;
|
|
|
-import android.database.sqlite.SQLiteDatabase;
|
|
|
-import android.os.AsyncTask;
|
|
|
-import android.os.Build;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.util.Log;
|
|
|
-import android.view.Gravity;
|
|
|
-import android.view.KeyEvent;
|
|
|
-import android.view.View;
|
|
|
-import android.view.inputmethod.EditorInfo;
|
|
|
-import android.view.inputmethod.InputMethodManager;
|
|
|
-import android.widget.ArrayAdapter;
|
|
|
-import android.widget.AutoCompleteTextView;
|
|
|
-import android.widget.EditText;
|
|
|
-import android.widget.TextView;
|
|
|
-import android.widget.Toast;
|
|
|
-
|
|
|
-import com.usai.util.AES;
|
|
|
-import com.usai.util.Crypto;
|
|
|
-import com.usai.util.Network;
|
|
|
-import com.usai.util.dbUtil;
|
|
|
-
|
|
|
-/**
|
|
|
- * Activity which displays a login screen to the user, offering registration as
|
|
|
- * well.
|
|
|
- */
|
|
|
-public class LockerActivity extends Activity
|
|
|
-{
|
|
|
- // public static final int ERR_CODE_NONE = 0;
|
|
|
- // public static final int ERR_CODE_NULLRETURN = 1;
|
|
|
- // public static final int ERR_CODE_NONETWORK = 2;
|
|
|
-
|
|
|
- /**
|
|
|
- * A dummy authentication store containing known user names and passwords.
|
|
|
- * TODO: remove after connecting to a real authentication system.
|
|
|
- */
|
|
|
- // private static final String[] DUMMY_CREDENTIALS = new String[] {
|
|
|
- // "foo@example.com:hello", "bar@example.com:world" };
|
|
|
-
|
|
|
- /**
|
|
|
- * The default email to populate the email field with.
|
|
|
- */
|
|
|
- // public static final String EXTRA_EMAIL =
|
|
|
- // "com.example.android.authenticatordemo.extra.EMAIL";
|
|
|
- // public static final String EXTRA_USER = "Login_User";
|
|
|
-
|
|
|
- /**
|
|
|
- * Keep track of the login task to ensure we can cancel it if requested.
|
|
|
- */
|
|
|
- private UserLoginTask mAuthTask = null;
|
|
|
- ArrayAdapter<String> adapter = null;
|
|
|
- // SQLiteDatabase m_db;
|
|
|
- // Values for email and password at the time of the login attempt.
|
|
|
- private String m_sName;
|
|
|
- private String m_sPassword;
|
|
|
-
|
|
|
- // UI references.
|
|
|
- private AutoCompleteTextView m_etName;
|
|
|
- private EditText m_etPassword;
|
|
|
- private View mLoginFormView;
|
|
|
- private View mLoginStatusView;
|
|
|
- private TextView mLoginStatusMessageView;
|
|
|
-
|
|
|
-// @Override
|
|
|
-// protected void onDestroy()
|
|
|
-// {
|
|
|
-// // TODO Auto-generated method stub
|
|
|
-//// dbUtil.CloseDB(m_db);
|
|
|
-//// super.onDestroy();
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState)
|
|
|
- {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
-
|
|
|
- setContentView(R.layout.activity_locker);
|
|
|
-
|
|
|
- // Set up the login form.
|
|
|
- // m_sName = getIntent().getStringExtra(EXTRA_USER);
|
|
|
- m_etName = (AutoCompleteTextView) findViewById(R.id.name);
|
|
|
-
|
|
|
- // m_etName.setText(m_sName);
|
|
|
-
|
|
|
- m_etPassword = (EditText) findViewById(R.id.password);
|
|
|
- m_etPassword
|
|
|
- .setOnEditorActionListener(new TextView.OnEditorActionListener()
|
|
|
- {
|
|
|
- @Override
|
|
|
- public boolean onEditorAction(TextView textView, int id,
|
|
|
- KeyEvent keyEvent)
|
|
|
- {
|
|
|
- if (id == R.id.login
|
|
|
- || id == EditorInfo.IME_ACTION_DONE)
|
|
|
- {
|
|
|
- InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext()
|
|
|
- .getSystemService(INPUT_METHOD_SERVICE);
|
|
|
-
|
|
|
- // EditText editText =
|
|
|
- // (EditText)findViewById(R.id.xxxx);
|
|
|
- inputMethodManager.hideSoftInputFromWindow(
|
|
|
- m_etPassword.getWindowToken(), 0); // ����
|
|
|
- attemptLogin();
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- mLoginFormView = findViewById(R.id.login_form);
|
|
|
- mLoginStatusView = findViewById(R.id.login_status);
|
|
|
- mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);
|
|
|
-
|
|
|
- findViewById(R.id.sign_in_button).setOnClickListener(
|
|
|
- new View.OnClickListener()
|
|
|
- {
|
|
|
- @Override
|
|
|
- public void onClick(View view)
|
|
|
- {
|
|
|
- attemptLogin();
|
|
|
- }
|
|
|
- });
|
|
|
- adapter = new ArrayAdapter<String>(this,
|
|
|
- android.R.layout.simple_list_item_1,
|
|
|
- dbUtil.get_userlist());
|
|
|
- m_etName.setAdapter(adapter);
|
|
|
- }
|
|
|
- @Override
|
|
|
- public boolean onKeyDown(int keyCode, KeyEvent event)
|
|
|
- {
|
|
|
- if (keyCode == KeyEvent.KEYCODE_BACK)
|
|
|
- {
|
|
|
- // Intent myIntent = new Intent();
|
|
|
- // myIntent = new Intent(EditActivity.this, tabActivity.class);
|
|
|
- // startActivity(myIntent);
|
|
|
- // this.finish();
|
|
|
- return true;
|
|
|
- }
|
|
|
- return super.onKeyDown(keyCode, event);
|
|
|
-
|
|
|
- }
|
|
|
-// @Override
|
|
|
-// public boolean onCreateOptionsMenu(Menu menu)
|
|
|
-// {
|
|
|
-// super.onCreateOptionsMenu(menu);
|
|
|
-// getMenuInflater().inflate(R.menu.login, menu);
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-
|
|
|
- /**
|
|
|
- * Attempts to sign in or register the account specified by the login form.
|
|
|
- * If there are form errors (invalid email, missing fields, etc.), the
|
|
|
- * errors are presented and no actual login attempt is made.
|
|
|
- */
|
|
|
- public void attemptLogin()
|
|
|
- {
|
|
|
- if (mAuthTask != null)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Reset errors.
|
|
|
- m_etName.setError(null);
|
|
|
- m_etPassword.setError(null);
|
|
|
-
|
|
|
- // Store values at the time of the login attempt.
|
|
|
- m_sName = m_etName.getText().toString();
|
|
|
- m_sPassword = m_etPassword.getText().toString();
|
|
|
-
|
|
|
- boolean cancel = false;
|
|
|
- View focusView = null;
|
|
|
-
|
|
|
- // Check for a valid password.
|
|
|
- if (TextUtils.isEmpty(m_sPassword))
|
|
|
- {
|
|
|
- m_etPassword.setError(getString(R.string.error_field_required));
|
|
|
- focusView = m_etPassword;
|
|
|
- cancel = true;
|
|
|
- }
|
|
|
- else if (m_sPassword.length() < 4)
|
|
|
- {
|
|
|
- m_etPassword.setError(getString(R.string.error_invalid_password));
|
|
|
- focusView = m_etPassword;
|
|
|
- cancel = true;
|
|
|
- }
|
|
|
-
|
|
|
- // Check for a valid user name.
|
|
|
- if (TextUtils.isEmpty(m_sName))
|
|
|
- {
|
|
|
- m_etName.setError(getString(R.string.error_field_required));
|
|
|
- focusView = m_etName;
|
|
|
- cancel = true;
|
|
|
- }
|
|
|
- // else if (!m_sName.contains("@")) {
|
|
|
- // m_etName.setError(getString(R.string.error_invalid_email));
|
|
|
- // focusView = m_etName;
|
|
|
- // cancel = true;
|
|
|
- // }
|
|
|
-
|
|
|
- if (cancel)
|
|
|
- {
|
|
|
- // There was an error; don't attempt login and focus the first
|
|
|
- // form field with an error.
|
|
|
- focusView.requestFocus();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Show a progress spinner, and kick off a background task to
|
|
|
- // perform the user login attempt.
|
|
|
- mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
|
|
|
- showProgress(true);
|
|
|
- mAuthTask = new UserLoginTask();
|
|
|
- mAuthTask.execute((Void) null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Shows the progress UI and hides the login form.
|
|
|
- */
|
|
|
- @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
|
|
|
- private void showProgress(final boolean show)
|
|
|
- {
|
|
|
- // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
|
|
|
- // for very easy animations. If available, use these APIs to fade-in
|
|
|
- // the progress spinner.
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
|
|
|
- {
|
|
|
- int shortAnimTime = getResources().getInteger(
|
|
|
- android.R.integer.config_shortAnimTime);
|
|
|
-
|
|
|
- mLoginStatusView.setVisibility(View.VISIBLE);
|
|
|
- mLoginStatusView.animate().setDuration(shortAnimTime)
|
|
|
- .alpha(show ? 1 : 0)
|
|
|
- .setListener(new AnimatorListenerAdapter()
|
|
|
- {
|
|
|
- @Override
|
|
|
- public void onAnimationEnd(Animator animation)
|
|
|
- {
|
|
|
- mLoginStatusView.setVisibility(show ? View.VISIBLE
|
|
|
- : View.GONE);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- mLoginFormView.setVisibility(View.VISIBLE);
|
|
|
- mLoginFormView.animate().setDuration(shortAnimTime)
|
|
|
- .alpha(show ? 0 : 1)
|
|
|
- .setListener(new AnimatorListenerAdapter()
|
|
|
- {
|
|
|
- @Override
|
|
|
- public void onAnimationEnd(Animator animation)
|
|
|
- {
|
|
|
- mLoginFormView.setVisibility(show ? View.GONE
|
|
|
- : View.VISIBLE);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // The ViewPropertyAnimator APIs are not available, so simply show
|
|
|
- // and hide the relevant UI components.
|
|
|
- mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
- mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Represents an asynchronous login/registration task used to authenticate
|
|
|
- * the user.
|
|
|
- */
|
|
|
- public class UserLoginTask extends AsyncTask<Void, Void, Boolean>
|
|
|
- {
|
|
|
- // int err_code = ERR_CODE_NONE;
|
|
|
- int verifyuser = Network.RESULT_TRUE;
|
|
|
-
|
|
|
- // int netconnect;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected Boolean doInBackground(Void... params)
|
|
|
- {
|
|
|
-
|
|
|
- verifyuser = Network.VerifyUser(m_sName, m_sPassword);
|
|
|
- if (verifyuser == Network.RESULT_TRUE)
|
|
|
- return true;
|
|
|
- else
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onPostExecute(final Boolean success)
|
|
|
- {
|
|
|
- Log.i("onPostExecute", "entry");
|
|
|
- mAuthTask = null;
|
|
|
- showProgress(false);
|
|
|
-
|
|
|
- if (success)
|
|
|
- {
|
|
|
- String encryptUser="";
|
|
|
- String encryptPass="";
|
|
|
- try
|
|
|
- {
|
|
|
- encryptUser=AES.encrypt("apexu", m_sName);
|
|
|
- encryptPass= AES.encrypt("apexp", m_sPassword);
|
|
|
- }
|
|
|
- catch (Exception e1)
|
|
|
- {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e1.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- SQLiteDatabase db = dbUtil.OpenDB(LockerActivity.this, null,
|
|
|
- true);
|
|
|
- Cursor cursor = db
|
|
|
- .query("users", new String[] { "_id" }, "name='"
|
|
|
- + encryptUser + "'", null, null, null, "_id", null);
|
|
|
- if (cursor.moveToNext())
|
|
|
- {
|
|
|
- int _id = cursor.getInt(0);
|
|
|
- String sql = "update users set pass='" + encryptPass
|
|
|
- + "' where _id=" + _id;
|
|
|
- db.execSQL(sql);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- String sql = "insert into users(name,pass) values('"
|
|
|
- + encryptUser + "','" + encryptPass + "')";
|
|
|
- db.execSQL(sql);
|
|
|
- }
|
|
|
- dbUtil.CloseCursor(cursor);
|
|
|
- dbUtil.CloseDB(db);
|
|
|
-
|
|
|
- RedAntApplication.user = m_sName;
|
|
|
- RedAntApplication.password = m_sPassword;
|
|
|
- Intent intent = new Intent();
|
|
|
- setResult(Activity.RESULT_OK, intent);
|
|
|
- finish();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- switch (verifyuser)
|
|
|
- {
|
|
|
- case Network.RESULT_NET_ERROR:
|
|
|
- case Network.RESULT_NET_NOTAVAILABLE:
|
|
|
- {
|
|
|
- SQLiteDatabase db = dbUtil.OpenDB(LockerActivity.this,
|
|
|
- null, true);
|
|
|
-
|
|
|
- String encryptUser="";
|
|
|
- try
|
|
|
- {
|
|
|
- encryptUser=Crypto.encrypt("apexu", m_sName);
|
|
|
- }
|
|
|
- catch (Exception e1)
|
|
|
- {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e1.printStackTrace();
|
|
|
- }
|
|
|
- Cursor cursor = db.query("users", new String[] {
|
|
|
- "pass", "_id" }, "name= '" + encryptUser + "'",
|
|
|
- null, null, null, "_id desc", null);
|
|
|
- if (cursor.moveToNext())
|
|
|
- {
|
|
|
- String pass="";
|
|
|
- try
|
|
|
- {
|
|
|
- pass = Crypto.decrypt("apexp", cursor.getString(0));
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if (pass.equals(m_sPassword))
|
|
|
- {
|
|
|
- dbUtil.CloseCursor(cursor);
|
|
|
- dbUtil.CloseDB(db);
|
|
|
- RedAntApplication.user = m_sName;
|
|
|
- RedAntApplication.password = m_sPassword;
|
|
|
- Intent intent = new Intent();
|
|
|
- setResult(Activity.RESULT_OK, intent);
|
|
|
- finish();
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // wrong password
|
|
|
- Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
- getText(R.string.msg_user_wrong),
|
|
|
- Toast.LENGTH_LONG);
|
|
|
- toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
- toast.show();
|
|
|
- m_etPassword
|
|
|
- .setError(getString(R.string.error_incorrect_password));
|
|
|
- m_etPassword.requestFocus();
|
|
|
- dbUtil.CloseCursor(cursor);
|
|
|
- dbUtil.CloseDB(db);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {//wrong user
|
|
|
- Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
- getText(R.string.msg_user_wrong),
|
|
|
- Toast.LENGTH_LONG);
|
|
|
- toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
- toast.show();
|
|
|
- m_etPassword
|
|
|
- .setError(getString(R.string.error_incorrect_password));
|
|
|
- m_etPassword.requestFocus();
|
|
|
- dbUtil.CloseCursor(cursor);
|
|
|
- dbUtil.CloseDB(db);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
- }
|
|
|
-// case Network.RESULT_NET_ERROR:
|
|
|
-// {
|
|
|
-// Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
-// getText(R.string.msg_net_error),
|
|
|
-// Toast.LENGTH_LONG);
|
|
|
-// toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
-// toast.show();
|
|
|
-// return;
|
|
|
-// }
|
|
|
- case Network.RESULT_FALSE:
|
|
|
- {
|
|
|
- Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
- getText(R.string.msg_user_wrong),
|
|
|
- Toast.LENGTH_LONG);
|
|
|
- toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
- toast.show();
|
|
|
- m_etPassword
|
|
|
- .setError(getString(R.string.error_incorrect_password));
|
|
|
- m_etPassword.requestFocus();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCancelled()
|
|
|
- {
|
|
|
- mAuthTask = null;
|
|
|
- showProgress(false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-// /**
|
|
|
-// * A dummy authentication store containing known user names and passwords.
|
|
|
-// * TODO: remove after connecting to a real authentication system.
|
|
|
-// */
|
|
|
-// // private static final String[] DUMMY_CREDENTIALS = new String[] {
|
|
|
-// // "foo@example.com:hello", "bar@example.com:world" };
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * The default email to populate the email field with.
|
|
|
-// */
|
|
|
-// public static final String EXTRA_EMAIL = "com.example.android.authenticatordemo.extra.EMAIL";
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * Keep track of the login task to ensure we can cancel it if requested.
|
|
|
-// */
|
|
|
-// private UserLoginTask mAuthTask = null;
|
|
|
-// ArrayAdapter<String> adapter = null;
|
|
|
-// SQLiteDatabase m_db;
|
|
|
-// // Values for email and password at the time of the login attempt.
|
|
|
-// private String m_sName;
|
|
|
-// private String m_sPassword;
|
|
|
-//
|
|
|
-// // UI references.
|
|
|
-// private AutoCompleteTextView m_etName;
|
|
|
-// private EditText m_etPassword;
|
|
|
-// private View mLoginFormView;
|
|
|
-// private View mLoginStatusView;
|
|
|
-// private TextView mLoginStatusMessageView;
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// protected void onCreate(Bundle savedInstanceState)
|
|
|
-// {
|
|
|
-// super.onCreate(savedInstanceState);
|
|
|
-// setContentView(R.layout.activity_locker);
|
|
|
-//
|
|
|
-// // Set up the login form.
|
|
|
-// // m_sName = getIntent().getStringExtra(EXTRA_USER);
|
|
|
-// m_etName = (AutoCompleteTextView) findViewById(R.id.name);
|
|
|
-//
|
|
|
-// // m_etName.setText(m_sName);
|
|
|
-//
|
|
|
-// m_etPassword = (EditText) findViewById(R.id.password);
|
|
|
-// m_etPassword
|
|
|
-// .setOnEditorActionListener(new TextView.OnEditorActionListener()
|
|
|
-// {
|
|
|
-// @Override
|
|
|
-// public boolean onEditorAction(TextView textView, int id,
|
|
|
-// KeyEvent keyEvent)
|
|
|
-// {
|
|
|
-// Log.d("onEditorAction", "id=" + id + " keyevent="
|
|
|
-// + keyEvent);
|
|
|
-// if (id == R.id.locker
|
|
|
-// || id == EditorInfo.IME_ACTION_DONE)
|
|
|
-// {
|
|
|
-// attemptLogin();
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// mLoginFormView = findViewById(R.id.login_form);
|
|
|
-// mLoginStatusView = findViewById(R.id.login_status);
|
|
|
-// mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);
|
|
|
-//
|
|
|
-// findViewById(R.id.sign_in_button).setOnClickListener(
|
|
|
-// new View.OnClickListener()
|
|
|
-// {
|
|
|
-// @Override
|
|
|
-// public void onClick(View view)
|
|
|
-// {
|
|
|
-// attemptLogin();
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// adapter = new ArrayAdapter<String>(this,
|
|
|
-// android.R.layout.simple_list_item_1,
|
|
|
-// dbUtil.get_userlist());
|
|
|
-// m_etName.setAdapter(adapter);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public boolean onCreateOptionsMenu(Menu menu)
|
|
|
-// {
|
|
|
-// super.onCreateOptionsMenu(menu);
|
|
|
-// getMenuInflater().inflate(R.menu.locker, menu);
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public boolean onKeyDown(int keyCode, KeyEvent event)
|
|
|
-// {
|
|
|
-// if (keyCode == KeyEvent.KEYCODE_BACK)
|
|
|
-// {
|
|
|
-// // Intent myIntent = new Intent();
|
|
|
-// // myIntent = new Intent(EditActivity.this, tabActivity.class);
|
|
|
-// // startActivity(myIntent);
|
|
|
-// // this.finish();
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-// return super.onKeyDown(keyCode, event);
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * Attempts to sign in or register the account specified by the login form.
|
|
|
-// * If there are form errors (invalid email, missing fields, etc.), the
|
|
|
-// * errors are presented and no actual login attempt is made.
|
|
|
-// */
|
|
|
-// public void attemptLogin()
|
|
|
-// {
|
|
|
-// if (mAuthTask != null)
|
|
|
-// {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // Reset errors.
|
|
|
-// m_etName.setError(null);
|
|
|
-// m_etPassword.setError(null);
|
|
|
-//
|
|
|
-// // Store values at the time of the login attempt.
|
|
|
-// m_sName = m_etName.getText().toString();
|
|
|
-// m_sPassword = m_etPassword.getText().toString();
|
|
|
-//
|
|
|
-// boolean cancel = false;
|
|
|
-// View focusView = null;
|
|
|
-//
|
|
|
-// // Check for a valid password.
|
|
|
-// if (TextUtils.isEmpty(m_sPassword))
|
|
|
-// {
|
|
|
-// m_etPassword.setError(getString(R.string.error_field_required));
|
|
|
-// focusView = m_etPassword;
|
|
|
-// cancel = true;
|
|
|
-// }
|
|
|
-// else if (m_sPassword.length() < 4)
|
|
|
-// {
|
|
|
-// m_etPassword.setError(getString(R.string.error_invalid_password));
|
|
|
-// focusView = m_etPassword;
|
|
|
-// cancel = true;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // Check for a valid user name.
|
|
|
-// if (TextUtils.isEmpty(m_sName))
|
|
|
-// {
|
|
|
-// m_etName.setError(getString(R.string.error_field_required));
|
|
|
-// focusView = m_etName;
|
|
|
-// cancel = true;
|
|
|
-// }
|
|
|
-// // else if (!m_sName.contains("@")) {
|
|
|
-// // m_etName.setError(getString(R.string.error_invalid_email));
|
|
|
-// // focusView = m_etName;
|
|
|
-// // cancel = true;
|
|
|
-// // }
|
|
|
-//
|
|
|
-// if (cancel)
|
|
|
-// {
|
|
|
-// // There was an error; don't attempt login and focus the first
|
|
|
-// // form field with an error.
|
|
|
-// focusView.requestFocus();
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// // Show a progress spinner, and kick off a background task to
|
|
|
-// // perform the user login attempt.
|
|
|
-// mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
|
|
|
-// showProgress(true);
|
|
|
-// mAuthTask = new UserLoginTask();
|
|
|
-// mAuthTask.execute((Void) null);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * Shows the progress UI and hides the login form.
|
|
|
-// */
|
|
|
-// @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
|
|
|
-// private void showProgress(final boolean show)
|
|
|
-// {
|
|
|
-// // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
|
|
|
-// // for very easy animations. If available, use these APIs to fade-in
|
|
|
-// // the progress spinner.
|
|
|
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
|
|
|
-// {
|
|
|
-// int shortAnimTime = getResources().getInteger(
|
|
|
-// android.R.integer.config_shortAnimTime);
|
|
|
-//
|
|
|
-// mLoginStatusView.setVisibility(View.VISIBLE);
|
|
|
-// mLoginStatusView.animate().setDuration(shortAnimTime)
|
|
|
-// .alpha(show ? 1 : 0)
|
|
|
-// .setListener(new AnimatorListenerAdapter()
|
|
|
-// {
|
|
|
-// @Override
|
|
|
-// public void onAnimationEnd(Animator animation)
|
|
|
-// {
|
|
|
-// mLoginStatusView.setVisibility(show ? View.VISIBLE
|
|
|
-// : View.GONE);
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// mLoginFormView.setVisibility(View.VISIBLE);
|
|
|
-// mLoginFormView.animate().setDuration(shortAnimTime)
|
|
|
-// .alpha(show ? 0 : 1)
|
|
|
-// .setListener(new AnimatorListenerAdapter()
|
|
|
-// {
|
|
|
-// @Override
|
|
|
-// public void onAnimationEnd(Animator animation)
|
|
|
-// {
|
|
|
-// mLoginFormView.setVisibility(show ? View.GONE
|
|
|
-// : View.VISIBLE);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// // The ViewPropertyAnimator APIs are not available, so simply show
|
|
|
-// // and hide the relevant UI components.
|
|
|
-// mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
-// mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * Represents an asynchronous login/registration task used to authenticate
|
|
|
-// * the user.
|
|
|
-// */
|
|
|
-// public class UserLoginTask extends AsyncTask<Void, Void, Boolean>
|
|
|
-// {
|
|
|
-// @Override
|
|
|
-// protected Boolean doInBackground(Void... params)
|
|
|
-// {
|
|
|
-//
|
|
|
-// m_db = dbUtil.OpenDB(LockerActivity.this, null, true);
|
|
|
-//
|
|
|
-// Cursor cursor = m_db.query("users", new String[] { "pass", "_id" },
|
|
|
-// "name= '" + m_sName + "'", null, null, null, "_id desc",
|
|
|
-// null);
|
|
|
-// if (cursor.moveToNext())
|
|
|
-// {
|
|
|
-// // user exist in local db;
|
|
|
-// // Log.d(TAG, "USER "+m_sName+" exist!");
|
|
|
-// String pass = cursor.getString(0);
|
|
|
-// if (pass.equals(m_sPassword))
|
|
|
-// return true;
|
|
|
-// else
|
|
|
-// {
|
|
|
-// return false;// wrong password
|
|
|
-// }
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// // user not exist in local db;
|
|
|
-// try
|
|
|
-// {
|
|
|
-// // Simulate network access.
|
|
|
-// Thread.sleep(2000);
|
|
|
-// }
|
|
|
-// catch (InterruptedException e)
|
|
|
-// {
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// // TODO: register the new account here.
|
|
|
-// // online check user here;
|
|
|
-// if (true)// check pass create user in local db;
|
|
|
-// {
|
|
|
-// ContentValues cv = new ContentValues();
|
|
|
-// cv.put("name", m_sName);
|
|
|
-// cv.put("pass", m_sPassword);
|
|
|
-//
|
|
|
-// m_db.insert("users", null, cv);
|
|
|
-//
|
|
|
-// return true;
|
|
|
-//
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// // no user exist on the server;
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// protected void onPostExecute(final Boolean success)
|
|
|
-// {
|
|
|
-// mAuthTask = null;
|
|
|
-// showProgress(false);
|
|
|
-//
|
|
|
-// if (success)
|
|
|
-// {
|
|
|
-//
|
|
|
-// // SharedPreferences.Editor editor = RunOnce.edit();
|
|
|
-// // editor.putBoolean("FirstRun"+globalUtil.getVerName(this),
|
|
|
-// // false);
|
|
|
-// // // Don't forget to commit your edits!!!
|
|
|
-// // editor.commit();
|
|
|
-//
|
|
|
-// Intent intent = new Intent();
|
|
|
-// intent.putExtra("user", m_sName);
|
|
|
-// /*
|
|
|
-// * ����setResult������ʾ�ҽ�Intent���ظ�֮ǰ���Ǹ�Activity�������Ϳ���
|
|
|
-// * ��onActivityResult�����еõ�Intent����
|
|
|
-// */
|
|
|
-// setResult(Activity.RESULT_OK, intent);
|
|
|
-// finish();
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// m_etPassword
|
|
|
-// .setError(getString(R.string.error_incorrect_password));
|
|
|
-// m_etPassword.requestFocus();
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// protected void onCancelled()
|
|
|
-// {
|
|
|
-// mAuthTask = null;
|
|
|
-// showProgress(false);
|
|
|
-// }
|
|
|
-// }
|
|
|
-}
|