Search in sources :

Example 1 with AccessTokenTracker

use of com.facebook.AccessTokenTracker in project facebook-android-sdk by facebook.

the class LoginButton method configureButton.

@Override
protected void configureButton(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
    super.configureButton(context, attrs, defStyleAttr, defStyleRes);
    setInternalOnClickListener(getNewLoginClickListener());
    parseLoginButtonAttributes(context, attrs, defStyleAttr, defStyleRes);
    if (isInEditMode()) {
        // cannot use a drawable in edit mode, so setting the background color instead
        // of a background resource.
        setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
        // hardcoding in edit mode as getResources().getString() doesn't seem to work in
        // IntelliJ
        loginText = "Continue with Facebook";
    } else {
        accessTokenTracker = new AccessTokenTracker() {

            @Override
            protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
                setButtonText();
            }
        };
    }
    setButtonText();
    // set vector drawables on the button
    setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(getContext(), R.drawable.com_facebook_button_login_logo), null, null, null);
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) AccessToken(com.facebook.AccessToken)

Example 2 with AccessTokenTracker

use of com.facebook.AccessTokenTracker in project facebook-android-sdk by facebook.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        userSkippedLogin = savedInstanceState.getBoolean(USER_SKIPPED_LOGIN_KEY);
    }
    callbackManager = CallbackManager.Factory.create();
    accessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (isResumed) {
                FragmentManager manager = getFragmentManager();
                int backStackSize = manager.getBackStackEntryCount();
                for (int i = 0; i < backStackSize; i++) {
                    manager.popBackStack();
                }
                if (currentAccessToken != null) {
                    showFragment(SELECTION, false);
                } else {
                    showFragment(SPLASH, false);
                }
            }
        }
    };
    setContentView(R.layout.main);
    FragmentManager fm = getFragmentManager();
    SplashFragment splashFragment = (SplashFragment) fm.findFragmentById(R.id.splashFragment);
    fragments[SPLASH] = splashFragment;
    fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
    fragments[SETTINGS] = fm.findFragmentById(R.id.userSettingsFragment);
    FragmentTransaction transaction = fm.beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        transaction.hide(fragments[i]);
    }
    transaction.commit();
    splashFragment.setSkipLoginCallback(new SplashFragment.SkipLoginCallback() {

        @Override
        public void onSkipLoginPressed() {
            userSkippedLogin = true;
            showFragment(SELECTION, false);
        }
    });
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction) AccessToken(com.facebook.AccessToken)

Example 3 with AccessTokenTracker

use of com.facebook.AccessTokenTracker in project facebook-android-sdk by facebook.

the class PickerFragment method onActivityCreated.

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    accessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            clearResults();
        }
    };
    setSettingsFromBundle(savedInstanceState);
    loadingStrategy = createLoadingStrategy();
    loadingStrategy.attach(adapter);
    selectionStrategy = createSelectionStrategy();
    selectionStrategy.readSelectionFromBundle(savedInstanceState, SELECTION_BUNDLE_KEY);
    // Should we display a title bar? (We need to do this after we've retrieved our bundle settings.)
    if (showTitleBar) {
        inflateTitleBar((ViewGroup) getView());
    }
    if (activityCircle != null && savedInstanceState != null) {
        boolean shown = savedInstanceState.getBoolean(ACTIVITY_CIRCLE_SHOW_KEY, false);
        if (shown) {
            displayActivityCircle();
        } else {
            // Should be hidden already, but just to be sure.
            hideActivityCircle();
        }
    }
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) AccessToken(com.facebook.AccessToken)

Example 4 with AccessTokenTracker

use of com.facebook.AccessTokenTracker in project facebook-android-sdk by facebook.

the class UserSettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    accessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            fetchUserInfo();
            updateUI();
        }
    };
    callbackManager = CallbackManager.Factory.create();
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) AccessToken(com.facebook.AccessToken)

Example 5 with AccessTokenTracker

use of com.facebook.AccessTokenTracker in project react-native-fbsdk by facebook.

the class RCTLoginButton method init.

public void init() {
    mAccessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (currentAccessToken == null) {
                WritableMap event = Arguments.createMap();
                event.putString("type", "logoutFinished");
                ReactContext context = (ReactContext) getContext();
                context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
            }
        }
    };
    this.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            result.putArray("grantedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyGrantedPermissions())));
            result.putArray("declinedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyDeniedPermissions())));
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onError(FacebookException error) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", error.toString());
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onCancel() {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", true);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }
    });
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) WritableMap(com.facebook.react.bridge.WritableMap) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) ReactContext(com.facebook.react.bridge.ReactContext) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult)

Aggregations

AccessToken (com.facebook.AccessToken)7 AccessTokenTracker (com.facebook.AccessTokenTracker)7 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 FacebookException (com.facebook.FacebookException)1 Profile (com.facebook.Profile)1 ProfileTracker (com.facebook.ProfileTracker)1 LoginResult (com.facebook.login.LoginResult)1 ReactContext (com.facebook.react.bridge.ReactContext)1 WritableMap (com.facebook.react.bridge.WritableMap)1 ThemedReactContext (com.facebook.react.uimanager.ThemedReactContext)1