Java 类com.google.firebase.auth.UserInfo 实例源码

项目:social-app-android    文件:LogoutHelper.java   
public static void signOut(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        DatabaseHelper.getInstance(fragmentActivity.getApplicationContext())
                .removeRegistrationToken(FirebaseInstanceId.getInstance().getToken(), user.getUid());

        for (UserInfo profile : user.getProviderData()) {
            String providerId = profile.getProviderId();
            logoutByProvider(providerId, mGoogleApiClient, fragmentActivity);
        }
        logoutFirebase(fragmentActivity.getApplicationContext());
    }

    if (clearImageCacheAsyncTask == null) {
        clearImageCacheAsyncTask = new ClearImageCacheAsyncTask(fragmentActivity.getApplicationContext());
        clearImageCacheAsyncTask.execute();
    }
}
项目:snippets-android    文件:MainActivity.java   
private void getProviderData() {
    // [START get_provider_data]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        for (UserInfo profile : user.getProviderData()) {
            // Id of the provider (ex: google.com)
            String providerId = profile.getProviderId();

            // UID specific to the provider
            String uid = profile.getUid();

            // Name, email address, and profile photo Url
            String name = profile.getDisplayName();
            String email = profile.getEmail();
            Uri photoUrl = profile.getPhotoUrl();
        };
    }
    // [END get_provider_data]
}
项目:social-journal    文件:MainActivity.java   
private void syncUserProfiles() {
        String uid = mFirebaseUser.getUid();
        final DatabaseReference user = mDatabase.getReference("/users").child(uid);
        user.child("email").setValue(mFirebaseUser.getEmail());
        user.child("name").setValue(mFirebaseUser.getDisplayName());
        setDisplayName(mFirebaseUser.getDisplayName());
        for (UserInfo userInfo : mFirebaseUser.getProviderData()) {
            if (!userInfo.getProviderId().equals("firebase")) {
                user.child(userInfo.getProviderId().split("\\.")[0]).setValue(userInfo.getUid());
            }
        }
//        if (isUsingInstagram()) {
//            if (instagramEngine == null) {
//                setupInstagram();
//            }
//            instagramEngine.getUserDetails(new InstagramUserIdCallback(user));
//        }
    }
项目:MikuyConcept    文件:SessionHandler.java   
@Override
public void saveUserInfo() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        String id = "";
        String name = user.getDisplayName();
        String email = user.getEmail();
        String photoUrl = user.getPhotoUrl().toString();

        for (UserInfo profile : user.getProviderData()) {
            String providerId = profile.getProviderId();
            if (providerId.compareToIgnoreCase("facebook.com") == 0) {
                id = profile.getUid();
                break;
            }
        }
        userInfo.put(USERINFO.ID, id);
        userInfo.put(USERINFO.FIRSTNAME, name.split(" ")[0]);
        userInfo.put(USERINFO.FULLNAME, name);
        userInfo.put(USERINFO.IMAGE_URL, photoUrl);
        userInfo.put(USERINFO.EMAIL, email);
    }

}
项目:flavordex    文件:SettingsActivity.java   
@Override
protected Void doInBackground(Void... voids) {
    final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if(user != null) {
        for(UserInfo info : user.getProviderData()) {
            switch(info.getProviderId()) {
                case GoogleAuthProvider.PROVIDER_ID:
                    logoutGoogle();
                    break;
                case FacebookAuthProvider.PROVIDER_ID:
                    logoutFacebook();
                    break;
                case TwitterAuthProvider.PROVIDER_ID:
                    logoutTwitter();
                    break;
            }
        }
        FirebaseAuth.getInstance().signOut();
    }
    return null;
}
项目:roboclub-amu    文件:AdminFragment.java   
private void showProviders(FirebaseUser user) {
    List<? extends UserInfo> providers = user.getProviderData();

    for (int i = 0; i < providers.size(); i++) {
        UserInfo userInfo = providers.get(i);

        RadioButton radioButton = createRadio(userInfo.getProviderId());
        radioButton.setId(i);
        if(userInfo.getPhotoUrl()!= null && userInfo.getPhotoUrl().equals(user.getPhotoUrl())) {
            radioButton.setChecked(true);
        }
        providersLayout.addView(radioButton);
    }

    providersLayout.setOnCheckedChangeListener((group, checkedId) -> {
        Uri uri = providers.get(checkedId).getPhotoUrl();
        showImageAvatar(uri);
    });
}
项目:FirebaseUI-Android    文件:AuthUI.java   
/**
 * Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
 * for saving since we don't have access to the password.
 */
private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
    if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
        return Collections.emptyList();
    }

    List<Credential> credentials = new ArrayList<>();
    for (UserInfo userInfo : user.getProviderData()) {
        if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
            continue;
        }

        String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());

        credentials.add(new Credential.Builder(
                user.getEmail() == null ? user.getPhoneNumber() : user.getEmail())
                .setAccountType(type)
                .build());
    }

    return credentials;
}
项目:School1-Android    文件:DashboardAdapter.java   
public DashboardAdapter(Context context) {
    Calendar calendar = Calendar.getInstance();
    int today = calendar.get(Calendar.DAY_OF_WEEK);

    // Today is default
    rowItems.add(new Section(context.getString(R.string.section_title_today), getSectionDate(calendar)));
    calendar.add(Calendar.DAY_OF_YEAR, 1);

    if (today >= Calendar.MONDAY && today <= Calendar.WEDNESDAY) {
        rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        rowItems.add(new Section(context.getString(R.string.section_title_this_week), getSectionDate(calendar)));
    } else if (today == Calendar.THURSDAY) {
        rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        rowItems.add(new Section(context.getString(R.string.section_title_weekend), getSectionDate(calendar)));
    } else if (today == Calendar.FRIDAY)
        rowItems.add(new Section(context.getString(R.string.section_title_weekend), getSectionDate(calendar)));
    else if (today == Calendar.SATURDAY)
        rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));

    calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

    if (calendar.getFirstDayOfWeek() != Calendar.SUNDAY || today != Calendar.SUNDAY)
        calendar.add(Calendar.WEEK_OF_YEAR, 1);

    rowItems.add(new Section(context.getString(R.string.section_title_next_week), getSectionDate(calendar)));

    // TODO: Holiday and interval sections (between two holidays, to give a clearer overview over whats happening in the long run)
    calendar.add(Calendar.WEEK_OF_YEAR, 1);
    rowItems.add(new Section("Until the end of the universe", getSectionDate(calendar)));

    // TODO: Listen on login
    UserInfo userInfo = FirebaseAuth.getInstance().getCurrentUser();
    if (userInfo != null) {
        DocumentReference userReference = FirebaseFirestore.getInstance()
                .collection("users")
                .document(userInfo.getUid());

        userReference.collection("groups")
                .addSnapshotListener(this);
        userReference.collection("items")
                .addSnapshotListener(new GroupItemsChangeListener(FirebaseAuth.getInstance().getCurrentUser().getUid()));
    }
}
项目:GodotFireBase    文件:FacebookSignIn.java   
public void init() {
    // Initialize listener.
    // ...

    FacebookSdk.sdkInitialize(activity);
    // FacebookSdk.setApplicationId(activity.getString(R.string.facebook_app_id));

    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                for (UserInfo usr : user.getProviderData()) {
                    if (usr.getProviderId().equals("facebook.com")) {
                        Utils.d("FB:AuthStateChanged:signed_in:"+
                        user.getUid());
                        successLogin(user);
                    }
                }
            } else {
                // User is signed out
                Utils.d("FB:onAuthStateChanged:signed_out");
                successLogOut();
            }

            // update user details;
        }
    };

    // AppEventsLogger.activityApp(activity);

    initCallbacks();
    onStart();

    Utils.d("Facebook auth initialized.");
}
项目:GodotFireBase    文件:TwitterSignIn.java   
public void init() {
    TwitterAuthConfig authConfig = new TwitterAuthConfig(
    activity.getString(R.string.twitter_consumer_key),
    activity.getString(R.string.twitter_consumer_secret));

    Fabric.with(activity, new Twitter(authConfig));

    mAuth = FirebaseAuth.getInstance();

    twitterAuthClient = new TwitterAuthClient();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();

            if (user != null) {
                // User is signed in
                for (UserInfo usr : user.getProviderData()) {
                    if (usr.getProviderId().equals("twitter.com")) {
                        Utils.d("Twitter:AuthStateChanged:signed_in:"+
                        user.getUid());

                        successSignIn(user);
                    }
                }

            } else {
                // User is signed out
                Utils.d("Twitter:onAuthStateChanged:signed_out");
                successSignOut();
            }

            // update firebase auth dets.
        }
    };

    onStart();
}
项目:BuddyBook    文件:User.java   
public static User setupUserFirstTime(FirebaseUser firebaseUser, Context context) {

        User user = new User(firebaseUser.getUid(),
                firebaseUser.getEmail(),
                firebaseUser.getDisplayName(),
                firebaseUser.getPhotoUrl() == null ? null : firebaseUser.getPhotoUrl().toString(),
                DateUtils.getCurrentTimeString());

        try {
            if (user.getPhotoUrl() == null) {
                for (UserInfo userInfo : firebaseUser.getProviderData()) {
                    if (userInfo.getPhotoUrl() != null) {
                        user.setPhotoUrl(userInfo.getPhotoUrl().toString());
                        break;
                    }
                }
            }
        } catch (Exception ex) {

        }

        Folder myBooksFolder = new Folder();
        myBooksFolder.setId(UUID.randomUUID().toString());
        myBooksFolder.setDescription(context.getResources().getString(R.string.tab_my_books));
        myBooksFolder.setCustom(false);

        user.setFolders(Collections.singletonMap(FirebaseDatabaseHelper.REF_MY_BOOKS_FOLDER, myBooksFolder));

        return user;

    }
项目:cordova-plugin-firebase-sdk    文件:AuthComponent.java   
private static JSONObject firebaseUserToJSONObject(FirebaseUser firebaseUser) throws Exception {
    JSONObject jsonUser = userInfoToJSONObject((UserInfo) firebaseUser);
    jsonUser.put("isAnonymous", firebaseUser.isAnonymous());

    JSONArray providerDataArray = new JSONArray();
    for (UserInfo userInfo : firebaseUser.getProviderData()) {
        providerDataArray.put(userInfoToJSONObject(userInfo));
    }
    jsonUser.put("providerData", providerDataArray);

    return jsonUser;
}
项目:cordova-plugin-firebase-sdk    文件:AuthComponent.java   
private static JSONObject userInfoToJSONObject(UserInfo userInfo) throws Exception {
    Uri photoUrl = userInfo.getPhotoUrl();

    JSONObject jsonUser = new JSONObject();
    jsonUser.put("uid", userInfo.getUid());
    jsonUser.put("displayName", userInfo.getDisplayName());
    jsonUser.put("email", userInfo.getEmail());
    jsonUser.put("photoURL", (photoUrl != null) ? photoUrl.toString() : null);
    jsonUser.put("providerId", userInfo.getProviderId());
    jsonUser.put("emailVerified", userInfo.isEmailVerified());
    return jsonUser;
}
项目:sabbath-school-android    文件:SSLoginViewModel.java   
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
    FirebaseUser user = firebaseAuth.getCurrentUser();
    if (user != null && firebaseBugFlag) {
        firebaseBugFlag = false;
        for (UserInfo profile : user.getProviderData()) {
            String providerId = profile.getProviderId();
            if (providerId.equals(FIREBASE_PROVIDER_ID)) {
                if (!user.isAnonymous()) {
                    if (context != null) {
                        String name = profile.getDisplayName();
                        String email = profile.getEmail();
                        Uri photoUrl = profile.getPhotoUrl();
                        String photo = photoUrl != null ? photoUrl.toString() : "";

                        SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
                        SharedPreferences.Editor editor = shared.edit();
                        editor.putString(SSConstants.SS_USER_NAME_INDEX, name);
                        editor.putString(SSConstants.SS_USER_EMAIL_INDEX, email);
                        editor.putString(SSConstants.SS_USER_PHOTO_INDEX, photo);
                        editor.commit();
                    }
                }

                SSEvent.track(SSConstants.SS_EVENT_APP_OPEN);

                openApp();
            }
        }
    }
}
项目:flavordex    文件:SettingsActivity.java   
/**
 * Update the visibility of the edit account preference based on whether the current user
 * is authenticated using the email provider.
 */
private void invalidateEditAccountPref() {
    mPrefEditAccount.setVisible(false);
    final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if(user != null) {
        for(UserInfo info : user.getProviderData()) {
            if(info.getProviderId().equals(EmailAuthProvider.PROVIDER_ID)) {
                mPrefEditAccount.setVisible(true);
                return;
            }
        }
    }
}
项目:LuxVilla    文件:Userprofile.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_userprofile);

    toolbarLayout= findViewById(R.id.tbprofile);
    toolbar= findViewById(R.id.barprofileactivity);
    toolbar.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
    setSupportActionBar(toolbar);
    profileimage= findViewById(R.id.imgprofile);
    mAuth=FirebaseAuth.getInstance();
    user=mAuth.getCurrentUser();
    if (user !=null) {
        for (UserInfo userdata: user.getProviderData()) {

            profileDisplayName=userdata.getDisplayName();
            toolbarLayout.setTitle(profileDisplayName);
            profilePhotoUrl=userdata.getPhotoUrl();
        }
        if (profilePhotoUrl !=null){
            String image=profilePhotoUrl.toString();
            Picasso.with(Userprofile.this)
                    .load(image)
                    .fit()
                    .into(profileimage);
        }else{
            profileimage.setImageDrawable(ContextCompat.getDrawable(Userprofile.this,R.drawable.nouserimage));
        }
    }
    tbs= findViewById(R.id.profiletabs);
    tbs.setSelectedTabIndicatorColor(ContextCompat.getColor(Userprofile.this,R.color.colorAccent));
    vwpgr= findViewById(R.id.profilevpgr);
    adaptadortabs adaptador=new adaptadortabs(getSupportFragmentManager());
    vwpgr.setAdapter(adaptador);
    tbs.setupWithViewPager(vwpgr);

}
项目:LuxVilla    文件:Editprofile.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_editprofile);

    toolbar= findViewById(R.id.barprofileactivity);
    toolbar.setTitle("Editar perfil");
    toolbar.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
    setSupportActionBar(toolbar);

    linearLayout= findViewById(R.id.linearLayouteditprofile);
    textInputLayoutusername= findViewById(R.id.text_input_username);

    editTextusername= findViewById(R.id.edittextusername);
    editTextuserbio= findViewById(R.id.edittextbio);

    mAuth=FirebaseAuth.getInstance();

    user=mAuth.getCurrentUser();
    if (user !=null){
        for (UserInfo userdata: user.getProviderData()) {
            String userprovider=userdata.getProviderId();

            if (userprovider.equals("google.com")){
                textInputLayoutusername.setVisibility(View.GONE);
            }
        }
    }
}
项目:roboclub-amu    文件:AdminFragment.java   
@OnClick(R.id.save_btn)
public void saveUser() {
    FirebaseUser user = auth.getCurrentUser();

    if(user == null)
        return;

    UserProfileChangeRequest.Builder userProfileChangeRequest = new UserProfileChangeRequest.Builder();

    String userName = name.getText().toString();
    if(!userName.equals(auth.getCurrentUser().getDisplayName())) {
        userProfileChangeRequest.setDisplayName(userName);
    }

    int index = providersLayout.getCheckedRadioButtonId();
    List<? extends UserInfo> providerData = user.getProviderData();
    if(index >= 0 && index < providerData.size()) {
        Uri uri = providerData.get(index).getPhotoUrl();
        if(uri != null && !uri.equals(user.getPhotoUrl())) {
            userProfileChangeRequest.setPhotoUri(uri);
        }
    }

    progressBar.setVisibility(View.VISIBLE);
    user.updateProfile(userProfileChangeRequest.build())
            .addOnCompleteListener(task -> {
                progressBar.setVisibility(View.INVISIBLE);
                if (task.isSuccessful()) {
                    showSnackbar(R.string.profile_updated);
                }
            });
}
项目:School1-Android    文件:SigninActivity.java   
private void onSuccess(UserInfo user) {
    finish();
}
项目:GodotFireBase    文件:GoogleSignIn.java   
public void init() {
    // Initialize listener.
    // ...

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestIdToken(activity.getString(R.string.default_web_client_id))
               .requestEmail()
    .build();

    /**

    try {
        Class.forName("org.godotengine.godot.PlayService");
    } catch () {  }

     **/

    mGoogleApiClient = new GoogleApiClient.Builder(activity)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
    .build();

    Utils.d("Google:Initialized");

    mAuth = FirebaseAuth.getInstance();

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();

            if (user != null) {
                for (UserInfo usr : user.getProviderData()) {
                    if (usr.getProviderId().equals("google.com")) {
                        Utils.d("Google:AuthStateChanged:signed_in:"+
                        user.getUid());

                        successSignIn(user);
                    }
                }
            } else {
                // User is signed out
                Utils.d("Google:onAuthStateChanged:signed_out");
                successSignOut();
            }

            // update firebase auth dets.
        }
    };

    onStart(); // calling on start form init
}
项目:Rubit    文件:FirebaseUtils.java   
/**
 * get user details
 *
 * @return UserModel
 */
public static UserModel getUserDetails() {
    final FirebaseUser user = getFirebaseNewInstance().getCurrentUser();
    if (user == null)
        return null;

    String name = user.getDisplayName();
    String email = user.getEmail();
    String picture = user.getPhotoUrl() != null ? user.getPhotoUrl().toString() : null;
    for (UserInfo userInfo : user.getProviderData()) {
        if (name == null && userInfo.getDisplayName() != null) {
            name = userInfo.getDisplayName();
        }

        if (email == null && userInfo.getEmail() != null) {
            email = userInfo.getEmail();
        }
    }

    // Tag
    Map<String, Boolean> tags = new HashMap<>();
    tags.put(DatabaseConstants.TAG_OTHERS, true);
    tags.put(DatabaseConstants.TAG_ANDROID, false);
    tags.put(DatabaseConstants.TAG_IOS, false);
    tags.put(DatabaseConstants.TAG_RUBY, false);
    tags.put(DatabaseConstants.TAG_PYTHON, false);
    tags.put(DatabaseConstants.TAG_NODEJS, false);

    return new UserModel(
            getCurrentUserId(),
            null,
            null,
            null,
            email,
            name,
            picture,
            0,
            false,
            tags,
            null);
}