Example usage for android.content RestrictionEntry getSelectedString

List of usage examples for android.content RestrictionEntry getSelectedString

Introduction

In this page you can find the example usage for android.content RestrictionEntry getSelectedString.

Prototype

public String getSelectedString() 

Source Link

Document

Returns the currently selected string value.

Usage

From source file:com.example.android.apprestrictionschema.AppRestrictionSchemaFragment.java

private void updateMessage(RestrictionEntry entry, Bundle restrictions) {
    if (restrictions == null || !restrictions.containsKey(KEY_MESSAGE)) {
        mMessage = entry.getSelectedString();
    } else {//w  ww.j a v a 2 s  .com
        mMessage = restrictions.getString(KEY_MESSAGE);
    }
}

From source file:com.example.android.apprestrictionschema.AppRestrictionSchemaFragment.java

private void updateRank(RestrictionEntry entry, Bundle restrictions) {
    String rank;//from w ww  .  j a  v  a2  s  .  co  m
    if (restrictions == null || !restrictions.containsKey(KEY_RANK)) {
        rank = entry.getSelectedString();
    } else {
        rank = restrictions.getString(KEY_RANK);
    }
    mTextRank.setText(getString(R.string.your_rank, rank));
}

From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java

/**
 * Loads the restrictions for the AppRestrictionSchema sample.
 *
 * @param activity The activity//from ww w .j av  a2  s.co  m
 */
private void loadRestrictions(Activity activity) {
    RestrictionsManager manager = (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE);
    List<RestrictionEntry> restrictions = manager
            .getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA);
    SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
    for (RestrictionEntry restriction : restrictions) {
        String key = restriction.getKey();
        if (RESTRICTION_KEY_SAY_HELLO.equals(key)) {
            updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO, restriction.getSelectedState()));
        } else if (RESTRICTION_KEY_MESSAGE.equals(key)) {
            updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_NUMBER.equals(key)) {
            updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER, restriction.getIntValue()));
        } else if (RESTRICTION_KEY_RANK.equals(key)) {
            updateRank(activity, restriction.getChoiceValues(),
                    prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_APPROVALS.equals(key)) {
            updateApprovals(activity, restriction.getChoiceValues(),
                    TextUtils.split(
                            prefs.getString(RESTRICTION_KEY_APPROVALS,
                                    TextUtils.join(DELIMETER, restriction.getAllSelectedStrings())),
                            DELIMETER));
        } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) {
            String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, "");
            HashMap<String, String> items = new HashMap<>();
            for (String itemString : TextUtils.split(itemsString, DELIMETER)) {
                String[] strings = itemString.split(SEPARATOR, 2);
                items.put(strings[0], strings[1]);
            }
            updateItems(activity, items);
        }
    }
}

From source file:com.android.tv.settings.users.AppRestrictionsFragment.java

private void onRestrictionsReceived(AppRestrictionsPreference preference,
        ArrayList<RestrictionEntry> restrictions) {
    // Remove any earlier restrictions
    preference.removeAll();/*from w w  w  .j a v  a 2 s . c  o m*/
    // Non-custom-activity case - expand the restrictions in-place
    int count = 1;
    final Context themedContext = getPreferenceManager().getContext();
    for (RestrictionEntry entry : restrictions) {
        Preference p = null;
        switch (entry.getType()) {
        case RestrictionEntry.TYPE_BOOLEAN:
            p = new SwitchPreference(themedContext);
            p.setTitle(entry.getTitle());
            p.setSummary(entry.getDescription());
            ((SwitchPreference) p).setChecked(entry.getSelectedState());
            break;
        case RestrictionEntry.TYPE_CHOICE:
        case RestrictionEntry.TYPE_CHOICE_LEVEL:
            p = new ListPreference(themedContext);
            p.setTitle(entry.getTitle());
            String value = entry.getSelectedString();
            if (value == null) {
                value = entry.getDescription();
            }
            p.setSummary(findInArray(entry.getChoiceEntries(), entry.getChoiceValues(), value));
            ((ListPreference) p).setEntryValues(entry.getChoiceValues());
            ((ListPreference) p).setEntries(entry.getChoiceEntries());
            ((ListPreference) p).setValue(value);
            ((ListPreference) p).setDialogTitle(entry.getTitle());
            break;
        case RestrictionEntry.TYPE_MULTI_SELECT:
            p = new MultiSelectListPreference(themedContext);
            p.setTitle(entry.getTitle());
            ((MultiSelectListPreference) p).setEntryValues(entry.getChoiceValues());
            ((MultiSelectListPreference) p).setEntries(entry.getChoiceEntries());
            HashSet<String> set = new HashSet<>();
            Collections.addAll(set, entry.getAllSelectedStrings());
            ((MultiSelectListPreference) p).setValues(set);
            ((MultiSelectListPreference) p).setDialogTitle(entry.getTitle());
            break;
        case RestrictionEntry.TYPE_NULL:
        default:
        }
        if (p != null) {
            p.setPersistent(false);
            p.setOrder(preference.getOrder() + count);
            // Store the restrictions key string as a key for the preference
            p.setKey(getPackageFromKey(preference.getKey()) + DELIMITER + entry.getKey());
            preference.addPreference(p);
            p.setOnPreferenceChangeListener(AppRestrictionsFragment.this);
            p.setIcon(BLANK_DRAWABLE);
            count++;
        }
    }
    preference.setRestrictions(restrictions);
    if (count == 1 // No visible restrictions
            && preference.isImmutable() && preference.isChecked()) {
        // Special case of required app with no visible restrictions. Remove it
        mAppList.removePreference(preference);
    }
}