Sei sulla pagina 1di 10

AndroidManifest.

xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity android:name=".MainActivity"> </activity>
</application>

</manifest>

activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/LoginTv"
android:textSize="50sp"
android:text="!Bienvenido!"
android:paddingVertical="30dp"
android:paddingHorizontal="40dp">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Lgnombre"
android:textSize="25sp"
android:text="Ingrese su nombre:"
android:layout_marginHorizontal="40dp">
</TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:id="@+id/LgEdit">
</EditText>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginHorizontal="40dp"
android:text="Siguiente"
android:onClick="onClick">
</Button>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/LgAviso"
android:textSize="25sp"
android:text=" "
android:layout_marginHorizontal="40dp"
android:layout_marginVertical="20dp">
</TextView>

</LinearLayout>

LoginActivity.java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.view.View;
import android.widget.TextView;

public class LoginActivity extends AppCompatActivity {

EditText LgEdit;
TextView LgAlert;
String Name;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
LgEdit = findViewById(R.id.LgEdit);
LgAlert = findViewById(R.id.LgAviso);
}

public void onClick(View view){


Name = String.valueOf(LgEdit.getText());

if ("".equals(Name)){
LgAlert.setText("Tu nombre es Requerido"); }
else {
Intent Next = new Intent(this, MainActivity.class);
Next.putExtra("Name", Name);
startActivity(Next);
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ViewB"
android:textSize="50sp"
android:text=""
android:paddingVertical="15dp"
android:paddingHorizontal="30dp"
android:layout_alignParentTop="true">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Label"
android:textSize="25sp"
android:text="Cambio:"
android:layout_below="@+id/ViewB"
android:paddingHorizontal="30dp">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ViewB2"
android:textSize="50sp"
android:text=""
android:paddingVertical="15dp"
android:paddingHorizontal="30dp"
android:layout_below="@+id/Label">
</TextView>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/LabelName"
android:textSize="20sp"
android:text=" Usuario"
android:layout_above="@+id/MnB"
android:paddingHorizontal="30dp">
</TextView>

<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/Teclado"
android:id="@+id/MnB"
android:stretchColumns="*">
<TableRow>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Mn1"
android:textOn="£GBP"
android:textOff="£GBP">
</ToggleButton>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Mn2"
android:textOn="$USD"
android:textOff="$USD">
</ToggleButton>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Mn3"
android:textOn="€EUR"
android:textOff="€EUR">
</ToggleButton>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Mn4"
android:textOn="$MXN"
android:textOff="$MXN">
</ToggleButton>
</TableRow>

</TableLayout>

<TableLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:stretchColumns="*"
android:layout_alignParentBottom="true"
android:id="@+id/Teclado">

<TableRow
android:layout_height="wrap_content">

<Button
android:id="@+id/Btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="40sp"
android:gravity="center"/>
</TableRow>

<TableRow
android:layout_height="wrap_content">

<Button
android:id="@+id/Btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:textSize="40sp"
android:gravity="center"/>
</TableRow>
<TableRow
android:layout_height="wrap_content">

<Button
android:id="@+id/Btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:textSize="40sp"
android:gravity="center"/>
</TableRow>
<TableRow
android:layout_height="wrap_content">

<Button
android:id="@+id/Clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cl"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btn0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="40sp"
android:gravity="center"/>
<Button
android:id="@+id/Btnp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:textSize="40sp"
android:gravity="center"/>
</TableRow>
</TableLayout>
</RelativeLayout>
MainActivity.java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Button;
import android.view.View;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {

TextView ViewB,ViewB2,LabelName;
Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btnp,
Clear;
ToggleButton Mn1,Mn2,Mn3,Mn4;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ViewB = findViewById(R.id.ViewB);
ViewB2 = findViewById(R.id.ViewB2);
LabelName = findViewById(R.id.LabelName);
btn0 = findViewById(R.id.Btn0);
btn1 = findViewById(R.id.Btn1);
btn2 = findViewById(R.id.Btn2);
btn3 = findViewById(R.id.Btn3);
btn4 = findViewById(R.id.Btn4);
btn5 = findViewById(R.id.Btn5);
btn6 = findViewById(R.id.Btn6);
btn7 = findViewById(R.id.Btn7);
btn8 = findViewById(R.id.Btn8);
btn9 = findViewById(R.id.Btn9);
btnp = findViewById(R.id.Btnp);
Clear = findViewById(R.id.Clear);
Mn1 = findViewById(R.id.Mn1);
Mn2 = findViewById(R.id.Mn2);
Mn3 = findViewById(R.id.Mn3);
Mn4 = findViewById(R.id.Mn4);

btn0.setOnClickListener(this);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
btn4.setOnClickListener(this);
btn5.setOnClickListener(this);
btn6.setOnClickListener(this);
btn7.setOnClickListener(this);
btn8.setOnClickListener(this);
btn9.setOnClickListener(this);
btnp.setOnClickListener(this);
Clear.setOnClickListener(this);
Mn1.setOnClickListener(this);
Mn2.setOnClickListener(this);
Mn3.setOnClickListener(this);
Mn4.setOnClickListener(this);

GetExtra();
}

@Override
public void onClick(android.view.View v) {
switch (v.getId()) {
case R.id.Btn0:
SetView("0");
break;
case R.id.Btn1:
SetView("1");
break;
case R.id.Btn2:
SetView("2");
break;
case R.id.Btn3:
SetView("3");
break;
case R.id.Btn4:
SetView("4");
break;
case R.id.Btn5:
SetView("5");
break;
case R.id.Btn6:
SetView("6");
break;
case R.id.Btn7:
SetView("7");
break;
case R.id.Btn8:
SetView("8");
break;
case R.id.Btn9:
SetView("9");
break;
case R.id.Btnp:
SetView(".");
break;
case R.id.Clear:
ViewB.setText("");
ViewB2.setText("");
break;
case R.id.Mn1:
Convert(69.51f);
Mn1.setChecked(true);
Mn2.setChecked(false);
Mn3.setChecked(false);
Mn4.setChecked(false);
break;
case R.id.Mn2:
Convert(53.31f);
Mn1.setChecked(false);
Mn2.setChecked(true);
Mn3.setChecked(false);
Mn4.setChecked(false);
break;
case R.id.Mn3:
Convert(59.07f);
Mn1.setChecked(false);
Mn2.setChecked(false);
Mn3.setChecked(true);
Mn4.setChecked(false);
break;
case R.id.Mn4:
Convert(2.84f);
Mn1.setChecked(false);
Mn2.setChecked(false);
Mn3.setChecked(false);
Mn4.setChecked(true);
break;
}

}
public void SetView(String N) {
String temp = (String) ViewB.getText();
ViewB.setText(temp + N);
}

public void Convert(float moneda) {

String temp = (String) ViewB.getText();


if ("".equals(temp)){

} else {
float value = Float.parseFloat(temp);
float convert = value * moneda;
ViewB2.setText(String.valueOf(convert));
}
}

public void GetExtra (){


Bundle extras = getIntent().getExtras();
String N = extras.getString("Name");

LabelName.setText(N);
}

}
CAPTURA DE PANTALLA

Potrebbero piacerti anche