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


Java SwitchPreference.setOnPreferenceChangeListener方法代码示例

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


在下文中一共展示了SwitchPreference.setOnPreferenceChangeListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.document_mode_preferences);
    getActivity().setTitle(R.string.tabs_and_apps_title);

    mDocumentModeManager = DocumentModeManager.getInstance(getActivity());

    mDocumentModeSwitch = (SwitchPreference) findPreference(PREF_DOCUMENT_MODE_SWITCH);

    boolean isdocumentModeEnabled = !mDocumentModeManager.isOptedOutOfDocumentMode();
    mDocumentModeSwitch.setChecked(isdocumentModeEnabled);

    mDocumentModeSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if ((boolean) newValue == !mDocumentModeManager.isOptedOutOfDocumentMode()) {
                return true;
            }
            createOptOutAlertDialog((boolean) newValue).show();
            return true;
        }
    });
}
 
开发者ID:Smalinuxer,项目名称:Vafrinn,代码行数:25,代码来源:DocumentModePreference.java

示例2: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.prefs = getSharedPreferences(Common.PREFS, Context.MODE_WORLD_READABLE);
    addPreferencesFromResource(R.xml.preference);

    mSwith = (SwitchPreference) findPreference("enable_toast");
    mStyle = (ListPreference) findPreference("style_key");
    mAnimation = (ListPreference) findPreference("animation_key");
    mEnable_icon = (CheckBoxPreference) findPreference("enable_icon");
    mGithub = findPreference("viewsource");


    mSwith.setOnPreferenceChangeListener(this);
    mStyle.setOnPreferenceChangeListener(this);
    mAnimation.setOnPreferenceChangeListener(this);
    mEnable_icon.setOnPreferenceChangeListener(this);
    mGithub.setOnPreferenceClickListener(this);
}
 
开发者ID:heshshark,项目名称:ToastUI,代码行数:21,代码来源:SettingActivity.java

示例3: updateShowTouchesOptions

import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void updateShowTouchesOptions() {
    final SwitchPreference showTouchesPref = (SwitchPreference) findPreference("show_touches");
    int enable = 0;
    try {
        enable = Settings.System.getInt(getContentResolver(), Constants.SETTINGS_SYSTEM_SHOW_TOUCHES);
    } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
    }
    showTouchesPref.setChecked(enable == 1);

    showTouchesPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Settings.System.putInt(getContentResolver(),
                    Constants.SETTINGS_SYSTEM_SHOW_TOUCHES,
                    newValue == Boolean.TRUE ? 1 : 0);
            return true;
        }
    });
}
 
开发者ID:XuDaojie,项目名称:DeveloperSettings,代码行数:21,代码来源:DevelopmentSettingsActivity.java

示例4: setupNightModeSwitch

import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setupNightModeSwitch() {
    // 设置夜间模式
    uiManager = (UiModeManager) getActivity().getSystemService(Context.UI_MODE_SERVICE);
    nightModeSwitch = (SwitchPreference) getPreferenceManager().findPreference("night_mode_switch");
    nightModeSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean nextNightMode = !PreferenceHelper.isNightModeEnabled();
            if (nextNightMode) {
                uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
            } else {
                uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
            }
            return true;
        }
    });
}
 
开发者ID:dianlujitao,项目名称:BigNews,代码行数:18,代码来源:SettingsActivity.java

示例5: onCreate

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

    cacheWithWifi = (SwitchPreference) findPreference("cache_with_wifi");
    cacheWithWifi.setOnPreferenceChangeListener(this);
    boolean checked = PreferenceManager.getBooleanValue(context, CACHE_KEY, true);
    cacheWithWifi.setChecked(checked);

    clearVideoCache  = findPreference("clear_video_cache");
    clearVideoCache.setOnPreferenceClickListener(this);

    float videoFileSize = calculateCacheFileSize("video-cache", true);

    clearVideoCache.setSummary(String.format(Locale.CHINESE, "%.2fMb", videoFileSize));

    clearPhotoCache = findPreference("clear_photo_cache");
    clearPhotoCache.setOnPreferenceClickListener(this);

    float photoFileSize = calculateCacheFileSize("image_manager_disk_cache", false);
    photoFileSize += calculateCacheFileSize("picasso-cache", false);

    clearPhotoCache.setSummary(String.format(Locale.CHINESE, "%.2fMb", photoFileSize));

}
 
开发者ID:Assassinss,项目名称:Interessant,代码行数:27,代码来源:SettingsFragment.java

示例6: initView

import android.preference.SwitchPreference; //导入方法依赖的package包/类
protected void initView() {
    final PreferenceScreen screen = getPreferenceScreen();
    final ContentResolver cr = getContentResolver();
    final SwitchPreference pref = (SwitchPreference) screen.findPreference("debug_switch");
    Utils.setValue(cr, ".com.tinker.debugtool.debug", pref.isChecked(), Utils.TYPE_BOOLEAN);

    pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.w(TAG, "set debug newValue:" + newValue);
            Utils.setValue(cr, ".com.tinker.debugtool.debug", newValue, Utils.TYPE_BOOLEAN);
            return true;
        }
    });

}
 
开发者ID:TinkerPatch,项目名称:tinkerpatch-debug-tool,代码行数:18,代码来源:SettingsActivity.java

示例7: onCreate

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

  // Bind the summaries of EditText/WeatherList/Dialog/Ringtone preferences
  // to their values. When their values change, their summaries are
  // updated to reflect the new value, per the Android Design
  // guidelines.
  mUsernameToDisplay = findPreference(USER_NAME_TO_DISPLAY);
  bindPreferenceSummaryToValue(mUsernameToDisplay);

  mTemperatureUnitsPreference = (SwitchPreference) findPreference(PREF_TEMPERATURE_UNITS);
  mTemperatureUnitsPreference.setOnPreferenceChangeListener(this);
  mUsernameToDisplay.setOnPreferenceClickListener(this);
}
 
开发者ID:rcgonzalezf,项目名称:weather-app-demo,代码行数:17,代码来源:SettingsActivity.java

示例8: onCreate

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

    SwitchPreference pref = (SwitchPreference) findPreference(
            Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
    pref.setPersistent(false);

    Bundle extras = new Bundle();
    extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
    Bundle value = getActivity().getContentResolver().call(
            LauncherSettings.Settings.CONTENT_URI,
            LauncherSettings.Settings.METHOD_GET_BOOLEAN,
            Utilities.ALLOW_ROTATION_PREFERENCE_KEY, extras);
    pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE));

    pref.setOnPreferenceChangeListener(this);
}
 
开发者ID:RunasSudo,项目名称:FLauncher,代码行数:20,代码来源:SettingsActivity.java

示例9: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Use Toolbar instead of ActionBar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Prepare ProgressBar
    progressBar = (ProgressBar) findViewById(R.id.progress_spinner);

    // Show app icon in Toolbar
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setLogo(R.mipmap.ic_logo);

    PreferenceFragment preferenceFragment = (PreferenceFragment) getFragmentManager().findFragmentById(R.id.frag_settings);
    switchAdmin = (SwitchPreference) preferenceFragment.findPreference("pref_key_device_admin_enabled");
    switchAdmin.setOnPreferenceChangeListener(switchAdminOnChangeListener);

    // Initialize Device Policy Manager service and our receiver class
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    snooperStopperDeviceAdmin = new ComponentName(this, SnooperStopperDeviceAdminReceiver.class);
}
 
开发者ID:xmikos,项目名称:SnooperStopper,代码行数:27,代码来源:MainActivity.java

示例10: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MainApplication.from(getActivity()).getObjectGraph().inject(this);

    addPreferencesFromResource(R.xml.preferences);
    PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences, true);
    locationPreference = (ListPreference) findPreference(getString(R.string.pref_location));
    locationPreference.setOnPreferenceChangeListener(locationChangeListener);
    statusPreference = (SwitchPreference) findPreference(getString(R.string.pref_service_enabled));
    statusPreference.setOnPreferenceChangeListener(serviceStatusListener);
    colorPreference = (EditTextPreference) findPreference(getString(R.string.pref_color));
    colorPreference.setOnPreferenceChangeListener(colorChangeListener);

    Intent intent = new Intent(getActivity(), OverlayService.class);
    intent.putExtra(KEY_LOCATION, locationPreference.getValue());
    intent.putExtra(KEY_ENABLED, String.valueOf(statusPreference.isChecked()));
    intent.putExtra(KEY_COLOR, colorPreference.getText());
    getActivity().startService(intent);
}
 
开发者ID:trevor-e,项目名称:InfoOverlay,代码行数:21,代码来源:MainActivity.java

示例11: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.prefs);
    indexInfo = new IndexInfo(this);
    SwitchPreference mEnableWifi = (SwitchPreference) findPreference("enabled");
    mEnableWifi.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
                if(!((Boolean) newValue)) {
                    Log.i(TAG, "Stopping indexer...");
                    indexInfo.stopIndexer(getApplicationContext());
                } else {
                    indexInfo.startIndexer(getApplicationContext());
                }
                return true;
        }
    });
}
 
开发者ID:benjaminwinger,项目名称:Android-Indexing-Service,代码行数:20,代码来源:AISPreferences.java

示例12: onCreate

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

    mUsePinForSecurityPreference = (SwitchPreference) findPreference(SecuritySettings.KEY_USE_PIN_FOR_SECURITY);
    mUsePinForSecurityPreference.setOnPreferenceChangeListener(this);

    Preference changePinPreference = findPreference(SecuritySettings.KEY_CHANGE_PIN);
    changePinPreference.setOnPreferenceClickListener(preference -> {
        startActivityForResult(new Intent(getActivity(), CreatePinActivity.class), REQUEST_CHANGE_PIN);
        return true;
    });

    Preference clearKeysPreference = findPreference(SecuritySettings.KEY_DELETE_KEYS);
    AssertUtils.requireNonNull(clearKeysPreference);
    clearKeysPreference.setOnPreferenceClickListener(preference -> {
        onClearKeysClick();
        return true;
    });

    findPreference("encryption_terms_of_use").setOnPreferenceClickListener(preference -> {
        View view = View.inflate(getActivity(), R.layout.content_encryption_terms_of_use, null);
        new AlertDialog.Builder(getActivity())
                .setView(view)
                .setTitle(R.string.phoenix_encryption)
                .setNegativeButton(R.string.button_cancel, null)
                .show();
        return true;
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:32,代码来源:SecurityPreferencesFragment.java

示例13: initInLineAction

import android.preference.SwitchPreference; //导入方法依赖的package包/类
public void initInLineAction(SwitchPreference switchPref) {
    switchPref.setChecked(true);
    mActionOn = switchPref.isChecked();
    switchPref.setOnPreferenceChangeListener(
            new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    mActionOn = (Boolean) newValue;
                    return true;
                }
            });
}
 
开发者ID:googlesamples,项目名称:android-WearAccessibilityApp,代码行数:13,代码来源:NotificationsActivity.java

示例14: initAvatar

import android.preference.SwitchPreference; //导入方法依赖的package包/类
public void initAvatar(SwitchPreference switchPref) {
    switchPref.setChecked(true);
    mAvatarOn = switchPref.isChecked();
    switchPref.setOnPreferenceChangeListener(
            new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    mAvatarOn = (Boolean) newValue;
                    return true;
                }
            });
}
 
开发者ID:googlesamples,项目名称:android-WearAccessibilityApp,代码行数:13,代码来源:NotificationsActivity.java

示例15: onCreate

import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.prefs_in_line_progress);

    mDeterminantSwitchPref =
            (SwitchPreference)
                    findPreference(getString(R.string.key_pref_determinant_switch));
    mDeterminantSwitchPref.setChecked(true);

    mCircledImageViewPref =
            (CircledImageViewPreference)
                    findPreference(getString(R.string.key_pref_circled_image_view));

    mPreferenceScreen =
            (PreferenceScreen) findPreference(getString(R.string.key_pref_progress_screen));

    mProgressBarPreference = new ProgressBarPreference(getContext());
    mProgressBarPreference.setTitle("@string/indeterminant_progress");

    mDeterminantSwitchPref.setOnPreferenceChangeListener(
            new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    mDeterminantSwitchPref.setChecked(!mDeterminantSwitchPref.isChecked());
                    if (mDeterminantSwitchPref.isChecked()) {
                        mCircledImageViewPref.cancelCountDownTimer();
                        mCircledImageViewPref.setStartCircledImageView();
                        mPreferenceScreen.removePreference(mProgressBarPreference);
                        mPreferenceScreen.addPreference(mCircledImageViewPref);
                    } else {
                        mPreferenceScreen.removePreference(mCircledImageViewPref);
                        mPreferenceScreen.addPreference(mProgressBarPreference);
                    }
                    return true;
                }
            });
}
 
开发者ID:googlesamples,项目名称:android-WearAccessibilityApp,代码行数:40,代码来源:InLineActivity.java


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