0% found this document useful (0 votes)
18 views4 pages

Prova Mobile

The document describes code for a mobile app project. It includes XML layout files and Java code for an activity to collect user information and display it or show errors. Fields are cleared after successful submission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Prova Mobile

The document describes code for a mobile app project. It includes XML layout files and Java code for an activity to collect user information and display it or show errors. Fields are cleared after successful submission.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

PROVA MOBILE ->

ALUNOS:
LUAN DE OLIVEIRA LEAL
THIAGO QUEIROZ
THIAGO XAVIER
MARCOS FERREIRA
LUCAS AMORIM
ARTHUR HENRIQUE

activity_main.xml (1):

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout 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"
android:padding="16dp">

<EditText
android:id="@+id/editTextLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Login"
android:inputType="text"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText,VisualLintTextFieldSize" />

<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextLogin"
android:layout_marginTop="16dp"
android:hint="Senha"
android:inputType="textPassword"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText,VisualLintTextFieldSize" />

<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextPassword"
android:layout_marginTop="24dp"
android:text="Logar"
tools:ignore="HardcodedText,VisualLintButtonSize" />
</RelativeLayout>

MainActivity.java (1):

package com.example.provamobile;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

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

Button buttonLogin = findViewById(R.id.buttonLogin);

buttonLogin.setOnClickListener(v -> {
// Redirecionar para a tela de cadastro
Intent intent = new Intent(MainActivity.this,
FormularioCadastroPetActivity.class);
startActivity(intent);
});
}
}

activity_main.xml (2):

<?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"
android:orientation="vertical"
android:padding="16dp">

<EditText
android:id="@+id/editTextCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Código"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText,TextFields,VisualLintTextFieldSize" />

<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="Nome"
android:minHeight="48dp"
tools:ignore="HardcodedText,TextFields,VisualLintTextFieldSize"
android:importantForAutofill="no" />

<EditText
android:id="@+id/editTextAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="Endereço"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText,TextFields,VisualLintTextFieldSize" />

<EditText
android:id="@+id/editTextPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="Telefone"
android:inputType="phone"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText,VisualLintTextFieldSize" />

<EditText
android:id="@+id/editTextNickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="Apelido"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText,TextFields,VisualLintTextFieldSize" />

<EditText
android:id="@+id/editTextZIP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="CEP"
android:inputType="number"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText,VisualLintTextFieldSize" />

<Button
android:id="@+id/buttonSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Cadastrar"
tools:ignore="HardcodedText,VisualLintButtonSize" />
</LinearLayout>

MainActivity.java (2):

package com.example.provamobile;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private EditText editTextCode;


private EditText editTextName;
private EditText editTextAddress;
private EditText editTextPhone;
private EditText editTextNickname;
private EditText editTextZIP;

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

editTextCode = findViewById(R.id.editTextCode);
editTextName = findViewById(R.id.editTextName);
editTextAddress = findViewById(R.id.editTextAddress);
editTextPhone = findViewById(R.id.editTextPhone);
editTextNickname = findViewById(R.id.editTextNickname);
editTextZIP = findViewById(R.id.editTextZIP);
Button buttonSubmit = findViewById(R.id.buttonSubmit);

buttonSubmit.setOnClickListener(v -> {

String code = editTextCode.getText().toString();


String name = editTextName.getText().toString();
String address = editTextAddress.getText().toString();
String phone = editTextPhone.getText().toString();
String nickname = editTextNickname.getText().toString();
String zip = editTextZIP.getText().toString();

if (code.isEmpty() || name.isEmpty() || address.isEmpty() ||


phone.isEmpty() || nickname.isEmpty() || zip.isEmpty()) {
Toast.makeText(MainActivity.this, "Por favor, preencha todos os
campos", Toast.LENGTH_SHORT).show();
} else {

String petInfo = "Código: " + code + "\nNome: " + name + "\


nEndereço: " + address +
"\nTelefone: " + phone + "\nApelido: " + nickname + "\nCEP:
" + zip;

Toast.makeText(MainActivity.this, "Pet cadastrado com sucesso!\n\n"


+ petInfo, Toast.LENGTH_LONG).show();

clearFields();
}
});
}

private void clearFields() {


editTextCode.getText().clear();
editTextName.getText().clear();
editTextAddress.getText().clear();
editTextPhone.getText().clear();
editTextNickname.getText().clear();
editTextZIP.getText().clear();
}
}

You might also like