Search in sources :

Example 66 with PreferenceCategory

use of android.preference.PreferenceCategory in project AndroidChromium by JackyAndroid.

the class SavePasswordsPreferences method passwordExceptionListAvailable.

@Override
public void passwordExceptionListAvailable(int count) {
    resetList(PREF_CATEGORY_EXCEPTIONS);
    mNoPasswordExceptions = count == 0;
    if (mNoPasswordExceptions) {
        if (mNoPasswords)
            displayEmptyScreenMessage();
        return;
    }
    displayManageAccountLink();
    PreferenceCategory profileCategory = new PreferenceCategory(getActivity());
    profileCategory.setKey(PREF_CATEGORY_EXCEPTIONS);
    profileCategory.setTitle(R.string.section_saved_passwords_exceptions);
    profileCategory.setOrder(ORDER_EXCEPTIONS);
    getPreferenceScreen().addPreference(profileCategory);
    for (int i = 0; i < count; i++) {
        String exception = mPasswordManagerHandler.getSavedPasswordException(i);
        PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());
        screen.setTitle(exception);
        screen.setOnPreferenceClickListener(this);
        Bundle args = screen.getExtras();
        args.putString(PASSWORD_LIST_URL, exception);
        args.putInt(PASSWORD_LIST_ID, i);
        profileCategory.addPreference(screen);
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) PreferenceCategory(android.preference.PreferenceCategory) Bundle(android.os.Bundle) SpannableString(android.text.SpannableString)

Example 67 with PreferenceCategory

use of android.preference.PreferenceCategory in project AndroidChromium by JackyAndroid.

the class SavePasswordsPreferences method resetList.

private void resetList(String preferenceCategoryKey) {
    PreferenceCategory profileCategory = (PreferenceCategory) getPreferenceScreen().findPreference(preferenceCategoryKey);
    if (profileCategory != null) {
        profileCategory.removeAll();
        getPreferenceScreen().removePreference(profileCategory);
    }
    mEmptyView.setVisibility(View.GONE);
}
Also used : PreferenceCategory(android.preference.PreferenceCategory)

Example 68 with PreferenceCategory

use of android.preference.PreferenceCategory in project robolectric by robolectric.

the class PreferenceIntegrationTest method inflate_shouldCreateCorrectClasses.

@Test
public void inflate_shouldCreateCorrectClasses() throws Exception {
    final PreferenceScreen screen = inflatePreferenceActivity();
    assertThat(screen.getPreference(0)).isInstanceOf(PreferenceCategory.class);
    PreferenceCategory category = (PreferenceCategory) screen.getPreference(0);
    assertThat(category.getPreference(0)).isInstanceOf(Preference.class);
    PreferenceScreen innerScreen = (PreferenceScreen) screen.getPreference(1);
    assertThat(innerScreen).isInstanceOf(PreferenceScreen.class);
    assertThat(innerScreen.getKey()).isEqualTo("screen");
    assertThat(innerScreen.getTitle().toString()).isEqualTo("Screen Test");
    assertThat(innerScreen.getSummary().toString()).isEqualTo("Screen summary");
    assertThat(innerScreen.getPreference(0)).isInstanceOf(Preference.class);
    assertThat(screen.getPreference(2)).isInstanceOf(CheckBoxPreference.class);
    assertThat(screen.getPreference(3)).isInstanceOf(EditTextPreference.class);
    assertThat(screen.getPreference(4)).isInstanceOf(ListPreference.class);
    assertThat(screen.getPreference(5)).isInstanceOf(Preference.class);
    assertThat(screen.getPreference(6)).isInstanceOf(RingtonePreference.class);
    assertThat(screen.getPreference(7)).isInstanceOf(Preference.class);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) PreferenceCategory(android.preference.PreferenceCategory) Test(org.junit.Test)

Example 69 with PreferenceCategory

use of android.preference.PreferenceCategory in project NimbusBase_Android_Tutorial by NimbusBase.

the class PGFragmentRecord method reload.

protected void reload(Map<String, Integer> typesByAttrName, Map<String, Object> valuesByAttrName) {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.removeAll();
    final Activity context = getActivity();
    final String[] attrNames = typesByAttrName.keySet().toArray(new String[typesByAttrName.size()]);
    for (final String attrName : attrNames) {
        final PreferenceCategory category = new PreferenceCategory(context);
        category.setTitle(attrName);
        preferenceScreen.addPreference(category);
        final Object value = valuesByAttrName.get(attrName);
        final int type = typesByAttrName.get(attrName);
        PGListItemAttribute attrItem = null;
        switch(type) {
            case Cursor.FIELD_TYPE_STRING:
                attrItem = new PGListItemString(context, attrName, (String) value);
                break;
            case // rare case: blob values in non blob column
            Cursor.FIELD_TYPE_BLOB:
                attrItem = new PGListItemBlob(context, attrName, (byte[]) value);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                attrItem = new PGListItemInteger(context, attrName, (Long) value);
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                attrItem = new PGListItemFloat(context, attrName, (Float) value);
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                attrItem = null;
                break;
        }
        if (attrItem != null) {
            attrItem.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    final PGListItemAttribute attrItem = (PGListItemAttribute) preference;
                    final boolean valid = validateValueOfAttributeName(attrItem.getAttributeName(), newValue);
                    if (valid)
                        preference.setTitle(newValue.toString());
                    return valid;
                }
            });
            category.addPreference(attrItem);
        }
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Activity(android.app.Activity) PreferenceCategory(android.preference.PreferenceCategory) Preference(android.preference.Preference)

Example 70 with PreferenceCategory

use of android.preference.PreferenceCategory in project android by cSploit.

the class MsfPreferences method createPreferenceHierarchy.

private PreferenceScreen createPreferenceHierarchy() {
    // Root
    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
    String title = null;
    PreferenceCategory cat_required = new PreferenceCategory(this);
    PreferenceCategory cat_general = new PreferenceCategory(this);
    PreferenceCategory cat_advanced = new PreferenceCategory(this);
    PreferenceCategory cat_evasion = new PreferenceCategory(this);
    ArrayList<Preference> required = new ArrayList<Preference>();
    ArrayList<Preference> general = new ArrayList<Preference>();
    ArrayList<Preference> advanced = new ArrayList<Preference>();
    ArrayList<Preference> evasion = new ArrayList<Preference>();
    Payload payload = System.getCurrentPayload();
    MsfExploit exploit = (MsfExploit) System.getCurrentExploit();
    System.setCurrentPayload(null);
    System.setCurrentExploit(null);
    if (payload != null) {
        options = payload.getOptions();
        title = payload.toString();
    } else if (exploit != null) {
        options = exploit.getOptions();
        title = exploit.toString();
    }
    if (options == null) {
        options = new ArrayList<Option>();
        title = getString(R.string.error);
        String error_message;
        if (exploit != null)
            error_message = String.format("cannot retrieve options for '%s'", exploit.getName());
        else if (payload != null)
            error_message = String.format("cannot retrieve options for '%s'", payload.getName());
        else
            error_message = "called without Payload or MsfExploit";
        Logger.error(error_message);
    }
    setTitle(title + " > " + getString(R.string.menu_settings));
    cat_required.setTitle(R.string.required);
    cat_general.setTitle(R.string.pref_general);
    cat_advanced.setTitle(R.string.pref_advanced);
    cat_evasion.setTitle(R.string.evasion);
    for (Option opt : options) {
        Preference item = null;
        int inputType = 0;
        switch(opt.getType()) {
            case ADDRESS:
            case STRING:
            case PATH:
            case INTEGER:
            case PORT:
                item = new EditTextPreference(this);
                item.setTitle(opt.getName());
                ((EditTextPreference) item).setDialogTitle(opt.getName());
                ((EditTextPreference) item).setDialogMessage(opt.getDescription());
                item.setSummary(opt.getDescription());
                item.setKey(opt.getName());
                item.setDefaultValue(opt.getValue());
                break;
            case BOOLEAN:
                item = new CheckBoxPreference(this);
                item.setTitle(opt.getName());
                item.setKey(opt.getName());
                item.setSummary(opt.getDescription());
                ((CheckBoxPreference) item).setChecked(opt.getValue().equals("true"));
                break;
            case ENUM:
                item = new ListPreference(this);
                ((ListPreference) item).setEntries(opt.getEnum());
                ((ListPreference) item).setEntryValues(opt.getEnum());
                ((ListPreference) item).setDialogTitle(opt.getName());
                ((ListPreference) item).setValue(opt.getValue());
                item.setKey(opt.getName());
                item.setTitle(opt.getName());
                item.setSummary(opt.getDescription());
                break;
        }
        switch(opt.getType()) {
            case ADDRESS:
                inputType = InputType.TYPE_CLASS_PHONE;
                break;
            case PATH:
            case STRING:
                inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
                break;
            case PORT:
            case INTEGER:
                inputType = InputType.TYPE_CLASS_NUMBER;
                break;
        }
        if (inputType != 0)
            ((EditTextPreference) item).getEditText().setInputType(inputType);
        if (opt.isAdvanced())
            advanced.add(item);
        else if (opt.isRequired())
            required.add(item);
        else if (opt.isEvasion())
            evasion.add(item);
        else
            general.add(item);
        item.setOnPreferenceChangeListener(listener);
    }
    if (required.size() > 0) {
        root.addPreference(cat_required);
        for (Preference i : required) cat_required.addPreference(i);
    }
    if (general.size() > 0) {
        root.addPreference(cat_general);
        for (Preference i : general) cat_general.addPreference(i);
    }
    if (advanced.size() > 0) {
        root.addPreference(cat_advanced);
        for (Preference i : advanced) cat_advanced.addPreference(i);
    }
    if (evasion.size() > 0) {
        root.addPreference(cat_evasion);
        for (Preference i : evasion) cat_evasion.addPreference(i);
    }
    return root;
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayList(java.util.ArrayList) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) MsfExploit(org.csploit.android.net.metasploit.MsfExploit) Payload(org.csploit.android.net.metasploit.Payload) Option(org.csploit.android.net.metasploit.Option)

Aggregations

PreferenceCategory (android.preference.PreferenceCategory)80 Preference (android.preference.Preference)49 PreferenceScreen (android.preference.PreferenceScreen)31 ListPreference (android.preference.ListPreference)30 CheckBoxPreference (android.preference.CheckBoxPreference)26 Intent (android.content.Intent)19 EditTextPreference (android.preference.EditTextPreference)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 SwitchPreference (android.preference.SwitchPreference)8 ArrayList (java.util.ArrayList)7 Uri (android.net.Uri)6 Bundle (android.os.Bundle)5 SharedPreferences (android.content.SharedPreferences)4 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)4 View (android.view.View)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 Context (android.content.Context)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 RingtonePreference (android.preference.RingtonePreference)3 ListView (android.widget.ListView)3