com.facebook.login.widget.LoginButton Java Examples

The following examples show how to use com.facebook.login.widget.LoginButton. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FacebookHelper.java    From AndroidBlueprints with Apache License 2.0 6 votes vote down vote up
/**
 * Register call back manager to Google log in button.
 *
 * @param activity    the activity
 * @param loginButton the login button
 */
private void registerCallBackManager(final Activity activity, LoginButton loginButton) {
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            mLoginResult = loginResult;
            getUserProfile(activity);
        }

        @Override
        public void onCancel() {
            mFacebookLoginResultCallBack.onFacebookLoginCancel();
        }

        @Override
        public void onError(FacebookException error) {
            mFacebookLoginResultCallBack.onFacebookLoginError(error);
        }
    });
}
 
Example #2
Source File: FacebookHelper.java    From AndroidBlueprints with Apache License 2.0 5 votes vote down vote up
/**
 * Sign in to google account - with Google's log in button.
 *
 * @param activity    the activity
 * @param callback    the callback to receive the method's result
 * @param loginButton the login button associated with this sign in
 */
public void signIn(@NonNull Activity activity, @NonNull final FacebookLoginResultCallback callback, @NonNull LoginButton loginButton) {
    mCallbackManager = CallbackManager.Factory.create();
    mFacebookLoginResultCallBack = callback;
    initLoginButton(activity, loginButton);
    registerCallBackManager(activity, loginButton);

}
 
Example #3
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //--------------------------------------------//
    FacebookSdk.sdkInitialize(this);//El SDK necesita ser inicializado antes de usar cualquiera de sus métodos,pasando el contexto de la actividad(Activity)
    callbackManager = CallbackManager.Factory.create();//inizializamos el CallbackManager
    //---------------------------------------------//
    setContentView(R.layout.activity_main);

    info = (TextView) findViewById(R.id.info);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    //--------------------------------------------------//

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {//Si la autenticacion fue correcta
            info.setText("Login attempt success.");

        }

        @Override
        public void onCancel() {//Si se cancela la solicitus de login
            info.setText("Login attempt canceled.");
        }

        @Override
        public void onError(FacebookException e) {//Si ocurre un error
            info.setText("Login attempt failed.");
        }
    });
}
 
Example #4
Source File: LoginActivity.java    From android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Launch Onboarding once only
    if (savedInstanceState == null && !isFirstClickFreeIntent(getIntent())) {
        if (PrkngPrefs.getInstance(this).isOnboarding()) {
            startActivityForResult(TutorialActivity.newIntent(this, true), Const.RequestCodes.ONBOARDING);
        }
    }

    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_login);

    vFacebookButton = (LoginButton) findViewById(R.id.btn_facebook);
    vGoogleButton = (Button) findViewById(R.id.btn_google);
    vEmailButton = (Button) findViewById(R.id.btn_email);
    vProgressBar = findViewById(R.id.progress);

    setupListeners();

    setupFacebookLogin();
    setupGoogleLogin();

    logoutIfNecessary();
}
 
Example #5
Source File: MainActivity.java    From EasyLogin with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EasyLogin.initialize();
    easyLogin = EasyLogin.getInstance();

    // TWITTER

    // Initialization needs to happen before setContentView() if using the LoginButton!
    String twitterKey = BuildConfig.TWITTER_CONSUMER_KEY;
    String twitterSecret = BuildConfig.TWITTER_CONSUMER_SECRET;
    easyLogin.addSocialNetwork(new TwitterNetwork(this, twitterKey, twitterSecret));

    setContentView(R.layout.activity_main);

    TwitterNetwork twitter = (TwitterNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.TWITTER);
    twitter.setAdditionalEmailRequest(true);
    TwitterLoginButton twitterButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
    twitter.requestLogin(twitterButton, this);

    // TWITTER END

    // FACEBOOK
    List<String> fbScope = Arrays.asList("public_profile", "email");
    easyLogin.addSocialNetwork(new FacebookNetwork(this, fbScope));

    FacebookNetwork facebook = (FacebookNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.FACEBOOK);
    LoginButton loginButton = (LoginButton) findViewById(R.id.facebook_login_button);
    facebook.requestLogin(loginButton, this);
    // FACEBOOK END

    // G+

    easyLogin.addSocialNetwork(new GooglePlusNetwork(this));
    gPlusNetwork = (GooglePlusNetwork) easyLogin.getSocialNetwork(SocialNetwork.Network.GOOGLE_PLUS);
    gPlusNetwork.setListener(this);

    gPlusButton = (SignInButton) findViewById(R.id.gplus_sign_in_button);

    gPlusNetwork.setSignInButton(gPlusButton);

    // G+ END

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    statusTextView = (TextView) findViewById(R.id.connected_status);
    setSupportActionBar(toolbar);
}
 
Example #6
Source File: FacebookNetwork.java    From EasyLogin with MIT License 4 votes vote down vote up
public void requestLogin(LoginButton button, OnLoginCompleteListener onLoginCompleteListener) {
    setListener(onLoginCompleteListener);
    button.setReadPermissions(permissions);
    button.registerCallback(callbackManager, loginCallback);
}
 
Example #7
Source File: FacebookLoginActivity.java    From quickstart-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBinding = ActivityFacebookBinding.inflate(getLayoutInflater());
    setContentView(mBinding.getRoot());
    setProgressBar(mBinding.progressBar);

    // Views
    mBinding.buttonFacebookSignout.setOnClickListener(this);

    // [START initialize_auth]
    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]

    // [START initialize_fblogin]
    // Initialize Facebook Login button
    mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = mBinding.buttonFacebookLogin;
    loginButton.setReadPermissions("email", "public_profile");
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
            // [START_EXCLUDE]
            updateUI(null);
            // [END_EXCLUDE]
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            // [START_EXCLUDE]
            updateUI(null);
            // [END_EXCLUDE]
        }
    });
    // [END initialize_fblogin]
}
 
Example #8
Source File: FacebookLoginActivity.java    From endpoints-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_facebook);

    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);
    mDetailTextView = (TextView) findViewById(R.id.detail);
    mResponseTextView = (TextView) findViewById(R.id.response);
    findViewById(R.id.button_facebook_signout).setOnClickListener(this);

    // [START initialize_auth]
    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]

    // [START auth_state_listener]
    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");
            }
            // [START_EXCLUDE]
            updateUI(user);
            // [END_EXCLUDE]
        }
    };
    // [END auth_state_listener]

    // [START initialize_fblogin]
    // Initialize Facebook Login button
    mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
    loginButton.setReadPermissions("email", "public_profile");
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
            // [START_EXCLUDE]
            updateUI(null);
            // [END_EXCLUDE]
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            // [START_EXCLUDE]
            updateUI(null);
            // [END_EXCLUDE]
        }
    });
    // [END initialize_fblogin]
}
 
Example #9
Source File: LoginWithFacebookSDKActivity.java    From Android-SDK with MIT License 4 votes vote down vote up
private void initUI() {
	loginFacebookButton = (LoginButton) findViewById(R.id.button_FacebookLogin);
	fbLogoutBackendlessButton = (Button) findViewById(R.id.button_fbBackendlessLogout);
	socialAccountInfo = (EditText) findViewById(R.id.editText_fbSocialAccountInfo);
	backendlessUserInfo = (EditText) findViewById(R.id.editText_fbBackendlessUserInfo);
}
 
Example #10
Source File: FacebookHelper.java    From AndroidBlueprints with Apache License 2.0 2 votes vote down vote up
/**
 * Init Google log in button.
 *
 * @param activity the activity
 */
private void initLoginButton(Activity activity, LoginButton loginButton) {
    loginButton.setReadPermissions(getFacebookReadPermissions());
    loginButton.setLoginBehavior(LoginBehavior.NATIVE_WITH_FALLBACK);
}