void UpdateCanSayHello(RestrictionEntry entry, Bundle restrictions)
        {
            bool canSayHello;
            if (restrictions == null || !restrictions.ContainsKey (KEY_CAN_SAY_HELLO))
                canSayHello = entry.SelectedState;
            else
                canSayHello = restrictions.GetBoolean (KEY_CAN_SAY_HELLO);

            textSayHello.SetText (canSayHello ? Resource.String.explanation_can_say_hello_true :
                Resource.String.explanation_can_say_hello_false);
            buttonSayHello.Enabled = canSayHello;
        }
		// Initializes a multi-select type restriction entry.
		public static void PopulateMultiEntry (Resources res, RestrictionEntry reMultiSelect)
		{
			String[] multiEntries = res.GetStringArray (Resource.Array.multi_entry_entries);
			String[] multiValues = res.GetStringArray (Resource.Array.multi_entry_values);

			if (reMultiSelect.GetAllSelectedStrings() == null)
				reMultiSelect.SetAllSelectedStrings (new String[0]);

			reMultiSelect.Title = res.GetString (Resource.String.multi_entry_title);
			reMultiSelect.SetChoiceEntries (multiEntries);
			reMultiSelect.SetChoiceValues (multiValues);
			reMultiSelect.Type = RestrictionEntryType.MultiSelect;
		}
		// Initializes a single choice type restriction entry.
		public static void PopulateChoiceEntry (Resources res, RestrictionEntry reSingleChoice)
		{
			String[] choiceEntries = res.GetStringArray (Resource.Array.choice_entry_entries);
			String[] choiceValues = res.GetStringArray (Resource.Array.choice_entry_values);

			if (reSingleChoice.SelectedString == null)
				reSingleChoice.SelectedString =  choiceValues [0];

			reSingleChoice.Title = res.GetString (Resource.String.choice_entry_title);
			reSingleChoice.SetChoiceEntries (choiceEntries);
			reSingleChoice.SetChoiceValues (choiceValues);
			reSingleChoice.Type = RestrictionEntryType.Choice;
		}
        // Initializes a multi-select type restriction entry.
        public static void PopulateMultiEntry(Resources res, RestrictionEntry reMultiSelect)
        {
            String[] multiEntries = res.GetStringArray(Resource.Array.multi_entry_entries);
            String[] multiValues  = res.GetStringArray(Resource.Array.multi_entry_values);

            if (reMultiSelect.GetAllSelectedStrings() == null)
            {
                reMultiSelect.SetAllSelectedStrings(new String[0]);
            }

            reMultiSelect.Title = res.GetString(Resource.String.multi_entry_title);
            reMultiSelect.SetChoiceEntries(multiEntries);
            reMultiSelect.SetChoiceValues(multiValues);
            reMultiSelect.Type = RestrictionEntryType.MultiSelect;
        }
        // Initializes a single choice type restriction entry.
        public static void PopulateChoiceEntry(Resources res, RestrictionEntry reSingleChoice)
        {
            String[] choiceEntries = res.GetStringArray(Resource.Array.choice_entry_entries);
            String[] choiceValues  = res.GetStringArray(Resource.Array.choice_entry_values);

            if (reSingleChoice.SelectedString == null)
            {
                reSingleChoice.SelectedString = choiceValues [0];
            }

            reSingleChoice.Title = res.GetString(Resource.String.choice_entry_title);
            reSingleChoice.SetChoiceEntries(choiceEntries);
            reSingleChoice.SetChoiceValues(choiceValues);
            reSingleChoice.Type = RestrictionEntryType.Choice;
        }
Example #6
0
        void UpdateCanSayHello(RestrictionEntry entry, Bundle restrictions)
        {
            bool canSayHello;

            if (restrictions == null || !restrictions.ContainsKey(KEY_CAN_SAY_HELLO))
            {
                canSayHello = entry.SelectedState;
            }
            else
            {
                canSayHello = restrictions.GetBoolean(KEY_CAN_SAY_HELLO);
            }

            textSayHello.SetText(canSayHello ? Resource.String.explanation_can_say_hello_true :
                                 Resource.String.explanation_can_say_hello_false);
            buttonSayHello.Enabled = canSayHello;
        }
        // Demonstrates the creation of standard app restriction types: boolean, single choice, and
        // multi-select.
        List <IParcelable> InitRestrictions(Context context)
        {
            List <IParcelable> newRestrictions = new List <IParcelable> ();
            Resources          res             = context.Resources;

            RestrictionEntry reBoolean = new RestrictionEntry(KEY_BOOLEAN, false);

            PopulateBooleanEntry(res, reBoolean);
            newRestrictions.Add(reBoolean);

            RestrictionEntry reSingleChoice = new RestrictionEntry(KEY_CHOICE, (String)null);

            PopulateChoiceEntry(res, reSingleChoice);
            newRestrictions.Add(reSingleChoice);

            RestrictionEntry reMultiSelect = new RestrictionEntry(KEY_MULTI_SELECT, (String[])null);

            PopulateMultiEntry(res, reMultiSelect);
            newRestrictions.Add(reMultiSelect);

            return(newRestrictions);
        }
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);
            Activity act = Activity;

            /* BEGIN_INCLUDE (GET_CURRENT_RESTRICTIONS) */
            // Existing app restriction settings, if exist, can be retrieved from the Bundle.
            mRestrictionsBundle = act.Intent.GetBundleExtra(Intent.ExtraRestrictionsBundle);

            if (mRestrictionsBundle == null)
            {
                mRestrictionsBundle = ((UserManager)act.GetSystemService(Context.UserService))
                                      .GetApplicationRestrictions(Activity.PackageName);
            }

            if (mRestrictionsBundle == null)
            {
                mRestrictionsBundle = new Bundle();
            }

            mRestrictions = (List <IParcelable>)act.Intent.GetParcelableArrayListExtra(Intent.ExtraRestrictionsList);
            /* END_INCLUDE (GET_CURRENT_RESTRICTIONS) */

            // Transfers the saved values into the preference hierarchy.
            if (mRestrictions != null)
            {
                foreach (RestrictionEntry entry in mRestrictions)
                {
                    if (entry.Key.Equals(GetRestrictionsReceiver.KEY_BOOLEAN))
                    {
                        mBooleanPref.Checked = entry.SelectedState;
                        mBooleanEntry        = entry;
                    }
                    else if (entry.Key.Equals(GetRestrictionsReceiver.KEY_CHOICE))
                    {
                        mChoicePref.Value = entry.SelectedString;
                        mChoiceEntry      = entry;
                    }
                    else if (entry.Key.Equals(GetRestrictionsReceiver.KEY_MULTI_SELECT))
                    {
                        List <String> list = new List <String> ();
                        foreach (String value in entry.GetAllSelectedStrings())
                        {
                            list.Add(value);
                        }
                        mMultiPref.Values = list;
                        mMultiEntry       = entry;
                    }
                }
            }
            else
            {
                mRestrictions = new List <IParcelable> ();

                // Initializes the boolean restriction entry and updates its corresponding shared
                // preference value.
                mBooleanEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_BOOLEAN,
                                                     mRestrictionsBundle.GetBoolean(GetRestrictionsReceiver.KEY_BOOLEAN, false));
                mBooleanEntry.Type   = RestrictionEntryType.Boolean;
                mBooleanPref.Checked = mBooleanEntry.SelectedState;

                // Initializes the single choice restriction entry and updates its corresponding
                // shared preference value.
                mChoiceEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_CHOICE,
                                                    mRestrictionsBundle.GetString(GetRestrictionsReceiver.KEY_CHOICE));
                mChoiceEntry.Type = RestrictionEntryType.Choice;
                mChoicePref.Value = mChoiceEntry.SelectedString;

                // Initializes the multi-select restriction entry and updates its corresponding
                // shared preference value.
                mMultiEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_MULTI_SELECT,
                                                   mRestrictionsBundle.GetStringArray(GetRestrictionsReceiver.KEY_MULTI_SELECT));
                mMultiEntry.Type = RestrictionEntryType.MultiSelect;

                if (mMultiEntry.GetAllSelectedStrings() != null)
                {
                    List <String> hset   = new List <String> ();
                    String[]      values = mRestrictionsBundle.GetStringArray(GetRestrictionsReceiver.KEY_MULTI_SELECT);

                    if (values != null)
                    {
                        foreach (String value in values)
                        {
                            hset.Add(value);
                        }
                    }
                    mMultiPref.Values = hset;
                }
                mRestrictions.Add(mBooleanEntry);
                mRestrictions.Add(mChoiceEntry);
                mRestrictions.Add(mMultiEntry);
            }
            // Prepares result to be passed back to the Settings app when the custom restrictions
            // activity finishes.
            Intent intent = new Intent(Activity.Intent);

            intent.PutParcelableArrayListExtra(Intent.ExtraRestrictionsList, new List <IParcelable> (mRestrictions));
            Activity.SetResult(Result.Ok, intent);
        }
 // Initializes a boolean type restriction entry.
 public static void PopulateBooleanEntry(Resources res, RestrictionEntry entry)
 {
     entry.Type  = RestrictionEntryType.Boolean;
     entry.Title = res.GetString(Resource.String.boolean_entry_title);
 }
		// Initializes a boolean type restriction entry.
		public static void PopulateBooleanEntry (Resources res, RestrictionEntry entry)
		{
			entry.Type = RestrictionEntryType.Boolean;
			entry.Title = res.GetString (Resource.String.boolean_entry_title);
		}
		// Demonstrates the creation of standard app restriction types: boolean, single choice, and
		// multi-select.
		List <IParcelable> InitRestrictions (Context context)
		{
			List <IParcelable> newRestrictions = new List <IParcelable> ();
			Resources res = context.Resources;

			RestrictionEntry reBoolean = new RestrictionEntry (KEY_BOOLEAN, false);
			PopulateBooleanEntry (res, reBoolean);
			newRestrictions.Add (reBoolean);

			RestrictionEntry reSingleChoice = new RestrictionEntry (KEY_CHOICE, (String) null);
			PopulateChoiceEntry (res, reSingleChoice);
			newRestrictions.Add (reSingleChoice);

			RestrictionEntry reMultiSelect = new RestrictionEntry (KEY_MULTI_SELECT, (String[]) null);
			PopulateMultiEntry (res, reMultiSelect);
			newRestrictions.Add (reMultiSelect);

			return newRestrictions;
		}
		public override void OnActivityCreated (Bundle savedInstanceState)
		{
			base.OnActivityCreated (savedInstanceState);
			Activity act = Activity; 

			/* BEGIN_INCLUDE (GET_CURRENT_RESTRICTIONS) */
			// Existing app restriction settings, if exist, can be retrieved from the Bundle.
			mRestrictionsBundle = act.Intent.GetBundleExtra (Intent.ExtraRestrictionsBundle);

			if (mRestrictionsBundle == null) {
				mRestrictionsBundle = ((UserManager) act.GetSystemService (Context.UserService))
							.GetApplicationRestrictions (Activity.PackageName);
			}

			if (mRestrictionsBundle == null) {
				mRestrictionsBundle = new Bundle ();
			}

			mRestrictions = (List<IParcelable>) act.Intent.GetParcelableArrayListExtra (Intent.ExtraRestrictionsList);
			/* END_INCLUDE (GET_CURRENT_RESTRICTIONS) */

			// Transfers the saved values into the preference hierarchy.
			if (mRestrictions != null) {
				foreach (RestrictionEntry entry in mRestrictions) {
					if (entry.Key.Equals (GetRestrictionsReceiver.KEY_BOOLEAN)) {
						mBooleanPref.Checked = entry.SelectedState;
						mBooleanEntry = entry;

					} else if (entry.Key.Equals (GetRestrictionsReceiver.KEY_CHOICE)) {
						mChoicePref.Value = entry.SelectedString;
						mChoiceEntry = entry;

					} else if (entry.Key.Equals (GetRestrictionsReceiver.KEY_MULTI_SELECT)) {
						List <String> list = new List <String> ();
						foreach (String value in entry.GetAllSelectedStrings ()) {
							list.Add (value);
						}
						mMultiPref.Values = list;
						mMultiEntry = entry;
					}
				}
			} else {
				mRestrictions = new List<IParcelable> ();

				// Initializes the boolean restriction entry and updates its corresponding shared
				// preference value.
				mBooleanEntry = new RestrictionEntry (GetRestrictionsReceiver.KEY_BOOLEAN, 
				                                      mRestrictionsBundle.GetBoolean (GetRestrictionsReceiver.KEY_BOOLEAN, false));
				mBooleanEntry.Type = RestrictionEntryType.Boolean;
				mBooleanPref.Checked = mBooleanEntry.SelectedState;

				// Initializes the single choice restriction entry and updates its corresponding
				// shared preference value.
				mChoiceEntry = new RestrictionEntry (GetRestrictionsReceiver.KEY_CHOICE, 
				                                     mRestrictionsBundle.GetString (GetRestrictionsReceiver.KEY_CHOICE));
				mChoiceEntry.Type = RestrictionEntryType.Choice;
				mChoicePref.Value = mChoiceEntry.SelectedString;

				// Initializes the multi-select restriction entry and updates its corresponding
				// shared preference value.
				mMultiEntry = new RestrictionEntry (GetRestrictionsReceiver.KEY_MULTI_SELECT,
					                                   mRestrictionsBundle.GetStringArray (GetRestrictionsReceiver.KEY_MULTI_SELECT));
				mMultiEntry.Type = RestrictionEntryType.MultiSelect;

				if (mMultiEntry.GetAllSelectedStrings() != null) {
					List <String> hset = new List <String> ();
					String[] values = mRestrictionsBundle.GetStringArray (GetRestrictionsReceiver.KEY_MULTI_SELECT);

					if (values != null) {
						foreach (String value in values) {
							hset.Add (value);
						}
					}
					mMultiPref.Values = hset;
				}
				mRestrictions.Add (mBooleanEntry);
				mRestrictions.Add (mChoiceEntry);
				mRestrictions.Add (mMultiEntry);
			}
			// Prepares result to be passed back to the Settings app when the custom restrictions
			// activity finishes.
			Intent intent = new Intent (Activity.Intent);
			intent.PutParcelableArrayListExtra (Intent.ExtraRestrictionsList, new List <IParcelable> (mRestrictions));
			Activity.SetResult (Result.Ok, intent);
		}