android.preference.SwitchPreference Java Examples

The following examples show how to use android.preference.SwitchPreference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingsActivity.java    From android with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    boolean hasReminders = accountManager.getAllowReminders(getActivity());
    ((SwitchPreference) findPreference(AccountManager.KEY_ALLOW_REMINDERS))
            .setChecked(hasReminders);

    Set<String> reminderDays = accountManager.getReminderDays(getActivity());
    MultiSelectListPreference daysPreference =
            (MultiSelectListPreference) findPreference(AccountManager.KEY_REMINDER_DAYS);
    daysPreference.setValues(reminderDays);
    updateReminderDaysSummary(daysPreference, reminderDays);

    String notificationSetting = accountManager.getNotificationPreference(getActivity());
    ListPreference notificationPref =
            (ListPreference) findPreference(AccountManager.KEY_NOTIFICATIONS);
    notificationPref.setValue(notificationSetting);
}
 
Example #2
Source File: SettingsFragment.java    From ToDoList with Apache License 2.0 6 votes vote down vote up
public void intView(){
    preferenceScreen = getPreferenceScreen();
    mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_RINGTONE);
    mFocus = (SwitchPreference) preferenceScreen.findPreference(KEY_FOCUS);
    mChangePassWord = (Preference) preferenceScreen.findPreference(KEY_PWD);
    mExitLogin = (Preference) preferenceScreen.findPreference(KEY_EXIT);
    Uri uri = Uri.parse(SPUtils.get(getActivity(), KEY_RINGTONE, "").toString());
    Log.i(TAG, "铃声" + getRingtonName(uri));
    if (getRingtonName(uri).equals("未知铃声")){
        mRingtone.setSummary("默认铃声");
    } else {
        mRingtone.setSummary(getRingtonName(uri));
    }
    mFocus.setChecked(getIsFocus(getActivity()));

}
 
Example #3
Source File: TwoStatePreferenceHelper.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #4
Source File: TwoStatePreferenceHelper.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #5
Source File: PrefFragment.java    From NetUpDown with Apache License 2.0 6 votes vote down vote up
@TargetApi(14)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    /*
     * SwitchPreferences calls multiple times the onPreferenceChange() method
     * It is due to the bug in SwitchPreference implementation.
     * And it's solved in API 21+
     */
    //if (C.SDK >= 14) {
    if (C.SDK >= 21) {
        switchPreference = (SwitchPreference) findPreference("run");
    } else {
        checkBoxPreference = (CheckBoxPreference) findPreference("run");
    }
    findPreference("run").setOnPreferenceChangeListener(this);

    serviceReceiver = new ServiceReceiver();

    sp = new SP(getActivity());
}
 
Example #6
Source File: TwoStatePreferenceHelper.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #7
Source File: SettingsActivity.java    From AudioAnchor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
    Preference pref = findPreference(s);

    updatePrefSummary(pref);

    if (s.equals(getString(R.string.settings_autoplay_key))) {
        boolean isChecked = ((SwitchPreference) pref).isChecked();
        final SwitchPreference autoplayPositionPref = (SwitchPreference) findPreference(getString(R.string.settings_autoplay_restart_key));
        if (isChecked) {
            autoplayPositionPref.setEnabled(true);
        } else {
            autoplayPositionPref.setEnabled(false);
        }
    }
}
 
Example #8
Source File: MainActivity.java    From SnooperStopper with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #9
Source File: TwoStatePreferenceHelper.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #10
Source File: CorrectionSettingsFragment.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_correction);

    final Context context = getActivity();
    final PackageManager pm = context.getPackageManager();

    final Preference editPersonalDictionary =
            findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
    final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
    final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS ? null
            : pm.resolveActivity(
                    editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
    if (ri == null) {
        overwriteUserDictionaryPreference(editPersonalDictionary);
    }

    mUseContactsPreference = (SwitchPreference) findPreference(Settings.PREF_KEY_USE_CONTACTS_DICT);
    turnOffUseContactsIfNoPermission();
}
 
Example #11
Source File: SettingsFragment.java    From always-on-amoled with GNU General Public License v3.0 6 votes vote down vote up
private boolean checkNotificationsPermission(Context c, boolean prompt) {
    ContentResolver contentResolver = c.getContentResolver();
    String enabledNotificationListeners = Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
    String packageName = c.getPackageName();

    // check to see if the enabledNotificationListeners String contains our package name
    if (enabledNotificationListeners == null || !enabledNotificationListeners.contains(packageName)) {
        ((SwitchPreference) findPreference("notifications_alerts")).setChecked(false);
        if (Utils.isAndroidNewerThanL() && prompt) {
            Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            checkAndStartActivity(intent);
            shouldEnableNotificationsAlerts = true;
        } else if (prompt) {
            checkAndStartActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
            shouldEnableNotificationsAlerts = true;
        }
        return false;
    }
    return true;
}
 
Example #12
Source File: SettingsActivity.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    final SwitchPreference zeroAmountTx = (SwitchPreference) findPreference("zeroAmountSwitch");
    zeroAmountTx.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            Settings.showTransactionsWithZero = !zeroAmountTx.isChecked();
            return true;
        }
    });
    Settings.displayAds = false;
}
 
Example #13
Source File: TwoStatePreferenceHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #14
Source File: NotificationsActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    mNotificationManagerCompat = NotificationManagerCompat.from(getActivity());

    final SwitchPreference mActionSwitchPref =
            (SwitchPreference) findPreference(getString(R.string.key_pref_action));
    final SwitchPreference mAvatarSwitchPref =
            (SwitchPreference) findPreference(getString(R.string.key_pref_avatar));
    Preference mPushNotificationPref =
            findPreference(getString(R.string.key_pref_push_notification));

    initInLineAction(mActionSwitchPref);
    initAvatar(mAvatarSwitchPref);
    initPushNotification(mPushNotificationPref);
}
 
Example #15
Source File: SettingsFragment.java    From Interessant with Apache License 2.0 6 votes vote down vote up
@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));

}
 
Example #16
Source File: SettingFragment.java    From Ency with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    sharePrefManager = new SharePrefManager(getActivity());

    provincialFlowPreference = (SwitchPreference) findPreference(getResources().getString(R.string.key_provincial_traffic_patterns));
    nightModePreference = (SwitchPreference) findPreference(getResources().getString(R.string.key_night_mode));
    cleanCachePreference = findPreference(getResources().getString(R.string.key_clear_cache));
    versionPreference = findPreference(getResources().getString(R.string.key_version));
    homepagePreference = findPreference(getResources().getString(R.string.key_homepage));

    provincialFlowPreference.setOnPreferenceChangeListener(this);
    nightModePreference.setOnPreferenceChangeListener(this);
    cleanCachePreference.setOnPreferenceClickListener(this);
    versionPreference.setOnPreferenceClickListener(this);
    homepagePreference.setOnPreferenceClickListener(this);

    // 设置当前版本号
    versionPreference.setSummary("V " + AppApplicationUtil.getVersionName(getActivity()));

    // 设置缓存大小
    cleanCachePreference.setSummary("缓存大小:" + SystemUtil.getTotalCacheSize(getActivity()));
}
 
Example #17
Source File: PBPreferenceFragment.java    From client-android with GNU General Public License v2.0 6 votes vote down vote up
private void startOrStopService(final SharedPreferences preferences) {
    boolean userDidStart = preferences.getBoolean(PBConstants.PREF_SERVICE_RUNNING, false);
    Log.i(LOG_TAG, "PREF_SERVICE_RUNNING = " + userDidStart);

    if (userDidStart) {
        if (validatePreferences()) {
            checkPermissions(PBConstants.PERM_ORIGIN_SERVICE);
        } else {
            final SwitchPreference switchPreference = (SwitchPreference) findPreference(PBConstants.PREF_SERVICE_RUNNING);
            switchPreference.setChecked(false);
        }
    } else if (isPhotoBackupServiceRunning() && currentService != null) {
        Log.i(LOG_TAG, "stop PhotoBackup service");
        getActivity().unbindService(serviceConnection);
        getActivity().invalidateOptionsMenu();
        isBoundToService = false;
        currentService.stopSelf();
        currentService = null;
        updatePreferences();
    }
}
 
Example #18
Source File: SettingFragment.java    From PicKing with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference_screen);

    colsDetail = (int) SPUtils.get(getActivity(), AppConfig.cols_detail, 0);
    RadioPreference cols = (RadioPreference) findPreference(AppConfig.cols_detail);
    cols.setSummary("当前显示列数: " + (colsDetail + 1) + "\n图册页加载图片一般较大,同时显示多列对设备性能要求较高,请酌情选择");

    EditTextPreference downloadPath = (EditTextPreference) findPreference(getResources().getString(R.string.download_path));
    downloadPath.setSummary((String) SPUtils.get(getActivity(), AppConfig.download_path, AppConfig.DOWNLOAD_PATH));

    noMedia = new File((String) SPUtils.get(getActivity(), AppConfig.download_path, AppConfig.DOWNLOAD_PATH) + File.separatorChar + ".nomedia");
    SwitchPreference noMediaSwitch = (SwitchPreference) findPreference(AppConfig.hide_pic);
    if (noMedia.exists())
        noMediaSwitch.setChecked(true);
    else
        noMediaSwitch.setChecked(false);

    Fresco.getImagePipelineFactory().getMainFileCache().trimToMinimum();
    float size = (float) Fresco.getImagePipelineFactory().getMainFileCache().getSize() / ByteConstants.MB;
    cacheSize = (EditTextPreference) findPreference(getResources().getString(R.string.cache_size));
    cacheSize.setSummary(String.format("已使用 %.2f MB", size));
}
 
Example #19
Source File: SettingsFragment.java    From android with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final PreferenceManager pm = this.getPreferenceManager();
    pm.setSharedPreferencesName(Const.APP_PREFS_NAME);
    pm.setSharedPreferencesMode(Context.MODE_PRIVATE);

    addPreferencesFromResource(R.xml.prefs_settings);

    mPrefs = pm.getSharedPreferences();
    pToggleLogin = findPreference(TOGGLE_LOGIN);
    pCity = findPreference(CITY);
    pCarshareMode = (SwitchPreference) findPreference(CARSHARE_MODE);

    // Listeners
    pToggleLogin.setOnPreferenceClickListener(this);

}
 
Example #20
Source File: TwoStatePreferenceHelper.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #21
Source File: CameraSettingFragment.java    From VIA-AI with MIT License 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    SharedPreferences sp = getPreferenceManager().getSharedPreferences();
    ((SwitchPreference)preference).setChecked((boolean) newValue);
    boolean isCamera = !((boolean) newValue);   // false is camera, true is playback

    // -----------------------------------------------------------------
    // Effected preference in this fragment
    findPreference(resource.getString(R.string.prefKey_CameraResource_ADAS_PlaybackPath)).setEnabled(!isCamera);
    findPreference(resource.getString(R.string.prefKey_CameraResource_ADAS_CameraDevices)).setEnabled(isCamera);

    // -----------------------------------------------------------------
    // Effected preference in other fragment.
    //  NO.

    return false;
}
 
Example #22
Source File: DebugSettingsFragment.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    BrowserApp.getAppComponent().inject(this);
    addPreferencesFromResource(R.xml.preference_debug);

    mSwitchLeakCanary = (SwitchPreference) findPreference(LEAK_CANARY);
    mSwitchLeakCanary.setChecked(mPreferenceManager.getUseLeakCanary());
    mSwitchLeakCanary.setOnPreferenceChangeListener(this);
}
 
Example #23
Source File: GeneralPreferenceFragment.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
private void toggleOver18Dependants(boolean flag){
    SwitchPreference labelPref = (SwitchPreference) getPreferenceManager().findPreference(SettingsActivity.general_label_nsfw);
    if(labelPref.isChecked() != flag){
        labelPref.setChecked(flag);
    }
    SwitchPreference prevPref = (SwitchPreference) getPreferenceManager().findPreference(SettingsActivity.general_preview_nsfw);
    if(prevPref.isChecked() != flag){
        prevPref.setChecked(flag);
    }
}
 
Example #24
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void adjustPointScanPrefs() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
    // Remove point scan screen
    PreferenceCategory customizeScanningCategory =
        (PreferenceCategory) findPreference(R.string.pref_category_customize_scanning_key);
    customizeScanningCategory.removePreference(
        findPreference(R.string.pref_category_point_scan_key));
  } else {
    SwitchPreference pointScanPreference =
        (SwitchPreference) findPreference(R.string.pref_key_point_scan_enabled);
    String enableAnimationsMessage =
        ((VERSION.SDK_INT >= VERSION_CODES.O) && !ValueAnimator.areAnimatorsEnabled())
            ? getString(R.string.point_scan_enable_animations_message)
            : "";
    String pointScanPreferenceSummary =
        getString(R.string.summary_pref_point_scan, enableAnimationsMessage);
    pointScanPreference.setSummary(pointScanPreferenceSummary);
    pointScanPreference.setEnabled(
        (VERSION.SDK_INT < VERSION_CODES.O) || ValueAnimator.areAnimatorsEnabled());

    // Make sure the subtitle reflects Point scan state
    PreferenceScreen pointScanScreen =
        (PreferenceScreen) findPreference(R.string.pref_category_point_scan_key);
    if (SwitchAccessPreferenceUtils.isPointScanEnabled(getActivity())) {
      pointScanScreen.setSummary(R.string.preference_on);
    } else {
      pointScanScreen.setSummary(R.string.preference_off);
    }
    ((BaseAdapter) pointScanScreen.getRootAdapter()).notifyDataSetChanged();
  }
}
 
Example #25
Source File: GeneralPreferenceFragment.java    From SimpleSmsRemote with MIT License 5 votes vote down vote up
private void savePreference(String key) {
    Preference pref = findPreference(key);
    switch (key) {
        case KEY_RECEIVER_AUTOSTART:
            DataManager.getUserData().getUserSettings().setStartReceiverOnSystemStart(
                    ((SwitchPreference) pref).isChecked());
            break;
        case KEY_NOTIFY_COMMANDS_EXECUTED:
            DataManager.getUserData().getUserSettings().setNotifyCommandsExecuted(
                    ((SwitchPreference) pref).isChecked());
            break;
        case KEY_REPLY_WITH_RESULT:
            if (((SwitchPreference) pref).isChecked()) {
                if (PermissionUtils.AppHasPermission(getActivity(), Manifest.permission.SEND_SMS))
                    DataManager.getUserData().getUserSettings().setReplyWithResult(true);
                else
                    PermissionUtils.RequestCommonPermissions(this,
                            new String[]{Manifest.permission.SEND_SMS},
                            RESULT_CODE_PERM_REQUEST_FOR_REPLY_WITH_RESULT);
            } else
                DataManager.getUserData().getUserSettings().setReplyWithResult(false);
            break;
        case KEY_RECEIVER_START_FOREGROUND:
            DataManager.getUserData().getUserSettings().setReceiverStartForeground(
                    ((SwitchPreference) pref).isChecked());
            break;
    }
}
 
Example #26
Source File: SettingsFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * Preferenceの設定を有効にします.
 */
private void enablePreference() {
    // 設定画面の有効化
    getPreferenceScreen().setEnabled(true);

    // 設定変更イベントの受信開始
    mCheckBoxSslPreferences.setOnPreferenceChangeListener(this);
    EditTextPreference editHostPreferences = (EditTextPreference) getPreferenceScreen()
        .findPreference(getString(R.string.key_settings_dconn_host));
    editHostPreferences.setOnPreferenceChangeListener(this);
    EditTextPreference editKeywordPreferences = (EditTextPreference) getPreferenceScreen()
        .findPreference(getString(R.string.key_settings_dconn_keyword));
    editKeywordPreferences.setOnPreferenceChangeListener(this);
    EditTextPreference editNamePreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_name));
    editNamePreferences.setOnPreferenceChangeListener(this);
    mEditPortPreferences.setOnPreferenceChangeListener(this);
    mCheckBoxOauthPreferences.setOnPreferenceChangeListener(this);
    mCheckBoxExternalIpPreferences.setOnPreferenceChangeListener(this);
    mCheckBoxExternalStartAndStartPreferences.setOnPreferenceChangeListener(this);
    mCheckBoxRequireOriginPreferences.setOnPreferenceChangeListener(this);
    mCheckBoxOriginBlockingPreferences.setOnPreferenceChangeListener(this);
    mCheckBoxManagerNameVisiblePreferences.setOnPreferenceChangeListener(this);
    mObserverPreferences.setOnPreferenceChangeListener(this);
    mWebPortPreferences.setOnPreferenceChangeListener(this);
    SwitchPreference serverPreferences = (SwitchPreference) getPreferenceScreen()
        .findPreference(getString(R.string.key_settings_dconn_server_on_off));
    serverPreferences.setOnPreferenceChangeListener(this);
    SwitchPreference webPreferences = (SwitchPreference) getPreferenceScreen()
        .findPreference(getString(R.string.key_settings_web_server_on_off));
    webPreferences.setOnPreferenceChangeListener(this);
    SwitchPreference eventKeepAlive = (SwitchPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_event_keep_alive_on_off));
    eventKeepAlive.setOnPreferenceChangeListener(this);
}
 
Example #27
Source File: GeneralPreferenceFragment.java    From SimpleSmsRemote with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref_general);

    UserSettings userSettings = DataManager.getUserData().getUserSettings();

    ((SwitchPreference) findPreference(KEY_RECEIVER_AUTOSTART)).setChecked(
            userSettings.isStartReceiverOnSystemStart());
    ((SwitchPreference) findPreference(KEY_NOTIFY_COMMANDS_EXECUTED)).setChecked(
            userSettings.isNotifyCommandsExecuted());
    ((SwitchPreference) findPreference(KEY_REPLY_WITH_RESULT)).setChecked(
            userSettings.isReplyWithResult());

    /*
    final SwitchPreference prefReceiverStartForeground =
            (SwitchPreference) findPreference(KEY_RECEIVER_START_FOREGROUND);
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
    {
        prefReceiverStartForeground.setEnabled(false);
        prefReceiverStartForeground.setChecked(true);
    }
    else
    {
        prefReceiverStartForeground.setChecked(userSettings.isReceiverStartForeground());
    }
    */
}
 
Example #28
Source File: SettingsFragment.java    From always-on-amoled with GNU General Public License v3.0 5 votes vote down vote up
private void updateSpecialPreferences() {
    if (shouldEnableNotificationsAlerts && checkNotificationsPermission(context, false)) {
        ((TwoStatePreference) findPreference("notifications_alerts")).setChecked(true);
    }
    if (((MaterialListPreference) findPreference("stop_delay")).getValue().equals("0"))
        findPreference("stop_delay").setSummary(R.string.settings_stop_delay_desc);
    else
        findPreference("stop_delay").setSummary("%s");
    findPreference("watchface_clock").setSummary(context.getResources().getStringArray(R.array.customize_clock)[prefs.clockStyle]);
    findPreference("watchface_date").setSummary(context.getResources().getStringArray(R.array.customize_date)[prefs.dateStyle]);
    findPreference("greenify_enabled").setSummary(isPackageInstalled("com.oasisfeng.greenify") ? context.getString(R.string.settings_greenify_integration_desc) : context.getString(R.string.settings_greenify_integration_desc_not_found));
    if (!isPackageInstalled("com.oasisfeng.greenify")) {
        ((SwitchPreference) findPreference("greenify_enabled")).setChecked(false);
    }
}
 
Example #29
Source File: SettingsFragment.java    From Capstone-Project with MIT License 5 votes vote down vote up
private void bindPreferences() {
    mListPreferenceManageThemes = (ListPreference) findPreference(getString(R.string.settings_manage_themes_key));
    mPredatorDialogPreferenceClearCache = (PredatorDialogPreference) findPreference(getString(R.string.settings_clear_cache_key));
    //mSwitchPreferenceEnableExperimentalFeatures = (SwitchPreference) findPreference(getString(R.string.settings_enable_experimental_features_key));
    mListPreferenceChangeFont = (ListPreference) findPreference(getString(R.string.settings_change_font_key));
    mSwitchPreferenceBackgroundSync = (SwitchPreference) findPreference(getString(R.string.settings_background_sync_key));
    mListPreferenceSyncInterval = (ListPreference) findPreference(getString(R.string.settings_sync_interval_key));
    mSwitchPreferenceNotifications = (SwitchPreference) findPreference(getString(R.string.settings_notifications_key));
    mMultiSelectListPreferenceNotificationSettings = (MultiSelectListPreference) findPreference(getString(R.string.settings_notification_settings_key));
}
 
Example #30
Source File: SettingsActivity.java    From XCallRecording-xposed with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
	addPreferencesFromResource(R.xml.preferences);

	findPreference(Settings.PREF_VERSION_NAME).setSummary(BuildConfig.VERSION_NAME);
	mPrefSkipMediaScan = (SwitchPreference) findPreference(Settings.PREF_SKIP_MEDIA_SCAN);
	mPrefSkipMediaScan.setOnPreferenceChangeListener(this);
}