예제 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.NewBigDays);

            Geneticist.Splice(this);

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetActionBar(toolbar);
            ActionBar.Title = "Edit Big Days";

            _cameraHelpers = new CameraHelpers(this);
            MainActivity._BDDB.CheckRepeats();
            _Edit = Intent.GetBooleanExtra("Edit", false);

            _ImageArea = FindViewById <ImageView>(Resource.Id.imageArea);
            _ImageArea.SetScaleType(ImageView.ScaleType.CenterCrop);


            _UiTimeEdit        = FindViewById <EditText>(Resource.Id.timeEdit);
            _UiTimeEdit.Click += (o, e) => ShowDialog(TIME_DIALOG_ID);

            _UiDateEdit        = FindViewById <EditText>(Resource.Id.dateEdit);
            _UiDateEdit.Click += (o, e) => { ShowDialog(DATE_DIALOG_ID); };

            _UiEditRepeat        = FindViewById <EditText>(Resource.Id.editRepeat);
            _UiEditRepeat.Click += (sender, e) =>
            {
                var IntentRepeatSelect = new Intent(this, typeof(RepeatSelect));
                IntentRepeatSelect.PutExtra("Num", _RepeatNum);
                StartActivityForResult(IntentRepeatSelect, (int)RequestCode.Repeat);
            };

            _ImgPath         = "img17.jpg";
            _ImageStorageNum = LocationPicture.ResourcesImage;

            // Get the current time
            DateTime now = DateTime.Now;

            now     = now.AddHours(1);
            hour    = now.Hour;
            minute  = DateTime.Now.Minute;
            seconds = DateTime.Now.Second;

            // get the current date
            date = DateTime.Today;

            _UiName = FindViewById <EditText>(Resource.Id.BigDayName);

            if (_Edit)
            {
                _ID = Intent.GetIntExtra("ID", 0);
                if (_ID != 0)
                {
                    _Item = MainActivity._BDDB.SelectItem(_ID);

                    _UiName.Text = _Item._Name;

                    // Get the current time
                    hour   = _Item._EndDate.Hour;
                    minute = _Item._EndDate.Minute;

                    // get the current date
                    date = _Item._EndDate;

                    _RepeatNum         = _Item._Repeat;
                    _Notification      = _Item._Notification;
                    _UiEditRepeat.Text = _RepeatStrs[_RepeatNum].ToString();

                    _AlertStr = _AlertStrOld = _Item._Alerts;

                    _ImageStorageNum = (LocationPicture)_Item._ImageStorage;
                    _ImgPath         = _Item._Image;
                    _ImageBase64     = _Item.ImageBase64;

                    foreach (var i in MainActivity._BDitems)
                    {
                        if (i._ID == _ID)
                        {
                            _ImageArea.SetImageBitmap(i._BigImg);
                        }
                    }
                }
            }
            else
            {
                Resources res     = Resources;
                int       imageID = res.GetIdentifier(_ImgPath.Replace(".jpg", ""), "drawable", PackageName);
                Drawable  def     = new BitmapDrawable(BitmapHelpers.DecodeSampledBitmapFromResource(res, imageID, (int)MainActivity._DisplayWidth, (int)MainActivity._DisplayWidth, this));
                _ImageArea.SetImageDrawable(def);
            }

            _NM = (NotificationManager)GetSystemService(NotificationService);

            _UiAlerts        = FindViewById <Button>(Resource.Id.Alerts);
            _UiAlerts.Click += (sender, e) =>
            {
                string[] alerts = _AlertStr.Split('#');
                int      i      = 0;
                foreach (var a in alerts)
                {
                    string[] alertStr = a.Split(';');
                    garbage[i] = 0;
                    if (alertStr[1] == "1")
                    {
                        garbage[i] = Convert.ToInt32(alertStr[2]);
                    }
                    i++;
                }
                var IntentAlerts = new Intent(this, typeof(Alerts));
                IntentAlerts.PutExtra("Alert", _AlertStr);
                StartActivityForResult(IntentAlerts, (int)RequestCode.Alerts);
            };

            // Display the current date
            UpdateDisplayTime();

            // display the current date (this method is below)
            UpdateDisplayDate();

            _UiSeveOrEdit        = FindViewById <ImageButton>(Resource.Id.SeveOrEdit);
            _UiSeveOrEdit.Click += (sender, e) =>
            {
                if (_Edit)
                {
                    _Item._ID   = _ID;
                    _Item._Name = _UiName.Text.ToString();
                    DateTime d = Convert.ToDateTime(_UiDateEdit.Text.ToString());
                    DateTime t = Convert.ToDateTime(_UiTimeEdit.Text.ToString());
                    _Item._EndDate      = new DateTime(d.Year, d.Month, d.Day, t.Hour, t.Minute, t.Second);
                    _Item._Image        = _ImgPath;
                    _Item._ImageStorage = (int)_ImageStorageNum;
                    _Item._Repeat       = _RepeatNum;
                    _Item.ImageBase64   = _ImageBase64;
                    int garbageMain = _Notification;

                    _Item._Notification = new System.Random().Next(0, 999999);

                    AlarmHelpers.UpdateAlarm(this, _Item, garbageMain);

                    _Item._Alerts = _AlertStr;
                    string[]            alertOld = _AlertStrOld.Split('#');
                    NotificationManager NM       = (NotificationManager)GetSystemService(Context.NotificationService);
                    foreach (var ao in alertOld)
                    {
                        string[] ao2 = ao.Split(';');
                        if (ao2[1] == "1")
                        {
                            int ID = Convert.ToInt32(ao2[2]);
                            NM.Cancel(ID);
                        }
                    }
                    string[] alerts = _AlertStr.Split('#');
                    int      i      = 0;
                    foreach (var a in alerts)
                    {
                        string[] alertStr = a.Split(';');
                        if (alertStr[1] == "1")
                        {
                            int ID = Convert.ToInt32(alertStr[2]);
                            AlarmHelpers.UpdateAlertsAlarm(this, _Item, ID, alertStr, garbage[i]);
                        }

                        i++;
                    }
                    MainActivity._BDDB.Update(_Item);
                    Intent ParentIntent = new Intent(this, typeof(MainActivity));
                    SetResult(Result.Ok, ParentIntent);
                    Finish();
                }
                else
                {
                    _Item       = new BigDaysItemModel();
                    _Item._Name = _UiName.Text.ToString();
                    DateTime d = Convert.ToDateTime(_UiDateEdit.Text.ToString());
                    DateTime t = Convert.ToDateTime(_UiTimeEdit.Text.ToString());
                    _Item._EndDate      = new DateTime(d.Year, d.Month, d.Day, t.Hour, t.Minute, t.Second);
                    _Item._Image        = _ImgPath;
                    _Item._ImageStorage = (int)_ImageStorageNum;
                    _Item._Repeat       = _RepeatNum;
                    _Item.ImageBase64   = _ImageBase64;


                    _Item._Notification = new System.Random().Next(0, 999999);
                    _Item._ID           = MainActivity._BDDB.GetLastID() + 1;

                    AlarmHelpers.SetAlarm(this, _Item);

                    _Item._Alerts = _AlertStr;
                    string[] alerts = _AlertStr.Split('#');
                    foreach (var a in alerts)
                    {
                        string[] alertStr = a.Split(';');
                        if (alertStr[1] == "1")
                        {
                            int ID = Convert.ToInt32(alertStr[2]);
                            _Item._ID = MainActivity._BDDB.GetLastID() + 1;

                            AlarmHelpers.SetAlertsAlarm(this, _Item, ID, alertStr);
                        }
                    }

                    MainActivity._BDDB.Insert(_Item);

                    List <BigDaysItemModel> items = MainActivity._BDDB.SelectBDItems();
                    if (items.Count == 1)
                    {
                        MainActivity._BDDB.SetActive(items[0]._ID);
                    }

                    Intent ParentIntent = new Intent(this, typeof(ListActivity));
                    SetResult(Result.Ok, ParentIntent);
                    Finish();
                }
            };
            _UiCancelOrDelete = FindViewById <ImageButton>(Resource.Id.CancelOrDelete);
            if (_Edit)
            {
                _UiCancelOrDelete.SetImageResource(Resource.Drawable.ic_action_discard);
            }

            _UiCancelOrDelete.Click += (sender, e) =>
            {
                if (_Edit)
                {
                    AlarmHelpers.RemoveAlarm(this, _Notification);

                    foreach (var g in garbage)
                    {
                        if (g != 0)
                        {
                            Intent        IntentNot          = new Intent(this, typeof(NotificationView));
                            PendingIntent mAlarmSenderCansel = PendingIntent.GetBroadcast(this, g, IntentNot, PendingIntentFlags.UpdateCurrent);
                            AlarmManager  am = (AlarmManager)GetSystemService(Context.AlarmService);
                            am.Cancel(mAlarmSenderCansel);
                        }
                    }

                    if (_ID != 0)
                    {
                        MainActivity._BDDB.Delete(_ID);
                    }

                    for (int i = 0; i < MainActivity._BDitems.Count; i++)
                    {
                        if (MainActivity._BDitems[i]._ID == _ID)
                        {
                            MainActivity._BDitems.RemoveAt(i);
                        }
                    }


                    List <BigDaysItemModel> items = MainActivity._BDDB.SelectBDItems();
                    if (items.Count > 0)
                    {
                        MainActivity._BDDB.SetActive(items[0]._ID);
                    }

                    Intent ParentIntent = new Intent(this, typeof(ListActivity));
                    SetResult(Result.Ok, ParentIntent);
                    Finish();
                }
                else
                {
                    Intent ParentIntent = new Intent(this, typeof(ListActivity));
                    SetResult(Result.Canceled, ParentIntent);
                    Finish();
                }
            };
        }
예제 #2
0
 public static Drawable LoadImage(string path)
 {
     return(new BitmapDrawable(BitmapHelpers.LoadAndResizeBitmap(path, 70, 70)));
 }