PageRenderTime 34ms CodeModel.GetById 16ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
16package com.google.tts;
17
18import android.app.Activity;
19import android.app.AlertDialog.Builder;
20import android.content.Context;
21import android.content.DialogInterface;
22import android.content.DialogInterface.OnClickListener;
23import android.content.Intent;
24import android.net.Uri;
25
26/**
27 * Creates an alert message that gives the user the option to install the
28 * missing TTS that is needed through the Android Market.
29 * 
30 * @author clchen@google.com (Charles L. Chen)
31 */
32public class TTSVersionAlert extends Builder {
33  // These strings must be in the Java file itself in order for this to be
34  // packed into a .jar file.
35  private final static String NO_TTS =
36      "This application can talk using the text-to-speech (TTS) library. Please install the TTS.";
37  private final static String MARKET_URI = "market://search?q=pname:com.google.tts";
38  private final static String INSTALL_TTS = "Install the TTS";
39  private final static String QUIT = "Do not install the TTS";
40
41  private Activity parent;
42
43  /**
44   * The constructor for the TTSVersionAlert.
45   * 
46   * @param context The context
47   * @param noTTSMessage The String that should be shown to users to prompt them
48   *        to install the TTS. If null, the default string will be used.
49   * @param installButtonMessage The String that should be used for the
50   *        "Install the TTS" button. If null, the default string will be used.
51   * @param quitButtonMessage The String that should be used for the
52   *        "Do not install the TTS" button. If null, the default string will be
53   *        used.
54   */
55  public TTSVersionAlert(Context context, String noTTSMessage, String installButtonMessage,
56      String quitButtonMessage) {
57    super(context);
58    parent = (Activity) context;
59    if (noTTSMessage != null) {
60      setMessage(noTTSMessage);
61    } else {
62      setMessage(NO_TTS);
63    }
64
65
66    OnClickListener installListener = new OnClickListener() {
67      public void onClick(DialogInterface dialog, int which) {
68        Uri marketUri = Uri.parse(MARKET_URI);
69        Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
70        parent.startActivity(marketIntent);
71      }
72    };
73
74    OnClickListener quitListener = new OnClickListener() {
75      public void onClick(DialogInterface dialog, int which) {
76
77      }
78    };
79
80    if (installButtonMessage != null) {
81      setPositiveButton(installButtonMessage, installListener);
82    } else {
83      setPositiveButton(INSTALL_TTS, installListener);
84    }
85    if (quitButtonMessage != null) {
86      setNegativeButton(quitButtonMessage, quitListener);
87    } else {
88      setNegativeButton(QUIT, quitListener);
89    }
90  }
91
92}