Beispiel #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = null;

            try
            {
                if (savedInstanceState != null)
                {
                    _contactId   = savedInstanceState.GetInt("contactId");
                    _contactName = savedInstanceState.GetString("contactName", "");
                    _willCall    = savedInstanceState.GetBoolean("call");
                    _willEMail   = savedInstanceState.GetBoolean("email");
                    _willSMS     = savedInstanceState.GetBoolean("sms");
                    _thumb       = (Bitmap)savedInstanceState.GetParcelable("thumb");
                }

                view = inflater.Inflate(Resource.Layout.ContactEmergencyItemStatusFragmentLayout, container, false);

                if (view != null)
                {
                    GetFieldComponents(view);
                    SetupCallbacks();

                    if (_contactThumb != null)
                    {
                        if (_thumb != null)
                        {
                            _contactThumb.SetImageBitmap(_thumb);
                        }
                        else
                        {
                            _contactThumb.SetImageResource(Resource.Drawable.Moods2);
                        }
                    }
                    if (_contact != null)
                    {
                        _contact.Text = _contactName.Trim();
                    }

                    _updating = true;
                    if (_call != null)
                    {
                        _call.Checked = _willCall;
                    }
                    if (_email != null)
                    {
                        _email.Checked = _willEMail;
                    }
                    if (_sms != null)
                    {
                        _sms.Checked = _willSMS;
                    }
                    _updating = false;
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreateView: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, e, "Creating View", "ContactEmergencyStatusDialogFragment.OnCreateView");
                }
            }

            return(view);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            try
            {
                if (savedInstanceState != null)
                {
                    RestoreValues(savedInstanceState);
                }

                if (Dialog != null)
                {
                    Dialog.SetTitle(_dialogTitle);
                }

                _thisView = inflater.Inflate(Resource.Layout.ActivityTimeFragment, container, false);

                if (_thisView != null)
                {
                    _initialising = true;

                    GetFieldComponents();
                    HandleMicPermission();

                    SetupCallbacks();

                    Activities   activity     = GlobalData.ActivitiesForWeek[_groupPosition];
                    ActivityTime activityTime = activity.ActivityTimes[_childPosition];
                    if (_dayName != null)
                    {
                        var mymDay = ConversionHelper.ConvertFromDateTimeDaysToMYMDays(activity.ActivityDate.DayOfWeek);
                        _dayName.Text = StringHelper.DayStringForConstant(mymDay);
                    }
                    if (_date != null)
                    {
                        _date.Text = activity.ActivityDate.ToShortDateString();
                    }
                    if (_startTime != null)
                    {
                        _startTime.Text = _startString.Trim();
                    }
                    if (_endTime != null)
                    {
                        _endTime.Text = _endString.Trim();
                    }
                    if (activityTime.ActivityTimeID != -1)
                    {
                        if (_activityName != null)
                        {
                            _activityName.Text = activityTime.ActivityName.Trim();
                        }
                        if (_achievement != null)
                        {
                            _achievement.Progress = activityTime.Achievement;
                        }
                        if (_achievementPercent != null)
                        {
                            _achievementPercent.Text = activityTime.Achievement.ToString();
                        }
                        if (_intimacy != null)
                        {
                            _intimacy.Progress = activityTime.Intimacy;
                        }
                        if (_intimacyPercent != null)
                        {
                            _intimacyPercent.Text = activityTime.Intimacy.ToString();
                        }
                        if (_pleasure != null)
                        {
                            _pleasure.Progress = activityTime.Pleasure;
                        }
                        if (_pleasurePercent != null)
                        {
                            _pleasurePercent.Text = activityTime.Pleasure.ToString();
                        }

                        if (_add != null)
                        {
                            _add.Text = _activity.GetString(Resource.String.wordAcceptUpper);
                        }
                    }
                    else
                    {
                        if (_add != null)
                        {
                            _add.Text = _activity.GetString(Resource.String.wordAddUpper);
                        }
                    }
                    _initialising = false;
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreateView: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(Activity, e, GetString(Resource.String.ErrorActivityTimeFragCreateView), "ActivityTimeDialogFragment.OnCreateView");
                }
            }
            return(_thisView);
        }
        private void Add_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(_activityName.Text))
                {
                    _activityName.Error = Activity.GetString(Resource.String.ActivityTimeFragmentAddToast);
                    return;
                }

                //get the activity
                Activities activity = GlobalData.ActivitiesForWeek[_groupPosition];
                if (activity.ActivityID == -1)
                {
                    activity.IsNew   = true;
                    activity.IsDirty = false;
                    Log.Info(TAG, "Add_Click: Activity ID is -1, setting IsNew, resetting IsDirty");
                }
                else
                {
                    Log.Info(TAG, "Add_Click: Activity ID is valid - " + activity.ActivityID.ToString() + ", set IsDirty, reset IsNew");
                    activity.IsDirty = true;
                    activity.IsNew   = false;
                }

                ActivityTime activityTime;
                Log.Info(TAG, "Add_Click: Created ActivityTime...");
                if (activity.ActivityTimes[_childPosition].ActivityTimeID == -1)
                {
                    activityTime         = new ActivityTime();
                    activityTime.IsNew   = true;
                    activityTime.IsDirty = false;
                    Log.Info(TAG, "Add_Click: ActivityTime is new - set IsNew, reset IsDirty");
                }
                else
                {
                    activityTime         = activity.ActivityTimes[_childPosition];
                    activityTime.IsNew   = false;
                    activityTime.IsDirty = true;
                    Log.Info(TAG, "Add_Click: Existing ActivityTime ID - " + activityTime.ActivityTimeID.ToString() + ", set IsDirty, reset IsNew");
                }
                Log.Info(TAG, "Add_Click: ActivityTime has been defined as a" + (activityTime.IsNew ? " new" : "n existing") + " ActivityTime");
                activityTime.ActivityID = activity.ActivityID;
                Log.Info(TAG, "Add_Click: Set ActivityTime ActivityID to " + activityTime.ActivityID.ToString());
                activityTime.ActivityName = _activityName.Text.Trim();
                Log.Info(TAG, "Add_Click: ActivityName - " + activityTime.ActivityName);
                activityTime.ActivityTime = _activityHours;
                Log.Info(TAG, "Add_Click: ActivityTime - " + StringHelper.ActivityTimeForConstant(_activityHours));
                activityTime.Achievement = _achievement.Progress;
                activityTime.Intimacy    = _intimacy.Progress;
                activityTime.Pleasure    = _pleasure.Progress;
                Log.Info(TAG, "Add_Click: Achievement - " + activityTime.Achievement.ToString() + ", Intimacy - " + activityTime.Intimacy.ToString() + ", Pleasure - " + activityTime.Pleasure.ToString());

                activity.ActivityTimes[_childPosition] = activityTime;
                Log.Info(TAG, "Add_Click: Set Activity Time at position " + _childPosition.ToString());
                GlobalData.ActivitiesForWeek[_groupPosition] = activity;
                Log.Info(TAG, "Add_Click: Set Activity in GlobalData at position " + _groupPosition.ToString());
                Log.Info(TAG, "Add_Click: Calling CompletedActivityTime with groupPosition - " + _groupPosition.ToString() + ", childPosition - " + _childPosition.ToString());
                ((IActivityTimeCallback)Activity).CompletedActivityTime(_groupPosition, _childPosition);

                Dismiss();
            }
            catch (Exception ex)
            {
                Log.Error(TAG, "Add_Click: Exception - " + ex.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(Activity, ex, GetString(Resource.String.ErrorActivityTimeFragAmendingActivityTime), "ActivityTimeDialogFragment.Add_Click");
                }
            }
        }
        private void ApplyRelevantImageResource(ConstantsAndTypes.NotificationCategories category)
        {
            try
            {
                if (_notificationImage != null)
                {
                    switch (category)
                    {
                    case ConstantsAndTypes.NotificationCategories.Achievement:
                        _notificationImage.SetImageResource(Resource.Drawable.chuffed);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Activity:
                        _notificationImage.SetImageResource(Resource.Drawable.activity);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Affirmation:
                        _notificationImage.SetImageResource(Resource.Drawable.affirmation);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Attitudes:
                        _notificationImage.SetImageResource(Resource.Drawable.attitudes);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Fantasy:
                        _notificationImage.SetImageResource(Resource.Drawable.fantasies);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Feelings:
                        _notificationImage.SetImageResource(Resource.Drawable.feelings);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Health:
                        _notificationImage.SetImageResource(Resource.Drawable.health);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Medication:
                        _notificationImage.SetImageResource(Resource.Drawable.tablets);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Reactions:
                        _notificationImage.SetImageResource(Resource.Drawable.reactions);
                        break;

                    case ConstantsAndTypes.NotificationCategories.Relationships:
                        _notificationImage.SetImageResource(Resource.Drawable.relationships);
                        break;

                    default:
                        _notificationImage.SetImageResource(Resource.Drawable.SymbolInformation);
                        break;
                    }
                }
                else
                {
                    Log.Error(TAG, "ApplyRelevantImageResource: _notificationImage is NULL!");
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "ApplyRelevantImageResource: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, e, _activity.GetString(Resource.String.ErrorMainNotHelpApplyImgResource), "MainNotificationHelper.ApplyRelevantImageResource");
                }
            }
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = null;

            try
            {
                if (savedInstanceState != null)
                {
                    _textTitle          = savedInstanceState.GetString("textTitle");
                    _genericTextEntered = savedInstanceState.GetString("genericText");
                    _thisDialogTitle    = savedInstanceState.GetString("dialogTitle");
                }

                if (Dialog != null)
                {
                    Dialog.SetTitle(_thisDialogTitle);
                }

                view = inflater.Inflate(Resource.Layout.GenericTextDialogFragmentLayout, container, false);

                if (view != null)
                {
                    GetFieldComponents(view);

                    HandleMicPermission();

                    SetupCallbacks();
                }

                if (_dialogTitle != null)
                {
                    _dialogTitle.Text = _textTitle.Trim();
                }

                if (_genericItemID != -1 || savedInstanceState != null)
                {
                    _genericText.Text = _genericTextEntered;
                    if (_add != null)
                    {
                        _add.Text = _parent.GetString(Resource.String.wordAcceptUpper);
                    }
                }
                else
                {
                    if (_add != null)
                    {
                        _add.Text = _parent.GetString(Resource.String.wordAddUpper);
                    }
                }
                Log.Info(TAG, "OnCreateView: Inflated view for " + _thisDialogTitle);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreateView: Exception - " + e.Message);
                if (Activity != null)
                {
                    if (GlobalData.ShowErrorDialog)
                    {
                        ErrorDisplay.ShowErrorAlert(Activity, e, Activity.GetString(Resource.String.ErrorCreatingGenericTextDialog), "GenericTextDialogFragment.OnCreateView");
                    }
                }
            }

            return(view);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            try
            {
                if (Dialog != null)
                {
                    Dialog.SetTitle(_dialogTitle);
                }

                View view = inflater.Inflate(Resource.Layout.MedicationReminderDialogFragmentLayout, container, false);

                if (view != null)
                {
                    GetFieldComponents(view);
                    Log.Info(TAG, "OnCreateView: Got field components");

                    SetupCallbacks();
                    Log.Info(TAG, "OnCreateView: Setup callbacks");

                    if (savedInstanceState != null)
                    {
                        _prescriptionType   = (ConstantsAndTypes.PRESCRIPTION_TYPE)savedInstanceState.GetInt("prescriptionType", -1);
                        _dayOfWeek          = (ConstantsAndTypes.DAYS_OF_THE_WEEK)savedInstanceState.GetInt("dayOfWeek", (int)ConstantsAndTypes.DAYS_OF_THE_WEEK.Monday);
                        _medicationSpreadID = savedInstanceState.GetInt("medicationSpreadID", -1);
                        _reminderTime       = Convert.ToDateTime(savedInstanceState.GetString("reminderTime"));
                        _dialogTitle        = savedInstanceState.GetString("dialogTitle");
                    }

                    _timeText.Text = _reminderTime.ToShortTimeString();

                    SetupSpinner();
                    Log.Info(TAG, "OnCreateView: Set up spinner");

                    if (_firstTimeView)
                    {
                        switch (_prescriptionType)
                        {
                        case ConstantsAndTypes.PRESCRIPTION_TYPE.Weekly:
                            if (_dayLabel != null)
                            {
                                _dayLabel.Visibility = ViewStates.Visible;
                            }
                            if (_daySpinner != null)
                            {
                                _daySpinner.Visibility = ViewStates.Visible;
                                _daySpinner.SetSelection((int)_dayOfWeek);
                            }
                            if (_timeText != null)
                            {
                                _timeText.Text = _reminderTime.ToShortTimeString();
                            }
                            break;

                        default:
                            if (_dayLabel != null)
                            {
                                _dayLabel.Visibility = ViewStates.Invisible;
                            }
                            if (_daySpinner != null)
                            {
                                _daySpinner.Visibility = ViewStates.Invisible;
                            }
                            if (_timeText != null)
                            {
                                _timeText.Text = _reminderTime.ToShortTimeString();
                            }
                            break;
                        }
                        _firstTimeView = false;
                    }
                }
                else
                {
                    Log.Error(TAG, "OnCreateView: View is NULL!");
                }
                return(view);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreateView: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(Activity, e, Activity.GetString(Resource.String.ErrorMedListFragCreateView), "MedicationreminderDialogFragment.OnCreateView");
                }
                return(null);
            }
        }
        private void PerformRandomSelection()
        {
            List <ConstantsAndTypes.NotificationCategories> categoryList = new List <ConstantsAndTypes.NotificationCategories>();
            bool      didGet         = false;
            const int MAX_CATEGORIES = 10;

            try
            {
                Random randomNotify = new Random();

                do
                {
                    ConstantsAndTypes.NotificationCategories category = (ConstantsAndTypes.NotificationCategories)randomNotify.Next((int)ConstantsAndTypes.NotificationCategories.Affirmation + 1);

                    if (!categoryList.Contains(category))
                    {
                        switch (category)
                        {
                        case ConstantsAndTypes.NotificationCategories.Achievement:
                            didGet = GetRandomAchievement();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Activity:
                            didGet = GetUpComingActivity();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Affirmation:
                            didGet = GetRandomAffirmation();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Attitudes:
                            didGet = GetRandomAttitude();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Fantasy:
                            didGet = GetRandomFantasy();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Feelings:
                            didGet = GetRandomFeelings();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Health:
                            didGet = GetRandomHealth();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Medication:
                            didGet = GetNextMedicationTime();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Reactions:
                            didGet = GetRandomReaction();
                            break;

                        case ConstantsAndTypes.NotificationCategories.Relationships:
                            didGet = GetRandomRelationship();
                            break;
                        }
                        if (!didGet)
                        {
                            categoryList.Add(category);
                        }
                    }
                }while (categoryList.Count < MAX_CATEGORIES && !didGet);
                if (!didGet)
                {
                    //provide a default
                    GetDefaultNotification();
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "PerformRandomSelection: Execption - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, e, _activity.GetString(Resource.String.ErrorMainNotHelpPerformRandom), "MainNotificationHelper.PerformRandomSelection");
                }
            }
        }
        private bool GetRandomAchievement()
        {
            bool didGet = false;

            try
            {
                List <AchievementChart> achievementsWeek = new List <AchievementChart>();
                if (_notificationBody != null)
                {
                    if (_notificationImage != null)
                    {
                        ApplyRelevantImageResource(ConstantsAndTypes.NotificationCategories.Achievement);
                    }
                    else
                    {
                        Log.Error(TAG, "GetRandomAchievement: _notificationImage is NULL!");
                    }
                    if (_notificationText != null)
                    {
                        if (GlobalData.AchievementChartItems == null)
                        {
                            GlobalData.AchievementChartItems = new List <AchievementChart>();
                        }
                        DateTime start = DateTime.Now.AddDays(-7);
                        for (DateTime theDay = start; theDay <= DateTime.Now; theDay = theDay.AddDays(1))
                        {
                            GlobalData.GetAchievementChartItemsForDate(theDay);
                            if (GlobalData.AchievementChartItems.Count > 0)
                            {
                                foreach (var item in GlobalData.AchievementChartItems)
                                {
                                    achievementsWeek.Add(item);
                                }
                            }
                        }
                        //got a selection from the last week, now pick a random one from this list
                        if (achievementsWeek.Count > 0)
                        {
                            Random           randomAchieve = new Random();
                            Int32            index         = randomAchieve.Next(achievementsWeek.Count);
                            AchievementChart achievement   = achievementsWeek[index];
                            _notificationText.Text = _activity.GetString(Resource.String.MainNotHelpAchievementText1) + " " + achievement.AchievementDate.ToShortDateString() + ", " + achievement.Achievement.Trim();
                            didGet = true;
                        }
                    }
                    else
                    {
                        Log.Error(TAG, "GetRandomAchievement: _notificationText is NULL!");
                    }
                }
                else
                {
                    Log.Error(TAG, "GetRandomAchievement: _notificationBody is NULL!");
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "GetRandomAchievement: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, e, _activity.GetString(Resource.String.ErrorGetRandomAchievement), "MainNotificationHelper.GetRandomAchievement");
                }
            }
            return(didGet);
        }
        private bool GetUpComingActivity()
        {
            Globals dbHelp = null;
            bool    didGet = false;

            try
            {
                if (_notificationBody != null)
                {
                    if (_notificationImage != null)
                    {
                        ApplyRelevantImageResource(ConstantsAndTypes.NotificationCategories.Activity);
                    }
                    else
                    {
                        Log.Error(TAG, "GetUpComingActivity: _notificationImage is NULL!");
                    }
                    if (_notificationText != null)
                    {
                        dbHelp = new Globals();
                        dbHelp.OpenDatabase();
                        if (dbHelp.GetSQLiteDatabase().IsOpen)
                        {
                            DateTime startDate = DateTime.Now;
                            if (GlobalData.ActivitiesForWeek != null)
                            {
                                if (GlobalData.ActivitiesForWeek.Count > 0)
                                {
                                    var laterActivities =
                                        (from itemActivity in GlobalData.ActivitiesForWeek
                                         where itemActivity.ActivityDate >= startDate
                                         select itemActivity).ToList();

                                    foreach (Activities activities in laterActivities)
                                    {
                                        //we need to find if there are any activities in this item
                                        if (activities.GetTotalNumberOfActivities() > 0)
                                        {
                                            bool getNextActivity = false;
                                            foreach (ActivityTime activityTime in activities.ActivityTimes)
                                            {
                                                if (activities.ActivityDate > startDate)
                                                {
                                                    getNextActivity = true;
                                                }
                                                if (!string.IsNullOrEmpty(activityTime.ActivityName.Trim()) && getNextActivity)
                                                {
                                                    _notificationText.Text = _activity.GetString(Resource.String.MainNotHelpNextActivity) + " " + activities.ActivityDate.ToShortDateString() + " " + StringHelper.ActivityTimeForConstant(activityTime.ActivityTime) + ",\n" + activityTime.ActivityName;
                                                    didGet = true;
                                                    break;
                                                }
                                                ConstantsAndTypes.NumericComparator comparator = DateHelper.CompareSpecifiedTimeWithActivityTimeRange(startDate, activityTime.ActivityTime);
                                                if (comparator == ConstantsAndTypes.NumericComparator.EqualTo)
                                                {
                                                    if (!string.IsNullOrEmpty(activityTime.ActivityName.Trim()))
                                                    {
                                                        _notificationText.Text = _activity.GetString(Resource.String.MainNotHelpNextActivity) + " " + activities.ActivityDate.ToShortDateString() + " " + StringHelper.ActivityTimeForConstant(activityTime.ActivityTime) + ",\n" + activityTime.ActivityName;
                                                        didGet = true;
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        getNextActivity = true;
                                                    }
                                                }
                                                if (comparator == ConstantsAndTypes.NumericComparator.LessThan)
                                                {
                                                    //we will cycle thru from here to the next activity
                                                    getNextActivity = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Error(TAG, "GetUpComingActivity: _notificationText is NULL!");
                    }
                }
                else
                {
                    Log.Error(TAG, "GetUpComingActivity: _notificationBody is NULL!");
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "GetUpComingActivity: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, e, _activity.GetString(Resource.String.ErrorGetRandomActivity), "MainNotificationHelper.GetUpComingActivity");
                }
            }
            return(didGet);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = null;

            try
            {
                if (savedInstanceState != null)
                {
                    _moodListID  = savedInstanceState.GetInt("moodListID");
                    _dialogTitle = savedInstanceState.GetString("dialogTitle");
                    _textTitle   = savedInstanceState.GetString("textTitle");
                    _moodName    = savedInstanceState.GetString("moodName");
                }

                if (Dialog != null)
                {
                    Dialog.SetTitle(_dialogTitle);
                }

                view = inflater.Inflate(Resource.Layout.MoodsAdjustDialogFragmentLayout, container, false);

                GetFieldComponents(view);
                HandleMicPermission();

                SetupCallbacks();

                if (_moodListID != -1)
                {
                    if (_moodListText != null)
                    {
                        _moodListText.Text = _moodName.Trim();
                    }
                    else
                    {
                        Log.Error(TAG, "OnCreateView: _moodListText is NULL!");
                    }
                    if (_add != null)
                    {
                        _add.Text = _activity.GetString(Resource.String.wordAcceptUpper);
                    }
                }
                else
                {
                    if (savedInstanceState != null)
                    {
                        _moodListText.Text = _moodName.Trim();
                    }
                    if (_add != null)
                    {
                        _add.Text = _activity.GetString(Resource.String.wordAddUpper);
                    }
                }

                if (_titleText != null)
                {
                    _titleText.Text = _textTitle.Trim();
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreateView: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(Activity, e, Activity.GetString(Resource.String.ErrorMoodsAdjustDialogCreateView), "MoodsAdjustDialogFragment.OnCreateView");
                }
            }

            return(view);
        }
        public static Toolbar SetupToolbar(AppCompatActivity activity, int toolbarId, int toolbarTitle, int textColour)
        {
            Toolbar toolbar = null;

            ConstantsAndTypes.ScreenSize screenSize = SystemHelper.GetScreenSize();

            try
            {
                toolbar = activity.FindViewById <Toolbar>(toolbarId);

                if (toolbar != null)
                {
                    activity.SetSupportActionBar(toolbar);
                    if (toolbar.Id != Resource.Id.my_toolbar)
                    {
                        activity.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                        activity.SupportActionBar.SetDisplayShowHomeEnabled(true);
                    }

                    if (toolbarTitle != -1)
                    {
                        activity.SupportActionBar.SetTitle(toolbarTitle);
                        toolbar.SetTitleTextColor(textColour);

                        switch (screenSize)
                        {
                        case ConstantsAndTypes.ScreenSize.Normal:
                            toolbar.SetTitleTextAppearance(activity, Resource.Style.MindYourMood_ActivityTheme_TitleTextAppearanceNormal);
                            break;

                        case ConstantsAndTypes.ScreenSize.Large:
                            toolbar.SetTitleTextAppearance(activity, Resource.Style.MindYourMood_ActivityTheme_TitleTextAppearanceLarge);
                            break;

                        case ConstantsAndTypes.ScreenSize.ExtraLarge:
                            toolbar.SetTitleTextAppearance(activity, Resource.Style.MindYourMood_ActivityTheme_TitleTextAppearanceExtraLarge);
                            break;
                        }
                    }
                    else
                    {
                        activity.SupportActionBar.SetDisplayShowTitleEnabled(false);
                    }

                    activity.SupportActionBar.Elevation = 1.0f;

                    if (toolbar.Id != Resource.Id.my_toolbar)
                    {
                        SetNavigationIcon(toolbar, activity);
                    }

                    toolbar.SetContentInsetsAbsolute(0, 0);
                    toolbar.SetContentInsetsRelative(0, 0);
                }
                return(toolbar);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "SetupToolbar: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(activity, e, "Setting up toolbar", "ToolbarHelper.SetupToolbar");
                }

                return(null);
            }
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);

            View view = null;

            try
            {
                if (savedInstanceState != null)
                {
                    _dialogTitle      = savedInstanceState.GetString("dialogTitle");
                    _PlayListID       = savedInstanceState.GetInt("playListID");
                    _trackListAdapter = new MusicPickerTrackListAdapter(Activity, _PlayListID);
                }

                if (Dialog != null)
                {
                    Dialog.SetTitle(_dialogTitle);
                }

                view = inflater.Inflate(Resource.Layout.MusicPickerDialogLayout, container, false);
                GetFieldComponents(view);

                if (_playListName != null)
                {
                    var playlist = GlobalData.PlayListItems.Find(play => play.PlayListID == _PlayListID);
                    if (playlist != null)
                    {
                        _playListName.Text = playlist.PlayListName.Trim();
                    }
                }
                if (_playListTracks != null)
                {
                    _playListTracks.Adapter = _trackListAdapter;
                }

                _imageLoader = ImageLoader.Instance;

                _imageLoader.LoadImage
                (
                    "drawable://" + Resource.Drawable.musicdj,
                    new ImageLoadingListener
                    (
                        loadingComplete: (imageUri, viewImg, loadedImage) =>
                {
                    var args = new LoadingCompleteEventArgs(imageUri, viewImg, loadedImage);
                    ImageLoader_LoadingComplete(null, args);
                }
                    )
                );

                SetupCallbacks();
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreateView: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(Activity, e, Activity.GetString(Resource.String.ErrorMusicPickerDialogFragmentCreateView), "MusicPickerDialogFragment.OnCreateView");
                }
            }
            return(view);
        }
        public LinearLayout GetProblemDisplay(int problemID)
        {
            //We have a problem, so this is how we want to return data for review:
            //
            //  Problem: A problem
            //      Step: First step
            //          Idea: First idea for first step
            //          Pros and cons: For first idea
            //              Pro
            //              Pro
            //              Con
            //              Con
            //          Idea: Second idea for first step
            //          Pros and cons: For second idea
            //              Pro
            //              Pro
            //              Con
            //              Con
            //          ... etc for all ideas for first step
            //          Select Solution Plan
            //          Provide Review of step - date achieved - stopped etc
            //
            //      Step: Second step
            //          Idea: First idea for second step
            //          Pros and cons: For first idea
            //              Pro
            //              Pro
            //              Con
            //              Con
            //          ... etc for all ideas for second step
            //      ... etc for all steps for A problem
            //---------------------------------------------------------------------
            //  Problem: A second problem...
            //
            //*********************************************************************
            LayoutInflater inflater          = null;
            LinearLayout   problemMainLayout = null;

            try
            {
                _problemID = problemID;
                GetProblem();
            }
            catch (Exception eg)
            {
                Log.Error(TAG, "GetProblemDisplay: Exception - " + eg.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, eg, _activity.GetString(Resource.String.ErrorProblemSolvingReviewHelperGetProblem), "ProblemSolvingReviewHelper.GetProblemDisplay");
                }
            }

            var screenSize = SystemHelper.GetScreenSize();
            int verticalPadding;
            int horizontalPadding;

            switch (screenSize)
            {
            case ConstantsAndTypes.ScreenSize.Normal:
                verticalPadding = (int)_context.Resources.GetDimension(Resource.Dimension.mindyourmood_padding_vertical_normal);
                break;

            case ConstantsAndTypes.ScreenSize.Large:
                verticalPadding = (int)_context.Resources.GetDimension(Resource.Dimension.mindyourmood_padding_vertical_large);
                break;

            case ConstantsAndTypes.ScreenSize.ExtraLarge:
                verticalPadding = (int)_context.Resources.GetDimension(Resource.Dimension.mindyourmood_padding_vertical_xlarge);
                break;

            default:
                verticalPadding = (int)_context.Resources.GetDimension(Resource.Dimension.mindyourmood_padding_vertical_normal);
                break;
            }

            horizontalPadding = (int)_context.Resources.GetDimension(Resource.Dimension.mindyourmood_padding_horizontal);

            try
            {
                //Create the main viewgroup to be passed back to the ProblemSolvingReviewActivity
                problemMainLayout = new LinearLayout(_context);

                problemMainLayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                problemMainLayout.Orientation      = Orientation.Vertical;

                //Grab the inflater
                inflater = (LayoutInflater)_context.GetSystemService(Context.LayoutInflaterService);

                //The main heading will be the problem itself (but we are going to lop off each image from the list item view
                //as it is doubling as our review item)
                View problemView = inflater.Inflate(Resource.Layout.ProblemSolvingListItem, null);

                problemView.SetPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

                ImageButton btn = problemView.FindViewById <ImageButton>(Resource.Id.imgbtnProblemSolvingListItemDetail);
                btn.Visibility = ViewStates.Gone;

                ImageView imgSteps = problemView.FindViewById <ImageView>(Resource.Id.imgStepsInProblem);
                imgSteps.Visibility = ViewStates.Gone;

                ImageView imgIdeas = problemView.FindViewById <ImageView>(Resource.Id.imgIdeasInProblem);
                imgIdeas.Visibility = ViewStates.Gone;

                ImageView imgProsAndCons = problemView.FindViewById <ImageView>(Resource.Id.imgProsAndConsInProblem);
                imgProsAndCons.Visibility = ViewStates.Gone;

                TextView txtSteps = problemView.FindViewById <TextView>(Resource.Id.txtStepsInProblem);
                txtSteps.Visibility = ViewStates.Gone;

                TextView txtIdeas = problemView.FindViewById <TextView>(Resource.Id.txtIdeasInProblem);
                txtIdeas.Visibility = ViewStates.Gone;

                TextView txtProsAndCons = problemView.FindViewById <TextView>(Resource.Id.txtProsAndConsInProblem);
                txtProsAndCons.Visibility = ViewStates.Gone;

                LinearLayout counts = problemView.FindViewById <LinearLayout>(Resource.Id.linCounts);
                counts.Visibility = ViewStates.Gone;

                TextView problemLabel = problemView.FindViewById <TextView>(Resource.Id.txtProblemSolvingListItemLabel);
                problemLabel.SetBackgroundColor(Color.Argb(255, 19, 75, 127));

                TextView probText = problemView.FindViewById <TextView>(Resource.Id.txtProblemSolvingListItemText);
                probText.SetBackgroundColor(Color.Argb(255, 19, 75, 127));
                probText.Text = _problem.ProblemText.Trim();

                problemView.SetBackgroundColor(Color.Argb(255, 19, 75, 127));
                problemMainLayout.AddView(problemView);
            }
            catch (Exception em)
            {
                Log.Error(TAG, "GetProblemDisplay: Exception - " + em.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, em, _activity.GetString(Resource.String.ErrorProblemSolvingReviewHelperCreateView), "ProblemSolvingReviewHelper.GetProblemDisplay");
                }
            }

            try
            {
                foreach (ProblemStep step in _problem.ProblemSteps)
                {
                    View stepView = inflater.Inflate(Resource.Layout.ProblemSolvingStepsListItem, null);
                    stepView.SetPadding(horizontalPadding, 0, horizontalPadding, 0);

                    stepView.SetBackgroundColor(new Color(250, 250, 221, 255));

                    ImageButton stepBtn = stepView.FindViewById <ImageButton>(Resource.Id.imgbtnProblemStepsListItemToIdeas);
                    stepBtn.Visibility = ViewStates.Invisible;

                    TextView priorityLabel = stepView.FindViewById <TextView>(Resource.Id.txtProblemStepsItemTitlePriority);
                    priorityLabel.SetTextColor(new Color(54, 93, 109, 255));
                    priorityLabel.SetBackgroundColor(new Color(250, 250, 221, 255));

                    TextView priorityText = stepView.FindViewById <TextView>(Resource.Id.txtProblemStepsItemDataPriority);
                    priorityText.SetTextColor(new Color(54, 93, 109, 255));
                    priorityText.SetBackgroundColor(new Color(250, 250, 221, 255));
                    priorityText.Text = step.PriorityOrder.ToString();

                    TextView stepLabel = stepView.FindViewById <TextView>(Resource.Id.txtProblemStepsItemTitleStep);
                    stepLabel.SetTextColor(new Color(54, 93, 109, 255));
                    stepLabel.SetBackgroundColor(new Color(250, 250, 221, 255));

                    TextView stepText = stepView.FindViewById <TextView>(Resource.Id.txtProblemStepsItemDataStep);
                    stepText.SetTextColor(new Color(54, 93, 109, 255));
                    stepText.SetBackgroundColor(new Color(250, 250, 221, 255));
                    stepText.Text = step.ProblemStep.Trim();

                    ImageButton toIdeas = stepView.FindViewById <ImageButton>(Resource.Id.imgbtnProblemStepsListItemToIdeas);
                    toIdeas.Visibility = ViewStates.Gone;

                    ImageView reviewBar = stepView.FindViewById <ImageView>(Resource.Id.imgProblemStepsItemReviewImage);
                    reviewBar.Visibility = ViewStates.Visible;
                    var newParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
                    newParams.RightMargin = 16;
                    newParams.Width       = 48;
                    newParams.Height      = 48;
                    newParams.Gravity     = GravityFlags.CenterVertical;

                    reviewBar.LayoutParameters = newParams;

                    problemMainLayout.AddView(stepView);

                    try
                    {
                        foreach (ProblemIdea idea in step.ProblemStepIdeas)
                        {
                            View ideaView = inflater.Inflate(Resource.Layout.ProblemSolvingIdeasListItem, null);
                            ideaView.SetPadding(horizontalPadding, 0, horizontalPadding, 0);

                            ImageButton ideaBtn = ideaView.FindViewById <ImageButton>(Resource.Id.imgbtnProblemSolvingIdeasToProsAndCons);
                            ideaBtn.Visibility = ViewStates.Gone;

                            TextView ideaText = ideaView.FindViewById <TextView>(Resource.Id.txtProblemSolvingIdeasText);
                            ideaText.Text = idea.ProblemIdeaText.Trim();

                            ImageView ideaBar = ideaView.FindViewById <ImageView>(Resource.Id.imgProblemSolvingIdeasReviewIndicator);
                            ideaBar.Visibility = ViewStates.Visible;

                            var ideaParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
                            ideaParams.RightMargin = 16;
                            ideaParams.LeftMargin  = 10;
                            ideaParams.Width       = 48;
                            ideaParams.Height      = 48;
                            ideaParams.Gravity     = GravityFlags.CenterVertical;

                            ideaBar.LayoutParameters = newParams;

                            if (idea.ProblemIdeaID == step.ProblemStepIdeas[step.ProblemStepIdeas.Count - 1].ProblemIdeaID)
                            {
                                ideaView.SetPadding(horizontalPadding, 0, horizontalPadding, verticalPadding);
                            }

                            problemMainLayout.AddView(ideaView);

                            try
                            {
                                foreach (ProblemProAndCon proCon in idea.ProsAndCons)
                                {
                                    View proConView = inflater.Inflate(Resource.Layout.ProblemSolvingProsAndConsListItem, null);
                                    proConView.SetPadding(horizontalPadding, 0, horizontalPadding, 0);

                                    TextView typeText = proConView.FindViewById <TextView>(Resource.Id.txtProblemSolvingProsAndConsTypeText);
                                    typeText.Text = StringHelper.ProConTypeForConstant(proCon.ProblemProAndConType);

                                    TextView proConText = proConView.FindViewById <TextView>(Resource.Id.txtProblemSolvingProsAndConsText);
                                    proConText.Text = proCon.ProblemProAndConText.Trim();

                                    Space proConBar = proConView.FindViewById <Space>(Resource.Id.spcprosAndConsPlaceholder);
                                    proConBar.Visibility = ViewStates.Visible;

                                    var proConParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.MatchParent);
                                    proConParams.RightMargin = 16;
                                    proConParams.LeftMargin  = 16;
                                    proConParams.Width       = 48;

                                    proConBar.LayoutParameters = newParams;

                                    problemMainLayout.AddView(proConView);
                                }
                            }
                            catch (Exception ep)
                            {
                                Log.Error(TAG, "GetProblemDisplay: Exception - " + ep.Message);
                                if (GlobalData.ShowErrorDialog)
                                {
                                    ErrorDisplay.ShowErrorAlert(_activity, ep, _activity.GetString(Resource.String.ErrorProblemSolvingReviewHelperCreateProConView), "ProblemSolvingReviewHelper.GetProblemDisplay");
                                }
                            }

                            if (idea.ProsAndCons.Count > 0)
                            {
                                //finally, the step review action buttons
                                View        reviewAct      = inflater.Inflate(Resource.Layout.ProblemSolvingReviewStepActions, null);
                                ImageButton buttonSolution = reviewAct.FindViewById <ImageButton>(Resource.Id.imgbtnReviewStepActionsSolutionPlan);
                                ImageButton buttonReviews  = reviewAct.FindViewById <ImageButton>(Resource.Id.imgbtnReviewStepActionsStepReviews);
                                //tag each one with the idea ID
                                if (buttonSolution != null)
                                {
                                    buttonSolution.Tag    = idea.ProblemIdeaID + ":" + idea.ProblemIdeaText.Trim();
                                    buttonSolution.Click += ButtonSolution_Click;
                                }
                                else
                                {
                                    Log.Error(TAG, "GetProblemDisplay: buttonSolution is NULL!");
                                }
                                if (buttonReviews != null)
                                {
                                    buttonReviews.Tag    = idea.ProblemIdeaID;
                                    buttonReviews.Click += ButtonReviews_Click;
                                    CheckIfThisIdeaHasReview(idea.ProblemIdeaID, reviewAct);
                                }
                                else
                                {
                                    Log.Error(TAG, "GetProblemDisplay: buttonReviews is NULL!");
                                }
                                problemMainLayout.AddView(reviewAct);
                            }
                        }
                    }
                    catch (Exception ei)
                    {
                        Log.Error(TAG, "GetProblemDisplay: Exception - " + ei.Message);
                        if (GlobalData.ShowErrorDialog)
                        {
                            ErrorDisplay.ShowErrorAlert(_activity, ei, _activity.GetString(Resource.String.ErrorProblemSolvingReviewHelperCreateIdeaview), "ProblemSolvingReviewHelper.GetProblemDisplay");
                        }
                    }
                }
            }
            catch (Exception es)
            {
                Log.Error(TAG, "GetProblemDisplay: Exception - " + es.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, es, "Creating Steps Views", "ProblemSolvingReviewHelper.GetProblemDisplay");
                }
            }

            return(problemMainLayout);
        }
        public LineChart SetupChartData(DateTime startDate, DateTime endDate)
        {
            //when first entered into this activity the default is the past weeks data, so we need to get that
            Globals dbHelp = null;

            try
            {
                if (_lineChart != null)
                {
                    Log.Info(TAG, "SetupChartData: Found _progressChart");
                    DateTime loopDate = startDate;
                    //this next array will contain the string labels for the X axis, which is the date of the point
                    List <string> pointsDates = new List <string>();

                    if (GlobalData.MoodListItems != null)
                    {
                        dbHelp = new Globals();
                        dbHelp.OpenDatabase();
                        LineDataSet         moodDataSet      = null;
                        List <ILineDataSet> moodLineDataSets = new List <ILineDataSet>();
                        var daysDifference = endDate.Subtract(startDate).Days;
                        Log.Info(TAG, "SetupChartData: Attempting to get " + daysDifference.ToString() + " days data from " + startDate.ToShortDateString() + " to " + endDate.ToShortDateString());
                        for (var a = 0; a <= daysDifference; a++)
                        {
                            pointsDates.Add(loopDate.ToShortDateString());
                            Log.Info(TAG, "SetupChartData: Added '" + loopDate.ToShortDateString() + " to date list");
                            loopDate = loopDate.AddDays(1);
                        }

                        Log.Info(TAG, "SetupChartData: MoodListItems global list contains " + GlobalData.MoodListItems.Count.ToString() + " items");
                        foreach (var item in GlobalData.MoodListItems)
                        {
                            Log.Info(TAG, "SetupChartData: Attempting to retrieve data points for " + item.MoodName.Trim());
                            moodDataSet = GetDataPoints(item.MoodId, startDate, endDate, item.MoodName);
                            if (moodDataSet != null)
                            {
                                int[] colorList = new int[1] {
                                    GlobalData.ColourList[item.MoodId - 1]
                                };
                                moodDataSet.SetColors(colorList);
                                moodLineDataSets.Add(moodDataSet);
                                Log.Info(TAG, "SetupChartData: Added " + item.MoodName + " to data sets list");
                            }
                            else
                            {
                                Log.Info(TAG, "SetupChartData: No data set returned for " + item.MoodName + "!");
                            }
                        }
                        LineData moodLineData = new LineData(pointsDates, moodLineDataSets);
                        Log.Info(TAG, "SetupChartData: Created LineData containing date list and mood data sets");
                        _lineChart.Data = moodLineData;
                        _lineChart.Legend.WordWrapEnabled = true;
                        _lineChart.SetDescriptionColor(Color.White);
                        _lineChart.SetDescription(_activity.GetString(Resource.String.MyProgressGraphDescription) + " " + startDate.ToShortDateString() + " - " + endDate.ToShortDateString());
                        _lineChart.XAxis.TextColor         = Color.White;
                        _lineChart.XAxis.AxisLineColor     = Color.White;
                        _lineChart.XAxis.GridColor         = Color.White;
                        _lineChart.AxisLeft.AxisLineColor  = Color.White;
                        _lineChart.AxisRight.AxisLineColor = Color.White;
                        _lineChart.AxisLeft.GridColor      = Color.White;
                        _lineChart.AxisRight.GridColor     = Color.White;
                        _lineChart.AxisLeft.TextColor      = Color.White;

                        _lineChart.AxisRight.TextColor = Color.White;
                        _lineChart.AxisLeft.TextSize   = 10f;
                        _lineChart.AxisRight.TextSize  = 10f;
                        var yaxis1 = _lineChart.GetAxis(YAxis.AxisDependency.Left);
                        yaxis1.AxisLineColor = Color.White;
                        yaxis1.GridColor     = Color.White;
                        yaxis1.TextColor     = Color.White;
                        yaxis1.TextSize      = 10f;
                        var yaxis2 = _lineChart.GetAxis(YAxis.AxisDependency.Right);
                        yaxis2.AxisLineColor = Color.White;
                        yaxis2.GridColor     = Color.White;
                        yaxis2.TextColor     = Color.White;
                        yaxis1.TextSize      = 10f;
                        _lineChart.SetBorderColor(Color.White);
                        moodLineData.SetValueTextColor(Color.White);
                        moodLineData.SetValueTextSize(10f);

                        _lineChart.Invalidate();
                        dbHelp.CloseDatabase();
                        Log.Info(TAG, "SetupChartData: Finished retrieving chart data");
                    }
                }
            }
            catch (Exception e)
            {
                if (dbHelp != null)
                {
                    if (dbHelp.GetSQLiteDatabase().IsOpen)
                    {
                        dbHelp.CloseDatabase();
                    }
                }
                Log.Error(TAG, "SetupChartData: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, e, "Setting data for chart", "ProgressChartHelper.SetupChartData");
                }
            }

            return(_lineChart);
        }
Beispiel #15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            try
            {
                if (savedInstanceState != null)
                {
                    _firstTimeView    = savedInstanceState.GetBoolean("firstTimeView");
                    _attitudesID      = savedInstanceState.GetInt("attitudesID");
                    _dialogTitle      = savedInstanceState.GetString("dialogTitle");
                    _currentSpeakType = savedInstanceState.GetInt("currentSpeakType");
                }
                if (Intent != null)
                {
                    _attitudesID = Intent.GetIntExtra("attitudesID", -1);
                    _dialogTitle = Intent.GetStringExtra("activityTitle");
                }

                SetContentView(Resource.Layout.StructuredPlanAttitudesDialogActivityLayout);

                GetFieldComponents();

                CheckMicPermission();

                _toolbar = ToolbarHelper.SetupToolbar(this, Resource.Id.structuredplanattitudesdialogToolbar, Resource.String.StructuredPlanAttitudesActivityTitle, Color.White);

                _imageLoader = ImageLoader.Instance;

                _imageLoader.LoadImage
                (
                    "drawable://" + Resource.Drawable.structuredplanattitudespager,
                    new ImageLoadingListener
                    (
                        loadingComplete: (imageUri, view, loadedImage) =>
                {
                    var args = new LoadingCompleteEventArgs(imageUri, view, loadedImage);
                    ImageLoader_LoadingComplete(null, args);
                }
                    )
                );

                SetupCallbacks();

                GetAttitudesData();

                SetupSpinners();

                if (_attitudesID != -1 && _attitudes != null)
                {
                    if (_firstTimeView)
                    {
                        //existing item
                        if (_toWhat != null)
                        {
                            _toWhat.Text = _attitudes.ToWhat.Trim();
                        }
                        if (_type != null)
                        {
                            _type.SetSelection((int)_attitudes.TypeOf);
                        }
                        if (_belief != null)
                        {
                            _belief.Progress = _attitudes.Belief;
                        }
                        if (_feeling != null)
                        {
                            _feeling.SetSelection(_attitudes.Feeling);
                        }
                        if (_action != null)
                        {
                            _action.SetSelection((int)_attitudes.Action);
                        }
                        if (_actionOf != null)
                        {
                            _actionOf.Text = _attitudes.ActionOf.Trim();
                        }
                        _firstTimeView = false;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreate: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(this, e, GetString(Resource.String.ErrorStructuredPlanAttitudeDialogCreateView), "StructuredPlanAttitudesDialogActivity.OnCreate");
                }
            }
        }
        private bool GetNextMedicationTime()
        {
            bool didGet = false;

            try
            {
                if (_notificationBody != null)
                {
                    if (_notificationImage != null)
                    {
                        ApplyRelevantImageResource(ConstantsAndTypes.NotificationCategories.Medication);
                    }
                    else
                    {
                        Log.Error(TAG, "GetNextMedicationTime: _notificationImage is NULL!");
                    }
                    if (_notificationText != null)
                    {
                        if (GlobalData.MedicationItems != null)
                        {
                            string medicationList             = "";
                            List <MedicationSpread> medSpread = new List <MedicationSpread>();
                            DateTime start = DateTime.Now;
                            foreach (Medication medication in GlobalData.MedicationItems)
                            {
                                medication.MedicationSpread.Sort(delegate(MedicationSpread A, MedicationSpread B)
                                {
                                    return(A.MedicationTakeTime.TakenTime.CompareTo(B.MedicationTakeTime.TakenTime));
                                });
                                foreach (MedicationSpread spread in medication.MedicationSpread)
                                {
                                    if (start.TimeOfDay < spread.MedicationTakeTime.TakenTime.TimeOfDay)
                                    {
                                        spread.Tag = medication.MedicationName.Trim();
                                        medSpread.Add(spread);
                                        break;
                                    }
                                }
                            }
                            if (medSpread.Count > 0)
                            {
                                didGet = true;
                                medSpread.Sort(delegate(MedicationSpread a, MedicationSpread b)
                                {
                                    return(a.MedicationTakeTime.TakenTime.CompareTo(b.MedicationTakeTime.TakenTime));
                                });
                                foreach (MedicationSpread remSpread in medSpread)
                                {
                                    medicationList += remSpread.Dosage.ToString() + "mg " + _activity.GetString(Resource.String.WordOfLabel) + " " + remSpread.Tag.Trim() + " " + _activity.GetString(Resource.String.WordAt) + " " + remSpread.MedicationTakeTime.TakenTime.ToShortTimeString() + "\n";
                                }
                                _notificationText.Text = medicationList.Trim();
                            }
                        }
                    }
                    else
                    {
                        Log.Error(TAG, "GetNextMedicationTime: _notificationText is NULL!");
                    }
                }
                else
                {
                    Log.Error(TAG, "GetNextMedicationTime: _notificationBody is NULL!");
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "GetNextMedicationTime: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(_activity, e, _activity.GetString(Resource.String.ErrorGetRandomMedicationTime), "MainNotificationHelper.GetNextMedicationTime");
                }
            }

            return(didGet);
        }
Beispiel #17
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = null;

            try
            {
                if (savedInstanceState != null)
                {
                    _problemID       = savedInstanceState.GetInt("problemID");
                    _problemStepID   = savedInstanceState.GetInt("problemStepID");
                    _problemIdeaID   = savedInstanceState.GetInt("problemIdeaID");
                    _problemIdeaText = savedInstanceState.GetString("problemIdeaText");
                    _dialogTitle     = savedInstanceState.GetString("dialogTitle");
                }

                if (Dialog != null)
                {
                    Dialog.SetTitle(_dialogTitle);
                }

                view = inflater.Inflate(Resource.Layout.ProblemSolvingIdeasDialogFragmentLayout, container, false);

                GetFieldComponenets(view);
                HandleMicPermission();

                SetupCallbacks();

                if (_problemIdeaID != -1)
                {
                    if (_ideaText != null)
                    {
                        _ideaText.Text = _problemIdeaText.Trim();
                    }
                    else
                    {
                        Log.Error(TAG, "OnCreateView: _problemText is NULL!");
                    }
                    if (_add != null)
                    {
                        _add.Text = _activity.GetString(Resource.String.wordAcceptUpper);
                    }
                }
                else
                {
                    if (_add != null)
                    {
                        _add.Text = _activity.GetString(Resource.String.wordAddUpper);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnCreateView: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(Activity, e, Activity.GetString(Resource.String.ErrorProblemSolvingIdeasDialogCreateView), "ProblemSolvingIdeasDialogFragment.OnCreateView");
                }
            }

            return(view);
        }
        private void RecordAudioButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (_recordAudioLabel.Text == GetString(Resource.String.recordAudioLabelReady))
                {
                    if (_recordAudioButton != null)
                    {
                        _recordAudioButton.Text = GetString(Resource.String.recordAudioButtonStop);
                    }

                    if (_recordAudioLabel != null)
                    {
                        _recordAudioLabel.Text = GetString(Resource.String.recordAudioLabelRecording);
                    }


                    //recorder.Stop();

                    // file path
                    string path = Activity.BaseContext.FilesDir.AbsolutePath;
                    if (!string.IsNullOrEmpty(path))
                    {
                        _filePath = path + "/voice_" + DateTime.Now.Day.ToString() +
                                    "_" + DateTime.Now.Month.ToString() +
                                    "_" + DateTime.Now.Year.ToString() +
                                    "_" + DateTime.Now.Hour.ToString() +
                                    "_" + DateTime.Now.Minute.ToString() +
                                    "_" + DateTime.Now.Second.ToString() +
                                    "_" + DateTime.Now.Millisecond.ToString() + ".3gpp";
                        Log.Info(TAG, "RecordAudioButton_Click: Full file and Path - '" + _filePath.Trim() + "'");

                        _isRecording = true;

                        Log.Info(TAG, "RecordAudioButton_Click: Recording Audio...");
                        SetControlsOnRecordingStateChange();
                        _mediaRecorder.SetAudioSource(AudioSource.Mic);
                        _mediaRecorder.SetOutputFormat(OutputFormat.ThreeGpp);
                        _mediaRecorder.SetAudioEncoder(AudioEncoder.AmrNb);
                        _mediaRecorder.SetOutputFile(_filePath.Trim());
                        _mediaRecorder.Prepare();
                        _mediaRecorder.Start();
                        Log.Info(TAG, "RecordAudioButton_Click: Start called on MediaRecorder...");
                    }
                    return;
                }

                if (_recordAudioLabel.Text == GetString(Resource.String.recordAudioLabelRecording))
                {
                    if (_recordAudioLabel != null)
                    {
                        _recordAudioLabel.Text = GetString(Resource.String.recordAudioLabelReady);
                    }
                    if (_recordAudioButton != null)
                    {
                        _recordAudioButton.Text = GetString(Resource.String.recordAudioButtonRecord);
                    }
                    Log.Info(TAG, "RecordAudioButton_Click: Attempting to stop recording...");
                    _mediaRecorder.Stop();
                    _mediaRecorder.Reset();
                    _mediaRecorder.Release();
                    Log.Info(TAG, "RecordAudioButton_Click: Successfully stopped MediaRecorder");
                    _isRecording = false;
                    _hasRecorded = true;

                    SetControlsOnRecordingStateChange();
                }
            }
            catch (Exception ex)
            {
                Log.Error(TAG, "RecordAudioButton_Click: Exception - " + ex.Message);
                if (Activity != null)
                {
                    if (GlobalData.ShowErrorDialog)
                    {
                        ErrorDisplay.ShowErrorAlert(Activity, ex, Activity.GetString(Resource.String.ErrorAddingVoiceRecording), "VoiceRecordingDialogFragment.RecordAudioButton_Click");
                    }
                }
            }
        }