Example usage for android.preference CheckBoxPreference setTitle

List of usage examples for android.preference CheckBoxPreference setTitle

Introduction

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

Prototype

public void setTitle(CharSequence title) 

Source Link

Document

Sets the title for this Preference with a CharSequence.

Usage

From source file:com.guipenedo.pokeradar.activities.settings.PokemonFilterSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();/* w  w  w  .ja v  a  2s  .co  m*/
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this);
    PreferenceCategory category = new PreferenceCategory(this);
    category.setTitle(R.string.filter_pokemons);
    screen.addPreference(category);
    try {
        JSONArray pokemonList = new JSONArray(Utils.loadJSONFromFile(this, "pokemon.json"));
        for (int i = 0; i < pokemonList.length(); i++) {
            JSONObject pokemon = pokemonList.getJSONObject(i);
            CheckBoxPreference checkBox = new CheckBoxPreference(this);
            checkBox.setTitle(pokemon.getString("Name"));
            checkBox.setIcon(new BitmapDrawable(getResources(),
                    Utils.bitmapForPokemon(this, Integer.parseInt(pokemon.getString("Number")))));
            checkBox.setDefaultValue(true);
            checkBox.setSummary(String.format(getString(R.string.setting_filter_pokemon_summary),
                    pokemon.getString("Name")));
            checkBox.setKey("pref_key_show_pokemon_" + Integer.parseInt(pokemon.getString("Number")));
            category.addPreference(checkBox);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    setPreferenceScreen(screen);
}

From source file:com.adam.aslfms.MusicAppsActivity.java

private void update() {
    mSupportedMusicAppsList.removeAll();
    mPrefsToMapisMap.clear();//from   ww  w .j a v a2  s  .c o  m
    mMapisToPrefsMap.clear();

    MusicAPI[] mapis = MusicAPI.all(this);
    for (MusicAPI mapi : mapis) {
        CheckBoxPreference appPref = new CheckBoxPreference(this, null);
        appPref.setTitle(mapi.getName());
        appPref.setPersistent(false);
        appPref.setChecked(mapi.isEnabled());

        mSupportedMusicAppsList.addPreference(appPref);
        mPrefsToMapisMap.put(appPref, mapi);
        mMapisToPrefsMap.put(mapi, appPref);
        setSMASummary(appPref, mapi);
    }

    // explanation text, for what this screen does
    Preference detect = new Preference(this);
    if (mapis.length == 0)
        detect.setTitle(R.string.no_supported_mapis_title);
    else if (mapis.length == 1)
        detect.setTitle(R.string.find_supported_mapis_one_title);
    else
        detect.setTitle(getString(R.string.find_supported_mapis_many_title).replace("%1",
                Integer.toString(mapis.length)));
    detect.setSummary(R.string.find_supported_mapis_summary);
    mSupportedMusicAppsList.addPreference(detect);
}

From source file:com.esminis.server.library.activity.DrawerFragment.java

protected CheckBoxPreference createPreferenceCheckbox(Context context, String key, boolean defaultValue,
        @StringRes int title, @StringRes int summary) {
    final CheckBoxPreference preference = new CheckBoxPreference(context);
    preference.setTitle(title);
    preference.setDefaultValue(defaultValue);
    preference.setSummary(summary);// w w w  . j a va2s  .  c om
    preference.setKey(key);
    return preference;
}

From source file:com.mattprecious.notisync.preferences.DevicePreferenceFragment.java

@Override
public void onResume() {
    super.onResume();

    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter == null) {
        return;//ww w . ja va 2 s .c  o m
    }

    PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();

    Set<String> selectedDevices = Preferences.getDevices(getActivity());

    // Get a set of currently paired devices
    Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
    for (BluetoothDevice device : pairedDevices) {
        CheckBoxPreference preference = new CheckBoxPreference(getActivity());
        preference.setOnPreferenceChangeListener(preferenceListener);
        preference.setTitle(device.getName());
        preference.setSummary(device.getAddress());

        int iconResId = Helpers.getBtClassDrawable(device);
        if (iconResId != 0) {
            preference.setIcon(iconResId);
        }

        if (selectedDevices.contains(device.getAddress())) {
            preference.setDefaultValue(true);
            localDeviceSet.add(device.getAddress());
        }

        getPreferenceScreen().addPreference(preference);
    }
}

From source file:de.badaix.snapcast.GroupSettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.group_preferences);
    PreferenceScreen screen = this.getPreferenceScreen();

    prefStreams = (ListPreference) findPreference("pref_stream");

    Bundle bundle = getArguments();/*from  w  ww.  j av a  2s .  c  o m*/
    try {
        group = new Group(new JSONObject(bundle.getString("group")));
        serverStatus = new ServerStatus(new JSONObject(bundle.getString("serverStatus")));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    final ArrayList<Stream> streams = serverStatus.getStreams();
    final CharSequence[] streamNames = new CharSequence[streams.size()];
    final CharSequence[] streamIds = new CharSequence[streams.size()];
    for (int i = 0; i < streams.size(); ++i) {
        streamNames[i] = streams.get(i).getName();
        streamIds[i] = streams.get(i).getId();
    }

    prefStreams.setEntries(streamNames);
    prefStreams.setEntryValues(streamIds);

    for (int i = 0; i < streams.size(); ++i) {
        if (streamIds[i].equals(group.getStreamId())) {
            prefStreams.setTitle(streamNames[i]);
            prefStreams.setValueIndex(i);
            oldStream = prefStreams.getValue();
            break;
        }
    }

    prefStreams.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            for (int i = 0; i < streams.size(); ++i) {
                if (streamIds[i].equals(newValue)) {
                    prefStreams.setTitle(streamNames[i]);
                    //                        client.getConfig().setStream(streamIds[i].toString());
                    prefStreams.setValueIndex(i);
                    break;
                }
            }

            return false;
        }
    });

    prefCatClients = (PreferenceCategory) findPreference("pref_cat_clients");
    ArrayList<CheckBoxPreference> allClients = new ArrayList<>();
    for (Group g : serverStatus.getGroups()) {
        for (Client client : g.getClients()) {
            CheckBoxPreference checkBoxPref = new CheckBoxPreference(screen.getContext());
            checkBoxPref.setKey(client.getId());
            checkBoxPref.setTitle(client.getVisibleName());
            checkBoxPref.setChecked(g.getId().equals(group.getId()));
            checkBoxPref.setPersistent(false);
            allClients.add(checkBoxPref);
        }
    }
    Collections.sort(allClients, new Comparator<CheckBoxPreference>() {
        @Override
        public int compare(CheckBoxPreference lhs, CheckBoxPreference rhs) {
            return lhs.getTitle().toString().compareToIgnoreCase(rhs.getTitle().toString());
        }
    });
    for (CheckBoxPreference pref : allClients)
        prefCatClients.addPreference(pref);

    oldClients = getClients().toString();
}

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

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addPasswordPreference(preferenceGroup);
    if (canHttps()) {
        CheckBoxPreference httpsPref = new CheckBoxPreference(context);
        httpsPref.setTitle(R.string.pref_use_https);
        httpsPref.setSummary(R.string.pref_use_https_summary);
        httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS));
        httpsPref.setDefaultValue(useHttpsDefaultValue());
        preferenceGroup.addPreference(httpsPref);
        addUnsafeSslPreference(preferenceGroup, getSharedKey(PREF_KEY_USE_HTTPS));
    }/*from w w w.  jav a 2 s . c  o m*/
    addProxyPreferences(preferenceGroup);
}

From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java

private void setupSimplePreferencesScreen() {
    addPreferencesFromResource(R.xml.pref_application);

    applicationCategory = (PreferenceCategory) findPreference("header_application");

    // Listen for check/uncheck all tap
    findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override//from   w  w w  . j  av a  2  s  .c  o  m
        public boolean onPreferenceChange(Preference arg0, Object arg1) {
            for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) {
                // Uncheck or check all items
                ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1);
            }
            return true;
        }
    });

    class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> {
        private PackageManager packageManager;

        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true);
        }

        @Override
        protected List<ApplicationInfo> doInBackground(String... notif) {

            packageManager = getApplicationContext().getPackageManager();

            // Comparator used to sort applications by name
            class CustomComparator implements Comparator<ApplicationInfo> {
                @Override
                public int compare(ApplicationInfo arg0, ApplicationInfo arg1) {
                    return arg0.loadLabel(packageManager).toString()
                            .compareTo(arg1.loadLabel(packageManager).toString());
                }
            }

            // Get installed applications
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            List<ApplicationInfo> appList = getApplicationContext().getPackageManager()
                    .getInstalledApplications(PackageManager.GET_META_DATA);

            // Sort by application name
            Collections.sort(appList, new CustomComparator());

            return appList;
        }

        @Override
        protected void onPostExecute(List<ApplicationInfo> result) {
            // Add each application to screen
            for (ApplicationInfo appInfo : result) {
                CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this);
                c.setTitle(appInfo.loadLabel(packageManager).toString());
                c.setSummary(appInfo.packageName);
                c.setIcon(appInfo.loadIcon(packageManager));
                c.setKey(appInfo.packageName);
                c.setChecked(true);

                c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference arg0, Object arg1) {
                        // On tap, show an enabled/disabled notification on the desktop
                        Object[] notif = new Object[3];

                        if (arg1.toString().equals("true")) {
                            notif[0] = arg0.getTitle().toString() + " notifications enabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        } else {
                            notif[0] = arg0.getTitle().toString() + " notifications disabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        }

                        new TestTask().execute(notif);

                        return true;
                    }

                });

                applicationCategory.addPreference(c);
            }
            progressDialog.dismiss();
        }
    }

    new ApplicationTask().execute();

}

From source file:org.teleportr.activity.Autocompletion.java

/** Called when the activity is first created. */
@Override//from   w w w. j a v  a2  s .  c  o  m
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setTitle(getString(R.string.downloads_activity_titel));
    getPreferenceManager().setSharedPreferencesName("autocompletion");
    setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));

    File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/teleporter");
    if (!dir.exists())
        dir.mkdir();

    final Map<String, ?> vals = getPreferenceManager().getSharedPreferences().getAll();
    if (vals.isEmpty() && dir.list().length > 0)
        Toast.makeText(this, getString(R.string.inform_sdcard), Toast.LENGTH_LONG).show();
    // clean up (autocompletion downloads deleted on sdcard)
    getPreferenceManager().getSharedPreferences().edit().clear().commit();

    for (String file : dir.list()) {
        CheckBoxPreference c = new CheckBoxPreference(this);
        getPreferenceScreen().addItemFromInflater(c);
        c.setKey(file);
        c.setTitle(file.split("_")[0]);
        c.setSummary(file.substring(file.indexOf("_") + 1, file.lastIndexOf(".")));
        if (vals.containsKey(file)) {
            c.setChecked((Boolean) vals.get(file));
        }
    }
    if (getPreferenceScreen().getPreferenceCount() == 0)
        new FetchNearbyDownloads().execute("");

}

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  w w  .ja va2s  . c  o 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;
}