Exemple #1
0
        private void SetBinding()
        {
            var bindingSet = this.CreateBindingSet <SettingsView, SettingsViewModel>();

            bindingSet.Bind(HoursList)
            .For(v => v.ItemsSource)
            .To(vm => vm.HoursList);

            bindingSet.Bind(addHour)
            .For(nameof(View.Click))
            .To(vm => vm.AddHour);

            bindingSet.Bind(soundLabel)
            .For(v => v.Text)
            .To(vm => vm.RingUri)
            .WithConversion(new InlineValueConverter <string, string>((arg) =>
            {
                var uri           = Android.Net.Uri.Parse(arg);
                Ringtone ringtone = RingtoneManager.GetRingtone(this, uri);
                return(RingtoneManager.IsDefault(uri) ? "Default" : ringtone.GetTitle(this));
            }));

            bindingSet.Bind(this.snooze)
            .For(v => v.Text)
            .To(vm => vm.SnoozeMinutes)
            .WithConversion(new InlineValueConverter <int, string>(arg => Humanizer.TimeSpanHumanizeExtensions.Humanize(TimeSpan.FromMinutes(arg), maxUnit: Humanizer.Localisation.TimeUnit.Minute, minUnit: Humanizer.Localisation.TimeUnit.Minute)));

            bindingSet.Bind(this.window)
            .For(v => v.Text)
            .To(vm => vm.WindowHours)
            .WithConversion(new InlineValueConverter <int, string>(arg => $"+/- {Humanizer.TimeSpanHumanizeExtensions.Humanize(TimeSpan.FromHours(arg), maxUnit: Humanizer.Localisation.TimeUnit.Hour, minUnit: Humanizer.Localisation.TimeUnit.Hour)}"));


            bindingSet.Apply();
        }
 public void StopRintone(string name)
 {
     if (ringtone.GetTitle(context) == name && name != null)
     {
         if (ringtone.IsPlaying)
         {
             ringtone.Stop();
         }
     }
 }
        public static bool OnPreferenceChange(Preference preference, object newValue)
        {
            var stringValue = newValue.ToString();

            if (preference is ListPreference)
            {
                // For list preferences, look up the correct display value in
                // the preference's 'entries' list.
                ListPreference listPreference = (ListPreference)preference;
                int            index          = listPreference.FindIndexOfValue(stringValue);

                // Set the summary to reflect the new value.
                preference.Summary = index >= 0 ? listPreference.GetEntries()[index] : null;
            }
            else if (preference is RingtonePreference)
            {
                // For ringtone preferences, look up the correct display value
                // using RingtoneManager.
                if (TextUtils.IsEmpty(stringValue))
                {
                    // Empty values correspond to 'silent' (no ringtone).
                    preference.Summary = Application.Context.Resources.GetString(Resource.String.pref_group_ringtone_silent);
                }
                else
                {
                    Ringtone ringtone = RingtoneManager.GetRingtone(preference.Context, Android.Net.Uri.Parse(stringValue));

                    if (ringtone == null)
                    {
                        // Clear the summary if there was a lookup error.
                        preference.Summary = null;
                    }
                    else
                    {
                        // Set the summary to reflect the new ringtone display
                        // name.
                        preference.Summary = ringtone.GetTitle(preference.Context);
                    }
                }
            }
            else
            {
                // For all other preferences, set the summary to the value's
                // simple string representation.
                preference.Summary = stringValue;
            }
            return(true);
        }
Exemple #4
0
        public bool OnPreferenceChange(Preference preference, Java.Lang.Object newValue)
        {
            string stringValue = newValue.ToString();

            if (Utils.ObjectUtility.CheckInherit(preference.GetType(), typeof(ListPreference)))
            {
                ListPreference listPreference = (ListPreference)preference;
                int            index          = listPreference.FindIndexOfValue(stringValue);

                // Set the summary to reflect the new value.
                preference.Summary = index >= 0 ? listPreference.GetEntries()[index] : null;
            }
            else if (Utils.ObjectUtility.CheckInherit(preference.GetType(), typeof(RingtonePreference)))
            {
                if (Android.Text.TextUtils.IsEmpty(stringValue))
                {
                    // Empty values correspond to 'silent' (no ringtone).
                    preference.SetSummary(Resource.String.pref_ringtone_silent);
                }
                else
                {
                    Ringtone ringtone = RingtoneManager.GetRingtone(preference.Context, Android.Net.Uri.Parse(stringValue));

                    if (ringtone == null)
                    {
                        // Clear the summary if there was a lookup error.
                        preference.Summary = null;
                    }
                    else
                    {
                        // Set the summary to reflect the new ringtone display name.
                        string name = ringtone.GetTitle(preference.Context);
                        preference.Summary = name;
                    }
                }
            }
            else
            {
                preference.Summary = stringValue;
            }

            return(true);
        }