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
fa4d6011
Unverified
Commit
fa4d6011
authored
Mar 19, 2020
by
nitinseshadri
Committed by
GitHub
Mar 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement new functions for the WebView component (#2043)
parent
9f5dc331
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
6 deletions
+86
-6
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
+7
-2
appinventor/components/src/com/google/appinventor/components/runtime/WebViewer.java
.../com/google/appinventor/components/runtime/WebViewer.java
+44
-0
appinventor/components/src/com/google/appinventor/components/runtime/util/FroyoUtil.java
...google/appinventor/components/runtime/util/FroyoUtil.java
+6
-1
appinventor/docs/html/reference/components/userinterface.html
...nventor/docs/html/reference/components/userinterface.html
+9
-0
appinventor/docs/markdown/reference/components/userinterface.md
...entor/docs/markdown/reference/components/userinterface.md
+13
-0
No files found.
appinventor/appengine/src/com/google/appinventor/client/youngandroid/YoungAndroidFormUpgrader.java
View file @
fa4d6011
...
...
@@ -1611,7 +1611,7 @@ public final class YoungAndroidFormUpgrader {
private
static
int
upgradeWebViewerProperties
(
Map
<
String
,
JSONValue
>
componentProperties
,
int
srcCompVersion
)
{
if
(
srcCompVersion
<
8
)
{
if
(
srcCompVersion
<
9
)
{
// The CanGoForward and CanGoBack methods were added.
// No properties need to be modified to upgrade to version 2.
// UsesLocation property added.
...
...
@@ -1622,7 +1622,8 @@ public final class YoungAndroidFormUpgrader {
// ClearCaches method was added (version 6)
// WebViewStringChange event was added (version 7)
// PageLoaded event was added (version 8)
srcCompVersion
=
8
;
// BeforePageLoad event and Stop, Reload, and ClearCookies methods added (version 9)
srcCompVersion
=
9
;
}
return
srcCompVersion
;
}
...
...
appinventor/blocklyeditor/src/versioning.js
View file @
fa4d6011
...
...
@@ -2676,7 +2676,10 @@ Blockly.Versioning.AllUpgradeMaps =
7
:
"
noUpgrade
"
,
//AI2: Added PageLoaded
8
:
"
noUpgrade
"
8
:
"
noUpgrade
"
,
// AI2: Added BeforePageLoad event and Stop, Reload, and ClearCookies methods
9
:
"
noUpgrade
"
},
// End WebViewer upgraders
...
...
appinventor/components/src/com/google/appinventor/components/common/YaVersion.java
View file @
fa4d6011
...
...
@@ -501,8 +501,10 @@ public class YaVersion {
// - CANVAS_COMPONENT_VERSION was incremented to 13
// For YOUNG_ANDROID_VERSION 202:
// - BLOCKS_LANGUAGE_VERSION was incremented to 30
// For YOUNG_ANDROID_VERSION 203:
// - WEBVIEWER_COMPONENT_VERSION was incremented to 9
public
static
final
int
YOUNG_ANDROID_VERSION
=
20
2
;
public
static
final
int
YOUNG_ANDROID_VERSION
=
20
3
;
// ............................... Blocks Language Version Number ...............................
...
...
@@ -1305,7 +1307,10 @@ public class YaVersion {
// - Added WebViewStringChange event
//For WEBVIEWER_COMPONENT_VERSION 8:
// - Added PageLoaded event
public
static
final
int
WEBVIEWER_COMPONENT_VERSION
=
8
;
// For WEBVIEWER_COMPONENT_VERSION 9:
// - Added BeforePageLoad event
// - Added Stop, Reload, and ClearCookies methods
public
static
final
int
WEBVIEWER_COMPONENT_VERSION
=
9
;
// For MEDIASTORE_COMPONENT_VERSION 1:
// - Initial Version.
...
...
appinventor/components/src/com/google/appinventor/components/runtime/WebViewer.java
View file @
fa4d6011
...
...
@@ -26,8 +26,10 @@ import com.google.appinventor.components.runtime.util.FroyoUtil;
import
com.google.appinventor.components.runtime.util.MediaUtil
;
import
com.google.appinventor.components.runtime.util.SdkLevel
;
import
android.graphics.Bitmap
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.webkit.CookieManager
;
import
android.webkit.WebView
;
import
android.webkit.WebViewClient
;
...
...
@@ -211,6 +213,11 @@ public final class WebViewer extends AndroidViewComponent {
return
!
followLinks
;
}
@Override
public
void
onPageStarted
(
WebView
view
,
String
url
,
Bitmap
favicon
)
{
BeforePageLoad
(
url
);
}
@Override
public
void
onPageFinished
(
WebView
view
,
String
url
)
{
PageLoaded
(
url
);
...
...
@@ -421,6 +428,24 @@ public final class WebViewer extends AndroidViewComponent {
loadUrl
(
"GoToUrl"
,
url
);
}
/**
* Stop loading a page.
*/
@SimpleFunction
(
description
=
"Stop loading a page."
)
public
void
StopLoading
()
{
webview
.
stopLoading
();
}
/**
* Reload the current page.
*/
@SimpleFunction
(
description
=
"Reload the current page."
)
public
void
Reload
()
{
webview
.
reload
();
}
/**
* Specifies whether or not this `WebViewer` can access the JavaScript
* geolocation API.
...
...
@@ -498,6 +523,20 @@ public final class WebViewer extends AndroidViewComponent {
webview
.
clearCache
(
true
);
}
/**
* Clear the webview's cookies. This is useful if you want to
* sign the user out of a website that uses them to store logins.
*/
@SimpleFunction
(
description
=
"Clear WebView cookies."
)
public
void
ClearCookies
()
{
CookieManager
cookieManager
=
CookieManager
.
getInstance
();
if
(
SdkLevel
.
getLevel
()
>=
SdkLevel
.
LEVEL_LOLLIPOP
)
{
cookieManager
.
removeAllCookies
(
null
);
}
else
{
cookieManager
.
removeAllCookie
();
}
}
/**
* Event that runs when the `AppInventor.setWebViewString` method is called from JavaScript.
* The new {@link #WebViewString()} is given by the `value`{:.variable.block} parameter.
...
...
@@ -508,6 +547,11 @@ public final class WebViewer extends AndroidViewComponent {
EventDispatcher
.
dispatchEvent
(
this
,
"WebViewStringChange"
,
value
);
}
@SimpleEvent
(
description
=
"When a page is about to load this event is run."
)
public
void
BeforePageLoad
(
String
url
)
{
EventDispatcher
.
dispatchEvent
(
this
,
"BeforePageLoad"
,
url
);
}
@SimpleEvent
(
description
=
"When a page is finished loading this event is run."
)
public
void
PageLoaded
(
String
url
)
{
EventDispatcher
.
dispatchEvent
(
this
,
"PageLoaded"
,
url
);
...
...
appinventor/components/src/com/google/appinventor/components/runtime/util/FroyoUtil.java
View file @
fa4d6011
...
...
@@ -8,6 +8,7 @@ package com.google.appinventor.components.runtime.util;
import
android.app.Activity
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.media.AudioManager
;
import
android.net.http.SslError
;
import
android.view.Display
;
...
...
@@ -143,10 +144,14 @@ public class FroyoUtil {
}
}
@Override
public
void
onPageStarted
(
WebView
view
,
String
url
,
Bitmap
favicon
)
{
EventDispatcher
.
dispatchEvent
(
component
,
"BeforePageLoad"
,
url
);
}
@Override
public
void
onPageFinished
(
WebView
view
,
String
url
)
{
EventDispatcher
.
dispatchEvent
(
component
,
"PageLoaded"
,
url
);
}
};
}
...
...
appinventor/docs/html/reference/components/userinterface.html
View file @
fa4d6011
...
...
@@ -1495,6 +1495,8 @@ having dark grey components.</li>
<h3
id=
"WebViewer-Events"
>
Events
</h3>
<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.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>
...
...
@@ -1513,6 +1515,9 @@ having dark grey components.</li>
<dd>
Clear the internal webview cache, both ram and disk. This is useful
when using the
<code
class=
"highlighter-rouge"
>
WebViewer
</code>
to poll a page that may not be sending
appropriate cache control headers.
</dd>
<dt
id=
"WebViewer.ClearCookies"
class=
"method"
><i></i>
ClearCookies()
</dt>
<dd>
Clear the webview’s cookies. This is useful if you want to
sign the user out of a website that uses them to store logins.
</dd>
<dt
id=
"WebViewer.ClearLocations"
class=
"method"
><i></i>
ClearLocations()
</dt>
<dd>
Clear Stored Location permissions. When the geolocation API is used in
the
<code
class=
"highlighter-rouge"
>
WebViewer
</code>
, the end user is prompted on a per URL basis for whether
...
...
@@ -1531,6 +1536,10 @@ Eclair, this function is a no-op on older phones.</p>
home URL is changed.
</dd>
<dt
id=
"WebViewer.GoToUrl"
class=
"method"
><i></i>
GoToUrl(
<em
class=
"text"
>
url
</em>
)
</dt>
<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.StopLoading"
class=
"method"
><i></i>
StopLoading()
</dt>
<dd>
Stop loading a page.
</dd>
</dl>
</article>
...
...
appinventor/docs/markdown/reference/components/userinterface.md
View file @
fa4d6011
...
...
@@ -1702,6 +1702,9 @@ Component for viewing Web pages.
{:.events}
{:id="WebViewer.BeforePageLoad"} BeforePageLoad(*url*{:.text})
: When a page is about to load this event is run.
{:id="WebViewer.PageLoaded"} PageLoaded(*url*{:.text})
: When a page is finished loading this event is run.
...
...
@@ -1724,6 +1727,10 @@ Component for viewing Web pages.
when using the `
WebViewer
` to poll a page that may not be sending
appropriate cache control headers.
{:id="WebViewer.ClearCookies" class="method"} <i/> ClearCookies()
: Clear the webview's cookies. This is useful if you want to
sign the user out of a website that uses them to store logins.
{:id="WebViewer.ClearLocations" class="method"} <i/> ClearLocations()
: Clear Stored Location permissions. When the geolocation API is used in
the `
WebViewer
`
, the end user is prompted on a per URL basis for whether
...
...
@@ -1745,3 +1752,9 @@ Component for viewing Web pages.
{:id="WebViewer.GoToUrl" class="method"}
<i/>
GoToUrl(
*url*
{:.text})
: Load the page at the given URL.
{:id="WebViewer.Reload" class="method"}
<i/>
Reload()
: Reload 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