Beispiel #1
0
        private void InitComponent()
        {
            try
            {
                MainSettings.SharedData = PreferenceManager.SharedPreferences;
                PreferenceManager.SharedPreferences.RegisterOnSharedPreferenceChangeListener(this);

                NotifcationPopupPref     = (SwitchPreferenceCompat)FindPreference("notifications_key");
                NotifcationPlaySoundPref = (CheckBoxPreference)FindPreference("checkBox_PlaySound_key");

                //Update Preferences data on Load
                OnSharedPreferenceChanged(MainSettings.SharedData, "notifications_key");

                NotifcationPopupPref.IconSpaceReserved = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey)
        {
            AddPreferencesFromResource(Resource.Xml.sound_preferences);


            mRegistrationBroadcastReceiver          = new Shared.BroadcastReceiver();
            mRegistrationBroadcastReceiver.Receive += (sender, e) =>
            {
                var reply_error = e.Intent.GetStringExtra("reply_error");
                var reply_data  = e.Intent.GetStringExtra("reply_data");

                if (reply_data == Shared.QueuedDeviceRequestType.NEW_SOUND)
                {
                    if (reply_error == Shared.ServerResponsecode.OK.ToString())
                    {
                        if (loading != null)
                        {
                            loading.Hide();
                        }
                        var intent = new Intent(parent, typeof(MicSoundsActivity));
                        parent.NavigateUpTo(intent);
                    }
                    else
                    {
                        if (loading != null)
                        {
                            loading.Hide();
                        }
                        var intent = new Intent(parent, typeof(MicSoundsActivity));
                        parent.NavigateUpTo(intent);
                    }
                }
                if (reply_data == Shared.QueuedDeviceRequestType.DELETE_SOUND)
                {
                    if (reply_error == Shared.ServerResponsecode.OK.ToString())
                    {
                        if (loading != null)
                        {
                            loading.Hide();
                        }
                        var intent = new Intent(parent, typeof(MicSoundsActivity));
                        parent.NavigateUpTo(intent);
                    }
                    else
                    {
                        if (loading != null)
                        {
                            loading.Hide();
                        }
                        var intent = new Intent(parent, typeof(MicSoundsActivity));
                        parent.NavigateUpTo(intent);
                    }
                }
            };

            LocalBroadcastManager.GetInstance(base.Activity).RegisterReceiver(mRegistrationBroadcastReceiver,
                                                                              new IntentFilter("reply_error"));



            if (sound.sound_settings == null)
            {
                sound.sound_settings = new Dictionary <string, string>();
            }
            //Preference

            var prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
            ISharedPreferencesEditor editor = prefs.Edit();

            soundPushCheck = FindPreference("sound_push") as Android.Support.V7.Preferences.CheckBoxPreference;
            soundPushCheck.PreferenceClick += settingsClicked;
            if (sound.sound_settings.ContainsKey("Push"))
            {
                soundPushCheck.Checked = Boolean.Parse(sound.sound_settings["Push"]);
            }
            else
            {
                sound.sound_settings.Add("Push", true.ToString());
                soundPushCheck.Checked = true;
            }

            soundVibrateCheck = FindPreference("sound_vibrate") as Android.Support.V7.Preferences.CheckBoxPreference;
            soundVibrateCheck.PreferenceClick += settingsClicked;
            if (sound.sound_settings.ContainsKey("Vibrate"))
            {
                soundVibrateCheck.Checked = Boolean.Parse(sound.sound_settings["Vibrate"]);
            }
            else
            {
                sound.sound_settings.Add("Vibrate", true.ToString());
                soundVibrateCheck.Checked = true;
            }

            soundshowMessageCheck = FindPreference("sound_open") as Android.Support.V7.Preferences.CheckBoxPreference;
            soundshowMessageCheck.PreferenceClick += settingsClicked;
            if (sound.sound_settings.ContainsKey("ShowMessage"))
            {
                soundshowMessageCheck.Checked = Boolean.Parse(sound.sound_settings["ShowMessage"]);
            }
            else
            {
                sound.sound_settings.Add("ShowMessage", false.ToString());
                soundshowMessageCheck.Checked = false;
            }

            deleteSoundButton = FindPreference("sound_delete") as Android.Support.V7.Preferences.PreferenceScreen;
            deleteSoundButton.PreferenceClick += deleteSound;

            changeIconButton = FindPreference("sound_icon") as Android.Support.V7.Preferences.PreferenceScreen;
            changeIconButton.PreferenceClick += changeIcon;
        }