/tts/src/com/google/tts/TTSVersionAlert.java

http://eyes-free.googlecode.com/ · Java · 92 lines · 47 code · 10 blank · 35 comment · 9 complexity · e88f8b8ba7b91272471fd5c5f9ceed52 MD5 · raw file

  1. /*
  2. * Copyright (C) 2008 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.tts;
  17. import android.app.Activity;
  18. import android.app.AlertDialog.Builder;
  19. import android.content.Context;
  20. import android.content.DialogInterface;
  21. import android.content.DialogInterface.OnClickListener;
  22. import android.content.Intent;
  23. import android.net.Uri;
  24. /**
  25. * Creates an alert message that gives the user the option to install the
  26. * missing TTS that is needed through the Android Market.
  27. *
  28. * @author clchen@google.com (Charles L. Chen)
  29. */
  30. public class TTSVersionAlert extends Builder {
  31. // These strings must be in the Java file itself in order for this to be
  32. // packed into a .jar file.
  33. private final static String NO_TTS =
  34. "This application can talk using the text-to-speech (TTS) library. Please install the TTS.";
  35. private final static String MARKET_URI = "market://search?q=pname:com.google.tts";
  36. private final static String INSTALL_TTS = "Install the TTS";
  37. private final static String QUIT = "Do not install the TTS";
  38. private Activity parent;
  39. /**
  40. * The constructor for the TTSVersionAlert.
  41. *
  42. * @param context The context
  43. * @param noTTSMessage The String that should be shown to users to prompt them
  44. * to install the TTS. If null, the default string will be used.
  45. * @param installButtonMessage The String that should be used for the
  46. * "Install the TTS" button. If null, the default string will be used.
  47. * @param quitButtonMessage The String that should be used for the
  48. * "Do not install the TTS" button. If null, the default string will be
  49. * used.
  50. */
  51. public TTSVersionAlert(Context context, String noTTSMessage, String installButtonMessage,
  52. String quitButtonMessage) {
  53. super(context);
  54. parent = (Activity) context;
  55. if (noTTSMessage != null) {
  56. setMessage(noTTSMessage);
  57. } else {
  58. setMessage(NO_TTS);
  59. }
  60. OnClickListener installListener = new OnClickListener() {
  61. public void onClick(DialogInterface dialog, int which) {
  62. Uri marketUri = Uri.parse(MARKET_URI);
  63. Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
  64. parent.startActivity(marketIntent);
  65. }
  66. };
  67. OnClickListener quitListener = new OnClickListener() {
  68. public void onClick(DialogInterface dialog, int which) {
  69. }
  70. };
  71. if (installButtonMessage != null) {
  72. setPositiveButton(installButtonMessage, installListener);
  73. } else {
  74. setPositiveButton(INSTALL_TTS, installListener);
  75. }
  76. if (quitButtonMessage != null) {
  77. setNegativeButton(quitButtonMessage, quitListener);
  78. } else {
  79. setNegativeButton(QUIT, quitListener);
  80. }
  81. }
  82. }