Criei menu de login e de criar conta (com design e tudo a funcionar)

main
230421 2025-11-25 16:55:30 +00:00
parent 852c716ef2
commit 72e39f447c
15 changed files with 433 additions and 46 deletions

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AppInsightsSettings">
<option name="tabSettings">
<map>
<entry key="Firebase Crashlytics">
<value>
<InsightsFilterSettings>
<option name="connection">
<ConnectionSetting>
<option name="appId" value="com.example.vdcscore" />
<option name="mobileSdkAppId" value="1:89853204936:android:a307054db52e1419e088fd" />
<option name="projectId" value="vdcscore" />
<option name="projectNumber" value="89853204936" />
</ConnectionSetting>
</option>
<option name="signal" value="SIGNAL_UNSPECIFIED" />
<option name="timeIntervalDays" value="THIRTY_DAYS" />
<option name="visibilityType" value="ALL" />
</InsightsFilterSettings>
</value>
</entry>
</map>
</option>
</component>
</project>

13
.idea/deviceManager.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DeviceTable">
<option name="columnSorters">
<list>
<ColumnSorterState>
<option name="column" value="Name" />
<option name="order" value="ASCENDING" />
</ColumnSorterState>
</list>
</option>
</component>
</project>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">

View File

@ -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)

View File

@ -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" />

View File

@ -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);
}
});
}
}

View 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();
}
});
}
}

View File

@ -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;
});
}
}

View 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>

View 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>

View File

@ -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>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="main" type="id" />
</resources>

View File

@ -1,4 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.google.gms.google.services) apply false
}

View File

@ -7,6 +7,12 @@ appcompat = "1.7.1"
material = "1.13.0"
activity = "1.11.0"
constraintlayout = "2.2.1"
googleGmsGoogleServices = "4.4.4"
firebaseAuth = "24.0.1"
credentials = "1.5.0"
credentialsPlayServicesAuth = "1.5.0"
googleid = "1.1.1"
firebaseDatabase = "22.0.1"
[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
@ -16,7 +22,13 @@ appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "a
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
firebase-auth = { group = "com.google.firebase", name = "firebase-auth", version.ref = "firebaseAuth" }
credentials = { group = "androidx.credentials", name = "credentials", version.ref = "credentials" }
credentials-play-services-auth = { group = "androidx.credentials", name = "credentials-play-services-auth", version.ref = "credentialsPlayServicesAuth" }
googleid = { group = "com.google.android.libraries.identity.googleid", name = "googleid", version.ref = "googleid" }
firebase-database = { group = "com.google.firebase", name = "firebase-database", version.ref = "firebaseDatabase" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
google-gms-google-services = { id = "com.google.gms.google-services", version.ref = "googleGmsGoogleServices" }