mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 20:33:07 +08:00
Don't need to manage resume/pause state - the OS does it.
This commit is contained in:
parent
c6280edbed
commit
86d6053d2d
@ -59,6 +59,26 @@ import android.widget.LinearLayout;
|
|||||||
import android.os.Build.*;
|
import android.os.Build.*;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is the main Android activity that represents the PhoneGap
|
||||||
|
* application. It should be extended by the user to load the specific
|
||||||
|
* html file that contains the application.
|
||||||
|
*
|
||||||
|
* As an example:
|
||||||
|
*
|
||||||
|
* package com.phonegap.examples;
|
||||||
|
* import android.app.Activity;
|
||||||
|
* import android.os.Bundle;
|
||||||
|
* import com.phonegap.*;
|
||||||
|
*
|
||||||
|
* public class Examples extends DroidGap {
|
||||||
|
* @Override
|
||||||
|
* public void onCreate(Bundle savedInstanceState) {
|
||||||
|
* super.onCreate(savedInstanceState);
|
||||||
|
* super.loadUrl("file:///android_asset/www/index.html");
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
public class DroidGap extends Activity {
|
public class DroidGap extends Activity {
|
||||||
|
|
||||||
private static final String LOG_TAG = "DroidGap";
|
private static final String LOG_TAG = "DroidGap";
|
||||||
@ -84,7 +104,6 @@ public class DroidGap extends Activity {
|
|||||||
private Uri imageUri;
|
private Uri imageUri;
|
||||||
private String url; // The initial URL for our app
|
private String url; // The initial URL for our app
|
||||||
private String baseUrl; // The base of the initial URL for our app
|
private String baseUrl; // The base of the initial URL for our app
|
||||||
private boolean resumeState = false; // Track if onResume() has been called
|
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
@ -132,7 +151,8 @@ public class DroidGap extends Activity {
|
|||||||
|
|
||||||
if (android.os.Build.VERSION.RELEASE.startsWith("2.")) {
|
if (android.os.Build.VERSION.RELEASE.startsWith("2.")) {
|
||||||
appView.setWebChromeClient(new EclairClient(DroidGap.this));
|
appView.setWebChromeClient(new EclairClient(DroidGap.this));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
appView.setWebChromeClient(new GapClient(DroidGap.this));
|
appView.setWebChromeClient(new GapClient(DroidGap.this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,9 +178,10 @@ public class DroidGap extends Activity {
|
|||||||
WebViewReflect.setGeolocationEnabled(settings, true);
|
WebViewReflect.setGeolocationEnabled(settings, true);
|
||||||
// Bind the appView object to the gap class methods
|
// Bind the appView object to the gap class methods
|
||||||
bindBrowser(appView);
|
bindBrowser(appView);
|
||||||
if(cupcakeStorage != null)
|
if (cupcakeStorage != null) {
|
||||||
cupcakeStorage.setStorage(appPackage);
|
cupcakeStorage.setStorage(appPackage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/**
|
||||||
@ -181,10 +202,7 @@ public class DroidGap extends Activity {
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
// Send pause event to JavaScript
|
// Send pause event to JavaScript
|
||||||
if (this.resumeState) {
|
|
||||||
appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
||||||
this.resumeState = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pause JavaScript timers (including setInterval)
|
// Pause JavaScript timers (including setInterval)
|
||||||
appView.pauseTimers();
|
appView.pauseTimers();
|
||||||
@ -198,10 +216,7 @@ public class DroidGap extends Activity {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
// Send resume event to JavaScript
|
// Send resume event to JavaScript
|
||||||
if (!this.resumeState) {
|
|
||||||
appView.loadUrl("javascript:try{PhoneGap.onResume.fire();}catch(e){};");
|
appView.loadUrl("javascript:try{PhoneGap.onResume.fire();}catch(e){};");
|
||||||
this.resumeState = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resume JavaScript timers (including setInterval)
|
// Resume JavaScript timers (including setInterval)
|
||||||
appView.resumeTimers();
|
appView.resumeTimers();
|
||||||
@ -215,10 +230,7 @@ public class DroidGap extends Activity {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
// Make sure pause event is sent if onPause hasn't been called before onDestroy
|
// Make sure pause event is sent if onPause hasn't been called before onDestroy
|
||||||
if (this.resumeState) {
|
|
||||||
appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
||||||
this.resumeState = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load blank page so that JavaScript onunload is called
|
// Load blank page so that JavaScript onunload is called
|
||||||
appView.loadUrl("about:blank");
|
appView.loadUrl("about:blank");
|
||||||
@ -435,6 +447,9 @@ public class DroidGap extends Activity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The webview client receives notifications about appView
|
||||||
|
*/
|
||||||
public class GapViewClient extends WebViewClient {
|
public class GapViewClient extends WebViewClient {
|
||||||
|
|
||||||
// TODO: hide splash screen here
|
// TODO: hide splash screen here
|
||||||
@ -461,12 +476,6 @@ public class DroidGap extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
|
|
||||||
// Make sure pause event is sent if loading a new url
|
|
||||||
if (mCtx.resumeState) {
|
|
||||||
appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
|
||||||
mCtx.resumeState = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If dialing phone (tel:5551212)
|
// If dialing phone (tel:5551212)
|
||||||
if (url.startsWith(WebView.SCHEME_TEL)) {
|
if (url.startsWith(WebView.SCHEME_TEL)) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user