logine registro
This commit is contained in:
@@ -46,5 +46,6 @@ dependencies {
|
||||
implementation(libs.credentials.play.services.auth)
|
||||
implementation(libs.googleid)
|
||||
implementation(libs.firebase.database)
|
||||
implementation(libs.activity)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.SmartAgenda">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.SmartAgenda">
|
||||
|
||||
<!-- LOGIN como Activity inicial -->
|
||||
<activity
|
||||
android:name=".Login"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Registo -->
|
||||
<activity
|
||||
android:name=".Registro"
|
||||
android:exported="false" />
|
||||
|
||||
<!-- MainActivity (apenas acessível depois do login) -->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="false" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
56
app/src/main/java/com/example/smartagenda/ui/Login.java
Normal file
56
app/src/main/java/com/example/smartagenda/ui/Login.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.example.smartagenda;
|
||||
|
||||
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 Login extends AppCompatActivity {
|
||||
|
||||
private EditText campoEmail, campoPassword;
|
||||
private Button btnEntrar, btnIrParaRegisto;
|
||||
|
||||
private FirebaseAuth auth;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
campoEmail = findViewById(R.id.campoEmail);
|
||||
campoPassword = findViewById(R.id.campoPassword);
|
||||
btnEntrar = findViewById(R.id.btnEntrar);
|
||||
btnIrParaRegisto = findViewById(R.id.btnIrParaRegisto);
|
||||
|
||||
auth = FirebaseAuth.getInstance();
|
||||
|
||||
btnEntrar.setOnClickListener(v -> {
|
||||
String email = campoEmail.getText().toString();
|
||||
String password = campoPassword.getText().toString();
|
||||
|
||||
if (email.isEmpty() || password.isEmpty()) {
|
||||
Toast.makeText(this, "Preencha todos os campos!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
auth.signInWithEmailAndPassword(email, password)
|
||||
.addOnSuccessListener(aVoid -> {
|
||||
Toast.makeText(this, "Login efetuado!", Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
finish();
|
||||
})
|
||||
.addOnFailureListener(e ->
|
||||
Toast.makeText(this, "Erro: " + e.getMessage(), Toast.LENGTH_LONG).show()
|
||||
);
|
||||
});
|
||||
|
||||
btnIrParaRegisto.setOnClickListener(v ->
|
||||
startActivity(new Intent(this, Registro.class))
|
||||
);
|
||||
}
|
||||
}
|
||||
52
app/src/main/java/com/example/smartagenda/ui/Registro.java
Normal file
52
app/src/main/java/com/example/smartagenda/ui/Registro.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.example.smartagenda;
|
||||
|
||||
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 Registro extends AppCompatActivity {
|
||||
|
||||
private EditText campoEmail, campoPassword;
|
||||
private Button btnCriarConta;
|
||||
|
||||
private FirebaseAuth auth;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_registro);
|
||||
|
||||
campoEmail = findViewById(R.id.campoEmailRegisto);
|
||||
campoPassword = findViewById(R.id.campoPasswordRegisto);
|
||||
btnCriarConta = findViewById(R.id.btnCriarConta);
|
||||
|
||||
auth = FirebaseAuth.getInstance();
|
||||
|
||||
btnCriarConta.setOnClickListener(v -> {
|
||||
|
||||
String email = campoEmail.getText().toString();
|
||||
String password = campoPassword.getText().toString();
|
||||
|
||||
if (email.isEmpty() || password.isEmpty()) {
|
||||
Toast.makeText(this, "Preencha todos os campos!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
auth.createUserWithEmailAndPassword(email, password)
|
||||
.addOnSuccessListener(aVoid -> {
|
||||
Toast.makeText(this, "Conta criada!", Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(this, Login.class));
|
||||
finish();
|
||||
})
|
||||
.addOnFailureListener(e ->
|
||||
Toast.makeText(this, "Erro: " + e.getMessage(), Toast.LENGTH_LONG).show()
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
7
app/src/main/res/drawable/rounded_edittext.xml
Normal file
7
app/src/main/res/drawable/rounded_edittext.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#F2F2F2"/>
|
||||
<corners android:radius="12dp"/>
|
||||
<padding android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp"/>
|
||||
</shape>
|
||||
10
app/src/main/res/layout/activity_login.xml
Normal file
10
app/src/main/res/layout/activity_login.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?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=".ui.Login">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
60
app/src/main/res/layout/activity_registro.xml
Normal file
60
app/src/main/res/layout/activity_registro.xml
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="24dp"
|
||||
android:background="#FFFFFF">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:src="@drawable/ic_launcher_foreground"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/nome"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:hint="Nome completo"
|
||||
android:background="@drawable/rounded_edittext"
|
||||
android:padding="12dp"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:hint="Email"
|
||||
android:background="@drawable/rounded_edittext"
|
||||
android:padding="12dp"
|
||||
android:inputType="textEmailAddress"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:hint="Password"
|
||||
android:background="@drawable/rounded_edittext"
|
||||
android:padding="12dp"
|
||||
android:inputType="textPassword"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnRegistar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:text="Criar Conta"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="18sp"
|
||||
android:backgroundTint="#000000"
|
||||
android:layout_marginTop="8dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
Reference in New Issue
Block a user