OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.mojo_shell_apk; | 5 package org.chromium.mojo_shell_apk; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.AlertDialog; | 8 import android.app.AlertDialog; |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.os.Bundle; | 11 import android.os.Bundle; |
12 import android.util.Log; | 12 import android.util.Log; |
13 import android.widget.EditText; | 13 import android.widget.EditText; |
14 | 14 |
15 /** | 15 /** |
16 * Activity for managing the Mojo Shell. | 16 * Activity for managing the Mojo Shell. |
17 */ | 17 */ |
18 public class MojoShellActivity extends Activity { | 18 public class MojoShellActivity extends Activity { |
19 private static final String TAG = "MojoShellActivity"; | 19 private static final String TAG = "MojoShellActivity"; |
20 | 20 |
21 @Override | 21 @Override |
22 protected void onCreate(final Bundle savedInstanceState) { | 22 protected void onCreate(final Bundle savedInstanceState) { |
23 super.onCreate(savedInstanceState); | 23 super.onCreate(savedInstanceState); |
24 | 24 |
25 String appUrl = getUrlFromIntent(getIntent()); | 25 // TODO(ppi): Gotcha - the call below will work only once per process li
fetime, but the OS |
26 if (appUrl == null) { | 26 // has no obligation to kill the application process between destroying
and restarting the |
| 27 // activity. If the application process is kept alive, initialization pa
rameters sent with |
| 28 // the intent will be stale. |
| 29 // TODO(qsr): We should be passing application context here as required
by |
| 30 // InitApplicationContext on the native side. Currently we can't, as Pla
tformViewportAndroid |
| 31 // relies on this being the activity context. |
| 32 MojoMain.ensureInitialized(this, getParametersFromIntent(getIntent())); |
| 33 |
| 34 if (MojoMain.start()) { |
| 35 Log.i(TAG, "Mojo started"); |
| 36 } else { |
27 Log.i(TAG, "No URL provided via intent, prompting user..."); | 37 Log.i(TAG, "No URL provided via intent, prompting user..."); |
28 AlertDialog.Builder alert = new AlertDialog.Builder(this); | 38 AlertDialog.Builder alert = new AlertDialog.Builder(this); |
29 alert.setTitle("Enter a URL"); | 39 alert.setTitle("Enter a URL"); |
30 alert.setMessage("Enter a URL"); | 40 alert.setMessage("Enter a URL"); |
31 final EditText input = new EditText(this); | 41 final EditText input = new EditText(this); |
32 alert.setView(input); | 42 alert.setView(input); |
33 alert.setPositiveButton("Load", new DialogInterface.OnClickListener(
) { | 43 alert.setPositiveButton("Load", new DialogInterface.OnClickListener(
) { |
34 @Override | 44 @Override |
35 public void onClick(DialogInterface dialog, int button) { | 45 public void onClick(DialogInterface dialog, int button) { |
36 String url = input.getText().toString(); | 46 String url = input.getText().toString(); |
37 startWithURL(url); | 47 MojoMain.addApplicationURL(url); |
| 48 MojoMain.start(); |
| 49 Log.i(TAG, "Mojo started"); |
38 } | 50 } |
39 }); | 51 }); |
40 alert.show(); | 52 alert.show(); |
41 } else { | |
42 startWithURL(appUrl); | |
43 } | 53 } |
44 } | 54 } |
45 | 55 |
46 private static String getUrlFromIntent(Intent intent) { | |
47 return intent != null ? intent.getDataString() : null; | |
48 } | |
49 | |
50 private static String[] getParametersFromIntent(Intent intent) { | 56 private static String[] getParametersFromIntent(Intent intent) { |
51 return intent != null ? intent.getStringArrayExtra("parameters") : null; | 57 return intent != null ? intent.getStringArrayExtra("parameters") : null; |
52 } | 58 } |
53 | 59 |
54 private void startWithURL(String url) { | 60 private void startWithURL(String url) { |
55 // TODO(ppi): Gotcha - the call below will work only once per process li
fetime, but the OS | |
56 // has no obligation to kill the application process between destroying
and restarting the | |
57 // activity. If the application process is kept alive, initialization pa
rameters sent with | |
58 // the intent will be stale. | |
59 // TODO(qsr): We should be passing application context here as required
by | |
60 // InitApplicationContext on the native side. Currently we can't, as Pla
tformViewportAndroid | |
61 // relies on this being the activity context. | |
62 MojoMain.ensureInitialized(this, getParametersFromIntent(getIntent())); | |
63 MojoMain.start(url); | |
64 Log.i(TAG, "Mojo started: " + url); | |
65 } | 61 } |
66 } | 62 } |
OLD | NEW |