Guest User

Untitled

a guest
Jul 19th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. public class Main extends Activity{
  2.  
  3.     EditText username, password;
  4.     Button login;
  5.     CheckBox rememberme;
  6.     SQLiteDatabase sq;
  7.     TextView gotoReg;
  8.     static boolean TrueOrNot = true;
  9.     static String TAG = Main.class.getSimpleName();
  10.     public static XMPPConnection conn;
  11.     VCard card = null;
  12.     Bitmap Myimage;
  13.     static String getUsername;
  14.     static String getPassword;
  15.     LoginDatabaseHandle re;
  16.     SharedPreferences pre;
  17.  
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         // TODO Auto-generated method stub
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.startlayout);
  23.  
  24.         cleaningup();
  25.        
  26.         login.setOnClickListener(new OnClickListener() {
  27.  
  28.             @Override
  29.             public void onClick(View v) {
  30.                 new LoginTask().execute();
  31.             }
  32.         });
  33.  
  34.     private void cleaningup() {
  35.  
  36.        
  37.         login = (Button) findViewById(R.id.buttonlogin);
  38.         // rememberme = (CheckBox) findViewById(R.id.checkBoxlogin);
  39.  
  40.     }
  41.  
  42.     public class LoginTask extends AsyncTask<Void, Void, Void> {
  43.         private ProgressDialog loading;
  44.        
  45.  
  46.         @Override
  47.         protected void onPreExecute() {
  48.             loading = ProgressDialog.show(Main.this, "", "Loading...");
  49.         }
  50.  
  51.         @Override
  52.         protected Void doInBackground(Void... params) {
  53.  
  54.             username = (EditText) findViewById(R.id.editloginusername);
  55.             password = (EditText) findViewById(R.id.editloginpassword);
  56.             password.setInputType(InputType.TYPE_CLASS_TEXT
  57.                     | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  58.             // setup XMPP connection
  59.             ConnectionConfiguration config = new ConnectionConfiguration(
  60.                     "chat.facebook.com", 5222, "chat.facebook.com");
  61.             config.setDebuggerEnabled(true);
  62.             config.setSASLAuthenticationEnabled(true); // TRUE for fb
  63.             conn = new XMPPConnection(config);
  64.  
  65.             try {
  66.                 // attempt login
  67.                 conn.connect();
  68.                 SASLAuthentication.supportSASLMechanism("PLAIN", 0);
  69.                 conn.login(username.getText().toString(), password.getText().toString());
  70.                 Presence presence = new Presence(Presence.Type.available);
  71.                 conn.sendPacket(presence);
  72.                 // AsmackChat.setConnection(conn);
  73.  
  74.                 Log.d("TRACE", "isAuthenticated? " + conn.isAuthenticated());
  75.  
  76.                 if (conn.isAuthenticated()) {
  77.  
  78.                     Intent i = new Intent(Main.this, BuddyList.class);
  79.                     startActivity(i);
  80.                     loading.dismiss();
  81.  
  82.                 } else {
  83.  
  84.                     Toast.makeText(getApplicationContext(),
  85.                             " Username or Password incorrect. Try again !!",
  86.                             Toast.LENGTH_SHORT).show();
  87.                 }
  88.             } catch (Exception e) {
  89.                 Log.d("EXCEPTION", e.toString());
  90.             }
  91.  
  92.             return null;
  93.         }
  94.  
  95.     }
  96.  
  97. }
Add Comment
Please, Sign In to add comment