Guest User

Untitled

a guest
Feb 8th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. package loginClient;
  2.  
  3. import gameClient.GameMain;
  4.  
  5. import org.jivesoftware.smack.ConnectionConfiguration;
  6. import org.jivesoftware.smack.XMPPConnection;
  7. import org.jivesoftware.smack.XMPPException;
  8.  
  9. import android.app.Activity;
  10. import android.app.ProgressDialog;
  11. import android.content.Context;
  12. import android.content.Intent;
  13. import android.os.AsyncTask;
  14. import android.os.Handler;
  15. import android.util.Log;
  16. import android.widget.Toast;
  17.  
  18. public class networkTask extends AsyncTask<Context, Integer, Boolean> {
  19. Handler handler;
  20. public static XMPPConnection connection;
  21. public static String username;
  22. public static String password;
  23. ProgressDialog dialog;
  24.  
  25. Activity acti;
  26.  
  27.  
  28.  
  29.  
  30. public static String getUsername() {
  31. return username;
  32. }
  33. public static void setUsername(String username) {
  34. networkTask.username = username;
  35. }
  36. public static String getPassword() {
  37. return password;
  38. }
  39. public static void setPassword(String password) {
  40. networkTask.password = password;
  41. }
  42.  
  43. public networkTask(String u, String p,Activity activity){
  44. username = u;
  45. password = p;
  46. acti = activity;
  47.  
  48.  
  49. }
  50.  
  51. public void disconnect(){
  52. connection.disconnect();
  53. }
  54.  
  55. protected void onPreExecute(){
  56. dialog = ProgressDialog.show(acti.getApplicationContext(), "Loading", "Logging in...");
  57.  
  58. }
  59.  
  60. protected Boolean doInBackground(Context...arg0){
  61.  
  62. try{
  63. ConnectionConfiguration config = new ConnectionConfiguration("vps01.fit3140hack.org", 5222);
  64. Log.d("Iteration to Network", "Starting app");
  65. config.setSASLAuthenticationEnabled(true);
  66. connection = new XMPPConnection(config);
  67.  
  68. Log.d("Iteration to Network", "Connecting");
  69. connection.connect();
  70. connection.login(username,password);
  71. Log.d("Iteration to Network", "Logged in");
  72. return true;
  73. }
  74. catch(Exception e){
  75. e.printStackTrace();
  76. return false;
  77. }
  78.  
  79.  
  80.  
  81.  
  82. }
  83.  
  84.  
  85. protected void onPostExecute(final Boolean success){
  86. if(success)
  87. dialog.setMessage("Succesfully Logged in");
  88. else
  89. dialog.setMessage("Failed to Log in");
  90.  
  91. try {
  92. this.wait(1000);
  93. } catch (InterruptedException e) {
  94. // TODO Auto-generated catch block
  95. e.printStackTrace();
  96. }
  97.  
  98. if(dialog.isShowing())
  99. dialog.dismiss();
  100. }
  101.  
  102. protected void onProgressUpdate(Integer...values){
  103. super.onProgressUpdate(values);
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. }
Add Comment
Please, Sign In to add comment