Esempio n. 1
0
 /*
 static public WeiboFunction getInstance(){
     if(weiboFunction==null){
         weiboFunction = new WeiboFunction();
     }
     return weiboFunction;
 }
 */
 public static boolean isBound() {
   if (!Util.isEmpty(Login.sinaWeiboToken) && !Util.isEmpty(Login.sinaExpiresIN)) {
     access_token = Login.sinaWeiboToken;
     expires_in = Login.sinaExpiresIN;
     accessToken = new Oauth2AccessToken(access_token, expires_in);
     if (!accessToken.isSessionValid()) {
       accessToken = null;
     }
   }
   return accessToken != null;
 }
Esempio n. 2
0
  public static void authorize(Context context) {
    if (accessToken != null) return;
    if (!Util.isEmpty(Login.sinaWeiboToken) && !Util.isEmpty(Login.sinaExpiresIN)) {
      access_token = Login.sinaWeiboToken;
      expires_in = Login.sinaExpiresIN;
      accessToken = new Oauth2AccessToken(access_token, expires_in);
      if (!accessToken.isSessionValid()) {
        accessToken = null;
      }
    }

    WeiboParameters parameters = new WeiboParameters();
    parameters.add("forcelogin", "true");
    com.weibo.sdk.android.util.Utility.isWifi(context);
    weibo.startDialog(
        context,
        parameters,
        new WeiboAuthListener() {

          // weibo.authorize(context, new WeiboAuthListener() {
          @Override
          public void onComplete(Bundle bundle) {
            access_token = bundle.getString("access_token");
            expires_in = bundle.getString("expires_in");
            accessToken = new Oauth2AccessToken(access_token, expires_in);
            try {
              SendToken();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }

          @Override
          public void onWeiboException(WeiboException e) {
            clearToken();
          }

          @Override
          public void onError(WeiboDialogError weiboDialogError) {
            clearToken();
          }

          @Override
          public void onCancel() {
            clearToken();
          }
        });
  }
Esempio n. 3
0
  public static int addPlan(Plan plan)
      throws SQLException, TextFormatException, JSONException, NoSuchAlgorithmException,
          UnsupportedEncodingException {

    if (plan == null) {
      logger.error("Can't add empty plan");
      return -1;
    }

    String SQLCommand = null;
    DBUtil du = DBUtil.getDBUtil();
    ResultSet rs;

    String title = plan.getTitle();
    String siteIDs = plan.getSiteIDs();
    int organizer = plan.getOrganizer();
    Date startTime = plan.getStartTime();
    Date endTime = plan.getEndTime();
    String describe = plan.getDescribe();
    if (Util.isEmpty(siteIDs)
        || organizer < 0
        || startTime == null
        || endTime == null
        || startTime.after(endTime)) {
      logger.error("illegal plan");
      return -1;
    }
    SQLCommand =
        " insert into "
            + tableName
            + " ( title, siteIDs, startTime, endTime, organizer, participants, budget, groupNum, groupNumMax, isDone, information ) "
            + " values ( '"
            + title
            + "' , '"
            + siteIDs
            + "' , '"
            + startTime
            + "' , '"
            + endTime
            + "' , "
            + organizer
            + " , '"
            + plan.getParticipants()
            + "' , "
            + plan.getBudget()
            + " , "
            + plan.getGroupNum()
            + " , "
            + plan.getGroupNumMax()
            + " , false , '"
            + describe
            + "')";
    System.out.println(SQLCommand);
    rs = du.executeUpdate(SQLCommand);
    rs.next();
    int planID = rs.getInt(1);
    // Plan new_plan = new Plan(planID, title, siteIDs, startTime, endTime, organizer,
    // plan.getParticipants(), plan.getBudget(), plan.getGroupNum(), plan.getGroupNumMax(),
    // plan.getTalkStreamID(), false);
    /*
    User user = new User();
    String orig_plans =new UserManager().selectUser(organizer).getPlans();
    user.setPlans(new JSONHelper().addToArray(orig_plans, planID));
    new UserManager().editUser(organizer, user);

    Vector<Integer> siteIDVector =new JSONHelper().convertToArray(siteIDs);
    for(int j=0;j<siteIDVector.size();j++){
        int siteID = siteIDVector.get(j);
        SQLCommand = " insert into " + relationTableName +"( userID, siteID, startTime, endTime, planID )" +
                    " values ( " + organizer + " , " + siteID + " , '" + startTime + "' , '" + endTime + "' , " + planID + ")";
        du.executeUpdate(SQLCommand);
    }
    */
    return planID;
  }
Esempio n. 4
0
  public static void editPlan(int planID, Plan new_plan)
      throws TextFormatException, SQLException, JSONException {
    DBUtil du = DBUtil.getDBUtil();
    String SQLCommand = null, subSQLcommand = null;
    boolean isComma = false;
    if (planID < 0) throw new TextFormatException("planID is null");
    SQLCommand = " update " + tableName + " set ";

    String siteIDs = new_plan.getSiteIDs();
    String title = new_plan.getTitle();
    Date startTime = new_plan.getStartTime();
    Date endTime = new_plan.getEndTime();
    int organizer = new_plan.getOrganizer();
    String participants = new_plan.getParticipants();
    int budget = new_plan.getBudget();
    int groupNum = new_plan.getGroupNum();
    int groupNumMax = new_plan.getGroupNumMax();
    int talkStreamID = new_plan.getTalkStreamID();
    boolean isDone = new_plan.getIsDone();

    Plan orig_plan = selectPlan(planID);
    if (orig_plan.getIsDone() == true) {
      throw new TextFormatException("Cannot modify isdone plan");
    }

    String orig_siteIDs = orig_plan.getSiteIDs();
    int orig_organizer = orig_plan.getOrganizer();
    String orig_participants = orig_plan.getParticipants();

    Vector<Integer> orig_siteIDVector = null;
    Vector<Integer> orig_userIDVector = null;
    Vector<Integer> new_siteIDVector = null;
    Vector<Integer> new_userIDVector = null;

    if (orig_siteIDs != null) orig_siteIDVector = new JSONHelper().convertToArray(orig_siteIDs);
    if (orig_participants != null)
      orig_userIDVector = new JSONHelper().convertToArray(orig_participants);

    if (budget >= 0) {
      SQLCommand += " budget = '" + budget + "'";
      isComma = true;
    }
    if (groupNum >= 0) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " groupNum = '" + groupNum + "'";
      isComma = true;
    }
    if (groupNumMax >= 0) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " groupNumMax = '" + groupNumMax + "'";
      isComma = true;
    }
    if (talkStreamID >= 0) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " talkStreamID = '" + talkStreamID + "'";
      isComma = true;
    }
    // if (title != null){
    if (!Util.isEmpty(title)) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += "title = '" + title + "'";
      isComma = true;
    }
    if (isDone) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += "isDone = true";
    }
    // if(siteIDs != null){
    if (!Util.isEmpty(siteIDs)) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " siteIDs = '" + siteIDs + "'";
      isComma = true;
      new_siteIDVector = new JSONHelper().convertToArray(siteIDs);
      for (int i = 0; i < new_siteIDVector.size(); i++) {
        if (!orig_siteIDVector.contains(new_siteIDVector.get(i))) {
          for (int j = 0; j < orig_userIDVector.size(); j++) {
            subSQLcommand =
                " insert into "
                    + relationTableName
                    + "(userID, siteID, startTime, endTime, planID) values "
                    + orig_userIDVector.get(j)
                    + " , "
                    + new_siteIDVector.get(i)
                    + " , '"
                    + orig_plan.getStartTime()
                    + "' , '"
                    + orig_plan.getEndTime()
                    + "' , "
                    + planID
                    + ")";
            du.executeUpdate(subSQLcommand);
          }
        }
      }
      for (int i = 0; i < orig_siteIDVector.size(); i++) {
        if (!new_siteIDVector.contains(orig_siteIDVector.get(i))) {
          subSQLcommand =
              "delete from "
                  + relationTableName
                  + " where planID = "
                  + planID
                  + " and siteID = "
                  + orig_siteIDVector.get(i);
          du.executeUpdate(subSQLcommand);
        }
      }
      orig_siteIDVector = new_siteIDVector;
    }

    // if(participants != null){
    if (!Util.isEmpty(participants)) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " participants = '" + participants + "'";
      isComma = true;
      new_userIDVector = new JSONHelper().convertToArray(participants);

      for (int i = 0; i < new_userIDVector.size(); i++) {
        if (!orig_userIDVector.contains(new_userIDVector.get(i))) {
          for (int j = 0; j < orig_siteIDVector.size(); j++) {
            subSQLcommand =
                " insert into "
                    + relationTableName
                    + "(userID, siteID, startTime, endTime, planID) values "
                    + new_userIDVector.get(i)
                    + " , "
                    + orig_siteIDVector.get(j)
                    + " , '"
                    + orig_plan.getStartTime()
                    + "' , '"
                    + orig_plan.getEndTime()
                    + "' , "
                    + planID
                    + ")";
            du.executeUpdate(subSQLcommand);
          }
        }
      }
      for (int i = 0; i < orig_userIDVector.size(); i++) {
        if (!new_userIDVector.contains(orig_userIDVector.get(i))) {
          subSQLcommand =
              "delete from "
                  + relationTableName
                  + " where planID = "
                  + planID
                  + " and userID = "
                  + orig_userIDVector.get(i);
          du.executeUpdate(subSQLcommand);
        }
      }
      orig_userIDVector = new_userIDVector;
    }
    if (organizer >= 0) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " organizer = '" + organizer + "'";
      isComma = true;
      subSQLcommand =
          "update "
              + relationTableName
              + " set userID = "
              + organizer
              + " where planID = "
              + planID
              + " and userID = "
              + orig_organizer;
      du.executeUpdate(subSQLcommand);
    }
    if (startTime != null) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " startTime = '" + startTime + "'";
      isComma = true;
      subSQLcommand =
          "update "
              + relationTableName
              + " set startTime = '"
              + startTime
              + "' where planID = "
              + planID;
      du.executeUpdate(subSQLcommand);
    }
    if (endTime != null) {
      if (isComma) SQLCommand += " , ";
      SQLCommand += " endTime = '" + endTime + "'";
      isComma = true;
      subSQLcommand =
          "update "
              + relationTableName
              + " set endTime = '"
              + endTime
              + "' where planID = "
              + planID;
      du.executeUpdate(subSQLcommand);
    }
    SQLCommand += " where planID = " + planID;
    du.executeUpdate(SQLCommand);
  }