upload android base code part7
This commit is contained in:
parent
4e516ec6ed
commit
841ae54672
25229 changed files with 1709508 additions and 0 deletions
14
android/development/samples/VoiceRecognitionService/Android.mk
Executable file
14
android/development/samples/VoiceRecognitionService/Android.mk
Executable file
|
@ -0,0 +1,14 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := samples
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
LOCAL_DEX_PREOPT := false
|
||||
|
||||
LOCAL_PACKAGE_NAME := VoiceRecognitionService
|
||||
|
||||
include $(BUILD_PACKAGE)
|
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
** Copyright 2010, The Android Open Source Project
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.android.voicerecognitionservice">
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
|
||||
<application>
|
||||
|
||||
<!-- The service that implements voice recognition. Note that a label
|
||||
for the service is important to provide, as this is what will show
|
||||
to users if they have to choose between multiple recognizers in
|
||||
system settings. -->
|
||||
<service android:name="VoiceRecognitionService"
|
||||
android:label="@string/service_name">
|
||||
|
||||
<intent-filter>
|
||||
<!-- Here we identify that we are a RecognitionService by specifying that
|
||||
we satisfy RecognitionService's interface intent.
|
||||
|
||||
The constant value is defined at RecognitionService.SERVICE_INTERFACE. -->
|
||||
<action android:name="android.speech.RecognitionService" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- This points to a metadata xml file that contains information about this
|
||||
RecognitionService - specifically, the name of the settings activity to
|
||||
expose in system settings.
|
||||
|
||||
The constant value is defined at RecognitionService.SERVICE_META_DATA. -->
|
||||
<meta-data android:name="android.speech" android:resource="@xml/recognizer" />
|
||||
|
||||
</service>
|
||||
|
||||
<!-- The settings activity for this sample voice recognizer. -->
|
||||
<activity android:name=".VoiceRecognitionSettings"
|
||||
android:label="@string/settings_name"
|
||||
android:exported="true" />
|
||||
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,29 @@
|
|||
<p>A sample application that demonstrates Android's pluggable voice recognition framework.</p>
|
||||
|
||||
<p>This application includes a
|
||||
<a href="src/com/example/android/voicerecognitionservice/VoiceRecognitionService.html">
|
||||
sample voice recognition service</a> (a subclass of
|
||||
<code><a href="../../../reference/android/speech/RecognitionService.html">RecognitionService</a></code>),
|
||||
and a <a href="src/com/example/android/voicerecognitionservice/VoiceRecognitionSettings.html">
|
||||
settings activity</a> for that service. It shows the basic skeleton for setting up a recognition
|
||||
service and exposing its settings activity to settings.</p>
|
||||
|
||||
<p>The behavior is extremely simple - it does no real voice recognition, and just returns a
|
||||
fixed set of results immediately. The results can be either a set of letters or numbers, as
|
||||
chosen by the user in the simplistic settings activity.</p>
|
||||
|
||||
<p>Installing this application onto a device that already has a voice recognition service
|
||||
available will expose a new option under "voice input & output" settings, to let the
|
||||
user choose between the multiple services.</p>
|
||||
|
||||
<p>Note that due to its simplicity, this voice recognition service is not compatible with
|
||||
every application that wishes to use voice recognition. For example, because Google's
|
||||
VoiceSearch application relies on more than just simple text results, it may not work
|
||||
as expected if this sample recognition service is chosen in settings. Other simpler
|
||||
applications, like voice input on the keyboard (e.g., in LatinIME), are more likely to
|
||||
work as expected - returning just the very simple list of results to the application.</p>
|
||||
|
||||
<p>See also:</p>
|
||||
<ul>
|
||||
<li><a href="../../../reference/android/speech/RecognitionService.html">RecognitionService</a></li>
|
||||
</ul>
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
** Copyright 2010, The Android Open Source Project
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
-->
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
|
||||
<!-- The name for the recognizer - to be shown in system settings. -->
|
||||
<string name="service_name">Sample Recognizer</string>
|
||||
|
||||
<!-- The name of the settings activity. -->
|
||||
<string name="settings_name">Voice Recognition Settings</string>
|
||||
|
||||
<!-- The title of the preference for the type of results to return (letters or numbers). -->
|
||||
<string name="results_type_title">Results type</string>
|
||||
|
||||
<!-- The entry names of the preference for the type of results to return
|
||||
(letters or numbers). -->
|
||||
<string-array name="results_type_entries">
|
||||
<item>Letters</item>
|
||||
<item>Numbers</item>
|
||||
</string-array>
|
||||
|
||||
<!-- The entry values of the preference for the type of results to return
|
||||
(letters or numbers). -->
|
||||
<string-array name="results_type_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
|
||||
<!-- The default value of the preference for the type of results to return
|
||||
(letters or numbers). -->
|
||||
<string name="results_type_default_value">0</string>
|
||||
|
||||
</resources>
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010, The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/settings_name">
|
||||
|
||||
<!-- This setting lets you choose what kind of fake results you get from
|
||||
this sample recognizer. If you choose "letters", you'll get letters
|
||||
like "a", "b", "c" in the list of results. If you choose "numbers",
|
||||
you'll get numbers like "1", "2", "3" in the list of results. -->
|
||||
<ListPreference
|
||||
android:key="results_type"
|
||||
android:title="@string/results_type_title"
|
||||
android:entries="@array/results_type_entries"
|
||||
android:entryValues="@array/results_type_values"
|
||||
android:dialogTitle="@string/results_type_title"
|
||||
android:defaultValue="@string/results_type_default_value"
|
||||
/>
|
||||
|
||||
</PreferenceScreen>
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright (c) 2010, The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<!-- The attributes in this XML file provide configuration information
|
||||
for the sample voice recognizer. -->
|
||||
|
||||
<recognition-service xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:settingsActivity="com.example.android.voicerecognitionservice.VoiceRecognitionSettings"
|
||||
/>
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* 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.example.android.voicerecognitionservice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.speech.SpeechRecognizer;
|
||||
import android.speech.RecognitionService;
|
||||
|
||||
/**
|
||||
* A sample implementation of a {@link RecognitionService}. This very simple implementation does
|
||||
* no actual voice recognition. It just immediately returns fake recognition results.
|
||||
* Depending on the setting chosen in {@link VoiceRecognitionSettings}, it either returns a
|
||||
* list of letters ("a", "b", "c"), or a list of numbers ("1", "2", "3").
|
||||
*/
|
||||
public class VoiceRecognitionService extends RecognitionService {
|
||||
|
||||
@Override
|
||||
protected void onCancel(Callback listener) {
|
||||
// A real recognizer would do something to shut down recognition here.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartListening(Intent recognizerIntent, Callback listener) {
|
||||
// A real recognizer would probably utilize a lot of the other listener callback
|
||||
// methods. But we'll just skip all that and pretend we've got a result.
|
||||
ArrayList<String> results = new ArrayList<String>();
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences(
|
||||
VoiceRecognitionSettings.SHARED_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
String resultType = prefs.getString(
|
||||
VoiceRecognitionSettings.PREF_KEY_RESULTS_TYPE,
|
||||
String.valueOf(VoiceRecognitionSettings.RESULT_TYPE_LETTERS));
|
||||
int resultTypeInt = Integer.parseInt(resultType);
|
||||
|
||||
if (resultTypeInt == VoiceRecognitionSettings.RESULT_TYPE_LETTERS) {
|
||||
results.add("a");
|
||||
results.add("b");
|
||||
results.add("c");
|
||||
} else if (resultTypeInt == VoiceRecognitionSettings.RESULT_TYPE_NUMBERS) {
|
||||
results.add("1");
|
||||
results.add("2");
|
||||
results.add("3");
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION, results);
|
||||
|
||||
try {
|
||||
listener.results(bundle);
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopListening(Callback listener) {
|
||||
// Not implemented - in this sample we assume recognition would be endpointed
|
||||
// automatically, though certain applications may wish to expose an affordance
|
||||
// for stopping recording manually.
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* 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.example.android.voicerecognitionservice;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
|
||||
/**
|
||||
* A settings activity for the sample voice recognizer.
|
||||
*/
|
||||
public class VoiceRecognitionSettings extends PreferenceActivity {
|
||||
|
||||
// The name of the SharedPreferences file we'll store preferences in.
|
||||
public static final String SHARED_PREFERENCES_NAME = "VoiceRecognitionService";
|
||||
|
||||
// The key to the preference for the type of results to show (letters or numbers).
|
||||
// Identical to the value specified in res/values/strings.xml.
|
||||
public static final String PREF_KEY_RESULTS_TYPE = "results_type";
|
||||
|
||||
// The values of the preferences for the type of results to show (letters or numbers).
|
||||
// Identical to the values specified in res/values/strings.xml.
|
||||
public static final int RESULT_TYPE_LETTERS = 0;
|
||||
public static final int RESULT_TYPE_NUMBERS = 1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getPreferenceManager().setSharedPreferencesName(SHARED_PREFERENCES_NAME);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue