Search in sources :

Example 36 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project platform_packages_apps_Settings by BlissRoms.

the class ApplicationSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.application_settings);
    mToggleAdvancedSettings = (CheckBoxPreference) findPreference(KEY_TOGGLE_ADVANCED_SETTINGS);
    mToggleAdvancedSettings.setChecked(isAdvancedSettingsEnabled());
    getPreferenceScreen().removePreference(mToggleAdvancedSettings);
    // not ready for prime time yet
    if (false) {
        getPreferenceScreen().removePreference(mInstallLocation);
    }
    mInstallLocation = (ListPreference) findPreference(KEY_APP_INSTALL_LOCATION);
    // Is app default install location set?
    boolean userSetInstLocation = (Settings.Global.getInt(getContentResolver(), Settings.Global.SET_INSTALL_LOCATION, 0) != 0);
    if (!userSetInstLocation) {
        getPreferenceScreen().removePreference(mInstallLocation);
    } else {
        mInstallLocation.setValue(getAppInstallLocation());
        mInstallLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String value = (String) newValue;
                handleUpdateAppInstallLocation(value);
                return false;
            }
        });
    }
}
Also used : Preference(android.support.v7.preference.Preference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 37 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project TumCampusApp by TCA-Team.

the class SettingsFragment method populateNewsSources.

private void populateNewsSources() {
    PreferenceCategory newsSourcesPreference = (PreferenceCategory) findPreference("card_news_sources");
    NewsController newsController = new NewsController(mContext);
    List<NewsSources> newsSources = newsController.getNewsSources();
    final NetUtils net = new NetUtils(mContext);
    for (NewsSources newsSource : newsSources) {
        final CheckBoxPreference pref = new CheckBoxPreference(mContext);
        pref.setKey("card_news_source_" + newsSource.getId());
        pref.setDefaultValue(true);
        // Load news source icon in background and set it
        final String url = newsSource.getIcon();
        if (url != null) {
            // Skip News that do not have a image
            new Thread(() -> {
                final Optional<Bitmap> bmp = net.downloadImageToBitmap(url);
                mContext.runOnUiThread(() -> {
                    if (bmp.isPresent()) {
                        pref.setIcon(new BitmapDrawable(getResources(), bmp.get()));
                    }
                });
            }).start();
        }
        pref.setTitle(newsSource.getTitle());
        if (newsSourcesPreference != null) {
            newsSourcesPreference.addPreference(pref);
        }
    }
}
Also used : NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) NetUtils(de.tum.in.tumcampusapp.utils.NetUtils) Optional(com.google.common.base.Optional) PreferenceCategory(android.support.v7.preference.PreferenceCategory) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 38 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project TumCampusApp by TCA-Team.

the class SettingsFragment method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference pref = findPreference(key);
    if (pref instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) pref;
        listPreference.setSummary(listPreference.getEntry());
    }
    // Refresh the cards after a change has been made to them
    if (key.startsWith("card_")) {
        CardManager.setShouldRefresh();
    }
    // selected source if one of all was selected before
    if ("news_newspread".equals(key)) {
        SharedPreferences.Editor e = sharedPreferences.edit();
        boolean value = false;
        for (int i = 7; i < 14; i++) {
            if (sharedPreferences.getBoolean("card_news_source_" + i, false)) {
                value = true;
            }
            e.putBoolean("card_news_source_" + i, false);
        }
        String newSource = sharedPreferences.getString(key, "7");
        e.putBoolean("card_news_source_" + newSource, value);
        e.apply();
        CardManager.setShouldRefresh();
    }
    // the service to call onHandleIntent which checks available lectures
    if (key.equals(Const.SILENCE_SERVICE)) {
        Intent service = new Intent(mContext, SilenceService.class);
        if (sharedPreferences.getBoolean(key, false)) {
            if (!SilenceService.hasPermissions(mContext)) {
                // disable until silence service permission is resolved
                CheckBoxPreference silenceCheckbox = (CheckBoxPreference) findPreference(Const.SILENCE_SERVICE);
                if (silenceCheckbox != null) {
                    silenceCheckbox.setChecked(false);
                }
                Utils.setSetting(mContext, Const.SILENCE_SERVICE, false);
                SilenceService.requestPermissions(mContext);
            } else {
                mContext.startService(service);
            }
        } else {
            mContext.stopService(service);
        }
    }
    // the service to call onHandleIntent which updates all background data
    if (key.equals(Const.BACKGROUND_MODE)) {
        Intent service = new Intent(mContext, BackgroundService.class);
        if (sharedPreferences.getBoolean(key, false)) {
            mContext.startService(service);
        } else {
            mContext.stopService(service);
        }
    }
}
Also used : CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SharedPreferences(android.content.SharedPreferences) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference)

Example 39 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project TumCampusApp by TCA-Team.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    // Load the correct preference category
    setPreferencesFromResource(R.xml.settings, rootKey);
    mContext = getActivity();
    // Disables silence service if the app is used without TUMOnline access
    CheckBoxPreference silent = (CheckBoxPreference) findPreference("silent_mode");
    if (silent != null && !new AccessTokenManager(mContext).hasValidAccessToken()) {
        silent.setEnabled(false);
    }
    // Only do these things if we are in the root of the preferences
    if (rootKey == null) {
        // Click listener for preference list entries. Used to simulate a button
        // (since it is not possible to add a button to the preferences screen)
        findPreference(BUTTON_CLEAR_CACHE).setOnPreferenceClickListener(this);
        // Set summary for these preferences
        setSummary("card_cafeteria_default_G");
        setSummary("card_cafeteria_default_K");
        setSummary("card_cafeteria_default_W");
        setSummary("card_role");
        setSummary("card_stations_default_G");
        setSummary("card_stations_default_C");
        setSummary("card_stations_default_K");
        setSummary("card_default_campus");
        setSummary("silent_mode_set_to");
        setSummary("background_mode_set_to");
    } else if (rootKey.equals("card_eduroam")) {
        findPreference(SETUP_EDUROAM).setOnPreferenceClickListener(this);
    }
    // Register the change listener to react immediately on changes
    PreferenceManager.getDefaultSharedPreferences(mContext).registerOnSharedPreferenceChangeListener(this);
}
Also used : AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference)

Example 40 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project i2p.i2p-bote by i2p.

the class AdvancedPreferenceFragment method setupAdvancedSettings.

private void setupAdvancedSettings() {
    final Context ctx = getPreferenceManager().getContext();
    final PreferenceCategory i2pCat = (PreferenceCategory) findPreference("i2pCategory");
    CheckBoxPreference routerAuto = (CheckBoxPreference) findPreference("i2pbote.router.auto");
    if (!routerAuto.isChecked()) {
        setupI2PCategory(ctx, i2pCat);
    }
    routerAuto.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final Boolean checked = (Boolean) newValue;
            if (!checked) {
                setupI2PCategory(ctx, i2pCat);
            } else {
                Preference p1 = i2pCat.findPreference("i2pbote.router.use");
                Preference p2 = i2pCat.findPreference("i2pbote.i2cp.tcp.host");
                Preference p3 = i2pCat.findPreference("i2pbote.i2cp.tcp.port");
                if (p1 != null)
                    i2pCat.removePreference(p1);
                if (p2 != null)
                    i2pCat.removePreference(p2);
                if (p3 != null)
                    i2pCat.removePreference(p3);
            }
            return true;
        }
    });
}
Also used : Context(android.content.Context) PreferenceCategory(android.support.v7.preference.PreferenceCategory) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) Preference(android.support.v7.preference.Preference) SummaryEditTextPreference(i2p.bote.android.config.util.SummaryEditTextPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference)

Aggregations

CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)31 Preference (android.support.v7.preference.Preference)17 ListPreference (android.support.v7.preference.ListPreference)13 Intent (android.content.Intent)10 CheckBoxPreference (android.preference.CheckBoxPreference)8 Context (android.content.Context)7 SharedPreferences (android.content.SharedPreferences)7 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)7 Preference (android.preference.Preference)6 AlertDialog (android.support.v7.app.AlertDialog)6 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)5 Uri (android.net.Uri)4 Build (android.os.Build)4 PreferenceScreen (android.preference.PreferenceScreen)4 View (android.view.View)4 ArrayList (java.util.ArrayList)4 PackageManager (android.content.pm.PackageManager)3 Bundle (android.os.Bundle)3 ListPreference (android.preference.ListPreference)3