Search in sources :

Example 31 with ListPreference

use of android.preference.ListPreference in project openScale by oliexdev.

the class GeneralPreferences method updatePrefSummary.

private void updatePrefSummary(Preference p) {
    if (p instanceof ListPreference) {
        ListPreference listPref = (ListPreference) p;
        p.setSummary(listPref.getEntry());
    }
    if (p instanceof EditTextPreference) {
        EditTextPreference editTextPref = (EditTextPreference) p;
        if (p.getTitle().toString().contains("assword")) {
            p.setSummary("******");
        } else {
            p.setSummary(editTextPref.getText());
        }
    }
    if (p instanceof MultiSelectListPreference) {
        MultiSelectListPreference editMultiListPref = (MultiSelectListPreference) p;
        CharSequence[] entries = editMultiListPref.getEntries();
        CharSequence[] entryValues = editMultiListPref.getEntryValues();
        List<String> currentEntries = new ArrayList<>();
        Set<String> currentEntryValues = editMultiListPref.getValues();
        for (int i = 0; i < entries.length; i++) {
            if (currentEntryValues.contains(entryValues[i].toString()))
                currentEntries.add(entries[i].toString());
        }
        p.setSummary(currentEntries.toString());
    }
}
Also used : ArrayList(java.util.ArrayList) MultiSelectListPreference(android.preference.MultiSelectListPreference) ListPreference(android.preference.ListPreference) MultiSelectListPreference(android.preference.MultiSelectListPreference) EditTextPreference(android.preference.EditTextPreference)

Example 32 with ListPreference

use of android.preference.ListPreference in project openScale by oliexdev.

the class FloatMeasurementView method prepareExtraPreferencesScreen.

@Override
public void prepareExtraPreferencesScreen(PreferenceScreen screen) {
    MeasurementViewSettings settings = getSettings();
    CheckBoxPreference overview = new CheckBoxPreference(screen.getContext());
    overview.setKey(settings.getInOverviewGraphKey());
    overview.setTitle(R.string.label_include_in_overview_graph);
    overview.setPersistent(true);
    overview.setDefaultValue(settings.isInOverviewGraph());
    screen.addPreference(overview);
    if (canConvertPercentageToAbsoluteWeight()) {
        SwitchPreference percentage = new SwitchPreference(screen.getContext());
        percentage.setKey(settings.getPercentageEnabledKey());
        percentage.setTitle(R.string.label_measurement_in_percent);
        percentage.setPersistent(true);
        percentage.setDefaultValue(settings.isPercentageEnabled());
        screen.addPreference(percentage);
    }
    if (isEstimationSupported()) {
        final CheckBoxPreference estimate = new CheckBoxPreference(screen.getContext());
        estimate.setKey(settings.getEstimationEnabledKey());
        estimate.setTitle(R.string.label_estimate_measurement);
        estimate.setSummary(R.string.label_estimate_measurement_summary);
        estimate.setPersistent(true);
        estimate.setDefaultValue(settings.isEstimationEnabled());
        screen.addPreference(estimate);
        final ListPreference formula = new ListPreference(screen.getContext());
        formula.setKey(settings.getEstimationFormulaKey());
        formula.setTitle(R.string.label_estimation_formula);
        formula.setPersistent(true);
        formula.setDefaultValue(settings.getEstimationFormula());
        prepareEstimationFormulaPreference(formula);
        formula.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                ListPreference list = (ListPreference) preference;
                int idx = list.findIndexOfValue((String) newValue);
                if (idx == -1) {
                    return false;
                }
                preference.setSummary(list.getEntries()[idx]);
                return true;
            }
        });
        final ListAdapter adapter = screen.getRootAdapter();
        adapter.registerDataSetObserver(new DataSetObserver() {

            @Override
            public void onChanged() {
                adapter.unregisterDataSetObserver(this);
                formula.setDependency(estimate.getKey());
                formula.setSummary(formula.getEntry());
            }
        });
        screen.addPreference(formula);
    }
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) SwitchPreference(android.preference.SwitchPreference) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) ListPreference(android.preference.ListPreference) DataSetObserver(android.database.DataSetObserver) ListAdapter(android.widget.ListAdapter)

Example 33 with ListPreference

use of android.preference.ListPreference in project GeometricWeather by WangDaYeeeeee.

the class SettingsFragment method initNotificationPart.

private void initNotificationPart(SharedPreferences sharedPreferences) {
    // widget icon style.
    ListPreference notificationIconStyle = (ListPreference) findPreference(getString(R.string.key_notification_icon_style));
    notificationIconStyle.setSummary(ValueUtils.getIconStyle(getActivity(), sharedPreferences.getString(getString(R.string.key_notification_icon_style), "material")));
    notificationIconStyle.setOnPreferenceChangeListener(this);
    // notification temp icon.
    CheckBoxPreference notificationTempIcon = (CheckBoxPreference) findPreference(getString(R.string.key_notification_temp_icon));
    // notification text color.
    ListPreference notificationTextColor = (ListPreference) findPreference(getString(R.string.key_notification_text_color));
    notificationTextColor.setSummary(ValueUtils.getNotificationTextColor(getActivity(), sharedPreferences.getString(getString(R.string.key_notification_text_color), "grey")));
    notificationTextColor.setOnPreferenceChangeListener(this);
    // notification background.
    CheckBoxPreference notificationBackground = (CheckBoxPreference) findPreference(getString(R.string.key_notification_background));
    // notification can be cleared.
    CheckBoxPreference notificationClearFlag = (CheckBoxPreference) findPreference(getString(R.string.key_notification_can_be_cleared));
    // notification hide icon.
    CheckBoxPreference notificationIconBehavior = (CheckBoxPreference) findPreference(getString(R.string.key_notification_hide_icon));
    // notification hide in lock screen.
    CheckBoxPreference notificationHideBehavior = (CheckBoxPreference) findPreference(getString(R.string.key_notification_hide_in_lockScreen));
    // notification hide big view.
    CheckBoxPreference notificationHideBigView = (CheckBoxPreference) findPreference(getString(R.string.key_notification_hide_big_view));
    if (sharedPreferences.getBoolean(getString(R.string.key_notification), false)) {
        // open notification.
        notificationIconStyle.setEnabled(true);
        notificationTempIcon.setEnabled(true);
        notificationTextColor.setEnabled(true);
        notificationBackground.setEnabled(true);
        notificationClearFlag.setEnabled(true);
        notificationIconBehavior.setEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            notificationHideBehavior.setEnabled(true);
        } else {
            notificationHideBehavior.setEnabled(false);
        }
        notificationHideBigView.setEnabled(true);
    } else {
        // close notification.
        notificationIconStyle.setEnabled(false);
        notificationTempIcon.setEnabled(false);
        notificationTextColor.setEnabled(false);
        notificationBackground.setEnabled(false);
        notificationClearFlag.setEnabled(false);
        notificationIconBehavior.setEnabled(false);
        notificationHideBehavior.setEnabled(false);
        notificationHideBigView.setEnabled(false);
    }
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference)

Example 34 with ListPreference

use of android.preference.ListPreference in project GeometricWeather by WangDaYeeeeee.

the class SettingsFragment method initWidgetPart.

private void initWidgetPart(SharedPreferences sharedPreferences) {
    // widget icon style.
    ListPreference widgetIconStyle = (ListPreference) findPreference(getString(R.string.key_widget_icon_style));
    widgetIconStyle.setSummary(ValueUtils.getIconStyle(getActivity(), sharedPreferences.getString(getString(R.string.key_widget_icon_style), "material")));
    widgetIconStyle.setOnPreferenceChangeListener(this);
}
Also used : ListPreference(android.preference.ListPreference)

Example 35 with ListPreference

use of android.preference.ListPreference in project Osmand by osmandapp.

the class SettingsAudioVideoActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    ((OsmandApplication) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);
    getToolbar().setTitle(R.string.av_settings);
    PreferenceScreen grp = getPreferenceScreen();
    AudioVideoNotesPlugin p = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
    if (p != null) {
        String[] entries;
        Integer[] intValues;
        entries = new String[] { getString(R.string.av_def_action_choose), getString(R.string.av_def_action_audio), getString(R.string.av_def_action_video), getString(R.string.av_def_action_picture) };
        intValues = new Integer[] { AV_DEFAULT_ACTION_CHOOSE, AV_DEFAULT_ACTION_AUDIO, AV_DEFAULT_ACTION_VIDEO, AV_DEFAULT_ACTION_TAKEPICTURE };
        ListPreference defAct = createListPreference(p.AV_DEFAULT_ACTION, entries, intValues, R.string.av_widget_action, R.string.av_widget_action_descr);
        grp.addPreference(defAct);
        PreferenceCategory photo = new PreferenceCategory(this);
        photo.setTitle(R.string.shared_string_photo);
        grp.addPreference(photo);
        final Camera cam = openCamera();
        if (cam != null) {
            // camera type settings
            photo.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_PHOTO_CAM, R.string.av_use_external_camera, R.string.av_use_external_camera_descr));
            Parameters parameters = cam.getParameters();
            // Photo picture size
            // get supported sizes
            List<Camera.Size> psps = parameters.getSupportedPictureSizes();
            // list of megapixels of each resolution
            List<Integer> mpix = new ArrayList<Integer>();
            // list of index each resolution in list, returned by getSupportedPictureSizes()
            List<Integer> picSizesValues = new ArrayList<Integer>();
            // fill lists for sort
            for (int index = 0; index < psps.size(); index++) {
                mpix.add((psps.get(index)).width * (psps.get(index)).height);
                picSizesValues.add(index);
            }
            // sort list for max resolution in begining of list
            for (int i = 0; i < mpix.size(); i++) {
                for (int j = 0; j < mpix.size() - i - 1; j++) {
                    if (mpix.get(j) < mpix.get(j + 1)) {
                        // change elements
                        int tmp = mpix.get(j + 1);
                        mpix.set(j + 1, mpix.get(j));
                        mpix.set(j, tmp);
                        tmp = picSizesValues.get(j + 1);
                        picSizesValues.set(j + 1, picSizesValues.get(j));
                        picSizesValues.set(j, tmp);
                    }
                }
            }
            // set default photo size to max resolution (set index of element with max resolution in List, returned by getSupportedPictureSizes() )
            cameraPictureSizeDefault = picSizesValues.get(0);
            log.debug("onCreate() set cameraPictureSizeDefault=" + cameraPictureSizeDefault);
            List<String> itemsPicSizes = new ArrayList<String>();
            String prefix;
            for (int index = 0; index < psps.size(); index++) {
                float px = (float) ((psps.get(picSizesValues.get(index))).width * (psps.get(picSizesValues.get(index))).height);
                if (// 100 K
                px > 102400) {
                    px = px / 1048576;
                    prefix = "Mpx";
                } else {
                    px = px / 1024;
                    prefix = "Kpx";
                }
                itemsPicSizes.add((psps.get(picSizesValues.get(index))).width + "x" + (psps.get(picSizesValues.get(index))).height + " ( " + String.format("%.2f", px) + " " + prefix + " )");
            }
            log.debug("onCreate() set default size: width=" + psps.get(cameraPictureSizeDefault).width + " height=" + psps.get(cameraPictureSizeDefault).height + " index in ps=" + cameraPictureSizeDefault);
            entries = itemsPicSizes.toArray(new String[itemsPicSizes.size()]);
            intValues = picSizesValues.toArray(new Integer[picSizesValues.size()]);
            if (entries.length > 0) {
                ListPreference camSizes = createListPreference(p.AV_CAMERA_PICTURE_SIZE, entries, intValues, R.string.av_camera_pic_size, R.string.av_camera_pic_size_descr);
                photo.addPreference(camSizes);
            }
            // focus mode settings
            // show in menu only suppoted modes
            List<String> sfm = parameters.getSupportedFocusModes();
            List<String> items = new ArrayList<String>();
            List<Integer> itemsValues = new ArrayList<Integer>();
            // filtering known types for translate and set index
            for (int index = 0; index < sfm.size(); index++) {
                if (sfm.get(index).equals("auto")) {
                    items.add(getString(R.string.av_camera_focus_auto));
                    itemsValues.add(AV_CAMERA_FOCUS_AUTO);
                } else if (sfm.get(index).equals("fixed")) {
                    items.add(getString(R.string.av_camera_focus_hiperfocal));
                    itemsValues.add(AV_CAMERA_FOCUS_HIPERFOCAL);
                } else if (sfm.get(index).equals("edof")) {
                    items.add(getString(R.string.av_camera_focus_edof));
                    itemsValues.add(AV_CAMERA_FOCUS_EDOF);
                } else if (sfm.get(index).equals("infinity")) {
                    items.add(getString(R.string.av_camera_focus_infinity));
                    itemsValues.add(AV_CAMERA_FOCUS_INFINITY);
                } else if (sfm.get(index).equals("macro")) {
                    items.add(getString(R.string.av_camera_focus_macro));
                    itemsValues.add(AV_CAMERA_FOCUS_MACRO);
                } else if (sfm.get(index).equals("continuous-picture")) {
                    items.add(getString(R.string.av_camera_focus_continuous));
                    itemsValues.add(AV_CAMERA_FOCUS_CONTINUOUS);
                }
            }
            entries = items.toArray(new String[items.size()]);
            intValues = itemsValues.toArray(new Integer[itemsValues.size()]);
            if (entries.length > 0) {
                ListPreference camFocus = createListPreference(p.AV_CAMERA_FOCUS_TYPE, entries, intValues, R.string.av_camera_focus, R.string.av_camera_focus_descr);
                photo.addPreference(camFocus);
            }
            // play sound on success photo
            photo.addPreference(createCheckBoxPreference(p.AV_PHOTO_PLAY_SOUND, R.string.av_photo_play_sound, R.string.av_photo_play_sound_descr));
            cam.release();
        }
        // video settings
        PreferenceCategory video = new PreferenceCategory(this);
        video.setTitle(R.string.shared_string_video);
        grp.addPreference(video);
        video.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_RECORDER, R.string.av_use_external_recorder, R.string.av_use_external_recorder_descr));
        // entries = new String[] { "3GP", "MP4" };
        // intValues = new Integer[] { VIDEO_OUTPUT_3GP, VIDEO_OUTPUT_MP4 };
        // ListPreference lp = createListPreference(p.AV_VIDEO_FORMAT, entries, intValues, R.string.av_video_format,
        // R.string.av_video_format_descr);
        // video.addPreference(lp);
        List<String> qNames = new ArrayList<>();
        List<Integer> qValues = new ArrayList<>();
        if (Build.VERSION.SDK_INT < 11 || CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_LOW)) {
            qNames.add(getString(R.string.av_video_quality_low));
            qValues.add(CamcorderProfile.QUALITY_LOW);
        }
        if (Build.VERSION.SDK_INT >= 11 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) {
            qNames.add("720 x 480 (480p)");
            qValues.add(CamcorderProfile.QUALITY_480P);
        }
        if (Build.VERSION.SDK_INT >= 11 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
            qNames.add("1280 x 720 (720p)");
            qValues.add(CamcorderProfile.QUALITY_720P);
        }
        if (Build.VERSION.SDK_INT >= 11 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P)) {
            qNames.add("1920 x 1080 (1080p)");
            qValues.add(CamcorderProfile.QUALITY_1080P);
        }
        if (Build.VERSION.SDK_INT >= 21 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_2160P)) {
            qNames.add("3840x2160 (2160p)");
            qValues.add(CamcorderProfile.QUALITY_2160P);
        }
        if (Build.VERSION.SDK_INT < 11 || CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_HIGH)) {
            qNames.add(getString(R.string.av_video_quality_high));
            qValues.add(CamcorderProfile.QUALITY_HIGH);
        }
        ListPreference lp = createListPreference(p.AV_VIDEO_QUALITY, qNames.toArray(new String[qNames.size()]), qValues.toArray(new Integer[qValues.size()]), R.string.av_video_quality, R.string.av_video_quality_descr);
        video.addPreference(lp);
        // Recorder Split settings
        PreferenceCategory recSplit = new PreferenceCategory(this);
        recSplit.setTitle(R.string.rec_split);
        grp.addPreference(recSplit);
        recSplit.addPreference(createCheckBoxPreference(p.AV_RECORDER_SPLIT, R.string.rec_split_title, R.string.rec_split_desc));
        intValues = new Integer[] { 1, 2, 3, 4, 5, 7, 10, 15, 20, 25, 30 };
        entries = new String[intValues.length];
        int i = 0;
        String minStr = getString(R.string.int_min);
        for (int v : intValues) {
            entries[i++] = String.valueOf(v) + " " + minStr;
        }
        lp = createListPreference(p.AV_RS_CLIP_LENGTH, entries, intValues, R.string.rec_split_clip_length, R.string.rec_split_clip_length_desc);
        recSplit.addPreference(lp);
        File dir = getMyApplication().getAppPath("").getParentFile();
        long size = 0;
        if (dir.canRead()) {
            StatFs fs = new StatFs(dir.getAbsolutePath());
            size = ((long) fs.getBlockSize() * (long) fs.getBlockCount()) / (1 << 30);
        }
        if (size > 0) {
            int value = 1;
            ArrayList<Integer> gbList = new ArrayList<>();
            while (value < size) {
                gbList.add(value);
                if (value < 5) {
                    value++;
                } else {
                    value += 5;
                }
            }
            if (value != size) {
                gbList.add((int) size);
            }
            MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
            entries = new String[gbList.size()];
            intValues = new Integer[gbList.size()];
            i = 0;
            for (int v : gbList) {
                intValues[i] = v;
                entries[i] = formatGb.format(new Object[] { (float) v });
                i++;
            }
            lp = createListPreference(p.AV_RS_STORAGE_SIZE, entries, intValues, R.string.rec_split_storage_size, R.string.rec_split_storage_size_desc);
            recSplit.addPreference(lp);
        }
        // audio settings
        PreferenceCategory audio = new PreferenceCategory(this);
        audio.setTitle(R.string.shared_string_audio);
        grp.addPreference(audio);
        entries = new String[] { "Default", "AAC" };
        intValues = new Integer[] { MediaRecorder.AudioEncoder.DEFAULT, MediaRecorder.AudioEncoder.AAC };
        lp = createListPreference(p.AV_AUDIO_FORMAT, entries, intValues, R.string.av_audio_format, R.string.av_audio_format_descr);
        audio.addPreference(lp);
        entries = new String[] { "Default", "16 kbps", "32 kbps", "48 kbps", "64 kbps", "96 kbps", "128 kbps" };
        intValues = new Integer[] { AUDIO_BITRATE_DEFAULT, 16 * 1024, 32 * 1024, 48 * 1024, 64 * 1024, 96 * 1024, 128 * 1024 };
        lp = createListPreference(p.AV_AUDIO_BITRATE, entries, intValues, R.string.av_audio_bitrate, R.string.av_audio_bitrate_descr);
        audio.addPreference(lp);
    }
}
Also used : Parameters(android.hardware.Camera.Parameters) OsmandApplication(net.osmand.plus.OsmandApplication) PreferenceScreen(android.preference.PreferenceScreen) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ListPreference(android.preference.ListPreference) StatFs(android.os.StatFs) PreferenceCategory(android.preference.PreferenceCategory) Camera(android.hardware.Camera) File(java.io.File)

Aggregations

ListPreference (android.preference.ListPreference)152 Preference (android.preference.Preference)76 CheckBoxPreference (android.preference.CheckBoxPreference)47 EditTextPreference (android.preference.EditTextPreference)32 PreferenceScreen (android.preference.PreferenceScreen)20 ArrayList (java.util.ArrayList)18 SharedPreferences (android.content.SharedPreferences)17 Intent (android.content.Intent)14 PreferenceCategory (android.preference.PreferenceCategory)14 SuppressLint (android.annotation.SuppressLint)13 MultiSelectListPreference (android.preference.MultiSelectListPreference)8 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 File (java.io.File)8 Bundle (android.os.Bundle)7 SwitchPreference (android.preference.SwitchPreference)7 View (android.view.View)7 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 RingtonePreference (android.preference.RingtonePreference)6