Search in sources :

Example 1 with ListPreference

use of androidx.preference.ListPreference in project fresco by facebook.

the class SettingsFragment method updateGridRecyclerLayoutSummary.

private void updateGridRecyclerLayoutSummary() {
    final ListPreference listPreference = (ListPreference) findPreference(Const.RECYCLER_LAYOUT_KEY);
    // We have to enable the Grid settings only if the selection is the related on
    final ListPreference gridPreference = (ListPreference) findPreference(Const.GRID_SPAN_COUNT_KEY);
    final String value = listPreference.getValue();
    final boolean gridGroupVisible = Const.GRID_RECYCLER_VIEW_LAYOUT_VALUE.equals(value);
    // We update summary
    if (gridGroupVisible) {
        final String spanCountValue = gridPreference.getValue();
        gridPreference.setSummary(getString(R.string.label_grid_recycler_span_count_summary, spanCountValue));
    }
    gridPreference.setVisible(gridGroupVisible);
}
Also used : ListPreference(androidx.preference.ListPreference)

Example 2 with ListPreference

use of androidx.preference.ListPreference in project kcanotify by antest1.

the class MainPreferenceFragment method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (sHandler != null) {
        JsonObject dmpData = new JsonObject();
        String kca_url = "";
        Bundle bundle = new Bundle();
        switch(key) {
            case PREF_KCA_SEEK_CN:
                kca_url = KCA_API_PREF_CN_CHANGED;
                break;
            case PREF_KCA_EXP_VIEW:
                kca_url = KCA_API_PREF_EXPVIEW_CHANGED;
                break;
            case PREF_KCA_SET_PRIORITY:
                kca_url = KCA_API_PREF_PRIORITY_CHANGED;
                break;
            case PREF_FAIRY_SIZE:
                kca_url = KCA_API_PREF_FAIRYSIZE_CHANGED;
                break;
            default:
                break;
        }
        if (kca_url.length() > 0) {
            bundle.putString("url", kca_url);
            bundle.putString("data", gson.toJson(dmpData));
            Message sMsg = sHandler.obtainMessage();
            sMsg.setData(bundle);
            sHandler.sendMessage(sMsg);
        }
    }
    Preference preference = findPreference(key);
    if (preference instanceof ListPreference) {
        ListPreference lp = (ListPreference) preference;
        if (!preference.getKey().equals(PREF_KCA_HP_FORMAT)) {
            // PREF_KCA_HP_FORMAT already has a summary
            preference.setSummary(lp.getEntry());
        }
    }
    if (preference instanceof EditTextPreference) {
        EditTextPreference etp = (EditTextPreference) preference;
        preference.setSummary(getEditTextSummary(key, etp.getText()));
    }
}
Also used : Message(android.os.Message) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) Bundle(android.os.Bundle) JsonObject(com.google.gson.JsonObject) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference)

Example 3 with ListPreference

use of androidx.preference.ListPreference in project Gadgetbridge by Freeyourgadget.

the class DeviceSpecificSettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Bundle arguments = getArguments();
    if (arguments == null) {
        return;
    }
    String settingsFileSuffix = arguments.getString("settingsFileSuffix", null);
    int[] supportedSettings = arguments.getIntArray("supportedSettings");
    String[] supportedLanguages = arguments.getStringArray("supportedLanguages");
    this.deviceSpecificSettingsCustomizer = arguments.getParcelable("deviceSpecificSettingsCustomizer");
    if (settingsFileSuffix == null || supportedSettings == null) {
        return;
    }
    getPreferenceManager().setSharedPreferencesName("devicesettings_" + settingsFileSuffix);
    if (rootKey == null) {
        // we are the main preference screen
        boolean first = true;
        for (int setting : supportedSettings) {
            if (first) {
                setPreferencesFromResource(setting, null);
                first = false;
            } else {
                addPreferencesFromResource(setting);
            }
            if (setting == R.xml.devicesettings_language_generic) {
                ListPreference languageListPreference = findPreference("language");
                CharSequence[] entries = languageListPreference.getEntries();
                CharSequence[] values = languageListPreference.getEntryValues();
                for (int i = entries.length - 1; i >= 0; i--) {
                    if (!ArrayUtils.contains(supportedLanguages, values[i])) {
                        entries = ArrayUtils.remove(entries, i);
                        values = ArrayUtils.remove(values, i);
                    }
                }
                languageListPreference.setEntries(entries);
                languageListPreference.setEntryValues(values);
            }
        }
    } else {
        // Now, this is ugly: search all the xml files for the rootKey
        for (int setting : supportedSettings) {
            try {
                setPreferencesFromResource(setting, rootKey);
            } catch (Exception ignore) {
                continue;
            }
            break;
        }
    }
    setChangeListener();
}
Also used : Bundle(android.os.Bundle) DragSortListPreference(com.mobeta.android.dslv.DragSortListPreference) ListPreference(androidx.preference.ListPreference)

Example 4 with ListPreference

use of androidx.preference.ListPreference in project Gadgetbridge by Freeyourgadget.

the class SonyHeadphonesSettingsCustomizer method customizeSettings.

@Override
public void customizeSettings(final DeviceSpecificSettingsHandler handler) {
    // Only enable the focus on voice check and voice level slider if the ambient sound control mode is ambient sound
    final ListPreference ambientSoundControl = handler.findPreference(PREF_SONY_AMBIENT_SOUND_CONTROL);
    if (ambientSoundControl != null) {
        final Preference focusOnVoice = handler.findPreference(PREF_SONY_FOCUS_VOICE);
        final Preference ambientSoundLevel = handler.findPreference(PREF_SONY_AMBIENT_SOUND_LEVEL);
        final Preference.OnPreferenceChangeListener ambientSoundControlPrefListener = new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newVal) {
                boolean isAmbientSoundEnabled = AmbientSoundControl.Mode.AMBIENT_SOUND.name().toLowerCase(Locale.getDefault()).equals(newVal);
                focusOnVoice.setEnabled(isAmbientSoundEnabled);
                ambientSoundLevel.setEnabled(isAmbientSoundEnabled);
                return true;
            }
        };
        ambientSoundControlPrefListener.onPreferenceChange(ambientSoundControl, ambientSoundControl.getValue());
        handler.addPreferenceHandlerFor(PREF_SONY_AMBIENT_SOUND_CONTROL, ambientSoundControlPrefListener);
    }
    // ANC Optimizer
    final Preference ancOptimizer = handler.findPreference("pref_sony_anc_optimizer");
    if (ancOptimizer != null) {
        ancOptimizer.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(final Preference preference) {
                if (ancOptimizerProgressDialog != null) {
                    // Already optimizing
                    return true;
                }
                final Context context = preference.getContext();
                new AlertDialog.Builder(context).setTitle(R.string.sony_anc_optimize_confirmation_title).setMessage(R.string.sony_anc_optimize_confirmation_description).setIcon(R.drawable.ic_hearing).setPositiveButton(R.string.start, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int whichButton) {
                        handler.notifyPreferenceChanged(PREF_SONY_NOISE_OPTIMIZER_START);
                        ancOptimizerProgressDialog = new ProgressDialog(context);
                        ancOptimizerProgressDialog.setCancelable(false);
                        ancOptimizerProgressDialog.setMessage(context.getString(R.string.sony_anc_optimizer_status_starting));
                        ancOptimizerProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        ancOptimizerProgressDialog.setProgress(0);
                        ancOptimizerProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.Cancel), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                dialog.dismiss();
                                ancOptimizerProgressDialog = null;
                                handler.notifyPreferenceChanged(PREF_SONY_NOISE_OPTIMIZER_CANCEL);
                            }
                        });
                        ancOptimizerProgressDialog.show();
                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
                return true;
            }
        });
    }
}
Also used : Context(android.content.Context) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ListPreference(androidx.preference.ListPreference) ProgressDialog(android.app.ProgressDialog) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference)

Example 5 with ListPreference

use of androidx.preference.ListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    doReturn(mSpyResources).when(mSpyContext).getResources();
    // Get XML values without mock
    // Setup test list preference using XML values
    mPreference = new ListPreference(mSpyContext);
    mPreference.setEntries(R.array.bluetooth_max_connected_audio_devices);
    mPreference.setEntryValues(R.array.bluetooth_max_connected_audio_devices_values);
    // Stub default max connected audio devices to a test controlled value
    doReturn(TEST_MAX_CONNECTED_AUDIO_DEVICES).when(mSpyResources).getInteger(com.android.internal.R.integer.config_bluetooth_max_connected_audio_devices);
    // Init the actual controller
    mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mSpyContext);
    // Construct preference in the controller via a mocked preference screen object
    when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
    mController.displayPreference(mPreferenceScreen);
    mListValues = mPreference.getEntryValues();
    mListEntries = mPreference.getEntries();
}
Also used : ListPreference(androidx.preference.ListPreference) Before(org.junit.Before)

Aggregations

ListPreference (androidx.preference.ListPreference)98 Preference (androidx.preference.Preference)15 Test (org.junit.Test)14 Before (org.junit.Before)11 EditTextPreference (androidx.preference.EditTextPreference)8 PreferenceScreen (androidx.preference.PreferenceScreen)7 SwitchPreference (androidx.preference.SwitchPreference)6 Intent (android.content.Intent)5 ContentResolver (android.content.ContentResolver)4 Context (android.content.Context)4 Resources (android.content.res.Resources)4 WifiConfiguration (android.net.wifi.WifiConfiguration)4 Bundle (android.os.Bundle)4 PersistableBundle (android.os.PersistableBundle)4 MultiSelectListPreference (androidx.preference.MultiSelectListPreference)3 Activity (android.app.Activity)2 BluetoothManager (android.bluetooth.BluetoothManager)2 RestrictionEntry (android.content.RestrictionEntry)2 OverlayInfo (android.content.om.OverlayInfo)2 ApplicationInfo (android.content.pm.ApplicationInfo)2