/ime/latinime/src/com/googlecode/eyesfree/inputmethod/voice/SettingsUtil.java

http://eyes-free.googlecode.com/ · Java · 110 lines · 34 code · 12 blank · 64 comment · 1 complexity · a9dda840a106b891c99a7f6fd69a6c04 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.googlecode.eyesfree.inputmethod.voice;
  17. import android.content.ContentResolver;
  18. import android.provider.Settings;
  19. /**
  20. * Utility for retrieving settings from Settings.Secure.
  21. */
  22. public class SettingsUtil {
  23. /**
  24. * A whitespace-separated list of supported locales for voice input from the keyboard.
  25. */
  26. public static final String LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES =
  27. "latin_ime_voice_input_supported_locales";
  28. /**
  29. * A whitespace-separated list of recommended app packages for voice input from the
  30. * keyboard.
  31. */
  32. public static final String LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES =
  33. "latin_ime_voice_input_recommended_packages";
  34. /**
  35. * The maximum number of unique days to show the swipe hint for voice input.
  36. */
  37. public static final String LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS =
  38. "latin_ime_voice_input_swipe_hint_max_days";
  39. /**
  40. * The maximum number of times to show the punctuation hint for voice input.
  41. */
  42. public static final String LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS =
  43. "latin_ime_voice_input_punctuation_hint_max_displays";
  44. /**
  45. * Endpointer parameters for voice input from the keyboard.
  46. */
  47. public static final String LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS =
  48. "latin_ime_speech_minimum_length_millis";
  49. public static final String LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS =
  50. "latin_ime_speech_input_complete_silence_length_millis";
  51. public static final String LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
  52. "latin_ime_speech_input_possibly_complete_silence_length_millis";
  53. /**
  54. * Min and max volume levels that can be displayed on the "speak now" screen.
  55. */
  56. public static final String LATIN_IME_MIN_MICROPHONE_LEVEL =
  57. "latin_ime_min_microphone_level";
  58. public static final String LATIN_IME_MAX_MICROPHONE_LEVEL =
  59. "latin_ime_max_microphone_level";
  60. /**
  61. * The number of sentence-level alternates to request of the server.
  62. */
  63. public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results";
  64. /**
  65. * Get a string-valued setting.
  66. *
  67. * @param cr The content resolver to use
  68. * @param key The setting to look up
  69. * @param defaultValue The default value to use if none can be found
  70. * @return The value of the setting, or defaultValue if it couldn't be found
  71. */
  72. public static String getSettingsString(ContentResolver cr, String key, String defaultValue) {
  73. String result = Settings.Secure.getString(cr, key);
  74. return (result == null) ? defaultValue : result;
  75. }
  76. /**
  77. * Get an int-valued setting.
  78. *
  79. * @param cr The content resolver to use
  80. * @param key The setting to look up
  81. * @param defaultValue The default value to use if the setting couldn't be found or parsed
  82. * @return The value of the setting, or defaultValue if it couldn't be found or parsed
  83. */
  84. public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) {
  85. return Settings.Secure.getInt(cr, key, defaultValue);
  86. }
  87. /**
  88. * Get a float-valued setting.
  89. *
  90. * @param cr The content resolver to use
  91. * @param key The setting to look up
  92. * @param defaultValue The default value to use if the setting couldn't be found or parsed
  93. * @return The value of the setting, or defaultValue if it couldn't be found or parsed
  94. */
  95. public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) {
  96. return Settings.Secure.getFloat(cr, key, defaultValue);
  97. }
  98. }