tou a fazer criar conta
|
|
@ -18,18 +18,19 @@
|
|||
android:name=".ui.Inicial.Criar_conta"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".ui.Inicial.iniciar_sessao"
|
||||
android:name=".ui.MainActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:name=".ui.Inicial.iniciar_sessao"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
After Width: | Height: | Size: 94 KiB |
|
|
@ -1,6 +1,7 @@
|
|||
package com.example.cuida.ui.Inicial;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.media.Image;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
|
@ -10,8 +11,6 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
|
@ -19,61 +18,58 @@ import androidx.core.view.WindowInsetsCompat;
|
|||
|
||||
import com.example.cuida.R;
|
||||
import com.example.cuida.ui.MainActivity;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.auth.AuthResult;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
|
||||
public class iniciar_sessao extends AppCompatActivity {
|
||||
|
||||
private ImageView imageView;
|
||||
|
||||
private EditText emailEditText;
|
||||
private EditText palavraPasseEditText;
|
||||
private Button entrarButton;
|
||||
private Button criarContaButton;
|
||||
private TextView bemVindoTextView;
|
||||
private Button esqueciAPalavraPasseButton;
|
||||
private TextView esqueciAPalavraPasseButton;
|
||||
|
||||
private FirebaseAuth mAuth;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_iniciar_sessao);
|
||||
|
||||
// Inicializar Firebase Auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
|
||||
// Configuração do layout para Edge-to-Edge
|
||||
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;
|
||||
});
|
||||
|
||||
// Associar as Views
|
||||
imageView = findViewById(R.id.imageView);
|
||||
emailEditText = findViewById(R.id.emailEditText);
|
||||
palavraPasseEditText = findViewById(R.id.palavraPasseEditText);
|
||||
entrarButton = findViewById(R.id.entarButton);
|
||||
criarContaButton = findViewById(R.id.criarContaButton);
|
||||
bemVindoTextView = findViewById(R.id.bemVindoTextView);
|
||||
esqueciAPalavraPasseButton = findViewById(R.id.esqueciAPalavraPasseButton);
|
||||
|
||||
|
||||
entrarButton.setOnClickListener(v -> iniciarSessao());
|
||||
|
||||
// Definir o listener para o botão de criar conta
|
||||
criarContaButton.setOnClickListener(v -> {
|
||||
// Chama o método para criar a conta
|
||||
criarConta();
|
||||
Intent intent = new Intent(iniciar_sessao.this, Criar_conta.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
esqueciAPalavraPasseButton.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(iniciar_sessao.this, Esqueci_a_palavra_passe.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Método para criar uma nova conta de utilizador.
|
||||
*/
|
||||
private void criarConta() {
|
||||
private void iniciarSessao() {
|
||||
String email = emailEditText.getText().toString().trim();
|
||||
String password = palavraPasseEditText.getText().toString().trim();
|
||||
|
||||
// 1. Validar as entradas do utilizador
|
||||
if (email.isEmpty()) {
|
||||
emailEditText.setError("O e-mail é obrigatório");
|
||||
emailEditText.requestFocus();
|
||||
|
|
@ -86,40 +82,23 @@ public class iniciar_sessao extends AppCompatActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
if (password.length() < 6) {
|
||||
palavraPasseEditText.setError("A palavra-passe deve ter no mínimo 6 caracteres");
|
||||
palavraPasseEditText.requestFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Criar o utilizador no Firebase
|
||||
mAuth.createUserWithEmailAndPassword(email, password)
|
||||
mAuth.signInWithEmailAndPassword(email, password)
|
||||
.addOnCompleteListener(this, task -> {
|
||||
if (task.isSuccessful()) {
|
||||
// Se o registo for bem-sucedido
|
||||
Log.d("FIREBASE_AUTH", "createUserWithEmail:success");
|
||||
Toast.makeText(iniciar_sessao.this, "Conta criada com sucesso.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// Navega para a MainActivity
|
||||
Log.d("FIREBASE_AUTH", "signInWithEmail:success");
|
||||
Toast.makeText(iniciar_sessao.this, "Login bem-sucedido.", Toast.LENGTH_SHORT).show();
|
||||
navegarParaMainActivity();
|
||||
|
||||
} else {
|
||||
// Se o registo falhar
|
||||
Log.w("FIREBASE_AUTH", "createUserWithEmail:failure", task.getException());
|
||||
// Mostra uma mensagem de erro mais específica
|
||||
String errorMessage = task.getException() != null ? task.getException().getMessage() : "Erro desconhecido.";
|
||||
Toast.makeText(iniciar_sessao.this, "Falha na autenticação: " + errorMessage, Toast.LENGTH_LONG).show();
|
||||
Log.w("FIREBASE_AUTH", "signInWithEmail:failure", task.getException());
|
||||
Toast.makeText(iniciar_sessao.this, "Falha na autenticação. Verifique suas credenciais.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Navega para a MainActivity e limpa a pilha de atividades.
|
||||
*/
|
||||
private void navegarParaMainActivity() {
|
||||
Intent intent = new Intent(iniciar_sessao.this, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
finish(); // Finaliza a atividade atual
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
@ -9,12 +9,108 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="170dp"
|
||||
android:layout_height="49dp"
|
||||
android:layout_marginTop="28dp"
|
||||
android:text="Criar conta"
|
||||
android:textColor="#020202"
|
||||
android:textSize="34sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="50dp"
|
||||
android:ems="10"
|
||||
android:hint="Nome e Apelido"
|
||||
android:inputType="text"
|
||||
app:layout_constraintEnd_toEndOf="@+id/textView3"
|
||||
app:layout_constraintStart_toStartOf="@+id/textView3"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView3" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextTextEmailAddress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ems="10"
|
||||
android:hint="Gmail"
|
||||
android:inputType="textEmailAddress"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextText"
|
||||
app:layout_constraintStart_toStartOf="@+id/editTextText"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextText" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextPhone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ems="10"
|
||||
android:hint="Nº de telemovel"
|
||||
android:inputType="phone"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextTextEmailAddress"
|
||||
app:layout_constraintStart_toStartOf="@+id/editTextTextEmailAddress"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextTextPassword"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ems="10"
|
||||
android:hint="Confirmar Palavra-Passe"
|
||||
android:inputType="textPassword"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextTextPassword2"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="@+id/editTextTextPassword2"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword2" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextTextPassword2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ems="10"
|
||||
android:hint="Palavra-Passe"
|
||||
android:inputType="textPassword"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextDate"
|
||||
app:layout_constraintStart_toStartOf="@+id/editTextDate"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextDate" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextText2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ems="10"
|
||||
android:hint="morada"
|
||||
android:inputType="text"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextPhone"
|
||||
app:layout_constraintStart_toStartOf="@+id/editTextPhone"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextPhone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="50dp"
|
||||
android:text="Criar Conta"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextTextPassword"
|
||||
app:layout_constraintStart_toStartOf="@+id/editTextTextPassword"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextDate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ems="10"
|
||||
android:hint="Data de nascimento"
|
||||
android:inputType="date"
|
||||
app:layout_constraintEnd_toEndOf="@+id/editTextText2"
|
||||
app:layout_constraintStart_toStartOf="@+id/editTextText2"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextText2" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -7,47 +7,28 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".ui.Inicial.iniciar_sessao">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginTop="48dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.493"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:srcCompat="@tools:sample/avatars" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/emailEditText"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="45dp"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginTop="112dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:ems="10"
|
||||
android:hint="Email"
|
||||
android:inputType="textEmailAddress"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.505"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/textView"
|
||||
app:layout_constraintHorizontal_bias="0.497"
|
||||
app:layout_constraintStart_toStartOf="@+id/textView"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/palavraPasseEditText"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="45dp"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
android:ems="10"
|
||||
android:hint="Palavra-Passe"
|
||||
android:inputType="textPassword"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.505"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/emailEditText"
|
||||
app:layout_constraintStart_toStartOf="@+id/emailEditText"
|
||||
app:layout_constraintTop_toBottomOf="@+id/emailEditText" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
|
|
@ -55,7 +36,7 @@
|
|||
android:layout_width="250dp"
|
||||
android:layout_height="45dp"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginTop="44dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
android:background="#2196F3"
|
||||
android:backgroundTint="#000000"
|
||||
|
|
@ -65,9 +46,9 @@
|
|||
android:textColorHighlight="#03A9F4"
|
||||
android:textColorHint="#03A9F4"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.515"
|
||||
app:layout_constraintHorizontal_bias="0.512"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/palavraPasseEditText"
|
||||
app:layout_constraintTop_toBottomOf="@+id/esqueciAPalavraPasseButton"
|
||||
app:rippleColor="#03A9F4"
|
||||
app:strokeColor="#03A9F4" />
|
||||
|
||||
|
|
@ -86,22 +67,35 @@
|
|||
android:id="@+id/criarContaButton"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="45dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:backgroundTint="#FFFFFF"
|
||||
android:text="Criar conta"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/entarButton"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="@+id/entarButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/entarButton" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/entarButton"
|
||||
app:layout_constraintVertical_bias="0.04" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bemVindoTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="BEM VINDO"
|
||||
android:textSize="34sp"
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="144dp"
|
||||
android:layout_height="37dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="bem vindo"
|
||||
android:textSize="30sp"
|
||||
app:layout_constraintEnd_toEndOf="@+id/imageView"
|
||||
app:layout_constraintStart_toStartOf="@+id/imageView"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="144dp"
|
||||
android:layout_height="148dp"
|
||||
android:layout_marginTop="172dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.498"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:srcCompat="@mipmap/img_cuida" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -7,11 +7,6 @@
|
|||
android:icon="@drawable/ic_home_black_24dp"
|
||||
android:title="@string/title_home" />
|
||||
|
||||
<item
|
||||
android:id="@+id/app_bar_search"
|
||||
android:icon="@drawable/ic_search_black_24dp"
|
||||
android:title="Search"
|
||||
app:actionViewClass="android.widget.SearchView" />
|
||||
<item
|
||||
android:id="@+id/navigation_dashboard"
|
||||
android:icon="@drawable/ic_dashboard_black_24dp"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/img_cuida_background"/>
|
||||
<foreground android:drawable="@mipmap/img_cuida_foreground"/>
|
||||
</adaptive-icon>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/img_cuida_background"/>
|
||||
<foreground android:drawable="@mipmap/img_cuida_foreground"/>
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="img_cuida_background">#FFFFFF</color>
|
||||
</resources>
|
||||