Esempio n. 1
0
        // 添加联系人
        @Override
        public String AddContacts(String uId) throws RemoteException {
          // TODO Auto-generated method stub
          String u_id = "";
          try {
            u_id = java.net.URLEncoder.encode(uId, "utf-8");
          } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          // 根据用户ID下载该用户的用户信息
          Contact contact =
              mTool.GetContact(mTool.URL_CONTACT + mTool.APPKEY + "&screen_name=" + u_id);
          // Contact contact = mTool.GetContact(mTool.URL_CONTACT + uId + mTool.APPKEY);
          // 如果下载的用户信息为空返回False
          if (contact == null) {
            return "";
          }
          /*储存数据以便插入数据库*/
          ContentValues values = new ContentValues();

          if (contact.getU_id() == null) {
            values.put("u_id", "");
          } else {
            values.put("u_id", contact.getU_id());
          }
          if (contact.getU_name() == null) {
            values.put("u_name", "");
          } else {
            values.put("u_name", contact.getU_name());
          }
          values.put("province", contact.getProvince());
          values.put("city", contact.getCity());
          if (contact.getLocation() == null) {
            values.put("location", "");
          } else {
            values.put("location", contact.getLocation());
          }
          if (contact.getDescription() == null) {
            values.put("description", "");
          } else {
            values.put("description", contact.getDescription());
          }
          if (contact.getUrl() == null) {
            values.put("url", "");
          } else {
            values.put("url", contact.getUrl());
          }
          if (contact.getProfile_image_url() == null) {
            values.put("profile_image_url", "");
          } else {
            values.put("profile_image_url", contact.getProfile_image_url());
          }
          if (contact.getDomain() == null) {
            values.put("domain", "");
          } else {
            values.put("domain", contact.getDomain());
          }
          if (contact.getGender() == null) {
            values.put("gender", "");
          } else {
            values.put("gender", contact.getGender());
          }
          values.put("followers_count", contact.getFollowers_count());
          values.put("friends_count", contact.getFriends_count());
          values.put("statuses_count", contact.getStatuses_count());
          values.put("favourites_count", contact.getFavourites_count());
          if (contact.getCreated_at() == null) {
            values.put("created_at", "");
          } else {
            values.put("created_at", contact.getCreated_at());
          }
          if (contact.getVerified() == null) {
            values.put("verified", "");
          } else {
            values.put("verified", contact.getVerified());
          }

          // 插入数据库
          long iNum = mBlogDatabase.insert("contact", null, values);
          if (iNum == -1) {
            return "";
          }
          return contact.getU_id();
        }
Esempio n. 2
0
  /** 更新新浪微博 */
  private void UpdateMicroblogInfo() {
    updateId.clear();
    List<String> u_ids = new ArrayList<String>();

    List<String> s_ids = new ArrayList<String>();

    if (blDSCode) {
      Cursor cur1 = mBlogDatabase.rawQuery("select u_id from contact", null);
      // 判断表中是否有记录
      if (cur1.getCount() > 0) {
        // 将游标移到开头
        cur1.moveToFirst();
        // 循环获取表中的数据
        do {
          u_ids.add(cur1.getString(cur1.getColumnIndex("u_id")));
        } while (cur1.moveToNext()); // 将游标下移一位
      }

      cur1.close();

      Cursor cur2 = mBlogDatabase.rawQuery("select s_id from news", null);
      // 判断表中是否有记录
      if (cur2.getCount() > 0) {
        // 将游标移到开头
        cur2.moveToFirst();
        // 循环获取表中的数据
        do {
          s_ids.add(cur2.getString(cur2.getColumnIndex("s_id")));
        } while (cur2.moveToNext()); // 将游标下移一位
      }

      cur2.close();

      int u_id_num = u_ids.size();
      boolean blTrue = true;
      for (int i = 0; i < u_id_num; i++) {
        List<News> news = mTool.GetNews(mTool.URL_NEWS + mTool.APPKEY + "&user_id=" + u_ids.get(i));
        int newsNum = news.size();
        for (int j = 0; j < newsNum; j++) {
          int sidNum = s_ids.size();
          for (int j2 = 0; j2 < sidNum; j2++) {
            if (news.get(j).getS_id().equals(s_ids.get(j2))) {
              blTrue = false;
              break;
            }
          }
          if (blTrue) {
            boolean blUpdate = true;
            for (int k = 0; k < u_ids.size(); k++) {
              if (updateId.size() == 0) {
                break;
              } else if (updateId.get(k).equals(u_ids.get(i))) {
                blUpdate = false;
                break;
              }
            }
            if (blUpdate) {
              updateId.add(u_ids.get(i));
            } else {
              blUpdate = true;
            }
            ContentValues values = new ContentValues();
            values.put("u_id", news.get(j).getU_id());
            values.put("u_name", news.get(j).getU_name());
            values.put("s_id", news.get(j).getS_id());
            values.put("text", news.get(j).getText());
            values.put("source", news.get(j).getSource());
            values.put("thumbnail_pic", news.get(j).getThumbnail_pic());
            values.put("bmiddle_pic", news.get(j).getBmiddle_pic());
            values.put("original_pic", news.get(j).getOriginal_pic());
            values.put("retweeted_status", news.get(j).getRetweeted_status());
            values.put("created_at", news.get(j).getCreated_at());
            values.put("is_read", 0);
            mBlogDatabase.insert("news", null, values);
          } else {
            blTrue = true;
          }
        }
      }
    } else {
      Log.v("DataBase", "SDCode not loaded!");
    }
  }