Java Code Examples for androidx.preference.ListPreference#setOnPreferenceChangeListener()

The following examples show how to use androidx.preference.ListPreference#setOnPreferenceChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsFragment.java    From android-DarkTheme with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    ListPreference themePreference = findPreference("themePref");
    if (themePreference != null) {
        themePreference.setOnPreferenceChangeListener(
                new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        String themeOption = (String) newValue;
                        ThemeHelper.applyTheme(themeOption);
                        return true;
                    }
                });
    }
}
 
Example 2
Source File: SettingsFragment.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    ListPreference themePreference = findPreference("themePref");
    if (themePreference != null) {
        themePreference.setOnPreferenceChangeListener(
                new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        String themeOption = (String) newValue;
                        ThemeHelper.applyTheme(themeOption);
                        return true;
                    }
                });
    }
}
 
Example 3
Source File: GeneralPreferenceFragment.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private void initStoragePaths(ListPreference storagePreference) {
    if(Build.VERSION.SDK_INT<Build.VERSION_CODES.KITKAT||!Global.hasStoragePermission(act)){
        storagePreference.setVisible(false);
        return;
    }
    List<File>files=Global.getUsableFolders(act);
    List<CharSequence>strings=new ArrayList<>(files.size());
    for(File f:files)strings.add(f.getAbsolutePath());
    storagePreference.setEntries(strings.toArray(new CharSequence[0]));
    storagePreference.setEntryValues(strings.toArray(new CharSequence[0]));
    storagePreference.setSummary(
            act.getSharedPreferences("Settings",Context.MODE_PRIVATE)
                    .getString(getString(R.string.key_save_path),Global.MAINFOLDER.getParent())
    );
    storagePreference.setOnPreferenceChangeListener((preference, newValue) -> {
        preference.setSummary(newValue.toString());
        return true;
    });
}
 
Example 4
Source File: DesktopPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ListPreference orientationMode = findPreference("orientation_mode");

    orientationMode.setOnPreferenceChangeListener(RotatingListListener);

    // Window bar hiding works only reliably in KitKat and above.
    if (Utils.atLeastKitKat()) {
        findPreference("windowbar_mode").setVisible(true);
    } else {
        findPreference("windowbar_status_switch").setVisible(true);
    }
}
 
Example 5
Source File: SettingsFragment.java    From Kore with Apache License 2.0 5 votes vote down vote up
private void setupLanguagePreference(final ListPreference languagePref) {
    Locale[] locales = getLocales();

    final Locale currentLocale = getCurrentLocale();
    Arrays.sort(locales, new Comparator<Locale>() {
        @Override
        public int compare(Locale o1, Locale o2) {
            return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
        }
    });

    String[] displayNames = new String[locales.length];
    String[] entryValues = new String[locales.length];
    for(int index = 0; index < locales.length; index++) {
        Locale locale = locales[index];
        displayNames[index] = locale.getDisplayName(locale);
        entryValues[index] = getLanguageCountryCode(locale);
    }

    languagePref.setValue(getLanguageCountryCode(currentLocale));
    languagePref.setEntries(displayNames);
    languagePref.setEntryValues(entryValues);
    languagePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            languagePref.setValue(o.toString());
            updatePreferredLanguage(o.toString());
            return true;
        }
    });
}
 
Example 6
Source File: NotificationColorSettingsFragment.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initNotificationPart() {
    // notification custom color.
    findPreference(getString(R.string.key_notification_custom_color)).setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setNotificationCustomColorEnabled((Boolean) newValue);
        initNotificationPart();
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        return true;
    });

    // notification background.
    ColorPreferenceCompat notificationBackgroundColor = findPreference(getString(R.string.key_notification_background_color));
    notificationBackgroundColor.setEnabled(getSettingsOptionManager().isNotificationCustomColorEnabled());
    notificationBackgroundColor.setOnPreferenceChangeListener((preference, newValue) -> {
        getSettingsOptionManager().setNotificationBackgroundColor((Integer) newValue);
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        return true;
    });

    // notification text color.
    ListPreference notificationTextColor = findPreference(getString(R.string.key_notification_text_color));
    notificationTextColor.setSummary(
            getSettingsOptionManager().getNotificationTextColor().getNotificationTextColorName(
                    getActivity()
            )
    );
    notificationTextColor.setOnPreferenceChangeListener((preference, newValue) -> {
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        preference.setSummary(
                getSettingsOptionManager().getNotificationTextColor().getNotificationTextColorName(
                        getActivity()
                )
        );
        return true;
    });
}
 
Example 7
Source File: GeneralPrefsFragment.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
private void setupPrefs() {
    final ListPreference bookmarkCount = (ListPreference) findPreference(getString(R.string.nav_drawer_bookmark_count_pref));
    bookmarkCount.setSummary(String.valueOf(MimiPrefs.navDrawerBookmarkCount(getActivity())));
    bookmarkCount.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String val = String.valueOf(newValue);
            bookmarkCount.setSummary(val);

            return true;
        }
    });
}
 
Example 8
Source File: GesturesPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    getAppList();

    ListPreference gestureLeftList = findPreference("gesture_left");
    ListPreference gestureRightList = findPreference("gesture_right");
    ListPreference gestureDownList = findPreference("gesture_down");
    ListPreference gestureUpList = findPreference("gesture_up");
    ListPreference gestureTapList = findPreference("gesture_single_tap");
    ListPreference gestureDoubleTapList = findPreference("gesture_double_tap");
    ListPreference gesturePinchList = findPreference("gesture_pinch");
    ListPreference gestureHandlerList = findPreference("gesture_handler");

    setNestedListSummary(gestureLeftList);
    setNestedListSummary(gestureRightList);
    setNestedListSummary(gestureDownList);
    setNestedListSummary(gestureUpList);
    setNestedListSummary(gestureTapList);
    setNestedListSummary(gestureDoubleTapList);
    setNestedListSummary(gesturePinchList);

    setGestureHandlerList(gestureHandlerList);
    gestureLeftList.setOnPreferenceChangeListener(NestingListListener);
    gestureRightList.setOnPreferenceChangeListener(NestingListListener);
    gestureDownList.setOnPreferenceChangeListener(NestingListListener);
    gestureUpList.setOnPreferenceChangeListener(NestingListListener);
    gestureDoubleTapList.setOnPreferenceChangeListener(NestingListListener);
    gestureTapList.setOnPreferenceChangeListener(NestingListListener);
    gesturePinchList.setOnPreferenceChangeListener(NestingListListener);
}
 
Example 9
Source File: SettingsPreferenceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private void createCameraSettingsPreference(final Context context) {
    CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    ListPreference facingPref = findPreference("camera_facing");
    if (facingPref != null) {
        if (cameraManager != null) {
            final int facing;
            String value = facingPref.getValue();
            if (value == null) {
                facing = Settings.DEFAULT_CAMERA_FACING;
                facingPref.setValueIndex(Settings.DEFAULT_CAMERA_FACING);
            } else {
                facing = Integer.parseInt(value);
            }

            facingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
                if (newValue instanceof String) {
                    int newFacing = Integer.parseInt((String) newValue);
                    createCameraPreviewPreference(cameraManager, newFacing);
                }
                return true;
            });

            createCameraPreviewPreference(cameraManager, facing);
        } else {
            facingPref.setEnabled(false);
        }
    }
}
 
Example 10
Source File: ChatsPreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);

  mediaQuality = (ListPreference) this.findPreference("pref_compression");
  mediaQuality.setOnPreferenceChangeListener((preference, newValue) -> {
    updateListSummary(preference, newValue);
    dcContext.setConfigInt(DcHelper.CONFIG_MEDIA_QUALITY, Util.objectToInt(newValue));
    return true;
  });

  showEmails = (ListPreference) this.findPreference("pref_show_emails");
  showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
    updateListSummary(preference, newValue);
    dcContext.setConfigInt(CONFIG_SHOW_EMAILS, Util.objectToInt(newValue));
    return true;
  });

  readReceiptsCheckbox = (CheckBoxPreference) this.findPreference("pref_read_receipts");
  readReceiptsCheckbox.setOnPreferenceChangeListener(new ReadReceiptToggleListener());

  this.findPreference("preference_category_blocked").setOnPreferenceClickListener(new BlockedContactsClickListener());

  Preference backup = this.findPreference("pref_backup");
  backup.setOnPreferenceClickListener(new BackupListener());

  autoDelDevice = findPreference("autodel_device");
  autoDelDevice.setOnPreferenceChangeListener(new AutodelChangeListener("delete_device_after"));

  autoDelServer = findPreference("autodel_server");
  autoDelServer.setOnPreferenceChangeListener(new AutodelChangeListener("delete_server_after"));
}
 
Example 11
Source File: PreferencesMain.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("SameReturnValue")
private static void prepareListPreference(final ListPreference listPreference, final Activity activity)
{
    if (listPreference == null)
    {
        return;
    }

    if (listPreference.getValue() == null)
    {
        // to ensure we don't get a null value
        // set first value by default
        listPreference.setValueIndex(0);
    }

    if (listPreference.getEntry() != null)
    {
        listPreference.setSummary(listPreference.getEntry().toString());
    }
    listPreference.setOnPreferenceChangeListener((preference, newValue) ->
    {
        listPreference.setValue(newValue.toString());
        preference.setSummary(listPreference.getEntry().toString());
        if (activity != null)
        {
            final Intent intent = activity.getIntent();
            activity.finish();
            activity.startActivity(intent);
        }
        return true;
    });
}
 
Example 12
Source File: VideoPreferenceFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.video_preferences, rootKey);

    ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY);
    SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS);
    SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS);

    if (videoAutoplayListPreference != null && autoplayNsfwVideosSwitchPreference != null) {
        videoAutoplayListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeVideoAutoplayEvent((String) newValue));
            return true;
        });

        autoplayNsfwVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeAutoplayNsfwVideosEvent((Boolean) newValue));
            return true;
        });
    }

    if (muteAutoplayingVideosSwitchPreference != null) {
        muteAutoplayingVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new ChangeMuteAutoplayingVideosEvent((Boolean) newValue));
            return true;
        });
    }
}
 
Example 13
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onCreatePreferences(Bundle bundle, String s) {

        addPreferencesFromResource(R.xml.settings);

        // general groups
        mEnablePref = findPreference(PrefConst.ENABLE);
        mEnablePref.setOnPreferenceChangeListener(this);

        // listen mode preference
        ListPreference listenModePref = findPreference(LISTEN_MODE);
        listenModePref.setOnPreferenceChangeListener(this);
        mCurListenMode = listenModePref.getValue();
        refreshListenModePreference(listenModePref, mCurListenMode);

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//            // hide copy to clipboard preference
//            PreferenceGroup generalGroup = findPreference(KEY_GENERAL);
//            Preference copyToClipboardPref = findPreference(COPY_TO_CLIPBOARD);
//            generalGroup.removePreference(copyToClipboardPref);
//        }

        findPreference(ENTRY_AUTO_INPUT_CODE).setOnPreferenceClickListener(this);

        Preference chooseThemePref = findPreference(PrefConst.CHOOSE_THEME);
        chooseThemePref.setOnPreferenceClickListener(this);
        initChooseThemePreference(chooseThemePref);
        // general groups end


        // experimental groups
        findPreference(MARK_AS_READ).setOnPreferenceChangeListener(this);

        findPreference(BLOCK_NOTIFICATION).setOnPreferenceChangeListener(this);

        findPreference(DELETE_SMS).setOnPreferenceChangeListener(this);
        // experimental groups end


        // code message group
        findPreference(CODE_RULES).setOnPreferenceClickListener(this);
        findPreference(SMSCODE_TEST).setOnPreferenceClickListener(this);
        // code message group end


        // code records group
        Preference recordsEntryPref = findPreference(ENTRY_CODE_RECORDS);
        recordsEntryPref.setOnPreferenceClickListener(this);
        initRecordEntryPreference(recordsEntryPref);
        // code records group end


        // others group
        // exclude from recent apps preference
        mExcludeFromRecentsPref = findPreference(EXCLUDE_FROM_RECENTS);
        mExcludeFromRecentsPref.setOnPreferenceChangeListener(this);

        // verbose log preference
        SwitchPreference verboseLogPref = findPreference(VERBOSE_LOG_MODE);
        verboseLogPref.setOnPreferenceChangeListener(this);
        refreshVerboseLogPreference(verboseLogPref, verboseLogPref.isChecked());
        // others group end


        // about group
        Preference versionPref = findPreference(VERSION);
        refreshVersionInfoPreference(versionPref);
        findPreference(SOURCE_CODE).setOnPreferenceClickListener(this);
        findPreference(RATING).setOnPreferenceClickListener(this);
        findPreference(GET_ALIPAY_PACKET).setOnPreferenceClickListener(this);
        findPreference(DONATE_BY_ALIPAY).setOnPreferenceClickListener(this);
        // about group end
    }
 
Example 14
Source File: SettingsFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

    addPreferencesFromResource(R.xml.settings);
    if (getArguments() != null && getArguments().getBoolean("showKerahatDuration"))
        setPreferenceScreen((PreferenceScreen) findPreference("kerahatDuration"));
    else {
   /*     findPreference("language").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.TRANSLATE)
                .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("arabicNames").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_OUT)
                .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("digits").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.NUMERIC)
                .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("calendarIntegration").setIcon(
                MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CALENDAR)
                        .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("kerahatDuration").setIcon(
                MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_ALERT)
                        .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
     */

        findPreference("numbers").setOnPreferenceChangeListener(this);
        findPreference("backupRestore").setOnPreferenceClickListener(this);
        findPreference("calendarIntegration").setOnPreferenceChangeListener(this);
        findPreference("ongoingIcon").setOnPreferenceClickListener(this);
        findPreference("ongoingNumber").setOnPreferenceClickListener(this);
        findPreference("kerahatDuration").setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            findPreference("ongoingNumber").setEnabled(false);
        }

        if (Build.VERSION.SDK_INT < 24)
            findPreference("showLegacyWidgets").setEnabled(false);


        findPreference("arabicNames").setEnabled(!new Locale("ar").getLanguage().equals(LocaleUtils.getLocale().getLanguage()));

        ListPreference lang = (ListPreference) findPreference("language");
        lang.setOnPreferenceChangeListener(this);

        List<LocaleUtils.Translation> languages = LocaleUtils.getSupportedLanguages(getActivity());
        CharSequence[] entries = new CharSequence[languages.size()];
        CharSequence[] values = new CharSequence[languages.size()];
        for (int i = 0; i < languages.size(); i++) {
            LocaleUtils.Translation trans = languages.get(i);
            entries[i] = trans.getDisplayText();
            values[i] = trans.getLanguage();
        }
        lang.setEntries(entries);
        lang.setEntryValues(values);


        int[][] colors = {{0, 0},
                {0xFFFFFFFF, 0xFF333333},
                {0xFFDDDDDD, 0xFF222222},
                {0xFFBBBBBB, 0xFF111111},
                {0xFF999999, 0xFF000000},
                {0xFF666666, 0xFFFFFFFF},
                {0xFF444444, 0xFFEEEEEE},
                {0xFF222222, 0xFFDDDDDD},
                {0xFF000000, 0xFFCCCCCC}
        };

        Preference ongoingColor = findPreference("ongoingColor");

        ongoingColor.setOnPreferenceClickListener(e -> {
            AlertDialog.Builder dlg = new AlertDialog.Builder(getActivity());
            dlg.setAdapter(new ArrayAdapter(getActivity(), android.R.layout.select_dialog_singlechoice) {
                @Override
                public int getCount() {
                    return colors.length;
                }

                @NonNull
                @Override
                public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                    CheckedTextView v = (CheckedTextView) LayoutInflater.from(getContext()).inflate(android.R.layout.select_dialog_singlechoice, parent, false);
                    int p = (int) Utils.convertDpToPixel(getContext(), 4);
                    v.setPadding(4 * p, p, 4 * p, p);
                    v.setText(position == 0 ? "System" : "Abc");
                    v.setBackgroundColor(position == 0 ? Color.WHITE : colors[position][0]);
                    v.setTextColor(position == 0 ? Color.BLACK : colors[position][1]);
                    v.setChecked(colors[position][0] == Preferences.ONGOING_BG_COLOR.get() && colors[position][1] == Preferences.ONGOING_TEXT_COLOR.get());
                    return v;
                }
            }, (dialog, which) -> {
                Preferences.ONGOING_BG_COLOR.set(colors[which][0]);
                Preferences.ONGOING_TEXT_COLOR.set(colors[which][1]);
            });
            dlg.show();
            return true;

        });
    }

}
 
Example 15
Source File: SettingsFragment.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void initDisplayPart() {
    // saturation animation enabled.
    SwitchPreference saturationEnabled = findPreference(getString(R.string.key_saturation_animation_enabled));
    saturationEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
        SettingsServiceIMP.getInstance(requireActivity())
                .setSaturationAnimationEnabled((Boolean) newValue);
        return true;
    });

    // saturation animation duration.
    ListPreference duration = findPreference(getString(R.string.key_saturation_animation_duration));
    duration.setSummary(
            getNameByValue(
                    ComponentFactory.getSettingsService().getSaturationAnimationDuration(),
                    R.array.saturation_animation_durations,
                    R.array.saturation_animation_duration_values
            )
    );
    duration.setOnPreferenceChangeListener((preference, newValue) -> {
        SettingsServiceIMP.getInstance(requireActivity())
                .setSaturationAnimationDuration((String) newValue);
        preference.setSummary(
                getNameByValue(
                        (String) newValue,
                        R.array.saturation_animation_durations,
                        R.array.saturation_animation_duration_values
                )
        );
        return true;
    });

    // grid list in port.
    SwitchPreference gridPort = findPreference(getString(R.string.key_grid_list_in_port));
    gridPort.setVisible(DisplayUtils.isTabletDevice(requireActivity()));
    gridPort.setOnPreferenceChangeListener((preference, newValue) -> {
        showRebootSnackbar();
        return true;
    });

    // grid list in land.
    findPreference(getString(R.string.key_grid_list_in_land)).setOnPreferenceChangeListener((p, v) -> {
        showRebootSnackbar();
        return true;
    });
}
 
Example 16
Source File: UnitSettingsFragment.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.perference_unit);

    // temperature.
    ListPreference temperature = findPreference(getString(R.string.key_temperature_unit));
    temperature.setSummary(
            getSettingsOptionManager().getTemperatureUnit().getAbbreviation(requireActivity())
    );
    temperature.setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setTemperatureUnit(OptionMapper.getTemperatureUnit((String) newValue));
        temperature.setSummary(
                getSettingsOptionManager().getTemperatureUnit().getAbbreviation(requireActivity())
        );
        SnackbarUtils.showSnackbar(
                (GeoActivity) requireActivity(), getString(R.string.feedback_refresh_ui_after_refresh));
        return true;
    });

    // distance.
    ListPreference distance = findPreference(getString(R.string.key_distance_unit));
    distance.setSummary(getSettingsOptionManager().getDistanceUnit().getAbbreviation(requireActivity()));
    distance.setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setDistanceUnit(OptionMapper.getDistanceUnit((String) newValue));
        distance.setSummary(getSettingsOptionManager().getDistanceUnit().getAbbreviation(requireActivity()));
        SnackbarUtils.showSnackbar(
                (GeoActivity) requireActivity(), getString(R.string.feedback_refresh_ui_after_refresh));
        return true;
    });

    // precipitation.
    ListPreference precipitation = findPreference(getString(R.string.key_precipitation_unit));
    precipitation.setSummary(getSettingsOptionManager().getPrecipitationUnit().getAbbreviation(requireActivity()));
    precipitation.setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setPrecipitationUnit(OptionMapper.getPrecipitationUnit((String) newValue));
        precipitation.setSummary(getSettingsOptionManager().getPrecipitationUnit().getAbbreviation(requireActivity()));
        SnackbarUtils.showSnackbar(
                (GeoActivity) requireActivity(), getString(R.string.feedback_refresh_ui_after_refresh));
        return true;
    });

    // pressure.
    ListPreference pressure = findPreference(getString(R.string.key_pressure_unit));
    pressure.setSummary(getSettingsOptionManager().getPressureUnit().getAbbreviation(requireActivity()));
    pressure.setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setPressureUnit(OptionMapper.getPressureUnit((String) newValue));
        pressure.setSummary(getSettingsOptionManager().getPressureUnit().getAbbreviation(requireActivity()));
        SnackbarUtils.showSnackbar(
                (GeoActivity) requireActivity(), getString(R.string.feedback_refresh_ui_after_refresh));
        return true;
    });

    // speed.
    ListPreference speed = findPreference(getString(R.string.key_speed_unit));
    speed.setSummary(getSettingsOptionManager().getSpeedUnit().getAbbreviation(requireActivity()));
    speed.setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setSpeedUnit(OptionMapper.getSpeedUnit((String) newValue));
        speed.setSummary(getSettingsOptionManager().getSpeedUnit().getAbbreviation(requireActivity()));
        SnackbarUtils.showSnackbar(
                (GeoActivity) requireActivity(), getString(R.string.feedback_refresh_ui_after_refresh));
        return true;
    });
}
 
Example 17
Source File: FontPreferenceFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.font_preferences, rootKey);
    ListPreference fontFamilyPreference = findPreference(SharedPreferencesUtils.FONT_FAMILY_KEY);
    ListPreference titleFontFamilyPreference = findPreference(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY);
    ListPreference contentFontFamilyPreference = findPreference(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY);
    ListPreference fontSizePreference = findPreference(SharedPreferencesUtils.FONT_SIZE_KEY);
    ListPreference titleFontSizePreference = findPreference(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY);
    ListPreference contentFontSizePreference = findPreference(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY);

    if (fontFamilyPreference != null) {
        fontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            activity.recreate();
            return true;
        });
    }

    if (titleFontFamilyPreference != null) {
        titleFontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            return true;
        });
    }

    if (contentFontFamilyPreference != null) {
        contentFontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            return true;
        });
    }

    if (fontSizePreference != null) {
        fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            activity.recreate();
            return true;
        });
    }

    if (titleFontSizePreference != null) {
        titleFontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            return true;
        });
    }

    if (contentFontSizePreference != null) {
        contentFontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> {
            EventBus.getDefault().post(new RecreateActivityEvent());
            return true;
        });
    }
}
 
Example 18
Source File: SettingsFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

    addPreferencesFromResource(R.xml.settings);
    if (getArguments() != null && getArguments().getBoolean("showKerahatDuration"))
        setPreferenceScreen((PreferenceScreen) findPreference("kerahatDuration"));
    else {
   /*     findPreference("language").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.TRANSLATE)
                .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("arabicNames").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_OUT)
                .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("digits").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.NUMERIC)
                .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("calendarIntegration").setIcon(
                MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CALENDAR)
                        .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
        findPreference("kerahatDuration").setIcon(
                MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_ALERT)
                        .setColor(getResources().getColor(R.color.foregroundSecondary)).build());
     */

        findPreference("numbers").setOnPreferenceChangeListener(this);
        findPreference("backupRestore").setOnPreferenceClickListener(this);
        findPreference("calendarIntegration").setOnPreferenceChangeListener(this);
        findPreference("ongoingIcon").setOnPreferenceClickListener(this);
        findPreference("ongoingNumber").setOnPreferenceClickListener(this);
        findPreference("kerahatDuration").setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            findPreference("ongoingNumber").setEnabled(false);
        }

        if (Build.VERSION.SDK_INT < 24)
            findPreference("showLegacyWidgets").setEnabled(false);


        findPreference("arabicNames").setEnabled(!new Locale("ar").getLanguage().equals(LocaleUtils.getLocale().getLanguage()));

        ListPreference lang = (ListPreference) findPreference("language");
        lang.setOnPreferenceChangeListener(this);

        List<LocaleUtils.Translation> languages = LocaleUtils.getSupportedLanguages(getActivity());
        CharSequence[] entries = new CharSequence[languages.size()];
        CharSequence[] values = new CharSequence[languages.size()];
        for (int i = 0; i < languages.size(); i++) {
            LocaleUtils.Translation trans = languages.get(i);
            entries[i] = trans.getDisplayText();
            values[i] = trans.getLanguage();
        }
        lang.setEntries(entries);
        lang.setEntryValues(values);


        int[][] colors = {{0, 0},
                {0xFFFFFFFF, 0xFF333333},
                {0xFFDDDDDD, 0xFF222222},
                {0xFFBBBBBB, 0xFF111111},
                {0xFF999999, 0xFF000000},
                {0xFF666666, 0xFFFFFFFF},
                {0xFF444444, 0xFFEEEEEE},
                {0xFF222222, 0xFFDDDDDD},
                {0xFF000000, 0xFFCCCCCC}
        };

        Preference ongoingColor = findPreference("ongoingColor");

        ongoingColor.setOnPreferenceClickListener(e -> {
            AlertDialog.Builder dlg = new AlertDialog.Builder(getActivity());
            dlg.setAdapter(new ArrayAdapter(getActivity(), android.R.layout.select_dialog_singlechoice) {
                @Override
                public int getCount() {
                    return colors.length;
                }

                @NonNull
                @Override
                public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                    CheckedTextView v = (CheckedTextView) LayoutInflater.from(getContext()).inflate(android.R.layout.select_dialog_singlechoice, parent, false);
                    int p = (int) Utils.convertDpToPixel(getContext(), 4);
                    v.setPadding(4 * p, p, 4 * p, p);
                    v.setText(position == 0 ? "System" : "Abc");
                    v.setBackgroundColor(position == 0 ? Color.WHITE : colors[position][0]);
                    v.setTextColor(position == 0 ? Color.BLACK : colors[position][1]);
                    v.setChecked(colors[position][0] == Preferences.ONGOING_BG_COLOR.get() && colors[position][1] == Preferences.ONGOING_TEXT_COLOR.get());
                    return v;
                }
            }, (dialog, which) -> {
                Preferences.ONGOING_BG_COLOR.set(colors[which][0]);
                Preferences.ONGOING_TEXT_COLOR.set(colors[which][1]);
            });
            dlg.show();
            return true;

        });
    }

}
 
Example 19
Source File: MuzeiSettingsFragment.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.perference_muzei);

    MuzeiOptionManager manager = MuzeiOptionManager.getInstance(requireActivity());

    // muzei source.
    ListPreference source = findPreference(getString(R.string.key_muzei_source));
    source.setSummary(
            getNameByValue(
                    manager.getSource(),
                    R.array.muzei_sources,
                    R.array.muzei_source_values
            )
    );
    source.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setSource((String) newValue);
        preference.setSummary(
                getNameByValue(
                        manager.getSource(),
                        R.array.muzei_sources,
                        R.array.muzei_source_values
                )
        );

        findPreference(getString(R.string.key_muzei_collection_source)).setEnabled(
                manager.getSource().equals(MuzeiOptionManager.SOURCE_COLLECTIONS)
        );
        return true;
    });

    // screen size.
    SwitchPreference screenSizeImage = findPreference(getString(R.string.key_muzei_screen_size_image));
    int[] size = MuzeiUpdateHelper.getScreenSize(requireActivity());
    screenSizeImage.setSummaryOn(size[1] + "×" + size[0]);
    screenSizeImage.setSummaryOff(R.string.muzei_settings_title_screen_size_image_summary_off);
    screenSizeImage.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setScreenSizeImage((Boolean) newValue);
        return true;
    });

    // cache mode.
    ListPreference cacheMode = findPreference(getString(R.string.key_muzei_cache_mode));
    cacheMode.setSummary(
            getNameByValue(
                    manager.getCacheMode(),
                    R.array.muzei_cache_modes,
                    R.array.muzei_cache_mode_values
            )
    );
    cacheMode.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setCacheMode((String) newValue);
        preference.setSummary(
                getNameByValue(
                        manager.getCacheMode(),
                        R.array.muzei_cache_modes,
                        R.array.muzei_cache_mode_values
                )
        );
        return true;
    });

    // collections.
    Preference collectionSource = findPreference(getString(R.string.key_muzei_collection_source));
    collectionSource.setEnabled(manager.getSource().equals(MuzeiOptionManager.SOURCE_COLLECTIONS));
    collectionSource.setOnPreferenceClickListener(preference -> {
        ComponentFactory.getMuzeiService()
                .startMuzeiCollectionSourceConfigActivity(requireActivity());
        return true;
    });

    // query.
    Preference query = findPreference(getString(R.string.key_muzei_query));
    query.setSummary(manager.getQuery());
    query.setOnPreferenceClickListener(preference -> {
        MuzeiQueryDialog dialog = new MuzeiQueryDialog();
        dialog.setOnQueryChangedListener(query1 -> {
            MuzeiOptionManager.updateQuery(requireActivity(), query1);
            Preference q = findPreference(getString(R.string.key_muzei_query));
            q.setSummary(MuzeiOptionManager.getInstance(requireActivity()).getQuery());
        });
        dialog.show(requireFragmentManager(), null);
        return true;
    });
}
 
Example 20
Source File: SettingsFragment.java    From mlkit-material-android with Apache License 2.0 4 votes vote down vote up
private void setUpRearCameraPreviewSizePreference() {
  ListPreference previewSizePreference =
      (ListPreference) findPreference(getString(R.string.pref_key_rear_camera_preview_size));
  if (previewSizePreference == null) {
    return;
  }

  Camera camera = null;
  try {
    camera = Camera.open(CameraSource.CAMERA_FACING_BACK);
    List<CameraSizePair> previewSizeList = Utils.generateValidPreviewSizeList(camera);
    String[] previewSizeStringValues = new String[previewSizeList.size()];
    Map<String, String> previewToPictureSizeStringMap = new HashMap<>();
    for (int i = 0; i < previewSizeList.size(); i++) {
      CameraSizePair sizePair = previewSizeList.get(i);
      previewSizeStringValues[i] = sizePair.preview.toString();
      if (sizePair.picture != null) {
        previewToPictureSizeStringMap.put(
            sizePair.preview.toString(), sizePair.picture.toString());
      }
    }
    previewSizePreference.setEntries(previewSizeStringValues);
    previewSizePreference.setEntryValues(previewSizeStringValues);
    previewSizePreference.setSummary(previewSizePreference.getEntry());
    previewSizePreference.setOnPreferenceChangeListener(
        (preference, newValue) -> {
          String newPreviewSizeStringValue = (String) newValue;
          previewSizePreference.setSummary(newPreviewSizeStringValue);
          PreferenceUtils.saveStringPreference(
              getActivity(),
              R.string.pref_key_rear_camera_picture_size,
              previewToPictureSizeStringMap.get(newPreviewSizeStringValue));
          return true;
        });

  } catch (Exception e) {
    // If there's no camera for the given camera id, hide the corresponding preference.
    if (previewSizePreference.getParent() != null) {
      previewSizePreference.getParent().removePreference(previewSizePreference);
    }
  } finally {
    if (camera != null) {
      camera.release();
    }
  }
}