本文整理汇总了Java中android.preference.SwitchPreference.setSummary方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreference.setSummary方法的具体用法?Java SwitchPreference.setSummary怎么用?Java SwitchPreference.setSummary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.SwitchPreference
的用法示例。
在下文中一共展示了SwitchPreference.setSummary方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSwitchPreferenceBasedOnCheckBoxPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox,
final PreferenceGroup group) {
final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext());
switchPref.setTitle(checkBox.getTitle());
switchPref.setKey(checkBox.getKey());
switchPref.setOrder(checkBox.getOrder());
switchPref.setPersistent(checkBox.isPersistent());
switchPref.setEnabled(checkBox.isEnabled());
switchPref.setChecked(checkBox.isChecked());
switchPref.setSummary(checkBox.getSummary());
switchPref.setSummaryOn(checkBox.getSummaryOn());
switchPref.setSummaryOff(checkBox.getSummaryOff());
switchPref.setSwitchTextOn(EMPTY_TEXT);
switchPref.setSwitchTextOff(EMPTY_TEXT);
group.addPreference(switchPref);
switchPref.setDependency(checkBox.getDependency());
}
示例2: setupDaydreamPreferences
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setupDaydreamPreferences() {
if (!isAdded() ) return;
enablePreference("autostart", !Utility.isConfiguredAsDaydream(mContext) );
Preference pref = findPreference("autostart");
boolean on = pref.isEnabled();
String summary = on ? "" : getString(R.string.autostart_message_disabled);
pref.setSummary(summary);
PreferenceCategory category = (PreferenceCategory) findPreference("category_behaviour");
removePreference("force_auto_rotation");
if (!on) {
SwitchPreference forceAutoRotation = new SwitchPreference(mContext);
forceAutoRotation.setKey("force_auto_rotation");
forceAutoRotation.setTitle(getString(R.string.force_auto_rotation));
forceAutoRotation.setSummary(getString(R.string.force_auto_rotation_summary));
forceAutoRotation.setDefaultValue(false);
category.addPreference(forceAutoRotation);
}
}
示例3: updatePreferenceScreen
import android.preference.SwitchPreference; //导入方法依赖的package包/类
void updatePreferenceScreen() {
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("dataSourceType");
PhoneSensorDataSource phoneSensorDataSource;
for (int i = 0; i < phoneSensorDataSources.getPhoneSensorDataSources().size(); i++) {
phoneSensorDataSource = phoneSensorDataSources.getPhoneSensorDataSources().get(i);
SwitchPreference switchPreference = (SwitchPreference) preferenceCategory.findPreference(phoneSensorDataSource.getDataSourceType());
switchPreference.setChecked(phoneSensorDataSource.isEnabled());
if (!isSensorSupported(phoneSensorDataSource.getDataSourceType()))
switchPreference.setSummary("Not Supported");
else {
try {
switchPreference.setSummary(phoneSensorDataSource.getFrequency() + " Hz");
} catch (NumberFormatException nfe) {
switchPreference.setSummary(phoneSensorDataSource.getFrequency());
}
}
}
}
示例4: updatePreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void updatePreference(int i) {
AppServiceManager appServiceManager= (AppServiceManager) ModelManager.getInstance(getActivity()).getModel(ModelFactory.MODEL_APP_SERVICE);
SwitchPreference switchPreference = (SwitchPreference) findPreference(String.valueOf(i));
Status status = appServiceManager.appServiceList.get(i).getStatus();
if(status.getStatus()== Status.APP_NOT_INSTALLED) {
switchPreference.setEnabled(false);
switchPreference.setChecked(false);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_error_red_50dp));
switchPreference.setSummary(status.getMessage());
}else if(status.getStatus()== Status.APP_NOT_RUNNING) {
switchPreference.setEnabled(true);
switchPreference.setChecked(false);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_error_red_50dp));
switchPreference.setSummary(status.getMessage());
}else{
switchPreference.setEnabled(true);
switchPreference.setChecked(true);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_ok_teal_50dp));
switchPreference.setSummary(status.getMessage());
}
}
示例5: setLastBackupTime
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setLastBackupTime()
{
SwitchPreference dailyBackupPref = getDailyBackupPref();
if( dailyBackupPref != null ) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Long lastBackupTime = sharedPreferences.getLong("last_backup_time", 0);
String lastBackupString = getResources().getString(R.string.last_run)+": ";
if (lastBackupTime > 0) {
lastBackupString += DateFormat.getDateTimeInstance().format(lastBackupTime);
} else {
lastBackupString += getResources().getString(R.string.never);
}
dailyBackupPref.setSummary(lastBackupString);
}
}
示例6: getVibrateDuringDndPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private SwitchPreference getVibrateDuringDndPreference() {
SwitchPreference vibrateDuringDnd = new SwitchPreference(getActivity());
vibrateDuringDnd.setKey("pref_key_vibrate_during_dnd");
vibrateDuringDnd
.setTitle(getActivity().getString
(R.string.vibrate_during_dnd_preference_title));
vibrateDuringDnd
.setSummary(getActivity().getString
(R.string.vibrate_during_dnd_preference_summary));
vibrateDuringDnd.setDefaultValue(true);
return vibrateDuringDnd;
}
示例7: createPreferences
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@SuppressLint("SdCardPath")
/* We hardcode /sdcard/ because we want the user to use /sdcard/ instead of emulated
* sdcard file paths such as /storage/emulated/0/ that was introduced in Android 4.2
* due to the multi-user account feature. */
private PreferenceScreen createPreferences(final Context ctx) {
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
prefFontFolder = new Preference(this);
prefFontFolder.setTitle(getResources().getString(R.string.font_folder_title));
prefFontFolder.setKey(Common.KEY_FOLDER_FONT);
prefFontFolder.setOnPreferenceClickListener(new OnPreferenceClickListener(){
@Override
public boolean onPreferenceClick(Preference arg0) {
Intent i = new Intent(ctx, DirectoryChooserActivity.class);
i.putExtra(DirectoryChooserActivity.EXTRA_INITIAL_DIRECTORY, "/sdcard/");
startActivityForResult(i, REQUEST_DIRECTORY);
return true;
}
});
root.addPreference(prefFontFolder);
prefFontEverythingEnable = new SwitchPreference(this);
prefFontEverythingEnable.setTitle(getResources().getString(R.string.font_everything_enable_title));
prefFontEverythingEnable.setSummary(getResources().getString(R.string.font_everything_enable_summary));
prefFontEverythingEnable.setKey(Common.KEY_ENABLE_EVERY_APP);
root.addPreference(prefFontEverythingEnable);
updateSummary();
return root;
}
示例8: initBluetoothPrefs
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void initBluetoothPrefs() {
SwitchPreference useBluetoothSwitch = (SwitchPreference) this
.findPreference(SettingKeys.USE_BLUETOOTH);
if (bluetoothIsSupported()) {
useBluetoothSwitch.setEnabled(true);
initBluetoothDeviceList();
} else {
useBluetoothSwitch.setEnabled(false);
useBluetoothSwitch.setChecked(false);
String msg = getString(R.string.summary_bluetooth_not_supported);
useBluetoothSwitch.setSummary(msg);
}
}
示例9: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
notificationSwitch =
(SwitchPreference)findPreference(
getString(R.string.notifications_switch_key) );
notificationSwitch.setTitle(R.string.notifications_switch_title);
if ( notificationSwitch.isChecked() ) {
notificationSwitch.setSummary( alarmNextDueString() );
} else {
notificationSwitch.setSummary(
R.string.notifications_switched_off_confirmation);
}
notificationSwitch.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
boolean switchValue = (Boolean)newValue;
Log.d(LOG_TAG, "New value for notification switch will be "
+ switchValue);
if (switchValue == false) {
Log.d(LOG_TAG, "Disabling notifications... ");
Alarms.getInstance().cancel();
SettingsFragment.this.notificationSwitch.setSummary(
R.string.notifications_switched_off_confirmation);
showToast(R.string.notifications_switched_off_confirmation);
} else {
Log.d(LOG_TAG, "Enabling notifications... ");
AlarmTimeInterval interval = getAlarmInterval();
Alarms.getInstance().set(interval);
SettingsFragment.this.notificationSwitch.setSummary(
alarmNextDueString() );
showToast(R.string.notifications_switched_on_confirmation,
interval.getDays(),
interval.getHours(),
interval.getMinutes() );
}
return true;
}
}
);
preferenceListener = new NextAlarmPreferenceListener();
getActivity().getSharedPreferences(LOG_TAG, Context.MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(preferenceListener);
}
示例10: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.internal_sensor__confix);
enabledSensorNr = 0;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
String[] internalSensorArrayList = getResources().getStringArray(
R.array.internal_sensor_config);
for (String s : internalSensorArrayList) {
final SwitchPreference swp = (SwitchPreference) getPreferenceManager()
.findPreference(s);
if (swp.isChecked())
enabledSensorNr++;
if (!availableSensor(swp.getKey())) {
swp.setSummary("not available");
swp.setEnabled(false);
} else {
swp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(
Preference preference, Object newValue) {
if ((Boolean) newValue) {
if (enabledSensorNr >= 2) {
openPopupDialog("Warning",
"More than 2 sensors can't be enabled at once!");
return false;
} else {
enabledSensorNr++;
return true;
}
} else {
enabledSensorNr--;
return true;
}
}
});
}
}
}