viernes, 29 de noviembre de 2019

practica android

Practica Android Colores y Enviar Parametros y Abrir 
Otra Actividad (Android 6.0 Api 23).






color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#2979FF</color>
    <color name="colorPrimaryDark">#00B0FF</color>
    <color name="colorAccent">#651FFF</color>
    <color name="fondo">#FFFFFF</color>
    <color name="boton">#859C8F</color>
    <color name="letraboton">#FFFFFF</color>
    <color name="letra">#651FFF</color>
</resources>

/////////////////////////////////////////////////////////////////


style.xml

<resources>
<!-- Base application theme. --><style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
</style>

</resources>
////////////////////////////////////////////////////////////////
Imagen de Logina
user.png

///////////////////////////////////////////////////////////////////////////////////////

Clase Usuario

public class Usuario {
    private String usuario;
    private String password;

    public Usuario(String usuario, String password) {
        this.usuario = usuario;
        this.password = password;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean validarUsuario(){
    boolean ret=(usuario.equals("admin") & password.equals("123456"))?true:false;
    return ret;
    }
}

//////////////////////////////////////////////////////////////////

Activity_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/fondo"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20sp"
            android:layout_marginBottom="20sp"
            android:gravity="center"
            android:text="Entrada del Sistema"
            android:textColor="@color/letra"
            android:textSize="24sp" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="154dp"
            android:layout_height="98dp"
            android:layout_gravity="center"
            app:srcCompat="@drawable/user" />

        <EditText
            android:id="@+id/usertext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="Usuario"
            android:inputType="textPersonName"
            android:textColor="@color/letra"
            android:textColorHint="@color/letra" />

        <EditText
            android:id="@+id/passtext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20sp"
            android:ems="10"
            android:hint="Password"
            android:inputType="textPassword"
            android:textColor="@color/letra"
            android:textColorHint="@color/letra" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10sp"
            android:layout_marginRight="10sp"
            android:background="@color/colorPrimary"
            android:elevation="5sp"
             android:padding="20sp"
            android:text="Entrar"
            android:textColor="@color/letraboton"
            android:textSize="18sp" />

    </LinearLayout>
</android.support.constraint.ConstraintLayout>

////////////////////////////////////////////////////////////////

activity_zona

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ZonaActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/userlogtext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="24sp" />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

/////////////////////////////////////////////////////////////////
metodo entrar

public void entrar(View view){
    int x=1;
    double y=4.5;
    boolean b=true;
    char c='f';
    String user=usertext.getText().toString();
    String pass=passtext.getText().toString();
    Intent intent=new Intent(this,ZonaActivity.class);
    Usuario usuario=new Usuario(user,pass);
    Bundle bundle=new Bundle();
    bundle.putString("usuario",usuario.getUsuario());
   
    intent.putExtra("bundle",bundle);

    if(usuario.validarUsuario()==true){
        startActivity(intent);
    }
    else{
        Toast.makeText(this,"Usuario o Password Invalido",
                Toast.LENGTH_SHORT).show();
    }
}

/////////////////////////////////////////////////////////////////
mostrar en zonactivity


Bundle bundle=getIntent().getExtras().getBundle("bundle");
String usuario=bundle.getString("usuario");
userlogtext.setText("Bienvenido "+usuario);

/////////////////////////////////////////////////////////////////

Descargar Proyecto