use of android.preference.Preference in project NimbusBase_Android_Tutorial by NimbusBase.
the class IndexFragment method initiatePreferenceScreen.
protected PreferenceScreen initiatePreferenceScreen(Base base, int preferencesResID) {
addPreferencesFromResource(preferencesResID);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
final PreferenceCategory serverCate = getServerCategory(preferenceScreen);
serverCate.setOrderingAsAdded(true);
final Server[] servers = base.getServers();
for (int index = 0; index < servers.length; index++) {
final Server server = servers[index];
final ListItemServer item = new ListItemServer(getActivity(), server);
item.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
onServerItemStateChange((ListItemServer) preference, (Boolean) newValue);
return false;
}
});
item.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
onServerItemClick((ListItemServer) preference);
return true;
}
});
serverCate.addPreference(item);
onServerStateChange(server, index);
}
final PreferenceCategory databaseCate = getDatabaseCategory(preferenceScreen);
final PreferenceScreen playgroundItem = (PreferenceScreen) databaseCate.findPreference(getString(R.string.item_playground));
playgroundItem.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
return onPlaygroundItemClick(preference);
}
});
return preferenceScreen;
}
use of android.preference.Preference in project NimbusBase_Android_Tutorial by NimbusBase.
the class PGFragmentTable method reload.
protected void reload(List<? extends PGRecord> records) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
for (final PGRecord user : records) {
final PGListItemRecord item = new PGListItemRecord(getActivity(), user);
item.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
return onRecordPressed((PGListItemRecord) preference);
}
});
preferenceScreen.addPreference(item);
}
}
use of android.preference.Preference in project NimbusBase_Android_Tutorial by NimbusBase.
the class PGFragmentTable method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final ActionBar actionBar = getActivity().getActionBar();
if (actionBar != null)
actionBar.setTitle("Table " + mTableName);
final SQLiteDatabase database = mSQLiteOpenHelper.getReadableDatabase();
final List<MDLUser> records = MDLUser.fetchAll(database);
database.close();
if (!records.equals(mRecords)) {
this.mRecords = records;
reload(records);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
for (final MDLUser user : records) {
final PGListItemRecord item = new PGListItemRecord(getActivity(), user);
item.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
return onRecordPressed((PGListItemRecord) preference);
}
});
preferenceScreen.addPreference(item);
}
}
}
use of android.preference.Preference in project Anki-Android by Ramblurr.
the class CramDeckOptions method updateSummaries.
protected void updateSummaries() {
mAllowCommit = false;
// for all text preferences, set summary as current database value
for (String key : mPref.mValues.keySet()) {
Preference pref = this.findPreference(key);
String value = null;
if (pref == null) {
continue;
} else if (pref instanceof CheckBoxPreference) {
continue;
} else if (pref instanceof ListPreference) {
ListPreference lp = (ListPreference) pref;
value = lp.getEntry().toString();
} else {
value = this.mPref.getString(key, "");
}
// update value for EditTexts
if (pref instanceof EditTextPreference) {
((EditTextPreference) pref).setText(value);
}
// update summary
if (!mPref.mSummaries.containsKey(key)) {
CharSequence s = pref.getSummary();
mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
}
String summ = mPref.mSummaries.get(key);
if (summ != null && summ.contains("XXX")) {
pref.setSummary(summ.replace("XXX", value));
} else {
pref.setSummary(value);
}
}
mAllowCommit = true;
}
use of android.preference.Preference in project Anki-Android by Ramblurr.
the class DeckOptions method updateSummaries.
protected void updateSummaries() {
Resources res = getResources();
// for all text preferences, set summary as current database value
for (String key : mPref.mValues.keySet()) {
Preference pref = this.findPreference(key);
if (key.equals("deckConf")) {
String groupName = getOptionsGroupName();
int count = getOptionsGroupCount();
pref.setSummary(res.getQuantityString(R.plurals.deck_conf_group_summ, count, groupName, count));
continue;
}
String value = null;
if (pref == null) {
continue;
} else if (pref instanceof CheckBoxPreference) {
continue;
} else if (pref instanceof ListPreference) {
ListPreference lp = (ListPreference) pref;
value = lp.getEntry() != null ? lp.getEntry().toString() : "";
} else {
value = this.mPref.getString(key, "");
}
// update summary
if (!mPref.mSummaries.containsKey(key)) {
CharSequence s = pref.getSummary();
mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
}
String summ = mPref.mSummaries.get(key);
if (summ != null && summ.contains("XXX")) {
pref.setSummary(summ.replace("XXX", value));
} else {
pref.setSummary(value);
}
}
// Update summaries of preference items that don't have values (aren't in mValues)
int subDeckCount = getSubdeckCount();
this.findPreference("confSetSubdecks").setSummary(res.getQuantityString(R.plurals.deck_conf_set_subdecks_summ, subDeckCount, subDeckCount));
}
Aggregations