Пример #1
0
  public void loadAlbumPhotoInfo() {
    if (facebookA != null) {
      facebookA.batch_run_getFacebookAlbumAndPhotoAsync(
          perm.getLogerInUserID(),
          new FacebookAdapter() {
            @Override
            public void getFacebookAlbumAndPhoto(HashMap<Integer, Object> albumAndPhotos) {
              Log.d("ALBUM PHOTO", " get Album and Photo information successfylly ");
              if (albumAndPhotos.size() > 2) {
                List<PhotoAlbum> albums = (List<PhotoAlbum>) albumAndPhotos.get(0);
                List<Photo> photos = (List<Photo>) albumAndPhotos.get(1);
                List<StreamFilter> filters = (List<StreamFilter>) albumAndPhotos.get(2);

                orm.addAlbum(albums);
                orm.addPhoto(photos, true);
                orm.addStreamFilter(filters);
              }
            }

            @Override
            public void onException(FacebookException e, int method) {
              Log.d(TAG, "fail to get album and photo information exception " + e.getMessage());
            }
          });
    }
  }
Пример #2
0
  private void getFacebookFriends(Message callback) {
    SocialORM.Account account = orm.getFacebookAccount();
    if (mContext.checkFacebookAccount(mContext, account)) {
      // perm = null;
      if (perm == null) {
        perm = loginHelper.getPermanentSesstion();
      }
      if (perm != null) {
        if (facebookA == null) {
          facebookA = new AsyncFacebook(perm);
        }
        facebookA.setSession(perm);
        final Message callMsg = callback;
        long hisuid = -1;
        if (callMsg != null) {
          hisuid = callMsg.getData().getLong("hisuid", -1);
        }
        if (hisuid == -1) {
          hisuid = perm.getLogerInUserID();
        } else {
          Log.d(TAG, "begin to get who's friends list=" + hisuid);
        }

        facebookA.getMyFriendsAsync(
            hisuid,
            limit,
            offset,
            userHander,
            new FacebookAdapter() {
              @Override
              public void getMyFriends(int size) {
                Log.d(TAG, "friend size=" + size);
                orm.checkNoneFriends();
                Message msd = handler.obtainMessage(FACEBOOK_FRIENDS_GET_END);
                msd.getData().putBoolean("RESULT", true);
                msd.getData().putInt("size", size);
                msd.getData().putParcelable(CALLBACK, callMsg);
                handler.sendMessage(msd);
              }

              @Override
              public void onException(FacebookException e, int method) {
                Log.d(TAG, "fail to get basic friends information");
                Message msd = handler.obtainMessage(FACEBOOK_FRIENDS_GET_END);
                msd.getData().putBoolean("RESULT", false);
                msd.getData().putParcelable(CALLBACK, callMsg);
                handler.sendMessage(msd);
              }
            });
      } else {
        mContext.needLogin();
      }
    }
  }
Пример #3
0
 void recordPermSession(FacebookSession tmps, SocialORM orm) {
   loghelper.recordPermanantSession(
       tmps.getSessionKey(), tmps.getSecretKey(), tmps.getLogerInUserID());
   // clear user data
   Log.d(TAG, "clear the pre-user data, this will need some time");
   // if the account is not changes, still have no necessary to clear the data
   String pre_account = orm.getSettingValue(SocialORM.pre_account);
   SocialORM.Account ac = orm.getFacebookAccount();
   if (pre_account == null || pre_account.equalsIgnoreCase(ac.email)) {
     Log.d(TAG, "we are the same account=" + pre_account);
     // if it is the same account, no need to remove the cache data,
     // if the user want to clear the history data,
     // she/he can use the "advanced setting" to reset the database
   } else {
     Log.d(TAG, "we are different account=" + pre_account);
     orm.clearCurrentUserData();
     TwitterHelper.ClearCache();
   }
   // update pre account
   orm.addSetting(SocialORM.pre_account, ac.email);
 }
Пример #4
0
    public void run() {
      handler.post(
          new Runnable() {
            public void run() {
              FacebookLoginActivity.this.setTitle(R.string.facebook_getsession_title);
              facebook_info.setText(R.string.facebook_getsession_wait_message);
            }
          });

      Log.d(TAG, "reconstrcut the facebook session");
      FacebookSession tmps = null;
      try {
        tmps = loghelper.getDesktopApp().requestSession(token);

        handler.post(
            new Runnable() {
              public void run() {
                facebook_info.setText(R.string.facebook_getsession_successed);
              }
            });
      } catch (FacebookException e) {
        Log.e(TAG, "fail to get facebook session=" + e.getMessage());
        handler.post(
            new Runnable() {
              public void run() {
                facebook_info.setText(R.string.facebook_fail_to_get_session);
                FacebookLoginActivity.this.setResult(200);
                sendMessageToService(false);
                quitLooperAndFinish();
              }
            });
        return;
      }
      // save into database
      String Sessionkey = tmps.getSessionKey();
      String secretKey = tmps.getSecretKey();
      long userId = tmps.getLogerInUserID();
      loghelper.recordTmpSession(Sessionkey, secretKey, userId);
      SocialORM orm = new SocialORM(FacebookLoginActivity.this);

      boolean persm = false;
      try {
        handler.post(
            new Runnable() {
              public void run() {
                facebook_info.setText(R.string.facebook_make_session_permanent);
              }
            });
        persm =
            tmps.AuthLogin(
                tmps.getSessionKey(),
                FacebookLoginHelper.SECRET_KEY,
                loghelper.getEmail(),
                loghelper.getPwd());

        handler.post(
            new Runnable() {
              public void run() {
                facebook_info.setText(R.string.facebook_make_session_permanent_suc);
              }
            });
      } catch (FacebookException kke) {
        Log.d(TAG, "fail to get perm session=" + kke.getMessage());
      }

      if (true == persm) {
        recordPermSession(tmps, orm);
      } else {
        Log.d(TAG, "fail to get permnant session");
        if (orm.isUsePermanentSeesion() == false) {
          Log.d(TAG, "fail to get permnant session, use tmp session");
          recordPermSession(tmps, orm);
        } else {
          handler.post(
              new Runnable() {
                public void run() {
                  Toast.makeText(
                          FacebookLoginActivity.this,
                          R.string.facebook_get_permanent_session_failed,
                          Toast.LENGTH_LONG)
                      .show();
                }
              });
        }
      }

      // reset the session and async in activity
      AccountManager.login();

      handler.post(
          new Runnable() {
            public void run() {
              FacebookLoginActivity.this.setResult(100);
              sendMessageToService(true);
            }
          });

      handler.post(
          new Runnable() {
            public void run() {
              quitLooperAndFinish();
            }
          });
    }
Пример #5
0
  void auth_login() {
    isInProcess = true;
    setButtonEnable(false);
    Log.d(TAG, "reconstrcut the facebook session");
    final FacebookSession tmps;
    boolean persm = false;
    try {
      setHint(getString(R.string.verify_account_hint));
      tmps = loghelper.getDesktopApp().AuthLoginNoSession(loghelper.getEmail(), loghelper.getPwd());
    } catch (FacebookException e) {
      Log.e(TAG, "fail to get facebook session=" + e.getMessage());
      handler.post(
          new Runnable() {
            public void run() {
              facebook_info.setText(R.string.facebook_fail_to_get_session);
              // FacebookLoginActivity.this.setResult(200);
              // sendMessageToService(false);
              // quitLooperAndFinish();
            }
          });
      mHandler.obtainMessage(QUIT_THREAD).sendToTarget();
      isInProcess = false;
      setButtonEnable(true);
      return;
    }
    try {
      persm =
          tmps.AuthLogin(
              tmps.getSessionKey(),
              FacebookLoginHelper.SECRET_KEY,
              loghelper.getEmail(),
              loghelper.getPwd());
    } catch (FacebookException e) {
      Log.e(TAG, "Fail to get permanant session, ignore this step.");
    }
    setHint(getString(R.string.verify_account_suc_hint));

    // get login info in background

    // save into database
    String Sessionkey = tmps.getSessionKey();
    String secretKey = tmps.getSecretKey();
    long userId = tmps.getLogerInUserID();
    loghelper.recordTmpSession(Sessionkey, secretKey, userId);
    SocialORM orm = SocialORM.instance(FacebookLoginActivity.this);

    if (true == persm) {
      recordPermSession(tmps, orm);
    } else {
      Log.d(TAG, "fail to get permnant session");
      if (orm.isUsePermanentSeesion() == false) {
        Log.d(TAG, "fail to get permnant session, use tmp session");
        recordPermSession(tmps, orm);
      } else {
        handler.post(
            new Runnable() {
              public void run() {
                Toast.makeText(
                        FacebookLoginActivity.this,
                        R.string.facebook_get_permanent_session_failed,
                        Toast.LENGTH_LONG)
                    .show();
              }
            });
      }
    }

    // reset the session and async in activity
    AccountManager.login();

    handler.post(
        new Runnable() {
          public void run() {
            FacebookLoginActivity.this.setResult(100);
            sendMessageToService(true);
          }
        });

    handler.post(
        new Runnable() {
          public void run() {
            quitLooperAndFinish();
          }
        });

    isInProcess = false;
    setButtonEnable(true);
  }