public bool CreateTable() { // if (_FileExists) // { _database.CreateTable <BigDaysItemModel>(); var count = _database.Table <BigDaysItemModel>().Count(); if (count == 0) { Random random = new Random(); var firstItem = new BigDaysItemModel() { _Name = "Weekend Paris", _Notification = random.Next(0, 999999), _EndDate = DateTime.Now.AddYears(1), _Image = "img17small.jpg", _ImageStorage = (int)LocationPicture.ResourcesImage, _Repeat = 0, _Alerts = "1;0#2;0#3;0#4;0#5;0", _Active = true, _PosLeft = 0, _PosTop = 0, _ChangePos = false }; _database.Insert(firstItem); _database.Close(); } //} return(_FileExists); }
void UpdateGeneration() { if (_infoBoxControl.Visibility != ViewStates.Gone) { if (_CurrentItem._Repeat != 0) { _CurrentItem = _BDDB.CheckRepeat(_CurrentItem); } TimeSpan ts = _CurrentItem._EndDate.Subtract(DateTime.Now); if (ts.Ticks < 0) { _infoBoxControl.SetTextColorInAllTextView(Color.Red); _infoBoxControl.Days = string.Format("{0:0000}", -ts.Days); _infoBoxControl.Hours = string.Format("{0:00}", -ts.Hours); _infoBoxControl.Min = string.Format("{0:00}", -ts.Minutes); _infoBoxControl.Sec = string.Format("{0:00}", -ts.Seconds); } else { _infoBoxControl.SetTextColorInAllTextView(Color.White); _infoBoxControl.Days = string.Format("{0:0000}", ts.Days); _infoBoxControl.Hours = string.Format("{0:00}", ts.Hours); _infoBoxControl.Min = string.Format("{0:00}", ts.Minutes); _infoBoxControl.Sec = string.Format("{0:00}", ts.Seconds); } } _TimerHandler.PostDelayed(UpdateGeneration, 1000); }
public BigDaysItemModel GetCurrentItem() { var n = _database.Table <BigDaysItemModel>(); BigDaysItemModel data = n.FirstOrDefault(x => x._Active == true); if (data == null) { data = _database.Table <BigDaysItemModel>().FirstOrDefault(); } _database.Close(); return(data); }
public bool Insert(BigDaysItemModel BDItem) { try { var db = new SQLiteConnection(_pathToDatabase); db.Insert(BDItem); _database.Close(); return(true); } catch (SQLiteException ex) { return(false); } }
public bool UpdatePos(BigDaysItemModel BDItem) { try { BDItem._ChangePos = true; var db = new SQLiteConnection(_pathToDatabase); db.Update(BDItem); _database.Close(); return(true); } catch (SQLiteException ex) { return(false); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if ((requestCode == 0) && (resultCode == Result.Ok) && (data != null)) { List <BigDaysItemModel> items = MainActivity._BDDB.SelectBDItems(); BigDaysItemModel item = MainActivity._BDDB.GetLastAddItem(); BitmapHelpers.LoadImage(this, item); MainActivity._BDitems.Add(item); MainActivity._BDitems = MainActivity._BDitems.OrderBy(o => o._EndDate).ToList(); _BigDaysListAdapter.Clear(); _BigDaysListAdapter.Update(MainActivity._BDitems.ToArray()); _BigDaysListAdapter.NotifyDataSetChanged(); } }
public static void SetAlarm(Context context, BigDaysItemModel item) { string MainMessage = string.Format("BIG DAYS OF OUR LIVES COUNTDOWN\r\n{0}\r\n\r\nCongratulation!\r\n{0} has com.", item._Name); DateTime d1Main = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan tsMain = new TimeSpan(item._EndDate.ToFileTimeUtc() - d1Main.Ticks); long whensysMain = (long)item._EndDate.ToUniversalTime().Subtract(d1Main).TotalMilliseconds; Intent IntentMainNot = new Intent(context, typeof(NotificationView)); IntentMainNot.PutExtra("ID", item._Notification); IntentMainNot.PutExtra("ItemID", item._ID); IntentMainNot.PutExtra("Title", item._Name); IntentMainNot.PutExtra("Message", MainMessage); PendingIntent mAlarmMainSender = PendingIntent.GetBroadcast(context, item._Notification, IntentMainNot, PendingIntentFlags.UpdateCurrent); AlarmManager amMain = (AlarmManager)context.GetSystemService(Context.AlarmService); amMain.Set(AlarmType.RtcWakeup, whensysMain, mAlarmMainSender); }
void ShowImage(BigDaysItemModel item) { //if (_CurrentImgStr != item._Image) { //_MainLayout.SetBackgroundDrawable (item._BigImg); try { _MainImage.SetImageBitmap(item._BigImg); } catch (OutOfMemoryError) { AlertDialog.Builder builder; builder = new AlertDialog.Builder(this); builder.SetTitle("Error"); builder.SetMessage("Out Of Memory Error"); builder.SetCancelable(false); builder.SetPositiveButton("OK", delegate { Finish(); }); builder.Show(); } _CurrentImgStr = item._Image; //} }
public static void UpdateAlertsAlarm(Context context, BigDaysItemModel item, int ID, string[] alertStr, int garbage) { string message = string.Format("{0} - {1}/{2}/{3} {4}:{5}", item._Name, item._EndDate.Day, item._EndDate.Month, item._EndDate.Year, item._EndDate.Hour, item._EndDate.Minute); DateTime when = CalcDateAlerts(alertStr, item); DateTime d1 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan ts = new TimeSpan(when.ToFileTimeUtc() - d1.Ticks); long whensys = (long)when.ToUniversalTime().Subtract(d1).TotalMilliseconds; Intent IntentNot = new Intent(context, typeof(NotificationView)); IntentNot.PutExtra("ID", ID); IntentNot.PutExtra("Title", item._Name); IntentNot.PutExtra("Message", message); IntentNot.PutExtra("ItemID", item._ID); PendingIntent mAlarmSender = PendingIntent.GetBroadcast(context, ID, IntentNot, PendingIntentFlags.UpdateCurrent); PendingIntent mAlarmSenderCansel = PendingIntent.GetBroadcast(context, garbage, IntentNot, PendingIntentFlags.UpdateCurrent); AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); am.Cancel(mAlarmSenderCansel); am.Set(AlarmType.RtcWakeup, whensys, mAlarmSender); }
public static void LoadImage(Activity context, BigDaysItemModel item) { switch (item._ImageStorage) { case (int)LocationPicture.ResourcesImage: string path_main_bg_def = item._Image.Replace("small", ""); Resources res = context.Resources; int imageID = res.GetIdentifier(path_main_bg_def.Replace(".jpg", ""), "drawable", context.PackageName); int imageIDsmall = res.GetIdentifier(item._Image.Replace(".jpg", ""), "drawable", context.PackageName); item._BigImg = DecodeSampledBitmapFromResource(res, imageID, (int)MainActivity._DisplayWidth, (int)MainActivity._DisplayWidth, context); item._SmallImg = DecodeSampledBitmapFromResource(res, imageIDsmall, 70, 70, context); break; case (int)LocationPicture.Base64Image: item._BigImg = BitmapToBase64Converter.Base64ToBitmap(item.ImageBase64); item._SmallImg = item._BigImg; break; case (int)LocationPicture.FileImage: item._BigImg = LoadAndResizeBitmap(item._Image, (int)MainActivity._DisplayWidth, (int)MainActivity._DisplayWidth); item._SmallImg = LoadAndResizeBitmap(item._Image, 70, 70); break; } }
private static DateTime CalcDateAlerts(string[] alertStr, BigDaysItemModel item) { DateTime when = item._EndDate; switch (Convert.ToInt16(alertStr[4])) { case 0: when = item._EndDate.AddSeconds(-Convert.ToInt16(alertStr[3])); break; case 1: when = item._EndDate.AddMinutes(-Convert.ToInt16(alertStr[3])); break; case 2: when = item._EndDate.AddHours(-Convert.ToInt16(alertStr[3])); break; case 3: when = item._EndDate.AddDays(-Convert.ToInt16(alertStr[3])); break; case 4: when = item._EndDate.AddDays(-(Convert.ToInt16(alertStr[3]) * 7)); break; case 5: when = item._EndDate.AddMonths(-Convert.ToInt16(alertStr[3])); break; case 6: when = item._EndDate.AddYears(-Convert.ToInt16(alertStr[3])); break; } return(when); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if ((requestCode == (int)BigDays.Enums.RequestCode.List_BigDays || requestCode == (int)BigDays.Enums.RequestCode.Edit_BigDay) && (resultCode == Result.Ok)) { _BDDB.CheckRepeats(); _CurrentItem = _BDDB.GetCurrentItem(); _infoBoxControl.Visibility = ViewStates.Visible; if (requestCode == (int)BigDays.Enums.RequestCode.Edit_BigDay) { for (int i = 0; i < _BDitems.Count; i++) { if (_BDitems[i]._ID == _CurrentItem._ID) { BigDaysItemModel item = _BDDB.SelectItem(_CurrentItem._ID); BitmapHelpers.LoadImage(this, item); _BDitems[i] = item; ShowImage(item); } } if (_BDitems.Count == 0) { ShowDefImage(); _infoBoxControl.Visibility = ViewStates.Gone; } } else { foreach (var i in _BDitems) { if (i._ID == _CurrentItem._ID) { ShowImage(i); } } } _ActiveBD = _BDitems.FirstOrDefault(x => x._Active == true); if (_ActiveBD == null) { _ActiveBD = _BDitems.FirstOrDefault(); } if (_infoBoxControl.Visibility != ViewStates.Gone) { _infoBoxControl.Title = _CurrentItem._Name; if (_ActiveBD._ChangePos) { RelativeLayout.LayoutParams infoBoxParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParams.LeftMargin = _ActiveBD._PosLeft; infoBoxParams.TopMargin = _ActiveBD._PosTop; _infoBoxControl.LayoutParameters = infoBoxParams; } else { RelativeLayout.LayoutParams infoBoxParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParams.LeftMargin = 0; infoBoxParams.AddRule(LayoutRules.CenterVertical); _infoBoxControl.LayoutParameters = infoBoxParams; } } } else if ((requestCode == (int)BigDays.Enums.RequestCode.AddNew_BigDay) && (resultCode == Result.Ok)) { BigDaysItemModel item = _BDDB.GetLastAddItem(); BitmapHelpers.LoadImage(this, item); _BDitems.Add(item); _infoBoxControl.Visibility = ViewStates.Visible; if (_BDitems.Count == 1) { ShowImage(_BDitems[0]); } _CurrentItem = _BDDB.GetCurrentItem(); _ActiveBD = _BDitems.FirstOrDefault(x => x._Active == true); if (_ActiveBD == null) { _ActiveBD = _BDitems.FirstOrDefault(); } if (_infoBoxControl.Visibility != ViewStates.Gone) { if (_ActiveBD._ChangePos) { RelativeLayout.LayoutParams infoBoxParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParams.LeftMargin = _ActiveBD._PosLeft; infoBoxParams.TopMargin = _ActiveBD._PosTop; _infoBoxControl.LayoutParameters = infoBoxParams; } else { RelativeLayout.LayoutParams infoBoxParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParams.LeftMargin = 0; infoBoxParams.AddRule(LayoutRules.CenterVertical); _infoBoxControl.LayoutParameters = infoBoxParams; } } } }
private void Init() { #if _TRIAL_ try { interstitialAds = new InterstitialAd(this); // initializing interstitial ads mAdView.Visibility = ViewStates.Visible; var adRequest = new Android.Gms.Ads.AdRequest.Builder(); #if DEBUG adRequest.AddTestDevice(Android.Gms.Ads.AdRequest.DeviceIdEmulator); //"TEST_EMULATOR" #endif var build = adRequest.Build(); mAdView.LoadAd(build); #if DEBUG //Test interstitialAds.AdUnitId = "ca-app-pub-3940256099942544/1033173712"; #else interstitialAds.AdUnitId = Resources.GetString(Resource.String.adMob_api_interstitial_key); #endif // loading test ad using adrequest interstitialAds.LoadAd(build); var ThisAdListener = new BigDays.AdListener(this); interstitialAds.AdListener = ThisAdListener; ThisAdListener.AdLoaded += () => { _trialImg.Visibility = ViewStates.Invisible; mAdView.Visibility = ViewStates.Visible; }; } catch { } #endif #if _TRIAL_ _trialImg.Visibility = ViewStates.Visible; _shopping.Visibility = ViewStates.Visible; Intent browserIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(Constants.VersionLink)); _trialImg.Click += (sender, e) => { StartActivity(browserIntent); }; _shopping.Click += (sender, e) => { StartActivity(browserIntent); }; #else _trialImg.Visibility = ViewStates.Gone; _shopping.Visibility = ViewStates.Gone; #endif long max_memory = Runtime.GetRuntime().MaxMemory(); long total_memory = Runtime.GetRuntime().TotalMemory(); _BDDB = new DataService(); _BDDB.ConnectToDB("BigDaysNew.db3"); _BDDB.CreateTable(); _BDDB.CheckRepeats(); _BDitems = _BDDB.SelectBDItems(); _ActiveBD = _BDitems.FirstOrDefault(x => x._Active == true); if (_ActiveBD == null) { _ActiveBD = _BDitems.FirstOrDefault(); } var Display = WindowManager.DefaultDisplay; _DisplayHeight = Display.Height; _DisplayWidth = Display.Width; _infoBoxControl.SetOnTouchListener(this); GlobalLayoutListener l = null; l = new GlobalLayoutListener(() => { if (_FirstAppOpen == 0) { RelativeLayout.LayoutParams infoBoxParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParams.LeftMargin = _ActiveBD._PosLeft; infoBoxParams.TopMargin = _ActiveBD._PosTop; if (_ActiveBD._ChangePos) { _infoBoxControl.LayoutParameters = infoBoxParams; } else { RelativeLayout.LayoutParams infoBoxParamsDef = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParamsDef.LeftMargin = 0; infoBoxParamsDef.AddRule(LayoutRules.CenterVertical); _infoBoxControl.LayoutParameters = infoBoxParamsDef; } _FirstAppOpen = 1; } _infoBoxControl.ViewTreeObserver.RemoveGlobalOnLayoutListener(l); }); _infoBoxControl.ViewTreeObserver.AddOnGlobalLayoutListener(l); int _ItemID = Intent.GetIntExtra("ItemID", 0); if (_BDitems.Count > 0) { BitmapHelpers.LoadImages(this, _BDitems); _CurrentItem = _BDDB.GetCurrentItem(); if (_ItemID != 0) { _CurrentItem._ID = _ItemID; } var currentItem = _BDitems.FirstOrDefault(n => n._ID == _CurrentItem._ID); if (currentItem != null) { ShowImage(currentItem); } _infoBoxControl.Visibility = ViewStates.Visible; } else { ShowDefImage(); _infoBoxControl.Visibility = ViewStates.Gone; } if (_infoBoxControl.Visibility != ViewStates.Gone) { _infoBoxControl.Title = _CurrentItem._Name; } var ui_showListButton = FindViewById <ImageButton>(Resource.Id.showListButton); ui_showListButton.Click += (sender, e) => { var IntentListActivity = new Intent(this, typeof(ListActivity)); StartActivityForResult(IntentListActivity, (int)BigDays.Enums.RequestCode.List_BigDays); }; var ui_addBigDaysBtn = FindViewById <ImageButton>(Resource.Id.mainAddBigDays); ui_addBigDaysBtn.Click += (sender, e) => { #if _TRIAL_ if (_BDitems.Count == 1) { AlertDialog.Builder builder; builder = new AlertDialog.Builder(this); builder.SetTitle("Free Version"); builder.SetMessage("You can add only 1 Big Day item in free version. Please purchase full version to enable adding unlimited Big Days items and Facebook share function.\n\nBy clicking \"Buy Now\" you will redirect to Full version (no ad banner) purchase page."); builder.SetCancelable(false); builder.SetPositiveButton("Buy Now", delegate { StartActivity(browserIntent); }); builder.SetNegativeButton("Continue", delegate { }); builder.Show(); } else { var IntentNewBigDaysActivity = new Intent(this, typeof(NewBigDays)); StartActivityForResult(IntentNewBigDaysActivity, (int)Enums.RequestCode.AddNew_BigDay); } #else var IntentNewBigDaysActivity = new Intent(this, typeof(NewBigDays)); StartActivityForResult(IntentNewBigDaysActivity, (int)BigDays.Enums.RequestCode.AddNew_BigDay); #endif }; var ui_Feedback = FindViewById <ImageButton>(Resource.Id.Feedback); ui_Feedback.Click += (sender, e) => { var IntentFeedbackActivity = new Intent(this, typeof(Feedback)); StartActivity(IntentFeedbackActivity); }; _infoBoxControl.EditBigDaysBtn.Click += (sender, e) => { var IntentNewBigDaysActivity = new Intent(this, typeof(NewBigDays)); IntentNewBigDaysActivity.PutExtra("Edit", true); IntentNewBigDaysActivity.PutExtra("ID", _CurrentItem._ID); StartActivityForResult(IntentNewBigDaysActivity, (int)BigDays.Enums.RequestCode.Edit_BigDay); }; _infoBoxControl.ShareBigDaysBtn.Click += (sender, e) => { var IntentShareActivity = new Intent(this, typeof(Share)); IntentShareActivity.PutExtra("ID", _CurrentItem._ID); StartActivity(IntentShareActivity); }; if (_infoBoxControl.Visibility != ViewStates.Gone) { if (_ActiveBD._ChangePos) { RelativeLayout.LayoutParams infoBoxParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParams.LeftMargin = _ActiveBD._PosLeft; infoBoxParams.TopMargin = _ActiveBD._PosTop; _infoBoxControl.LayoutParameters = infoBoxParams; } else { RelativeLayout.LayoutParams infoBoxParamsDef = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent - 30, ViewGroup.LayoutParams.WrapContent); infoBoxParamsDef.LeftMargin = 0; infoBoxParamsDef.AddRule(LayoutRules.CenterVertical); _infoBoxControl.LayoutParameters = infoBoxParamsDef; } } _TimerHandler = new Handler(); UpdateGeneration(); }
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(); } }; }
public BigDaysItemModel CheckRepeat(BigDaysItemModel item) { switch (item._Repeat) { case 1: while (true) { if (item._EndDate < DateTime.Now) { item._EndDate = item._EndDate.AddDays(1); } else { break; } } break; case 2: while (true) { if (item._EndDate < DateTime.Now) { item._EndDate = item._EndDate.AddDays(7); } else { break; } } break; case 3: while (true) { if (item._EndDate < DateTime.Now) { item._EndDate = item._EndDate.AddMonths(1); } else { break; } } break; case 4: while (true) { if (item._EndDate < DateTime.Now) { item._EndDate = item._EndDate.AddYears(2); } else { break; } } break; } return(item); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); _uiHelper = new UiLifecycleHelper(this, callback); _uiHelper.OnCreate(savedInstanceState); if (savedInstanceState != null) { string name = savedInstanceState.GetString(PENDING_ACTION_BUNDLE_KEY); _pendingAction = (PendingAction)Enum.Parse(typeof(PendingAction), name); } SetContentView(Resource.Layout.FacebookScreen); //_googlePlayLink = "http://play.google.com/store/apps/details?id=" + this.PackageName; _ID = Intent.GetIntExtra("ID", 0); _Item = MainActivity._BDDB.SelectItem(_ID); TimeSpan ts = _Item._EndDate.Subtract(DateTime.Now); string DaysTo = String.Format("{0:0000}", ts.Days); string HoursTo = String.Format("{0:00}", ts.Hours); string MinTo = String.Format("{0:00}", ts.Minutes); string SecTo = String.Format("{0:00}", ts.Seconds); _message = string.Format("{0} {1} {2} days, {3} hours, {4} minutes, {5} seconds {6}", _Item._Name, _Item._EndDate < DateTime.Now ? "was" : "is coming in", DaysTo, HoursTo, MinTo, SecTo, _Item._EndDate < DateTime.Now ? " ago" : ""); _textFacebookDescription = (TextView)FindViewById(Resource.Id.textFacebookDescription); _textFacebookDescription.Text = _message; _textMessage = (EditText)FindViewById(Resource.Id.txtMessage); _loginButton = (LoginButton)FindViewById(Resource.Id.facebook_login_button); _loginButton.UserInfoChangedCallback = new MyUserInfoChangedCallback(this); _postStatusUpdateButton = FindViewById <Button> (Resource.Id.postStatusUpdateButton); _postStatusUpdateButton.Click += delegate { OnClickPostStatusUpdate(); }; _controlsContainer = (ViewGroup)FindViewById(Resource.Id.main_ui_container); Android.Support.V4.App.FragmentManager fm = SupportFragmentManager; Android.Support.V4.App.Fragment fragment = fm.FindFragmentById(Resource.Id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. _controlsContainer.Visibility = ViewStates.Gone; } fm.BackStackChanged += delegate { if (fm.BackStackEntryCount == 0) { // We need to re-show our UI. _controlsContainer.Visibility = ViewStates.Visible; } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Share); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbarShare); SetActionBar(toolbar); ActionBar.Title = "Share"; _ID = Intent.GetIntExtra("ID", 0); _Item = MainActivity._BDDB.SelectItem(_ID); var googlePlayLink = "http://play.google.com/store/apps/details?id=" + this.PackageName; #if __AMAZON__ googlePlayLink = "http://www.amazon.com/gp/mas/dl/android?p=" + this.PackageName; #endif var ui_sendEmailBtn = FindViewById <Button> (Resource.Id.sendEmail); ui_sendEmailBtn.Click += (sender, e) => { TimeSpan ts = _Item._EndDate.Subtract(DateTime.Now); string DaysTo = String.Format("{0:0000}", ts.Days); string HoursTo = String.Format("{0:00}", ts.Hours); string MinTo = String.Format("{0:00}", ts.Minutes); string SecTo = String.Format("{0:00}", ts.Seconds); String message = string.Format("{0} {1} {2} days, {3} hours, {4} minutes, {5} seconds {6} \n{7}", _Item._Name, _Item._EndDate < DateTime.Now ? "was" : "is coming in", DaysTo, HoursTo, MinTo, SecTo, _Item._EndDate < DateTime.Now ? " ago" : "", googlePlayLink); Intent i = new Intent(Intent.ActionSend); i.SetType("message/rfc822"); i.PutExtra(Intent.ExtraSubject, _Item._Name); i.PutExtra(Intent.ExtraText, message); try { StartActivityForResult(Intent.CreateChooser(i, "Send mail..."), 0); } catch (Android.Content.ActivityNotFoundException ex) { Toast.MakeText(this, "There are no email clients installed.", ToastLength.Short).Show(); } }; var ui_sendSMSBtn = FindViewById <Button> (Resource.Id.sendSMS); ui_sendSMSBtn.Click += (sender, e) => { if (PermissionHelpers.NeedPermissionsSendSms(this)) { PermissionHelpers.RequestPermissionssSendSms(this); } else { TimeSpan ts = _Item._EndDate.Subtract(DateTime.Now); string DaysTo = String.Format("{0:0000}", ts.Days); string HoursTo = String.Format("{0:00}", ts.Hours); string MinTo = String.Format("{0:00}", ts.Minutes); string SecTo = String.Format("{0:00}", ts.Seconds); String message = string.Format("{0} {1} {2} days, {3} hours, {4} minutes, {5} seconds {6} \n{7}", _Item._Name, _Item._EndDate < DateTime.Now ? "was" : "is coming in", DaysTo, HoursTo, MinTo, SecTo, _Item._EndDate < DateTime.Now ? " ago" : "", googlePlayLink); try { Intent sendIntent = new Intent(Intent.ActionView); sendIntent.PutExtra("sms_body", message); sendIntent.SetType("vnd.android-dir/mms-sms"); StartActivity(sendIntent); } catch (Exception em) { Toast.MakeText(this, "SMS faild, please try again later!", ToastLength.Long).Show(); } } }; var ui_FacebookBtn = FindViewById <Button> (Resource.Id.FacebookBtn); ui_FacebookBtn.Click += (sender, e) => { var IntentShareActivity = new Intent(this, typeof(FacebookScreen)); IntentShareActivity.PutExtra("ID", _ID); StartActivity(IntentShareActivity); }; var ui_TwitterBtn = FindViewById <Button> (Resource.Id.TwitterBtn); ui_TwitterBtn.Click += (sender, e) => { TimeSpan ts = _Item._EndDate.Subtract(DateTime.Now); string DaysTo = String.Format("{0:0000}", ts.Days); string HoursTo = String.Format("{0:00}", ts.Hours); string MinTo = String.Format("{0:00}", ts.Minutes); string SecTo = String.Format("{0:00}", ts.Seconds); String message = string.Format("{0} {1} {2} days, {3} hours, {4} minutes, {5} seconds {6}", _Item._Name, _Item._EndDate < DateTime.Now ? "was" : "is coming in", DaysTo, HoursTo, MinTo, SecTo, _Item._EndDate < DateTime.Now ? " ago" : ""); Intent browserIntent = new Intent(Android.Content.Intent.ActionView, Android.Net.Uri.Parse( string.Format("http://www.twitter.com/intent/tweet?&text={0}&url={1}", message, googlePlayLink))); StartActivity(browserIntent); }; }