mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 01:42:58 +08:00
Better way to handle splash screen when back button pressed.
This commit is contained in:
parent
b8b1ad8421
commit
0e08af98ca
@ -23,7 +23,9 @@ import android.view.ViewGroup;
|
|||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.webkit.JsResult;
|
import android.webkit.JsResult;
|
||||||
|
import android.webkit.WebBackForwardList;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
|
import android.webkit.WebHistoryItem;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebStorage;
|
import android.webkit.WebStorage;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -107,8 +109,8 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
// Plugin to call when activity result is received
|
// Plugin to call when activity result is received
|
||||||
private Plugin activityResultCallback = null;
|
private Plugin activityResultCallback = null;
|
||||||
|
|
||||||
// Flag indicates that splash screen is currently showing
|
// URL of the splash screen that is currently showing
|
||||||
private boolean splashScreenShowing = false;
|
private String splashScreenShowing = null;
|
||||||
|
|
||||||
// Flag indicates that a loadUrl timeout occurred
|
// Flag indicates that a loadUrl timeout occurred
|
||||||
private boolean loadUrlTimeout = false;
|
private boolean loadUrlTimeout = false;
|
||||||
@ -402,7 +404,7 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
*/
|
*/
|
||||||
public void loadSplashScreen(final String url) {
|
public void loadSplashScreen(final String url) {
|
||||||
System.out.println("loadSplashScreen("+url+")");
|
System.out.println("loadSplashScreen("+url+")");
|
||||||
this.splashScreenShowing = true;
|
this.splashScreenShowing = url;
|
||||||
|
|
||||||
// Load URL on UI thread
|
// Load URL on UI thread
|
||||||
final DroidGap me = this;
|
final DroidGap me = this;
|
||||||
@ -922,11 +924,15 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear history, so that splash screen isn't there when Back button is pressed
|
// Clear history, so that splash screen isn't there when Back button is pressed
|
||||||
if (this.ctx.splashScreenShowing && this.ctx.appView.canGoBack()) {
|
WebBackForwardList history = this.ctx.appView.copyBackForwardList();
|
||||||
this.ctx.splashScreenShowing = false;
|
int i = history.getCurrentIndex();
|
||||||
|
if (i > 0) {
|
||||||
|
WebHistoryItem item = history.getItemAtIndex(i-1);
|
||||||
|
if (item.getUrl().equals(this.ctx.splashScreenShowing)) {
|
||||||
this.ctx.appView.clearHistory();
|
this.ctx.appView.clearHistory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
|
* Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
|
||||||
|
Loading…
Reference in New Issue
Block a user