Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.android.login;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.text.Editable;
- import android.util.Log;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.message.BasicNameValuePair;
- import org.json.JSONArray;
- import org.json.JSONObject;
- public class LoginActivity
- extends Activity
- {
- EditText pass;
- EditText user;
- Button validar;
- public void onCreate(Bundle paramBundle)
- {
- super.onCreate(paramBundle);
- setContentView(2130903043);
- this.user = ((EditText)findViewById(2131034118));
- this.pass = ((EditText)findViewById(2131034119));
- this.validar = ((Button)findViewById(2131034120));
- ((TextView)findViewById(2131034121)).setOnClickListener(new View.OnClickListener()
- {
- public void onClick(View paramAnonymousView)
- {
- paramAnonymousView = new Intent(LoginActivity.this.getApplicationContext(), RegisterActivity.class);
- LoginActivity.this.startActivity(paramAnonymousView);
- }
- });
- this.validar.setOnClickListener(new View.OnClickListener()
- {
- public void onClick(View paramAnonymousView)
- {
- paramAnonymousView = new ArrayList();
- paramAnonymousView.add("Usuario");
- paramAnonymousView.add(LoginActivity.this.user.getText().toString());
- paramAnonymousView.add("Contrasena");
- paramAnonymousView.add(LoginActivity.this.pass.getText().toString());
- try
- {
- paramAnonymousView = new LoginActivity.Post(LoginActivity.this).getServerData(paramAnonymousView, "http://nosscier.16mb.com/login.php");
- if ((paramAnonymousView != null) && (paramAnonymousView.length() > 0))
- {
- Object localObject = paramAnonymousView.getJSONObject(0);
- if (((JSONObject)localObject).getInt("id") > 0)
- {
- Toast.makeText(LoginActivity.this.getBaseContext(), "Usuario correcto. Cargando...", 0).show();
- paramAnonymousView = new Intent(LoginActivity.this.getApplicationContext(), WelcomeActivity.class);
- String str1 = LoginActivity.this.user.getText().toString();
- String str2 = ((JSONObject)localObject).getString("email").toString();
- localObject = ((JSONObject)localObject).getString("pais").toString();
- Bundle localBundle = new Bundle();
- localBundle.putString("NICK", str1);
- localBundle.putString("EMAIL", str2);
- localBundle.putString("PAIS", (String)localObject);
- paramAnonymousView.putExtras(localBundle);
- LoginActivity.this.startActivity(paramAnonymousView);
- }
- }
- else
- {
- Toast.makeText(LoginActivity.this.getBaseContext(), "Usuario o contrase�a incorrectos", 0).show();
- return;
- }
- }
- catch (Exception paramAnonymousView)
- {
- Toast.makeText(LoginActivity.this.getBaseContext(), "Necesitas conexi�n a Internet para utilizar Nosscier. Error al conectar con el servidor", 0).show();
- }
- }
- });
- }
- class Post
- {
- private InputStream is = null;
- private String respuesta = "";
- Post() {}
- private void conectaPost(ArrayList<String> paramArrayList, String paramString)
- {
- try
- {
- DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
- paramString = new HttpPost(paramString);
- ArrayList localArrayList = new ArrayList();
- int i;
- if (paramArrayList != null) {
- i = 0;
- }
- for (;;)
- {
- if (i >= paramArrayList.size() - 1)
- {
- paramString.setEntity(new UrlEncodedFormEntity(localArrayList));
- this.is = localDefaultHttpClient.execute(paramString).getEntity().getContent();
- return;
- }
- localArrayList.add(new BasicNameValuePair((String)paramArrayList.get(i), (String)paramArrayList.get(i + 1)));
- i += 2;
- }
- return;
- }
- catch (Exception paramArrayList)
- {
- Log.e("log_tag", "Error in http connection " + paramArrayList.toString());
- }
- }
- /* Error */
- private JSONArray getJsonArray()
- {
- // Byte code:
- // 0: new 116 org/json/JSONArray
- // 3: dup
- // 4: aload_0
- // 5: getfield 26 com/android/login/LoginActivity$Post:respuesta Ljava/lang/String;
- // 8: invokespecial 117 org/json/JSONArray:<init> (Ljava/lang/String;)V
- // 11: astore_1
- // 12: aload_1
- // 13: areturn
- // 14: astore_1
- // 15: aconst_null
- // 16: areturn
- // 17: astore_1
- // 18: aconst_null
- // 19: areturn
- // Local variable table:
- // start length slot name signature
- // 0 20 0 this Post
- // 11 2 1 localJSONArray JSONArray
- // 14 1 1 localObject Object
- // 17 1 1 localException Exception
- // Exception table:
- // from to target type
- // 0 12 14 finally
- // 0 12 17 java/lang/Exception
- }
- private void getRespuestaPost()
- {
- try
- {
- BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(this.is, "iso-8859-1"), 8);
- StringBuilder localStringBuilder = new StringBuilder();
- for (;;)
- {
- String str = localBufferedReader.readLine();
- if (str == null)
- {
- this.is.close();
- this.respuesta = localStringBuilder.toString();
- Log.e("log_tag", "Cadena JSon " + this.respuesta);
- return;
- }
- localStringBuilder.append(str + "\n");
- }
- return;
- }
- catch (Exception localException)
- {
- Log.e("log_tag", "Error converting result " + localException.toString());
- }
- }
- public JSONArray getServerData(ArrayList<String> paramArrayList, String paramString)
- {
- conectaPost(paramArrayList, paramString);
- if (this.is != null) {
- getRespuestaPost();
- }
- if ((this.respuesta != null) && (this.respuesta.trim() != "")) {
- return getJsonArray();
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement