예제 #1
0
    bool RatingConditionsHaveBeenMet()
    {
        //if (settings.Debug)
        //	return true;

        NSUserDefaults userDefaults         = NSUserDefaults.StandardUserDefaults;
        DateTime       dateOfFirstLaunch    = DateTime.FromOADate(userDefaults.DoubleForKey(FIRST_USE_DATE));
        TimeSpan       timeSinceFirstLaunch = DateTime.Now.Subtract(dateOfFirstLaunch);
        TimeSpan       timeUntilRate        = new TimeSpan(settings.DaysUntilPrompt, 0, 0, 0);

        if (timeSinceFirstLaunch < timeUntilRate)
        {
            return(false);
        }

        // check if the app has been used enough
        int useCount = userDefaults.IntForKey(USE_COUNT);

        if (useCount < settings.UsesUntiPrompt)
        {
            return(false);
        }

        // check if the user has done enough significant events
        int sigEventCount = userDefaults.IntForKey(SIGNIFICANT_EVENT_COUNT);

        if (sigEventCount < settings.SigEventsUntilPrompt)
        {
            return(false);
        }

        // has the user previously declined to rate this version of the app?
        if (userDefaults.BoolForKey(DECLINED_TO_RATE))
        {
            return(false);
        }

        // has the user already rated the app?
        if (userDefaults.BoolForKey(RATED_CURRENT_VERSION))
        {
            return(false);
        }

        // if the user wanted to be reminded later, has enough time passed?
        DateTime reminderRequestDate      = DateTime.FromOADate(userDefaults.DoubleForKey(REMINDER_REQUEST_DATE));
        TimeSpan timeSinceReminderRequest = DateTime.Now.Subtract(reminderRequestDate);
        TimeSpan timeUntilReminder        = new TimeSpan(settings.TimeBeforeReminding, 0, 0, 0);

        if (timeSinceReminderRequest < timeUntilReminder)
        {
            return(false);
        }

        return(true);
    }
예제 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            View.BackgroundColor = UIColor.Clear;
            var NMode = userDefault.BoolForKey("NM");

            Console.WriteLine((NMode));

            Slider.ValueChanged    += Slider_ValueChanged;
            btnCalcu.TouchUpInside += BtnCalcu_TouchUpInside;
        }
예제 #3
0
        public override void WillActivate()
        {
            // This method is called when the watch view controller is about to be visible to the user.
            Console.WriteLine("{0} will activate", this);

            NSUserDefaults shared    = new NSUserDefaults();
            var            isEnabled = shared.BoolForKey("enabled_preference");
            var            name      = shared.StringForKey("name_preference");

            Console.WriteLine("Enabled: " + isEnabled);
            Console.WriteLine("Name: " + name);

            // reload each view
            data = Database.GetItems().ToList();


            // HACK: the recommendation is to use Insert and Remove rows
            // becaues if you reload the entire table, all the data is
            // re-sent from the extension to the watch
            TodoTable.SetNumberOfRows((nint)data.Count, "todoRow");
            for (var i = 0; i < data.Count; i++)
            {
                var elementRow = (TodoRowController)TodoTable.GetRowController(i);
                elementRow.Set(data [i].Name, data [i].Done);
            }
        }
예제 #4
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);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            View.BackgroundColor = UIColor.Clear;
            var isNightMode = userDefaults.BoolForKey("night-mode");

            Console.WriteLine(isNightMode);

            sldshido.ValueChanged         += SldCalc_ValueChanged;
            sldshido.MinimumTrackTintColor = UIColor.DarkGray;
            sldshido.MaximumTrackTintColor = UIColor.DarkGray;

            btnCalc.TouchUpInside += BtnCalc_TouchUpInside;
        }
예제 #6
0
        /// <summary>
        /// Called when a file transfer is done.
        /// </summary>
        public override void DidFinishFileTransfer(WCSession session, WatchConnectivity.WCSessionFileTransfer fileTransfer, NSError error)
        {
            var commandStatus = new CommandStatus(Command.TransferFile, Phrase.Finished);

            if (error != null)
            {
                commandStatus.ErrorMessage = error.LocalizedDescription;
                this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
            }
            else
            {
                commandStatus.FileTransfer = fileTransfer;
                commandStatus.TimedColor   = new TimedColor(fileTransfer.File.Metadata);

#if __WATCHOS__
                if (!string.IsNullOrEmpty(WatchSettings.SharedContainerId))
                {
                    var defaults = new NSUserDefaults(WatchSettings.SharedContainerId, NSUserDefaultsType.SuiteName);
                    if (defaults.BoolForKey(WatchSettings.ClearLogsAfterTransferred))
                    {
                        Logger.Shared.ClearLogs();
                    }
                }
#endif
                this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
            }
        }
예제 #7
0
        private void InitView()
        {
            var arr      = NSBundle.MainBundle.LoadNib(nameof(SettingsView), this, null);
            var rootView = ObjCRuntime.Runtime.GetNSObject(arr.ValueAt(0)) as SettingsView;

            UsePinSwitchCell = rootView?.usePinSwitchCell;

            NSUserDefaults preferences = NSUserDefaults.StandardUserDefaults;

            UsePinSwitchCell.On = preferences.BoolForKey(ConstantsHelper.UsePinKey);

            PinEntry = rootView?.pinEntry;

            PinEntry.KeyboardType = UIKeyboardType.NumberPad;
            int pinEntryMaxLength = 4;

            PinEntry.ShouldChangeCharacters = (field, range, replacementString) =>
            {
                var newContent = new NSString(field.Text).Replace(range, new NSString(replacementString)).ToString();
                return(newContent.Length <= pinEntryMaxLength && (replacementString.Length == 0 || int.TryParse(replacementString, out var number)));
            };

            SaveButton        = rootView?.saveButton;
            SaveButton.Hidden = true;

            SubscribeOnEvents();
            AddSubview(rootView);
            this.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
            this.AddConstraints(
                rootView.WithSameTop(this),
                rootView.WithSameBottom(this),
                rootView.WithSameLeft(this),
                rootView.WithSameRight(this));
        }
예제 #8
0
        private bool SelectCropArea()
        {
            bool smartCrop = ProcessCrop(this.inImage, out points);

            NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

            bool b = defaults.BoolForKey("cropState");

            if (b && smartCrop)
            {
                Process();
            }
            else
            {
                CGPoint[] cg_points = points.ToCGPointRect();

                PageEditorController pageEditor = new PageEditorController(this.inImage.Image, cg_points);
                pageEditor.Delegate = this;
                pageEditor.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;

                this.PresentViewController(pageEditor, false, null);
            }

            return(smartCrop);
        }
예제 #9
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);
        }
예제 #10
0
        private void RefreshFields()
        {
            NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

            HumiditySwitch.On = defaults.BoolForKey(Constants.HUMID_SWITCH_KEY);
            if (HumiditySwitch.On)
            {
                HumidityField.Enabled = true;
                HumidityField.Text    = defaults.StringForKey(Constants.HUMID_PERCENT_KEY);
            }

            WindSlider.Value    = defaults.IntForKey(Constants.WIND_SPEED_KEY);
            WindSpeedLabel.Text = Metric ? $"Wind Speed (0-100 kph) {WindSlider.Value}" :
                                  $"Wind Speed (0-100 mph) {WindSlider.Value}";
            Metric = defaults.StringForKey(Constants.MEASUREMENT_KEY) == "Metric";
            string bgColor = defaults.StringForKey(Constants.BACKGROUND_KEY);

            switch (bgColor)
            {
            case "White":
                View.BackgroundColor = UIColor.White;
                break;

            case "Green":
                View.BackgroundColor = UIColor.Green;
                break;

            case "Blue":
                View.BackgroundColor = UIColor.Blue;
                break;
            }
            compute(null, null);
        }
예제 #11
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);
 }
예제 #12
0
 public bool GetBool(string ToGet, bool Default)
 {
     try
     {
         return(userSettings.BoolForKey(ToGet));
     }
     catch { return(Default); }
 }
예제 #13
0
 public static bool BoolForKey(this NSUserDefaults defaults, bool defaultValue, string key)
 {
     if (defaults.ValueForKey(new NSString(key)) == null)
     {
         return(defaultValue);
     }
     return(defaults.BoolForKey(key));
 }
예제 #14
0
 private bool LoadCheckbox(NSButton box)
 {
     if (!defaults.BoolForKey(box.Title))
     {
         return(false);
     }
     box.State = NSCellStateValue.On;
     return(true);
 }
예제 #15
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"));
 }
예제 #16
0
 private UserModel ReadUserFromPreferences(NSUserDefaults preferences)
 {
     return(new UserModel
     {
         Email = preferences.StringForKey("user_email"),
         IsLogged = preferences.BoolForKey("is_logged"),
         PhotoUrl = preferences.StringForKey("user_photo_url"),
         UserId = (int)preferences.IntForKey("user_user_id"),
         Username = preferences.StringForKey("user_username")
     });
 }
예제 #17
0
        public bool TryGet(string key, out bool value)
        {
            if (Defaults[key] == null)
            {
                value = default(bool);
                return(false);
            }

            value = Defaults.BoolForKey(key);
            return(true);
        }
        public void UpdateLabelText()
        {
            NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

            nint tag = this.Tag;

            UISwitch cell = this.SwitchCell;

            UILabel label = this.CellNameLabel;

            if (tag == 100)
            {
                label.Text = "Smart crop";

                cell.On = defaults.BoolForKey("cropState");
            }
            else if (tag == 101)
            {
                label.Text = "Crop mode";

                cell.On = defaults.BoolForKey("cropMode");
            }
            else if (tag == 102)
            {
                label.Text = "Document borders detector";

                cell.On = defaults.BoolForKey("borderDetector");
            }
            else if (tag == 103)
            {
                label.Text = "AutoShot";

                cell.On = defaults.BoolForKey("autoShot");
            }
            else if (tag == 104)
            {
                label.Text = "Simulate multi-page file";

                cell.On = defaults.BoolForKey("simulateMultipageFile");
            }
        }
예제 #19
0
        partial void UIButton12_TouchUpInside(UIButton sender)
        {
            //Store value on Userdefaults
            storevalues.SetString(txtString.Text, "stringvalue");
            storevalues.SetInt(Int32.Parse(txtInteger.Text), "integervalue");

            //Get values form Userdefaults

            lblString.Text  = storevalues.StringForKey("stringvalue");
            lblInteger.Text = storevalues.IntForKey("integervalue").ToString();
            lblBoolean.Text = storevalues.BoolForKey("swithvalue").ToString();;
        }
예제 #20
0
        static public bool GetBoolSetting(string name, bool defValue = false)
        {
            var isSet = g_prefs[name];

            if (isSet == null)
            {
                return(defValue);
            }
            bool res = g_prefs.BoolForKey(name);

            return(res);
        }
예제 #21
0
        static bool ShowDeviceBezels(InspectableWindow window)
        {
            var simDefaults = new NSUserDefaults(
                "com.apple.iphonesimulator",
                NSUserDefaultsType.SuiteName);

            const string ShowChromeSetting = "ShowChrome";

            return(simDefaults.ValueForKey(new NSString(ShowChromeSetting)) == null
                ? true
                : simDefaults.BoolForKey(ShowChromeSetting));
        }
예제 #22
0
        public bool GetBool(string key)
        {
            try
            {
                return(_defaults.BoolForKey(key));
            }
            catch (Exception e)
            {
                Logger.Error($"Error Getting Bool UserSetting {key} - {e.Message}", e);
            }

            return(false);
        }
        public void Logout()
        {
            NSUserDefaults preferences = NSUserDefaults.StandardUserDefaults;
            var            usePin      = preferences.BoolForKey(ConstantsHelper.UsePinKey);

            var window = UIApplication.SharedApplication.KeyWindow;

            UIViewController rootViewController = usePin ? new PinViewController()
                : (UIViewController) new LoginViewController();

            window.RootViewController = new UINavigationController(rootViewController);
            Helpers.Settings.AppUser  = string.Empty;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            Title = "WatchTodo";
            // Perform any additional setup after loading the view, typically from a nib.

            NSUserDefaults shared = new NSUserDefaults(
                "group.co.conceptdev.WatchTodo", NSUserDefaultsType.SuiteName);
            var isEnabled = shared.BoolForKey ("enabled_preference");
            var name = shared.StringForKey ("name_preference");
            Console.WriteLine ("Enabled: " + isEnabled);
            Console.WriteLine ("Name: " + name);
            //Title = name; // for testing
        }
예제 #25
0
 bool IsInitialized()
 {
     try
     {
         var settings = new NSUserDefaults($"group.{AboutThisApp.PackageName}", NSUserDefaultsType.SuiteName);
         settings.Synchronize();
         return(settings.BoolForKey("FavoritesInitialized"));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(false);
     }
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title = "WatchTodo";
            // Perform any additional setup after loading the view, typically from a nib.

            NSUserDefaults shared = new NSUserDefaults(
                "group.com.conceptdevelopment.WatchTodo", NSUserDefaultsType.SuiteName);
            var isEnabled = shared.BoolForKey("enabled_preference");
            var name      = shared.StringForKey("name_preference");

            Console.WriteLine("Enabled: " + isEnabled);
            Console.WriteLine("Name: " + name);
            //Title = name; // for testing
        }
예제 #27
0
        public void RunHandlerOnFirstLaunch(Action firstLaunchHandler)
        {
            NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

            defaults.RegisterDefaults(new NSMutableDictionary {
                { (NSString)FirstLaunchUserDefaultsKey, NSObject.FromObject(true) },
                { (NSString)StorageOptionUserDefaultsKey, NSObject.FromObject(StorageType.NotSet) }
            });

            if (defaults.BoolForKey(FirstLaunchUserDefaultsKey))
            {
                defaults.SetBool(false, FirstLaunchUserDefaultsKey);
                firstLaunchHandler();
            }
        }
 public T Get <T>(string key)
 {
     if (typeof(T) == typeof(int))
     {
         return((T)(object)Defaults.IntForKey(key));
     }
     if (typeof(T) == typeof(bool))
     {
         return((T)(object)Defaults.BoolForKey(key));
     }
     if (typeof(T) == typeof(string))
     {
         return((T)(object)Defaults.StringForKey(key));
     }
     throw new Exception("Key does not exist in Default database.");
 }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            NSUserDefaults preferences = NSUserDefaults.StandardUserDefaults;
            var            usePin      = preferences.BoolForKey(ConstantsHelper.UsePinKey);

            UIViewController rootViewController = usePin ? new PinViewController()
                : (UIViewController) new LoginViewController();

            Window.RootViewController = new UINavigationController(rootViewController);

            Window.MakeKeyAndVisible();
            return(true);
        }
예제 #30
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            UpdateSessionsSource();
            TabBarController.Title        = StringResources.sessions_ui_title;
            SessionsInstructions.Text     = StringResources.sessions_ui_header_instructions;
            SessionsInstructionsBody.Text = StringResources.sessions_ui_body_instructions;

            NSUserDefaults prefs = NSUserDefaults.StandardUserDefaults;

            if (prefs.BoolForKey("SESSION_RECORDED"))
            {
                prefs.SetBool(false, "SESSION_RECORDED");

                // Get epoch time
                TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
                int      secondsSinceEpoch = (int)t.TotalSeconds;

                Analytics.SetUserProperty(
                    "lastUploadAdded",
                    secondsSinceEpoch.ToString());

                var currentConnections = CrossConnectivity.Current.ConnectionTypes;
                if (!currentConnections.Contains(Plugin.Connectivity.Abstractions.ConnectionType.WiFi))
                {
                    var alertController = UIAlertController.Create(StringResources.sessions_ui_wifiwarning_title,
                                                                   StringResources.sessions_ui_wifiwarning_message,
                                                                   UIAlertControllerStyle.Alert);
                    alertController.AddAction(UIAlertAction.Create(StringResources.sessions_ui_wifiwarning_cancel,
                                                                   UIAlertActionStyle.Cancel, (obj) => { }));
                    alertController.AddAction(UIAlertAction.Create(StringResources.sessions_ui_wifiwarning_confirm,
                                                                   UIAlertActionStyle.Default, (obj) =>
                    {
                        UploadIfNot(0, true);
                    }));

                    PresentViewController(alertController, true, null);
                }
                else
                {
                    UploadIfNot(0, true);
                }
            }
        }
예제 #31
0
        SortedSet <CountriesEnum> GetCountriesFromSettings(NSUserDefaults settings)
        {
            var countries = new SortedSet <CountriesEnum> ();

            var possibleCountires = new List <string>()
            {
                "HU", "SW", "SE", "FL", "CZ"
            };


            foreach (var c in possibleCountires)
            {
                if (settings.BoolForKey(c))
                {
                    countries.Add(c.ToEnum <CountriesEnum>());
                }
            }


            return(countries);
        }
        public override void WillActivate()
        {
            // This method is called when the watch view controller is about to be visible to the user.
            Console.WriteLine ("{0} will activate", this);

            NSUserDefaults shared = new NSUserDefaults ();
            var isEnabled = shared.BoolForKey ("enabled_preference");
            var name = shared.StringForKey ("name_preference");
            Console.WriteLine ("Enabled: " + isEnabled);
            Console.WriteLine ("Name: " + name);

            // reload each view
            data = Database.GetItems ().ToList();

            // HACK: the recommendation is to use Insert and Remove rows
            // becaues if you reload the entire table, all the data is
            // re-sent from the extension to the watch
            TodoTable.SetNumberOfRows ((nint)data.Count, "todoRow");
            for (var i = 0; i < data.Count; i++) {
                var elementRow = (TodoRowController)TodoTable.GetRowController (i);
                elementRow.Set(data [i].Name, data [i].Done);
            }
        }
		void SetElementValueFromDefaults(CheckboxElement e, NSUserDefaults defs, string key, bool defaultVal)
		{
			var value = defs.DataForKey (key);
			if (value == null)
				e.Value = defaultVal;
			else
				e.Value = defs.BoolForKey(key);
		}