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);
}
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);
}
});
}
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();
}
}
}
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();
}
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);
}
});
}
Aggregations