private double GetDoubleObject(string doubleKey)
        {
            long   doubleValueAsLong = AndroidSharedPreferences.GetLong(doubleKey, 0);
            double doubleValue       = Java.Lang.Double.LongBitsToDouble(doubleValueAsLong);

            return(doubleValue);
        }
Ejemplo n.º 2
0
        private static WidgetSuggestionItem getItem(ISharedPreferences sharedPreferences, int index)
        {
            var projectId = (long?)sharedPreferences.GetLong($"{prefix}{nameof(ProjectId)}{index}", 0);

            projectId = projectId == 0 ? null : projectId;

            var taskId = (long?)sharedPreferences.GetLong($"{prefix}{nameof(TaskId)}{index}", 0);

            taskId = taskId == 0 ? null : taskId;

            var tagsIdsString = sharedPreferences.GetString($"{prefix}{nameof(TagsIds)}{index}", null);
            var tagsIds       = tagsIdsString?.Split(',').Select(long.Parse).ToArray() ?? Array.Empty <long>();

            return(new WidgetSuggestionItem
            {
                ProjectId = projectId,
                WorkspaceId = sharedPreferences.GetLong($"{prefix}{nameof(WorkspaceId)}{index}", 0),
                Description = sharedPreferences.GetString($"{prefix}{nameof(Description)}{index}", ""),
                ProjectName = sharedPreferences.GetString($"{prefix}{nameof(ProjectName)}{index}", ""),
                ProjectColor = sharedPreferences.GetString($"{prefix}{nameof(ProjectColor)}{index}", null) ?? Colors.Black.ToHexString(),
                ClientName = sharedPreferences.GetString($"{prefix}{nameof(ClientName)}{index}", ""),
                IsBillable = sharedPreferences.GetBoolean($"{prefix}{nameof(IsBillable)}{index}", false),
                TaskId = taskId,
                TagsIds = tagsIds
            });
        }
Ejemplo n.º 3
0
        protected override void OnCreate(Bundle bundle)
        {
            StartSetup();
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.BarcodeEntry);

            prefs              = PreferenceManager.GetDefaultSharedPreferences(this);
            locationname       = prefs.GetString("LocationName", "");
            EditInventoryID    = prefs.GetString("EditFromItemListForBarcode", "");
            AccessBarCodeScan  = prefs.GetString("AccessBarCodeScan", "");
            AccessFindITExport = prefs.GetString("AccessFindITExport", "");
            AccessExport       = prefs.GetString("AccessExport", "");
            editor             = prefs.Edit();

            _fab             = FindViewById <Fab>(Resource.Id.btnSaveBarCode);
            _fab.FabColor    = Color.Blue;
            _fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.icon_save2x);
            _fab.Show();
            _fabbacktolist = FindViewById <ImageView>(Resource.Id.btnBarBacktolist);



            empid        = prefs.GetLong("EmpID", 0);
            projectid    = prefs.GetLong("ProjectID", 0);
            projectname  = prefs.GetString("ProjectName", "");
            clientname   = prefs.GetString("ClientName", "");
            AlertVibrate = prefs.GetInt("AlertVibrate", 0);
            AlertTone    = prefs.GetInt("AlertTone", 0);
            editor       = prefs.Edit();

            SetTypeFace();
        }
Ejemplo n.º 4
0
        private async void ProfileInfo()
        {
            try
            {
                string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "user.db3"); //Call Database
                var    db     = new SQLiteConnection(dpPath);
                //Check if database exists
                if (tblUserProfile.TableExists <tblUserProfile>(db))
                {
                    var data  = db.Table <tblUserProfile>();                                                   //Call Table
                    var query = data.Where(x => (x.UserID == session.GetLong("userid", -1))).FirstOrDefault(); //Linq Query
                    if (query != null)
                    {
                        loggedOnUser = query;
                        userProfile  = await getUserProfile();

                        if (userProfile.Equals(loggedOnUser))
                        {
                            Toast.MakeText(this, "User Profile Loaded!", ToastLength.Short).Show();
                        }
                        else
                        {
                            Toast.MakeText(this, "User Profile MISMATCH!", ToastLength.Short).Show();
                        }
                        msg = null;
                    }
                    else
                    {
                        //User ID not found, so create user profile
                        userProfile = await getUserProfile();

                        string success = tblUserProfile.insertUpdateData(userProfile, dpPath);
                        if (success == "Single data file inserted or updated")
                        {
                            loggedOnUser = userProfile;
                        }
                        else
                        {
                            Toast.MakeText(this, "User Profile Insertion Failed!", ToastLength.Short).Show();
                        }
                        msg = null;
                    }
                }
                //Create database and userprofile
                else
                {
                    createuserProfileDatabase();
                    msg = null;
                }
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, ex.ToString(), ToastLength.Short).Show();
            }
        }
Ejemplo n.º 5
0
 public User(ISharedPreferences Prefs)
 {
     ID              = Prefs.GetInt($"Usr_{nameof(ID)}", 0);
     RoleID          = Prefs.GetInt($"Usr_{nameof(RoleID)}", 0);
     AccessRightsID  = Prefs.GetInt($"Usr_{nameof(AccessRightsID)}", 0);
     LoginID         = Prefs.GetString($"Usr_{nameof(LoginID)}", null);
     Hash            = Prefs.GetString($"Usr_{nameof(Hash)}", null);
     Name            = Prefs.GetString($"Usr_{nameof(Name)}", null);
     AccessToken     = Prefs.GetString($"Usr_{nameof(AccessToken)}", null);
     TokenType       = Prefs.GetString($"Usr_{nameof(TokenType)}", null);
     TokenExpiryDate = new DateTime(Prefs.GetLong($"Usr_{nameof(TokenExpiryDate)}", DateTime.Now.Ticks));
     LastServerLogin = new DateTime(Prefs.GetLong($"Usr_{nameof(LastServerLogin)}", DateTime.Now.Ticks));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Displays a dialog every 5th call
        /// </summary>
        /// <param name="context"></param>
        public static void RequestRatingReminder(Context context)
        {
            ISharedPreferences sharedPreferences = context.GetSharedPreferences(typeof(RatingDialog).FullName, 0);

            string preferenceKeyDontShowAgain = context.GetString(Resource.String.RateReminderDialog_doNotShowAgainKey);

            // Check if we want to show it
            if (sharedPreferences.GetBoolean(preferenceKeyDontShowAgain, false))
            {
                return;
            }

            ISharedPreferencesEditor editor = sharedPreferences.Edit();

            if (editor != null)
            {
                string preferenceKeyLaunchCount = context.GetString(Resource.String.RateReminderDialog_launchCountKey);

                long launchCount = sharedPreferences.GetLong(preferenceKeyLaunchCount, 0);
                editor.PutLong(preferenceKeyLaunchCount, launchCount + 1);

                // Displays the rating reminder dialog when we have enough launch counts
                if (launchCount >= LaunchesUntilPrompt && (launchCount + 1) % (AskIntervall) == 0)
                {
                    ShowRateDialog(context);
                }

                editor.Commit();
            }
        }
        public void PrepareNoDonatePreference(Context ctx, Preference preference)
        {
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx);

            long usageCount = prefs.GetLong(ctx.GetString(Resource.String.UsageCount_key), 0);

#if DEBUG
            preference.Enabled = (usageCount > 1);
#else
            preference.Enabled = (usageCount > 50);
#endif
            preference.PreferenceChange += delegate(object sender, Preference.PreferenceChangeEventArgs args)
            {
                if ((bool)args.NewValue)
                {
                    new AlertDialog.Builder(ctx)
                    .SetTitle(ctx.GetString(AppNames.AppNameResource))
                    .SetCancelable(false)
                    .SetPositiveButton(Android.Resource.String.Ok, delegate(object o, DialogClickEventArgs eventArgs)
                    {
                        Util.GotoDonateUrl(ctx);
                        ((Dialog)o).Dismiss();
                    })
                    .SetMessage(Resource.String.NoDonateOption_question)
                    .Create().Show();
                }
            };
        }
        public object Get(string key, Type type)
        {
            var typeCode = Type.GetTypeCode(type);

            switch (typeCode)
            {
            case TypeCode.Boolean: return(preferences.GetBoolean(key, false));

            case TypeCode.String: return(preferences.GetString(key, null));

            case TypeCode.Single: return(preferences.GetFloat(key, 0));

            case TypeCode.Int64: return(preferences.GetLong(key, 0));

            case TypeCode.Int16:
            case TypeCode.Int32:
                return(preferences.GetInt(key, 0));

#if FEATURE_SERIALIZATION
            case TypeCode.Object:
            {
                var stringValue = preferences.GetString(key, null);
                return(serializationManager.Deserialize(stringValue, type));
            }
#endif

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 9
0
        public static bool DeliverProduct(Context context, String productId, String purchaseToken)
        {
            if (TextUtils.IsEmpty(productId) || TextUtils.IsEmpty(purchaseToken))
            {
                Log.Info("Delivery", "fail empty");
                return(false);
            }
            if (!getNumOfGems().ContainsKey(productId))
            {
                Log.Info("Delivery", "fail product id not found");
                return(false);
            }
            ISharedPreferences       sharedPreferences = context.GetSharedPreferences(DATA_NAME, FileCreationMode.Private);
            ISharedPreferencesEditor editor            = sharedPreferences.Edit();

            long count = sharedPreferences.GetLong(GEMS_COUNT_KEY, 0);

            count += (long)getNumOfGems().Get(productId);
            editor.PutLong(GEMS_COUNT_KEY, count);

            ICollection <String> stringSet = sharedPreferences.GetStringSet(PURCHASETOKEN_KEY, new HashSet <String>());

            stringSet.Add(purchaseToken);
            editor.PutStringSet(PURCHASETOKEN_KEY, stringSet);
            return(editor.Commit());
        }
Ejemplo n.º 10
0
        public static void ShowDonateReminderIfAppropriate(Activity context)
        {
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(context);

            if (prefs.GetBoolean(context.GetString(Resource.String.NoDonationReminder_key), false))
            {
                return;
            }

            long usageCount = prefs.GetLong(context.GetString(Resource.String.UsageCount_key), 0);

            if (usageCount <= 5)
            {
                return;
            }

            foreach (Reminder r in GetReminders())
            {
                if ((DateTime.Now >= r.From) &&
                    (DateTime.Now < r.To))
                {
                    if (prefs.GetBoolean(r.Key, false) == false)
                    {
                        ISharedPreferencesEditor edit = prefs.Edit();
                        edit.PutBoolean(r.Key, true);
                        EditorCompat.Apply(edit);

                        context.StartActivity(new Intent(context, typeof(DonateReminder)));
                        break;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
        /// </summary>
        /// <returns>The parameter.</returns>
        /// <param name="context">Context.</param>
        /// <param name="key">Key.</param>
        /// <param name="defaultObject">Default object.</param>
        public static Object GetParam(Context context, String key, Object defaultObject)
        {
            String             type = defaultObject.GetType().Name;
            ISharedPreferences sp   = context.GetSharedPreferences(FILE_NAME, FileCreationMode.Private);

            if ("String".Equals(type))
            {
                return(sp.GetString(key, (String)defaultObject));
            }
            else if ("Integer".Equals(type))
            {
                return(sp.GetInt(key, Int32.Parse(defaultObject.ToString())));
            }
            else if ("Boolean".Equals(type))
            {
                return(sp.GetBoolean(key, bool.Parse(defaultObject.ToString())));
            }
            else if ("Float".Equals(type))
            {
                return(sp.GetFloat(key, float.Parse(defaultObject.ToString())));
            }
            else if ("Long".Equals(type))
            {
                return(sp.GetLong(key, long.Parse(defaultObject.ToString())));
            }

            return(null);
        }
Ejemplo n.º 12
0
        public static long getCountOfGems(Context context)
        {
            ISharedPreferences sharedPreferences = context.GetSharedPreferences(DATA_NAME, FileCreationMode.Private);
            long count = sharedPreferences.GetLong(GEMS_COUNT_KEY, 0);

            return(count);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);

            long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0);

            ISharedPreferencesEditor edit = prefs.Edit();

            edit.PutLong(GetString(Resource.String.UsageCount_key), usageCount + 1);
            edit.Commit();

            _showPassword =
                !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default));

            Entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, "philipp "));
            Entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, "password value"));
            Entry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, "https://www.google.com"));
            Entry.Strings.Set("field header", new ProtectedString(true, "protected field value"));
            Entry.Strings.Set("public field header", new ProtectedString(false, "public field value"));

            base.OnCreate(savedInstanceState);
            SetEntryView();

            FillData();

            SetupEditButtons();

            App.Kp2A.GetDb().LastOpenedEntry = new PwEntryOutput(Entry, App.Kp2A.GetDb().KpDatabase);

            RegisterReceiver(new PluginActionReceiver(this), new IntentFilter(Strings.ActionAddEntryAction));
            RegisterReceiver(new PluginFieldReceiver(this), new IntentFilter(Strings.ActionSetEntryField));

            new Thread(NotifyPluginsOnOpen).Start();
        }
Ejemplo n.º 14
0
 public long?GetLong(string key)
 {
     if (_preferenceManager.Contains(key))
     {
         return(_preferenceManager.GetLong(key, 0));
     }
     return(null);
 }
 /// <summary>
 /// Retrieve an Long value from the mPreferences.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="defaultValue"></param>
 /// <returns></returns>
 public long GetLong(string key, long defaultValue)
 {
     if (_preferences.Contains(ToKey(key)))
     {
         return(_preferences.GetLong(ToKey(key), defaultValue));
     }
     return(defaultValue);
 }
Ejemplo n.º 16
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            prefs        = PreferenceManager.GetDefaultSharedPreferences(this);
            Backfrommain = prefs.GetLong("Backfrommain", 0);
            EmpID        = prefs.GetLong("EmpID", 0);

            if (Backfrommain == 0)
            {
                if (EmpID > 0)
                {
                    StartActivity(typeof(Main));
                    this.Finish();
                }
            }

            this.RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Login);

            db = this.OpenOrCreateDatabase("ImInventory", FileCreationMode.Private, null);

            //String path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString() + "/ImInventory";
            //var files = Directory.GetFiles (db.Path);
            //db.ExecSQL("DROP TABLE IF EXISTS " + "tbl_Inventory");
            db.ExecSQL("CREATE TABLE IF NOT EXISTS "
                       + "tbl_Inventory"
                       + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, EmpID INTEGER,ProjectID VARCHAR, ProjectName VARCHAR, ClientName VARCHAR,Location VARCHAR, Image1 VARCHAR , Image2 VARCHAR, Image3 VARCHAR, Image4 VARCHAR," +
                       "ItemDescription VARCHAR, Brand VARCHAR, Quantity VARCHAR, ModelNumber VARCHAR, UnitCost VARCHAR, Notes VARCHAR , Addeddate VARCHAR,BarCodeNumber VARCHAR,AudioFileName VARCHAR,InventoryType VARCHAR,UploadURL VARCHAR,UploadedBytes VARCHAR,UploadedStatus VARCHAR" +
                       "" +
                       "" +
                       ");");


            db.ExecSQL("CREATE TABLE IF NOT EXISTS "
                       + "tbl_UserDetails"
                       + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, EmpID INTEGER,Name VARCHAR, Email VARCHAR, Company VARCHAR,Phone VARCHAR, Address VARCHAR , Alert VARCHAR, Vibrate VARCHAR, Wifi VARCHAR," +
                       "Bluetooth VARCHAR" + ");");

            InitializetypefaceandClickevents();


            // Create your application here
        }
Ejemplo n.º 17
0
 protected DateTime?GetDateTime(string key)
 {
     if (!prefs.Contains(key))
     {
         return(null);
     }
     else
     {
         return(DateTime.FromBinary(prefs.GetLong(key, 0)).ToUtc());
     }
 }
Ejemplo n.º 18
0
        private bool IsTimeForInfotext(out string lastInfoText)
        {
            DateTime lastDisplayTime = new DateTime(_prefs.GetLong("LastInfoTextTime", 0));

            lastInfoText = _prefs.GetString("LastInfoTextKey", "");
#if DEBUG
            return(DateTime.UtcNow - lastDisplayTime > TimeSpan.FromSeconds(10));
#else
            return(DateTime.UtcNow - lastDisplayTime > TimeSpan.FromDays(3));
#endif
        }
Ejemplo n.º 19
0
        public long GetLong(string key)
        {
            try
            {
                return(_preferences.GetLong(key, 0));
            }
            catch (Exception e)
            {
                Logger.Error($"Error Getting Long UserSetting {key} - {e.Message}", e);
            }

            return(0);
        }
Ejemplo n.º 20
0
        //todo fix this
        public TPrimitive Get <TPrimitive>(string name) where TPrimitive : struct
        {
            TPrimitive value = default(TPrimitive);
            Type       type  = typeof(TPrimitive);

#if ANDROID
            if (type == typeof(int))
            {
                value = _preferences.GetInt(name, 0).Cast <TPrimitive>();
            }
            else if (type == typeof(bool))
            {
                value = _preferences.GetBoolean(name, true).Cast <TPrimitive>();
            }
            else if (type == typeof(float))
            {
                value = _preferences.GetFloat(name, 0).Cast <TPrimitive>();
            }
            else if (type == typeof(long))
            {
                value = _preferences.GetLong(name, 0).Cast <TPrimitive>();
            }
            else
            {
                throw new NotImplementedException("");
            }
#elif iOS
            if (type == typeof(int))
            {
                value = MonoTouch.Foundation.NSUserDefaults.StandardUserDefaults.IntForKey(name).Cast <TPrimitive>();
            }
            else if (type == typeof(bool))
            {
                value = MonoTouch.Foundation.NSUserDefaults.StandardUserDefaults.BoolForKey(name).Cast <TPrimitive>();
            }
            else if (type == typeof(float))
            {
                value = MonoTouch.Foundation.NSUserDefaults.StandardUserDefaults.FloatForKey(name).Cast <TPrimitive>();
            }
            else if (type == typeof(long))
            {
                value = MonoTouch.Foundation.NSUserDefaults.StandardUserDefaults.StringForKey(name).ToLong().Cast <TPrimitive>();
            }
            else
            {
                throw new NotImplementedException("");
            }
#endif

            return(value);
        }
Ejemplo n.º 21
0
        private void UpdateScreenData()
        {
            var  now = new Date();
            long monitoringStartTime;

            if ((monitoringStartTime = mPreferences.GetLong(ScreenUtils.MonitoringLastStartTime, -1)) == -1)
            {
                monitoringStartTime = ScreenUtils.GetMonitoringStartTime(now);
                mPreferences.Edit().PutLong(ScreenUtils.MonitoringLastStartTime, monitoringStartTime).Apply();
                using (StreamWriter writer = new StreamWriter(
                           OpenFileOutput(ScreenUnlockReceiver.DebugFile, FileCreationMode.Append)))
                {
                    writer.WriteLine($"----Monitoring m start Time: {now.GetFormattedDateTime()}----");
                }
            }
            else
            {
                var today = mPreferences.GetInt(ScreenUtils.UnlocksToday, -1);
                monitoringStartTime = ScreenUtils.GetMonitoringStartTime(new Date(monitoringStartTime));
                if (TimeUnit.Milliseconds.ToDays(now.Time - monitoringStartTime) >= 1 && today != -1)
                {
                    int u;
                    var lastDayUnlocked = mPreferences.GetInt(ScreenUtils.LastUnlockDay, -1);
                    if ((u = mPreferences.GetInt($"{ScreenUtils.UnlocksDayNumber}{lastDayUnlocked}", -1)) != -1)
                    {
                        today = (int)Math.Ceiling((u + today) / 2d);
                    }
                    if (lastDayUnlocked != -1)
                    {
                        mPreferences.Edit()
                        .PutInt($"{ScreenUtils.UnlocksDayNumber}{lastDayUnlocked}", today)
                        .PutInt(ScreenUtils.LastUnlockDay, lastDayUnlocked)
                        .PutLong(ScreenUtils.MonitoringLastStartTime, monitoringStartTime)
                        .PutInt(ScreenUtils.UnlocksToday, 0)
                        .PutInt(ScreenUtils.UnlocksNewNormalCount, -1)
                        .Apply();
                    }
                    else
                    {
                        mPreferences.Edit()
                        .PutLong(ScreenUtils.MonitoringLastStartTime, monitoringStartTime)
                        .PutInt(ScreenUtils.UnlocksToday, 0)
                        .PutInt(ScreenUtils.UnlocksNewNormalCount, -1)
                        .Apply();
                    }
                    ScreenUnlockReceiver.SetToZero();
                }
            }
            Adapter?.Refresh();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Loads long by key ((If database is not exist, it will be created)(If there is no value by this key, returns default value)).
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="defValue">The default value.</param>
        /// <returns>Long by key (If database is not exist, or there is not any value by this key, returns default value).</returns>
        public override long LoadData(string key, long defValue)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(defValue);
            }

            if (_preferences == null)
            {
                CreateIfNotExist();
            }

            return(_preferences.GetLong(key, defValue));
        }
Ejemplo n.º 23
0
        private void GetPreferenceManager()
        {
            prefs     = PreferenceManager.GetDefaultSharedPreferences(this);
            ProjectID = prefs.GetLong("ProjectID", 0);


            if (ProjectID == 0)
            {
                if (isNetworkConnected())
                {
                    prefs     = IMApplication.pref;
                    ProjectID = IMApplication.projectid;
                }
                else
                {
                    Toast.MakeText(this, "Please check data connection. Select a project. Then try back !!!!", ToastLength.Short).Show();
                }
            }
            EmpID      = prefs.GetLong("EmpID", 5);
            UserType   = prefs.GetLong("UserType", 1);
            UserPlan   = prefs.GetString("UserPlan", "");
            IsInternal = prefs.GetLong("IsInternal", 0);
        }
Ejemplo n.º 24
0
        protected override void OnResume()
        {
            base.OnResume();

            ISharedPreferences preferences = PreferenceManager.GetDefaultSharedPreferences(Application.Context);

            timerOn   = preferences.GetBoolean("timerOn", false);
            startTime = new DateTime(preferences.GetLong("startTimeTicks", 0));
            System.Diagnostics.Debug.WriteLine($"MainActivity - OnResume {startTime}, {timerOn}");

            if (timerOn)
            {
                ResumeTimer();
            }
        }
Ejemplo n.º 25
0
        public long ReadPresestingLong(string Key)
        {
            try
            {
                ISharedPreferences settings = this.GetSharedPreferences("AutoLock", FileCreationMode.Private);
                ISharedPreferences prefs    = PreferenceManager.GetDefaultSharedPreferences(this);
                return(prefs.GetLong(Key, 0));
            }

            catch (Exception ex)
            {
                Toast.MakeText(this, "Error:" + ex.Message, ToastLength.Long).Show();
                return(0);
            }
        }
Ejemplo n.º 26
0
        public static void ScheduleAlarms(IAlarmListener alarmListener, Context context, bool force)
        {
            ISharedPreferences preferences = context.GetSharedPreferences(NAME, 0);
            long lastAlarm = preferences.GetLong(LAST_ALARM, 0);

            if (lastAlarm == 0 || force ||
                (DateTime.Now.Millisecond > lastAlarm &&
                 DateTime.Now.Millisecond - lastAlarm > alarmListener.GetMaxAge()))
            {
                AlarmManager  manager       = (AlarmManager)context.GetSystemService(Context.AlarmService);
                Intent        intent        = new Intent(context, typeof(AlarmReceiver));
                PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, 0);
                alarmListener.ScheduleAlarms(manager, pendingIntent, context);
            }
        }
Ejemplo n.º 27
0
        public void OnSharedPreferenceChanged(ISharedPreferences preferences, String key)
        {
            switch (key)
            {
            case "FeatureDiscoveryState":
            case "CurrentScheduleId":
            case "LastMigrationVersion":
            case "LastSeenUpdateVersion":
                break;

            case "UpperWeekDate":
                UpperWeekDate = new DateTime(preferences.GetLong("UpperWeekDate", 0));
                break;

            // case "CheckUpdatesOnStart":
            //     CheckUpdatesOnStart = preferences.GetBoolean("CheckUpdatesOnStart", true);
            //     break;

            case "UseFabDateSelector":
                UseFabDateSelector = preferences.GetBoolean("UseFabDateSelector", true);
                break;

            case "UseDarkTheme":
                UseDarkTheme = preferences.GetBoolean("UseDarkTheme", false);
                ThemeChanged?.Invoke();
                break;

            case "LessonRemindTimes":
                LessonRemindTimes = ParseLessonRemindTimes(preferences);
                LessonRemindTimesChanged?.Invoke();
                break;

            case "DisplaySubjectEndTime":
                DisplaySubjectEndTime = preferences.GetBoolean("DisplaySubjectEndTime", true);
                break;

            case "UpdateSchedulesOnStart":
                UpdateSchedulesOnStart = preferences.GetBoolean("UpdateSchedulesOnStart", true);
                UpdateSchedulesOnStartChanged?.Invoke();
                break;

            case "ReplayFeatureDiscovery":
                ReplayFeatureDiscovery = preferences.GetBoolean("ReplayFeatureDiscovery", false);
                break;
            }
        }
Ejemplo n.º 28
0
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        ISharedPreferences       prefs  = PreferenceManager.GetDefaultSharedPreferences(this);
        ISharedPreferencesEditor editor = prefs.Edit();
        long memStartTime = prefs.GetLong("startTime", 0);

        if (memStartTime != 0)
        {
            startTime = new DateTime(memStartTime);
        }
        else
        {
            editor.PutLong("startTime", startTime.Ticks);
            editor.Apply();
        }
        TimerUpdate();
    }
Ejemplo n.º 29
0
        ��������public async void checkCredentials()
        {
            ISharedPreferences preferences = GetSharedPreferences(userSessionPref, FileCreationMode.Private);
            String             email       = preferences.GetString("email", "");
            String             username    = preferences.GetString("username", "");

            Toast.MakeText(this, "Username: "******"\nEmail: " + email, ToastLength.Short).Show();
            String pass   = preferences.GetString("pass", "");
            long   userid = preferences.GetLong("userid", -1);

            if (!username.Equals("") && !email.Equals("") && !pass.Equals("") && userid != -1)
            {
                //Check with webserver HERE
                _client.ValidateLogin_UserInfoAsync(email, pass);

                //Figure out a better way to wait and break out
                while (msg == null || msg != "Login Successful!")
                {
                    await delayTask();

                    if (msg != null && msg != "Login Successful!")
                    {
                        break;  //Error
                    }
                }

                if (msg == "Login Successful!")
                {
                    //Set user preferences
                    msg = null;
                    RunOnUiThread(() => Toast.MakeText(this, "Successful Login!!,", ToastLength.Short).Show());
                    Intent n = new Intent(this, typeof(MainInterfaceActivity));
                    n.PutExtra("UserInfo", JsonConvert.SerializeObject(user));
                    StartActivity(n);
                    Finish();
                }
                else
                {
                    msg = null;
                    Toast.MakeText(this, "Login Failed", ToastLength.Long).Show();  //Add error message on UI code saying why it failed. IE: "Username or password incorrect"
                }
            }
        }
            /**
             * Called when a new message arrives
             *
             * @param message Message to add
             * @param text    Notification text for added Message
             */
            internal void Add(Context context, IMessage message, string text)
            {
                Conversation conversation    = message.Conversation;
                string       key             = conversation.Id.ToString();
                long         currentPosition = mPositions.GetLong(key, long.MinValue);

                // Ignore older messages
                if (message.Position <= currentPosition)
                {
                    return;
                }

                string currentMessages = mMessages.GetString(key, null);

                try {
                    JSONObject messages   = currentMessages == null ? new JSONObject() : new JSONObject(currentMessages);
                    string     messageKey = message.Id.ToString();

                    // Ignore if we already have this message
                    if (messages.Has(messageKey))
                    {
                        return;
                    }

                    JSONObject messageEntry = new JSONObject();
                    messageEntry.Put(KEY_POSITION, message.Position);
                    messageEntry.Put(KEY_TEXT, text);
                    messages.Put(messageKey, messageEntry);

                    mMessages.Edit().PutString(key, messages.ToString()).Commit();
                } catch (JSONException e) {
                    if (Util.Log.IsLoggable(Util.Log.ERROR))
                    {
                        Util.Log.e(e.Message, e);
                    }
                    return;
                }
                Update(context, conversation, message);
            }