Search in sources :

Example 21 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project NPSmiles by bmcglynn1.

the class LoginAuth method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_auth);
    setTitle("Login");
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        // ...
        }
    };
    final EditText emailText = (EditText) findViewById(R.id.emailEditText);
    final EditText passwordText = (EditText) findViewById(R.id.passwordEditText);
    Button loginButton = (Button) findViewById(R.id.loginButton);
    loginButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (emailText.getText().toString().length() != 0 && passwordText.getText().toString().length() != 0) {
                signIn(emailText.getText().toString(), passwordText.getText().toString());
            }
        }
    });
    findViewById(R.id.relativeLayoutLogin).setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getDecorView().getRootView().getWindowToken(), 0);
            return true;
        }
    });
}
Also used : EditText(android.widget.EditText) Button(android.widget.Button) InputMethodManager(android.view.inputmethod.InputMethodManager) FirebaseUser(com.google.firebase.auth.FirebaseUser) View(android.view.View) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) MotionEvent(android.view.MotionEvent)

Example 22 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project Pepper_v0 by SamDaQueen.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // loading the default fragment
    loadFragment(new CategoryFragment());
    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    Bundle bundle = getIntent().getBundleExtra("items");
    if (bundle != null)
        arrayList = bundle.getParcelableArrayList("order");
    // Firebase Authentication
    mUsername = ANONYMOUS;
    mFirebaseAuth = FirebaseAuth.getInstance();
    mAuthStateListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // user signed in
                onSignedInInitialize(user.getDisplayName());
            } else {
                // user signed out
                onSignedOutCleanup();
                startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().setIsSmartLockEnabled(false).setAvailableProviders(Arrays.asList(new AuthUI.IdpConfig.GoogleBuilder().build(), new AuthUI.IdpConfig.EmailBuilder().build(), new AuthUI.IdpConfig.PhoneBuilder().build())).setLogo(R.drawable.pepper_500px).build(), RC_SIGN_IN);
            }
        }
    };
}
Also used : BottomNavigationView(android.support.design.widget.BottomNavigationView) Bundle(android.os.Bundle) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 23 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project Grupp by tmoronta1208.

the class UserProfileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_profile);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mAuth = FirebaseAuth.getInstance();
    mPager = findViewById(R.id.pager);
    mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
    mPager.setAdapter(mPagerAdapter);
    context = this;
    activity = this;
    floatingActionMenu = findViewById(R.id.floatingaction_menu);
    creatEvent = findViewById(R.id.create_event_mini);
    creatEvent.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(UserProfileActivity.this, CreateEventActivity.class));
        }
    });
    addPerson = findViewById(R.id.add_group_mini);
    addPerson.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // startActivity(new Intent(UserProfileActivity.this, AddPersonActivity.class));
            UPCreateGroupFragment upCreateGroupFragment = new UPCreateGroupFragment();
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.addToBackStack("Grupp Details Fragment").replace(R.id.drawer_layout, upCreateGroupFragment);
            fragmentTransaction.commit();
        }
    });
    mAuthListner = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (mAuth.getCurrentUser() == null) {
                startActivity(new Intent(UserProfileActivity.this, LoginActivity.class));
            }
        }
    };
    pushEventInviteNotifications();
// new InviteNotifications("test", "notification", getApplicationContext());
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) UPCreateGroupFragment(com.example.c4q.capstone.userinterface.user.userprofilefragments.UPCreateGroupFragment) FragmentTransaction(android.support.v4.app.FragmentTransaction) Intent(android.content.Intent) ScreenSlidePagerAdapter(com.example.c4q.capstone.userinterface.user.userprofilefragments.fragmentanimation.ScreenSlidePagerAdapter) View(android.view.View) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 24 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project Grupp by tmoronta1208.

the class EditProfileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_profile);
    saveBtn = findViewById(R.id.edit_profile_save_button);
    ageGroup = findViewById(R.id.radio_group_age);
    budgetGroup = findViewById(R.id.radio_group_budget);
    radiusGroup = findViewById(R.id.radio_group_radius);
    firstName = findViewById(R.id.edit_profile_firstname);
    lastName = findViewById(R.id.edit_profile_lastname);
    zipCode = findViewById(R.id.edit_profile_zip_code);
    mAuth = FirebaseAuth.getInstance();
    rootRef = FirebaseDatabase.getInstance().getReference();
    publicUserReference = rootRef.child(PUBLIC_USER);
    privateUserReference = rootRef.child(PRIVATE_USER);
    privateUserLocationReference = rootRef.child(PRIVATE_USER);
    userIconReference = rootRef.child(USER_ICON);
    currentUser = mAuth.getCurrentUser();
    currentUserID = currentUser.getUid();
    currentUserEmail = currentUser.getEmail();
    radioGroupSelection();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (currentUser != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + currentUser.getUid());
            // Toast.makeText(EditProfileActivity.this, "Successfully signed in with: " + currentUser.getEmail(), Toast.LENGTH_SHORT).show();
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            // Toast.makeText(EditProfileActivity.this, "Successfully signed out.", Toast.LENGTH_SHORT).show();
            }
        }
    };
    ValueEventListener valueEventListener = new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            privateUser = dataSnapshot.child(currentUserID).getValue(PrivateUser.class);
            privateUserLocation = dataSnapshot.child(currentUserID).getValue(PrivateUserLocation.class);
            publicUser = dataSnapshot.child(currentUserID).getValue(PublicUser.class);
            userIcon = dataSnapshot.child(currentUserID).getValue(UserIcon.class);
            iconUrl = userIcon.getIcon_url();
            Log.d(TAG, "onDataChange: Added information to database: \n" + dataSnapshot.getValue());
        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Log.w(TAG, "Failed to read value.", error.toException());
        }
    };
    publicUserReference.addValueEventListener(valueEventListener);
    privateUserReference.addValueEventListener(valueEventListener);
    privateUserLocationReference.addValueEventListener(valueEventListener);
    userIconReference.addListenerForSingleValueEvent(valueEventListener);
    saveBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveToDatabase();
        }
    });
    // /////////////////////////////////////////
    /**
     * code below needs to be place in the launch of the app so the user can give location
     * permission beforehand.
     */
    LocationManager locationManager = (LocationManager) getSystemService(this.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION }, 1020);
        share_location = true;
        return;
    }
/* Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        lat = location.getLatitude();
        lng = location.getLongitude();*/
}
Also used : PrivateUser(com.example.c4q.capstone.database.privateuserdata.PrivateUser) LocationManager(android.location.LocationManager) PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) PrivateUserLocation(com.example.c4q.capstone.database.privateuserdata.PrivateUserLocation) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) DatabaseError(com.google.firebase.database.DatabaseError) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) ValueEventListener(com.google.firebase.database.ValueEventListener) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 25 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project BloodHub by kazijehangir.

the class AppointmentsFragment method fetchData.

// Getting data from database
public void fetchData() {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            appointments.clear();
            keys.clear();
            for (DataSnapshot child : dataSnapshot.getChildren()) {
                Appointment appointment = child.getValue(Appointment.class);
                appointments.add(appointment);
                keys.add(child.getKey());
            }
            numAppointments.setText("Appointments: " + appointments.size());
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return;
}
Also used : Appointment(com.jexapps.bloodhub.m_Model.Appointment) DatabaseError(com.google.firebase.database.DatabaseError) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Aggregations

FirebaseAuth (com.google.firebase.auth.FirebaseAuth)32 FirebaseUser (com.google.firebase.auth.FirebaseUser)20 Intent (android.content.Intent)11 DataSnapshot (com.google.firebase.database.DataSnapshot)8 DatabaseError (com.google.firebase.database.DatabaseError)8 View (android.view.View)7 ValueEventListener (com.google.firebase.database.ValueEventListener)7 AuthResult (com.google.firebase.auth.AuthResult)6 IdpResponse (com.firebase.ui.auth.IdpResponse)5 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)5 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)4 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 RestrictTo (androidx.annotation.RestrictTo)3 AuthCredential (com.google.firebase.auth.AuthCredential)3 Application (android.app.Application)2 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 FacebookException (com.facebook.FacebookException)2 LoginResult (com.facebook.login.LoginResult)2