Search in sources :

Example 1 with LoginResult

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

the class SplashFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.splash, container, false);
    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) view.findViewById(R.id.login_button);
    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getActivity(), "Login successful", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast.makeText(getActivity(), "Login canceled", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(FacebookException exception) {
            Toast.makeText(getActivity(), "Login error", Toast.LENGTH_SHORT).show();
        }
    });
    skipLoginButton = (TextView) view.findViewById(R.id.skip_login_button);
    skipLoginButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (skipLoginCallback != null) {
                skipLoginCallback.onSkipLoginPressed();
            }
        }
    });
    return view;
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) TextView(android.widget.TextView) View(android.view.View)

Example 2 with LoginResult

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

the class SettingsFragment method setUpCallbacks.

private void setUpCallbacks() {
    callbackManager = CallbackManager.Factory.create();
    LoginManager manager = LoginManager.getInstance();
    manager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Profile.fetchProfileForCurrentAccessToken();
        }

        @Override
        public void onError(FacebookException exception) {
            AccessToken.setCurrentAccessToken(null);
            currentUserChanged();
        }

        @Override
        public void onCancel() {
            AccessToken.setCurrentAccessToken(null);
            currentUserChanged();
        }
    });
    profileTracker = new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            Slot currentSlot = slotManager.getSelectedSlot();
            AccessToken currentAccessToken = AccessToken.getCurrentAccessToken();
            if (currentSlot != null && currentAccessToken != null && currentProfile != null) {
                currentSlot.setUserInfo(new UserInfo(currentProfile.getName(), currentAccessToken));
                currentUserChanged();
            }
        }
    };
}
Also used : LoginManager(com.facebook.login.LoginManager) ProfileTracker(com.facebook.ProfileTracker) FacebookException(com.facebook.FacebookException) AccessToken(com.facebook.AccessToken) LoginResult(com.facebook.login.LoginResult) Profile(com.facebook.Profile)

Example 3 with LoginResult

use of com.facebook.login.LoginResult in project EC2018App by Manan-YMCA.

the class FragmentFbLogin method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fblogin_dialog_box, container, false);
    if (mContext == null) {
        mContext = getActivity();
    }
    skipLogin = (TextView) rootView.findViewById(R.id.tv_skip_fb_login);
    loginButton = (LoginButton) rootView.findViewById(R.id.login_button);
    FacebookSdk.sdkInitialize(mContext);
    callbackManager = CallbackManager.Factory.create();
    barLogin = (ProgressBar) rootView.findViewById(R.id.pb_login);
    mAuth = FirebaseAuth.getInstance();
    skipLogin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            fbLoginButton activity = (fbLoginButton) getActivity();
            activity.fbStatus(false, null);
            dismiss();
        }
    });
    final String EMAIL = "email";
    loginButton.setReadPermissions(Arrays.asList(EMAIL));
    loginButton.setFragment(this);
    // If you are using in a fragment, call loginButton.setFragment(this);
    // Callback registration
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            barLogin.setVisibility(View.VISIBLE);
            skipLogin.setClickable(false);
            skipLogin.setLongClickable(false);
            skipLogin.setVisibility(View.INVISIBLE);
            getDialog().setCancelable(false);
            AccessToken accessToken = loginResult.getAccessToken();
            fbLoginButton activity = (fbLoginButton) mContext;
            handleFacebookAccessToken(loginResult.getAccessToken());
            activity.fbStatus(true, accessToken.getUserId());
        }

        @Override
        public void onCancel() {
            MDToast.makeText(mContext, "Facebook login cancelled", Toast.LENGTH_SHORT, MDToast.TYPE_ERROR).show();
        }

        @Override
        public void onError(FacebookException exception) {
        }
    });
    return rootView;
}
Also used : AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) View(android.view.View) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable)

Example 4 with LoginResult

use of com.facebook.login.LoginResult in project Devsfolio by Madonahs.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /*Send user to Main activity if they're already signed in*/
    if (LoginStatusManager.getLoginStatus(this) && FirebaseAuth.getInstance().getCurrentUser() != null) {
        startActivity(new Intent(this, MainActivity.class));
        return;
    }
    binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
    mCallbackManager = CallbackManager.Factory.create();
    // Binding and listening to all the buttons
    binding.btnLogin.setOnClickListener(this);
    binding.btnRegister.setOnClickListener(this);
    binding.btnFacebookLogin.setOnClickListener(this);
    binding.btnGoogleLogin.setOnClickListener(this);
    // Buttons initial state
    binding.btnLogin.setBackgroundResource(R.drawable.button_rounded_focused);
    binding.btnRegister.setBackgroundResource(R.drawable.button_rounded_normal);
    // this will set login fragment as the first thing you see
    setViewPager(binding.container);
    // Google login set up
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
    // Switch between login fragment and register fragment
    binding.btnRegister.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Toggle buttons
            binding.btnLogin.setBackgroundResource(R.drawable.button_rounded_normal);
            binding.btnRegister.setBackgroundResource(R.drawable.button_rounded_focused);
            // Toast.makeText(LoginActivity.this, "Going to register fragment", Toast.LENGTH_SHORT).show();
            registerFragment();
        }
    });
    binding.btnLogin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Toggle buttons
            binding.btnLogin.setBackgroundResource(R.drawable.button_rounded_focused);
            binding.btnRegister.setBackgroundResource(R.drawable.button_rounded_normal);
            // Toast.makeText(LoginActivity.this, "Going to login fragment", Toast.LENGTH_SHORT).show();
            setViewPager(binding.container);
        }
    });
    // Custom facebook login button
    binding.btnFacebookLogin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this, Arrays.asList(PUBLIC_PROFILE_PERMISSION, EMAIL_PERMISSION));
        }
    });
    LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getBaseContext(), R.string.facebook_login_success, Toast.LENGTH_LONG).show();
            Log.d(TAG, "Facebook user id: " + loginResult.getAccessToken().getUserId());
            Log.d(TAG, "Facebook access token: " + loginResult.getAccessToken().getToken());
            // TODO: Use the returned token from loginResult to make a graph API request for user info (name, email, ....)
            // Redirect user to the MainActivity
            Intent mainActivityIntent = new Intent(getBaseContext(), MainActivity.class);
            startActivity(mainActivityIntent);
        }

        @Override
        public void onCancel() {
            Toast.makeText(getBaseContext(), R.string.facebook_login_cancel, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(FacebookException error) {
            Toast.makeText(getBaseContext(), R.string.facebook_login_error, Toast.LENGTH_LONG).show();
        }
    });
    // setup the onboarding activity
    Once.initialise(this);
    if (!Once.beenDone(Once.THIS_APP_INSTALL, "showTutorial")) {
        Log.i(TAG, "onCreate: First time");
        startActivityForResult(new Intent(this, OnBoardingActivity.class), SHOW_INTRO);
    }
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) OnBoardingActivity(com.madonasyombua.growwithgoogleteamproject.ui.intro.OnBoardingActivity) Intent(android.content.Intent) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) View(android.view.View)

Example 5 with LoginResult

use of com.facebook.login.LoginResult in project android by testpress.

the class LoginActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    Injector.inject(this);
    accountManager = AccountManager.get(this);
    final Intent intent = getIntent();
    username = intent.getStringExtra(PARAM_USERNAME);
    authTokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
    confirmCredentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false);
    requestNewAccount = username == null;
    if (AccessToken.getCurrentAccessToken() != null) {
        LoginManager.getInstance().logOut();
    }
    setContentView(layout.login_activity);
    ButterKnife.inject(this);
    UIUtils.setIndeterminateDrawable(this, progressBar, 4);
    passwordText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == IME_ACTION_SEND && signInButton.isEnabled()) {
                signIn();
                return true;
            }
            return false;
        }
    });
    usernameText.addTextChangedListener(watcher);
    usernameText.setSingleLine();
    passwordText.addTextChangedListener(watcher);
    passwordText.setTypeface(Typeface.DEFAULT);
    passwordText.setTransformationMethod(new PasswordTransformationMethod());
    callbackManager = CallbackManager.Factory.create();
    fbLoginButton.invalidate();
    fbLoginButton.setReadPermissions("email");
    fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            loginLayout.setVisibility(View.GONE);
            username = loginResult.getAccessToken().getUserId();
            authenticate(loginResult.getAccessToken().getUserId(), loginResult.getAccessToken().getToken(), TestpressSdk.Provider.FACEBOOK);
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException error) {
            if (error.getMessage().contains("CONNECTION_FAILURE")) {
                showAlert(getString(R.string.no_internet_try_again));
            } else {
                Log.e("Facebook sign in error", "check hashes");
                showAlert(getString(R.string.something_went_wrong_please_try_after));
            }
        }
    });
    GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(getString(R.string.server_client_id)).build();
    googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {

        @Override
        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
            if (connectionResult.getErrorMessage() != null) {
                showAlert(connectionResult.getErrorMessage());
            } else {
                showAlert(connectionResult.toString());
            }
        }
    }).addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions).build();
    orLabel.setTypeface(TestpressSdk.getRubikMediumFont(this));
    DaoSession daoSession = ((TestpressApplication) getApplicationContext()).getDaoSession();
    instituteSettingsDao = daoSession.getInstituteSettingsDao();
    List<InstituteSettings> instituteSettingsList = instituteSettingsDao.queryBuilder().where(InstituteSettingsDao.Properties.BaseUrl.eq(Constants.Http.URL_BASE)).list();
    if (instituteSettingsList.size() == 0) {
        getInstituteSettings();
    } else {
        instituteSettings = instituteSettingsList.get(0);
        updateInstituteSpecificFields();
    }
}
Also used : LoginResult(com.facebook.login.LoginResult) Intent(android.content.Intent) InstituteSettings(in.testpress.testpress.models.InstituteSettings) TestpressApplication(in.testpress.testpress.TestpressApplication) KeyEvent(android.view.KeyEvent) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) FacebookException(com.facebook.FacebookException) NonNull(android.support.annotation.NonNull) ConnectionResult(com.google.android.gms.common.ConnectionResult) TextView(android.widget.TextView) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) DaoSession(in.testpress.testpress.models.DaoSession)

Aggregations

LoginResult (com.facebook.login.LoginResult)25 FacebookException (com.facebook.FacebookException)22 View (android.view.View)12 TextView (android.widget.TextView)10 AccessToken (com.facebook.AccessToken)9 Intent (android.content.Intent)7 FacebookCallback (com.facebook.FacebookCallback)7 LoginButton (com.facebook.login.widget.LoginButton)7 CallbackManager (com.facebook.CallbackManager)6 LoginManager (com.facebook.login.LoginManager)6 ArrayList (java.util.ArrayList)6 Profile (com.facebook.Profile)5 Bundle (android.os.Bundle)4 Activity (android.app.Activity)3 Toolbar (android.support.v7.widget.Toolbar)3 ImageView (android.widget.ImageView)3 ProfileTracker (com.facebook.ProfileTracker)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ObjectAnimator (android.animation.ObjectAnimator)2