Example usage for android.preference CheckBoxPreference CheckBoxPreference

List of usage examples for android.preference CheckBoxPreference CheckBoxPreference

Introduction

In this page you can find the example usage for android.preference CheckBoxPreference CheckBoxPreference.

Prototype

public CheckBoxPreference(Context context) 

Source Link

Usage

From source file:nya.miku.wishmaster.api.AbstractChanModule.java

/**
 *     ( ?/ )   ? ?-?//from  ww  w  .java 2s . c  o m
 * @param group ,   ??? 
 */
protected void addProxyPreferences(PreferenceGroup group) {
    final Context context = group.getContext();
    PreferenceCategory proxyCat = new PreferenceCategory(context); //? ? ?
    proxyCat.setTitle(R.string.pref_cat_proxy);
    group.addPreference(proxyCat);
    CheckBoxPreference useProxyPref = new CheckBoxPreference(context); //? "?  ? "
    useProxyPref.setTitle(R.string.pref_use_proxy);
    useProxyPref.setSummary(R.string.pref_use_proxy_summary);
    useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY));
    useProxyPref.setDefaultValue(false);
    useProxyPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(useProxyPref);
    EditTextPreference proxyHostPref = new EditTextPreference(context); //  ? ?-?
    proxyHostPref.setTitle(R.string.pref_proxy_host);
    proxyHostPref.setDialogTitle(R.string.pref_proxy_host);
    proxyHostPref.setSummary(R.string.pref_proxy_host_summary);
    proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST));
    proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST);
    proxyHostPref.getEditText().setSingleLine();
    proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    proxyHostPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPref);
    proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
    EditTextPreference proxyHostPort = new EditTextPreference(context); //   ?-?
    proxyHostPort.setTitle(R.string.pref_proxy_port);
    proxyHostPort.setDialogTitle(R.string.pref_proxy_port);
    proxyHostPort.setSummary(R.string.pref_proxy_port_summary);
    proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT));
    proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT);
    proxyHostPort.getEditText().setSingleLine();
    proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    proxyHostPort.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPort);
    proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
}

From source file:de.azapps.mirakel.settings.model_settings.special_list.SpecialListDetailFragment.java

private CheckBoxPreference getIsActivePreference() {
    final CheckBoxPreference active = new CheckBoxPreference(getActivity());
    active.setTitle(R.string.special_list_active);
    active.setChecked(mItem.isActive());
    active.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//w ww .  j a v a 2s .co  m
        public boolean onPreferenceClick(Preference preference) {
            boolean a = !active.isChecked();
            mItem.setActive(a);
            mItem.save();
            active.setChecked(mItem.isActive());
            mAdapter.notifyDataSetChanged();
            return true;
        }
    });
    return active;
}

From source file:com.github.howeyc.slideshow.activities.SettingsActivity.java

private void setIncludeSubdirsSwitchPref() {
    Preference myRecCheckbox;/*from   w  ww.  j  a  v a 2  s.c om*/
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        myRecCheckbox = new CheckBoxPreference(this);
        ((CheckBoxPreference) myRecCheckbox).setSummaryOff(R.string.sett_recursiveSearchSummOff);
        ((CheckBoxPreference) myRecCheckbox).setSummaryOn(R.string.sett_recursiveSearchSummOn);
    } else {
        myRecCheckbox = new MySwitchPref(this);
        ((MySwitchPref) myRecCheckbox).setSummaryOff(R.string.sett_recursiveSearchSummOff);
        ((MySwitchPref) myRecCheckbox).setSummaryOn(R.string.sett_recursiveSearchSummOn);
    }
    myRecCheckbox.setTitle(R.string.sett_recursiveSearch);
    myRecCheckbox.setSummary(R.string.sett_recursiveSearchSumm);
    myRecCheckbox.setDefaultValue(true);
    myRecCheckbox.setKey(getString(R.string.sett_key_recursiveSearch));
    if (myCat2 != null) {
        myCat2.addPreference(myRecCheckbox);
    }
}

From source file:org.linphone.SettingsFragment.java

private void initAudioSettings() {
    PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_codecs_key));
    if (codecs == null)
        return;//  ww w.j av a  2 s . c  o  m

    codecs.removeAll();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    for (final PayloadType pt : lc.getAudioCodecs()) {
        CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
        codec.setTitle(pt.getMime());
        codec.setSummary(pt.getRate() + " Hz");
        codec.setChecked(lc.isPayloadTypeEnabled(pt));

        codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enable = (Boolean) newValue;
                try {
                    LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
                } catch (LinphoneCoreException e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        codecs.addPreference(codec);
    }

    CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(
            getString(R.string.pref_echo_cancellation_key));
    echoCancellation.setChecked(mPrefs.isEchoCancellationEnabled());

    if (mPrefs.isEchoCancellationEnabled()) {
        Preference echoCalibration = findPreference(getString(R.string.pref_echo_canceller_calibration_key));
        echoCalibration
                .setSummary(String.format(getString(R.string.ec_calibrated), mPrefs.getEchoCalibration()));
    }

    CheckBoxPreference adaptiveRateControl = (CheckBoxPreference) findPreference(
            getString(R.string.pref_adaptive_rate_control_key));
    adaptiveRateControl.setChecked(mPrefs.isAdaptiveRateControlEnabled());

    ListPreference adaptiveRateAlgorithm = (ListPreference) findPreference(
            getString(R.string.pref_adaptive_rate_algorithm_key));
    adaptiveRateAlgorithm.setSummary(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));
    adaptiveRateAlgorithm.setValue(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));

    ListPreference bitrateLimit = (ListPreference) findPreference(
            getString(R.string.pref_codec_bitrate_limit_key));
    bitrateLimit.setSummary(String.valueOf(mPrefs.getCodecBitrateLimit()));
    bitrateLimit.setValue(String.valueOf(mPrefs.getCodecBitrateLimit()));
}

From source file:org.linphone.SettingsFragment.java

private void initVideoSettings() {
    initializePreferredVideoSizePreferences(
            (ListPreference) findPreference(getString(R.string.pref_preferred_video_size_key)));

    PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key));

    if (codecs == null)
        return;//from w w w  .  java  2  s  .co  m

    codecs.removeAll();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    for (final PayloadType pt : lc.getVideoCodecs()) {
        CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
        codec.setTitle(pt.getMime());

        if (!pt.getMime().equals("VP8")) {
            if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
                continue;
            } else {
                if (!Version.hasFastCpuWithAsmOptim() && pt.getMime().equals("H264")) {
                    // Android without neon doesn't support H264
                    Log.w("CPU does not have asm optimisations available, disabling H264");
                    continue;
                }
            }
        }
        codec.setChecked(lc.isPayloadTypeEnabled(pt));

        codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enable = (Boolean) newValue;
                try {
                    LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
                } catch (LinphoneCoreException e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        codecs.addPreference(codec);
    }

    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_enable_key)))
            .setChecked(mPrefs.isVideoEnabled());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_use_front_camera_key)))
            .setChecked(mPrefs.useFrontCam());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_initiate_call_with_video_key)))
            .setChecked(mPrefs.shouldInitiateVideoCall());
    //((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_share_my_video_key))).setChecked(mPrefs.shouldAutomaticallyShareMyVideo());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_accept_video_key)))
            .setChecked(mPrefs.shouldAutomaticallyAcceptVideoRequests());
}

From source file:github.daneren2005.dsub.fragments.SettingsFragment.java

private PreferenceScreen expandServer(final int instance) {
    final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context);
    screen.setTitle(R.string.settings_server_unused);
    screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance);

    final EditTextPreference serverNamePreference = new EditTextPreference(context);
    serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance);
    serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused));
    serverNamePreference.setTitle(R.string.settings_server_name);
    serverNamePreference.setDialogTitle(R.string.settings_server_name);

    if (serverNamePreference.getText() == null) {
        serverNamePreference.setText(getResources().getString(R.string.settings_server_unused));
    }//  ww w  .  ja va2  s.  c o  m

    serverNamePreference.setSummary(serverNamePreference.getText());

    final EditTextPreference serverUrlPreference = new EditTextPreference(context);
    serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance);
    serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverUrlPreference.setDefaultValue("http://yourhost");
    serverUrlPreference.setTitle(R.string.settings_server_address);
    serverUrlPreference.setDialogTitle(R.string.settings_server_address);

    if (serverUrlPreference.getText() == null) {
        serverUrlPreference.setText("http://yourhost");
    }

    serverUrlPreference.setSummary(serverUrlPreference.getText());
    screen.setSummary(serverUrlPreference.getText());

    final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) {
        @Override
        protected void onAddEditTextToDialogView(View dialogView, final EditText editText) {
            super.onAddEditTextToDialogView(dialogView, editText);
            ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0);

            Button defaultButton = new Button(getContext());
            defaultButton.setText(internalSSIDDisplay);
            defaultButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    editText.setText(internalSSID);
                }
            });
            root.addView(defaultButton);
        }
    };
    serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance);
    serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid);
    serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid);

    final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context);
    serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance);
    serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverInternalUrlPreference.setDefaultValue("");
    serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText());

    final EditTextPreference serverUsernamePreference = new EditTextPreference(context);
    serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance);
    serverUsernamePreference.setTitle(R.string.settings_server_username);
    serverUsernamePreference.setDialogTitle(R.string.settings_server_username);

    final EditTextPreference serverPasswordPreference = new EditTextPreference(context);
    serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance);
    serverPasswordPreference.getEditText()
            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    serverPasswordPreference.setSummary("***");
    serverPasswordPreference.setTitle(R.string.settings_server_password);

    final CheckBoxPreference serverTagPreference = new CheckBoxPreference(context);
    serverTagPreference.setKey(Constants.PREFERENCES_KEY_BROWSE_TAGS + instance);
    serverTagPreference.setChecked(Util.isTagBrowsing(context, instance));
    serverTagPreference.setSummary(R.string.settings_browse_by_tags_summary);
    serverTagPreference.setTitle(R.string.settings_browse_by_tags);
    serverPasswordPreference.setDialogTitle(R.string.settings_server_password);

    final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context);
    serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance);
    serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance));
    serverSyncPreference.setSummary(R.string.settings_server_sync_summary);
    serverSyncPreference.setTitle(R.string.settings_server_sync);

    final Preference serverOpenBrowser = new Preference(context);
    serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER);
    serverOpenBrowser.setPersistent(false);
    serverOpenBrowser.setTitle(R.string.settings_server_open_browser);
    serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            openInBrowser(instance);
            return true;
        }
    });

    Preference serverRemoveServerPreference = new Preference(context);
    serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance);
    serverRemoveServerPreference.setPersistent(false);
    serverRemoveServerPreference.setTitle(R.string.settings_servers_remove);

    serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Reset values to null so when we ask for them again they are new
                            serverNamePreference.setText(null);
                            serverUrlPreference.setText(null);
                            serverUsernamePreference.setText(null);
                            serverPasswordPreference.setText(null);

                            // Don't use Util.getActiveServer since it is 0 if offline
                            int activeServer = Util.getPreferences(context)
                                    .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
                            for (int i = instance; i <= serverCount; i++) {
                                Util.removeInstanceName(context, i, activeServer);
                            }

                            serverCount--;
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
                            editor.commit();

                            removeCurrent();

                            SubsonicFragment parentFragment = context.getCurrentFragment();
                            if (parentFragment instanceof SettingsFragment) {
                                SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment;
                                serverSelectionFragment.checkForRemoved();
                            }
                        }
                    });

            return true;
        }
    });

    Preference serverTestConnectionPreference = new Preference(context);
    serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance);
    serverTestConnectionPreference.setPersistent(false);
    serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title);
    serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            testConnection(instance);
            return false;
        }
    });

    screen.addPreference(serverNamePreference);
    screen.addPreference(serverUrlPreference);
    screen.addPreference(serverInternalUrlPreference);
    screen.addPreference(serverLocalNetworkSSIDPreference);
    screen.addPreference(serverUsernamePreference);
    screen.addPreference(serverPasswordPreference);
    screen.addPreference(serverTagPreference);
    screen.addPreference(serverSyncPreference);
    screen.addPreference(serverTestConnectionPreference);
    screen.addPreference(serverOpenBrowser);
    screen.addPreference(serverRemoveServerPreference);

    return screen;
}

From source file:github.popeen.dsub.fragments.SettingsFragment.java

private PreferenceScreen expandServer(final int instance) {
    final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context);
    screen.setTitle(R.string.settings_server_unused);
    screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance);

    final EditTextPreference serverNamePreference = new EditTextPreference(context);
    serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance);
    serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused));
    serverNamePreference.setTitle(R.string.settings_server_name);
    serverNamePreference.setDialogTitle(R.string.settings_server_name);

    if (serverNamePreference.getText() == null) {
        serverNamePreference.setText(getResources().getString(R.string.settings_server_unused));
    }/*from  www  . j a v  a2s  . co  m*/

    serverNamePreference.setSummary(serverNamePreference.getText());

    final EditTextPreference serverUrlPreference = new EditTextPreference(context);
    serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance);
    serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverUrlPreference.setDefaultValue("http://yourhost");
    serverUrlPreference.setTitle(R.string.settings_server_address);
    serverUrlPreference.setDialogTitle(R.string.settings_server_address);

    if (serverUrlPreference.getText() == null) {
        serverUrlPreference.setText("http://yourhost");
    }

    serverUrlPreference.setSummary(serverUrlPreference.getText());
    screen.setSummary(serverUrlPreference.getText());

    final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) {
        @Override
        protected void onAddEditTextToDialogView(View dialogView, final EditText editText) {
            super.onAddEditTextToDialogView(dialogView, editText);
            ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0);

            Button defaultButton = new Button(getContext());
            defaultButton.setText(internalSSIDDisplay);
            defaultButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    editText.setText(internalSSID);
                }
            });
            root.addView(defaultButton);
        }
    };
    serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance);
    serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid);
    serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid);

    final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context);
    serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance);
    serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverInternalUrlPreference.setDefaultValue("");
    serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText());

    final EditTextPreference serverUsernamePreference = new EditTextPreference(context);
    serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance);
    serverUsernamePreference.setTitle(R.string.settings_server_username);
    serverUsernamePreference.setDialogTitle(R.string.settings_server_username);

    final EditTextPreference serverPasswordPreference = new EditTextPreference(context);
    serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance);
    serverPasswordPreference.getEditText()
            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    serverPasswordPreference.setSummary("***");
    serverPasswordPreference.setTitle(R.string.settings_server_password);
    final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context);
    serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance);
    serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance));
    serverSyncPreference.setSummary(R.string.settings_server_sync_summary);
    serverSyncPreference.setTitle(R.string.settings_server_sync);

    final Preference serverOpenBrowser = new Preference(context);
    serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER);
    serverOpenBrowser.setPersistent(false);
    serverOpenBrowser.setTitle(R.string.settings_server_open_browser);
    serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            openInBrowser(instance);
            return true;
        }
    });

    Preference serverRemoveServerPreference = new Preference(context);
    serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance);
    serverRemoveServerPreference.setPersistent(false);
    serverRemoveServerPreference.setTitle(R.string.settings_servers_remove);

    serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Reset values to null so when we ask for them again they are new
                            serverNamePreference.setText(null);
                            serverUrlPreference.setText(null);
                            serverUsernamePreference.setText(null);
                            serverPasswordPreference.setText(null);

                            // Don't use Util.getActiveServer since it is 0 if offline
                            int activeServer = Util.getPreferences(context)
                                    .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
                            for (int i = instance; i <= serverCount; i++) {
                                Util.removeInstanceName(context, i, activeServer);
                            }

                            serverCount--;
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
                            editor.commit();

                            removeCurrent();

                            SubsonicFragment parentFragment = context.getCurrentFragment();
                            if (parentFragment instanceof SettingsFragment) {
                                SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment;
                                serverSelectionFragment.checkForRemoved();
                            }
                        }
                    });

            return true;
        }
    });

    Preference serverTestConnectionPreference = new Preference(context);
    serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance);
    serverTestConnectionPreference.setPersistent(false);
    serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title);
    serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            testConnection(instance);
            return false;
        }
    });

    screen.addPreference(serverNamePreference);
    screen.addPreference(serverUrlPreference);
    screen.addPreference(serverInternalUrlPreference);
    screen.addPreference(serverLocalNetworkSSIDPreference);
    screen.addPreference(serverUsernamePreference);
    screen.addPreference(serverPasswordPreference);
    screen.addPreference(serverSyncPreference);
    screen.addPreference(serverTestConnectionPreference);
    screen.addPreference(serverOpenBrowser);
    screen.addPreference(serverRemoveServerPreference);

    return screen;
}

From source file:org.geometerplus.android.fbreader.preferences.PreferenceActivity.java

@Override
protected void init(Intent intent) {
    try {/*w ww.j a v  a 2 s  .c o  m*/
        this.runFromBook = getIntent().getExtras().getBoolean("fromBook", false);
    } catch (NullPointerException e) {
        this.runFromBook = false;
    }
    if (getIntent() != null) {
        Intent myIntent = getIntent();
        if (myIntent.hasExtra(PreferenceActivity.OPEN_COLOR_PREFERENCES)) {
            showColorsScreen = true;
        }
    }
    setResult(FullReaderActivity.RESULT_REPAINT);

    ReaderApp myReaderApp = (ReaderApp) ReaderApp.Instance();
    if (myReaderApp == null) {
        myReaderApp = new ReaderApp(new BookCollectionShadow());
    }
    final ZLAndroidLibrary androidLibrary = (ZLAndroidLibrary) ZLAndroidLibrary.Instance();
    final ColorProfile profile = myReaderApp.getColorProfile();
    final String profileName = myReaderApp.getColorProfileName();

    //androidLibrary.setActivity(Reader.getInstance());
    //androidLibrary.setActivity(intent.getC);

    //      final ZLAndroidApplication androidApplication = (ZLAndroidApplication)getApplication();
    //      if (androidApplication.myMainWindow == null) {
    //         androidApplication.myMainWindow = new ZLAndroidApplicationWindow(myReaderApp);
    //         myReaderApp.initWindow();
    //      }

    //GENERAL
    Screen appearanceScreen = null;
    Screen GeneralScreen = createPreferenceScreen("general");
    if (!isOpenFromPdfDjvu) {
        appearanceScreen = createPreferenceScreen("appearance");
    }
    Log.d("runFromBookPREFS: ", String.valueOf(runFromBook));
    if (runFromBook) {
        if (android.os.Build.VERSION.SDK_INT >= 11) {
            GeneralScreen.addPreference(new LanguagePreference(this, appearanceScreen.Resource, "language",
                    ZLResource.languages()) {

                @Override
                protected void init() {
                    setInitialValue(ZLResource.LanguageOption.getValue());
                }

                @Override
                protected void setLanguage(String code) {
                    if (!code.equals(ZLResource.LanguageOption.getValue())) {
                        ZLResource.LanguageOption.setValue(code);
                        //               startActivity(new Intent(
                        //                     Intent.ACTION_VIEW, Uri.parse("reader-action:preferences#appearance")
                        //                     ));
                        Editor editor = PreferenceManager.getDefaultSharedPreferences(PreferenceActivity.this)
                                .edit();
                        editor.putString(IConstants.PREF_LOCALE, code);
                        editor.commit();
                        recreatethis();
                    }
                }
            });

            appearanceScreen.addPreference(new ThemeListPreference(this) {

                @Override
                public void updatePref() {
                    //                  startActivity(new Intent(
                    //                        Intent.ACTION_VIEW, Uri.parse("reader-action:preferences#general")
                    //                        ));
                    //                  finish();
                    mFromTheme = true;
                    recreatethis();
                }
            });
        }
    } else {
        if (isOpenFromPdfDjvu) {

        }
        if (!isOpenFromPdfDjvu) {
            GeneralScreen.addPreference(new LanguagePreference(this, appearanceScreen.Resource, "language",
                    ZLResource.languages()) {

                @Override
                protected void init() {
                    setInitialValue(ZLResource.LanguageOption.getValue());
                }

                @Override
                protected void setLanguage(String code) {
                    if (!code.equals(ZLResource.LanguageOption.getValue())) {
                        ZLResource.LanguageOption.setValue(code);
                        //               startActivity(new Intent(
                        //                     Intent.ACTION_VIEW, Uri.parse("reader-action:preferences#appearance")
                        //                     ));
                        Editor editor = PreferenceManager.getDefaultSharedPreferences(PreferenceActivity.this)
                                .edit();
                        editor.putString(IConstants.PREF_LOCALE, code);
                        editor.commit();
                        recreatethis();
                    }
                }
            });

            appearanceScreen.addPreference(new ThemeListPreference(this) {

                @Override
                public void updatePref() {
                    //               startActivity(new Intent(
                    //                     Intent.ACTION_VIEW, Uri.parse("reader-action:preferences#general")
                    //                     ));
                    //               finish();
                    mFromTheme = true;
                    recreatethis();
                }
            });
        }
    }
    //REMINDER
    GeneralScreen.addPreference(
            new ZLBooleanPreference(this, myReaderApp.ReaderOption, GeneralScreen.Resource, "reminder") {
                @Override
                protected void onClick() {
                    super.onClick();
                    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putBoolean("needToRemind", isChecked());
                    editor.commit();
                }
            });

    remindPref = new ReminderChoosePreference(this);
    remindPref.setEnabled(
            PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getBoolean("needToRemind", false));

    GeneralScreen.addPreference(remindPref);
    if (!isOpenFromPdfDjvu) {
        GeneralScreen.addPreference(new OrientationChangePreference(this, GeneralScreen.Resource,
                "screenOrientation", androidLibrary.OrientationOption, androidLibrary.allOrientations()));

        /*      
        final Screen directoriesScreen = createPreferenceScreen("directories");
        directoriesScreen.addPreference(new ZLStringOptionPreference(
           this, Paths.BooksDirectoryOption(), directoriesScreen.Resource, "books"
        ) {
           protected void setValue(String value) {
              super.setValue(value);
              myCollection.reset(false);
           }
        });
        directoriesScreen.addOption(Paths.FontsDirectoryOption(), "fonts");
        directoriesScreen.addOption(Paths.WallpapersDirectoryOption(), "wallpapers");
         */

        //      appearanceScreen.addPreference(new ZLStringChoicePreference(
        //            this, appearanceScreen.Resource, "screenOrientation",
        //            androidLibrary.OrientationOption, androidLibrary.allOrientations()
        //         ));

        appearanceScreen
                .addPreference(new ZLBooleanPreference(this, myReaderApp.AllowScreenBrightnessAdjustmentOption,
                        appearanceScreen.Resource, "allowScreenBrightnessAdjustment") {
                    private final int myLevel = androidLibrary.ScreenBrightnessLevelOption.getValue();

                    @Override
                    protected void onClick() {
                        super.onClick();
                        androidLibrary.ScreenBrightnessLevelOption.setValue(isChecked() ? myLevel : 0);
                    }
                });

        /*appearanceScreen.addPreference(new BatteryLevelToTurnScreenOffPreference(
           this,
           androidLibrary.BatteryLevelToTurnScreenOffOption,
           appearanceScreen.Resource,
           "dontTurnScreenOff"
        ));
                
        appearanceScreen.addPreference(new ZLBooleanPreference(
           this,
           androidLibrary.DontTurnScreenOffDuringChargingOption,
           appearanceScreen.Resource,
           "dontTurnScreenOffDuringCharging"
        ));
                
        appearanceScreen.addOption(androidLibrary.ShowStatusBarOption, "showStatusBar");
        appearanceScreen.addOption(androidLibrary.DisableButtonLightsOption, "disableButtonLights");
                
         */

        final Screen textScreen = createPreferenceScreen("text");
        final Screen fontPropertiesScreen = textScreen.createPreferenceScreen("fontProperties");
        fontPropertiesScreen.addOption(ZLAndroidPaintContext.AntiAliasOption, "antiAlias");
        fontPropertiesScreen.addOption(ZLAndroidPaintContext.DeviceKerningOption, "deviceKerning");
        fontPropertiesScreen.addOption(ZLAndroidPaintContext.DitheringOption, "dithering");
        fontPropertiesScreen.addOption(ZLAndroidPaintContext.SubpixelOption, "subpixel");

        final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance();
        final ZLTextBaseStyle baseStyle = collection.getBaseStyle();

        textScreen.addPreference(
                new FontOption(this, textScreen.Resource, "font", baseStyle.FontFamilyOption, false));
        textScreen.addPreference(new ZLIntegerRangePreference(this, textScreen.Resource.getResource("fontSize"),
                baseStyle.FontSizeOption));
        textScreen.addPreference(new FontStylePreference(this, textScreen.Resource, "fontStyle",
                baseStyle.BoldOption, baseStyle.ItalicOption));
        final ZLIntegerRangeOption spaceOption = baseStyle.LineSpaceOption;
        final String[] spacings = new String[spaceOption.MaxValue - spaceOption.MinValue + 1];
        for (int i = 0; i < spacings.length; ++i) {
            final int val = spaceOption.MinValue + i;
            spacings[i] = (char) (val / 10 + '0') + "." + (char) (val % 10 + '0');
        }
        textScreen.addPreference(
                new ZLChoicePreference(this, textScreen.Resource, "lineSpacing", spaceOption, spacings));
        final String[] alignments = { "left", "right", "center", "justify" };
        textScreen.addPreference(new ZLChoicePreference(this, textScreen.Resource, "alignment",
                baseStyle.AlignmentOption, alignments));
        textScreen.addOption(baseStyle.AutoHyphenationOption, "autoHyphenations");

        final Screen moreStylesScreen = textScreen.createPreferenceScreen("more");

        byte styles[] = { FBTextKind.REGULAR, FBTextKind.TITLE, FBTextKind.SECTION_TITLE, FBTextKind.SUBTITLE,
                FBTextKind.H1, FBTextKind.H2, FBTextKind.H3, FBTextKind.H4, FBTextKind.H5, FBTextKind.H6,
                FBTextKind.ANNOTATION, FBTextKind.EPIGRAPH, FBTextKind.AUTHOR, FBTextKind.POEM_TITLE,
                FBTextKind.STANZA, FBTextKind.VERSE, FBTextKind.CITE, FBTextKind.INTERNAL_HYPERLINK,
                FBTextKind.EXTERNAL_HYPERLINK, FBTextKind.FOOTNOTE, FBTextKind.ITALIC, FBTextKind.EMPHASIS,
                FBTextKind.BOLD, FBTextKind.STRONG, FBTextKind.DEFINITION, FBTextKind.DEFINITION_DESCRIPTION,
                FBTextKind.PREFORMATTED, FBTextKind.CODE };
        for (int i = 0; i < styles.length; ++i) {
            final ZLTextStyleDecoration decoration = collection.getDecoration(styles[i]);
            if (decoration == null) {
                continue;
            }
            ZLTextFullStyleDecoration fullDecoration = decoration instanceof ZLTextFullStyleDecoration
                    ? (ZLTextFullStyleDecoration) decoration
                    : null;

            final Screen formatScreen = moreStylesScreen.createPreferenceScreen(decoration.getName());
            formatScreen.addPreference(
                    new FontOption(this, textScreen.Resource, "font", decoration.FontFamilyOption, true));
            formatScreen.addPreference(new ZLIntegerRangePreference(this,
                    textScreen.Resource.getResource("fontSizeDifference"), decoration.FontSizeDeltaOption));
            formatScreen.addPreference(
                    new ZLBoolean3Preference(this, textScreen.Resource, "bold", decoration.BoldOption));
            formatScreen.addPreference(
                    new ZLBoolean3Preference(this, textScreen.Resource, "italic", decoration.ItalicOption));
            formatScreen.addPreference(new ZLBoolean3Preference(this, textScreen.Resource, "underlined",
                    decoration.UnderlineOption));
            formatScreen.addPreference(new ZLBoolean3Preference(this, textScreen.Resource, "strikedThrough",
                    decoration.StrikeThroughOption));
            if (fullDecoration != null) {
                final String[] allAlignments = { "unchanged", "left", "right", "center", "justify" };
                formatScreen.addPreference(new ZLChoicePreference(this, textScreen.Resource, "alignment",
                        fullDecoration.AlignmentOption, allAlignments));
            }
            formatScreen.addPreference(new ZLBoolean3Preference(this, textScreen.Resource, "allowHyphenations",
                    decoration.AllowHyphenationsOption));
            if (fullDecoration != null) {
                formatScreen.addPreference(new ZLIntegerRangePreference(this,
                        textScreen.Resource.getResource("spaceBefore"), fullDecoration.SpaceBeforeOption));
                formatScreen.addPreference(new ZLIntegerRangePreference(this,
                        textScreen.Resource.getResource("spaceAfter"), fullDecoration.SpaceAfterOption));
                formatScreen.addPreference(new ZLIntegerRangePreference(this,
                        textScreen.Resource.getResource("leftIndent"), fullDecoration.LeftIndentOption));
                formatScreen.addPreference(new ZLIntegerRangePreference(this,
                        textScreen.Resource.getResource("rightIndent"), fullDecoration.RightIndentOption));
                formatScreen.addPreference(
                        new ZLIntegerRangePreference(this, textScreen.Resource.getResource("firstLineIndent"),
                                fullDecoration.FirstLineIndentDeltaOption));
                final ZLIntegerOption spacePercentOption = fullDecoration.LineSpacePercentOption;
                final int[] spacingValues = new int[17];
                final String[] spacingKeys = new String[17];
                spacingValues[0] = -1;
                spacingKeys[0] = "unchanged";
                for (int j = 1; j < spacingValues.length; ++j) {
                    final int val = 4 + j;
                    spacingValues[j] = 10 * val;
                    spacingKeys[j] = (char) (val / 10 + '0') + "." + (char) (val % 10 + '0');
                }
                formatScreen.addPreference(new ZLIntegerChoicePreference(this, textScreen.Resource,
                        "lineSpacing", spacePercentOption, spacingValues, spacingKeys));
            }
        }
        /*final ZLPreferenceSet bgPreferences = new ZLPreferenceSet();
                
                
        if(profileName.equals(ColorProfile.DAY)){
        final Screen colorsScreen = createPreferenceScreen("colors");
           colorsScreen.addPreference(new WallpaperPreference(
          this, profile, colorsScreen.Resource, "background"
          ) {
              @Override
              protected void onDialogClosed(boolean result) {
          super.onDialogClosed(result);
          bgPreferences.setEnabled("".equals(getValue()));
              }
           });
           bgPreferences.add(
          colorsScreen.addOption(profile.BackgroundOption, "#FFFFFF")
              ); 
           bgPreferences.setEnabled("".equals(profile.WallpaperOption.getValue()));
        }*/
        final Screen colorsScreen = createPreferenceScreen("colors");
        if (profileName.equals(ColorProfile.DAY)) {
            final ZLPreferenceSet bgPreferences = new ZLPreferenceSet();
            final WallpaperPreference wallpaperPreference = new WallpaperPreference(this, profile,
                    colorsScreen.Resource, "background") {
                @Override
                protected void onDialogClosed(boolean result) {
                    super.onDialogClosed(result);
                    bgPreferences.setEnabled("".equals(getValue()));
                }
            };
            colorsScreen.addPreference(wallpaperPreference);

            /*
             * ?? ? ? ? 
             */
            WallpaperAlignmentPreference wallpaperAlignment = new WallpaperAlignmentPreference(this);
            wallpaperAlignment.setKey(WallpaperAlignmentPreference.WALLPAPER_ALIGN_KEY);

            String currentLanguage = loadCurrentLanguage();
            if (currentLanguage.equals("ru")) {
                wallpaperAlignment.setTitle(russianTitle);
                wallpaperAlignment.setEntries(russianValues);
            } else if (currentLanguage.equals("uk")) {
                wallpaperAlignment.setTitle(ukrainianTitle);
                wallpaperAlignment.setEntries(ukrainianValues);
            } else if (currentLanguage.equals("en")) {
                wallpaperAlignment.setTitle(englishTitle);
                wallpaperAlignment.setEntries(englishValues);
            } else if (currentLanguage.equals("de")) {
                wallpaperAlignment.setTitle(germanTitle);
                wallpaperAlignment.setEntries(germanValues);
            } else if (currentLanguage.equals("fr")) {
                wallpaperAlignment.setTitle(frenchTitle);
                wallpaperAlignment.setEntries(frenchValues);
            } else {
                if (Locale.getDefault().getDisplayLanguage().equals("??")) {
                    wallpaperAlignment.setTitle(russianTitle);
                    wallpaperAlignment.setEntries(russianValues);
                } else if (Locale.getDefault().getDisplayLanguage().equals("?")) {
                    wallpaperAlignment.setTitle(ukrainianTitle);
                    wallpaperAlignment.setEntries(ukrainianValues);
                } else {
                    wallpaperAlignment.setTitle(englishTitle);
                    wallpaperAlignment.setEntries(englishValues);
                }
            }
            wallpaperAlignment.setEntryValues(R.array.wallpaper_alignment_entry_values);
            //  ,   ? ? ?   ? 
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(PreferenceActivity.this);
            boolean isEnabled = prefs.getBoolean(WallpaperAlignmentPreference.WALLPAPER_ALIGN_ENABLED, false);
            wallpaperAlignment.setEnabled(isEnabled);
            wallpaperPreference.setWallpaperAlignmentPreference(wallpaperAlignment);
            colorsScreen.addPreference(wallpaperAlignment);
            /*
             * 
             */
            /*bgPreferences.add(
               colorsScreen.addOption(profile.BackgroundOption, "backgroundColor")
            );*/
            bgPreferences.setEnabled("".equals(profile.WallpaperOption.getValue()));

            Preference bcgColorPref = colorsScreen.addOption(profile.BackgroundOption, "backgroundColor");
            wallpaperPreference.setBcgColorPreference(bcgColorPref);
            if (wallpaperPreference.getValue().length() != 0)
                bcgColorPref.setEnabled(false);

            colorsScreen.addOption(profile.HighlightingOption, "highlighting");
            colorsScreen.addOption(profile.RegularTextOption, "text");
            colorsScreen.addOption(profile.HyperlinkTextOption, "hyperlink");
            colorsScreen.addOption(profile.VisitedHyperlinkTextOption, "hyperlinkVisited");
            //colorsScreen.addOption(profile.FooterFillOption, "footer");
            colorsScreen.addOption(profile.SelectionBackgroundOption, "selectionBackground");
            colorsScreen.addOption(profile.SelectionForegroundOption, "selectionForeground");
            // Colors SCREEN
            /*colorsScreen.addOption(profile.HighlightingOption, "highlighting");
            colorsScreen.addOption(profile.RegularTextOption, "text");
            colorsScreen.addOption(profile.HyperlinkTextOption, "hyperlink");
            colorsScreen.addOption(profile.VisitedHyperlinkTextOption, "hyperlinkVisited");
            colorsScreen.addOption(profile.FooterFillOption, "footer");
            colorsScreen.addOption(profile.SelectionBackgroundOption, "selectionBackground");
            colorsScreen.addOption(profile.SelectionForegroundOption, "selectionForeground");*/
            //profile

            /*   
            colorsScreen.addOption(profile.SelectionBackgroundOption, "selectionBackground");
            colorsScreen.addOption(profile.HighlightingOption, "highlighting");
            colorsScreen.addOption(profile.HyperlinkTextOption, "hyperlink");
            colorsScreen.addOption(profile.VisitedHyperlinkTextOption, "hyperlinkVisited");
            colorsScreen.addOption(profile.FooterFillOption, "footer");
            colorsScreen.addOption(profile.SelectionBackgroundOption, "selectionBackground");
            colorsScreen.addOption(profile.SelectionForegroundOption, "selectionForeground");
                    
            final Screen marginsScreen = createPreferenceScreen("margins");
            marginsScreen.addPreference(new ZLIntegerRangePreference(
               this, marginsScreen.Resource.getResource("left"),
               fbReader.LeftMarginOption
            ));
            marginsScreen.addPreference(new ZLIntegerRangePreference(
               this, marginsScreen.Resource.getResource("right"),
               fbReader.RightMarginOption
            ));
            marginsScreen.addPreference(new ZLIntegerRangePreference(
               this, marginsScreen.Resource.getResource("top"),
               fbReader.TopMarginOption
            ));
            marginsScreen.addPreference(new ZLIntegerRangePreference(
               this, marginsScreen.Resource.getResource("bottom"),
               fbReader.BottomMarginOption
            ));
                    
            final Screen statusLineScreen = createPreferenceScreen("scrollBar");
                    
            final String[] scrollBarTypes = {"hide", "show", "showAsProgress", "showAsFooter"};
            statusLineScreen.addPreference(new ZLChoicePreference(
               this, statusLineScreen.Resource, "scrollbarType",
               fbReader.ScrollbarTypeOption, scrollBarTypes
            ) {
               @Override
               protected void onDialogClosed(boolean result) {
                  super.onDialogClosed(result);
                  footerPreferences.setEnabled(
             findIndexOfValue(getValue()) == FBView.SCROLLBAR_SHOW_AS_FOOTER
                  );
               }
            });
                    
            footerPreferences.add(statusLineScreen.addPreference(new ZLIntegerRangePreference(
               this, statusLineScreen.Resource.getResource("footerHeight"),
               fbReader.FooterHeightOption
            )));
            footerPreferences.add(statusLineScreen.addOption(profile.FooterFillOption, "footerColor"));
            footerPreferences.add(statusLineScreen.addOption(fbReader.FooterShowTOCMarksOption, "tocMarks"));
                    
            footerPreferences.add(statusLineScreen.addOption(fbReader.FooterShowClockOption, "showClock"));
            footerPreferences.add(statusLineScreen.addOption(fbReader.FooterShowBatteryOption, "showBattery"));
            footerPreferences.add(statusLineScreen.addOption(fbReader.FooterShowProgressOption, "showProgress"));
            footerPreferences.add(statusLineScreen.addPreference(new FontOption(
               this, statusLineScreen.Resource, "font",
               fbReader.FooterFontOption, false
            )));
            footerPreferences.setEnabled(
               fbReader.ScrollbarTypeOption.getValue() == FBView.SCROLLBAR_SHOW_AS_FOOTER
            );
                    
            final Screen colorProfileScreen = createPreferenceScreen("colorProfile");
            final ZLResource resource = colorProfileScreen.Resource;
            colorProfileScreen.setSummary(ColorProfilePreference.createTitle(resource, fbreader.getColorProfileName()));
            for (String key : ColorProfile.names()) {
               colorProfileScreen.addPreference(new ColorProfilePreference(
                  this, fbreader, colorProfileScreen, key, ColorProfilePreference.createTitle(resource, key)
               ));
            }
             */

            /*      final Screen imagesScreen = createPreferenceScreen("images");
            imagesScreen.addOption(fbReader.ImageTappingActionOption, "tappingAction");
            imagesScreen.addOption(fbReader.FitImagesToScreenOption, "fitImagesToScreen");
            imagesScreen.addOption(fbReader.ImageViewBackgroundOption, "backgroundColor");
                    
            final Screen cancelMenuScreen = createPreferenceScreen("cancelMenu");
            cancelMenuScreen.addOption(fbReader.ShowLibraryInCancelMenuOption, "library");
            cancelMenuScreen.addOption(fbReader.ShowNetworkLibraryInCancelMenuOption, "networkLibrary");
            cancelMenuScreen.addOption(fbReader.ShowPreviousBookInCancelMenuOption, "previousBook");
            cancelMenuScreen.addOption(fbReader.ShowPositionsInCancelMenuOption, "positions");
            final String[] backKeyActions =
               { ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU };
            cancelMenuScreen.addPreference(new ZLStringChoicePreference(
               this, cancelMenuScreen.Resource, "backKeyAction",
               keyBindings.getOption(KeyEvent.KEYCODE_BACK, false), backKeyActions
            ));
            final String[] backKeyLongPressActions =
               { ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU, ReaderApp.NoAction };
            cancelMenuScreen.addPreference(new ZLStringChoicePreference(
               this, cancelMenuScreen.Resource, "backKeyLongPressAction",
               keyBindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyLongPressActions
            ));
                    
            final Screen tipsScreen = createPreferenceScreen("tips");
            tipsScreen.addOption(TipsManager.Instance().ShowTipsOption, "showTips");
                    
            final Screen aboutScreen = createPreferenceScreen("about");
            aboutScreen.addPreference(new InfoPreference(
               this,
               aboutScreen.Resource.getResource("version").getValue(),
               androidLibrary.getFullVersionName()
            ));
            aboutScreen.addPreference(new UrlPreference(this, aboutScreen.Resource, "site"));
            aboutScreen.addPreference(new UrlPreference(this, aboutScreen.Resource, "email"));
            aboutScreen.addPreference(new UrlPreference(this, aboutScreen.Resource, "twitter"));
             */
        } else {
            myScreen.removePreference(colorsScreen.myScreen);
        }

        //GENERAL
        Screen otherScreen = createPreferenceScreen("other");

        otherScreen.addPreference(
                new ZLBooleanPreference(this, myReaderApp.DayNight, otherScreen.Resource, "daynightenable") {
                    @Override
                    protected void onClick() {
                        super.onClick();
                        SharedPreferences settings = PreferenceManager
                                .getDefaultSharedPreferences(getContext());
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putBoolean("daynightenable", isChecked());
                        editor.commit();
                    }
                });

        dayNight = new TimePreference(this);
        dayNight.setEnabled(PreferenceManager.getDefaultSharedPreferences(getBaseContext())
                .getBoolean("daynightenable", false));
        otherScreen.addPreference(dayNight);
        //otherScreen.addOption(myReaderApp.EnableDoubleTapOption, "enableDoubleTapDetection");

        final ScrollingPreferences scrollingPreferences = ScrollingPreferences.Instance();
        final Screen scrollingScreen = createPreferenceScreenForScreen("scrolling", otherScreen);

        //AUTOPAGGINg
        scrollingScreen.addPreference(new ZLBooleanPreference(this, myReaderApp.AllowAutopaggingOption,
                GeneralScreen.Resource, "autoscrolling") {
            @Override
            protected void onClick() {
                super.onClick();
                SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
                SharedPreferences.Editor editor = settings.edit();
                if (isChecked()) {
                    FullReaderActivity.autopagingTimer = true;
                } else {
                    FullReaderActivity.autopagingTimer = false;
                }
                editor.putBoolean("needToAutopaging", isChecked());
                editor.commit();
            }
        });

        timePref = new TimeSwitchPreference(this);
        timePref.setEnabled(PreferenceManager.getDefaultSharedPreferences(getBaseContext())
                .getBoolean("needToAutopaging", false));

        scrollingScreen.addPreference(timePref);
        scrollingScreen.addOption(scrollingPreferences.FingerScrollingOption, "fingerScrolling");

        /*
        final ZLPreferenceSet volumeKeysPreferences = new ZLPreferenceSet();
        scrollingScreen.addPreference(new ZLCheckBoxPreference(
           this, scrollingScreen.Resource, "volumeKeys"
        ) {
           {
              setChecked(fbReader.hasActionForKey(KeyEvent.KEYCODE_VOLUME_UP, false));
           }
                
           @Override
           protected void onClick() {
              super.onClick();
              if (isChecked()) {
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ActionCode.VOLUME_KEY_SCROLL_FORWARD);
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ActionCode.VOLUME_KEY_SCROLL_BACK);
              } else {
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ReaderApp.NoAction);
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ReaderApp.NoAction);
              }
              volumeKeysPreferences.setEnabled(isChecked());
           }
        });
        volumeKeysPreferences.add(scrollingScreen.addPreference(new ZLCheckBoxPreference(
           this, scrollingScreen.Resource, "invertVolumeKeys"
        ) {
           {
              setChecked(ActionCode.VOLUME_KEY_SCROLL_FORWARD.equals(
          keyBindings.getBinding(KeyEvent.KEYCODE_VOLUME_UP, false)
              ));
           }
                
           @Override
           protected void onClick() {
              super.onClick();
              if (isChecked()) {
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ActionCode.VOLUME_KEY_SCROLL_BACK);
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ActionCode.VOLUME_KEY_SCROLL_FORWARD);
              } else {
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ActionCode.VOLUME_KEY_SCROLL_FORWARD);
          keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ActionCode.VOLUME_KEY_SCROLL_BACK);
              }
           }
        }));
        volumeKeysPreferences.setEnabled(fbReader.hasActionForKey(KeyEvent.KEYCODE_VOLUME_UP, false));
         */

        scrollingScreen.addOption(scrollingPreferences.AnimationOption, "animation");
        /*scrollingScreen.addPreference(new AnimationSpeedPreference(
              this,
              scrollingScreen.Resource,
              "animationSpeed",
              scrollingPreferences.AnimationSpeedOption
              ));*/

        scrollingScreen.addOption(scrollingPreferences.HorizontalOption, "horizontal");

        final Screen dictionaryScreen = createPreferenceScreenForScreen("dictionary", otherScreen);
        try {
            dictionaryScreen.addPreference(new DictionaryPreference(this, dictionaryScreen.Resource,
                    "dictionary", DictionaryUtil.singleWordTranslatorOption(),
                    DictionaryUtil.dictionaryInfos(this, true)));
            dictionaryScreen.addPreference(new DictionaryPreference(this, dictionaryScreen.Resource,
                    "translator", DictionaryUtil.multiWordTranslatorOption(),
                    DictionaryUtil.dictionaryInfos(this, false)));
        } catch (Exception e) {
            // ignore: dictionary lists are not initialized yet
        }
        dictionaryScreen.addPreference(new ZLBooleanPreference(this, myReaderApp.NavigateAllWordsOption,
                dictionaryScreen.Resource, "navigateOverAllWords"));
        //dictionaryScreen.addOption(myReaderApp.WordTappingActionOption, "tappingAction");

        //initAdMob();

        // ?? ?
        final Screen syncScreen = createPreferenceScreen("synchronization");
        ZLBooleanOption DropboxSync = new ZLBooleanOption("Syncronization", "DropboxSync", false);
        mDbxBoolPref = new ZLBooleanPreference(this, DropboxSync, otherScreen.Resource,
                "synchronizationDropbox");
        mDbxBoolPref.setupForDropbox(this);
        syncScreen.addPreference(mDbxBoolPref);

        /*
         * 
         *   ? ? -
         *  
         */
        tapScreen = createPreferenceScreen("tapzones");
        ZLResource tapRes = ZLResource.resource("tapzones");
        tapzonesListPrefs = new TapzonesListPreference(this);
        tapzonesListPrefs.setKey(TapzonesListPreference.TAPZONES_LIST_KEY);
        String[] entries = new String[] { tapRes.getResource("tapzone_horizontal").getValue(),
                tapRes.getResource("tapzone_vertical").getValue(), };
        String[] entryValues = new String[] { TapzonesListPreference.TAPZONE_HORIZONTAL,
                TapzonesListPreference.TAPZONE_VERTICAL };
        tapzonesListPrefs.setTitle(tapRes.getResource("tapzone_choose").getValue());
        tapzonesListPrefs.setEntries(entries);
        tapzonesListPrefs.setEntryValues(entryValues);
        tapzonesListPrefs.setOnPreferenceChangeListener(tapListPrefChangeListener);
        tapScreen.addPreference(tapzonesListPrefs);

        // ? c ? ?   
        horTapzoneCat = new PreferenceCategory(this);
        horTapzoneCat.setKey(HOR_TAPZONE_CAT);
        horTapzoneCat.setTitle(tapRes.getResource("tapzone_horisontal_category").getValue());
        tapScreen.addPreference(horTapzoneCat);

        String[] tapzoneOptEntries = new String[] { tapRes.getResource("tapzone_next_page").getValue(),
                tapRes.getResource("tapzone_prev_page").getValue(),
                tapRes.getResource("tapzone_day_mode").getValue(),
                tapRes.getResource("tapzone_night_mode").getValue(),
                tapRes.getResource("tapzone_book_info").getValue(),
                tapRes.getResource("tapzone_bookmarks").getValue(),
                tapRes.getResource("tapzone_quotes").getValue(),
                tapRes.getResource("tapzone_preferences").getValue(),
                tapRes.getResource("tapzone_increase_font").getValue(),
                tapRes.getResource("tapzone_decrease_font").getValue(),
                tapRes.getResource("tapzone_contents").getValue(),
                tapRes.getResource("tapzone_search").getValue(),
                tapRes.getResource("tapzone_navigate").getValue(),
                tapRes.getResource("tapzone_close").getValue(),
                tapRes.getResource("tapzone_library").getValue(), tapRes.getResource("tapzone_menu").getValue(),
                tapRes.getResource("tapzone_colors").getValue(),
                tapRes.getResource("tapzone_next_book").getValue(),
                tapRes.getResource("tapzone_previous_book").getValue(),
                tapRes.getResource("tapzone_fullscreen").getValue() };

        horTopPref = new TapzoneOptionsPreference(this);
        horTopPref.setKey(TapzoneOptionsPreference.TAPZONE_HOR_TOP_KEY);
        horTopPref.setTitle(tapRes.getResource("tapzone_top_touch").getValue());
        horTopPref.setEntries(tapzoneOptEntries);
        horTopPref.setEntryValues(TAP_ACTIONS);
        horTopPref.setOnPreferenceChangeListener(tapOptionPrefChangeListener);
        horTapzoneCat.addPreference(horTopPref);

        horCenterPref = new TapzoneOptionsPreference(this);
        horCenterPref.setKey(TapzoneOptionsPreference.TAPZONE_HOR_CENTER_KEY);
        horCenterPref.setTitle(tapRes.getResource("tapzone_center_touch").getValue());
        horCenterPref.setEntries(tapzoneOptEntries);
        horCenterPref.setEntryValues(TAP_ACTIONS);
        horCenterPref.setOnPreferenceChangeListener(tapOptionPrefChangeListener);
        horTapzoneCat.addPreference(horCenterPref);

        horBottomPref = new TapzoneOptionsPreference(this);
        horBottomPref.setKey(TapzoneOptionsPreference.TAPZONE_HOR_BOTTOM_KEY);
        horBottomPref.setTitle(tapRes.getResource("tapzone_bottom_touch").getValue());
        horBottomPref.setEntries(tapzoneOptEntries);
        horBottomPref.setEntryValues(TAP_ACTIONS);
        horBottomPref.setOnPreferenceChangeListener(tapOptionPrefChangeListener);
        horTapzoneCat.addPreference(horBottomPref);

        // ? c ? ?   
        verTapzoneCat = new PreferenceCategory(this);
        verTapzoneCat.setKey(VER_TAPZONE_CAT);
        verTapzoneCat.setTitle(tapRes.getResource("tapzone_vertical_category").getValue());
        tapScreen.addPreference(verTapzoneCat);

        verLeftPref = new TapzoneOptionsPreference(this);
        verLeftPref.setKey(TapzoneOptionsPreference.TAPZONE_VER_LEFT_KEY);
        verLeftPref.setTitle(tapRes.getResource("tapzone_left_touch").getValue());
        verLeftPref.setEntries(tapzoneOptEntries);
        verLeftPref.setEntryValues(TAP_ACTIONS);
        verLeftPref.setOnPreferenceChangeListener(tapOptionPrefChangeListener);
        verTapzoneCat.addPreference(verLeftPref);

        verCenterPref = new TapzoneOptionsPreference(this);
        verCenterPref.setKey(TapzoneOptionsPreference.TAPZONE_VER_CENTER_KEY);
        verCenterPref.setTitle(tapRes.getResource("tapzone_center_touch").getValue());
        verCenterPref.setEntries(tapzoneOptEntries);
        verCenterPref.setEntryValues(TAP_ACTIONS);
        verCenterPref.setOnPreferenceChangeListener(tapOptionPrefChangeListener);
        verTapzoneCat.addPreference(verCenterPref);

        verRightPref = new TapzoneOptionsPreference(this);
        verRightPref.setKey(TapzoneOptionsPreference.TAPZONE_VER_RIGHT_KEY);
        verRightPref.setTitle(tapRes.getResource("tapzone_right_touch").getValue());
        verRightPref.setEntries(tapzoneOptEntries);
        verRightPref.setEntryValues(TAP_ACTIONS);
        verRightPref.setOnPreferenceChangeListener(tapOptionPrefChangeListener);
        verTapzoneCat.addPreference(verRightPref);

        tapzoneDoubleTapPref = tapScreen.addOption(myReaderApp.EnableDoubleTapOption,
                "tapzoneDoubleTapDetection");

        tapDefault = new CheckBoxPreference(this);
        tapDefault.setKey(tapDefaultKey);
        tapDefault.setSummary(tapRes.getResource("tapzone_default").getValue());
        tapDefault.setOnPreferenceChangeListener(mTapDefaultChangeListener);
        tapDefault.setChecked(false);
        tapScreen.addPreference(tapDefault);

        // , ? ?    ?? ?  -
        //  ??  , ?    ?,  ? 
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
        String selectedValue = settings.getString(TapzonesListPreference.TAPZONES_LIST_KEY, "");
        if (selectedValue.equals(TapzonesListPreference.TAPZONE_HORIZONTAL)) {
            tapScreen.myScreen.removePreference(verTapzoneCat);
            initTapPrefs(selectedValue);
        } else if (selectedValue.equals(TapzonesListPreference.TAPZONE_VERTICAL)) {
            tapScreen.myScreen.removePreference(horTapzoneCat);
            initTapPrefs(selectedValue);
        } else {
            tapScreen.myScreen.removePreference(horTapzoneCat);
            tapScreen.myScreen.removePreference(verTapzoneCat);
            tapScreen.myScreen.removePreference(tapzoneDoubleTapPref);
            tapScreen.myScreen.removePreference(tapDefault);
        }

        // ?  -    ? ? ? 
        if (showColorsScreen && profileName.equals(ColorProfile.DAY)) {
            runOnUiThread(new Runnable() {
                public void run() {
                    PreferenceActivity.this.setPreferenceScreen((PreferenceScreen) colorsScreen.myScreen);
                }
            });
        }
    }
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
}