Exemplo n.º 1
0
 /**
  * @Title: insertNewLog @Description: insert new log to database
  *
  * @param callLog MyCallLog instance
  * @param recordFlagState is record exists
  * @param recordState record storage state
  * @return boolean operation result
  * @throws
  */
 public boolean insertNewLog(
     MyCallLog callLog, RecordFlagState recordFlagState, RecordState recordState) {
   SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
   String sql =
       "INSERT INTO logs (name, number, duration, date, type, uid, record_flag, log_state_flag, record_state_flag) VALUES(?, ?, ?, ?, ?, ?, ?, 0, ?)";
   try {
     db.execSQL(
         sql,
         new Object[] {
           callLog.getName(),
           callLog.getNumber(),
           callLog.getDuration(),
           callLog.getDate(),
           callLog.getCallType().ordinal(),
           Check.getCRC32(callLog),
           recordFlagState.ordinal(),
           recordState.ordinal()
         });
   } catch (SQLException e) {
     e.printStackTrace();
     return false;
   } finally {
     if (db != null && db.isOpen()) {
       db.close();
     }
   }
   return true;
 }
Exemplo n.º 2
0
  /**
   * @Title: getIndividualLogs @Description: get individual logs by page
   *
   * @param page
   * @return ArrayList<Log>
   * @throws
   */
  public ArrayList<Log> getIndividualLogs(String number, int page) {
    SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
    String sql =
        "SELECT * FROM logs WHERE number like '%"
            + number
            + "%' AND record_state_flag = "
            + RecordState.LOCAL.ordinal()
            + " ORDER BY date DESC limit "
            + (page * 10)
            + ", 10";
    //		System.out.println(sql);
    Cursor cursor = null;

    ArrayList<Log> list = new ArrayList<Log>();
    try {
      cursor = db.rawQuery(sql, null);
      while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex("id"));
        String name = cursor.getString(cursor.getColumnIndex("name"));
        int duration = cursor.getInt(cursor.getColumnIndex("duration"));
        long date = Long.parseLong(cursor.getString(cursor.getColumnIndex("date")));
        CallType callType = CallType.fromInt(cursor.getInt(cursor.getColumnIndex("type")) - 1);
        String uid = cursor.getString(cursor.getColumnIndex("uid"));
        RecordFlagState recordFlag =
            RecordFlagState.fromInt(cursor.getInt(cursor.getColumnIndex("record_flag")));
        LogState logState = LogState.NOT_DELETED;
        RecordState recordState =
            RecordState.fromInt(cursor.getInt(cursor.getColumnIndex("record_state_flag")));
        Timestamp addDate =
            Timestamp.valueOf(cursor.getString(cursor.getColumnIndex("update_date")));

        list.add(
            new Log(
                id,
                name,
                number,
                duration,
                date,
                callType,
                uid,
                recordFlag,
                logState,
                recordState,
                addDate));
      }
      return list;
    } catch (SQLException e) {
      e.printStackTrace();
      return null;
    } finally {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      if (db != null && db.isOpen()) {
        db.close();
      }
    }
  }
Exemplo n.º 3
0
 /**
  * @Title: updateRecordState @Description: update record state
  *
  * @param uid the unique id of the record
  * @param state the state to set
  * @return boolean operation result
  * @throws
  */
 public boolean updateRecordState(String uid, RecordState state) {
   SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
   String sql =
       "UPDATE logs SET record_state_flag = " + state.ordinal() + " WHERE uid = \"" + uid + "\"";
   try {
     db.execSQL(sql);
   } catch (SQLException e) {
     e.printStackTrace();
     return false;
   } finally {
     if (db != null && db.isOpen()) {
       db.close();
     }
   }
   return true;
 }