Search in sources :

Example 1 with LoginButton

use of com.facebook.login.widget.LoginButton in project quickstart-android by firebase.

the class FacebookLoginActivity method onCreate.

@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);
    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]
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) LoginButton(com.facebook.login.widget.LoginButton) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 2 with LoginButton

use of com.facebook.login.widget.LoginButton in project facebook-android-sdk by facebook.

the class FacebookLoginActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_facebook_login);
    callbackManager = CallbackManager.Factory.create();
    fbLoginButton = (LoginButton) findViewById(R.id._fb_login);
    profilePictureView = (ProfilePictureView) findViewById(R.id.user_pic);
    profilePictureView.setCropped(true);
    userNameView = (TextView) findViewById(R.id.user_name);
    final Button deAuthButton = (Button) findViewById(R.id.deauth);
    deAuthButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (!isLoggedIn()) {
                Toast.makeText(FacebookLoginActivity.this, R.string.app_not_logged_in, Toast.LENGTH_LONG).show();
                return;
            }
            GraphRequest.Callback callback = new GraphRequest.Callback() {

                @Override
                public void onCompleted(GraphResponse response) {
                    try {
                        if (response.getError() != null) {
                            Toast.makeText(FacebookLoginActivity.this, getResources().getString(R.string.failed_to_deauth, response.toString()), Toast.LENGTH_LONG).show();
                        } else if (response.getJSONObject().getBoolean(SUCCESS)) {
                            LoginManager.getInstance().logOut();
                        // updateUI();?
                        }
                    } catch (JSONException ex) {
                    /* no op */
                    }
                }
            };
            GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), GRAPH_PATH, new Bundle(), HttpMethod.DELETE, callback);
            request.executeAsync();
        }
    });
    final Button permsButton = (Button) findViewById(R.id.perms);
    permsButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(final View v) {
            Intent selectPermsIntent = new Intent(FacebookLoginActivity.this, PermissionSelectActivity.class);
            startActivityForResult(selectPermsIntent, PICK_PERMS_REQUEST);
        }
    });
    // Callback registration
    fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(final LoginResult loginResult) {
            // App code
            Toast.makeText(FacebookLoginActivity.this, R.string.success, Toast.LENGTH_LONG).show();
            updateUI();
        }

        @Override
        public void onCancel() {
            // App code
            Toast.makeText(FacebookLoginActivity.this, R.string.cancel, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(final FacebookException exception) {
            // App code
            Toast.makeText(FacebookLoginActivity.this, R.string.error, Toast.LENGTH_LONG).show();
        }
    });
    new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(final Profile oldProfile, final Profile currentProfile) {
            updateUI();
        }
    };
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle) LoginResult(com.facebook.login.LoginResult) JSONException(org.json.JSONException) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) ProfilePictureView(com.facebook.login.widget.ProfilePictureView) Profile(com.facebook.Profile) FacebookCallback(com.facebook.FacebookCallback) ProfileTracker(com.facebook.ProfileTracker) Button(android.widget.Button) LoginButton(com.facebook.login.widget.LoginButton) GraphResponse(com.facebook.GraphResponse) FacebookException(com.facebook.FacebookException)

Example 3 with LoginButton

use of com.facebook.login.widget.LoginButton in project facebook-android-sdk by facebook.

the class ShareFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    mCallbackManager = CallbackManager.Factory.create();
    View view = inflater.inflate(R.layout.share_it_view, container, false);
    LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
    loginButton.setFragment(this);
    loginButton.setReadPermissions("public_profile");
    setupViewPage(view);
    LikeView pageLike = (LikeView) view.findViewById(R.id.like_page);
    pageLike.setFragment(this);
    return view;
}
Also used : LikeView(com.facebook.share.widget.LikeView) View(android.view.View) LikeView(com.facebook.share.widget.LikeView) LoginButton(com.facebook.login.widget.LoginButton)

Example 4 with LoginButton

use of com.facebook.login.widget.LoginButton in project YourAppIdea by Michenux.

the class FbLoginFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.login_facebook, container, false);
    LoginButton loginButton = (LoginButton) view.findViewById(R.id.navmenufacebook_loginbutton);
    loginButton.setReadPermissions("public_profile", "email");
    loginButton.setFragment(this);
    // Hide facebook login button if facebook app not installed
    if (!mFacebookDelegate.isFacebookInstalled()) {
        loginButton.setVisibility(View.GONE);
    }
    return view;
}
Also used : View(android.view.View) LoginButton(com.facebook.login.widget.LoginButton)

Aggregations

LoginButton (com.facebook.login.widget.LoginButton)4 View (android.view.View)3 FacebookException (com.facebook.FacebookException)2 LoginResult (com.facebook.login.LoginResult)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 FacebookCallback (com.facebook.FacebookCallback)1 GraphRequest (com.facebook.GraphRequest)1 GraphResponse (com.facebook.GraphResponse)1 Profile (com.facebook.Profile)1 ProfileTracker (com.facebook.ProfileTracker)1 ProfilePictureView (com.facebook.login.widget.ProfilePictureView)1 LikeView (com.facebook.share.widget.LikeView)1 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)1 FirebaseUser (com.google.firebase.auth.FirebaseUser)1 JSONException (org.json.JSONException)1