PageRenderTime 13ms CodeModel.GetById 7ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/config/src/com/google/marvin/config/CoreComponentsCheckActivity.java

http://eyes-free.googlecode.com/
Java | 104 lines | 75 code | 10 blank | 19 comment | 13 complexity | 8cc1491be2ef5de6724786262cd815dd MD5 | raw file
  1package com.google.marvin.config;
  2
  3import com.google.tts.ConfigurationManager;
  4import com.google.tts.TextToSpeechBeta;
  5import android.app.Activity;
  6import android.app.AlertDialog;
  7import android.app.AlertDialog.Builder;
  8import android.content.DialogInterface;
  9import android.content.Intent;
 10import android.content.DialogInterface.OnClickListener;
 11import android.os.Bundle;
 12
 13/**
 14 * Does a quick sanity check to make sure that critical core components (the TTS
 15 * and the Eyes-Free Shell) are both installed before starting the main config
 16 * screen.
 17 * 
 18 * @author clchen@google.com (Charles L. Chen)
 19 */
 20public class CoreComponentsCheckActivity extends Activity {
 21  private static final int ttsCheckCode = 42;
 22  private static final int shellCheckCode = 43;
 23  private static final String ttsPackageName = "com.google.tts";
 24  private static final String shellPackageName = "com.google.marvin.shell";
 25
 26  /** Called when the activity is first created. */
 27  @Override
 28  public void onCreate(Bundle savedInstanceState) {
 29    super.onCreate(savedInstanceState);
 30    // Do not proceed unless both the TTS and the Shell have been installed.
 31    if (checkTtsRequirements(this)) {
 32      if (checkShell(this)) {
 33        startConfig();
 34      }
 35    }
 36  }
 37
 38  @Override
 39  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 40    if (requestCode == ttsCheckCode) {
 41      //if (TTS.isInstalled(this)) {
 42        if (checkShell(this)) {
 43          startConfig();
 44        }
 45     // } else {
 46     //   displayMissingComponentError("Text-To-Speech Library");
 47     // }
 48    } else if (requestCode == shellCheckCode) {
 49      if (shellInstalled()) {
 50        startConfig();
 51      } else {
 52        displayMissingComponentError("Eyes-Free Shell");
 53      }
 54    } else {
 55      finish();
 56    }
 57  }
 58
 59  /** Checks to make sure that all the requirements for the TTS are there */
 60  private boolean checkTtsRequirements(Activity activity) {
 61   // if (!TTS.isInstalled(activity)) {
 62   //   activity.startActivityForResult(Utils.getMarketIntent(ttsPackageName), ttsCheckCode);
 63  //    return false;
 64  //  }
 65    if (!ConfigurationManager.allFilesExist()) {
 66      Intent intent =
 67          Utils.getAppStartIntent(this, ttsPackageName, "com.google.tts.ConfigurationManager");
 68      startActivityForResult(intent, ttsCheckCode);
 69      return false;
 70    }
 71    return true;
 72  }
 73
 74  /** Checks to make sure that the shell is there */
 75  private boolean checkShell(Activity activity) {
 76    if (!shellInstalled()) {
 77      activity.startActivityForResult(Utils.getMarketIntent(shellPackageName), shellCheckCode);
 78      return false;
 79    }
 80    return true;
 81  }
 82
 83  private boolean shellInstalled() {
 84    return Utils.applicationInstalled(this, shellPackageName);
 85  }
 86
 87  private void displayMissingComponentError(String component) {
 88    AlertDialog errorDialog = new Builder(this).create();
 89    errorDialog.setTitle("Unable to continue");
 90    errorDialog.setMessage(component + " is a required component. Please install it first.");
 91    errorDialog.setButton("Quit", new OnClickListener() {
 92      public void onClick(DialogInterface arg0, int arg1) {
 93        finish();
 94      }
 95    });
 96    errorDialog.show();
 97  }
 98
 99  private void startConfig() {
100    Intent mainConfigIntent = new Intent(this, MainConfigActivity.class);
101    startActivityForResult(mainConfigIntent, 0);
102  }
103
104}