Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends Activity{
- EditText username, password;
- Button login;
- CheckBox rememberme;
- SQLiteDatabase sq;
- TextView gotoReg;
- static boolean TrueOrNot = true;
- static String TAG = Main.class.getSimpleName();
- public static XMPPConnection conn;
- VCard card = null;
- Bitmap Myimage;
- static String getUsername;
- static String getPassword;
- LoginDatabaseHandle re;
- SharedPreferences pre;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.startlayout);
- cleaningup();
- login.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- new LoginTask().execute();
- }
- });
- private void cleaningup() {
- login = (Button) findViewById(R.id.buttonlogin);
- // rememberme = (CheckBox) findViewById(R.id.checkBoxlogin);
- }
- public class LoginTask extends AsyncTask<Void, Void, Void> {
- private ProgressDialog loading;
- @Override
- protected void onPreExecute() {
- loading = ProgressDialog.show(Main.this, "", "Loading...");
- }
- @Override
- protected Void doInBackground(Void... params) {
- username = (EditText) findViewById(R.id.editloginusername);
- password = (EditText) findViewById(R.id.editloginpassword);
- password.setInputType(InputType.TYPE_CLASS_TEXT
- | InputType.TYPE_TEXT_VARIATION_PASSWORD);
- // setup XMPP connection
- ConnectionConfiguration config = new ConnectionConfiguration(
- "chat.facebook.com", 5222, "chat.facebook.com");
- config.setDebuggerEnabled(true);
- config.setSASLAuthenticationEnabled(true); // TRUE for fb
- conn = new XMPPConnection(config);
- try {
- // attempt login
- conn.connect();
- SASLAuthentication.supportSASLMechanism("PLAIN", 0);
- conn.login(username.getText().toString(), password.getText().toString());
- Presence presence = new Presence(Presence.Type.available);
- conn.sendPacket(presence);
- // AsmackChat.setConnection(conn);
- Log.d("TRACE", "isAuthenticated? " + conn.isAuthenticated());
- if (conn.isAuthenticated()) {
- Intent i = new Intent(Main.this, BuddyList.class);
- startActivity(i);
- loading.dismiss();
- } else {
- Toast.makeText(getApplicationContext(),
- " Username or Password incorrect. Try again !!",
- Toast.LENGTH_SHORT).show();
- }
- } catch (Exception e) {
- Log.d("EXCEPTION", e.toString());
- }
- return null;
- }
- }
- }
Add Comment
Please, Sign In to add comment