OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.content.Context; | |
8 import android.os.Build; | 7 import android.os.Build; |
9 import android.speech.tts.TextToSpeech; | 8 import android.speech.tts.TextToSpeech; |
10 import android.speech.tts.UtteranceProgressListener; | 9 import android.speech.tts.UtteranceProgressListener; |
11 | 10 |
| 11 import org.chromium.base.ContextUtils; |
12 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
13 import org.chromium.base.TraceEvent; | 13 import org.chromium.base.TraceEvent; |
14 import org.chromium.base.annotations.CalledByNative; | 14 import org.chromium.base.annotations.CalledByNative; |
15 | 15 |
16 import java.util.ArrayList; | 16 import java.util.ArrayList; |
17 import java.util.HashMap; | 17 import java.util.HashMap; |
18 import java.util.Locale; | 18 import java.util.Locale; |
19 | 19 |
20 /** | 20 /** |
21 * This class is the Java counterpart to the C++ TtsPlatformImplAndroid class. | 21 * This class is the Java counterpart to the C++ TtsPlatformImplAndroid class. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 float mVolume; | 61 float mVolume; |
62 } | 62 } |
63 | 63 |
64 private long mNativeTtsPlatformImplAndroid; | 64 private long mNativeTtsPlatformImplAndroid; |
65 protected final TextToSpeech mTextToSpeech; | 65 protected final TextToSpeech mTextToSpeech; |
66 private boolean mInitialized; | 66 private boolean mInitialized; |
67 private ArrayList<TtsVoice> mVoices; | 67 private ArrayList<TtsVoice> mVoices; |
68 private String mCurrentLanguage; | 68 private String mCurrentLanguage; |
69 private PendingUtterance mPendingUtterance; | 69 private PendingUtterance mPendingUtterance; |
70 | 70 |
71 protected TtsPlatformImpl(long nativeTtsPlatformImplAndroid, Context context
) { | 71 protected TtsPlatformImpl(long nativeTtsPlatformImplAndroid) { |
72 mInitialized = false; | 72 mInitialized = false; |
73 mNativeTtsPlatformImplAndroid = nativeTtsPlatformImplAndroid; | 73 mNativeTtsPlatformImplAndroid = nativeTtsPlatformImplAndroid; |
74 mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListene
r() { | 74 mTextToSpeech = new TextToSpeech( |
75 @Override | 75 ContextUtils.getApplicationContext(), new TextToSpeech.OnInitLis
tener() { |
76 public void onInit(int status) { | 76 @Override |
77 if (status == TextToSpeech.SUCCESS) { | 77 public void onInit(int status) { |
78 ThreadUtils.runOnUiThread(new Runnable() { | 78 if (status == TextToSpeech.SUCCESS) { |
79 @Override | 79 ThreadUtils.runOnUiThread(new Runnable() { |
80 public void run() { | 80 @Override |
81 initialize(); | 81 public void run() { |
82 } | 82 initialize(); |
83 }); | 83 } |
| 84 }); |
| 85 } |
84 } | 86 } |
85 } | 87 }); |
86 }); | |
87 addOnUtteranceProgressListener(); | 88 addOnUtteranceProgressListener(); |
88 } | 89 } |
89 | 90 |
90 /** | 91 /** |
91 * Create a TtsPlatformImpl object, which is owned by TtsPlatformImplAndroid | 92 * Create a TtsPlatformImpl object, which is owned by TtsPlatformImplAndroid |
92 * on the C++ side. | 93 * on the C++ side. |
| 94 * @param nativeTtsPlatformImplAndroid The C++ object that owns us. |
93 * | 95 * |
94 * @param nativeTtsPlatformImplAndroid The C++ object that owns us. | |
95 * @param context The app context. | |
96 */ | 96 */ |
97 @CalledByNative | 97 @CalledByNative |
98 private static TtsPlatformImpl create(long nativeTtsPlatformImplAndroid, | 98 private static TtsPlatformImpl create(long nativeTtsPlatformImplAndroid) { |
99 Context context) { | |
100 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 99 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
101 return new LollipopTtsPlatformImpl(nativeTtsPlatformImplAndroid, con
text); | 100 return new LollipopTtsPlatformImpl(nativeTtsPlatformImplAndroid); |
102 } else { | 101 } else { |
103 return new TtsPlatformImpl(nativeTtsPlatformImplAndroid, context); | 102 return new TtsPlatformImpl(nativeTtsPlatformImplAndroid); |
104 } | 103 } |
105 } | 104 } |
106 | 105 |
107 /** | 106 /** |
108 * Called when our C++ counterpoint is deleted. Clear the handle to our | 107 * Called when our C++ counterpoint is deleted. Clear the handle to our |
109 * native C++ object, ensuring it's never called. | 108 * native C++ object, ensuring it's never called. |
110 */ | 109 */ |
111 @CalledByNative | 110 @CalledByNative |
112 private void destroy() { | 111 private void destroy() { |
113 mNativeTtsPlatformImplAndroid = 0; | 112 mNativeTtsPlatformImplAndroid = 0; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 if (mPendingUtterance != null) mPendingUtterance.speak(); | 317 if (mPendingUtterance != null) mPendingUtterance.speak(); |
319 | 318 |
320 TraceEvent.end("TtsPlatformImpl:initialize"); | 319 TraceEvent.end("TtsPlatformImpl:initialize"); |
321 } | 320 } |
322 | 321 |
323 private native void nativeVoicesChanged(long nativeTtsPlatformImplAndroid); | 322 private native void nativeVoicesChanged(long nativeTtsPlatformImplAndroid); |
324 private native void nativeOnEndEvent(long nativeTtsPlatformImplAndroid, int
utteranceId); | 323 private native void nativeOnEndEvent(long nativeTtsPlatformImplAndroid, int
utteranceId); |
325 private native void nativeOnStartEvent(long nativeTtsPlatformImplAndroid, in
t utteranceId); | 324 private native void nativeOnStartEvent(long nativeTtsPlatformImplAndroid, in
t utteranceId); |
326 private native void nativeOnErrorEvent(long nativeTtsPlatformImplAndroid, in
t utteranceId); | 325 private native void nativeOnErrorEvent(long nativeTtsPlatformImplAndroid, in
t utteranceId); |
327 } | 326 } |
OLD | NEW |