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")); }
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); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. standardUserDefaults = NSUserDefaults.StandardUserDefaults; selectedType = (VisionType)(int)standardUserDefaults.IntForKey(nameof(VisionType)); selectedScript = (TextRecognitionScript)(int)standardUserDefaults.IntForKey(nameof(TextRecognitionScript)); SettingsTable.ReloadSections(NSIndexSet.FromNSRange(new NSRange(0, 2)), UITableViewRowAnimation.Automatic); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. standardUserDefaults = NSUserDefaults.StandardUserDefaults; selectedApiResource = (ApiResource)(int)standardUserDefaults.IntForKey(Constants.SelectedApiResource); selectedModelIndex = standardUserDefaults.IntForKey(Constants.SelectedModel); SgmApi.SelectedSegment = (int)selectedApiResource; SgmApi.ValueChanged += SgmApi_ValueChanged; }
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 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); }
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); }
public int PublicationDownloadingProgress() { NSUserDefaults userDefault = NSUserDefaults.StandardUserDefaults; nint value = userDefault.IntForKey(BookTitle); return(Convert.ToInt32(value)); }
public static int IntForKey(this NSUserDefaults defaults, int defaultValue, string key) { if (defaults.ValueForKey(new NSString(key)) == null) { return(defaultValue); } return((int)defaults.IntForKey(key)); }
public override void ViewDidLoad() { base.ViewDidLoad(); SetButtonsActive(App.Document != null); var userDefaults = new NSUserDefaults(); var value = userDefaults.IntForKey("CensusProvider"); CensusSearchProviderOutlet.SelectItem(value); }
static public int GetIntSetting(string name, int defValue = 0) { int res = (int)g_prefs.IntForKey(name); if (res == 0 && defValue != 0) { res = defValue; } return(res); }
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") }); }
public void WidgetPerformUpdate(Action <NCUpdateResult> completionHandler) { // Perform any setup necessary in order to update the view. // If an error is encoutered, use NCUpdateResultFailed // If there's no update required, use NCUpdateResultNoData // If there's an update, use NCUpdateResultNewData var shared = new NSUserDefaults( "se.tinystuff.TinyShopping.shared", NSUserDefaultsType.SuiteName); //shared.Synchronize(); var total = shared.IntForKey("total"); var done = shared.IntForKey("done"); lblSummary.Text = $"{done} / {total} items is done"; completionHandler(NCUpdateResult.NewData); }
private async Task CreateNewRemoteController(NSUserDefaults defaults) { var host = defaults.StringForKey("remote_device_host_preference"); var port = defaults.IntForKey("remote_device_port_preference"); if (!string.IsNullOrEmpty(host) && port > 0) { remoteController = new LightsRemoteController(); await remoteController.ConnectAsync(host, (int)port); } }
public bool TryGet(string key, out int value) { if (Defaults[key] == null) { value = default(int); return(false); } value = (int)Defaults.IntForKey(key); return(true); }
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();; }
public int Get(string key, int defaultValue) { nint value = nsUserDefaults.IntForKey(new NSString(key)); if (value != 0) { return((int)value); } else { return(defaultValue); } }
public int GetInt(string key) { try { return((int)_defaults.IntForKey(key)); } catch (Exception e) { Logger.Error($"Error Getting Int UserSetting {key} - {e.Message}", e); } return(0); }
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) { base.PrepareForSegue(segue, sender); //Performance update, passes the already downloaded images to the next viewcontroller if (segue.Identifier == "gameDetailSegue" && selectedGame != null) { var gameDetailController = (GameDetailViewController)segue.DestinationViewController; gameDetailController.game = this.selectedGame; var id = plist.IntForKey("userId"); gameDetailController.isOwnerOfTheGame = selectedGame.owner.id == id; gameDetailController.team1Player1Image = imgTeam1Player1; gameDetailController.team1Player2Image = imgTeam1Player2; gameDetailController.team2Player1Image = imgTeam2Player1; gameDetailController.team2Player2Image = imgTeam2Player2; } }
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."); }
void IncrementSignificantEventCount() { // get the app's version string version = CurrentVersion; // get the version number that we've been tracking NSUserDefaults userDefaults = NSUserDefaults.StandardUserDefaults; string trackingVersion = userDefaults.StringForKey(CURRENT_VERSION); if (string.IsNullOrEmpty(trackingVersion)) { trackingVersion = version; userDefaults.SetString(version, CURRENT_VERSION); } if (settings.Debug) { Debug.WriteLine("APPIRATER Tracking version: {0}", trackingVersion); } if (trackingVersion == version) { // check if the first use date has been set. if not, set it. double timeInterval = userDefaults.DoubleForKey(FIRST_USE_DATE); if (timeInterval == 0) { timeInterval = DateTime.Now.ToOADate(); userDefaults.SetDouble(timeInterval, FIRST_USE_DATE); } // increment the significant event count int sigEventCount = userDefaults.IntForKey(SIGNIFICANT_EVENT_COUNT); sigEventCount++; userDefaults.SetInt(sigEventCount, SIGNIFICANT_EVENT_COUNT); if (settings.Debug) { Debug.WriteLine("APPIRATER Significant event count: {0}", sigEventCount); } } else { Restart(); } userDefaults.Synchronize(); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear (animated); NSUserDefaults shared = new NSUserDefaults("group.com.conceptdevelopment.TodoToday", NSUserDefaultsType.SuiteName); var count = shared.IntForKey ("TodoCount"); Console.WriteLine ("Read NSUserDefaults TodoCount: " + count); if (count == 0) { todoLabel.Text = "nothing to do"; } else if (count == 1) { todoLabel.Text = "one thing to do"; } else { todoLabel.Text = String.Format("{0} things to do", count); } // textToSpeak = todoLabel.Text; }
public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action <UNNotificationContent> contentHandler) { ContentHandler = contentHandler; BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy(); // Modify the notification content here... var plist = new NSUserDefaults("group.com.libin.sharing", NSUserDefaultsType.SuiteName); nint badgeCount = plist.IntForKey("BadgeCount"); badgeCount++; var newAlertContent = new UNMutableNotificationContent { Body = BestAttemptContent.Body, Title = BestAttemptContent.Title, Sound = BestAttemptContent.Sound, Badge = new NSNumber(badgeCount) }; plist.SetInt(badgeCount, "BadgeCount"); ContentHandler(newAlertContent); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); NSUserDefaults shared = new NSUserDefaults("group.co.conceptdev.TodoToday", NSUserDefaultsType.SuiteName); var count = shared.IntForKey("TodoCount"); Console.WriteLine("Read NSUserDefaults TodoCount: " + count); if (count == 0) { todoLabel.Text = "nothing to do"; } else if (count == 1) { todoLabel.Text = "one thing to do"; } else { todoLabel.Text = String.Format("{0} things to do", count); } // textToSpeak = todoLabel.Text; }
/// <inheritdoc /> public int GetInt(string key, int defaultValue) { return(_standardDefaults.IntForKey(defaultValue, key)); }
async Task ReportScore() { string leaderboardIdentifier = null; string gameTypeString = null; GameTypePlayed gameType = GameTypePlayed.Invalid; if (GameInfo.GameTime == GameTime.Fifteen) { if (GameInfo.GameMode == GameMode.Easy) { gameTypeString = "15secondseasymode"; gameType = GameTypePlayed.Easy15; } else if (GameInfo.GameMode == GameMode.Hard) { gameTypeString = "15secondshardmode"; gameType = GameTypePlayed.Hard15; } } else if (GameInfo.GameTime == GameTime.Thirty) { if (GameInfo.GameMode == GameMode.Easy) { gameTypeString = "30secondseasymode"; gameType = GameTypePlayed.Easy30; } else if (GameInfo.GameMode == GameMode.Hard) { gameTypeString = "30secondshardmode"; gameType = GameTypePlayed.Hard30; } } else if (GameInfo.GameTime == GameTime.FourtyFive) { if (GameInfo.GameMode == GameMode.Easy) { gameTypeString = "45secondseasymode"; gameType = GameTypePlayed.Easy45; } else if (GameInfo.GameMode == GameMode.Hard) { gameTypeString = "45secondshardmode"; gameType = GameTypePlayed.Hard45; } } if (gameTypeString != null) { leaderboardIdentifier = Prefix + gameTypeString; } if (leaderboardIdentifier != null) { GKScore score = new GKScore(leaderboardIdentifier) { Value = GameInfo.CurrentTaps, Context = 0 }; var challenges = GameInfo.Challenge == null ? null : new [] { GameInfo.Challenge }; await GKScore.ReportScoresAsync(new [] { score }, challenges); } if (GKLocalPlayer.LocalPlayer.Authenticated) { if (GameInfo.GameMode == GameMode.Hard) { var playhard = new GKAchievement(PlayHardId, GKLocalPlayer.LocalPlayer.PlayerID) { PercentComplete = 100 }; await GKAchievement.ReportAchievementsAsync(new [] { playhard }); } int playedGameTypesBitField; using (NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults) { playedGameTypesBitField = defaults.IntForKey("playedGameTypes") | (int)gameType; defaults.SetInt(playedGameTypesBitField, "playedGameTypes"); defaults.Synchronize(); } int numTypesPlayed = 0; for (int i = 0; i < 6; i++) { if ((playedGameTypesBitField & 0x01) != 0) { numTypesPlayed++; } playedGameTypesBitField >>= 1; } GKAchievement playAllModesAchievement = new GKAchievement(PlayAllId) { PercentComplete = numTypesPlayed / 6.0 * 100.0 }; await GKAchievement.ReportAchievementsAsync(new [] { playAllModesAchievement }); await UpdateCurrentTapsLeaderboardAndTapAchievements(); } }
public int GetInt(string key) { return((int)_prefs.IntForKey(key)); }
public static nint GetStore() { nint storeid = plist.IntForKey("storeid"); return storeid; }
public void DoWorkInBackground() { ThreadPool.QueueUserWorkItem(delegate { using (NSAutoreleasePool autorelease = new NSAutoreleasePool()) { Util.Log("Apirator launched"); bool forceShowDialog = false; #if DEBUG //forceShowDialog = true; #endif bool shouldShowDialog = false; string currentVersion = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString(); using (NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults) { string trackingVersion = defaults.StringForKey(CONFIG_CURRENTVERSION); if (trackingVersion == null) { trackingVersion = currentVersion; defaults.SetString(trackingVersion, CONFIG_CURRENTVERSION); } Util.Log("Tracking version: " + trackingVersion); if (trackingVersion == currentVersion) { int launchCount = defaults.IntForKey(CONFIG_LAUNCHCOUNT); launchCount++; defaults.SetInt(launchCount, CONFIG_LAUNCHCOUNT); Util.Log("Launch count is: " + launchCount); bool declinedToRate = defaults.BoolForKey(CONFIG_DECLINEDTORATE); bool hasRated = defaults.BoolForKey(CONFIG_RATEDCURRENTVERSION); if (launchCount > LAUNCHES_UNTIL_PROMPT && !declinedToRate && !hasRated) { if (IsConnectedToNetwork()) { shouldShowDialog = true; } } defaults.Synchronize(); } else { Util.Log("Setting defatuls"); defaults.SetString(currentVersion, CONFIG_CURRENTVERSION); defaults.SetInt(1, CONFIG_LAUNCHCOUNT); defaults.SetBool(false, CONFIG_RATEDCURRENTVERSION); defaults.SetBool(false, CONFIG_DECLINEDTORATE); defaults.Synchronize(); } } if (shouldShowDialog || forceShowDialog) { Util.Log("Apirator: Showing Dialog"); UIApplication.SharedApplication.InvokeOnMainThread(delegate { alertView = new UIAlertView(string.Format(MESSAGE_TITLE, APP_NAME), string.Format(MESSAGE, APP_NAME), null, CANCEL_BUTTON, string.Format(RATE_BUTTON, APP_NAME), LATER_BUTTON); alertView.Clicked += delegate(object sender, UIButtonEventArgs e) { using (NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults) { switch (e.ButtonIndex) { case 0: defaults.SetBool(true, CONFIG_DECLINEDTORATE); defaults.Synchronize(); Util.Log("declined to rate. Boo"); break; case 1: Util.Log("rating it! yay!"); string reviewUrl = string.Format(TemplateReviewUrl, APP_ID); Util.Log(reviewUrl); UIApplication.SharedApplication.OpenUrl(new NSUrl(reviewUrl)); defaults.SetBool(true, CONFIG_RATEDCURRENTVERSION); defaults.Synchronize(); break; case 2: Util.Log("doing it later"); defaults.SetInt(5, CONFIG_LAUNCHCOUNT); defaults.Synchronize(); int launchCount = defaults.IntForKey(CONFIG_LAUNCHCOUNT); Util.Log("Launch count is: " + launchCount); break; } } }; alertView.Canceled += delegate(object sender, EventArgs e) { }; alertView.Show(); }); } } }); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { SettingsTableViewCell cell; SettingsProfileTableViewCell cell2; TextTableViewCell cell3; int section = indexPath.Section; int row = indexPath.Row; if (section == 0) { if (row == 0) { cell = (SettingsTableViewCell)tableView.DequeueReusableCell(CELL_ID, indexPath); cell.Tag = 100; cell.UpdateLabelText(); return(cell); } else if (row == 1) { cell = (SettingsTableViewCell)tableView.DequeueReusableCell(CELL_ID, indexPath); cell.Tag = 101; cell.UpdateLabelText(); return(cell); } } else if (section == 1) { cell2 = (SettingsProfileTableViewCell)tableView.DequeueReusableCell(PROFILE_CELL_ID, indexPath); NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults; nint row_ = defaults.IntForKey("selectedProfile"); if (row_ == row) { cell2.Accessory = UITableViewCellAccessory.Checkmark; } else { cell2.Accessory = UITableViewCellAccessory.None; } switch (row) { case 0: cell2.Configure("profile_button_original", "Original"); break; case 1: cell2.Configure("profile_button_bw", "Black & White"); break; case 2: cell2.Configure("profile_button_gray", "Gray"); break; case 3: cell2.Configure("profile_button_color", "Color"); break; } return(cell2); } else if (section == 2) { cell = (SettingsTableViewCell)tableView.DequeueReusableCell(CELL_ID, indexPath); cell.Accessory = UITableViewCellAccessory.None; if (row == 0) { cell.Tag = 102; } else { cell.Tag = 103; } cell.UpdateLabelText(); return(cell); } else if (section == 3) { cell3 = (TextTableViewCell)tableView.DequeueReusableCell(TEXT_PROFILE_CELL_ID, indexPath); cell3.Accessory = UITableViewCellAccessory.None; if (row == 0) { cell3.Tag = 104; } cell3.UpdateLabelText(); return(cell3); } else if (section == 4) { cell2 = (SettingsProfileTableViewCell)tableView.DequeueReusableCell(PROFILE_CELL_ID, indexPath); NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults; nint row_ = defaults.IntForKey("selectedSaveFormat"); cell2.Accessory = row_ == row ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None ; switch (row) { case 0: cell2.Configure("save_format_button_pdf", "PDF"); break; case 1: { cell2.Configure("save_format_button_pdf_from_png", "PDF from PNG"); break; } case 2: { cell2.Configure("save_format_button_tiff", "TIFF G4"); break; } case 3: { cell2.Configure("save_format_button_png", "PNG"); break; } case 4: { cell2.Configure("save_format_button_jpg", "JPG"); break; } } return(cell2); } else if (section == 5) { cell = (SettingsTableViewCell)tableView.DequeueReusableCell(CELL_ID, indexPath); cell.Accessory = UITableViewCellAccessory.None; cell.Tag = 104; cell.UpdateLabelText(); return(cell); } else if (section == 6) { cell2 = (SettingsProfileTableViewCell)tableView.DequeueReusableCell(PROFILE_CELL_ID, indexPath); cell2.Accessory = UITableViewCellAccessory.None; cell2.Configure("", "About product"); return(cell2); } return(null); }
protected DateTime GetDateTime(string key) { var s = defs.IntForKey(key); return(Epoch + TimeSpan.FromSeconds(s)); }