/// <summary>
        /// Creates the text encoding preference.
        /// </summary>
        private void CreateTextEncodingPreference()
        {
            // clear information about text encodings
            _encodingEntries.Clear();
            _encodingEntryValues.Clear();

            // get the preference for text encoding list
            _textEncodingListPreference = FindPreference("list_encodings") as Android.Support.V7.Preferences.ListPreference;
            // if text encoding list preference is found
            if (_textEncodingListPreference != null)
            {
                // add "Default" value to the text encoding
                _encodingEntries.AddRange(_textEncodingListPreference.GetEntries());
                _encodingEntryValues.AddRange(_textEncodingListPreference.GetEntryValues());

                // for each available encoding
                foreach (KeyValuePair <string, EncodingInfo> encoding in Utils.AvailableEncodings)
                {
                    // add encoding name to the encoding list
                    _encodingEntries.Add(string.Format("{0}: {1}", encoding.Value.CodePage, encoding.Value.Name));
                    _encodingEntryValues.Add(encoding.Key);
                }

                // add information about available text encodings to the list preference with text encodings
                _textEncodingListPreference.SetEntries(_encodingEntries.ToArray());
                _textEncodingListPreference.SetEntryValues(_encodingEntryValues.ToArray());
            }
        }
        /// <summary>
        /// Refreshes the preference fragment view.
        /// </summary>
        private void RefreshUI()
        {
            base.PreferenceScreen.RemoveAll();

            AddPreferencesFromResource(Resource.Xml.settings_page);

            // get the preference for camera preview sizes list
            _cameraPreviewSizesListPreference = FindPreference("list_camera_preview_sizes") as Android.Support.V7.Preferences.ListPreference;
            // if camera preview size list preference is found
            if (_cameraPreviewSizesListPreference != null)
            {
                // add the camera preview sizes to the list preference with camera preview sizes
                _cameraPreviewSizesListPreference.SetEntries(_sizeEntries.ToArray());
                _cameraPreviewSizesListPreference.SetEntryValues(_sizeEntryValues.ToArray());
                // set the "Auto" value as the default value
                _cameraPreviewSizesListPreference.SetValueIndex(0);
            }

            // get the preference for text encoding list
            _textEncodingListPreference = FindPreference("list_encodings") as Android.Support.V7.Preferences.ListPreference;

            // if text encoding list preference is found
            if (_textEncodingListPreference != null)
            {
                // add the encoding to the list preference with text encodings
                _textEncodingListPreference.SetEntries(_encodingEntries.ToArray());
                _textEncodingListPreference.SetEntryValues(_encodingEntryValues.ToArray());
                // set the "Default" value as the default value
                _textEncodingListPreference.SetValueIndex(0);
            }
        }
        public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey)
        {
            // TODO: ugh, this is crashing again
            AddPreferencesFromResource(Resource.Xml.settings);

// TODO: remove any of these that are unused

            _personalInformationCategory = (Android.Support.V7.Preferences.PreferenceCategory)FindPreference(PersonalInformation.PreferenceKey);
            _namePreference = (Android.Support.V7.Preferences.EditTextPreference)FindPreference(PersonalInformation.NamePreferenceKey);

            _birthDatePreference = (Android.Support.V7.Preferences.EditTextPreference)FindPreference(PersonalInformation.DateOfBirthPreferenceKey);
            _birthDatePreference.PreferenceClick += (sender, args) => {
                DateTime dateTime = DateTime.Now;
                try {
                    dateTime = Convert.ToDateTime(_birthDatePreference.Text);
                } catch(FormatException) {
                }

                DatePickerFragment picker = new DatePickerFragment(dateTime);
                picker.DateSetEvent += (s, a) => {
                    _birthDatePreference.Text = a.Date.ToString("yyyy-MM-dd", CultureInfo.CurrentCulture);
                };
                picker.Show(Activity.SupportFragmentManager, null);
            };

            _userSexPreference = (Android.Support.V7.Preferences.ListPreference)FindPreference(PersonalInformation.UserSexPreferenceKey);
            _heightPreference = (Android.Support.V7.Preferences.EditTextPreference)FindPreference(PersonalInformation.HeightPreferenceKey);
            _weightPreference = (Android.Support.V7.Preferences.EditTextPreference)FindPreference(PersonalInformation.WeightPreferenceKey);

            _unitsCategory = (Android.Support.V7.Preferences.PreferenceCategory)FindPreference(BackpackPlannerSettings.UnitsPreferenceKey);
            _unitSystemPreference = (Android.Support.V7.Preferences.ListPreference)FindPreference(BackpackPlannerSettings.UnitSystemPreferenceKey);
            _currencyPreference = (Android.Support.V7.Preferences.ListPreference)FindPreference(BackpackPlannerSettings.CurrencyPreferenceKey);

#if !DEBUG
            PreferenceScreen.RemovePreference(_personalInformationCategory);
            _unitsCategory.RemovePreference(_currencyPreference);
#endif

            UpdateLabels();
            UpdateSummaries();

            Activity.Title = Resources.GetString(Resource.String.title_settings);
        }
        /// <summary>
        /// Creates the camera preview size preference.
        /// </summary>
        private void CreateCameraPreviewSizePreference()
        {
            // clear information about camera preview sizes
            _sizeEntries.Clear();
            _sizeEntryValues.Clear();

            // get the preference for camera preview sizes list
            _cameraPreviewSizesListPreference = FindPreference("list_camera_preview_sizes") as Android.Support.V7.Preferences.ListPreference;
            // if camera preview size list preference is found
            if (_cameraPreviewSizesListPreference != null)
            {
                // add "Auto" value to the camera preview sizes
                _sizeEntries.AddRange(_cameraPreviewSizesListPreference.GetEntries());
                _sizeEntryValues.AddRange(_cameraPreviewSizesListPreference.GetEntryValues());

                // if camera controller is not emtpy and camera preview size list is not empty
                if (CameraController != null && CameraController.CameraPreviewSizes != null)
                {
                    int sizeIndex = 0;
                    // for each camera preview size
                    foreach (Camera.Size size in CameraController.CameraPreviewSizes)
                    {
                        // add camera preview size to the camera preview sizes
                        _sizeEntries.Add(string.Format("{0}x{1}", size.Width, size.Height));
                        _sizeEntryValues.Add(sizeIndex.ToString());
                        sizeIndex++;
                    }
                }

                // add the camera preview sizes to the list preference with camera preview sizes
                _cameraPreviewSizesListPreference.SetEntries(_sizeEntries.ToArray());
                _cameraPreviewSizesListPreference.SetEntryValues(_sizeEntryValues.ToArray());

                // if camera preview size is not selected
                if (CameraController.СameraPreviewSize == null)
                {
                    // set the "Auto" value as the default value
                    _cameraPreviewSizesListPreference.SetValueIndex(0);
                }
            }
        }
Esempio n. 5
0
 public static string BindValue(this Android.Support.V7.Preferences.ListPreference listPreference)
 => MvxPreferencePropertyBinding.ListPreference_Value;