當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。