Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
96928efc
Unverified
Commit
96928efc
authored
Mar 24, 2020
by
nitinseshadri
Committed by
GitHub
Mar 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ErrorOccurred event and RunJavaScript method to WebView component (#2070)
parent
4385caa7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
4 deletions
+54
-4
appinventor/appengine/src/com/google/appinventor/client/youngandroid/YoungAndroidFormUpgrader.java
...nventor/client/youngandroid/YoungAndroidFormUpgrader.java
+3
-2
appinventor/blocklyeditor/src/versioning.js
appinventor/blocklyeditor/src/versioning.js
+4
-1
appinventor/components/src/com/google/appinventor/components/common/YaVersion.java
...c/com/google/appinventor/components/common/YaVersion.java
+4
-1
appinventor/components/src/com/google/appinventor/components/runtime/WebViewer.java
.../com/google/appinventor/components/runtime/WebViewer.java
+24
-0
appinventor/components/src/com/google/appinventor/components/runtime/util/FroyoUtil.java
...google/appinventor/components/runtime/util/FroyoUtil.java
+9
-0
appinventor/docs/html/reference/components/userinterface.html
...nventor/docs/html/reference/components/userinterface.html
+4
-0
appinventor/docs/markdown/reference/components/userinterface.md
...entor/docs/markdown/reference/components/userinterface.md
+6
-0
No files found.
appinventor/appengine/src/com/google/appinventor/client/youngandroid/YoungAndroidFormUpgrader.java
View file @
96928efc
...
...
@@ -1616,7 +1616,7 @@ public final class YoungAndroidFormUpgrader {
private
static
int
upgradeWebViewerProperties
(
Map
<
String
,
JSONValue
>
componentProperties
,
int
srcCompVersion
)
{
if
(
srcCompVersion
<
9
)
{
if
(
srcCompVersion
<
10
)
{
// The CanGoForward and CanGoBack methods were added.
// No properties need to be modified to upgrade to version 2.
// UsesLocation property added.
...
...
@@ -1628,7 +1628,8 @@ public final class YoungAndroidFormUpgrader {
// WebViewStringChange event was added (version 7)
// PageLoaded event was added (version 8)
// BeforePageLoad event and Stop, Reload, and ClearCookies methods added (version 9)
srcCompVersion
=
9
;
// ErrorOccurred event and RunJavaScript method added (version 10)
srcCompVersion
=
10
;
}
return
srcCompVersion
;
}
...
...
appinventor/blocklyeditor/src/versioning.js
View file @
96928efc
...
...
@@ -2683,7 +2683,10 @@ Blockly.Versioning.AllUpgradeMaps =
8
:
"
noUpgrade
"
,
// AI2: Added BeforePageLoad event and Stop, Reload, and ClearCookies methods
9
:
"
noUpgrade
"
9
:
"
noUpgrade
"
,
// AI2: Added ErrorOccurred event and RunJavaScript method
10
:
"
noUpgrade
"
},
// End WebViewer upgraders
...
...
appinventor/components/src/com/google/appinventor/components/common/YaVersion.java
View file @
96928efc
...
...
@@ -1319,7 +1319,10 @@ public class YaVersion {
// For WEBVIEWER_COMPONENT_VERSION 9:
// - Added BeforePageLoad event
// - Added Stop, Reload, and ClearCookies methods
public
static
final
int
WEBVIEWER_COMPONENT_VERSION
=
9
;
// For WEBVIEWER_COMPONENT_VERSION 10:
// - Added ErrorOccurred event
// - Added RunJavaScript method
public
static
final
int
WEBVIEWER_COMPONENT_VERSION
=
10
;
// For MEDIASTORE_COMPONENT_VERSION 1:
// - Initial Version.
...
...
appinventor/components/src/com/google/appinventor/components/runtime/WebViewer.java
View file @
96928efc
...
...
@@ -222,6 +222,15 @@ public final class WebViewer extends AndroidViewComponent {
public
void
onPageFinished
(
WebView
view
,
String
url
)
{
PageLoaded
(
url
);
}
@Override
public
void
onReceivedError
(
WebView
view
,
final
int
errorCode
,
final
String
description
,
final
String
failingUrl
)
{
container
.
$form
().
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
ErrorOccurred
(
errorCode
,
description
,
failingUrl
);
}
});
}
}
// Components don't normally override Width and Height, but we do it here so that
...
...
@@ -537,6 +546,16 @@ public final class WebViewer extends AndroidViewComponent {
}
}
/**
* Run JavaScript in the current page.
*/
@SimpleFunction
(
description
=
"Run JavaScript in the current page."
)
public
void
RunJavaScript
(
String
js
)
{
// evaluateJavascript() was added in API 19
// and is therefore not used here for compatibility purposes.
webview
.
loadUrl
(
"javascript:(function(){"
+
js
+
"})()"
);
}
/**
* Event that runs when the `AppInventor.setWebViewString` method is called from JavaScript.
* The new {@link #WebViewString()} is given by the `value`{:.variable.block} parameter.
...
...
@@ -557,6 +576,11 @@ public final class WebViewer extends AndroidViewComponent {
EventDispatcher
.
dispatchEvent
(
this
,
"PageLoaded"
,
url
);
}
@SimpleEvent
(
description
=
"When an error occurs this event is run."
)
public
void
ErrorOccurred
(
int
errorCode
,
String
description
,
String
failingUrl
)
{
EventDispatcher
.
dispatchEvent
(
this
,
"ErrorOccurred"
,
errorCode
,
description
,
failingUrl
);
}
private
void
loadUrl
(
final
String
caller
,
final
String
url
)
{
if
(!
havePermission
&&
MediaUtil
.
isExternalFileUrl
(
url
))
{
container
.
$form
().
askPermission
(
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
...
...
appinventor/components/src/com/google/appinventor/components/runtime/util/FroyoUtil.java
View file @
96928efc
...
...
@@ -153,6 +153,15 @@ public class FroyoUtil {
public
void
onPageFinished
(
WebView
view
,
String
url
)
{
EventDispatcher
.
dispatchEvent
(
component
,
"PageLoaded"
,
url
);
}
@Override
public
void
onReceivedError
(
WebView
view
,
final
int
errorCode
,
final
String
description
,
final
String
failingUrl
)
{
form
.
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
EventDispatcher
.
dispatchEvent
(
component
,
"ErrorOccurred"
,
errorCode
,
description
,
failingUrl
);
}
});
}
};
}
...
...
appinventor/docs/html/reference/components/userinterface.html
View file @
96928efc
...
...
@@ -1497,6 +1497,8 @@ having dark grey components.</li>
<dl
class=
"events"
>
<dt
id=
"WebViewer.BeforePageLoad"
>
BeforePageLoad(
<em
class=
"text"
>
url
</em>
)
</dt>
<dd>
When a page is about to load this event is run.
</dd>
<dt
id=
"WebViewer.ErrorOccurred"
>
ErrorOccurred(
<em
class=
"number"
>
errorCode
</em>
,
<em
class=
"text"
>
description
</em>
,
<em
class=
"text"
>
failingUrl
</em>
)
</dt>
<dd>
When an error occurs this event is run.
</dd>
<dt
id=
"WebViewer.PageLoaded"
>
PageLoaded(
<em
class=
"text"
>
url
</em>
)
</dt>
<dd>
When a page is finished loading this event is run.
</dd>
<dt
id=
"WebViewer.WebViewStringChange"
>
WebViewStringChange(
<em
class=
"text"
>
value
</em>
)
</dt>
...
...
@@ -1538,6 +1540,8 @@ Eclair, this function is a no-op on older phones.</p>
<dd>
Load the page at the given URL.
</dd>
<dt
id=
"WebViewer.Reload"
class=
"method"
><i></i>
Reload()
</dt>
<dd>
Reload the current page.
</dd>
<dt
id=
"WebViewer.RunJavaScript"
class=
"method"
><i></i>
RunJavaScript(
<em
class=
"text"
>
js
</em>
)
</dt>
<dd>
Run JavaScript in the current page.
</dd>
<dt
id=
"WebViewer.StopLoading"
class=
"method"
><i></i>
StopLoading()
</dt>
<dd>
Stop loading a page.
</dd>
</dl>
...
...
appinventor/docs/markdown/reference/components/userinterface.md
View file @
96928efc
...
...
@@ -1705,6 +1705,9 @@ Component for viewing Web pages.
{:id="WebViewer.BeforePageLoad"} BeforePageLoad(*url*{:.text})
: When a page is about to load this event is run.
{:id="WebViewer.ErrorOccurred"} ErrorOccurred(*errorCode*{:.number},*description*{:.text},*failingUrl*{:.text})
: When an error occurs this event is run.
{:id="WebViewer.PageLoaded"} PageLoaded(*url*{:.text})
: When a page is finished loading this event is run.
...
...
@@ -1756,5 +1759,8 @@ Component for viewing Web pages.
{:id="WebViewer.Reload" class="method"}
<i/>
Reload()
: Reload the current page.
{:id="WebViewer.RunJavaScript" class="method"}
<i/>
RunJavaScript(
*js*
{:.text})
: Run JavaScript in the current page.
{:id="WebViewer.StopLoading" class="method"}
<i/>
StopLoading()
: Stop loading a page.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment