예제 #1
0
  public static int saveAlarm(Context context, Alarm alarm) {
    List<Alarm> alarms;
    int lastId = 0;
    try {
      alarms = getAlarmList(context, FILENAME);
      StringBuilder sb = new StringBuilder();
      for (Alarm a : alarms) {
        if (alarm.getId() == a.getId()) a = alarm;
        sb.append(a.toString());
        lastId = a.getId();
      }

      if (alarm.getId() == 0) {
        lastId++;
        alarm.setId(lastId);
        sb.append(alarm.toString());
      }

      saveFile(context, FILENAME, sb.toString());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return lastId;
  }
예제 #2
0
  public static Alarm getAlarmById(Context context, int id) {

    try {
      List<Alarm> alarms = getAlarmList(context, FILENAME);
      for (Alarm a : alarms) {
        if (a.getId() == id) {
          return a;
        }
      }
    } catch (Exception e) {

      e.printStackTrace();
    } finally {
    }
    return null;
  }