예제 #1
0
  public void auth(final Activity activity, String[] scope, OnAuthListener listener) {
    authListener = listener;
    currentAction = ACTION_AUTH;

    simpleFacebook = SimpleFacebook.getInstance(activity);

    simpleFacebook.login(
        new OnLoginListener() {
          @Override
          public void onLogin(
              final String accessToken,
              List<Permission> acceptedPermissions,
              List<Permission> declinedPermissions) {
            // (accessToken, simpleFacebook.getAccessToken().getUserId());
            switch (currentAction) {
              case ACTION_AUTH:
                if (authListener != null) {
                  authListener.onSuccess(
                      VKSdk.getAccessToken().accessToken, VKSdk.getAccessToken().userId);
                }
                break;
              case ACTION_POST:
                post(activity, SSNetwork.getBitmap(), SSNetwork.getText(), getListener());
                break;
            }

            currentAction = ACTION_NONE;
          }

          @Override
          public void onCancel() {
            // user canceled the dialog
            Log.i(TAG, "cancel");
          }

          @Override
          public void onFail(String reason) {
            // failed to login
            switch (currentAction) {
              case ACTION_AUTH:
                if (authListener != null) authListener.onError(reason);
                break;
            }

            Log.e(TAG, "error: " + reason);
          }

          @Override
          public void onException(Throwable throwable) {
            // exception from facebook
            switch (currentAction) {
              case ACTION_AUTH:
                if (authListener != null) authListener.onError(throwable.toString());
                break;
            }

            Log.e(TAG, "error: " + throwable.toString());
          }
        });
  }
 /**
  * Set buttons and all ui controls to be enabled or disabled according to facebook login status
  */
 private void setUIState() {
   if (mSimpleFacebook.isLogin()) {
     loggedInUIState();
   } else {
     loggedOutUIState();
   }
 }
  @Override
  public void onCreate() {
    super.onCreate();

    File cacheDir = new File(Environment.getExternalStorageDirectory(), "Midipile/Cache");
    DisplayImageOptions defaultOptions =
        new DisplayImageOptions.Builder()
            .showImageOnLoading(android.R.color.white)
            .showImageForEmptyUri(android.R.color.white)
            .displayer(new FadeInBitmapDisplayer(500))
            .build();
    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(getApplicationContext())
            .diskCache(new UnlimitedDiscCache(cacheDir))
            .build();
    ImageLoader.getInstance().init(config);

    // set log to true
    Logger.DEBUG_WITH_STACKTRACE = true;
    // initialize facebook configuration
    Permission[] permissions = new Permission[] {Permission.PUBLIC_PROFILE, Permission.EMAIL};
    SimpleFacebookConfiguration configuration =
        new SimpleFacebookConfiguration.Builder()
            .setAppId(getString(R.string.app_id))
            .setNamespace("midipile")
            .setPermissions(permissions)
            .setDefaultAudience(SessionDefaultAudience.FRIENDS)
            .setAskForAllPermissionsAtOnce(true)
            .build();
    SimpleFacebook.setConfiguration(configuration);
  }
예제 #4
0
  @Override
  public void onCreate() {
    super.onCreate();
    MMX.init(this, R.raw.whisper);
    SimpleFacebookConfiguration configuration =
        new SimpleFacebookConfiguration.Builder()
            .setAppId(getString(R.string.app_id))
            .setNamespace(Constants.APP_NS)
            .setPermissions(Constants.permissions)
            .build();
    SimpleFacebook.setConfiguration(configuration);
    Instance = this;
    applicationHandler = new Handler(getInstance().getMainLooper());
    NativeLoader.initNativeLibs(App.getInstance());
    MMX.registerWakeupBroadcast(new Intent("MY_WAKEUP_ACTION"));
    MMX.registerListener(
        new MMX.EventListener() {
          @Override
          public boolean onMessageReceived(MMXMessage mmxMessage) {
            // sendNotification(mmxMessage);
            return true;
          }

          @Override
          public boolean onLoginRequired(MMX.LoginReason reason) {
            if (reason == MMX.LoginReason.SERVICE_UNAVAILABLE) attemptLogin();
            else if (reason == MMX.LoginReason.DISCONNECTED) attemptLogin();
            else if (reason == MMX.LoginReason.SERVICE_AVAILABLE) {;
            } else if (reason == MMX.LoginReason.CREDENTIALS_EXPIRED) goToLoginActivity();
            return true;
          }
        });
  }
예제 #5
0
  @Override
  public boolean onActivityResult(
      final Activity activity, int requestCode, int resultCode, Intent data) {
    simpleFacebook.onActivityResult(requestCode, resultCode, data);

    return resultCode == Activity.RESULT_OK;
  }
 @Override
 public void onResume() {
   super.onResume();
   mSimpleFacebook = SimpleFacebook.getInstance(getActivity());
   setUIState();
 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   SimpleFacebook.getInstance(this).onActivityResult(this, requestCode, resultCode, data);
 }