예제 #1
0
        public object GetValue(Type valueType, string key)
        {
            object value = null;

            if (valueType == typeof(string))
            {
                value = UserDefaults.StringForKey(key);
            }
            else if (valueType == typeof(int))
            {
                value = UserDefaults.IntForKey(key);
            }
            else if (valueType == typeof(bool))
            {
                value = UserDefaults.BoolForKey(key);
            }
            else if (valueType == typeof(float))
            {
                value = UserDefaults.FloatForKey(key);
            }
            else if (valueType == typeof(double))
            {
                value = UserDefaults.DoubleForKey(key);
            }
            else if (valueType == typeof(long))
            {
                value = (long)((NSNumber)UserDefaults.ValueForKey(new NSString(key)));
            }
            else
            {
                Log.Error(INCORRECT_VALUE_TYPE_ERROR);
            }

            return(value);
        }
예제 #2
0
 internal void ReloadAppSettings()
 {
     _settings.API_Key     = _defaults.StringForKey(DefaultKeys.API_KEY);
     _settings.API_Secret  = _defaults.StringForKey(DefaultKeys.API_SECRET);
     _settings.RefreshRate = _defaults.FloatForKey(DefaultKeys.REFRESH_RATE);
     _settings.AutoStart   = _defaults.BoolForKey(DefaultKeys.AUTO_START);
 }
예제 #3
0
        private T Get <T>(string key, NSUserDefaults defaults)
        {
            object result;

            switch (Type.GetTypeCode(typeof(T)))
            {
            case TypeCode.Boolean:
                result = (bool)defaults.BoolForKey(key);
                break;

            case TypeCode.Int32:
                result = (int)defaults.IntForKey(key);
                break;

            case TypeCode.Single:
                result = (float)defaults.FloatForKey(key);
                break;

            case TypeCode.String:
                result = (string)defaults.StringForKey(key);
                break;

            default:
                throw new NotSupportedException($"{typeof(T)} is not supported.");
            }

            return((T)result);
        }
예제 #4
0
 public static float FloatForKey(this NSUserDefaults defaults, float defaultValue, string key)
 {
     if (defaults.ValueForKey(new NSString(key)) == null)
     {
         return(defaultValue);
     }
     return(defaults.FloatForKey(key));
 }
예제 #5
0
 void LePreferencias()
 {
     txtNome.Text = prefs.StringForKey("user");
     boolSwitch.SetState(prefs.BoolForKey("habilitado"), true);
     floatSlider.Value = prefs.FloatForKey("slider");
     lblInt.Text       = prefs.IntForKey("int").ToString();
     intStepper.Value  = prefs.IntForKey("int");
     dtPicker.Date     = NSDate.FromTimeIntervalSince1970(prefs.DoubleForKey("data"));
 }
예제 #6
0
        static public float GetFloatSetting(string name, float defValue = 0)
        {
            float res = g_prefs.FloatForKey(name);

            if (res == 0.0 && defValue != 0.0)
            {
                res = defValue;
            }
            return(res);
        }
예제 #7
0
        public float GetFloat(string key)
        {
            try
            {
                return(_defaults.FloatForKey(key));
            }
            catch (Exception e)
            {
                Logger.Error($"Error Getting Float UserSetting {key} - {e.Message}", e);
            }

            return(0);
        }
예제 #8
0
        private void RefreshFields()
        {
            NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

            ServiceSlider.Value    = defaults.FloatForKey(Constants.TIPPERCENTAGE_KEY);
            TaxPercentageText.Text = defaults.StringForKey(Constants.TAXPERCENTAGE_KEY);
            tipCalc.currencyType   = defaults.StringForKey(Constants.CURRENCYTYPE_KEY);
            UIColor color       = UIColor.White;
            string  colorString = defaults.StringForKey(Constants.BACKGROUNDCOLOR_KEY);

            if (colorString == "White")
            {
                color = UIColor.White;
            }
            else if (colorString == "Green")
            {
                color = UIColor.Green;
            }
            else
            {
                color = UIColor.Blue;
            }
            this.View.BackgroundColor = color;
        }
예제 #9
0
 /// <inheritdoc />
 public float GetFloat(string key, float defaultValue)
 {
     return(_standardDefaults.FloatForKey(defaultValue, key));
 }