mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 02:12:58 +08:00
CordovaActivity: don't create WebView until loadUrl() so that apps can tweak preferences after super.onCreate()
This commit is contained in:
parent
9358838dab
commit
4b4b71ff32
@ -108,7 +108,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
// Draw a splash screen using an image located in the drawable resource directory.
|
// Draw a splash screen using an image located in the drawable resource directory.
|
||||||
// This is not the same as calling super.loadSplashscreen(url)
|
// This is not the same as calling super.loadSplashscreen(url)
|
||||||
protected int splashscreen = 0;
|
protected int splashscreen = 0;
|
||||||
protected int splashscreenTime = 3000;
|
|
||||||
|
|
||||||
// LoadUrl timeout value in msec (default of 20 sec)
|
// LoadUrl timeout value in msec (default of 20 sec)
|
||||||
protected int loadUrlTimeoutValue = 20000;
|
protected int loadUrlTimeoutValue = 20000;
|
||||||
@ -141,7 +140,9 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init() {
|
||||||
if(!preferences.getBoolean("ShowTitle", false))
|
if(!preferences.getBoolean("ShowTitle", false))
|
||||||
{
|
{
|
||||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||||
@ -261,15 +262,17 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
/**
|
/**
|
||||||
* Load the url into the webview.
|
* Load the url into the webview.
|
||||||
*/
|
*/
|
||||||
public void loadUrl(String url) {
|
public void loadUrl(String url, int splashscreenTime) {
|
||||||
this.splashscreenTime = preferences.getInteger("SplashScreenDelay", this.splashscreenTime);
|
if (appView == null) {
|
||||||
|
init();
|
||||||
|
}
|
||||||
String splash = preferences.getString("SplashScreen", null);
|
String splash = preferences.getString("SplashScreen", null);
|
||||||
if(this.splashscreenTime > 0 && splash != null)
|
if(splashscreenTime > 0 && splash != null)
|
||||||
{
|
{
|
||||||
this.splashscreen = getResources().getIdentifier(splash, "drawable", getClass().getPackage().getName());;
|
this.splashscreen = getResources().getIdentifier(splash, "drawable", getClass().getPackage().getName());;
|
||||||
if(this.splashscreen != 0)
|
if(this.splashscreen != 0)
|
||||||
{
|
{
|
||||||
this.showSplashScreen(this.splashscreenTime);
|
this.showSplashScreen(splashscreenTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,10 +300,11 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
* @param url
|
* @param url
|
||||||
* @param time The number of ms to wait before loading webview
|
* @param time The number of ms to wait before loading webview
|
||||||
*/
|
*/
|
||||||
public void loadUrl(final String url, int time) {
|
public void loadUrl(final String url) {
|
||||||
|
if (appView == null) {
|
||||||
this.splashscreenTime = time;
|
init();
|
||||||
this.loadUrl(url);
|
}
|
||||||
|
this.loadUrl(url, preferences.getInteger("SplashScreenDelay", 3000));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -456,6 +460,11 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
* End this activity by calling finish for activity
|
* End this activity by calling finish for activity
|
||||||
*/
|
*/
|
||||||
public void endActivity() {
|
public void endActivity() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finish() {
|
||||||
this.activityState = ACTIVITY_EXITING;
|
this.activityState = ACTIVITY_EXITING;
|
||||||
super.finish();
|
super.finish();
|
||||||
}
|
}
|
||||||
@ -590,19 +599,25 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
if (appView != null) {
|
||||||
appView.getPluginManager().postMessage("onCreateOptionsMenu", menu);
|
appView.getPluginManager().postMessage("onCreateOptionsMenu", menu);
|
||||||
|
}
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
if (appView != null) {
|
||||||
appView.getPluginManager().postMessage("onPrepareOptionsMenu", menu);
|
appView.getPluginManager().postMessage("onPrepareOptionsMenu", menu);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (appView != null) {
|
||||||
appView.getPluginManager().postMessage("onOptionsItemSelected", item);
|
appView.getPluginManager().postMessage("onOptionsItemSelected", item);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,7 +702,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
if (splashResource != null) {
|
if (splashResource != null) {
|
||||||
splashscreen = getResources().getIdentifier(splashResource, "drawable", getClass().getPackage().getName());
|
splashscreen = getResources().getIdentifier(splashResource, "drawable", getClass().getPackage().getName());
|
||||||
}
|
}
|
||||||
this.showSplashScreen(this.splashscreenTime);
|
this.showSplashScreen(preferences.getInteger("SplashScreenDelay", 3000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user