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 17 package com.android.inputmethod.voice; 18 19 import android.content.ContentResolver; 20 import android.database.Cursor; 21 import android.net.Uri; 22 import android.provider.Settings; 23 import android.util.Log; 24 25 /** 26 * Utility for retrieving settings from Settings.Secure. 27 */ 28 public class SettingsUtil { 29 /** 30 * A whitespace-separated list of supported locales for voice input from the keyboard. 31 */ 32 public static final String LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES = 33 "latin_ime_voice_input_supported_locales"; 34 35 /** 36 * A whitespace-separated list of recommended app packages for voice input from the 37 * keyboard. 38 */ 39 public static final String LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES = 40 "latin_ime_voice_input_recommended_packages"; 41 42 /** 43 * The maximum number of unique days to show the swipe hint for voice input. 44 */ 45 public static final String LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS = 46 "latin_ime_voice_input_swipe_hint_max_days"; 47 48 /** 49 * The maximum number of times to show the punctuation hint for voice input. 50 */ 51 public static final String LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS = 52 "latin_ime_voice_input_punctuation_hint_max_displays"; 53 54 /** 55 * Endpointer parameters for voice input from the keyboard. 56 */ 57 public static final String LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS = 58 "latin_ime_speech_minimum_length_millis"; 59 public static final String LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS = 60 "latin_ime_speech_input_complete_silence_length_millis"; 61 public static final String LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS = 62 "latin_ime_speech_input_possibly_complete_silence_length_millis"; 63 64 /** 65 * Min and max volume levels that can be displayed on the "speak now" screen. 66 */ 67 public static final String LATIN_IME_MIN_MICROPHONE_LEVEL = 68 "latin_ime_min_microphone_level"; 69 public static final String LATIN_IME_MAX_MICROPHONE_LEVEL = 70 "latin_ime_max_microphone_level"; 71 72 /** 73 * The number of sentence-level alternates to request of the server. 74 */ 75 public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results"; 76 77 /** 78 * Get a string-valued setting. 79 * 80 * @param cr The content resolver to use 81 * @param key The setting to look up 82 * @param defaultValue The default value to use if none can be found 83 * @return The value of the setting, or defaultValue if it couldn't be found 84 */ 85 public static String getSettingsString(ContentResolver cr, String key, String defaultValue) { 86 String result = Settings.Secure.getString(cr, key); 87 return (result == null) ? defaultValue : result; 88 } 89 90 /** 91 * Get an int-valued setting. 92 * 93 * @param cr The content resolver to use 94 * @param key The setting to look up 95 * @param defaultValue The default value to use if the setting couldn't be found or parsed 96 * @return The value of the setting, or defaultValue if it couldn't be found or parsed 97 */ 98 public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) { 99 return Settings.Secure.getInt(cr, key, defaultValue); 100 } 101 102 /** 103 * Get a float-valued setting. 104 * 105 * @param cr The content resolver to use 106 * @param key The setting to look up 107 * @param defaultValue The default value to use if the setting couldn't be found or parsed 108 * @return The value of the setting, or defaultValue if it couldn't be found or parsed 109 */ 110 public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) { 111 return Settings.Secure.getFloat(cr, key, defaultValue); 112 } 113 } 114