// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.mojo_shell_apk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import org.chromium.mojo_shell_apk.LibraryLoader;
import org.chromium.mojo_shell_apk.MojoMain;

/**
 * Activity for managing the Mojo Shell.
 */
public class MojoShellActivity extends Activity {
    private static final String TAG = "MojoShellActivity";

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {
            LibraryLoader.ensureInitialized();
        } catch (UnsatisfiedLinkError e) {
            Log.e(TAG, "libmojo_shell initialization failed.", e);
            finish();
            return;
        }

        MojoMain.init(this);

        String appUrl = getUrlFromIntent(getIntent());
        MojoMain.start(this, appUrl);
        Log.i(TAG, "Mojo started: " + appUrl);
    }

    private static String getUrlFromIntent(Intent intent) {
        return intent != null ? intent.getDataString() : null;
    }
}

@@ -226,16 +226,88 @@
 tivity;%0A
+import android.app.AlertDialog;%0Aimport android.content.DialogInterface;%0A
 import a
@@ -379,16 +379,48 @@
 til.Log;
+%0Aimport android.widget.EditText;
 %0A%0Aimport
@@ -1111,213 +1111,988 @@
     
-MojoMain.start(this, appUrl);%0A        Log.i(TAG, %22Mojo started: %22 + appUrl);%0A    %7D%0A%0A    private static String getUrlFromIntent(Intent intent) %7B%0A        return intent != null ? intent.getDataString() : null
+if (appUrl == null) %7B%0A            Log.i(TAG, %22No URL provided via intent, prompting user...%22);%0A            AlertDialog.Builder alert = new AlertDialog.Builder(this);%0A            alert.setTitle(%22Enter a URL%22);%0A            alert.setMessage(%22Enter a URL%22);%0A            final EditText input = new EditText(this);%0A            alert.setView(input);%0A            alert.setPositiveButton(%22Load%22, new DialogInterface.OnClickListener() %7B%0A                public void onClick(DialogInterface dialog, int button) %7B%0A                    String url = input.getText().toString();%0A                    startWithURL(url);%0A                %7D%0A            %7D);%0A            alert.show();%0A        %7D else %7B%0A            startWithURL(appUrl);%0A        %7D%0A    %7D%0A%0A    private static String getUrlFromIntent(Intent intent) %7B%0A        return intent != null ? intent.getDataString() : null;%0A    %7D%0A%0A    private void startWithURL(String url) %7B%0A        MojoMain.start(this, url);%0A        Log.i(TAG, %22Mojo started: %22 + url)
 ;%0A  

Add a URL entry prompt