Commit 323ab909 authored by ellelili2025's avatar ellelili2025 Committed by Evan W. Patton

Added PageLoaded event for WebViewer

Fixes #1235

Change-Id: Ia697085337cf3aa286f69d3eeba3ccedb7ae643f
parent fbd75360
......@@ -1591,7 +1591,7 @@ public final class YoungAndroidFormUpgrader {
private static int upgradeWebViewerProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 7) {
if (srcCompVersion < 8) {
// The CanGoForward and CanGoBack methods were added.
// No properties need to be modified to upgrade to version 2.
// UsesLocation property added.
......@@ -1601,7 +1601,8 @@ public final class YoungAndroidFormUpgrader {
// IgnoreSslError property added (version 5)
// ClearCaches method was added (version 6)
// WebViewStringChange event was added (version 7)
srcCompVersion = 7;
// PageLoaded event was added (version 8)
srcCompVersion = 8;
}
return srcCompVersion;
}
......
......@@ -2649,7 +2649,10 @@ Blockly.Versioning.AllUpgradeMaps =
6: "noUpgrade",
// AI2: Added WebViewStringChange
7: "noUpgrade"
7: "noUpgrade",
//AI2: Added PageLoaded
8: "noUpgrade"
}, // End WebViewer upgraders
......
......@@ -486,8 +486,10 @@ public class YaVersion {
// - TEXTBOX_COMPONENT_VERSION was incremented to 6
// For YOUNG_ANDROID_VERSION 195:
// - PEDOMETER_COMPONENT_VERSION was incremented to 2
// For YOUNG_ANDROID_VERSION 196:
// - WEBVIEWER_COMPONENT_VERSION was incremented to 8
public static final int YOUNG_ANDROID_VERSION = 195;
public static final int YOUNG_ANDROID_VERSION = 196;
// ............................... Blocks Language Version Number ...............................
......@@ -1272,7 +1274,9 @@ public class YaVersion {
// - ClearCaches method was added
// For WEBVIEWER_COMPONENT_VERSiON 7:
// - Added WebViewStringChange event
public static final int WEBVIEWER_COMPONENT_VERSION = 7;
//For WEBVIEWER_COMPONENT_VERSION 8:
// - Added PageLoaded event
public static final int WEBVIEWER_COMPONENT_VERSION = 8;
// For MEDIASTORE_COMPONENT_VERSION 1:
// - Initial Version.
......
......@@ -164,7 +164,7 @@ public final class WebViewer extends AndroidViewComponent {
// Create a class so we can override the default link following behavior.
// The handler doesn't do anything on its own. But returning true means that
// this do nothing will override the default WebVew behavior. Returning
// this do nothing will override the default WebView behavior. Returning
// false means to let the WebView handle the Url. In other words, returning
// true will not follow the link, and returning false will follow the link.
private class WebViewerClient extends WebViewClient {
......@@ -172,6 +172,11 @@ public final class WebViewer extends AndroidViewComponent {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return !followLinks;
}
@Override
public void onPageFinished(WebView view, String url) {
PageLoaded(url);
}
}
// Components don't normally override Width and Height, but we do it here so that
......@@ -447,6 +452,11 @@ public final class WebViewer extends AndroidViewComponent {
EventDispatcher.dispatchEvent(this, "WebViewStringChange", value);
}
@SimpleEvent(description = "When a page is finished loading this event is run.")
public void PageLoaded(String url) {
EventDispatcher.dispatchEvent(this, "PageLoaded", url);
}
private void loadUrl(final String caller, final String url) {
if (!havePermission && MediaUtil.isExternalFileUrl(url)) {
container.$form().askPermission(Manifest.permission.READ_EXTERNAL_STORAGE,
......
......@@ -16,6 +16,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.Player;
......@@ -141,6 +142,12 @@ public class FroyoUtil {
ErrorMessages.ERROR_WEBVIEW_SSL_ERROR);
}
}
@Override
public void onPageFinished(WebView view, String url) {
EventDispatcher.dispatchEvent(component, "PageLoaded", url);
}
};
}
......
......@@ -1424,6 +1424,10 @@ none
</dl>
<h3>Events</h3>
<dl>
<dt><code>PageLoaded(text url)</code></dt>
<dd>Event that runs when a page finishes loading.</dd>
</dl>
<dl>
<dt><code>WebViewStringChange(text value)</code></dt>
<dd>Event that runs when the AppInventor.setWebViewString method is called from JavaScript. The new WebViewString is given by the value parameter.</dd>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment