/// <summary> /// Method that handles updating all the boxes in the calendar so that /// the dates line up in the week /// </summary> public void handleCalendar (DateTime date) { currentDate = null; string day = date.AddDays (-date.DayOfWeek.GetHashCode ()) .ToString ("M/d"); DateTime temp = date.AddDays (-date.DayOfWeek.GetHashCode ()); string weekDay = temp.ToString ("ddd"); monthInfo.Text = temp.ToString ("MMMMMMMMMM") + " of " + temp.Year; for (int i = 0; i < 7; i++) { // Determines the day from how far away from the beginning (Sunday) // and displays appropriately day = date.AddDays (-date.DayOfWeek.GetHashCode () + i).ToString ("MM/d"); weekDay = date.AddDays (-date.DayOfWeek.GetHashCode () + i) .ToString ("ddddddd"); daysList [i].wrappedButton.Text = weekDay.Substring (0, 3) + "\n" + day; // Change the above line from a 3 to a 1 daysList [i].SetDateField (date.AddDays (-date.DayOfWeek.GetHashCode () + i)); // Sets all the buttons to the default colors daysList [i].wrappedButton.SetBackgroundColor (Resources.GetColor (Resource.Color.light_gray)); daysList [i].wrappedButton.SetTextColor (Resources.GetColor (Resource.Color.black_text)); // Handles setting the highlighting of the current day on the phone if (i == current.DayOfWeek.GetHashCode () && date.Date.Equals (current.Date)) { currentDate = daysList [i].wrappedButton; daysList [i].wrappedButton.SetBackgroundColor (Resources.GetColor (Resource.Color.selected_date)); daysList [i].wrappedButton.SetBackgroundColor (Resources.GetColor (Resource.Color.current_date)); // daysList [i].wrappedButton.SetBackgroundResource (); } } // Removes any selected day selected = null; mealDisplay.Visibility = Android.Views.ViewStates.Invisible; // Makes the add button invisible addBar.Visibility = Android.Views.ViewStates.Invisible; }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Create your application here SetContentView (Resource.Layout.MealPlannerCalendar); // Provides global mealDisplay = FindViewById<LinearLayout> (Resource.Id.mealDisplay); debug = FindViewById<TextView> (Resource.Id.debug); monthInfo = FindViewById<TextView> (Resource.Id.weekOf); daysList = new DateButton[7]; addBar = FindViewById<RelativeLayout> (Resource.Id.addBar); // Makes sure day is selected before you can add a meal if (selected == null) { addBar.Visibility = Android.Views.ViewStates.Invisible; mealDisplay.Visibility = Android.Views.ViewStates.Invisible; } Button addButton = FindViewById<Button> (Resource.Id.addMeal); addButton.Click += (sender, e) => { Intent intent = new Intent (this, typeof(MealDesign)); intent.PutExtra ("Date", selected.GetDateField ().ToBinary ()); StartActivityForResult (intent, 0); }; //MENU VIEW Button menu_button = FindViewById<Button> (Resource.Id.menu_button); MenuButtonSetupSuperClass (menu_button); // Define variables Calendar c = Calendar.GetInstance (Java.Util.TimeZone.Default); Button[] shifters = new Button[2]; // Setting up month bar monthInfo.Text = current.ToString ("MMMMMMMMMM") + " of " + current.Year; // Retrieve buttons from layouts daysList [0] = new DateButton (FindViewById<Button> (Resource.Id.day1)); daysList [1] = new DateButton (FindViewById<Button> (Resource.Id.day2)); daysList [2] = new DateButton (FindViewById<Button> (Resource.Id.day3)); daysList [3] = new DateButton (FindViewById<Button> (Resource.Id.day4)); daysList [4] = new DateButton (FindViewById<Button> (Resource.Id.day5)); daysList [5] = new DateButton (FindViewById<Button> (Resource.Id.day6)); daysList [6] = new DateButton (FindViewById<Button> (Resource.Id.day7)); // Assigning dates to days handleCalendar (current); // Adding action listeners for (int i = 0; i < daysList.Length; i++) { daysList [i].wrappedButton.Click += new EventHandler ((s, e) => dayClick (s, e)); } // Go backwards a week button shifters [0] = FindViewById<Button> (Resource.Id.leftShift); shifters [0].Click += delegate { GoBackWeek (); }; // Advance week button shifters [1] = FindViewById<Button> (Resource.Id.rightShift); shifters [1].Click += delegate { GoForwardWeek (); }; debug.Text = ""; // LinearLayout ll = FindViewById<LinearLayout> (Resource.Id.MealDisplay); // Console.WriteLine (ll.ChildCount + " Look for me"); }
/// <summary> /// Event handler method to help get date to pass to next object /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> protected void dayClick (object sender, EventArgs e) { if (selected != null) { selected.wrappedButton.SetBackgroundColor (Resources.GetColor (Resource.Color.light_gray)); selected.wrappedButton.SetTextColor (Resources.GetColor (Resource.Color.black_text)); } if (currentDate != null) { currentDate.SetBackgroundColor (Resources.GetColor (Resource.Color.current_date)); } selected = GetDateButton ((Button)sender); mealDisplay.Visibility = Android.Views.ViewStates.Visible; // Console.WriteLine(selected.GetDateField().ToBinary()); selected.wrappedButton.SetBackgroundColor (Resources.GetColor (Resource.Color.selected_date)); selected.wrappedButton.SetTextColor (Resources.GetColor (Resource.Color.white_text)); // Can click the button after an action listener finds this. addBar.Visibility = Android.Views.ViewStates.Visible; RefreshMeals (); }