本文整理汇总了Java中android.preference.Preference.getContext方法的典型用法代码示例。如果您正苦于以下问题:Java Preference.getContext方法的具体用法?Java Preference.getContext怎么用?Java Preference.getContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.Preference
的用法示例。
在下文中一共展示了Preference.getContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateKeyboardThemeSummary
import android.preference.Preference; //导入方法依赖的package包/类
static void updateKeyboardThemeSummary(final Preference pref) {
final Context context = pref.getContext();
final Resources res = context.getResources();
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
for (int index = 0; index < keyboardThemeNames.length; index++) {
if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
pref.setSummary(keyboardThemeNames[index]);
return;
}
}
}
示例2: onPreferenceChange
import android.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final Context context = preference.getContext();
if (Boolean.parseBoolean(newValue.toString())) {
if (!isValidServerSetup(context)) {
Toast.makeText(context, R.string.provide_user_pass_url, Toast.LENGTH_LONG).show();
return false;
}
}
return true;
}
示例3: onPreferenceClick
import android.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceClick(Preference preference) {
final Context context = preference.getContext();
DbAccess db = DbAccess.getInstance();
db.open(context);
if (db.getTrackId() > 0) {
// track saved on server
Alert.showInfo(context,
context.getString(R.string.warning),
context.getString(R.string.track_server_setup_warning)
);
}
return true;
}
示例4: updateSubtypeEnabler
import android.preference.Preference; //导入方法依赖的package包/类
public void updateSubtypeEnabler() {
final Preference pref = mSubtypeEnablerPreference;
if (pref == null) {
return;
}
final Context context = pref.getContext();
final CharSequence title;
if (mSubtypeEnablerTitleRes != 0) {
title = context.getString(mSubtypeEnablerTitleRes);
} else {
title = mSubtypeEnablerTitle;
}
pref.setTitle(title);
final Intent intent = pref.getIntent();
if (intent != null) {
intent.putExtra(Intent.EXTRA_TITLE, title);
}
final String summary = getEnabledSubtypesLabel(context, mImm, mImi);
if (!TextUtils.isEmpty(summary)) {
pref.setSummary(summary);
}
if (mSubtypeEnablerIconRes != 0) {
pref.setIcon(mSubtypeEnablerIconRes);
} else {
pref.setIcon(mSubtypeEnablerIcon);
}
}
示例5: onPreferenceChange
import android.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
String title = index >= 0 ? String.valueOf(listPreference.getEntries()[index]) : "";
//Exibir o tempo total de funcionamento do registrador depois do ultimo reset.
if (OhaEnergyUseSyncHelper.ENERGY_USE_SYNC_OFTEN_LOGGER_RESET.equals(preference.getKey())){
Context context = preference.getContext();
long durationLoggerRunning = preference.getSharedPreferences().getLong(OhaEnergyUseSyncHelper.ENERGY_USE_SYNC_DURATION_LOGGER_RUNNING,0);
preference.setTitle(String.format(context.getString(R.string.pref_title_energy_use_sync_often_logger_reset), title));
preference.setSummary(String.format(context.getString(R.string.pref_summary_energy_use_sync_often_logger_reset), OhaHelper.convertMillisToHours(durationLoggerRunning)));
} else {
// Set the summary to reflect the new value.
preference.setSummary(title);
}
} else if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value
// using RingtoneManager.
if (!TextUtils.isEmpty(stringValue)) {
Ringtone ringtone = RingtoneManager.getRingtone(
preference.getContext(), Uri.parse(stringValue));
if (ringtone == null) {
// Clear the summary if there was a lookup error.
preference.setSummary(null);
} else {
// Set the summary to reflect the new ringtone display
// name.
String name = ringtone.getTitle(preference.getContext());
preference.setSummary(name);
}
}
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}