forked from github/cordova-android
Utility Methods based on Feedback
This commit is contained in:
parent
b9b2c6a013
commit
b234b0bded
@ -785,4 +785,62 @@ public class CordovaWebView extends WebView {
|
|||||||
{
|
{
|
||||||
return this.bound;
|
return this.bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handlePause(boolean keepRunning)
|
||||||
|
{
|
||||||
|
// Send pause event to JavaScript
|
||||||
|
this.loadUrl("javascript:try{cordova.fireDocumentEvent('pause');}catch(e){console.log('exception firing pause event from native');};");
|
||||||
|
|
||||||
|
// Forward to plugins
|
||||||
|
if (this.pluginManager != null) {
|
||||||
|
this.pluginManager.onPause(keepRunning);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If app doesn't want to run in background
|
||||||
|
if (keepRunning) {
|
||||||
|
// Pause JavaScript timers (including setInterval)
|
||||||
|
this.pauseTimers();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleResume(boolean keepRunning, boolean activityResultKeepRunning)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Send resume event to JavaScript
|
||||||
|
this.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};");
|
||||||
|
|
||||||
|
// Forward to plugins
|
||||||
|
if (this.pluginManager != null) {
|
||||||
|
this.pluginManager.onResume(keepRunning);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If app doesn't want to run in background
|
||||||
|
if (!keepRunning || activityResultKeepRunning) {
|
||||||
|
// Resume JavaScript timers (including setInterval)
|
||||||
|
this.resumeTimers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleDestroy()
|
||||||
|
{
|
||||||
|
// Send destroy event to JavaScript
|
||||||
|
this.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
|
||||||
|
|
||||||
|
// Load blank page so that JavaScript onunload is called
|
||||||
|
this.loadUrl("about:blank");
|
||||||
|
|
||||||
|
// Forward to plugins
|
||||||
|
if (this.pluginManager != null) {
|
||||||
|
this.pluginManager.onDestroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onNewIntent(Intent intent)
|
||||||
|
{
|
||||||
|
//Forward to plugins
|
||||||
|
if (this.pluginManager != null) {
|
||||||
|
this.pluginManager.onNewIntent(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import android.graphics.Color;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -600,6 +601,8 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
|
LOG.d(TAG, "Paused the application!");
|
||||||
|
|
||||||
// Don't process pause if shutting down, since onDestroy() will be called
|
// Don't process pause if shutting down, since onDestroy() will be called
|
||||||
if (this.activityState == ACTIVITY_EXITING) {
|
if (this.activityState == ACTIVITY_EXITING) {
|
||||||
return;
|
return;
|
||||||
@ -608,19 +611,9 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
if (this.appView == null) {
|
if (this.appView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Send pause event to JavaScript
|
{
|
||||||
this.appView.loadUrl("javascript:try{cordova.fireDocumentEvent('pause');}catch(e){console.log('exception firing pause event from native');};");
|
this.appView.handlePause(this.keepRunning);
|
||||||
|
|
||||||
// Forward to plugins
|
|
||||||
if (this.appView.pluginManager != null) {
|
|
||||||
this.appView.pluginManager.onPause(this.keepRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If app doesn't want to run in background
|
|
||||||
if (!this.keepRunning) {
|
|
||||||
// Pause JavaScript timers (including setInterval)
|
|
||||||
this.appView.pauseTimers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide the splash screen to avoid leaking a window
|
// hide the splash screen to avoid leaking a window
|
||||||
@ -633,11 +626,9 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
**/
|
**/
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
|
||||||
//Forward to plugins
|
//Forward to plugins
|
||||||
if ((this.appView != null) && (this.appView.pluginManager != null)) {
|
if (this.appView != null)
|
||||||
this.appView.pluginManager.onNewIntent(intent);
|
this.appView.onNewIntent(intent);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -647,6 +638,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
LOG.d(TAG, "Resuming the App");
|
||||||
if (this.activityState == ACTIVITY_STARTING) {
|
if (this.activityState == ACTIVITY_STARTING) {
|
||||||
this.activityState = ACTIVITY_RUNNING;
|
this.activityState = ACTIVITY_RUNNING;
|
||||||
return;
|
return;
|
||||||
@ -656,13 +648,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send resume event to JavaScript
|
this.appView.handleResume(this.keepRunning, this.activityResultKeepRunning);
|
||||||
this.appView.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};");
|
|
||||||
|
|
||||||
// Forward to plugins
|
|
||||||
if (this.appView.pluginManager != null) {
|
|
||||||
this.appView.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If app doesn't want to run in background
|
// If app doesn't want to run in background
|
||||||
if (!this.keepRunning || this.activityResultKeepRunning) {
|
if (!this.keepRunning || this.activityResultKeepRunning) {
|
||||||
@ -672,9 +658,6 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
this.keepRunning = this.activityResultKeepRunning;
|
this.keepRunning = this.activityResultKeepRunning;
|
||||||
this.activityResultKeepRunning = false;
|
this.activityResultKeepRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resume JavaScript timers (including setInterval)
|
|
||||||
this.appView.resumeTimers();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,17 +673,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
this.removeSplashScreen();
|
this.removeSplashScreen();
|
||||||
|
|
||||||
if (this.appView != null) {
|
if (this.appView != null) {
|
||||||
|
appView.handleDestroy();
|
||||||
// Send destroy event to JavaScript
|
|
||||||
this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
|
|
||||||
|
|
||||||
// Load blank page so that JavaScript onunload is called
|
|
||||||
this.appView.loadUrl("about:blank");
|
|
||||||
|
|
||||||
// Forward to plugins
|
|
||||||
if (this.appView.pluginManager != null) {
|
|
||||||
this.appView.pluginManager.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.endActivity();
|
this.endActivity();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user