diff options
| author | 2012-09-11 13:23:44 -0700 | |
|---|---|---|
| committer | 2012-09-11 13:23:45 -0700 | |
| commit | faed98a161f58441ebce3dcb08cd8bf76a76da4e (patch) | |
| tree | c2d89d35cf90566fd437d00d602ebce559be43a2 | |
| parent | ea4f446a816ee1558c2776206642d0751fc2afb7 (diff) | |
| parent | b743a23fc5bce9965c1539c3c8611614424a5aff (diff) | |
Merge "Added annotations for injected accessibility objects" into jb-mr1-dev
| -rw-r--r-- | core/java/android/webkit/AccessibilityInjector.java | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/core/java/android/webkit/AccessibilityInjector.java b/core/java/android/webkit/AccessibilityInjector.java index fd73fdaa03e2..a51a8f67cc64 100644 --- a/core/java/android/webkit/AccessibilityInjector.java +++ b/core/java/android/webkit/AccessibilityInjector.java @@ -34,6 +34,7 @@ import org.json.JSONObject; import java.net.URI; import java.net.URISyntaxException; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -53,7 +54,7 @@ class AccessibilityInjector { private final WebView mWebView; // The Java objects that are exposed to JavaScript. - private TextToSpeech mTextToSpeech; + private TextToSpeechWrapper mTextToSpeech; private CallbackHandler mCallback; // Lazily loaded helper objects. @@ -367,10 +368,7 @@ class AccessibilityInjector { if (mTextToSpeech != null) { return; } - - final String pkgName = mContext.getPackageName(); - - mTextToSpeech = new TextToSpeech(mContext, null, null, pkgName + ".**webview**", true); + mTextToSpeech = new TextToSpeechWrapper(mContext); mWebView.addJavascriptInterface(mTextToSpeech, ALIAS_TTS_JS_INTERFACE); } @@ -526,6 +524,41 @@ class AccessibilityInjector { } /** + * Used to protect the TextToSpeech class, only exposing the methods we want to expose. + */ + private static class TextToSpeechWrapper { + private TextToSpeech mTextToSpeech; + + public TextToSpeechWrapper(Context context) { + final String pkgName = context.getPackageName(); + mTextToSpeech = new TextToSpeech(context, null, null, pkgName + ".**webview**", true); + } + + @JavascriptInterface + @SuppressWarnings("unused") + public boolean isSpeaking() { + return mTextToSpeech.isSpeaking(); + } + + @JavascriptInterface + @SuppressWarnings("unused") + public int speak(String text, int queueMode, HashMap<String, String> params) { + return mTextToSpeech.speak(text, queueMode, params); + } + + @JavascriptInterface + @SuppressWarnings("unused") + public int stop() { + return mTextToSpeech.stop(); + } + + @SuppressWarnings("unused") + protected void shutdown() { + mTextToSpeech.shutdown(); + } + } + + /** * Exposes result interface to JavaScript. */ private static class CallbackHandler { @@ -621,6 +654,7 @@ class AccessibilityInjector { * @param id The result id of the request as a {@link String}. * @param result The result of the request as a {@link String}. */ + @JavascriptInterface @SuppressWarnings("unused") public void onResult(String id, String result) { final long resultId; |