Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String scriptName = getIntent().getStringExtra(Constants.EXTRA_SCRIPT_PATH);
    String interpreter = FeaturedInterpreters.getInterpreterNameForScript(scriptName);

    if (interpreter == null) {
      Log.e("Cannot find interpreter for script " + scriptName);
      finish();
    }

    final Intent activityIntent = new Intent();

    Intent resolveIntent = new Intent(InterpreterConstants.ACTION_DISCOVER_INTERPRETERS);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setType(InterpreterConstants.MIME + Script.getFileExtension(this));
    List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(resolveIntent, 0);

    if (resolveInfos != null && resolveInfos.size() == 1) {
      ActivityInfo info = resolveInfos.get(0).activityInfo;
      activityIntent.setComponent(new ComponentName(info.packageName, info.name));
      activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
      final URL url = FeaturedInterpreters.getUrlForName(interpreter);
      activityIntent.setAction(Intent.ACTION_VIEW);
      activityIntent.setData(Uri.parse(url.toString()));
    }

    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle(String.format("%s is not installed.", interpreter));
    dialog.setMessage(
        String.format("Do you want to download and install APK for %s ?", interpreter));

    DialogInterface.OnClickListener buttonListener =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
              startActivity(activityIntent);
            }
            dialog.dismiss();
            finish();
          }
        };
    dialog.setNegativeButton("No", buttonListener);
    dialog.setPositiveButton("Yes", buttonListener);
    dialog.show();
  }
Ejemplo n.º 2
0
  @Override
  public void onStart(Intent intent, final int startId) {
    super.onStart(intent, startId);

    String path = intent.getStringExtra("scriptPath");
    Log.d("Script Path: " + path);
    mScript = new Script(path);
    Log.d("FileName: " + mScript.getFileName());
    Log.d("FileExtension: " + mScript.getFileExtension());

    handleNetwork();

    Interpreter interpreter =
        mInterpreterConfiguration.getInterpreterForScript(mScript.getFileName());
    if (interpreter == null || !interpreter.isInstalled()) {
      mLatch.countDown();
      if (FeaturedInterpreters.isSupported(mScript.getFileName())) {
        Log.d("Is Supported");
        Intent i = new Intent(this, DialogActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.putExtra(Constants.EXTRA_SCRIPT_PATH, mScript.getFileName());
        startActivity(i);
      } else {
        Log.e(this, "Cannot find an interpreter for script " + mScript.getFileName());
      }
      stopSelf(startId);
      return;
    }

    File script = new File(path);
    Log.d("Launch with proxy ");

    mProxy = new AndroidProxy(this, null, true);
    mProxy.startLocal();
    mLatch.countDown();
    ScriptLauncher.launchScript(
        script,
        mInterpreterConfiguration,
        mProxy,
        new Runnable() {
          @Override
          public void run() {
            mProxy.shutdown();
            stopSelf(startId);
          }
        });
  }