Esempio n. 1
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);
  }