Beispiel #1
0
 protected virtual void InitializePreferences(PreferenceScreen preferenceScreen, int preferencesResId)
 {
     preferenceScreen.SetBindingMemberValue(AttachedMembers.Object.Parent, Target);
     SetPreferenceParent(preferenceScreen);
     using (XmlReader reader = preferenceScreen.Context.Resources.GetXml(preferencesResId))
     {
         var document = new XmlDocument();
         document.Load(reader);
         var xDocument = XDocument.Parse(document.InnerXml);
         foreach (var descendant in xDocument.Descendants())
         {
             var bindAttr = descendant
                            .Attributes()
                            .FirstOrDefault(xAttribute => xAttribute.Name.LocalName.Equals("bind", StringComparison.OrdinalIgnoreCase));
             if (bindAttr == null)
             {
                 continue;
             }
             var attribute = descendant.Attribute(XName.Get("key", "http://schemas.android.com/apk/res/android"));
             if (attribute == null)
             {
                 Tracer.Error("Preference {0} must have a key to use it with bindings", descendant);
                 continue;
             }
             var preference = preferenceScreen.FindPreference(attribute.Value);
             BindingServiceProvider.BindingProvider.CreateBindingsFromString(preference, bindAttr.Value);
         }
     }
     SetPreferenceListener();
 }
        private void UpdateNotification(string key, List <League> filteredLeagues)
        {
            var startsPreference = PreferenceScreen.FindPreference(key) as MultiSelectListPreference;

            startsPreference.SetEntryValues(filteredLeagues.Select(l => l.Id.ToString()).ToArray());
            startsPreference.SetEntries(filteredLeagues.Select(l => l.Name).ToArray());
        }
Beispiel #3
0
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var UoW = new UnitOfWork();

            Leagues = UoW.LeagueRepo.GetAllLeague();

            var countriesCategory = PreferenceScreen.FindPreference("countriesCategory") as PreferenceCategory;

            foreach (var country in countries)
            {
                MultiSelectListPreference listPreference = new MultiSelectListPreference(Activity);
                listPreference.Title = Resources.GetString(Resources.GetIdentifier(country.ToLower(), "string", "com.resitomi.floorball"));
                listPreference.Key   = country.ToLower();

                var listItems = Leagues.Where(l => l.Country.ToString() == country);
                listPreference.SetEntryValues(listItems.Select(l => l.Id.ToString()).ToArray());
                listPreference.SetEntries(listItems.Select(l => l.Name).ToArray());

                countriesCategory.AddPreference(listPreference);
            }

            var pref = PreferenceManager.GetDefaultSharedPreferences(Activity);
        }
Beispiel #4
0
        public void SignedIn()
        {
            AccountPreference accountPreference = (AccountPreference)PreferenceScreen.FindPreference("account");

            accountPreference.Title   = "Logged in as:";
            accountPreference.Summary = MainActivity.account.DisplayName;
            accountPreference.OnSignedIn();
            MainActivity.instance.InvalidateOptionsMenu();
        }
        public static void InitializePreferences(PreferenceScreen preferenceScreen, int preferencesResId, object parent)
        {
            preferenceScreen.SetBindingMemberValue(AttachedMembers.Object.Parent, parent);
            SetPreferenceParent(preferenceScreen);

            List <KeyValuePair <string, string> > bindings;

            if (!PreferenceBindMapping.TryGetValue(preferencesResId, out bindings))
            {
                bindings = new List <KeyValuePair <string, string> >();
                using (var reader = preferenceScreen.Context.Resources.GetXml(preferencesResId))
                {
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            string bind = null;
                            for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
                            {
                                reader.MoveToAttribute(attInd);
                                if (reader.Name == "bind")
                                {
                                    bind = reader.Value;
                                    break;
                                }
                            }
                            reader.MoveToElement();
                            var key = reader.GetAttribute("key", "http://schemas.android.com/apk/res/android");
                            if (string.IsNullOrEmpty(bind))
                            {
                                break;
                            }
                            if (string.IsNullOrEmpty(key))
                            {
                                Tracer.Error("Preference {0} must have a key to use it with bindings", reader.Name);
                                break;
                            }
                            bindings.Add(new KeyValuePair <string, string>(key, bind));
                            break;
                        }
                    }
                }
                PreferenceBindMapping[preferencesResId] = bindings;
            }

            foreach (var map in bindings)
            {
                var preference = preferenceScreen.FindPreference(map.Key);
                BindingServiceProvider.BindingProvider.CreateBindingsFromString(preference, map.Value);
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            AddPreferencesFromResource(Resource.Menu.settings);
            var pref = (EditTextPreference)PreferenceScreen.FindPreference("prefIPAddress");

            pref.PreferenceChange += (obj, args) =>
            {
                bool result = true;
                System.Net.IPAddress address;

                if ((string)args.NewValue != String.Empty && !System.Net.IPAddress.TryParse((string)args.NewValue, out address))
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationContext);
                    builder.SetTitle("Invalid IP Address");
                    builder.SetMessage("The entered IP address was not valid");
                    builder.SetPositiveButton("OK", (o, e) => { });
                    builder.Show();
                    result = false;
                }

                args.Handled = result;
            };

            pref = (EditTextPreference)PreferenceScreen.FindPreference("prefPort");

            pref.PreferenceChange += (obj, args) =>
            {
                bool   result = true;
                ushort port;

                if ((string)args.NewValue != String.Empty && !ushort.TryParse((string)args.NewValue, out port))
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationContext);
                    builder.SetTitle("Invalid Port");
                    builder.SetMessage("The entered port was not valid");
                    builder.SetPositiveButton("OK", (o, e) => { });
                    builder.Show();
                    result = false;
                }

                args.Handled = result;
            };
        }
Beispiel #7
0
        public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey)
        {
            instance = this;
            SetPreferencesFromResource(Resource.Layout.AboutPreferences, rootKey);

            //OpenSource click
            Preference openSource = PreferenceScreen.FindPreference("view_opensource");

            openSource.IconSpaceReserved = false;
            openSource.PreferenceClick  += (s, e) =>
            {
                Preferences.instance.SupportFragmentManager.BeginTransaction().Replace(Android.Resource.Id.ListContainer, new OpenSourceViewer()).AddToBackStack(null).Commit();
            };

            //Website click
            Preference website = PreferenceScreen.FindPreference("website");

            website.IconSpaceReserved = false;
            website.PreferenceClick  += (s, e) =>
            {
                Intent intent = new Intent(Intent.ActionView);
                intent.SetData(Uri.Parse("https://www.raccoon-sdg.fr"));
                StartActivity(intent);
            };

            //Github click
            Preference github = PreferenceScreen.FindPreference("github");

            github.IconSpaceReserved = false;
            github.PreferenceClick  += (s, e) =>
            {
                Intent intent = new Intent(Intent.ActionView);
                intent.SetData(Uri.Parse("https://github.com/AnonymusRaccoon/Opus"));
                StartActivity(intent);
            };
        }
Beispiel #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            AppHelper.UpdateLocale(this);

            if (AppHelper.allCities == null || AppHelper.allCities.Count == 0)
            {
                AppHelper.LoadCities();
            }

            AddPreferencesFromResource(Resource.Layout.PrefLayout);
            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            city  = PreferenceScreen.FindPreference("city_key");
            temp  = PreferenceScreen.FindPreference("temp_key");
            lang  = PreferenceScreen.FindPreference("lang_key");

            city.Summary = GetString(Resource.String.current_pref) + prefs.GetString("city_key", GetString(Resource.String.default_city));
            temp.Summary = GetString(Resource.String.current_pref) + prefs.GetString("temp_key", GetString(Resource.String.default_temp));
            lang.Summary = GetString(Resource.String.current_pref) + prefs.GetString("lang_key", GetString(Resource.String.default_lang));

            temp.PreferenceChange += TempLang_PreferenceChange;
            lang.PreferenceChange += TempLang_PreferenceChange;
            city.PreferenceClick  += City_PreferenceClick;
        }
Beispiel #9
0
        public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey)
        {
            instance = this;
            SetPreferencesFromResource(Resource.Layout.Preferences, rootKey);
            ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Application.Context);

            //Download Path
            Preference downloadPref = PreferenceScreen.FindPreference("downloadPath");

            downloadPref.IconSpaceReserved = false;
            downloadPref.PreferenceClick  += DownloadClick;
            downloadPref.Summary           = prefManager.GetString("downloadPath", Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic).ToString());
            path = prefManager.GetString("downloadPath", Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic).ToString());

            //Maximum Download
            Preference maxDlPref = PreferenceScreen.FindPreference("maxDownload");

            maxDlPref.IconSpaceReserved = false;
            maxDlPref.PreferenceClick  += MaxDownloadClick;
            maxDlPref.Summary           = prefManager.GetInt("maxDownload", 4).ToString();

            //Keep Deleted
            Preference keepDeletedPref = PreferenceScreen.FindPreference("keepDeleted");

            keepDeletedPref.IconSpaceReserved = false;
            keepDeletedPref.PreferenceClick  += KeepDeletedClick;
            keepDeletedPref.Summary           = (!prefManager.GetBoolean("keepDeleted", true)).ToString();

            //Theme
            Preference themePreference = PreferenceScreen.FindPreference("theme");

            themePreference.IconSpaceReserved = false;
            themePreference.PreferenceClick  += ChangeTheme;
            switch (prefManager.GetInt("theme", 0))
            {
            case 0:
            default:
                themePreference.Summary = Resources.GetString(Resource.String.white_theme);
                break;

            case 1:
                themePreference.Summary = Resources.GetString(Resource.String.dark_theme);
                break;

            case 2:
                themePreference.Summary = Resources.GetString(Resource.String.black_theme);
                break;
            }

            //Check For Update
            Preference updatePreference = PreferenceScreen.FindPreference("update");

            updatePreference.IconSpaceReserved = false;
            updatePreference.PreferenceClick  += UpdatePreference_PreferenceClick;

            //Version Number
            Preference   versionPreference = PreferenceScreen.FindPreference("version");
            string       VersionAsset;
            string       Beta;
            AssetManager assets = Application.Context.Assets;

            using (StreamReader sr = new StreamReader(assets.Open("Version.txt")))
            {
                VersionAsset = sr.ReadLine();
                Beta         = sr.ReadLine();
            }

            string version = VersionAsset.Substring(9, 5);

            if (version.EndsWith(".0"))
            {
                version = version.Substring(0, 3);
            }
            bool beta = false;

            if (Beta.Substring(6, 1) == "T")
            {
                beta = true;
            }

            versionPreference.Summary           = "v" + version + (beta ? "-Beta" : "");
            versionPreference.IconSpaceReserved = false;
            versionPreference.PreferenceClick  += About;

            //Account
            Preference accountPreference = PreferenceScreen.FindPreference("account");

            accountPreference.IconSpaceReserved = false;

            if (MainActivity.account != null)
            {
                accountPreference.Title   = Resources.GetString(Resource.String.logged_in);
                accountPreference.Summary = MainActivity.account.DisplayName;
            }
        }