//Toggle alarm (on/off) public static void ToggleAlarm(int alarmID, bool alarmStatus, bool isListOn = false) { //- 알람이 켜져있는 상태에서 끌 경우, LocalNotification도 같이 종료 //- 알람이 꺼져있는 상태에서 킬 경우, 상황에 따라 (반복체크후) LocalNotification 추가 if (!isAlarmMergedFirst) { MergeAlarm(); } //merge first for (int i = 0; i < alarmsArray.Count; ++i) { if (alarmsArray[i].alarmID == alarmID) //target found { Log.Debug(UPLog.TAG, "Toggling. target:" + alarmID.ToString()); if (alarmsArray[i].alarmToggle == alarmStatus) { Log.Debug(UPLog.TAG, "status already same..!!"); break; //상태가 같으므로 변경할 필요 없음 } //Notifi 구현 필요 없음 if (alarmStatus == false) //알람 끄기 { alarmsArray[i].alarmToggle = false; //alarm toggle to off. } else { //알람 켜기 (addalarm 재탕) Calendar tmpC = Calendar.Instance; Calendar oldC = Calendar.Instance; oldC.TimeInMillis = alarmsArray[i].alarmFireDate; tmpC.Set(CalendarField.Hour, oldC.Get(CalendarField.Hour)); //move hour and min from old date tmpC.Set(CalendarField.Minute, oldC.Get(CalendarField.Minute)); tmpC.Set(CalendarField.Second, 0); //remove second alarmsArray[i].alarmFireDate = (int)tmpC.TimeInMillis; Log.Debug(UPLog.TAG, "Comp changed date to", alarmsArray[i].alarmFireDate.ToString()); AlarmElement alarmsArrTmpPointer = alarmsArray[i]; alarmsArray.RemoveAt(i); AddAlarm(alarmsArrTmpPointer.alarmFireDate, alarmsArrTmpPointer.alarmName, alarmsArrTmpPointer.gameSelected, alarmsArrTmpPointer.alarmSound, alarmsArrTmpPointer.alarmRepeat, i, alarmsArrTmpPointer.alarmID, !isListOn); //return; //한번더 저장해야됨. break; //save } //end status break; //해당 ID를 처리했으므로 다음부터의 루프는 무의미 } //end alarmid target search } //end for //save it Log.Debug(UPLog.TAG, "Status change saving"); //TODO: 시스템 저장 UPDataManager.SaveDataJObject(UPDataManager.KEY_ALARMS, JsonConvert.SerializeObject(alarmsArray, Formatting.Indented)); } //end func
//알람 게임 클리어 토글 public static void GameClearToggleAlarm(int alarmID, bool cleared) { AlarmElement modAlarmElement = GetAlarm(alarmID); modAlarmElement.alarmCleared = cleared; //save it //TODO 20160421 데이터 저장 UPDataManager.SaveDataJObject(UPDataManager.KEY_ALARMS, JsonConvert.SerializeObject(alarmsArray, Formatting.Indented)); Log.Debug(UPLog.TAG, "Alarm clear toggle to ... " + cleared.ToString() + " to id " + alarmID.ToString()); }
protected override Element CreateChildForParameter(Parameter parameter) { if (IsBip) { switch (parameter.Id) { case 1: Bluetooth = new BluetoothElement(parameter, this); return(Bluetooth); case 2: Alarm = new AlarmElement(parameter, this); return(Alarm); case 3: Unlocked = new UnlockedElement(parameter, this); return(Unlocked); case 4: DoNotDisturb = new DoNotDisturbElement(parameter, this); return(DoNotDisturb); } } else { switch (parameter.Id) { case 1: DoNotDisturb = new DoNotDisturbElement(parameter, this); return(DoNotDisturb); case 2: Unlocked = new UnlockedElement(parameter, this); return(Unlocked); case 3: Bluetooth = new BluetoothElement(parameter, this); return(Bluetooth); case 4: Battery = new BatteryElement(parameter, this); return(Battery); } } return(base.CreateChildForParameter(parameter)); }
public static void SaveAlarmListToFile() { _AlarmListUserData ud = new _AlarmListUserData(); ud.nid = Notifications.Id; if (ui_alarmlist.Count > 0) { ud.numAlarms = ui_alarmlist.Count; ud.id = new int[ud.numAlarms]; ud.profile_idx = new int[ud.numAlarms]; ud.hr_dp_val = new int[ud.numAlarms]; ud.min_dp_val = new int[ud.numAlarms]; ud.ampm_dp_val = new int[ud.numAlarms]; ud.repeat_dp_val = new int[ud.numAlarms]; ud.ringer_dp_val = new int[ud.numAlarms]; ud.label_if_val = new string[ud.numAlarms]; for (int i = 0; i < ui_alarmlist.Count; ++i) { AlarmElement ae_comp = ui_alarmlist[i].GetComponent <AlarmElement>(); ud.id[i] = ae_comp.Id; ud.profile_idx[i] = ae_comp.profile_idx; ud.hr_dp_val[i] = ae_comp.hr_dp_val; ud.min_dp_val[i] = ae_comp.min_dp_val; ud.ampm_dp_val[i] = ae_comp.ampm_dp_val; ud.repeat_dp_val[i] = ae_comp.repeat_dp_val; ud.ringer_dp_val[i] = ae_comp.ringer_dp_val; ud.label_if_val[i] = ae_comp.label_if_val; } } else { ud.numAlarms = 0; ud.id = new int[] { }; ud.profile_idx = new int[] { }; ud.hr_dp_val = new int[] { }; ud.min_dp_val = new int[] { }; ud.ampm_dp_val = new int[] { }; ud.repeat_dp_val = new int[] { }; ud.ringer_dp_val = new int[] { }; ud.label_if_val = new string[] { }; } SaveSystem.SaveAlarmListUserData(ud); }
//Add alarm to system public static void AddAlarm(int funcDate, string funcAlarmTitle, int gameID, string soundFile, bool[] repeatArr, int insertAt = -1, int alarmID = -1, bool isToggled = true, bool redrawList = true) { //repeatarr에 일,월,화,수,목,금,토 순으로 채움 Calendar date = Calendar.Instance; date.TimeInMillis = funcDate; string alarmTitle = funcAlarmTitle; int currentDayOfWeek = date.Get(CalendarField.DayOfWeek); if (alarmTitle == "") //알람 타이틀이 없으면 소리만 울리는 상황이 발생하므로 기본 이름 설정 { alarmTitle = "알람"; } int fireOnce = -1; /* 반복요일 설정이 없는경우 1회성으로 판단하고 date 변화 없음) */ bool fireSearched = false; for (int i = 0; i < repeatArr.Length; ++i) { if (repeatArr[i] == true) { fireOnce = i; break; } } if (fireOnce != -1) //여러번 울려야 하는 경우 오늘을 포함해서 다음 fireDate까지만 더함 { Log.Debug(UPLog.TAG, "TODAY OF WEEK =>" + currentDayOfWeek.ToString()); //일요일이 0부터 시작하는지 1부터 시작하는지 확인할 필요가 있음. 1부터 시작하면 DayOfWeek 확인을 6으로 해야함 for (int i = 0; i < (currentDayOfWeek == 7 ? 0 : currentDayOfWeek); ++i) { if (repeatArr[i] == true) { fireOnce = i; fireSearched = true; break; } } //없을경우 다음주로 넘어간것으로 치고 한번더 루프 if (!fireSearched) { for (int i = 0; i < repeatArr.Length; ++i) { if (repeatArr[i] == true) { fireOnce = i; fireSearched = true; break; } } } } Log.Debug(UPLog.TAG, "Next alarm date is " + fireOnce.ToString() + " (-1: no repeat, 0=sunday)"); int fireAfterDay = 0; if (fireOnce == -1 || (fireSearched && fireOnce == currentDayOfWeek - 1)) { //Firedate modifiy not needed but check time //시간이 과거면 알람 추가 안해야함 + 다음날로 넘겨야됨 if (funcDate <= (Calendar.Instance.TimeInMillis / 1000)) { //과거의 알람이기 때문에, 다음날로 넘겨야됨! if (fireOnce == -1) //반복 꺼짐인 경우 그냥 다음날로 넘김. { Log.Debug(UPLog.TAG, "Past alarm!! add 1 day"); date.Add(CalendarField.Date, 1); } else { //다음 반복일까지 대기후 추가 if (fireOnce - (currentDayOfWeek - 1) > 0) { fireAfterDay = fireOnce - (currentDayOfWeek - 1); Log.Debug(UPLog.TAG, "(past) Firedate is over today: " + fireAfterDay.ToString()); } else { fireAfterDay = (7 - (currentDayOfWeek - 1)) + fireOnce; Log.Debug(UPLog.TAG, "(past) Firedate is before today: " + fireAfterDay.ToString()); } date.Add(CalendarField.Date, fireAfterDay); Log.Debug(UPLog.TAG, "Firedate " + date.ToString()); } } else { Log.Debug(UPLog.TAG, "This is not past alarm."); } //end if } else { //Firedate modify. if (fireOnce - (currentDayOfWeek - 1) > 0) { fireAfterDay = fireOnce - (currentDayOfWeek - 1); Log.Debug(UPLog.TAG, "Firedate is over today: " + fireAfterDay.ToString()); } else { fireAfterDay = (7 - (currentDayOfWeek - 1)) + fireOnce; Log.Debug(UPLog.TAG, "Firedate is before today: " + fireAfterDay.ToString()); } //Add to date date.Add(CalendarField.Date, fireAfterDay); Log.Debug(UPLog.TAG, "Firedate " + date.ToString()); } int alarmUUID = alarmID == -1 ? (int)Calendar.Instance.TimeInMillis : alarmID; //// ~~ 원래 이 부분에 Notifi 등록 부분이 있었는데, //// 안드로이드는 서비스로 직접 알람이 울려야 하면 음악 재생 및 가능하면 액티비티를 띄우는 //// 작업을 할 거기 때문에 알람 데이터만 저장되면 됨. (즉 노티피 필요 X) //Remove seconds date.Set(CalendarField.Second, 0); //Add alarm to system (array) and save to nsdef AlarmElement tmpAlarmEle = new AlarmElement( alarmTitle, gameID, repeatArr, soundFile, (int)date.TimeInMillis /* 밀리세컨드 그대로 저장함 */, isToggled, alarmUUID ); if (insertAt == -1) { //add to arr and save alarmsArray.Add(tmpAlarmEle); } else { alarmsArray.Insert(insertAt, tmpAlarmEle); } //// TODO!!! 20160421 //// 안드로이드 데이터 저장 코드를 넣어야함 UPDataManager.SaveDataJObject(UPDataManager.KEY_ALARMS, JsonConvert.SerializeObject(alarmsArray, Formatting.Indented)); }
public void SetAlarm() { if (settingAlarm) { return; } settingAlarm = true; int jaarId = tijdInfo[4].value; int maandId = tijdInfo[3].value; int dagId = tijdInfo[2].value; int minuutId = tijdInfo[1].value; int urenId = tijdInfo[0].value; int jaar = int.Parse(tijdInfo[4].options[jaarId].text); int maand = int.Parse(tijdInfo[3].options[maandId].text); int dag = int.Parse(tijdInfo[2].options[dagId].text); int uren = int.Parse(tijdInfo[1].options[minuutId].text); int minuten = int.Parse(tijdInfo[0].options[urenId].text); if (jaar == null) { jaar = 0; } if (maand == null) { maand = 0; } if (dag == null) { dag = 0; } if (uren == null) { uren = 0; } if (minuten == null) { minuten = 0; } DateTime alarmTime = new DateTime(jaar, maand, dag, uren, minuten, 0); Alarm newAlarm = new Alarm(); switch (alarmOption.value) { case 0: newAlarm = new Alarm(alarmTime, KoffieAan); break; case 1: newAlarm = new Alarm(alarmTime, KoffieZetten); break; default: newAlarm = new Alarm(DateTime.Now, null); break; } if (!newAlarm.Equals(null)) { AlarmElement temp = new AlarmElement(newAlarm.AlarmTime().ToString(), newAlarm.actionToPerform.Method.Name); fullfile.alarms.Add(temp); alarmCount++; network.debugText.GetComponent <Text>().text = alarmCount + " alarm count"; dirty = true; } settingAlarm = false; }