0
votes

Login Button will respond when email and password are entered to log in. All the other button in the app works fine need help, please. How do I get my login button to work?

  package com.icmg.cs0480;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

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;

import java.util.Map;

public class DriverLoginRegisterActivity extends AppCompatActivity  {

    private Button DriverLoginButton;
    private Button DriverRegisterButton;
    private Button DriverRegisterLink;
    private EditText DriverEmail;
    private EditText DriverPassword;
    private ProgressDialog loadingBar;

    private FirebaseAuth mAuth;



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

        mAuth = FirebaseAuth.getInstance();

        DriverLoginButton = findViewById(R.id.driver_login_btn);
        DriverRegisterButton = findViewById(R.id.driver_register_btn);
        DriverRegisterLink = findViewById(R.id.register_driver_link);
        TextView DriverStatus = findViewById(R.id.driver_status);
        DriverEmail = findViewById(R.id.driver_email);
        DriverPassword = findViewById(R.id.driver_password);
        loadingBar = new ProgressDialog(this);


        DriverRegisterButton.setVisibility(View.INVISIBLE);
        DriverRegisterButton.setEnabled(false);

        DriverRegisterLink.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DriverLoginButton.setVisibility(View.INVISIBLE);
                DriverRegisterLink.setVisibility(View.INVISIBLE);


                DriverRegisterButton.setVisibility(View.VISIBLE);
                DriverRegisterButton.setEnabled(true);

                DriverRegisterButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String email = DriverEmail.getText().toString();
                        String password = DriverPassword.getText().toString();

                        RegisterDriver(email, password);
                    }


                });

                    }
                });
                    }




    private void RegisterDriver(String email, String password) {
        if (TextUtils.isEmpty(email)) {
            Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Email....", Toast.LENGTH_SHORT).show();
        }
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Password....", Toast.LENGTH_SHORT).show();
        } else {
            loadingBar.setTitle("Driver Registration");
            loadingBar.setMessage("Please wait, While we register your data...");
            loadingBar.show();

            mAuth.createUserWithEmailAndPassword((email), password)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Register Successfully... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();

                                Intent driverIntent = new Intent(DriverLoginRegisterActivity.this, DriversMapsActivity.class);
                                startActivity(driverIntent);
                            } else {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Register Unsuccessful, Please try again... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();
                            }
                        }
                    });

            DriverLoginButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String email = DriverEmail.getText().toString();
                    String password = DriverPassword.getText().toString();

                    DriverSignIn(email, password);}


    private void DriverSignIn(String email, String password) {   if (TextUtils.isEmpty(email)) {
        Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Email....", Toast.LENGTH_SHORT).show();
    }
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Password....", Toast.LENGTH_SHORT).show();
        } else {
            loadingBar.setTitle("Driver Login");
            loadingBar.setMessage("Please wait, While we check your credentials...");
            loadingBar.show();

            mAuth.signInWithEmailAndPassword((email), password)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Login Successfully... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();

                                Intent driverIntent = new Intent(DriverLoginRegisterActivity.this, DriversMapsActivity.class);
                                startActivity(driverIntent);
                            } else {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Login Unsuccessful, Please try again... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();

        }}});}}});}}}

I expect the login to log in the driver in and take them to the map page

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
        tools:context=".GuestLoginRegisterActivity"
        android:orientation="vertical"
        android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="18dp"
    android:paddingRight="18dp"
    android:background="@drawable/new_login_gradients">



    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- Here you can put your logo or brand name -->

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#f9d7db" />

        <ImageView
            android:id="@+id/logo"
            android:layout_width="match_parent"
            android:layout_height="289dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="8dp"
            android:adjustViewBounds="true"
            android:cropToPadding="false"
            android:padding="16dp"
            android:scaleType="fitXY"
            android:src="@drawable/nhfclogo" />

        <TextView
            android:id="@+id/driver_status"
            android:layout_width="match_parent"
            android:layout_height="37dp"
            android:gravity="center_horizontal"
            android:text="DRIVER LOGIN"
            android:textColor="@android:color/background_light"
            android:textSize="30sp"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/driver_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="70dp"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_email"
            android:drawablePadding="12dp"
            android:ems="10"
            android:hint="Email"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:padding="8dp"
            android:singleLine="false"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/driver_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_lock_white_24dp"
            android:drawablePadding="12dp"
            android:ems="10"
            android:hint="......."
            android:inputType="textPassword"
            android:maxLines="1"
            android:padding="8dp"
            android:textColorHint="#fff" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#f9d7db" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:padding="8dp"
            android:text="Remember me "
            android:textColor="#fff" />

        <Button
            android:id="@+id/driver_login_btn"
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:background="@drawable/background_login"
            android:clickable="true"
            android:focusable="true"
            android:padding="16dp"
            android:text="Login"
            android:textAllCaps="false"
            android:textColor="#f16f7d"
            android:textSize="18sp"
            android:visibility="visible" />

        <Button
            android:id="@+id/register_driver_link"
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:background="@drawable/background_signup"
            android:clickable="true"
            android:padding="16dp"
            android:text="Don't have a Account"
            android:textAllCaps="false"
            android:textColor="#fff"
            android:textSize="18sp"
            android:visibility="visible" />

        <TextView
            style="@style/TextAppearance.AppCompat.Body2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:clickable="true"
            android:padding="16dp"
            android:text="Forget your Password? "
            android:textColor="#fff" />

        <Button
            android:id="@+id/driver_register_btn"
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:background="@drawable/background_signup"
            android:clickable="true"
            android:padding="16dp"
            android:text="Register"
            android:textAllCaps="false"
            android:textColor="#fff"
            android:textSize="18sp"
            android:visibility="invisible" />

    </LinearLayout>
    </ScrollView>

</LinearLayout>

Catlog

01-31 18:55:31.502 18620-18643/com.icmg.cs0480 V/FA: Inactivity, disconnecting from the service 01-31 18:55:39.812 18620-18643/com.icmg.cs0480 V/FA: Recording user engagement, ms: 21593 01-31 18:55:39.812 18620-18643/com.icmg.cs0480 V/FA: Connecting to remote service 01-31 18:55:39.822 18620-18643/com.icmg.cs0480 V/FA: Activity paused, time: 95029052 01-31 18:55:39.832 18620-18643/com.icmg.cs0480 D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=21593, firebase_screen_class(_sc)=DriverLoginRegisterActivity, firebase_screen_id(_si)=2202821951799111479}] 01-31 18:55:39.842 18620-18643/com.icmg.cs0480 V/FA: Connection attempt already in progress 01-31 18:55:39.872 18620-18620/com.icmg.cs0480 V/FA: onActivityCreated 01-31 18:55:40.482 18620-18643/com.icmg.cs0480 D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=DriverLoginRegisterActivity, firebase_previous_id(_pi)=2202821951799111479, firebase_screen_class(_sc)=DriversMapsActivity, firebase_screen_id(_si)=2202821951799111480}] 01-31 18:55:40.532 18620-18643/com.icmg.cs0480 V/FA: Connection attempt already in progress 01-31 18:55:40.532 18620-18643/com.icmg.cs0480 V/FA: Connection attempt already in progress 01-31 18:55:40.532 18620-18643/com.icmg.cs0480 V/FA: Activity resumed, time: 95029717 01-31 18:55:40.632 18620-18643/com.icmg.cs0480 D/FA: Connected to remote service 01-31 18:55:40.632 18620-18643/com.icmg.cs0480 V/FA: Processing queued up service tasks: 4 01-31 18:55:40.672 2515-18372/? V/FA-SVC: Logging event: origin=auto,name=user_engagement(_e),params=Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=21593, firebase_screen_class(_sc)=DriverLoginRegisterActivity, firebase_screen_id(_si)=2202821951799111479}] 01-31 18:55:40.702 2515-18372/? V/FA-SVC: Saving event, name, data size: user_engagement(_e), 83 01-31 18:55:40.702 2515-18372/? V/FA-SVC: Event recorded: Event{appId='com.icmg.cs0480', name='user_engagement(_e)', params=Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=21593, firebase_screen_class(_sc)=DriverLoginRegisterActivity, firebase_screen_id(_si)=2202821951799111479}]} 01-31 18:55:40.702 2515-18372/? V/FA-SVC: Upload scheduled in approximately ms: 3579318 01-31 18:55:40.702 2515-18372/? V/FA-SVC: Scheduling upload with GcmTaskService 01-31 18:55:40.702 2515-18372/? V/FA-SVC: Scheduling task with Gcm. time: 3579318 01-31 18:55:40.722 2515-18372/? V/FA-SVC: Background event processing time, ms: 46 01-31 18:55:40.772 2515-18372/? V/FA-SVC: Logging event: origin=auto,name=screen_view(_vs),params=Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=DriverLoginRegisterActivity, firebase_previous_id(_pi)=2202821951799111479, firebase_screen_class(_sc)=DriversMapsActivity, firebase_screen_id(_si)=2202821951799111480}] 01-31 18:55:40.822 2515-18372/? V/FA-SVC: Saving event, name, data size: screen_view(_vs), 117 01-31 18:55:40.822 2515-18372/? V/FA-SVC: Event recorded: Event{appId='com.icmg.cs0480', name='screen_view(_vs)', params=Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=DriverLoginRegisterActivity, firebase_previous_id(_pi)=2202821951799111479, firebase_screen_class(_sc)=DriversMapsActivity, firebase_screen_id(_si)=2202821951799111480}]} 01-31 18:55:40.822 2515-18372/? V/FA-SVC: Upload scheduled in approximately ms: 3579196 01-31 18:55:40.862 2515-18372/? V/FA-SVC: Scheduling upload with GcmTaskService 01-31 18:55:40.862 2515-18372/? V/FA-SVC: Scheduling task with Gcm. time: 3579196 01-31 18:55:40.882 2515-18372/? V/FA-SVC: Background event processing time, ms: 117 01-31 18:55:41.042 18620-18648/com.icmg.cs0480 D/FA: Fetching user attributes (FE) 01-31 18:55:43.972 18968-18968/? V/FA: Registered activity lifecycle callback 01-31 18:55:44.232 18968-18990/com.icmg.cs0480 V/FA: Collection enabled 01-31 18:55:44.242 18968-18990/com.icmg.cs0480 V/FA: App package, google app id: com.icmg.cs0480, 1:513219199166:android:0d8e627edae5ac24 01-31 18:55:44.242 18968-18990/com.icmg.cs0480 I/FA: App measurement is starting up, version: 14710 01-31 18:55:44.242 18968-18990/com.icmg.cs0480 I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE 01-31 18:55:44.242 18968-18990/com.icmg.cs0480 I/FA: To enable faster debug mode event logging run: adb shell setprop debug.firebase.analytics.app com.icmg.cs0480 01-31 18:55:44.242 18968-18990/com.icmg.cs0480 D/FA: Debug-level message logging enabled 01-31 18:55:44.272 18968-18990/com.icmg.cs0480 V/FA: Connecting to remote service 01-31 18:55:44.302 18968-18968/com.icmg.cs0480 V/FA: onActivityCreated 01-31 18:55:44.312 18968-18990/com.icmg.cs0480 V/FA: Connection attempt already in progress 01-31 18:55:44.592 18968-18990/com.icmg.cs0480 I/FA: Tag Manager is not found and thus will not be used 01-31 18:55:44.602 18968-18990/com.icmg.cs0480 D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=DriverLoginRegisterActivity, firebase_screen_id(_si)=2202821951799111479}] 01-31 18:55:44.642 18968-18990/com.icmg.cs0480 V/FA: Connection attempt already in progress 01-31 18:55:44.652 18968-18990/com.icmg.cs0480 V/FA: Connection attempt already in progress 01-31 18:55:44.652 18968-18990/com.icmg.cs0480 V/FA: Activity resumed, time: 95033830 01-31 18:55:44.772 18968-18990/com.icmg.cs0480 D/FA: Connected to remote service 01-31 18:55:44.772 18968-18990/com.icmg.cs0480 V/FA: Processing queued up service tasks: 4 01-31 18:55:44.802 2515-18372/? V/FA-SVC: Logging event: origin=auto,name=screen_view(_vs),params=Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=DriverLoginRegisterActivity, firebase_screen_id(_si)=2202821951799111479}] 01-31 18:55:44.812 2515-18372/? V/FA-SVC: Saving event, name, data size: screen_view(_vs), 72 01-31 18:55:44.822 2515-18372/? V/FA-SVC: Event recorded: Event{appId='com.icmg.cs0480', name='screen_view(_vs)', params=Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=DriverLoginRegisterActivity, firebase_screen_id(_si)=2202821951799111479}]} 01-31 18:55:44.822 2515-18372/? V/FA-SVC: Upload scheduled in approximately ms: 3575199 01-31 18:55:44.832 2515-18372/? V/FA-SVC: Scheduling upload with GcmTaskService 01-31 18:55:44.832 2515-18372/? V/FA-SVC: Scheduling task with Gcm. time: 3575199 01-31 18:55:44.842 2515-18372/? V/FA-SVC: Background event processing time, ms: 45 01-31 18:55:49.872 18968-18990/com.icmg.cs0480 V/FA: Inactivity, disconnecting from the service 01-31 19:01:22.142 1775-1775/? E/FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement 01-31 19:01:22.142 1775-1775/? E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.

2
I don't see your xml code where you should have added button with some id. And you don't map that button from UI to your DriverLoginButton in the code. So either post xml or initialize button via findViewById(R.id.loginButton). Also you will need to call setContenView(R.layout.your_xml_name) at the beginning of onCreate, before calling findViewById - shtolik
have you ever bothered to read the error message? - Martin Zeitler
@Martin Zeitler yes, did bother read the error message - Sapphire Travel Agency
@SapphireTravelAgency and have you enabled the Maps API for that key/fingerprint combination yet? this isn't really en error message, where one would have to guess, what it is trying to tell. and better remove the key & fingerprint from the question; they are not meant for the public. better invalidate them and generate new ones. - Martin Zeitler
@MartinZeitler, This my first app and As I said before I'm new to this. - Sapphire Travel Agency

2 Answers

2
votes

You should get your findViewById() for your button first..Before you do the operation.

 Button DriverLoginButton = findViewById(R.id.ur_button);

At the same time,comment this line first:

//Button DriverLoginButton = new Button(this);

And then set the onClickListener inside your onCreate part of the code.You are putting in the wrong place as I see

@Override
protected void onCreate(Bundle savedInstanceState) {
     //.... all other code

     //set the onClickListener in the onCreate part
     DriverLoginButton.setOnClickListener{
        //bla bla bla
     }
}
0
votes

create the button in your layout.xml file, give your button ID, and set onClick attribute, and just implement it in the java file.

Just because you're directly creating a button in the java file, you will also need to add it into your ViewGroup manually, so instead use design editor if you prefer GUI, or the XML file.