Пример #1
0
  /**
   * 获取count条未读短消息(有bug,获取的都是已读的)
   *
   * @param count
   * @return
   */
  public JSArray getUnreadSms(int count) {
    boolean limit = count > 0; // count大于0,则加上limit
    JSArray smsArray = new JSArray();
    ContentResolver resolver = context.getContentResolver();
    // 查询短消息详细信息,按日期降序排列
    Cursor cursor =
        resolver.query(
            Telephony.Sms.Inbox.CONTENT_URI,
            null,
            Telephony.Sms.Inbox.READ + "=?",
            new String[] {"0"},
            Telephony.Sms.DEFAULT_SORT_ORDER + (limit ? " limit 0," + count : ""));
    int idIndex = cursor.getColumnIndexOrThrow(Telephony.Sms._ID);
    int addressIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS);
    int dateIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.DATE);
    int pidIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.PERSON_ID);
    int bodyIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.BODY);

    while (cursor.moveToNext()) {
      long id = cursor.getLong(idIndex);
      String address = cursor.getString(addressIndex);
      long pid = cursor.getLong(pidIndex);
      long date = cursor.getLong(dateIndex);
      String body = cursor.getString(bodyIndex);

      SmsInfo sms = new SmsInfo(body, date, address, id, pid);
      smsArray.add(sms);
    }
    return smsArray;
  }
Пример #2
0
  /**
   * 从uri中获取SmsInfo对象数组
   *
   * @param uri
   * @param count
   * @return
   */
  private JSArray getSmsInfoFromUri(Uri uri, int count) {
    boolean limit = count > 0; // count大于0,则加上limit
    JSArray smsArray = new JSArray();
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor =
        resolver.query(
            uri,
            null,
            null,
            null,
            Telephony.Sms.DEFAULT_SORT_ORDER + (limit ? " limit 0," + count : ""));

    int idIndex = cursor.getColumnIndexOrThrow(Telephony.Sms._ID);
    int addressIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS);
    int dateIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.DATE);
    int pidIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.PERSON_ID);
    int bodyIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.BODY);

    while (cursor.moveToNext()) {
      long id = cursor.getLong(idIndex);
      String address = cursor.getString(addressIndex);
      long pid = cursor.getLong(pidIndex);
      long date = cursor.getLong(dateIndex);
      String body = cursor.getString(bodyIndex);

      SmsInfo sms = new SmsInfo(body, date, address, id, pid);
      smsArray.add(sms);
    }
    return smsArray;
  }
Пример #3
0
  static void doJsonRpc(Machine mc, Context c, int m, Register[] registers, int r, int nbParams) {
    Task task = null;
    switch (m) {
      case 0: // call ( async, method, [params, ...], 'PARAMS_END')
        {
          Object[] params = JSArray.getParams(registers, r + 2, nbParams - 2);
          task = new JsonTask(registers[r + 1].getString(), params, params.length, 0);
          break;
        }
      case 1: // getResult (id)
        {
          int id = registers[r].getInt();
          if (s_tasks != null && id >= 0 && id < MAX_TASKS && s_tasks[id] != null) {
            JSArray.setParam(registers[r], s_tasks[id].getResult());
            s_tasks[id] = null;
            return;
          }
        }
      case 2: // cancel (id)
        {
          int id = registers[r].getInt();
          if (s_tasks != null && id >= 0 && id < MAX_TASKS && s_tasks[id] != null) {
            TaskQueue.getInstance().cancelTask(s_tasks[id]);
            s_tasks[id] = null;
          }
        }
      case 3: // addCallback (taskId, signal, cb, [data, ...],'PARAMS_END')
        {
          int id = registers[r].getInt();
          if (s_tasks != null && id >= 0 && id < MAX_TASKS && s_tasks[id] != null) {
            String signal = registers[r + 1].getString();
            int function = registers[r + 2].getInt();
            if (!mc.hasFunction(function)) {
              System.err.println("addCallback: Target method ref=" + function + " is undefined !");
              registers[r].setInt(-1);
              return;
            }
            if (registers[r + nbParams - 1].getString().equals("PARAMS_END")) nbParams--;
            nbParams -= 3;
            Register[] params =
                new Register
                    [nbParams + 2]; // +2 : first param is Id, last param is set by listenner
            params[0] = new Register();
            params[0].setInt(id); // First param : task id
            while (nbParams > 0) { // copy all data args
              params[nbParams] = new Register();
              params[nbParams].set(registers[r + 3 + nbParams - 1]);
              nbParams--;
            }
            s_tasks[id].addTaskListener(
                new TaskListenerCb(c.scene, c.script, function, params, signal));
            registers[r].setInt(1);
            return;
          }
        }
      case 4: // clean()
        clean();
        return;
      case 5: // ALL_STATES
        registers[r].setString("allStates");
        return;
      case 6: // ON_PROGRESS
        registers[r].setString("onProgress");
        return;
      case 7: // ON_START
        registers[r].setString("onStart");
        return;
      case 8: // ON_SUCCESS
        registers[r].setString("onSuccess");
        return;
      case 9: // ON_ERROR
        registers[r].setString("onError");
        return;
      default:
        System.err.println("dotransfer (m:" + m + "): Static call: Invalid method");
        return;
    }

    // register new task
    if (m < 3 && task != null) {

      if (registers[r].getBool()) {
        if (s_tasks == null) {
          s_tasks = new Task[MAX_TASKS];
        }
        for (int id = 0; id < MAX_TASKS; id++) {
          if (s_tasks[id] == null) {
            s_tasks[id] = task;
            TaskQueue.getInstance().addTask(task);
            registers[r].setInt(id);
            return;
          }
        }
      } else {
        JSArray.setParam(registers[r], TaskQueue.getInstance().runTaskNow(task));
        return;
      }
    }
    registers[r].setInt(-1);
  }