Java Code Examples for android.preference.ListPreference#getValue()

The following examples show how to use android.preference.ListPreference#getValue() . 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: PreferencesDecorator.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
protected void decorateListPreference(final ListPreference listPrefs) {
    final CharSequence summary = listPrefs.getSummary();
    summaries.put(listPrefs.getKey(), summary);

    final String value = listPrefs.getValue();

    setListPreferenceSummary(listPrefs, value);

    addListener(listPrefs, new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            setListPreferenceSummary(listPrefs, (String) newValue);
            return true;
        }
    });
}
 
Example 2
Source File: SettingsActivity.java    From your-local-weather with GNU General Public License v3.0 6 votes vote down vote up
private void setDetailedSummary(CharSequence prefKey) {
    Preference updatePref = findPreference(prefKey);
    ListPreference updateListPref = (ListPreference) updatePref;
    switch (updateListPref.getValue()) {
        case "preference_display_update_value":
            updatePref.setSummary(R.string.preference_display_update_value_info);
            break;
        case "preference_display_update_location_source":
            updatePref.setSummary(R.string.preference_display_update_location_source_info);
            break;
        case "preference_display_update_nothing":
        default:
            updatePref.setSummary(updateListPref.getEntry());
            break;
    }
}
 
Example 3
Source File: CameraSettingsActivity.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the summary for the given list preference.
 *
 * @param displayableSizes The human readable preferred sizes
 * @param preference       The preference for which to set the summary.
 */
private void setSummaryForSelection(List<Size> displayableSizes,
                                    ListPreference preference)
{
    String setting = preference.getValue();
    if (setting == null || !setting.contains("x"))
    {
        return;
    }
    Size settingSize = SettingsUtil.sizeFromSettingString(setting);
    if (settingSize == null || settingSize.area() == 0)
    {
        return;
    }
    preference.setSummary(getSizeSummaryString(settingSize));
}
 
Example 4
Source File: SettingsActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
private void changeOmemoSettingSummary() {
	ListPreference omemoPreference = (ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING);
	if (omemoPreference != null) {
		String value = omemoPreference.getValue();
		switch (value) {
			case "always":
				omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
				break;
			case "default_on":
				omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
				break;
			case "default_off":
				omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
				break;
		}
	} else {
		Log.d(Config.LOGTAG,"unable to find preference named "+OMEMO_SETTING);
	}
}
 
Example 5
Source File: SettingsFragment.java    From 600SeriesAndroidUploader with MIT License 6 votes vote down vote up
/**
 * set lowBatPollInterval to normal poll interval at least
 * and adapt the selectable values
 *
 * @param pollIntervalPref
 * @param lowBatPollIntervalPref
 */
private void setMinBatPollIntervall(ListPreference pollIntervalPref, ListPreference lowBatPollIntervalPref) {
    final String currentValue = lowBatPollIntervalPref.getValue();
    final int pollIntervalPos = (pollIntervalPref.findIndexOfValue(pollIntervalPref.getValue()) >= 0?pollIntervalPref.findIndexOfValue(pollIntervalPref.getValue()):0),
            length = pollIntervalPref.getEntries().length;

    CharSequence[] entries = new String[length - pollIntervalPos],
            entryValues = new String[length - pollIntervalPos];

    // generate temp Entries and EntryValues
    for(int i = pollIntervalPos; i < length; i++) {
        entries[i - pollIntervalPos] = pollIntervalPref.getEntries()[i];
        entryValues[i - pollIntervalPos] = pollIntervalPref.getEntryValues()[i];
    }
    lowBatPollIntervalPref.setEntries(entries);
    lowBatPollIntervalPref.setEntryValues(entryValues);

    // and set the correct one
    if (lowBatPollIntervalPref.findIndexOfValue(currentValue) == -1) {
        lowBatPollIntervalPref.setValueIndex(0);
    }
}
 
Example 6
Source File: SettingsFragment.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
                                      final String key) {
    final Preference connectionPref = findPreference(key);
    if (connectionPref instanceof ListPreference) {
        showUserDescriptionAsSummary(connectionPref);
    }

    //Copy the preference to the Account:
    //This is an awful hack. Hopefully there is some other way to use preferences per-account.
    //If not, maybe we need to reimplement this fragment without using PreferencesFragment.
    String value = null;
    if (connectionPref instanceof ListPreference) {
        final ListPreference listPref = (ListPreference) connectionPref;
        value = listPref.getValue();
    } else if (connectionPref instanceof CheckBoxPreference) {
        final CheckBoxPreference checkboxPref = (CheckBoxPreference) connectionPref;
        value = checkboxPref.isChecked() ? "true" : ""; //See Boolean.parseBoolean().
    }

    LoginUtils.copyPrefToAccount(getActivity(), key, value);
}
 
Example 7
Source File: SettingsActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
private void changeOmemoSettingSummary() {
    ListPreference omemoPreference = (ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING);
    if (omemoPreference != null) {
        String value = omemoPreference.getValue();
        switch (value) {
            case "always":
                omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
                break;
            case "default_on":
                omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
                break;
            case "default_off":
                omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
                break;
            case "always_off":
                omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always_off);
                break;
        }
    } else {
        Log.d(Config.LOGTAG, "unable to find preference named " + OMEMO_SETTING);
    }
}
 
Example 8
Source File: OthersPreferenceFragment.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preference_others);

		// Default tab
		defaultTabPref = (ListPreference)findPreference(getString(R.string.pref_key_default_tab_name));
		Set<String> hiddenFragments = SkyTubeApp.getPreferenceManager().getStringSet(getString(R.string.pref_key_hide_tabs), new HashSet<>());
		String[] tabListValues = SkyTubeApp.getStringArray(R.array.tab_list_values);
		if(hiddenFragments.size() == 0) {
			defaultTabPref.setEntries(SkyTubeApp.getStringArray(R.array.tab_list));
			defaultTabPref.setEntryValues(tabListValues);
		} else {
			List<String> defaultTabEntries = new ArrayList<>();
			List<String> defaultTabEntryValues = new ArrayList<>();
			for(int i=0;i<SkyTubeApp.getStringArray(R.array.tab_list).length;i++) {
				if(!hiddenFragments.contains(tabListValues[i])) {
					defaultTabEntries.add(SkyTubeApp.getStringArray(R.array.tab_list)[i]);
					defaultTabEntryValues.add(tabListValues[i]);

				}
			}
			defaultTabPref.setEntries(defaultTabEntries.toArray(new CharSequence[defaultTabEntries.size()]));
			defaultTabPref.setEntryValues(defaultTabEntryValues.toArray(new CharSequence[defaultTabEntryValues.size()]));
		}
		if (defaultTabPref.getValue() == null) {
			defaultTabPref.setValueIndex(0);
		}
		defaultTabPref.setSummary(String.format(getString(R.string.pref_summary_default_tab), defaultTabPref.getEntry()));

		MultiSelectListPreference hiddenTabsPref = (MultiSelectListPreference)findPreference(getString(R.string.pref_key_hide_tabs));
		hiddenTabsPref.setEntryValues(tabListValues);

//		ListPreference feedNotificationPref = (ListPreference) findPreference(getString(R.string.pref_feed_notification_key));
//		if(feedNotificationPref.getValue() == null) {
//			feedNotificationPref.setValueIndex(0);
//		}
//		feedNotificationPref.setSummary(String.format(getString(R.string.pref_summary_feed_notification), feedNotificationPref.getEntry()));
	}
 
Example 9
Source File: PeepersPreferenceActivity.java    From peepers with Apache License 2.0 5 votes vote down vote up
private void setSizePreferences(final ListPreference sizePreference,
                                final ListPreference cameraPreference)
{
    final String cameraPreferenceValue = cameraPreference.getValue();
    final int cameraIndex;
    if (cameraPreferenceValue != null)
    {
        cameraIndex = Integer.parseInt(cameraPreferenceValue);
    } // if
    else
    {
        cameraIndex = 0;
    } // else
    final Camera camera = Camera.open(cameraIndex);
    final Camera.Parameters params = camera.getParameters();
    camera.release();

    final List<Camera.Size> supportedPreviewSizes = params.getSupportedPreviewSizes();
    CharSequence[] entries = new CharSequence[supportedPreviewSizes.size()];
    CharSequence[] entryValues = new CharSequence[supportedPreviewSizes.size()];
    for (int previewSizeIndex = 0; previewSizeIndex < supportedPreviewSizes.size();
         previewSizeIndex++)
    {
        Camera.Size supportedPreviewSize = supportedPreviewSizes.get(previewSizeIndex);
        entries[previewSizeIndex] = supportedPreviewSize.width + "x"
                                    + supportedPreviewSize.height;
        entryValues[previewSizeIndex] = String.valueOf(previewSizeIndex);
    } // for

    sizePreference.setEntries(entries);
    sizePreference.setEntryValues(entryValues);

}
 
Example 10
Source File: SettingsFragment.java    From meatspace-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ListPreference urlPreference = (ListPreference) findPreference(getString(R.string.settings_url_key));
    if (urlPreference.getValue() == null) {
        urlPreference.setValue(getString(BuildConfig.MEATSPACE_BASE_URL));
    }
    urlPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            getActivity().sendBroadcast(new Intent(Constants.FILTER_CHAT_CLOSE));
            return true;
        }
    });
}
 
Example 11
Source File: SettingsActivity.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
protected void updatePrefsSummary(Preference pref) {
    if (pref == null) {
        return;
    }

    if (pref instanceof ListPreference) {
        ListPreference lst = (ListPreference) pref;
        String currentValue = lst.getValue();

        int index = lst.findIndexOfValue(currentValue);
        CharSequence[] entries = lst.getEntries();
        if (index >= 0 && index < entries.length) {
            pref.setSummary(entries[index]);
        }
    } else if (pref instanceof PreferenceScreen) {
        PreferenceScreen screen = (PreferenceScreen) pref;

        if (screen.getKey().equals(getString(R.string.prefs_key_account_info))) {
            if (mTokenStorage.isLoggedIn()) {
                screen.setSummary(getString(R.string.logged_in));
            } else {
                screen.setSummary(R.string.tap_to_sign_in);
            }
        }
    } else if (pref instanceof DragReorderActionsPreference) {
        pref.setSummary(pref.getSummary());
    }
}
 
Example 12
Source File: WidgetActivity.java    From Torch with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
  // No need to go to fragments right now
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

mActivity = this;
      mContext = this.getApplicationContext();
      mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

      addPreferencesFromResource(R.layout.activity_widget);

      mWidgetProvider = TorchWidgetProvider.getInstance();

      mColor = (ListPreference) findPreference(KEY_WIDGET_COLOR);
      if(mColor.getValue()==null){
          mColor.setValueIndex(0);
      }
      mColor.setSummary(mColor.getValue().toString());
      mColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
              preference.setSummary(newValue.toString());
              String mPrefColor = newValue.toString();
              Utils.colorizeBar(mActivity, mContext, mPrefColor);
              return true;
          }
      });

      Bundle extras = getIntent().getExtras();
      if (extras != null) {
          mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                  AppWidgetManager.INVALID_APPWIDGET_ID);
      }

      mPreferences.registerOnSharedPreferenceChangeListener(this);
  }
 
Example 13
Source File: SetupActivity.java    From trigger with GNU General Public License v2.0 5 votes vote down vote up
private String getText(String key) {
    Preference p = findAnyPreference(key, null);
    if (p instanceof EditTextPreference) {
        EditTextPreference etp = (EditTextPreference) p;
        return etp.getText();
    } else if (p instanceof ListPreference) {
        ListPreference lp = (ListPreference) p;
        return lp.getValue();
    } else {
        Log.w("SetupActivity.setText", "Cannot find EditTextPreference/ListPreference in PreferenceGroup with key: " + key);
        return "";
    }
}
 
Example 14
Source File: AdvancedSettingsFragment.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_advanced);

    final Resources res = getResources();
    final Context context = getActivity();

    // When we are called from the Settings application but we are not already running, some
    // singleton and utility classes may not have been initialized.  We have to call
    // initialization method of these classes here. See {@link LatinIME#onCreate()}.
    AudioAndHapticFeedbackManager.init(context);

    final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();

    if (!Settings.isInternal(prefs)) {
        removePreference(Settings.SCREEN_DEBUG);
    }

    if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
        removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
    }

    // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
    if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
        removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
    } else {
        // TODO: Cleanup this setup.
        final ListPreference keyPreviewPopupDismissDelay =
                (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
        final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
                R.integer.config_key_preview_linger_timeout));
        keyPreviewPopupDismissDelay.setEntries(new String[] {
                res.getString(R.string.key_preview_popup_dismiss_no_delay),
                res.getString(R.string.key_preview_popup_dismiss_default_delay),
        });
        keyPreviewPopupDismissDelay.setEntryValues(new String[] {
                "0",
                popupDismissDelayDefaultValue
        });
        if (null == keyPreviewPopupDismissDelay.getValue()) {
            keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
        }
        keyPreviewPopupDismissDelay.setEnabled(
                Settings.readKeyPreviewPopupEnabled(prefs, res));
    }

    setupKeypressVibrationDurationSettings();
    setupKeypressSoundVolumeSettings();
    setupKeyLongpressTimeoutSettings();
    refreshEnablingsOfKeypressSoundAndVibrationSettings();
}
 
Example 15
Source File: AdvancedSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_advanced);

    final Resources res = getResources();
    final Context context = getActivity();

    // When we are called from the Settings application but we are not already running, some
    // singleton and utility classes may not have been initialized.  We have to call
    // initialization method of these classes here. See {@link LatinIME#onCreate()}.
    AudioAndHapticFeedbackManager.init(context);

    final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();

    if (!Settings.isInternal(prefs)) {
        removePreference(Settings.SCREEN_DEBUG);
    }

    if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
        removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
    }

    // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
    if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
        removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
    } else {
        // TODO: Cleanup this setup.
        final ListPreference keyPreviewPopupDismissDelay =
                (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
        final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
                R.integer.config_key_preview_linger_timeout));
        keyPreviewPopupDismissDelay.setEntries(new String[] {
                res.getString(R.string.key_preview_popup_dismiss_no_delay),
                res.getString(R.string.key_preview_popup_dismiss_default_delay),
        });
        keyPreviewPopupDismissDelay.setEntryValues(new String[] {
                "0",
                popupDismissDelayDefaultValue
        });
        if (null == keyPreviewPopupDismissDelay.getValue()) {
            keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
        }
        keyPreviewPopupDismissDelay.setEnabled(
                Settings.readKeyPreviewPopupEnabled(prefs, res));
    }

    setupKeypressVibrationDurationSettings();
    setupKeypressSoundVolumeSettings();
    setupKeyLongpressTimeoutSettings();
    refreshEnablingsOfKeypressSoundAndVibrationSettings();
}
 
Example 16
Source File: AdvancedSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_advanced);

    final Resources res = getResources();
    final Context context = getActivity();

    // When we are called from the Settings application but we are not already running, some
    // singleton and utility classes may not have been initialized.  We have to call
    // initialization method of these classes here. See {@link LatinIME#onCreate()}.
    AudioAndHapticFeedbackManager.init(context);

    final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();

    if (!Settings.isInternal(prefs)) {
        removePreference(Settings.SCREEN_DEBUG);
    }

    if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
        removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
    }

    // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
    if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
        removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
    } else {
        // TODO: Cleanup this setup.
        final ListPreference keyPreviewPopupDismissDelay =
                (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
        final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
                R.integer.config_key_preview_linger_timeout));
        keyPreviewPopupDismissDelay.setEntries(new String[] {
                res.getString(R.string.key_preview_popup_dismiss_no_delay),
                res.getString(R.string.key_preview_popup_dismiss_default_delay),
        });
        keyPreviewPopupDismissDelay.setEntryValues(new String[] {
                "0",
                popupDismissDelayDefaultValue
        });
        if (null == keyPreviewPopupDismissDelay.getValue()) {
            keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
        }
        keyPreviewPopupDismissDelay.setEnabled(
                Settings.readKeyPreviewPopupEnabled(prefs, res));
    }

    setupKeypressVibrationDurationSettings();
    setupKeypressSoundVolumeSettings();
    setupKeyLongpressTimeoutSettings();
    refreshEnablingsOfKeypressSoundAndVibrationSettings();
}
 
Example 17
Source File: SettingsActivity.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref_updates);

    SensorManager senSensorManager  = (SensorManager) getActivity()
            .getSystemService(Context.SENSOR_SERVICE);
    Sensor senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    boolean deviceHasAccelerometer = senSensorManager.registerListener(
            sensorListener,
            senAccelerometer,
            SensorManager.SENSOR_DELAY_FASTEST);
    senSensorManager.unregisterListener(sensorListener);

    Preference updateWidgetUpdatePref = findPreference(Constants.KEY_PREF_LOCATION_AUTO_UPDATE_PERIOD);
    ListPreference updateListPref = (ListPreference) updateWidgetUpdatePref;
    int accIndex = updateListPref.findIndexOfValue("0");

    if (!deviceHasAccelerometer) {
        CharSequence[] entries = updateListPref.getEntries();
        CharSequence[] newEntries = new CharSequence[entries.length - 1];
        int i = 0;
        int j = 0;
        for (CharSequence entry : entries) {
            if (i != accIndex) {
                newEntries[j] = entries[i];
                j++;
            }
            i++;
        }
        updateListPref.setEntries(newEntries);
        if (updateListPref.getValue() == null) {
            updateListPref.setValueIndex(updateListPref.findIndexOfValue("60") - 1);
        }
    } else if (updateListPref.getValue() == null) {
        updateListPref.setValueIndex(accIndex);
    }
    LocationsDbHelper locationsDbHelper = LocationsDbHelper.getInstance(getActivity());
    List<Location> availableLocations = locationsDbHelper.getAllRows();
    boolean oneNoautoLocationAvailable = false;
    for (Location location: availableLocations) {
        if (location.getOrderId() != 0) {
            oneNoautoLocationAvailable = true;
            break;
        }
    }
    if (!oneNoautoLocationAvailable) {
        ListPreference locationPreference = (ListPreference) findPreference("location_update_period_pref_key");
        locationPreference.setEnabled(false);
    }

    ListPreference locationAutoPreference = (ListPreference) findPreference("location_auto_update_period_pref_key");
    locationAutoPreference.setEnabled(locationsDbHelper.getLocationByOrderId(0).isEnabled());
}
 
Example 18
Source File: GroupSettingsFragment.java    From snapdroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.group_preferences);
        PreferenceScreen screen = this.getPreferenceScreen();

        prefStreams = (ListPreference) findPreference("pref_stream");

        Bundle bundle = getArguments();
        try {
            group = new Group(new JSONObject(bundle.getString("group")));
            serverStatus = new ServerStatus(new JSONObject(bundle.getString("serverStatus")));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        final ArrayList<Stream> streams = serverStatus.getStreams();
        final CharSequence[] streamNames = new CharSequence[streams.size()];
        final CharSequence[] streamIds = new CharSequence[streams.size()];
        for (int i = 0; i < streams.size(); ++i) {
            streamNames[i] = streams.get(i).getName();
            streamIds[i] = streams.get(i).getId();
        }

        prefStreams.setEntries(streamNames);
        prefStreams.setEntryValues(streamIds);

        for (int i = 0; i < streams.size(); ++i) {
            if (streamIds[i].equals(group.getStreamId())) {
                prefStreams.setTitle(streamNames[i]);
                prefStreams.setValueIndex(i);
                oldStream = prefStreams.getValue();
                break;
            }
        }

        prefStreams.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                for (int i = 0; i < streams.size(); ++i) {
                    if (streamIds[i].equals(newValue)) {
                        prefStreams.setTitle(streamNames[i]);
//                        client.getConfig().setStream(streamIds[i].toString());
                        prefStreams.setValueIndex(i);
                        break;
                    }
                }

                return false;
            }
        });


        prefCatClients = (PreferenceCategory) findPreference("pref_cat_clients");
        ArrayList<CheckBoxPreference> allClients = new ArrayList<>();
        for (Group g : serverStatus.getGroups()) {
            for (Client client : g.getClients()) {
                CheckBoxPreference checkBoxPref = new CheckBoxPreference(screen.getContext());
                checkBoxPref.setKey(client.getId());
                checkBoxPref.setTitle(client.getVisibleName());
                checkBoxPref.setChecked(g.getId().equals(group.getId()));
                checkBoxPref.setPersistent(false);
                allClients.add(checkBoxPref);
            }
        }
        Collections.sort(allClients, new Comparator<CheckBoxPreference>() {
            @Override
            public int compare(CheckBoxPreference lhs, CheckBoxPreference rhs) {
                return lhs.getTitle().toString().compareToIgnoreCase(rhs.getTitle().toString());
            }
        });
        for (CheckBoxPreference pref : allClients)
            prefCatClients.addPreference(pref);

        oldClients = getClients().toString();
    }
 
Example 19
Source File: AdvancedSettingsFragment.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_advanced);

    final Resources res = getResources();
    final Context context = getActivity();

    // When we are called from the Settings application but we are not already running, some
    // singleton and utility classes may not have been initialized.  We have to call
    // initialization method of these classes here. See {@link LatinIME#onCreate()}.
    AudioAndHapticFeedbackManager.init(context);

    final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();

    if (!Settings.isInternal(prefs)) {
        removePreference(Settings.SCREEN_DEBUG);
    }

    if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
        removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
    }

    // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
    if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
        removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
    } else {
        // TODO: Cleanup this setup.
        final ListPreference keyPreviewPopupDismissDelay =
                (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
        final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
                R.integer.config_key_preview_linger_timeout));
        keyPreviewPopupDismissDelay.setEntries(new String[] {
                res.getString(R.string.key_preview_popup_dismiss_no_delay),
                res.getString(R.string.key_preview_popup_dismiss_default_delay),
        });
        keyPreviewPopupDismissDelay.setEntryValues(new String[] {
                "0",
                popupDismissDelayDefaultValue
        });
        if (null == keyPreviewPopupDismissDelay.getValue()) {
            keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
        }
        keyPreviewPopupDismissDelay.setEnabled(
                Settings.readKeyPreviewPopupEnabled(prefs, res));
    }

    setupKeypressVibrationDurationSettings();
    setupKeypressSoundVolumeSettings();
    setupKeyLongpressTimeoutSettings();
    refreshEnablingsOfKeypressSoundAndVibrationSettings();
}