Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.83 KB | None | 0 0
  1. package com.android.login;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.text.Editable;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14. import java.io.BufferedReader;
  15. import java.io.InputStream;
  16. import java.io.InputStreamReader;
  17. import java.util.ArrayList;
  18. import org.apache.http.HttpEntity;
  19. import org.apache.http.HttpResponse;
  20. import org.apache.http.client.HttpClient;
  21. import org.apache.http.client.entity.UrlEncodedFormEntity;
  22. import org.apache.http.client.methods.HttpPost;
  23. import org.apache.http.impl.client.DefaultHttpClient;
  24. import org.apache.http.message.BasicNameValuePair;
  25. import org.json.JSONArray;
  26. import org.json.JSONObject;
  27.  
  28. public class LoginActivity
  29.   extends Activity
  30. {
  31.   EditText pass;
  32.   EditText user;
  33.   Button validar;
  34.  
  35.   public void onCreate(Bundle paramBundle)
  36.   {
  37.     super.onCreate(paramBundle);
  38.     setContentView(2130903043);
  39.     this.user = ((EditText)findViewById(2131034118));
  40.     this.pass = ((EditText)findViewById(2131034119));
  41.     this.validar = ((Button)findViewById(2131034120));
  42.     ((TextView)findViewById(2131034121)).setOnClickListener(new View.OnClickListener()
  43.     {
  44.       public void onClick(View paramAnonymousView)
  45.       {
  46.         paramAnonymousView = new Intent(LoginActivity.this.getApplicationContext(), RegisterActivity.class);
  47.         LoginActivity.this.startActivity(paramAnonymousView);
  48.       }
  49.     });
  50.     this.validar.setOnClickListener(new View.OnClickListener()
  51.     {
  52.       public void onClick(View paramAnonymousView)
  53.       {
  54.         paramAnonymousView = new ArrayList();
  55.         paramAnonymousView.add("Usuario");
  56.         paramAnonymousView.add(LoginActivity.this.user.getText().toString());
  57.         paramAnonymousView.add("Contrasena");
  58.         paramAnonymousView.add(LoginActivity.this.pass.getText().toString());
  59.         try
  60.         {
  61.           paramAnonymousView = new LoginActivity.Post(LoginActivity.this).getServerData(paramAnonymousView, "http://nosscier.16mb.com/login.php");
  62.           if ((paramAnonymousView != null) && (paramAnonymousView.length() > 0))
  63.           {
  64.             Object localObject = paramAnonymousView.getJSONObject(0);
  65.             if (((JSONObject)localObject).getInt("id") > 0)
  66.             {
  67.               Toast.makeText(LoginActivity.this.getBaseContext(), "Usuario correcto. Cargando...", 0).show();
  68.               paramAnonymousView = new Intent(LoginActivity.this.getApplicationContext(), WelcomeActivity.class);
  69.               String str1 = LoginActivity.this.user.getText().toString();
  70.               String str2 = ((JSONObject)localObject).getString("email").toString();
  71.               localObject = ((JSONObject)localObject).getString("pais").toString();
  72.               Bundle localBundle = new Bundle();
  73.               localBundle.putString("NICK", str1);
  74.               localBundle.putString("EMAIL", str2);
  75.               localBundle.putString("PAIS", (String)localObject);
  76.               paramAnonymousView.putExtras(localBundle);
  77.               LoginActivity.this.startActivity(paramAnonymousView);
  78.             }
  79.           }
  80.           else
  81.           {
  82.             Toast.makeText(LoginActivity.this.getBaseContext(), "Usuario o contrase�a incorrectos", 0).show();
  83.             return;
  84.           }
  85.         }
  86.         catch (Exception paramAnonymousView)
  87.         {
  88.           Toast.makeText(LoginActivity.this.getBaseContext(), "Necesitas conexi�n a Internet para utilizar Nosscier. Error al conectar con el servidor", 0).show();
  89.         }
  90.       }
  91.     });
  92.   }
  93.  
  94.   class Post
  95.   {
  96.     private InputStream is = null;
  97.     private String respuesta = "";
  98.    
  99.     Post() {}
  100.    
  101.     private void conectaPost(ArrayList<String> paramArrayList, String paramString)
  102.     {
  103.       try
  104.       {
  105.         DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
  106.         paramString = new HttpPost(paramString);
  107.         ArrayList localArrayList = new ArrayList();
  108.         int i;
  109.         if (paramArrayList != null) {
  110.           i = 0;
  111.         }
  112.         for (;;)
  113.         {
  114.           if (i >= paramArrayList.size() - 1)
  115.           {
  116.             paramString.setEntity(new UrlEncodedFormEntity(localArrayList));
  117.             this.is = localDefaultHttpClient.execute(paramString).getEntity().getContent();
  118.             return;
  119.           }
  120.           localArrayList.add(new BasicNameValuePair((String)paramArrayList.get(i), (String)paramArrayList.get(i + 1)));
  121.           i += 2;
  122.         }
  123.         return;
  124.       }
  125.       catch (Exception paramArrayList)
  126.       {
  127.         Log.e("log_tag", "Error in http connection " + paramArrayList.toString());
  128.       }
  129.     }
  130.    
  131.     /* Error */
  132.     private JSONArray getJsonArray()
  133.     {
  134.       // Byte code:
  135.       //   0: new 116   org/json/JSONArray
  136.       //   3: dup
  137.       //   4: aload_0
  138.       //   5: getfield 26   com/android/login/LoginActivity$Post:respuesta  Ljava/lang/String;
  139.       //   8: invokespecial 117 org/json/JSONArray:<init>   (Ljava/lang/String;)V
  140.       //   11: astore_1
  141.       //   12: aload_1
  142.       //   13: areturn
  143.       //   14: astore_1
  144.       //   15: aconst_null
  145.       //   16: areturn
  146.       //   17: astore_1
  147.       //   18: aconst_null
  148.       //   19: areturn
  149.       // Local variable table:
  150.       //   start    length  slot    name    signature
  151.       //   0    20  0   this    Post
  152.       //   11   2   1   localJSONArray  JSONArray
  153.       //   14   1   1   localObject Object
  154.       //   17   1   1   localException  Exception
  155.       // Exception table:
  156.       //   from to  target  type
  157.       //   0    12  14  finally
  158.       //   0    12  17  java/lang/Exception
  159.     }
  160.    
  161.     private void getRespuestaPost()
  162.     {
  163.       try
  164.       {
  165.         BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(this.is, "iso-8859-1"), 8);
  166.         StringBuilder localStringBuilder = new StringBuilder();
  167.         for (;;)
  168.         {
  169.           String str = localBufferedReader.readLine();
  170.           if (str == null)
  171.           {
  172.             this.is.close();
  173.             this.respuesta = localStringBuilder.toString();
  174.             Log.e("log_tag", "Cadena JSon " + this.respuesta);
  175.             return;
  176.           }
  177.           localStringBuilder.append(str + "\n");
  178.         }
  179.         return;
  180.       }
  181.       catch (Exception localException)
  182.       {
  183.         Log.e("log_tag", "Error converting result " + localException.toString());
  184.       }
  185.     }
  186.    
  187.     public JSONArray getServerData(ArrayList<String> paramArrayList, String paramString)
  188.     {
  189.       conectaPost(paramArrayList, paramString);
  190.       if (this.is != null) {
  191.         getRespuestaPost();
  192.       }
  193.       if ((this.respuesta != null) && (this.respuesta.trim() != "")) {
  194.         return getJsonArray();
  195.       }
  196.       return null;
  197.     }
  198.   }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement