<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="20dip">
<EditText android:id="@+id/txtEmail" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:hint="Email" android:inputType="textEmailAddress" />
<EditText android:id="@+id/txtPass" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:hint="Password" android:inputType="textPassword"
android:layout_marginTop="15dip" android:layout_marginBottom="30dip" />
<Button android:id="@+id/btnLogin" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="enviar"
android:layout_gravity="center_horizontal" android:paddingLeft="15dip" android:paddingRight="15dip" />
<TextView android:id="@+id/link_to_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:text="registrate!"
android:gravity="center"
android:textSize="20dip"
android:textColor="#0b84aa"/>
<TextView android:id="@+id/login_error"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:gravity="center"
android:textSize="20dip"
android:textColor="#0b84aa"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="20dip" android:orientation="vertical">
<EditText android:id="@+id/txtUserName" android:layout_height="wrap_content" android:layout_width="fill_parent"
android:hint="UserName" android:inputType="text" />
<EditText android:id="@+id/txtEmail" android:layout_marginTop="15dip" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:hint="Email" android:inputType="textEmailAddress" />
<EditText android:id="@+id/txtPass" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:hint="Password" android:inputType="textPassword"
android:layout_marginTop="15dip" android:layout_marginBottom="30dip" />
<Button android:id="@+id/btnRegister" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="enviar"
android:layout_gravity="center_horizontal" android:paddingLeft="15dip" android:paddingRight="15dip" />
<TextView android:id="@+id/link_to_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:text="Ya tienes cuenta! Accede!"
android:gravity="center"
android:textSize="20dip"
android:textColor="#0b84aa"/>
<TextView android:id="@+id/register_error"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:gravity="center"
android:textSize="20dip"
android:textColor="#0b84aa"/>
</LinearLayout>
public class Login extends Activity {
private TextView lblGotoRegister;
private Button btnLogin;
private EditText inputEmail;
private EditText inputPassword;
private TextView loginErrorMsg;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
inputEmail = (EditText) findViewById(R.id.txtEmail);
inputPassword = (EditText) findViewById(R.id.txtPass);
btnLogin = (Button) findViewById(R.id.btnLogin);
loginErrorMsg = (TextView) findViewById(R.id.login_error);
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
Usuario usuario = new Usuario();
usuario.setOnLoginUsuario(new OnLoginUsuario() {
@Override
public void onLoginWrong(String msg) {loginErrorMsg.setText(msg);}
@Override
public void onLoginCorrect(JSONObject json, String msg) {
loginErrorMsg.setText("");
Intent itemintent = new Intent(Login.this, ActivityPrincipal.class);
Login.this.startActivity(itemintent);
}
});
usuario.login(Login.this, email, password);
}
});
lblGotoRegister = (TextView) findViewById(R.id.link_to_register);
lblGotoRegister.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {Intent itemintent = new Intent(Login.this, Register.class);
Login.this.startActivity(itemintent);}
});
}
}
public class Register extends Activity {
private TextView lblGotoLogin;
private Button btnRegister;
private EditText inputFullName;
private EditText inputEmail;
private EditText inputPassword;
private TextView registerErrorMsg;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
inputFullName = (EditText) findViewById(R.id.txtUserName);
inputEmail = (EditText) findViewById(R.id.txtEmail);
inputPassword = (EditText) findViewById(R.id.txtPass);
btnRegister = (Button) findViewById(R.id.btnRegister);
registerErrorMsg = (TextView) findViewById(R.id.register_error);
btnRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String name = inputFullName.getText().toString();
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
Usuario usuario = new Usuario();
usuario.setOnRegisterUsuario(new OnRegisterUsuario() {
@Override
public void onRegisterFinish(JSONObject json, String msg) {
registerErrorMsg.setText("");
Intent itemintent = new Intent(Login.this, ActivityPrincipal.class);
Register.this.startActivity(itemintent);>
}
@Override
public void onRegisterFail(String msg) {registerErrorMsg.setText(msg);}
@Override
public void onRegisterException(Exception e, String msg) {registerErrorMsg.setText(msg);}
});
usuario.register(Register.this, name, email, password);
}
});
lblGotoLogin = (TextView) findViewById(R.id.link_to_login);
lblGotoLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {Intent itemintent = new Intent(Register.this, Login.class);
Register.this.startActivity(itemintent);}
});
}
}