Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.configuration);

            locationManager = (LocationManager)GetSystemService(LocationService);
            bool enabled_GPS = false;

            enabled_GPS = locationManager.IsProviderEnabled(LocationManager.GpsProvider);
            if (enabled_GPS)
            {
                provider = LocationManager.GpsProvider;
            }
            else
            {
                provider = LocationManager.NetworkProvider;
            }

            Location location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);

            if (location != null)
            {
                currentLatitude  = location.Latitude;
                currentLatitude  = System.Math.Round(currentLatitude * 100000.00) / 100000.00;
                currentLongitude = location.Longitude;
                currentLongitude = System.Math.Round(currentLongitude * 100000.00) / 100000.00;
            }
            else
            {
                currentLatitude  = 44.98;
                currentLongitude = -93.24;
            }

            Log.Warn(MainActivity.TAG, "enabled_GPS == true? " + (enabled_GPS == true).ToString());
            Log.Warn(MainActivity.TAG, "location != null? " + (location != null).ToString());
            Log.Warn(MainActivity.TAG, "currentLatitude: " + currentLatitude.ToString());
            Log.Warn(MainActivity.TAG, "currentLongitude: " + currentLongitude.ToString());

            current_cal = Calendar.Instance;
            TimeZone tz   = current_cal.TimeZone;
            Date     date = current_cal.Time;

            offsetFromUtc = (tz.GetOffset(date.Time)) / 3600000.0;

            datepicker = FindViewById <DatePicker>(Resource.Id.datePicker_1);
            datepicker.Init(current_cal.Get(CalendarField.Year), current_cal.Get(CalendarField.Month),
                            current_cal.Get(CalendarField.DayOfMonth), null);

            ISharedPreferences settings = GetSharedPreferences(PREFS_NAME, 0);

            message_lat = settings.GetString("myLatitude", currentLatitude.ToString());
            message_lon = settings.GetString("myLongitude", currentLongitude.ToString());
            message_off = settings.GetString("myOffset", offsetFromUtc.ToString());
            userYear    = settings.GetInt("myYear", userYear);
            userMonth   = settings.GetInt("myMonth", userMonth);
            userDay     = settings.GetInt("myDay", userDay);
            Init();
        }
Пример #2
0
        protected override void OnResume()
        {
            base.OnResume();
            locationManager = (LocationManager)GetSystemService(Context.LocationService);
            bool enabled_GPS = locationManager.IsProviderEnabled(LocationManager.GpsProvider);

            if (enabled_GPS)
            {
                provider = LocationManager.GpsProvider;
            }
            else
            {
                provider = LocationManager.NetworkProvider;
            }

            Location location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);

            if (location != null)
            {
                currentLatitude  = location.Latitude;
                currentLatitude  = System.Math.Round(currentLatitude * 100000.00) / 100000.00;
                currentLongitude = location.Longitude;
                currentLongitude = System.Math.Round(currentLongitude * 100000.00) / 100000.00;
            }
            else
            {
                currentLatitude  = 44.98;
                currentLongitude = -93.24;
            }

            current_cal = Calendar.Instance;
            TimeZone tz   = current_cal.TimeZone;
            Date     date = current_cal.Time;

            offsetFromUtc = (tz.GetOffset(date.Time)) / 3600000.0;

            datepicker = FindViewById <DatePicker>(Resource.Id.datePicker_1);

            /*
             * datepicker.Init(current_cal.Get(CalendarField.Year), current_cal.Get(CalendarField.Month),
             *              current_cal.Get(CalendarField.DayOfMonth), null);
             */

            datepicker.Init(userYear, userMonth, userDay, null);

            ISharedPreferences settings = GetSharedPreferences(PREFS_NAME, 0);

            message_lat = settings.GetString("myLatitude", currentLatitude.ToString());
            message_lon = settings.GetString("myLongitude", currentLongitude.ToString());
            message_off = settings.GetString("myOffset", offsetFromUtc.ToString());
            userYear    = settings.GetInt("myYear", userYear);
            userMonth   = settings.GetInt("myMonth", userMonth);
            userDay     = settings.GetInt("myDay", userDay);
        }
        public virtual string ToiCalFormat()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("BEGIN:VEVENT");
            sb.AppendLine(String.Format("UID:{0}", string.IsNullOrEmpty(this.Uid) ? this.Id : this.Uid));
            sb.AppendLine(String.Format("SUMMARY:{0}", this.Name));

            if (!string.IsNullOrEmpty(this.Description))
            {
                sb.AppendLine(String.Format("DESCRIPTION:{0}", this.Description.Replace("\n", "\\n")));
            }

            if (this.AllDayLong)
            {
                DateTime startDate = this.UtcStartDate, endDate = this.UtcEndDate;
                if (this.TimeZone != null)
                {
                    if (this.UtcStartDate != DateTime.MinValue && startDate.Kind == DateTimeKind.Utc)
                    {
                        startDate = startDate.Add(TimeZone.GetOffset());
                    }

                    if (this.UtcEndDate != DateTime.MinValue && endDate.Kind == DateTimeKind.Utc)
                    {
                        endDate = endDate.Add(TimeZone.GetOffset());
                    }
                }

                if (this.UtcStartDate != DateTime.MinValue)
                {
                    sb.AppendLine(String.Format("DTSTART;VALUE=DATE:{0}", startDate.ToString("yyyyMMdd")));
                }

                if (this.UtcEndDate != DateTime.MinValue)
                {
                    sb.AppendLine(String.Format("DTEND;VALUE=DATE:{0}", endDate.AddDays(1).ToString("yyyyMMdd")));
                }
            }
            else
            {
                if (this.UtcStartDate != DateTime.MinValue)
                {
                    sb.AppendLine(String.Format("DTSTART:{0}", this.UtcStartDate.ToString("yyyyMMdd'T'HHmmss'Z'")));
                }

                if (this.UtcEndDate != DateTime.MinValue)
                {
                    sb.AppendLine(String.Format("DTEND:{0}", this.UtcEndDate.ToString("yyyyMMdd'T'HHmmss'Z'")));
                }
            }


            if (this.RecurrenceRule != null)
            {
                sb.AppendLine(this.RecurrenceRule.ToiCalFormat());
            }

            sb.Append("END:VEVENT");
            return(sb.ToString());
        }