Merge TTS support library into android-support-v4

v4 is the lowest API that exposes TextToSpeech, so it makes sense
to drop the TTS support library into the existing android-support-v4.

I've added a new helper sub-library named android-support-v4-donut (API level 4).
It contains all the public classes and interfaces needed by the new TTS API
support. Thanks to that library, all later helper sub-libraries can directly
use those classes and interfaces - it makes the implementation significantly
simpler.

Change-Id: Idd03a8ad85e256007874e611c464f378e7a29c15
diff --git a/tests/Android.mk b/tests/Android.mk
index b14ca93..7bd3b00 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -5,7 +5,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, java)
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
+LOCAL_STATIC_JAVA_LIBRARIES := mockito-target android-support-v4
 LOCAL_JAVA_LIBRARIES := android.test.runner
 LOCAL_PACKAGE_NAME := AndroidSupportTests
 
diff --git a/v8/tts/tests/java/android/support/v8/speech/tts/TTSImplementationV1Test.java b/tests/java/android/support/v4/speech/tts/TTSImplementationV1Test.java
similarity index 97%
rename from v8/tts/tests/java/android/support/v8/speech/tts/TTSImplementationV1Test.java
rename to tests/java/android/support/v4/speech/tts/TTSImplementationV1Test.java
index 840ae14..f006042 100644
--- a/v8/tts/tests/java/android/support/v8/speech/tts/TTSImplementationV1Test.java
+++ b/tests/java/android/support/v4/speech/tts/TTSImplementationV1Test.java
@@ -14,14 +14,14 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.speech.tts.TextToSpeech;
 import android.speech.tts.UtteranceProgressListener;
-import android.support.v8.speech.tts.TextToSpeechClient.ConnectionCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.EngineStatus;
-import android.support.v8.speech.tts.TextToSpeechClient.RequestCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.UtteranceId;
+import android.support.v4.speech.tts.TextToSpeechClient.ConnectionCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.EngineStatus;
+import android.support.v4.speech.tts.TextToSpeechClient.RequestCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.UtteranceId;
 import android.test.InstrumentationTestCase;
 
 import org.mockito.ArgumentCaptor;
@@ -439,4 +439,3 @@
     }
 
 }
-
diff --git a/v8/tts/tests/java/android/support/v8/speech/tts/TTSImplementationV2Test.java b/tests/java/android/support/v4/speech/tts/TTSImplementationV2Test.java
similarity index 97%
rename from v8/tts/tests/java/android/support/v8/speech/tts/TTSImplementationV2Test.java
rename to tests/java/android/support/v4/speech/tts/TTSImplementationV2Test.java
index bcb2555..26e8dfd 100644
--- a/v8/tts/tests/java/android/support/v8/speech/tts/TTSImplementationV2Test.java
+++ b/tests/java/android/support/v4/speech/tts/TTSImplementationV2Test.java
@@ -14,14 +14,14 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.content.Context;
 import android.os.Bundle;
 import android.speech.tts.TextToSpeech;
-import android.support.v8.speech.tts.TextToSpeechClient.ConnectionCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.RequestCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.UtteranceId;
+import android.support.v4.speech.tts.TextToSpeechClient.ConnectionCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.RequestCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.UtteranceId;
 import android.test.InstrumentationTestCase;
 
 import org.mockito.ArgumentCaptor;
diff --git a/v4/Android.mk b/v4/Android.mk
index 526a1c6..148fd9d 100644
--- a/v4/Android.mk
+++ b/v4/Android.mk
@@ -14,11 +14,21 @@
 
 LOCAL_PATH := $(call my-dir)
 
+# A helper sub-library that makes direct use of Donut APIs.
+include $(CLEAR_VARS)
+LOCAL_MODULE := android-support-v4-donut
+LOCAL_SDK_VERSION := 4
+LOCAL_SRC_FILES := $(call all-java-files-under, donut)
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+# -----------------------------------------------------------------------
+
 # A helper sub-library that makes direct use of Eclair APIs.
 include $(CLEAR_VARS)
 LOCAL_MODULE := android-support-v4-eclair
 LOCAL_SDK_VERSION := 5
 LOCAL_SRC_FILES := $(call all-java-files-under, eclair)
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4-donut
 include $(BUILD_STATIC_JAVA_LIBRARY)
 
 # -----------------------------------------------------------------------
diff --git a/v8/tts/src/android/support/v8/speech/tts/TTSImplementationV2.java b/v4/api20/android/support/v4/speech/tts/TTSImplementationV2.java
similarity index 95%
rename from v8/tts/src/android/support/v8/speech/tts/TTSImplementationV2.java
rename to v4/api20/android/support/v4/speech/tts/TTSImplementationV2.java
index 2608fa6..e7f9b6e 100644
--- a/v8/tts/src/android/support/v8/speech/tts/TTSImplementationV2.java
+++ b/v4/api20/android/support/v4/speech/tts/TTSImplementationV2.java
@@ -14,14 +14,14 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.content.Context;
 import android.net.Uri;
-import android.support.v8.speech.tts.TextToSpeechClient.ConnectionCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.EngineStatus;
-import android.support.v8.speech.tts.TextToSpeechClient.RequestCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.UtteranceId;
+import android.support.v4.speech.tts.TextToSpeechClient.ConnectionCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.EngineStatus;
+import android.support.v4.speech.tts.TextToSpeechClient.RequestCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.UtteranceId;
 import android.util.Log;
 
 import java.io.File;
@@ -29,7 +29,7 @@
 
 /** Simple bridge to the actual TTS V2 implementation. */
 class TTSImplementationV2 implements ITextToSpeechClient {
-    private static final String TAG = "android.support.v8.speech.tts";
+    private static final String TAG = "android.support.v4.speech.tts";
 
     interface TextToSpeechClientConstructor {
         public android.speech.tts.TextToSpeechClient newClient(
diff --git a/v8/tts/src/android/support/v8/speech/tts/ITextToSpeechClient.java b/v4/donut/android/support/v4/speech/tts/ITextToSpeechClient.java
similarity index 84%
rename from v8/tts/src/android/support/v8/speech/tts/ITextToSpeechClient.java
rename to v4/donut/android/support/v4/speech/tts/ITextToSpeechClient.java
index cf6a9c1..051f101 100644
--- a/v8/tts/src/android/support/v8/speech/tts/ITextToSpeechClient.java
+++ b/v4/donut/android/support/v4/speech/tts/ITextToSpeechClient.java
@@ -14,14 +14,14 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.content.Context;
 import android.net.Uri;
-import android.support.v8.speech.tts.TextToSpeechClient.ConnectionCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.EngineStatus;
-import android.support.v8.speech.tts.TextToSpeechClient.RequestCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.UtteranceId;
+import android.support.v4.speech.tts.TextToSpeechClient.ConnectionCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.EngineStatus;
+import android.support.v4.speech.tts.TextToSpeechClient.RequestCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.UtteranceId;
 
 import java.io.File;
 
diff --git a/v8/tts/src/android/support/v8/speech/tts/RequestConfig.java b/v4/donut/android/support/v4/speech/tts/RequestConfig.java
similarity index 99%
rename from v8/tts/src/android/support/v8/speech/tts/RequestConfig.java
rename to v4/donut/android/support/v4/speech/tts/RequestConfig.java
index 784abfe..9b3e78c 100644
--- a/v8/tts/src/android/support/v8/speech/tts/RequestConfig.java
+++ b/v4/donut/android/support/v4/speech/tts/RequestConfig.java
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.media.AudioManager;
 import android.os.Bundle;
diff --git a/v8/tts/src/android/support/v8/speech/tts/RequestConfigHelper.java b/v4/donut/android/support/v4/speech/tts/RequestConfigHelper.java
similarity index 89%
rename from v8/tts/src/android/support/v8/speech/tts/RequestConfigHelper.java
rename to v4/donut/android/support/v4/speech/tts/RequestConfigHelper.java
index 54c8532..4385bda 100644
--- a/v8/tts/src/android/support/v8/speech/tts/RequestConfigHelper.java
+++ b/v4/donut/android/support/v4/speech/tts/RequestConfigHelper.java
@@ -1,6 +1,22 @@
-package android.support.v8.speech.tts;
+/*
+ * Copyright (C) 2014 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.
+ */
 
-import android.support.v8.speech.tts.TextToSpeechClient.EngineStatus;
+package android.support.v4.speech.tts;
+
+import android.support.v4.speech.tts.TextToSpeechClient.EngineStatus;
 
 import java.util.Locale;
 
diff --git a/v8/tts/src/android/support/v8/speech/tts/TextToSpeechClient.java b/v4/donut/android/support/v4/speech/tts/TextToSpeechClient.java
similarity index 89%
rename from v8/tts/src/android/support/v8/speech/tts/TextToSpeechClient.java
rename to v4/donut/android/support/v4/speech/tts/TextToSpeechClient.java
index 13ac1fa..ac8351e 100644
--- a/v8/tts/src/android/support/v8/speech/tts/TextToSpeechClient.java
+++ b/v4/donut/android/support/v4/speech/tts/TextToSpeechClient.java
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.content.Context;
 import android.net.Uri;
@@ -367,55 +367,6 @@
 
     private final ITextToSpeechClient mImplementation;
 
-    /**
-     * Create TextToSpeech service client.
-     *
-     * Will connect to the default TTS service. In order to be usable, {@link #connect()} need
-     * to be called first and successful connection callback need to be received.
-     *
-     * @param context
-     *            The context this instance is running in.
-     * @param engine
-     *            Package name of requested TTS engine. If it's null, then default engine will
-     *            be selected regardless of {@code fallbackToDefaultEngine} parameter value.
-     * @param fallbackToDefaultEngine
-     *            If requested engine is not available, should we fallback to the default engine?
-     * @param defaultRequestCallbacks
-     *            Default request callbacks, it will be used for all synthesis requests without
-     *            supplied RequestCallbacks instance. Can't be null.
-     * @param connectionCallbacks
-     *            Callbacks for connecting and disconnecting from the service. Can't be null.
-     */
-    public TextToSpeechClient(Context context,
-            String engine, boolean fallbackToDefaultEngine,
-            RequestCallbacks defaultRequestCallbacks,
-            ConnectionCallbacks connectionCallbacks) {
-        if (Build.VERSION.CODENAME.equals("L")) {
-            mImplementation = new TTSImplementationV2();
-        } else {
-            mImplementation = new TTSImplementationV1();
-        }
-        mImplementation.setup(context, engine, fallbackToDefaultEngine, defaultRequestCallbacks,
-                connectionCallbacks);
-    }
-
-    /**
-     * Create TextToSpeech service client. Will connect to the default TTS
-     * service. In order to be usable, {@link #connect()} need to be called
-     * first and successful connection callback need to be received.
-     *
-     * @param context Context this instance is running in.
-     * @param defaultRequestCallbacks Default request callbacks, it
-     *            will be used for all synthesis requests without supplied
-     *            RequestCallbacks instance. Can't be null.
-     * @param connectionCallbacks Callbacks for connecting and disconnecting
-     *            from the service. Can't be null.
-     */
-    public TextToSpeechClient(Context context, RequestCallbacks defaultRequestCallbacks,
-            ConnectionCallbacks connectionCallbacks) {
-        this(context, null, true, defaultRequestCallbacks, connectionCallbacks);
-    }
-
     TextToSpeechClient(ITextToSpeechClient implementation,
             Context context, String engine, boolean fallbackToDefaultEngine,
             RequestCallbacks defaultRequestCallbacks,
diff --git a/v8/tts/src/android/support/v8/speech/tts/VoiceInfo.java b/v4/donut/android/support/v4/speech/tts/VoiceInfo.java
similarity index 99%
rename from v8/tts/src/android/support/v8/speech/tts/VoiceInfo.java
rename to v4/donut/android/support/v4/speech/tts/VoiceInfo.java
index a7eed1e..6269744 100644
--- a/v8/tts/src/android/support/v8/speech/tts/VoiceInfo.java
+++ b/v4/donut/android/support/v4/speech/tts/VoiceInfo.java
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.os.Bundle;
 import android.os.Parcel;
diff --git a/v8/tts/ics-mr1/android/support/v8/speech/tts/TextToSpeechICSMR1.java b/v4/ics-mr1/android/support/v4/speech/tts/TextToSpeechICSMR1.java
similarity index 92%
rename from v8/tts/ics-mr1/android/support/v8/speech/tts/TextToSpeechICSMR1.java
rename to v4/ics-mr1/android/support/v4/speech/tts/TextToSpeechICSMR1.java
index ef795f2..bbad4c1 100644
--- a/v8/tts/ics-mr1/android/support/v8/speech/tts/TextToSpeechICSMR1.java
+++ b/v4/ics-mr1/android/support/v4/speech/tts/TextToSpeechICSMR1.java
@@ -1,4 +1,4 @@
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.speech.tts.TextToSpeech;
 import android.speech.tts.UtteranceProgressListener;
@@ -9,7 +9,6 @@
 
 /** Helper class for TTS functionality introduced in ICS MR1 */
 class TextToSpeechICSMR1 {
-
     /**
      * Call {@link TextToSpeech#getFeatures} if available.
      *
@@ -23,6 +22,9 @@
         return null;
     }
 
+    public static final String KEY_FEATURE_EMBEDDED_SYNTHESIS = "embeddedTts";
+    public static final String KEY_FEATURE_NETWORK_SYNTHESIS = "networkTts";
+
     static interface UtteranceProgressListenerICSMR1 {
         void onDone(String utteranceId);
         void onError(String utteranceId);
diff --git a/v8/tts/ics/android/support/v8/speech/tts/TextToSpeechICS.java b/v4/ics/android/support/v4/speech/tts/TextToSpeechICS.java
similarity index 88%
rename from v8/tts/ics/android/support/v8/speech/tts/TextToSpeechICS.java
rename to v4/ics/android/support/v4/speech/tts/TextToSpeechICS.java
index b557c41..4e0c041 100644
--- a/v8/tts/ics/android/support/v8/speech/tts/TextToSpeechICS.java
+++ b/v4/ics/android/support/v4/speech/tts/TextToSpeechICS.java
@@ -1,4 +1,4 @@
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.content.Context;
 import android.os.Build;
@@ -8,7 +8,7 @@
 
 /** Helper class for TTS functionality introduced in ICS */
 class TextToSpeechICS {
-    private static final String TAG = "android.support.v8.speech.tts";
+    private static final String TAG = "android.support.v4.speech.tts";
 
     static TextToSpeech construct(Context context, OnInitListener onInitListener,
             String engineName) {
diff --git a/v8/tts/src/android/support/v8/speech/tts/TTSImplementationV1.java b/v4/java/android/support/v4/speech/tts/TTSImplementationV1.java
similarity index 94%
rename from v8/tts/src/android/support/v8/speech/tts/TTSImplementationV1.java
rename to v4/java/android/support/v4/speech/tts/TTSImplementationV1.java
index cf03537..434f7a3 100644
--- a/v8/tts/src/android/support/v8/speech/tts/TTSImplementationV1.java
+++ b/v4/java/android/support/v4/speech/tts/TTSImplementationV1.java
@@ -14,23 +14,22 @@
  * the License.
  */
 
-package android.support.v8.speech.tts;
+package android.support.v4.speech.tts;
 
 import android.content.Context;
 import android.net.Uri;
 import android.os.Bundle;
 import android.provider.Settings;
 import android.speech.tts.TextToSpeech;
-import android.speech.tts.TtsEngines;
 import android.speech.tts.TextToSpeech.Engine;
 import android.speech.tts.TextToSpeech.OnInitListener;
 import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
-import android.support.v8.speech.tts.TextToSpeechClient.ConnectionCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.EngineStatus;
-import android.support.v8.speech.tts.TextToSpeechClient.RequestCallbacks;
-import android.support.v8.speech.tts.TextToSpeechClient.Status;
-import android.support.v8.speech.tts.TextToSpeechClient.UtteranceId;
-import android.support.v8.speech.tts.TextToSpeechICSMR1.UtteranceProgressListenerICSMR1;
+import android.support.v4.speech.tts.TextToSpeechClient.ConnectionCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.EngineStatus;
+import android.support.v4.speech.tts.TextToSpeechClient.RequestCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.Status;
+import android.support.v4.speech.tts.TextToSpeechClient.UtteranceId;
+import android.support.v4.speech.tts.TextToSpeechICSMR1.UtteranceProgressListenerICSMR1;
 import android.util.Log;
 
 import java.io.File;
@@ -44,7 +43,7 @@
  * Implementation of the TTS V2 API using V1 API.
  */
 class TTSImplementationV1 implements ITextToSpeechClient {
-    private static final String TAG = "android.support.v8.speech.tts";
+    private static final String TAG = "android.support.v4.speech.tts";
     private TextToSpeech mOldClient;
     private Context mContext;
     private String mEngine;
@@ -229,7 +228,8 @@
     private EngineStatus generateEngineStatus() {
         Bundle defaultParams = new Bundle();
         defaultParams.putFloat(TextToSpeechClient.Params.SPEECH_PITCH, 1.0f);
-        defaultParams.putFloat(TextToSpeechClient.Params.SPEECH_SPEED, -1.0f);
+        // Zero value will make it use system default
+        defaultParams.putFloat(TextToSpeechClient.Params.SPEECH_SPEED, 0.0f);
 
         // Enumerate all locales and check if they are available
         ArrayList<VoiceInfo> voicesInfo = new ArrayList<VoiceInfo>();
@@ -245,7 +245,7 @@
             try {
                 // Call those to prevent log spam from isLanguageAvailable.
                 locale.getISO3Language();
-                if (!locale.getCountry().isEmpty()) {
+                if (locale.getCountry() != null && locale.getCountry().length() > 0) {
                     locale.getISO3Country();
                 }
                 if (mOldClient.isLanguageAvailable(locale) != expectedStatus) {
@@ -333,14 +333,15 @@
 
         int voiceType = VoiceInfoPrivate.getVoiceType(config.getVoice());
         if (voiceType == VoiceInfoPrivate.VOICE_TYPE_NETWORK) {
-            parameters.put(TextToSpeech.Engine.KEY_FEATURE_NETWORK_SYNTHESIS,
+            parameters.put(TextToSpeechICSMR1.KEY_FEATURE_NETWORK_SYNTHESIS,
                     "true");
         } else if (voiceType == VoiceInfoPrivate.VOICE_TYPE_EMBEDDED) {
-            parameters.put(TextToSpeech.Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS,
+            parameters.put(TextToSpeechICSMR1.KEY_FEATURE_EMBEDDED_SYNTHESIS,
                     "true");
         }
         return parameters;
     }
+
     @Override
     public void queueSpeak(final String utterance, final UtteranceId utteranceId,
             final RequestConfig config, final RequestCallbacks callbacks) {
@@ -451,7 +452,7 @@
 
     /** Read default speech speed rate from settings */
     float getDefaultSpeechRate() {
-        return getSecureSettingInt(Settings.Secure.TTS_DEFAULT_RATE, Engine.DEFAULT_RATE) / 100.0f;
+        return getSecureSettingInt(Settings.Secure.TTS_DEFAULT_RATE, 100) / 100.0f;
     }
 
     int getSecureSettingInt(String name, int defaultValue) {
diff --git a/v4/java/android/support/v4/speech/tts/TextToSpeechClientCompat.java b/v4/java/android/support/v4/speech/tts/TextToSpeechClientCompat.java
new file mode 100644
index 0000000..7cc0e31
--- /dev/null
+++ b/v4/java/android/support/v4/speech/tts/TextToSpeechClientCompat.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2014 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 android.support.v4.speech.tts;
+
+import android.content.Context;
+import android.os.Build;
+import android.support.v4.speech.tts.TextToSpeechClient.ConnectionCallbacks;
+import android.support.v4.speech.tts.TextToSpeechClient.RequestCallbacks;
+
+/**
+ * Helper for accessing features in {@link android.speech.tts.TextToSpeechClient}
+ * introduced in API level 20 in a backwards compatible fashion.
+ */
+public class TextToSpeechClientCompat {
+    /**
+     * Create TextToSpeech service client.
+     *
+     * Will connect to the default TTS service. In order to be usable, {@link #connect()} need
+     * to be called first and successful connection callback need to be received.
+     *
+     * @param context
+     *            The context this instance is running in.
+     * @param engine
+     *            Package name of requested TTS engine. If it's null, then default engine will
+     *            be selected regardless of {@code fallbackToDefaultEngine} parameter value.
+     * @param fallbackToDefaultEngine
+     *            If requested engine is not available, should we fallback to the default engine?
+     * @param defaultRequestCallbacks
+     *            Default request callbacks, it will be used for all synthesis requests without
+     *            supplied RequestCallbacks instance. Can't be null.
+     * @param connectionCallbacks
+     *            Callbacks for connecting and disconnecting from the service. Can't be null.
+     */
+    public static TextToSpeechClient createTextToSpeechClient(Context context,
+            String engine, boolean fallbackToDefaultEngine,
+            RequestCallbacks defaultRequestCallbacks,
+            ConnectionCallbacks connectionCallbacks) {
+        ITextToSpeechClient implementation;
+        if (Build.VERSION.CODENAME.equals("L")) {
+            implementation = new TTSImplementationV2();
+        } else {
+            implementation = new TTSImplementationV1();
+        }
+        return new TextToSpeechClient(implementation, context, engine, fallbackToDefaultEngine,
+                defaultRequestCallbacks, connectionCallbacks);
+    }
+
+    /**
+     * Create TextToSpeech service client. Will connect to the default TTS
+     * service. In order to be usable, {@link #connect()} need to be called
+     * first and successful connection callback need to be received.
+     *
+     * @param context Context this instance is running in.
+     * @param defaultRequestCallbacks Default request callbacks, it
+     *            will be used for all synthesis requests without supplied
+     *            RequestCallbacks instance. Can't be null.
+     * @param connectionCallbacks Callbacks for connecting and disconnecting
+     *            from the service. Can't be null.
+     */
+    public static TextToSpeechClient createTextToSpeechClient(Context context,
+            RequestCallbacks defaultRequestCallbacks, ConnectionCallbacks connectionCallbacks) {
+        return createTextToSpeechClient(context, null, true, defaultRequestCallbacks,
+                connectionCallbacks);
+    }
+
+}
diff --git a/v8/tts/Android.mk b/v8/tts/Android.mk
deleted file mode 100644
index 0e60af6..0000000
--- a/v8/tts/Android.mk
+++ /dev/null
@@ -1,41 +0,0 @@
-# Copyright (C) 2013 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-# -----------------------------------------------------------------------
-
-# A helper sub-library that makes direct use of Ice Cream Sandwich APIs.
-include $(CLEAR_VARS)
-LOCAL_MODULE := android-support-tts-ics
-LOCAL_SDK_VERSION := 14
-LOCAL_SRC_FILES := $(call all-java-files-under, ics)
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-# A helper sub-library that makes direct use of Ice Cream Sandwich MR1 APIs.
-include $(CLEAR_VARS)
-LOCAL_MODULE := android-support-tts-ics-mr1
-LOCAL_SDK_VERSION := 15
-LOCAL_SRC_FILES := $(call all-java-files-under, ics-mr1)
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := android-support-v8-tts
-#LOCAL_SDK_VERSION := 8
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-tts-ics-mr1 android-support-tts-ics
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-include $(LOCAL_PATH)/tests/Android.mk
diff --git a/v8/tts/AndroidManifest.xml b/v8/tts/AndroidManifest.xml
deleted file mode 100644
index 0f52756..0000000
--- a/v8/tts/AndroidManifest.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 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="android.support.v8.speech.tts">
-    <uses-sdk android:minSdkVersion="8"/>
-</manifest>
diff --git a/v8/tts/tests/Android.mk b/v8/tts/tests/Android.mk
deleted file mode 100644
index 9101d2f..0000000
--- a/v8/tts/tests/Android.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-java-files-under, java)
-#LOCAL_SDK_VERSION := cur
-LOCAL_STATIC_JAVA_LIBRARIES := mockito-target android-support-v8-tts
-LOCAL_JAVA_LIBRARIES := android.test.runner
-LOCAL_PACKAGE_NAME := android-support-v8-tts-tests
-
-include $(BUILD_PACKAGE)
diff --git a/v8/tts/tests/AndroidManifest.xml b/v8/tts/tests/AndroidManifest.xml
deleted file mode 100644
index 684db70..0000000
--- a/v8/tts/tests/AndroidManifest.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 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="android.support.v8.speech.tts">
-
-    <application>
-        <uses-library android:name="android.test.runner" />
-    </application>
-
-    <instrumentation
-        android:name="android.test.InstrumentationTestRunner"
-        android:targetPackage="android.support.v8.speech.tts" />
-</manifest>