当前位置: 首页>>代码示例>>Java>>正文


Java SwitchPreference.setEnabled方法代码示例

本文整理汇总了Java中android.preference.SwitchPreference.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreference.setEnabled方法的具体用法?Java SwitchPreference.setEnabled怎么用?Java SwitchPreference.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.preference.SwitchPreference的用法示例。


在下文中一共展示了SwitchPreference.setEnabled方法的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());
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:18,代码来源:TwoStatePreferenceHelper.java

示例2: 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());
    }
}
 
开发者ID:MD2Korg,项目名称:mCerebrum-Study,代码行数:22,代码来源:PrefsFragmentServiceApp.java

示例3: createSwitchPreference

import android.preference.SwitchPreference; //导入方法依赖的package包/类
private SwitchPreference createSwitchPreference(String dataSourceType) {
        SwitchPreference switchPreference = new SwitchPreference(getActivity());
        switchPreference.setKey(dataSourceType);
        String title = dataSourceType;
        title = title.replace("_", " ");
        title = title.substring(0, 1).toUpperCase() + title.substring(1).toLowerCase();
        switchPreference.setTitle(title);
        switchPreference.setOnPreferenceChangeListener(onPreferenceChangeListener);
        switchPreference.setEnabled(isSensorSupported(dataSourceType));
        switch (dataSourceType) {
            case (DataSourceType.ACCELEROMETER):
                switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Accelerometer.frequencyOptions));
                break;
            case (DataSourceType.GYROSCOPE):
                switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Gyroscope.frequencyOptions));
                break;
            case (DataSourceType.AMBIENT_TEMPERATURE):
//                switchPreference.setOnPreferenceClickListener(alertDialogFrequency(AmbientTemperature.frequencyOptions));
                break;
            case (DataSourceType.COMPASS):
                switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Compass.frequencyOptions));
                break;
            case (DataSourceType.AMBIENT_LIGHT):
                switchPreference.setOnPreferenceClickListener(alertDialogFrequency(AmbientLight.frequencyOptions));
                break;
            case (DataSourceType.PRESSURE):
//                switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Pressure.frequencyOptions));
                break;
            case (DataSourceType.PROXIMITY):
//                switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Proximity.frequencyOptions));
                break;
        }
        return switchPreference;
    }
 
开发者ID:MD2Korg,项目名称:mCerebrum-PhoneSensor,代码行数:35,代码来源:PrefsFragmentSettings.java

示例4: setupPreference

import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setupPreference() {
    SwitchPreference calendarSyncState = (SwitchPreference) findPreference("calendar_sync_state");
    PreferenceCategory calendarCategory = (PreferenceCategory) findPreference("calendar_category");
    if (!SupporterHelper.isSupporter()) {
        calendarSyncState.setChecked(false);
        calendarSyncState.setEnabled(false);
        calendarCategory.setTitle(calendarCategory.getTitle() + " (Supporter Feature)");
    } else {
        if (calendarSyncState.isChecked() && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
            setCalendarPreference();
        } else if (calendarSyncState.isChecked() && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(context, "Calendar permission denied, try re-selecting or go to Android Settings -> Apps to enable.", Toast.LENGTH_LONG).show();
        }
    }
}
 
开发者ID:ItsCalebJones,项目名称:SpaceLaunchNow-Android,代码行数:16,代码来源:GeneralFragment.java

示例5: refreshFingerprintPreference

import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void refreshFingerprintPreference() {
    final SwitchPreference fingerprintPreference = (SwitchPreference) findPreference(PreferenceKeys.FINGERPRINT_ENABLED.key());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && new FingerprintHelper(this).canUseFingerPrint()) {
        fingerprintPreference.setChecked(PreferenceUtils.getBoolean(PreferenceKeys.FINGERPRINT_ENABLED, false));
        if (PINManager.isPINSet()) {
            fingerprintPreference.setEnabled(true);
        } else {
            fingerprintPreference.setEnabled(false);
        }
    } else {
        final PreferenceCategory privacy = (PreferenceCategory) findPreference(PreferenceKeys.PRIVACY.key());
        privacy.removePreference(fingerprintPreference);
    }
}
 
开发者ID:citiususc,项目名称:calendula,代码行数:15,代码来源:SettingsActivity.java

示例6: 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);
    }
}
 
开发者ID:jthurne,项目名称:kanban-salad,代码行数:16,代码来源:SettingsActivity.java

示例7: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        getPreferenceManager().setStorageDeviceProtected();
    }

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.settings);

    PreferenceScreen preferenceScreen = getPreferenceScreen();

    preferenceDonation = (SwitchPreference) preferenceScreen.findPreference(SHOW_DONATION);

    preferenceStandbyTimeout = preferenceScreen
            .findPreference(BreventConfiguration.BREVENT_STANDBY_TIMEOUT);

    preferenceScreen.findPreference("brevent_language")
            .setOnPreferenceChangeListener(this);

    BreventApplication application = (BreventApplication) getActivity().getApplication();
    if (!application.supportStandby()) {
        ((PreferenceCategory) preferenceScreen.findPreference("brevent_list"))
                .removePreference(preferenceStandbyTimeout);
    }
    if (!application.supportUpgrade()) {
        SwitchPreference preferenceAutoUpdate = (SwitchPreference) preferenceScreen
                .findPreference(BreventConfiguration.BREVENT_AUTO_UPDATE);
        preferenceAutoUpdate.setEnabled(false);
    }

    if (!BuildConfig.RELEASE) {
        preferenceScreen.removePreference(preferenceScreen.findPreference("brevent"));
    }
    if (!application.supportAppops()) {
        ((PreferenceCategory) preferenceScreen.findPreference("brevent"))
                .removePreference(preferenceScreen.findPreference(BREVENT_APPOPS));
    }
    if (BuildConfig.RELEASE) {
        preferenceScreen.findPreference("brevent_about_version")
                .setOnPreferenceClickListener(this);
        updateDonation();
    }
    onUpdateBreventMethod();
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:46,代码来源:SettingsFragment.java

示例8: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstance) {
	super.onCreate(savedInstance);
	addPreferencesFromResource(R.xml.pref_main);

	mSets = Settings.getInstance(getActivity().getApplicationContext());

	getActivity().setTitle(R.string.title_settings);

	pref_version = findPreference("application_version");
	pref_weibo = findPreference("sina_weibo");
	pref_os_license = findPreference("open_source_license");
	pref_api_provider = findPreference("api_provider");
	pref_github = findPreference("github_repo");
	pref_token_choose = (MaterialListPreference) findPreference("api_token_choose");
	pref_token_custom = findPreference("api_token_custom");
	pref_swipe_back = (SwitchPreference) findPreference("swipe_back");
	pref_notification_interval = (MaterialListPreference) findPreference("notification_interval");
	pref_do_not_disturb = (SwitchPreference) findPreference("do_not_disturb");
	pref_disable_animation = (SwitchPreference) findPreference("disable_animation");
	pref_navigation_tint = (SwitchPreference) findPreference("navigation_tint");

	String version = "Unknown";
	try {
		version = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName;
		version += " (" + getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionCode + ")";
	} catch (Exception e) {
		// Keep the default value
	}
	pref_version.setSummary(version);
	pref_swipe_back.setChecked(mSets.getBoolean(Settings.KEY_SWIPE_BACK, true));
	pref_token_custom.setDefaultValue(mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0));
	pref_token_custom.setEnabled(mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0) == 2);
	pref_do_not_disturb.setChecked(mSets.getBoolean(Settings.KEY_NOTIFICATION_DO_NOT_DISTURB, true));
	pref_disable_animation.setChecked(mSets.getBoolean(Settings.KEY_DISABLE_ANIMATION, false));
	if (Build.VERSION.SDK_INT < 21) {
		pref_navigation_tint.setEnabled(false);
		pref_navigation_tint.setChecked(false);
	} else {
		pref_navigation_tint.setChecked(mSets.getBoolean(Settings.KEY_NAVIGATION_TINT, true));
	}

	String[] values = getResources().getStringArray(R.array.item_token_list_values);
	int index, target = mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0);
	for (index = 0; index < values.length; index++) {
		if (values[index].equals(String.valueOf(target))) break;
	}
	pref_token_choose.setSummary(
			getResources().getStringArray(R.array.item_token_list)
			[index]
	);
	String[] values1 = getResources().getStringArray(R.array.notification_interval_item);
	int index1, target1 = mSets.getInt(Settings.KEY_NOTIFICATION_INTERVAL, 0);
	for (index1 = 0; index1 < values.length; index1++) {
		if (values1[index1].equals(String.valueOf(target1))) break;
	}
	pref_notification_interval.setSummary(
			getResources().getStringArray(R.array.notification_interval)
					[index1]
	);

	pref_weibo.setOnPreferenceClickListener(this);
	pref_os_license.setOnPreferenceClickListener(this);
	pref_api_provider.setOnPreferenceClickListener(this);
	pref_github.setOnPreferenceClickListener(this);
	pref_token_custom.setOnPreferenceClickListener(this);
	pref_token_choose.setOnPreferenceChangeListener(this);
	pref_swipe_back.setOnPreferenceChangeListener(this);
	pref_notification_interval.setOnPreferenceChangeListener(this);
	pref_do_not_disturb.setOnPreferenceChangeListener(this);
	pref_disable_animation.setOnPreferenceChangeListener(this);
	pref_navigation_tint.setOnPreferenceChangeListener(this);
}
 
开发者ID:fython,项目名称:ExpressHelper,代码行数:74,代码来源:SettingsMain.java

示例9: setupPreferences

import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setupPreferences() {
    widgetPresets = findPreference("widget_presets");
    widgetBackgroundColor = (ColorPreference) findPreference("widget_background_color");
    widgetTextColor = (ColorPreference) findPreference("widget_text_color");
    widgetSecondaryTextColor = (ColorPreference) findPreference("widget_secondary_text_color");
    widgetIconColor = (ColorPreference) findPreference("widget_icon_color");
    widgetRoundCorners = (SwitchPreference) findPreference("widget_theme_round_corner");
    widgetAccentColor = (ColorPreference) findPreference("widget_list_accent_color");
    widgetTitleColor = (ColorPreference) findPreference("widget_title_text_color");
    widgetHideSettings = (SwitchPreference) findPreference("widget_refresh_enabled");
    if (!SupporterHelper.isSupporter()) {
        Preference weather = findPreference("weather");
        weather.setEnabled(false);
        weather.setSelectable(false);

        PreferenceCategory prefCatWeather = (PreferenceCategory) findPreference("weather_category");
        prefCatWeather.setTitle(prefCatWeather.getTitle() + " (Supporter Feature)");
        Preference measurement = findPreference("weather_US_SI");
        measurement.setEnabled(false);
        measurement.setSelectable(false);

        PreferenceCategory prefCatWidget = (PreferenceCategory) findPreference("widget_category");
        prefCatWidget.setTitle(prefCatWidget.getTitle() + " (Supporter Feature)");


        widgetPresets.setEnabled(false);
        widgetPresets.setSelectable(false);

        widgetBackgroundColor.setEnabled(false);
        widgetBackgroundColor.setSelectable(false);

        widgetTextColor.setEnabled(false);
        widgetTextColor.setSelectable(false);

        widgetSecondaryTextColor.setEnabled(false);
        widgetSecondaryTextColor.setSelectable(false);

        widgetIconColor.setEnabled(false);
        widgetIconColor.setSelectable(false);

        widgetRoundCorners.setEnabled(false);
        widgetRoundCorners.setSelectable(false);

        widgetAccentColor.setEnabled(false);
        widgetAccentColor.setSelectable(false);

        widgetTitleColor.setEnabled(false);
        widgetTitleColor.setSelectable(false);

        widgetHideSettings.setEnabled(false);
        widgetHideSettings.setSelectable(false);
    }
    Preference localTime = findPreference("local_time");
    localTime.setOnPreferenceChangeListener(createLocalTimeListener());
}
 
开发者ID:ItsCalebJones,项目名称:SpaceLaunchNow-Android,代码行数:56,代码来源:AppearanceFragment.java

示例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;
					}
				}
			});
		}
	}
}
 
开发者ID:myHealthAssistant-tudarmstadt,项目名称:myHealthHub,代码行数:44,代码来源:InternalSensorPreference.java


注:本文中的android.preference.SwitchPreference.setEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。