Criei menu de login e de criar conta (com design e tudo a funcionar)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.google.gms.google.services)
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -37,6 +38,11 @@ dependencies {
|
||||
implementation(libs.material)
|
||||
implementation(libs.activity)
|
||||
implementation(libs.constraintlayout)
|
||||
implementation(libs.firebase.auth)
|
||||
implementation(libs.credentials)
|
||||
implementation(libs.credentials.play.services.auth)
|
||||
implementation(libs.googleid)
|
||||
implementation(libs.firebase.database)
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.ext.junit)
|
||||
androidTestImplementation(libs.espresso.core)
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.VdcScore">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
android:name=".CriarContaActivity"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.example.vdcscore;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
public class CriarContaActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_criarconta);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
EditText editPassword2;
|
||||
EditText editEmail;
|
||||
EditText editConfirmPassword;
|
||||
Button btnCreateAccount;
|
||||
TextView txtGoLogin;
|
||||
|
||||
|
||||
editEmail = findViewById(R.id.editEmail);
|
||||
editPassword2 = findViewById(R.id.editPassword2);
|
||||
editConfirmPassword = findViewById(R.id.editConfirmPassword);
|
||||
btnCreateAccount = findViewById(R.id.btnCreateAccount);
|
||||
txtGoLogin = findViewById(R.id.txtGoLogin);
|
||||
|
||||
// Criar conta
|
||||
btnCreateAccount.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String email = editEmail.getText().toString();
|
||||
String pass = editPassword2.getText().toString();
|
||||
String conf = editConfirmPassword.getText().toString();
|
||||
|
||||
if (email.isEmpty() || pass.isEmpty() || conf.isEmpty()) {
|
||||
Toast.makeText(CriarContaActivity.this, "Preencha todos os campos!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pass.equals(conf)) {
|
||||
Toast.makeText(CriarContaActivity.this, "As passwords não coincidem!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Por agora só mostra mensagem (podemos pôr Firebase ou SQLite depois)
|
||||
Toast.makeText(CriarContaActivity.this, "Conta criada com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
finish(); // volta para o login
|
||||
}
|
||||
});
|
||||
|
||||
// Voltar ao login
|
||||
txtGoLogin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(CriarContaActivity.this, LoginActivity.class);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
59
app/src/main/java/com/example/vdcscore/LoginActivity.java
Normal file
59
app/src/main/java/com/example/vdcscore/LoginActivity.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.example.vdcscore;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
EditText editEmail, editPassword;
|
||||
Button btnLogin;
|
||||
FirebaseAuth mAuth;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
editEmail = findViewById(R.id.editEmail);
|
||||
editPassword = findViewById(R.id.editPassword2);
|
||||
btnLogin = findViewById(R.id.btnLogin);
|
||||
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
|
||||
btnLogin.setOnClickListener(v -> loginUser());
|
||||
}
|
||||
|
||||
private void loginUser() {
|
||||
String email = editEmail.getText().toString().trim();
|
||||
String password = editPassword.getText().toString().trim();
|
||||
|
||||
if (email.isEmpty() || password.isEmpty()) {
|
||||
Toast.makeText(this, "Preencha todos os campos", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
mAuth.signInWithEmailAndPassword(email, password)
|
||||
.addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
|
||||
Toast.makeText(this, "Login efetuado!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// Abre a tua página principal
|
||||
startActivity(new Intent(LoginActivity.this, CriarContaActivity.class));
|
||||
finish();
|
||||
|
||||
} else {
|
||||
Toast.makeText(this,
|
||||
"Erro: " + task.getException().getMessage(),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.example.vdcscore;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_main);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
}
|
||||
}
|
||||
132
app/src/main/res/layout/activity_criarconta.xml
Normal file
132
app/src/main/res/layout/activity_criarconta.xml
Normal file
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.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"
|
||||
android:background="#ECEFF1"
|
||||
android:id="@+id/main">
|
||||
|
||||
<!-- Título Criar Conta -->
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="56dp"
|
||||
android:text="Criar Conta"
|
||||
android:textSize="35sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.497"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- Subtítulo VdcScore -->
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:text="VdcScore"
|
||||
android:textSize="25sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/cardRegister"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
|
||||
<!-- Card -->
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardRegister"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:elevation="10dp"
|
||||
android:padding="24dp"
|
||||
app:cardCornerRadius="18dp"
|
||||
app:cardUseCompatPadding="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_marginTop="80dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Nome -->
|
||||
|
||||
<!-- Email -->
|
||||
<EditText
|
||||
android:id="@+id/editEmail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:drawableLeft="@android:drawable/ic_menu_send"
|
||||
android:hint="Email"
|
||||
android:padding="12dp"
|
||||
android:textColor="#263238"
|
||||
android:textColorHint="#90A4AE" />
|
||||
|
||||
<!-- Password -->
|
||||
<EditText
|
||||
android:id="@+id/editPassword2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:drawableLeft="@android:drawable/ic_lock_lock"
|
||||
android:hint="Password"
|
||||
android:inputType="textPassword"
|
||||
android:padding="12dp"
|
||||
android:textColor="#263238"
|
||||
android:textColorHint="#90A4AE" />
|
||||
|
||||
<!-- Confirmar Password -->
|
||||
<EditText
|
||||
android:id="@+id/editConfirmPassword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:drawableLeft="@android:drawable/ic_lock_lock"
|
||||
android:hint="Confirmar Password"
|
||||
android:inputType="textPassword"
|
||||
android:padding="12dp"
|
||||
android:textColor="#263238"
|
||||
android:textColorHint="#90A4AE" />
|
||||
|
||||
<!-- Botão -->
|
||||
<Button
|
||||
android:id="@+id/btnCreateAccount"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:backgroundTint="#1E88E5"
|
||||
android:padding="12dp"
|
||||
android:text="Criar Conta"
|
||||
android:textColor="#FFFFFF" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<!-- Voltar ao Login -->
|
||||
<TextView
|
||||
android:id="@+id/txtGoLogin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="Já tens conta? Entrar"
|
||||
android:textColor="#1E88E5"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cardRegister" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
101
app/src/main/res/layout/activity_login.xml
Normal file
101
app/src/main/res/layout/activity_login.xml
Normal file
@@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.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"
|
||||
android:background="#ECEFF1">
|
||||
|
||||
<!-- Card -->
|
||||
|
||||
<!-- Texto "Criar conta" -->
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardLogin"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:elevation="10dp"
|
||||
android:padding="24dp"
|
||||
app:cardCornerRadius="18dp"
|
||||
app:cardUseCompatPadding="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_margin="140dp"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Email -->
|
||||
<EditText
|
||||
android:id="@+id/editEmail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:drawableLeft="@android:drawable/ic_menu_send"
|
||||
android:hint="Email"
|
||||
android:padding="12dp"
|
||||
android:textColor="#263238"
|
||||
android:textColorHint="#90A4AE" />
|
||||
|
||||
<!-- Password -->
|
||||
<EditText
|
||||
android:id="@+id/editPassword2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:drawableLeft="@android:drawable/ic_lock_lock"
|
||||
android:hint="Password"
|
||||
android:inputType="textPassword"
|
||||
android:padding="12dp"
|
||||
android:textColor="#263238"
|
||||
android:textColorHint="#90A4AE" />
|
||||
|
||||
<!-- Botão -->
|
||||
<Button
|
||||
android:id="@+id/btnLogin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:backgroundTint="#1E88E5"
|
||||
android:padding="12dp"
|
||||
android:text="Entrar"
|
||||
android:textColor="#FFFFFF" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtRegister"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:text="Criar conta"
|
||||
android:textColor="#1E88E5"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_margin="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cardLogin" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="50dp"
|
||||
android:text="VdcScore"
|
||||
android:textSize="25sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/cardLogin"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
4
app/src/main/res/values/ids.xml
Normal file
4
app/src/main/res/values/ids.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="main" type="id" />
|
||||
</resources>
|
||||
Reference in New Issue
Block a user