Esempio n. 1
0
        private Native.AlarmWeekFlag Convert(AlarmWeekFlag flag)
        {
            Native.AlarmWeekFlag nativeWeekFlag = 0;

            if (flag == AlarmWeekFlag.AllDays)
            {
                nativeWeekFlag = Native.AlarmWeekFlag.AllDays;
            }
            else if (flag == AlarmWeekFlag.WeekDays)
            {
                nativeWeekFlag = Native.AlarmWeekFlag.WeekDays;
            }
            else
            {
                for (int i = 1; i < 7; i++)
                {
                    int mask = 1 << i;
                    if (((int)flag & mask) > 0)
                    {
                        switch (mask)
                        {
                        case (int)AlarmWeekFlag.Monday:
                            nativeWeekFlag |= Native.AlarmWeekFlag.Monday;
                            break;

                        case (int)AlarmWeekFlag.Tuesday:
                            nativeWeekFlag |= Native.AlarmWeekFlag.Tuesday;
                            break;

                        case (int)AlarmWeekFlag.Wednesday:
                            nativeWeekFlag |= Native.AlarmWeekFlag.Wednesday;
                            break;

                        case (int)AlarmWeekFlag.Thursday:
                            nativeWeekFlag |= Native.AlarmWeekFlag.Thursday;
                            break;

                        case (int)AlarmWeekFlag.Friday:
                            nativeWeekFlag |= Native.AlarmWeekFlag.Friday;
                            break;

                        case (int)AlarmWeekFlag.Saturday:
                            nativeWeekFlag |= Native.AlarmWeekFlag.Saturday;
                            break;
                        }
                    }
                }

                if (((int)flag & 0x1) > 0)
                {
                    nativeWeekFlag |= Native.AlarmWeekFlag.Sunday;
                }
            }

            return(nativeWeekFlag);
        }
 internal static int?SaveAlarm(AlarmRecord alarmRecord)
 {
     Native.AppControl appControl = new Native.AppControl()
     {
         ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId
     };
     appControl.ExtraData.Add("AlarmRecord.DateCreated", alarmRecord.DateCreated.ToString());
     Native.AlarmWeekFlag nativeFlag  = Convert(alarmRecord.WeekFlag);
     Native.Alarm         nativeAlarm = Native.AlarmManager.CreateAlarm(alarmRecord.ScheduledDateTime, nativeFlag, appControl);
     return(nativeAlarm.AlarmId);
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a system alarm of AlarmRecord
        /// </summary>
        /// <param name="binableAlarmRecord">AlarmRecord object to create a system alarm based on</param>
        /// <seealso cref="AlarmRecord">
        /// <returns> Returns native alarm object </returns>
        public int CreateAlarm(AlarmRecord record)
        {
            Native.AppControl appControl = new Native.AppControl()
            {
                ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId
            };
            appControl.ExtraData.Add("AlarmRecord.UniqueIdentifier", record.GetUniqueIdentifier());
            appControl.ExtraData.Add("RingType", RingType.RING_TYPE_ALARM.ToString());
            Native.AlarmWeekFlag nativeFlag  = Convert(record.WeekFlag);
            Native.Alarm         nativeAlarm = Native.AlarmManager.CreateAlarm(record.ScheduledDateTime, nativeFlag, appControl);
#if ALARM_DEBUG
            System.Diagnostics.Debug.WriteLine("@@ [Alarm.CreateAlarm] UID : " + record.GetUniqueIdentifier()
                                               + ", ScheduledDateTime : " + record.ScheduledDateTime + " nativeFlag : " + nativeFlag);
            System.Diagnostics.Debug.WriteLine(" --> Done       Native UID : " + nativeAlarm.AlarmId
                                               + ", ScheduledDate : " + nativeAlarm.ScheduledDate + " nativeFlag : " + nativeAlarm.WeekFlag);
#endif
            return(nativeAlarm.AlarmId);
        }
        private static Native.AlarmWeekFlag Convert(AlarmWeekFlag flag)
        {
            Native.AlarmWeekFlag ret = Native.AlarmWeekFlag.AllDays;
            switch (flag)
            {
            case AlarmWeekFlag.Monday:
                ret = Native.AlarmWeekFlag.Monday;
                break;

            case AlarmWeekFlag.Tuesday:
                ret = Native.AlarmWeekFlag.Tuesday;
                break;

            case AlarmWeekFlag.Wednesday:
                ret = Native.AlarmWeekFlag.Wednesday;
                break;

            case AlarmWeekFlag.Thursday:
                ret = Native.AlarmWeekFlag.Thursday;
                break;

            case AlarmWeekFlag.Friday:
                ret = Native.AlarmWeekFlag.Friday;
                break;

            case AlarmWeekFlag.WeekDays:
                ret = Native.AlarmWeekFlag.WeekDays;
                break;

            case AlarmWeekFlag.AllDays:
                ret = Native.AlarmWeekFlag.AllDays;
                break;

            default:
                break;
            }

            return(ret);
        }