Search in sources :

Example 1 with PreferenceGroup

use of android.preference.PreferenceGroup in project KISS by Neamar.

the class SettingsActivity method addSearchProvidersSelector.

private void addSearchProvidersSelector(SharedPreferences prefs) {
    MultiSelectListPreference multiPreference = new MultiSelectListPreference(this);
    String[] searchProviders = SearchProvider.getSearchProviders();
    String search_providers_title = this.getString(R.string.search_providers_title);
    multiPreference.setTitle(search_providers_title);
    multiPreference.setDialogTitle(search_providers_title);
    multiPreference.setKey("search-providers");
    multiPreference.setEntries(searchProviders);
    multiPreference.setEntryValues(searchProviders);
    multiPreference.setDefaultValue(new HashSet<>(Collections.singletonList("Google")));
    PreferenceGroup category = (PreferenceGroup) findPreference("providers");
    category.addPreference(multiPreference);
}
Also used : MultiSelectListPreference(android.preference.MultiSelectListPreference) PreferenceGroup(android.preference.PreferenceGroup)

Example 2 with PreferenceGroup

use of android.preference.PreferenceGroup in project Shuttle by timusus.

the class SettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().supportInvalidateOptionsMenu();
    mTintManager = new SystemBarTintManager(getActivity());
    if (getArguments() != null) {
        mPrefResId = getArguments().getInt(PREF_RES_ID);
    } else {
        mPrefResId = R.xml.settings_headers;
    }
    // Load the preferences from an XML resource
    addPreferencesFromResource(mPrefResId);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    final Preference chooseTabsPreference = findPreference("pref_tab_chooser");
    if (chooseTabsPreference != null) {
        chooseTabsPreference.setOnPreferenceClickListener(preference -> {
            RecyclerView recyclerView = (RecyclerView) LayoutInflater.from(getContext()).inflate(R.layout.dialog_tab_chooser, null);
            recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            TabsAdapter tabsAdapter = new TabsAdapter(getContext());
            ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(tabsAdapter::moveItem, (fromPosition, toPosition) -> tabsAdapter.updatePreferences(), () -> {
            }));
            itemTouchHelper.attachToRecyclerView(recyclerView);
            tabsAdapter.setListener(new TabsAdapter.TabListener() {

                @Override
                public void onItemClick(View v, int position, CategoryItem categoryItem) {
                    categoryItem.setChecked(!categoryItem.isChecked());
                    com.simplecity.amp_library.utils.AnalyticsManager.logTabVisibilityChanged(categoryItem.isChecked(), categoryItem.title);
                    tabsAdapter.notifyItemChanged(position);
                    tabsAdapter.updatePreferences();
                }

                @Override
                public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
                    itemTouchHelper.startDrag(viewHolder);
                }
            });
            recyclerView.setAdapter(tabsAdapter);
            DialogUtils.getBuilder(getContext()).title(R.string.pref_title_choose_tabs).customView(recyclerView, false).positiveText(R.string.button_done).onPositive((materialDialog, dialogAction) -> {
                DialogUtils.createRestartDialog(getActivity());
                materialDialog.dismiss();
            }).show();
            return true;
        });
    }
    final Preference colorPickerPreference = findPreference("pref_theme_highlight_color");
    if (colorPickerPreference != null) {
        colorPickerPreference.setOnPreferenceClickListener(preference -> {
            int selectedColor = mPrefs.getInt("pref_theme_highlight_color", -1);
            DialogUtils.showColorPickerDialog(this, selectedColor, color -> mPrefs.edit().putInt("pref_theme_highlight_color", color).apply());
            return true;
        });
    }
    final Preference accentPickerPreference = findPreference("pref_theme_accent_color");
    if (accentPickerPreference != null) {
        accentPickerPreference.setOnPreferenceClickListener(preference -> {
            int selectedColor = mPrefs.getInt("pref_theme_accent_color", -1);
            DialogUtils.showColorPickerDialog(this, selectedColor, ColorPalette.getAccentColors(), ColorPalette.getAccentColorsSub(), color -> mPrefs.edit().putInt("pref_theme_accent_color", color).apply());
            return true;
        });
    }
    mListener = (sharedPreferences, key) -> {
        if (key.equals("pref_theme_highlight_color") || key.equals("pref_theme_accent_color") || key.equals("pref_theme_white_accent")) {
            ThemeUtils.setTheme(getActivity());
            ThemeUtils.themeActionBar((SettingsActivity) getActivity());
            ThemeUtils.themeStatusBar(getActivity(), mTintManager);
            getListView().invalidate();
            themeUIElements();
            for (int i = 0, size = getListView().getChildCount(); i < size; i++) {
                View view = getListView().getChildAt(i);
                ThemeUtils.updateThemableViews(view);
            }
        }
        if (key.equals("pref_theme_base") || key.equals("pref_default_page")) {
            DialogUtils.createRestartDialog(getActivity());
        }
    };
    final Preference restartPreference = findPreference("pref_restart");
    if (restartPreference != null) {
        restartPreference.setOnPreferenceClickListener(preference -> {
            Intent intent = new Intent(getActivity(), MainActivity.class);
            ComponentName componentNAme = intent.getComponent();
            Intent mainIntent = IntentCompat.makeRestartActivityTask(componentNAme);
            startActivity(mainIntent);
            return true;
        });
    }
    final CheckBoxPreference showLockscreenArtworkPreference = (CheckBoxPreference) findPreference(SettingsManager.KEY_SHOW_LOCKSCREEN_ARTWORK);
    if (showLockscreenArtworkPreference != null) {
        showLockscreenArtworkPreference.setOnPreferenceClickListener(preference -> {
            MusicUtils.toggleLockscreenArtwork();
            return false;
        });
    }
    final Preference downloadArtworkPreference = findPreference("pref_download_artwork");
    if (downloadArtworkPreference != null) {
        downloadArtworkPreference.setOnPreferenceClickListener(preference -> {
            DialogUtils.showDownloadWarningDialog(getActivity(), (materialDialog, dialogAction) -> {
                Intent intent = new Intent(getContext(), ArtworkDownloadService.class);
                ShuttleApplication.getInstance().startService(intent);
            });
            return true;
        });
    }
    final Preference deleteArtworkPreference = findPreference("pref_delete_artwork");
    if (deleteArtworkPreference != null) {
        deleteArtworkPreference.setOnPreferenceClickListener(preference -> {
            DialogUtils.getBuilder(getActivity()).title(getString(R.string.pref_title_delete_artwork)).icon(DrawableUtils.themeLightOrDark(getActivity(), getResources().getDrawable(R.drawable.ic_dialog_alert))).content(getString(R.string.delete_artwork_confirmation_dialog)).positiveText(getString(R.string.button_ok)).onPositive((materialDialog, dialogAction) -> {
                Glide.get(getContext()).clearMemory();
                ShuttleUtils.execute(new AsyncTask<Void, Void, Void>() {

                    @Override
                    protected Void doInBackground(Void... params) {
                        Glide.get(getContext()).clearDiskCache();
                        return null;
                    }
                });
            }).negativeText(getString(R.string.cancel)).show();
            return true;
        });
    }
    final Preference downloadSimpleLastFmScrobbler = findPreference("pref_download_simple_lastfm_scrobbler");
    if (downloadSimpleLastFmScrobbler != null) {
        if (ShuttleUtils.isAmazonBuild()) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("pref_key_simple_lastfm_scrobble_settings");
            if (preferenceGroup != null) {
                preferenceGroup.removePreference(downloadSimpleLastFmScrobbler);
            }
        } else {
            downloadSimpleLastFmScrobbler.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.adam.aslfms")));
        }
    }
    final Preference about = findPreference("pref_about");
    if (about != null) {
        about.setOnPreferenceClickListener(preference -> {
            View customView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_changelog, null);
            WebView webView = (WebView) customView.findViewById(R.id.webView);
            int themeType = ThemeUtils.getThemeType(getActivity());
            webView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
            if (themeType == ThemeUtils.ThemeType.TYPE_LIGHT || themeType == ThemeUtils.ThemeType.TYPE_SOLID_LIGHT) {
                webView.loadUrl("file:///android_asset/web/info.html");
            } else {
                webView.loadUrl("file:///android_asset/web/info_dark.html");
            }
            DialogUtils.getBuilder(getActivity()).title(R.string.pref_title_about).customView(customView, false).negativeText(R.string.close).show();
            AnalyticsManager.logChangelogViewed();
            return true;
        });
    }
    final Preference upgrade = findPreference("pref_upgrade");
    if (upgrade != null) {
        if (ShuttleUtils.isUpgraded()) {
            SettingsFragment.this.getPreferenceScreen().removePreference(upgrade);
        }
        upgrade.setOnPreferenceClickListener(preference -> {
            DialogUtils.showUpgradeDialog(getActivity(), (materialDialog, dialogAction) -> {
                if (ShuttleUtils.isAmazonBuild()) {
                    ShuttleUtils.openShuttleLink(getActivity(), "com.simplecity.amp_pro");
                } else {
                    AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.UPGRADE);
                    ((SettingsActivity) getActivity()).purchasePremiumUpgrade();
                }
            });
            return true;
        });
    }
    final Preference viewBlacklist = findPreference("pref_blacklist_view");
    if (viewBlacklist != null) {
        viewBlacklist.setOnPreferenceClickListener(preference -> {
            DialogUtils.showBlacklistDialog(getActivity());
            return true;
        });
    }
    final Preference viewWhitelist = findPreference("pref_whitelist_view");
    if (viewWhitelist != null) {
        viewWhitelist.setOnPreferenceClickListener(preference -> {
            DialogUtils.showWhitelistDialog(getActivity());
            return true;
        });
    }
    final Preference clearBlacklist = findPreference("pref_blacklist_clear");
    if (clearBlacklist != null) {
        clearBlacklist.setOnPreferenceClickListener(preference -> {
            BlacklistHelper.deleteAllSongs();
            Toast.makeText(getActivity(), R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
            return true;
        });
    }
    final Preference clearWhitelist = findPreference("pref_whitelist_clear");
    if (clearWhitelist != null) {
        clearWhitelist.setOnPreferenceClickListener(preference -> {
            WhitelistHelper.deleteAllFolders();
            Toast.makeText(getActivity(), R.string.whitelist_deleted, Toast.LENGTH_SHORT).show();
            return true;
        });
    }
    final CheckBoxPreference ignoreEmbeddedArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_EMBEDDED_ARTWORK);
    if (ignoreEmbeddedArtwork != null) {
        ignoreEmbeddedArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference ignoreFolderArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_FOLDER_ARTWORK);
    if (ignoreFolderArtwork != null) {
        ignoreFolderArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference preferEmbeddedArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_PREFER_EMBEDDED_ARTWORK);
    if (preferEmbeddedArtwork != null) {
        preferEmbeddedArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference ignoreMediaStoreArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_MEDIASTORE_ART);
    if (ignoreMediaStoreArtwork != null) {
        ignoreMediaStoreArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final CheckBoxPreference preferLastFmArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_PREFER_LAST_FM);
    if (preferLastFmArtwork != null) {
        preferLastFmArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
            showArtworkPreferenceDialog();
            return true;
        });
    }
    final Preference restorePurchases = findPreference("pref_restore_purchases");
    if (ShuttleUtils.isAmazonBuild() || ShuttleUtils.isUpgraded()) {
        PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("support_group");
        if (preferenceGroup != null) {
            preferenceGroup.removePreference(restorePurchases);
        }
    } else if (restorePurchases != null) {
        restorePurchases.setOnPreferenceClickListener(preference -> {
            ((SettingsActivity) getActivity()).restorePurchases();
            return true;
        });
    }
    final Preference versionPreference = findPreference("pref_version");
    if (versionPreference != null) {
        versionPreference.setSummary("Shuttle Music Player " + BuildConfig.VERSION_NAME + (ShuttleUtils.isUpgraded() ? " (Upgraded)" : " (Free)"));
    }
    final Preference faqPreference = findPreference("pref_faq");
    if (faqPreference != null) {
        faqPreference.setOnPreferenceClickListener(preference -> {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://www.shuttlemusicplayer.com/#faq"));
            startActivity(intent);
            return true;
        });
    }
    final Preference gplusPreference = findPreference("pref_gplus");
    if (gplusPreference != null) {
        gplusPreference.setOnPreferenceClickListener(preference -> {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/communities/112365043563095486408"));
            startActivity(intent);
            return true;
        });
    }
    final Preference ratePreference = findPreference("pref_rate");
    if (ratePreference != null) {
        ratePreference.setOnPreferenceClickListener(preference -> {
            final String appPackageName = getActivity().getPackageName();
            ShuttleUtils.openShuttleLink(getActivity(), appPackageName);
            SettingsManager.getInstance().setHasRated();
            return true;
        });
    }
    final CheckBoxPreference openOnClickPreference = (CheckBoxPreference) findPreference("pref_open_now_playing_on_click");
    if (openOnClickPreference != null) {
        if (!ShuttleUtils.isTablet()) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("display_group");
            if (preferenceGroup != null) {
                preferenceGroup.removePreference(openOnClickPreference);
            }
        }
    }
    if (!ShuttleUtils.hasLollipop()) {
        PreferenceScreen preferenceScreen = getPreferenceScreen();
        if (preferenceScreen != null) {
            Preference notificationPreference = preferenceScreen.findPreference("pref_category_notifications");
            if (notificationPreference != null) {
                preferenceScreen.removePreference(notificationPreference);
            }
        }
    }
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) Uri(android.net.Uri) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Dialog(android.app.Dialog) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) CategoryItem(com.simplecity.amp_library.model.CategoryItem) ArtworkDownloadService(com.simplecity.amp_library.services.ArtworkDownloadService) PreferenceScreen(android.preference.PreferenceScreen) Drawable(android.graphics.drawable.Drawable) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) PreferenceFragment(android.support.v4.preference.PreferenceFragment) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Toast(android.widget.Toast) View(android.view.View) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) Build(android.os.Build) PreferenceManager(android.preference.PreferenceManager) WebView(android.webkit.WebView) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TargetApi(android.annotation.TargetApi) TabsAdapter(com.simplecity.amp_library.ui.adapters.TabsAdapter) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) InsetDrawable(android.graphics.drawable.InsetDrawable) AsyncTask(android.os.AsyncTask) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) IntentCompat(android.support.v4.content.IntentCompat) ColorPalette(com.simplecity.amp_library.utils.ColorPalette) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BuildConfig(com.simplecity.amp_library.BuildConfig) ViewGroup(android.view.ViewGroup) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) RecyclerView(android.support.v7.widget.RecyclerView) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) PreferenceGroup(android.preference.PreferenceGroup) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) Intent(android.content.Intent) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TabsAdapter(com.simplecity.amp_library.ui.adapters.TabsAdapter) View(android.view.View) WebView(android.webkit.WebView) RecyclerView(android.support.v7.widget.RecyclerView) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) RecyclerView(android.support.v7.widget.RecyclerView) ComponentName(android.content.ComponentName) PreferenceGroup(android.preference.PreferenceGroup) WebView(android.webkit.WebView) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) CategoryItem(com.simplecity.amp_library.model.CategoryItem)

Example 3 with PreferenceGroup

use of android.preference.PreferenceGroup in project OpenCamera by ageback.

the class MyPreferenceFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    final Bundle bundle = getArguments();
    this.cameraId = bundle.getInt("cameraId");
    if (MyDebug.LOG)
        Log.d(TAG, "cameraId: " + cameraId);
    final int nCameras = bundle.getInt("nCameras");
    if (MyDebug.LOG)
        Log.d(TAG, "nCameras: " + nCameras);
    final String camera_api = bundle.getString("camera_api");
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    final boolean supports_auto_stabilise = bundle.getBoolean("supports_auto_stabilise");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_auto_stabilise: " + supports_auto_stabilise);
    /*if( !supports_auto_stabilise ) {
			Preference pref = findPreference("preference_auto_stabilise");
			PreferenceGroup pg = (PreferenceGroup)this.findPreference("preference_category_camera_effects");
        	pg.removePreference(pref);
		}*/
    // readFromBundle(bundle, "color_effects", Preview.getColorEffectPreferenceKey(), Camera.Parameters.EFFECT_NONE, "preference_category_camera_effects");
    // readFromBundle(bundle, "scene_modes", Preview.getSceneModePreferenceKey(), Camera.Parameters.SCENE_MODE_AUTO, "preference_category_camera_effects");
    // readFromBundle(bundle, "white_balances", Preview.getWhiteBalancePreferenceKey(), Camera.Parameters.WHITE_BALANCE_AUTO, "preference_category_camera_effects");
    // readFromBundle(bundle, "isos", Preview.getISOPreferenceKey(), "auto", "preference_category_camera_effects");
    // readFromBundle(bundle, "exposures", "preference_exposure", "0", "preference_category_camera_effects");
    final boolean supports_face_detection = bundle.getBoolean("supports_face_detection");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_face_detection: " + supports_face_detection);
    if (!supports_face_detection) {
        Preference pref = findPreference("preference_face_detection");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_category_camera_controls");
        pg.removePreference(pref);
    }
    final int preview_width = bundle.getInt("preview_width");
    final int preview_height = bundle.getInt("preview_height");
    final int[] preview_widths = bundle.getIntArray("preview_widths");
    final int[] preview_heights = bundle.getIntArray("preview_heights");
    final int[] video_widths = bundle.getIntArray("video_widths");
    final int[] video_heights = bundle.getIntArray("video_heights");
    final int[] video_fps = bundle.getIntArray("video_fps");
    final int resolution_width = bundle.getInt("resolution_width");
    final int resolution_height = bundle.getInt("resolution_height");
    final int[] widths = bundle.getIntArray("resolution_widths");
    final int[] heights = bundle.getIntArray("resolution_heights");
    if (widths != null && heights != null) {
        CharSequence[] entries = new CharSequence[widths.length];
        CharSequence[] values = new CharSequence[widths.length];
        for (int i = 0; i < widths.length; i++) {
            entries[i] = widths[i] + " x " + heights[i] + " " + Preview.getAspectRatioMPString(widths[i], heights[i]);
            values[i] = widths[i] + " " + heights[i];
        }
        ListPreference lp = (ListPreference) findPreference("preference_resolution");
        lp.setEntries(entries);
        lp.setEntryValues(values);
        String resolution_preference_key = PreferenceKeys.getResolutionPreferenceKey(cameraId);
        String resolution_value = sharedPreferences.getString(resolution_preference_key, "");
        if (MyDebug.LOG)
            Log.d(TAG, "resolution_value: " + resolution_value);
        lp.setValue(resolution_value);
        // now set the key, so we save for the correct cameraId
        lp.setKey(resolution_preference_key);
    } else {
        Preference pref = findPreference("preference_resolution");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
        pg.removePreference(pref);
    }
    String fps_preference_key = PreferenceKeys.getVideoFPSPreferenceKey(cameraId);
    if (MyDebug.LOG)
        Log.d(TAG, "fps_preference_key: " + fps_preference_key);
    String fps_value = sharedPreferences.getString(fps_preference_key, "default");
    if (MyDebug.LOG)
        Log.d(TAG, "fps_value: " + fps_value);
    if (video_fps != null) {
        // build video fps settings
        CharSequence[] entries = new CharSequence[video_fps.length + 1];
        CharSequence[] values = new CharSequence[video_fps.length + 1];
        int i = 0;
        // default:
        entries[i] = getResources().getString(R.string.preference_video_fps_default);
        values[i] = "default";
        i++;
        for (int fps : video_fps) {
            entries[i] = "" + fps;
            values[i] = "" + fps;
            i++;
        }
        ListPreference lp = (ListPreference) findPreference("preference_video_fps");
        lp.setEntries(entries);
        lp.setEntryValues(values);
        lp.setValue(fps_value);
        // now set the key, so we save for the correct cameraId
        lp.setKey(fps_preference_key);
        lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                if (MyDebug.LOG)
                    Log.d(TAG, "fps listpreference changed: " + newValue);
                // if fps has changed, we nee to update the available video resolutions
                setupVideoResolutions((String) newValue);
                return true;
            }
        });
    }
    {
        final int n_quality = 100;
        CharSequence[] entries = new CharSequence[n_quality];
        CharSequence[] values = new CharSequence[n_quality];
        for (int i = 0; i < n_quality; i++) {
            entries[i] = "" + (i + 1) + "%";
            values[i] = "" + (i + 1);
        }
        ListPreference lp = (ListPreference) findPreference("preference_quality");
        lp.setEntries(entries);
        lp.setEntryValues(values);
    }
    final boolean supports_raw = bundle.getBoolean("supports_raw");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_raw: " + supports_raw);
    if (!supports_raw) {
        Preference pref = findPreference("preference_raw");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
        pg.removePreference(pref);
    } else {
        ListPreference pref = (ListPreference) findPreference("preference_raw");
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            // RAW only mode requires at least Android 7; earlier versions seem to have poorer support for DNG files
            pref.setEntries(R.array.preference_raw_entries_preandroid7);
            pref.setEntryValues(R.array.preference_raw_values_preandroid7);
        }
        pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                if (MyDebug.LOG)
                    Log.d(TAG, "clicked raw: " + newValue);
                if (newValue.equals("preference_raw_yes") || newValue.equals("preference_raw_only")) {
                    // we check done_raw_info every time, so that this works if the user selects RAW again without leaving and returning to Settings
                    boolean done_raw_info = sharedPreferences.contains(PreferenceKeys.RawInfoPreferenceKey);
                    if (!done_raw_info) {
                        AlertDialog.Builder alertDialog = new AlertDialog.Builder(MyPreferenceFragment.this.getActivity());
                        alertDialog.setTitle(R.string.preference_raw);
                        alertDialog.setMessage(R.string.raw_info);
                        alertDialog.setPositiveButton(android.R.string.ok, null);
                        alertDialog.setNegativeButton(R.string.dont_show_again, new OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (MyDebug.LOG)
                                    Log.d(TAG, "user clicked dont_show_again for raw info dialog");
                                SharedPreferences.Editor editor = sharedPreferences.edit();
                                editor.putBoolean(PreferenceKeys.RawInfoPreferenceKey, true);
                                editor.apply();
                            }
                        });
                        final AlertDialog alert = alertDialog.create();
                        // AlertDialog.Builder.setOnDismissListener() requires API level 17, so do it this way instead
                        alert.setOnDismissListener(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface arg0) {
                                if (MyDebug.LOG)
                                    Log.d(TAG, "raw dialog dismissed");
                                dialogs.remove(alert);
                            }
                        });
                        alert.show();
                        dialogs.add(alert);
                    }
                }
                return true;
            }
        });
    }
    final boolean supports_hdr = bundle.getBoolean("supports_hdr");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_hdr: " + supports_hdr);
    if (!supports_hdr) {
        Preference pref = findPreference("preference_hdr_save_expo");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
        pg.removePreference(pref);
    }
    final boolean supports_expo_bracketing = bundle.getBoolean("supports_expo_bracketing");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_expo_bracketing: " + supports_expo_bracketing);
    final int max_expo_bracketing_n_images = bundle.getInt("max_expo_bracketing_n_images");
    if (MyDebug.LOG)
        Log.d(TAG, "max_expo_bracketing_n_images: " + max_expo_bracketing_n_images);
    final boolean supports_nr = bundle.getBoolean("supports_nr");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_nr: " + supports_nr);
    if (!supports_nr) {
        Preference pref = findPreference("preference_nr_save");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
        pg.removePreference(pref);
    }
    final boolean supports_exposure_compensation = bundle.getBoolean("supports_exposure_compensation");
    final int exposure_compensation_min = bundle.getInt("exposure_compensation_min");
    final int exposure_compensation_max = bundle.getInt("exposure_compensation_max");
    if (MyDebug.LOG) {
        Log.d(TAG, "supports_exposure_compensation: " + supports_exposure_compensation);
        Log.d(TAG, "exposure_compensation_min: " + exposure_compensation_min);
        Log.d(TAG, "exposure_compensation_max: " + exposure_compensation_max);
    }
    final boolean supports_iso_range = bundle.getBoolean("supports_iso_range");
    final int iso_range_min = bundle.getInt("iso_range_min");
    final int iso_range_max = bundle.getInt("iso_range_max");
    if (MyDebug.LOG) {
        Log.d(TAG, "supports_iso_range: " + supports_iso_range);
        Log.d(TAG, "iso_range_min: " + iso_range_min);
        Log.d(TAG, "iso_range_max: " + iso_range_max);
    }
    final boolean supports_exposure_time = bundle.getBoolean("supports_exposure_time");
    final long exposure_time_min = bundle.getLong("exposure_time_min");
    final long exposure_time_max = bundle.getLong("exposure_time_max");
    if (MyDebug.LOG) {
        Log.d(TAG, "supports_exposure_time: " + supports_exposure_time);
        Log.d(TAG, "exposure_time_min: " + exposure_time_min);
        Log.d(TAG, "exposure_time_max: " + exposure_time_max);
    }
    final boolean supports_white_balance_temperature = bundle.getBoolean("supports_white_balance_temperature");
    final int white_balance_temperature_min = bundle.getInt("white_balance_temperature_min");
    final int white_balance_temperature_max = bundle.getInt("white_balance_temperature_max");
    if (MyDebug.LOG) {
        Log.d(TAG, "supports_white_balance_temperature: " + supports_white_balance_temperature);
        Log.d(TAG, "white_balance_temperature_min: " + white_balance_temperature_min);
        Log.d(TAG, "white_balance_temperature_max: " + white_balance_temperature_max);
    }
    if (!supports_expo_bracketing || max_expo_bracketing_n_images <= 3) {
        Preference pref = findPreference("preference_expo_bracketing_n_images");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
        pg.removePreference(pref);
    }
    if (!supports_expo_bracketing) {
        Preference pref = findPreference("preference_expo_bracketing_stops");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
        pg.removePreference(pref);
    }
    preference_video_quality_lp = (ListPreference) findPreference("preference_video_quality");
    setupVideoResolutions(fps_value);
    final String current_video_quality = bundle.getString("current_video_quality");
    final int video_frame_width = bundle.getInt("video_frame_width");
    final int video_frame_height = bundle.getInt("video_frame_height");
    final int video_bit_rate = bundle.getInt("video_bit_rate");
    final int video_frame_rate = bundle.getInt("video_frame_rate");
    final boolean supports_force_video_4k = bundle.getBoolean("supports_force_video_4k");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_force_video_4k: " + supports_force_video_4k);
    if (!supports_force_video_4k || video_quality == null) {
        Preference pref = findPreference("preference_force_video_4k");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_category_video_debugging");
        pg.removePreference(pref);
    }
    final boolean supports_video_stabilization = bundle.getBoolean("supports_video_stabilization");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_video_stabilization: " + supports_video_stabilization);
    if (!supports_video_stabilization) {
        Preference pref = findPreference("preference_video_stabilization");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_video_settings");
        pg.removePreference(pref);
    }
    final boolean can_disable_shutter_sound = bundle.getBoolean("can_disable_shutter_sound");
    if (MyDebug.LOG)
        Log.d(TAG, "can_disable_shutter_sound: " + can_disable_shutter_sound);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !can_disable_shutter_sound) {
        // Camera.enableShutterSound requires JELLY_BEAN_MR1 or greater
        Preference pref = findPreference("preference_shutter_sound");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_camera_controls_more");
        pg.removePreference(pref);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        // Some immersive modes require KITKAT - simpler to require Kitkat for any of the menu options
        Preference pref = findPreference("preference_immersive_mode");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_gui");
        pg.removePreference(pref);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        // the required ExifInterface tags requires Android N or greater
        Preference pref = findPreference("preference_category_exif_tags");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
        pg.removePreference(pref);
    } else {
        setSummary("preference_exif_artist");
        setSummary("preference_exif_copyright");
    }
    final boolean using_android_l = bundle.getBoolean("using_android_l");
    if (!using_android_l) {
        Preference pref = findPreference("preference_show_iso");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_gui");
        pg.removePreference(pref);
    }
    if (!using_android_l) {
        Preference pref = findPreference("preference_camera2_fake_flash");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_category_photo_debugging");
        pg.removePreference(pref);
        pref = findPreference("preference_camera2_fast_burst");
        pg = (PreferenceGroup) this.findPreference("preference_category_photo_debugging");
        pg.removePreference(pref);
    }
    {
        // remove preference_category_photo_debugging category if empty (which will be the case for old api)
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_category_photo_debugging");
        if (MyDebug.LOG)
            Log.d(TAG, "preference_category_photo_debugging children: " + pg.getPreferenceCount());
        if (pg.getPreferenceCount() == 0) {
            // pg.getParent() requires API level 26
            PreferenceGroup parent = (PreferenceGroup) this.findPreference("preference_screen_photo_settings");
            parent.removePreference(pg);
        }
    }
    final boolean supports_camera2 = bundle.getBoolean("supports_camera2");
    if (MyDebug.LOG)
        Log.d(TAG, "supports_camera2: " + supports_camera2);
    if (supports_camera2) {
        final Preference pref = findPreference("preference_use_camera2");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (pref.getKey().equals("preference_use_camera2")) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "user clicked camera2 API - need to restart");
                    // see http://stackoverflow.com/questions/2470870/force-application-to-restart-on-first-activity
                    Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                    return false;
                }
                return false;
            }
        });
    } else {
        Preference pref = findPreference("preference_use_camera2");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_category_online");
        pg.removePreference(pref);
    }
    {
        final Preference pref = findPreference("preference_online_help");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (pref.getKey().equals("preference_online_help")) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "user clicked online help");
                    MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
                    main_activity.launchOnlineHelp();
                    return false;
                }
                return false;
            }
        });
    }
    /*{
        	EditTextPreference edit = (EditTextPreference)findPreference("preference_save_location");
        	InputFilter filter = new InputFilter() { 
        		// whilst Android seems to allow any characters on internal memory, SD cards are typically formatted with FAT32
        		String disallowed = "|\\?*<\":>";
                public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { 
                    for(int i=start;i<end;i++) { 
                    	if( disallowed.indexOf( source.charAt(i) ) != -1 ) {
                            return ""; 
                    	}
                    } 
                    return null; 
                }
        	}; 
        	edit.getEditText().setFilters(new InputFilter[]{filter});         	
        }*/
    {
        Preference pref = findPreference("preference_save_location");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (MyDebug.LOG)
                    Log.d(TAG, "clicked save location");
                MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
                if (main_activity.getStorageUtils().isUsingSAF()) {
                    main_activity.openFolderChooserDialogSAF(true);
                    return true;
                } else {
                    FolderChooserDialog fragment = new SaveFolderChooserDialog();
                    fragment.show(getFragmentManager(), "FOLDER_FRAGMENT");
                    return true;
                }
            }
        });
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Preference pref = findPreference("preference_using_saf");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_camera_controls_more");
        pg.removePreference(pref);
    } else {
        final Preference pref = findPreference("preference_using_saf");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (pref.getKey().equals("preference_using_saf")) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "user clicked saf");
                    if (sharedPreferences.getBoolean(PreferenceKeys.getUsingSAFPreferenceKey(), false)) {
                        if (MyDebug.LOG)
                            Log.d(TAG, "saf is now enabled");
                        // seems better to alway re-show the dialog when the user selects, to make it clear where files will be saved (as the SAF location in general will be different to the non-SAF one)
                        // String uri = sharedPreferences.getString(PreferenceKeys.getSaveLocationSAFPreferenceKey(), "");
                        // if( uri.length() == 0 )
                        {
                            MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
                            Toast.makeText(main_activity, R.string.saf_select_save_location, Toast.LENGTH_SHORT).show();
                            main_activity.openFolderChooserDialogSAF(true);
                        }
                    } else {
                        if (MyDebug.LOG)
                            Log.d(TAG, "saf is now disabled");
                    }
                }
                return false;
            }
        });
    }
    {
        final Preference pref = findPreference("preference_calibrate_level");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (pref.getKey().equals("preference_calibrate_level")) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "user clicked calibrate level option");
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(MyPreferenceFragment.this.getActivity());
                    alertDialog.setTitle(getActivity().getResources().getString(R.string.preference_calibrate_level));
                    alertDialog.setMessage(R.string.preference_calibrate_level_dialog);
                    alertDialog.setPositiveButton(R.string.preference_calibrate_level_calibrate, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int id) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "user clicked calibrate level");
                            MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
                            if (main_activity.getPreview().hasLevelAngle()) {
                                double current_level_angle = main_activity.getPreview().getLevelAngleUncalibrated();
                                SharedPreferences.Editor editor = sharedPreferences.edit();
                                editor.putFloat(PreferenceKeys.CalibratedLevelAnglePreferenceKey, (float) current_level_angle);
                                editor.apply();
                                main_activity.getPreview().updateLevelAngles();
                                Toast.makeText(main_activity, R.string.preference_calibrate_level_calibrated, Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                    alertDialog.setNegativeButton(R.string.preference_calibrate_level_reset, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int id) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "user clicked reset calibration level");
                            MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
                            SharedPreferences.Editor editor = sharedPreferences.edit();
                            editor.putFloat(PreferenceKeys.CalibratedLevelAnglePreferenceKey, 0.0f);
                            editor.apply();
                            main_activity.getPreview().updateLevelAngles();
                            Toast.makeText(main_activity, R.string.preference_calibrate_level_calibration_reset, Toast.LENGTH_SHORT).show();
                        }
                    });
                    final AlertDialog alert = alertDialog.create();
                    // AlertDialog.Builder.setOnDismissListener() requires API level 17, so do it this way instead
                    alert.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface arg0) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "calibration dialog dismissed");
                            dialogs.remove(alert);
                        }
                    });
                    alert.show();
                    dialogs.add(alert);
                    return false;
                }
                return false;
            }
        });
    }
    {
        final Preference pref = findPreference("preference_donate");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (pref.getKey().equals("preference_donate")) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "user clicked to donate");
                    /*Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(MainActivity.getDonateMarketLink()));
            	        try {
            	        	startActivity(browserIntent);
            	        }
            			catch(ActivityNotFoundException e) {
            				// needed in case market:// not supported
            				if( MyDebug.LOG )
            					Log.d(TAG, "can't launch market:// intent");
                	        browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(MainActivity.getDonateLink()));
            	        	startActivity(browserIntent);
            			}*/
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(MainActivity.getDonateLink()));
                    startActivity(browserIntent);
                    return false;
                }
                return false;
            }
        });
    }
    {
        final Preference pref = findPreference("preference_about");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (pref.getKey().equals("preference_about")) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "user clicked about");
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(MyPreferenceFragment.this.getActivity());
                    alertDialog.setTitle(R.string.preference_about);
                    final StringBuilder about_string = new StringBuilder();
                    final String gpl_link = "GPL v3 or later";
                    final String online_help_link = "online help";
                    String version = "UNKNOWN_VERSION";
                    int version_code = -1;
                    try {
                        PackageInfo pInfo = MyPreferenceFragment.this.getActivity().getPackageManager().getPackageInfo(MyPreferenceFragment.this.getActivity().getPackageName(), 0);
                        version = pInfo.versionName;
                        version_code = pInfo.versionCode;
                    } catch (NameNotFoundException e) {
                        if (MyDebug.LOG)
                            Log.d(TAG, "NameNotFoundException exception trying to get version number");
                        e.printStackTrace();
                    }
                    about_string.append("Open Camera v");
                    about_string.append(version);
                    about_string.append("\nCode: ");
                    about_string.append(version_code);
                    about_string.append("\n(c) 2013-2017 Mark Harman");
                    about_string.append("\nReleased under the ");
                    about_string.append(gpl_link);
                    about_string.append(" (Open Camera also uses additional third party files, see " + online_help_link + " for full licences and attributions.)");
                    about_string.append("\nPackage: ");
                    about_string.append(MyPreferenceFragment.this.getActivity().getPackageName());
                    about_string.append("\nAndroid API version: ");
                    about_string.append(Build.VERSION.SDK_INT);
                    about_string.append("\nDevice manufacturer: ");
                    about_string.append(Build.MANUFACTURER);
                    about_string.append("\nDevice model: ");
                    about_string.append(Build.MODEL);
                    about_string.append("\nDevice code-name: ");
                    about_string.append(Build.HARDWARE);
                    about_string.append("\nDevice variant: ");
                    about_string.append(Build.DEVICE);
                    about_string.append("\nLanguage: ");
                    about_string.append(Locale.getDefault().getLanguage());
                    {
                        ActivityManager activityManager = (ActivityManager) getActivity().getSystemService(Activity.ACTIVITY_SERVICE);
                        about_string.append("\nStandard max heap?: ");
                        about_string.append(activityManager.getMemoryClass());
                        about_string.append("\nLarge max heap?: ");
                        about_string.append(activityManager.getLargeMemoryClass());
                    }
                    {
                        Point display_size = new Point();
                        Display display = MyPreferenceFragment.this.getActivity().getWindowManager().getDefaultDisplay();
                        display.getSize(display_size);
                        about_string.append("\nDisplay size: ");
                        about_string.append(display_size.x);
                        about_string.append("x");
                        about_string.append(display_size.y);
                    }
                    about_string.append("\nCurrent camera ID: ");
                    about_string.append(cameraId);
                    about_string.append("\nNo. of cameras: ");
                    about_string.append(nCameras);
                    about_string.append("\nCamera API: ");
                    about_string.append(camera_api);
                    {
                        String last_video_error = sharedPreferences.getString("last_video_error", "");
                        if (last_video_error.length() > 0) {
                            about_string.append("\nLast video error: ");
                            about_string.append(last_video_error);
                        }
                    }
                    if (preview_widths != null && preview_heights != null) {
                        about_string.append("\nPreview resolutions: ");
                        for (int i = 0; i < preview_widths.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(preview_widths[i]);
                            about_string.append("x");
                            about_string.append(preview_heights[i]);
                        }
                    }
                    about_string.append("\nPreview resolution: ");
                    about_string.append(preview_width);
                    about_string.append("x");
                    about_string.append(preview_height);
                    if (widths != null && heights != null) {
                        about_string.append("\nPhoto resolutions: ");
                        for (int i = 0; i < widths.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(widths[i]);
                            about_string.append("x");
                            about_string.append(heights[i]);
                        }
                    }
                    about_string.append("\nPhoto resolution: ");
                    about_string.append(resolution_width);
                    about_string.append("x");
                    about_string.append(resolution_height);
                    if (video_quality != null) {
                        about_string.append("\nVideo qualities: ");
                        for (int i = 0; i < video_quality.size(); i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(video_quality.get(i));
                        }
                    }
                    if (video_widths != null && video_heights != null) {
                        about_string.append("\nVideo resolutions: ");
                        for (int i = 0; i < video_widths.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(video_widths[i]);
                            about_string.append("x");
                            about_string.append(video_heights[i]);
                        }
                    }
                    about_string.append("\nVideo quality: ");
                    about_string.append(current_video_quality);
                    about_string.append("\nVideo frame width: ");
                    about_string.append(video_frame_width);
                    about_string.append("\nVideo frame height: ");
                    about_string.append(video_frame_height);
                    about_string.append("\nVideo bit rate: ");
                    about_string.append(video_bit_rate);
                    about_string.append("\nVideo frame rate: ");
                    about_string.append(video_frame_rate);
                    about_string.append("\nAuto-stabilise?: ");
                    about_string.append(getString(supports_auto_stabilise ? R.string.about_available : R.string.about_not_available));
                    about_string.append("\nAuto-stabilise enabled?: ");
                    about_string.append(sharedPreferences.getBoolean(PreferenceKeys.AutoStabilisePreferenceKey, false));
                    about_string.append("\nFace detection?: ");
                    about_string.append(getString(supports_face_detection ? R.string.about_available : R.string.about_not_available));
                    about_string.append("\nRAW?: ");
                    about_string.append(getString(supports_raw ? R.string.about_available : R.string.about_not_available));
                    about_string.append("\nHDR?: ");
                    about_string.append(getString(supports_hdr ? R.string.about_available : R.string.about_not_available));
                    about_string.append("\nExpo?: ");
                    about_string.append(getString(supports_expo_bracketing ? R.string.about_available : R.string.about_not_available));
                    about_string.append("\nExpo compensation?: ");
                    about_string.append(getString(supports_exposure_compensation ? R.string.about_available : R.string.about_not_available));
                    if (supports_exposure_compensation) {
                        about_string.append("\nExposure compensation range: ");
                        about_string.append(exposure_compensation_min);
                        about_string.append(" to ");
                        about_string.append(exposure_compensation_max);
                    }
                    about_string.append("\nManual ISO?: ");
                    about_string.append(getString(supports_iso_range ? R.string.about_available : R.string.about_not_available));
                    if (supports_iso_range) {
                        about_string.append("\nISO range: ");
                        about_string.append(iso_range_min);
                        about_string.append(" to ");
                        about_string.append(iso_range_max);
                    }
                    about_string.append("\nManual exposure?: ");
                    about_string.append(getString(supports_exposure_time ? R.string.about_available : R.string.about_not_available));
                    if (supports_exposure_time) {
                        about_string.append("\nExposure range: ");
                        about_string.append(exposure_time_min);
                        about_string.append(" to ");
                        about_string.append(exposure_time_max);
                    }
                    about_string.append("\nManual WB?: ");
                    about_string.append(getString(supports_white_balance_temperature ? R.string.about_available : R.string.about_not_available));
                    if (supports_white_balance_temperature) {
                        about_string.append("\nWB temperature: ");
                        about_string.append(white_balance_temperature_min);
                        about_string.append(" to ");
                        about_string.append(white_balance_temperature_max);
                    }
                    about_string.append("\nVideo stabilization?: ");
                    about_string.append(getString(supports_video_stabilization ? R.string.about_available : R.string.about_not_available));
                    about_string.append("\nCan disable shutter sound?: ");
                    about_string.append(getString(can_disable_shutter_sound ? R.string.about_available : R.string.about_not_available));
                    about_string.append("\nFlash modes: ");
                    String[] flash_values = bundle.getStringArray("flash_values");
                    if (flash_values != null && flash_values.length > 0) {
                        for (int i = 0; i < flash_values.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(flash_values[i]);
                        }
                    } else {
                        about_string.append("None");
                    }
                    about_string.append("\nFocus modes: ");
                    String[] focus_values = bundle.getStringArray("focus_values");
                    if (focus_values != null && focus_values.length > 0) {
                        for (int i = 0; i < focus_values.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(focus_values[i]);
                        }
                    } else {
                        about_string.append("None");
                    }
                    about_string.append("\nColor effects: ");
                    String[] color_effects_values = bundle.getStringArray("color_effects");
                    if (color_effects_values != null && color_effects_values.length > 0) {
                        for (int i = 0; i < color_effects_values.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(color_effects_values[i]);
                        }
                    } else {
                        about_string.append("None");
                    }
                    about_string.append("\nScene modes: ");
                    String[] scene_modes_values = bundle.getStringArray("scene_modes");
                    if (scene_modes_values != null && scene_modes_values.length > 0) {
                        for (int i = 0; i < scene_modes_values.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(scene_modes_values[i]);
                        }
                    } else {
                        about_string.append("None");
                    }
                    about_string.append("\nWhite balances: ");
                    String[] white_balances_values = bundle.getStringArray("white_balances");
                    if (white_balances_values != null && white_balances_values.length > 0) {
                        for (int i = 0; i < white_balances_values.length; i++) {
                            if (i > 0) {
                                about_string.append(", ");
                            }
                            about_string.append(white_balances_values[i]);
                        }
                    } else {
                        about_string.append("None");
                    }
                    if (!using_android_l) {
                        about_string.append("\nISOs: ");
                        String[] isos = bundle.getStringArray("isos");
                        if (isos != null && isos.length > 0) {
                            for (int i = 0; i < isos.length; i++) {
                                if (i > 0) {
                                    about_string.append(", ");
                                }
                                about_string.append(isos[i]);
                            }
                        } else {
                            about_string.append("None");
                        }
                        String iso_key = bundle.getString("iso_key");
                        if (iso_key != null) {
                            about_string.append("\nISO key: ");
                            about_string.append(iso_key);
                        }
                    }
                    about_string.append("\nUsing SAF?: ");
                    about_string.append(sharedPreferences.getBoolean(PreferenceKeys.getUsingSAFPreferenceKey(), false));
                    String save_location = sharedPreferences.getString(PreferenceKeys.getSaveLocationPreferenceKey(), "OpenCamera");
                    about_string.append("\nSave Location: ");
                    about_string.append(save_location);
                    String save_location_saf = sharedPreferences.getString(PreferenceKeys.getSaveLocationSAFPreferenceKey(), "");
                    about_string.append("\nSave Location SAF: ");
                    about_string.append(save_location_saf);
                    about_string.append("\nParameters: ");
                    String parameters_string = bundle.getString("parameters_string");
                    if (parameters_string != null) {
                        about_string.append(parameters_string);
                    } else {
                        about_string.append("None");
                    }
                    SpannableString span = new SpannableString(about_string);
                    span.setSpan(new ClickableSpan() {

                        @Override
                        public void onClick(View v) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "gpl link clicked");
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.gnu.org/copyleft/gpl.html"));
                            startActivity(browserIntent);
                        }
                    }, about_string.indexOf(gpl_link), about_string.indexOf(gpl_link) + gpl_link.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                    span.setSpan(new ClickableSpan() {

                        @Override
                        public void onClick(View v) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "online help link clicked");
                            MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
                            main_activity.launchOnlineHelp();
                        }
                    }, about_string.indexOf(online_help_link), about_string.indexOf(online_help_link) + online_help_link.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                    // clickable text is only supported if we call setMovementMethod on the TextView - which means we need to create
                    // our own for the AlertDialog!
                    final float scale = getActivity().getResources().getDisplayMetrics().density;
                    TextView textView = new TextView(getActivity());
                    textView.setText(span);
                    textView.setMovementMethod(LinkMovementMethod.getInstance());
                    textView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Medium);
                    ScrollView scrollView = new ScrollView(getActivity());
                    scrollView.addView(textView);
                    // padding values from /sdk/platforms/android-18/data/res/layout/alert_dialog.xml
                    textView.setPadding((int) (5 * scale + 0.5f), (int) (5 * scale + 0.5f), (int) (5 * scale + 0.5f), (int) (5 * scale + 0.5f));
                    scrollView.setPadding((int) (14 * scale + 0.5f), (int) (2 * scale + 0.5f), (int) (10 * scale + 0.5f), (int) (12 * scale + 0.5f));
                    alertDialog.setView(scrollView);
                    // alertDialog.setMessage(about_string);
                    alertDialog.setPositiveButton(android.R.string.ok, null);
                    alertDialog.setNegativeButton(R.string.about_copy_to_clipboard, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int id) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "user clicked copy to clipboard");
                            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("OpenCamera About", about_string);
                            clipboard.setPrimaryClip(clip);
                        }
                    });
                    final AlertDialog alert = alertDialog.create();
                    // AlertDialog.Builder.setOnDismissListener() requires API level 17, so do it this way instead
                    alert.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface arg0) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "about dialog dismissed");
                            dialogs.remove(alert);
                        }
                    });
                    alert.show();
                    dialogs.add(alert);
                    return false;
                }
                return false;
            }
        });
    }
    {
        final Preference pref = findPreference("preference_reset");
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                if (pref.getKey().equals("preference_reset")) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "user clicked reset");
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(MyPreferenceFragment.this.getActivity());
                    alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                    alertDialog.setTitle(R.string.preference_reset);
                    alertDialog.setMessage(R.string.preference_reset_question);
                    alertDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "user confirmed reset");
                            SharedPreferences.Editor editor = sharedPreferences.edit();
                            editor.clear();
                            editor.putBoolean(PreferenceKeys.FirstTimePreferenceKey, true);
                            try {
                                PackageInfo pInfo = MyPreferenceFragment.this.getActivity().getPackageManager().getPackageInfo(MyPreferenceFragment.this.getActivity().getPackageName(), 0);
                                int version_code = pInfo.versionCode;
                                editor.putInt(PreferenceKeys.LatestVersionPreferenceKey, version_code);
                            } catch (NameNotFoundException e) {
                                if (MyDebug.LOG)
                                    Log.d(TAG, "NameNotFoundException exception trying to get version number");
                                e.printStackTrace();
                            }
                            editor.apply();
                            MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
                            main_activity.setDeviceDefaults();
                            if (MyDebug.LOG)
                                Log.d(TAG, "user clicked reset - need to restart");
                            // see http://stackoverflow.com/questions/2470870/force-application-to-restart-on-first-activity
                            Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
                            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(i);
                        }
                    });
                    alertDialog.setNegativeButton(android.R.string.no, null);
                    final AlertDialog alert = alertDialog.create();
                    // AlertDialog.Builder.setOnDismissListener() requires API level 17, so do it this way instead
                    alert.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface arg0) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "reset dialog dismissed");
                            dialogs.remove(alert);
                        }
                    });
                    alert.show();
                    dialogs.add(alert);
                }
                return false;
            }
        });
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) SpannableString(android.text.SpannableString) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) ActivityManager(android.app.ActivityManager) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) FolderChooserDialog(net.sourceforge.opencamera.UI.FolderChooserDialog) TextView(android.widget.TextView) ClipboardManager(android.content.ClipboardManager) SharedPreferences(android.content.SharedPreferences) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Bundle(android.os.Bundle) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) ListPreference(android.preference.ListPreference) Point(android.graphics.Point) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) Point(android.graphics.Point) SpannableString(android.text.SpannableString) OnClickListener(android.content.DialogInterface.OnClickListener) ScrollView(android.widget.ScrollView) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) OnClickListener(android.content.DialogInterface.OnClickListener) PreferenceGroup(android.preference.PreferenceGroup) ClipData(android.content.ClipData) Display(android.view.Display)

Example 4 with PreferenceGroup

use of android.preference.PreferenceGroup in project OpenCamera by ageback.

the class MyPreferenceFragment method setupVideoResolutions.

/**
 * Call to set up or update the video resolutions listpreference.
 *  Note that we don't care if the currently selected preference for video resolution is no
 *  longer in the supported list for the new fps value, we let the user select a new one, else
 *  the Preview will choose an appropriate resolution when the user exits settings.
 */
private void setupVideoResolutions(String fps_value) {
    if (MyDebug.LOG)
        Log.d(TAG, "setupVideoResolutions: " + fps_value);
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
    // video_quality = main_activity.getPreview().getVideoQualityHander().getSupportedVideoQuality();
    video_quality = main_activity.getPreview().getSupportedVideoQuality(fps_value);
    if (video_quality == null || video_quality.size() == 0) {
        Log.e(TAG, "can't find any supported video sizes for current fps!");
        // fall back to unfiltered list
        video_quality = main_activity.getPreview().getVideoQualityHander().getSupportedVideoQuality();
    }
    if (video_quality != null) {
        CharSequence[] entries = new CharSequence[video_quality.size()];
        CharSequence[] values = new CharSequence[video_quality.size()];
        for (int i = 0; i < video_quality.size(); i++) {
            entries[i] = main_activity.getPreview().getCamcorderProfileDescription(video_quality.get(i));
            values[i] = video_quality.get(i);
        }
        ListPreference lp = preference_video_quality_lp;
        lp.setEntries(entries);
        lp.setEntryValues(values);
        String video_quality_preference_key = PreferenceKeys.getVideoQualityPreferenceKey(cameraId, main_activity.getPreview().fpsIsHighSpeed(fps_value));
        if (MyDebug.LOG)
            Log.d(TAG, "video_quality_preference_key: " + video_quality_preference_key);
        String video_quality_value = sharedPreferences.getString(video_quality_preference_key, "");
        if (MyDebug.LOG)
            Log.d(TAG, "video_quality_value: " + video_quality_value);
        // set the key, so we save for the correct cameraId and high-speed setting
        // this must be done before setting the value (otherwise the video resolutions preference won't be
        // updated correctly when this is called from the callback when the user switches between
        // normal and high speed frame rates
        lp.setKey(video_quality_preference_key);
        lp.setValue(video_quality_value);
    } else {
        Preference pref = findPreference("preference_video_quality");
        PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_video_settings");
        pg.removePreference(pref);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) PreferenceGroup(android.preference.PreferenceGroup) ListPreference(android.preference.ListPreference) SpannableString(android.text.SpannableString) Point(android.graphics.Point)

Example 5 with PreferenceGroup

use of android.preference.PreferenceGroup in project keepass2android by PhilippC.

the class InputLanguageSelection method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    // Get the settings preferences
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Design.updateTheme(this, sp);
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.language_prefs);
    mSelectedLanguages = sp.getString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, "");
    String[] languageList = mSelectedLanguages.split(",");
    // first try to get the unique locales in a strict mode (filtering most redundant layouts like English (Jamaica) etc.)
    mAvailableLanguages = getUniqueLocales(true);
    // sometimes the strict check returns only EN_US, EN_GB and ES_US. Accept more in these cases:
    if (mAvailableLanguages.size() < 5) {
        mAvailableLanguages = getUniqueLocales(false);
    }
    PreferenceGroup parent = getPreferenceScreen();
    for (int i = 0; i < mAvailableLanguages.size(); i++) {
        CheckBoxPreference pref = new CheckBoxPreference(this);
        Locale locale = mAvailableLanguages.get(i).locale;
        pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale), locale));
        boolean checked = isLocaleIn(locale, languageList);
        pref.setChecked(checked);
        if (hasDictionary(locale, this)) {
            pref.setSummary(R.string.has_dictionary);
        }
        parent.addPreference(pref);
    }
}
Also used : Locale(java.util.Locale) SharedPreferences(android.content.SharedPreferences) CheckBoxPreference(android.preference.CheckBoxPreference) PreferenceGroup(android.preference.PreferenceGroup)

Aggregations

PreferenceGroup (android.preference.PreferenceGroup)38 Preference (android.preference.Preference)26 ListPreference (android.preference.ListPreference)7 SharedPreferences (android.content.SharedPreferences)6 CheckBoxPreference (android.preference.CheckBoxPreference)6 PreferenceScreen (android.preference.PreferenceScreen)6 Intent (android.content.Intent)5 Bundle (android.os.Bundle)4 TwoStatePreference (android.preference.TwoStatePreference)4 ArrayList (java.util.ArrayList)4 EditTextPreference (android.preference.EditTextPreference)3 MultiSelectListPreference (android.preference.MultiSelectListPreference)3 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)3 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)3 Point (android.graphics.Point)2 DialogPreference (android.preference.DialogPreference)2 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)2 PreferenceCategory (android.preference.PreferenceCategory)2 SpannableString (android.text.SpannableString)2 View (android.view.View)2