aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/voice/SettingsUtil.java
blob: abf52047fff33c01d0f46eb7602a2979094cb079 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (C) 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.android.inputmethod.voice;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.provider.Settings;
import android.util.Log;

/**
 * Utility for retrieving settings from Settings.Secure.
 */
public class SettingsUtil {
    /**
     * A whitespace-separated list of supported locales for voice input from the keyboard.
     */
    public static final String LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES =
            "latin_ime_voice_input_supported_locales";

    /**
     * A whitespace-separated list of recommended app packages for voice input from the
     * keyboard.
     */
    public static final String LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES =
            "latin_ime_voice_input_recommended_packages";

    /**
     * The maximum number of unique days to show the swipe hint for voice input.
     */
    public static final String LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS =
            "latin_ime_voice_input_swipe_hint_max_days";

    /**
     * The maximum number of times to show the punctuation hint for voice input.
     */
    public static final String LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS =
            "latin_ime_voice_input_punctuation_hint_max_displays";

    /**
     * Endpointer parameters for voice input from the keyboard.
     */
    public static final String LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS =
            "latin_ime_speech_minimum_length_millis";
    public static final String LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS =
            "latin_ime_speech_input_complete_silence_length_millis";
    public static final String LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
            "latin_ime_speech_input_possibly_complete_silence_length_millis";

    /**
     * Min and max volume levels that can be displayed on the "speak now" screen.
     */
    public static final String LATIN_IME_MIN_MICROPHONE_LEVEL =
            "latin_ime_min_microphone_level";
    public static final String LATIN_IME_MAX_MICROPHONE_LEVEL =
            "latin_ime_max_microphone_level";

    /**
     * The number of sentence-level alternates to request of the server.
     */
    public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results";

    /**
     * Get a string-valued setting.
     *
     * @param cr The content resolver to use
     * @param key The setting to look up
     * @param defaultValue The default value to use if none can be found
     * @return The value of the setting, or defaultValue if it couldn't be found
     */
    public static String getSettingsString(ContentResolver cr, String key, String defaultValue) {
        String result = Settings.Secure.getString(cr, key);
        return (result == null) ? defaultValue : result;
    }

    /**
     * Get an int-valued setting.
     *
     * @param cr The content resolver to use
     * @param key The setting to look up
     * @param defaultValue The default value to use if the setting couldn't be found or parsed
     * @return The value of the setting, or defaultValue if it couldn't be found or parsed
     */
    public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) {
        return Settings.Secure.getInt(cr, key, defaultValue);
    }

    /**
     * Get a float-valued setting.
     *
     * @param cr The content resolver to use
     * @param key The setting to look up
     * @param defaultValue The default value to use if the setting couldn't be found or parsed
     * @return The value of the setting, or defaultValue if it couldn't be found or parsed
     */
    public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) {
        return Settings.Secure.getFloat(cr, key, defaultValue);
    }
}