AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.WebViewer Class Reference
Inheritance diagram for com.google.appinventor.components.runtime.WebViewer:
com.google.appinventor.components.runtime.AndroidViewComponent com.google.appinventor.components.runtime.VisibleComponent com.google.appinventor.components.runtime.Component

Classes

class  WebViewInterface
 

Public Member Functions

 WebViewer (ComponentContainer container)
 
String WebViewString ()
 
void WebViewString (String newString)
 
View getView ()
 
void Width (int width)
 
void Height (int height)
 
String HomeUrl ()
 
void HomeUrl (String url)
 
String CurrentUrl ()
 
String CurrentPageTitle ()
 
boolean FollowLinks ()
 
void FollowLinks (boolean follow)
 
boolean IgnoreSslErrors ()
 
void IgnoreSslErrors (boolean ignoreSslErrors)
 
void GoHome ()
 
void GoBack ()
 
void GoForward ()
 
boolean CanGoForward ()
 
boolean CanGoBack ()
 
void GoToUrl (String url)
 
void StopLoading ()
 
void Reload ()
 
void UsesLocation (boolean uses)
 
boolean PromptforPermission ()
 
void PromptforPermission (boolean prompt)
 
void ClearLocations ()
 
void ClearCaches ()
 
void ClearCookies ()
 
void RunJavaScript (String js)
 
void WebViewStringChange (String value)
 
void BeforePageLoad (String url)
 
void PageLoaded (String url)
 
void ErrorOccurred (int errorCode, String description, String failingUrl)
 
- Public Member Functions inherited from com.google.appinventor.components.runtime.AndroidViewComponent
boolean Visible ()
 
void Visible (boolean visibility)
 
int Width ()
 
void WidthPercent (int pCent)
 
void setLastWidth (int width)
 
int getSetWidth ()
 
void setLastHeight (int height)
 
int getSetHeight ()
 
void CopyWidth (AndroidViewComponent sourceComponent)
 
int Height ()
 
void HeightPercent (int pCent)
 
void CopyHeight (AndroidViewComponent sourceComponent)
 
int Column ()
 
void Column (int column)
 
int Row ()
 
void Row (int row)
 
HandlesEventDispatching getDispatchDelegate ()
 

Additional Inherited Members

- Static Public Attributes inherited from com.google.appinventor.components.runtime.Component
static final String ASSET_DIRECTORY = "component"
 
static final int ALIGNMENT_NORMAL = 0
 
static final int ALIGNMENT_CENTER = 1
 
static final int ALIGNMENT_OPPOSITE = 2
 
static final int ACCELEROMETER_SENSITIVITY_WEAK = 1
 
static final int ACCELEROMETER_SENSITIVITY_MODERATE = 2
 
static final int ACCELEROMETER_SENSITIVITY_STRONG = 3
 
static final int BUTTON_SHAPE_DEFAULT = 0
 
static final int BUTTON_SHAPE_ROUNDED = 1
 
static final int BUTTON_SHAPE_RECT = 2
 
static final int BUTTON_SHAPE_OVAL = 3
 
static final int COLOR_NONE = 0x00FFFFFF
 
static final int COLOR_BLACK = 0xFF000000
 
static final int COLOR_BLUE = 0xFF0000FF
 
static final int COLOR_CYAN = 0xFF00FFFF
 
static final int COLOR_DKGRAY = 0xFF444444
 
static final int COLOR_GRAY = 0xFF888888
 
static final int COLOR_GREEN = 0xFF00FF00
 
static final int COLOR_LTGRAY = 0xFFCCCCCC
 
static final int COLOR_MAGENTA = 0xFFFF00FF
 
static final int COLOR_ORANGE = 0xFFFFC800
 
static final int COLOR_PINK = 0xFFFFAFAF
 
static final int COLOR_RED = 0xFFFF0000
 
static final int COLOR_WHITE = 0xFFFFFFFF
 
static final int COLOR_YELLOW = 0xFFFFFF00
 
static final int COLOR_DEFAULT = 0x00000000
 
static final String DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF"
 
static final String DEFAULT_VALUE_COLOR_BLACK = "&HFF000000"
 
static final String DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF"
 
static final String DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF"
 
static final String DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444"
 
static final String DEFAULT_VALUE_COLOR_GRAY = "&HFF888888"
 
static final String DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00"
 
static final String DEFAULT_VALUE_COLOR_LTGRAY = "&HFFCCCCCC"
 
static final String DEFAULT_VALUE_COLOR_MAGENTA = "&HFFFF00FF"
 
static final String DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800"
 
static final String DEFAULT_VALUE_COLOR_PINK = "&HFFFFAFAF"
 
static final String DEFAULT_VALUE_COLOR_RED = "&HFFFF0000"
 
static final String DEFAULT_VALUE_COLOR_WHITE = "&HFFFFFFFF"
 
static final String DEFAULT_VALUE_COLOR_YELLOW = "&HFFFFFF00"
 
static final String DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000"
 
static final float FONT_DEFAULT_SIZE = 14
 
static final int LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL
 
static final int LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL
 
static final int SCALING_SCALE_PROPORTIONALLY = 0
 
static final int SCALING_SCALE_TO_FIT = 1
 
static final int TYPEFACE_DEFAULT = 0
 
static final int TYPEFACE_SANSSERIF = 1
 
static final int TYPEFACE_SERIF = 2
 
static final int TYPEFACE_MONOSPACE = 3
 
static final int LENGTH_PREFERRED = -1
 
static final int LENGTH_FILL_PARENT = -2
 
static final int LENGTH_UNKNOWN = -3
 
static final int LENGTH_PERCENT_TAG = -1000
 
static final int TOAST_LENGTH_SHORT = 0
 
static final int TOAST_LENGTH_LONG = 1
 
static final int DIRECTION_NORTH = 1
 
static final int DIRECTION_NORTHEAST = 2
 
static final int DIRECTION_EAST = 3
 
static final int DIRECTION_SOUTHEAST = 4
 
static final int DIRECTION_SOUTH = -1
 
static final int DIRECTION_SOUTHWEST = -2
 
static final int DIRECTION_WEST = -3
 
static final int DIRECTION_NORTHWEST = -4
 
static final int DIRECTION_NONE = 0
 
static final int DIRECTION_MIN = -4
 
static final int DIRECTION_MAX = 4
 
static float SLIDER_MIN_VALUE = 10
 
static float SLIDER_MAX_VALUE = 50
 
static float SLIDER_THUMB_VALUE = (SLIDER_MIN_VALUE + SLIDER_MAX_VALUE) / 2.0f
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_COUNTRY = ""
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_LANGUAGE = ""
 
- Protected Member Functions inherited from com.google.appinventor.components.runtime.AndroidViewComponent
 AndroidViewComponent (ComponentContainer container)
 
- Protected Member Functions inherited from com.google.appinventor.components.runtime.VisibleComponent
 VisibleComponent ()
 
- Protected Attributes inherited from com.google.appinventor.components.runtime.AndroidViewComponent
final ComponentContainer container
 

Detailed Description

Component for viewing Web pages.

WebViewer icon

The HomeUrl() can be specified in the Designer or in the Blocks Editor. The view can be set to follow links when they are tapped, and users can fill in Web forms.

Warning: This is not a full browser. For example, pressing the phone's hardware Back key will exit the app, rather than move back in the browser history.

You can use the WebViewString(String) property to communicate between your app and Javascript code running in the WebViewer page. In the app, you get and set WebViewString(String). In the WebViewer, you include Javascript that references the window.AppInventor object, using the methods getWebViewString() and setWebViewString(text).

For example, if the WebViewer opens to a page that contains the Javascript command

document.write("The answer is" + window.AppInventor.getWebViewString());

and if you set WebViewString(String) to "hello", then the web page will show

The answer is hello.

And if the Web page contains Javascript that executes the command

windowAppInventor.setWebViewString("hello from Javascript"),

then the value of the WebViewString() property will be

hello from Javascript.

Calling setWebViewString from JavaScript will also run the WebViewStringChange(String) event so that the blocks can handle when the WebViewString(String) property changes.

@internaldoc Component for displaying web pages This is a very limited form of browser. You can view web pages and click on links. It also handles Javascript. There are lots of things that could be added, but this component is mostly for viewing individual pages. It's not intended to take the place of the browser.

Author
halab.nosp@m.elso.nosp@m.n@goo.nosp@m.gle..nosp@m.com (Hal Abelson)

Definition at line 107 of file WebViewer.java.

Constructor & Destructor Documentation

◆ WebViewer()

com.google.appinventor.components.runtime.WebViewer.WebViewer ( ComponentContainer  container)

Creates a new WebViewer component.

Parameters
containercontainer the component will be placed in

Definition at line 136 of file WebViewer.java.

Member Function Documentation

◆ BeforePageLoad()

void com.google.appinventor.components.runtime.WebViewer.BeforePageLoad ( String  url)

Definition at line 570 of file WebViewer.java.

◆ CanGoBack()

boolean com.google.appinventor.components.runtime.WebViewer.CanGoBack ( )
Returns
true if the WebViewer can go back in the history list

Definition at line 426 of file WebViewer.java.

◆ CanGoForward()

boolean com.google.appinventor.components.runtime.WebViewer.CanGoForward ( )
Returns
true if the WebViewer can go forward in the history list

Definition at line 416 of file WebViewer.java.

◆ ClearCaches()

void com.google.appinventor.components.runtime.WebViewer.ClearCaches ( )

Clear the internal webview cache, both ram and disk. This is useful when using the WebViewer to poll a page that may not be sending appropriate cache control headers.

Definition at line 531 of file WebViewer.java.

◆ ClearCookies()

void com.google.appinventor.components.runtime.WebViewer.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.

Definition at line 540 of file WebViewer.java.

◆ ClearLocations()

void com.google.appinventor.components.runtime.WebViewer.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 or not permission should be granted to access their location. This function clears this information for all locations.

As the permissions interface is not available on phones older then Eclair, this function is a no-op on older phones.

Definition at line 512 of file WebViewer.java.

◆ CurrentPageTitle()

String com.google.appinventor.components.runtime.WebViewer.CurrentPageTitle ( )

Returns the title of the page currently being viewed

Returns
title of the page being viewed

Definition at line 317 of file WebViewer.java.

◆ CurrentUrl()

String com.google.appinventor.components.runtime.WebViewer.CurrentUrl ( )

Returns the URL currently being viewed. This could be different from the HomeUrl() if new pages were visited by following links.

Returns
URL of the page being viewed

Definition at line 305 of file WebViewer.java.

◆ ErrorOccurred()

void com.google.appinventor.components.runtime.WebViewer.ErrorOccurred ( int  errorCode,
String  description,
String  failingUrl 
)

Definition at line 580 of file WebViewer.java.

◆ FollowLinks() [1/2]

boolean com.google.appinventor.components.runtime.WebViewer.FollowLinks ( )

Indicates whether to follow links when they are tapped in the WebViewer

Returns
true or false

Definition at line 329 of file WebViewer.java.

◆ FollowLinks() [2/2]

void com.google.appinventor.components.runtime.WebViewer.FollowLinks ( boolean  follow)

Determines whether to follow links when they are tapped in the WebViewer. If you follow links, you can use GoBack() and GoForward() to navigate the browser history.

Parameters
follow

Definition at line 342 of file WebViewer.java.

◆ getView()

View com.google.appinventor.components.runtime.WebViewer.getView ( )

Returns the View that is displayed in the UI.

Reimplemented from com.google.appinventor.components.runtime.AndroidViewComponent.

Definition at line 201 of file WebViewer.java.

◆ GoBack()

void com.google.appinventor.components.runtime.WebViewer.GoBack ( )

Go back to the previous page in the history list. Does nothing if there is no previous page.

Definition at line 393 of file WebViewer.java.

◆ GoForward()

void com.google.appinventor.components.runtime.WebViewer.GoForward ( )

Go forward to the next page in the history list. Does nothing if there is no next page.

Definition at line 405 of file WebViewer.java.

◆ GoHome()

void com.google.appinventor.components.runtime.WebViewer.GoHome ( )

Loads the page from the home URL. This happens automatically when home URL is changed.

Definition at line 383 of file WebViewer.java.

◆ GoToUrl()

void com.google.appinventor.components.runtime.WebViewer.GoToUrl ( String  url)

Load the page at the given URL.

Definition at line 436 of file WebViewer.java.

◆ Height()

void com.google.appinventor.components.runtime.WebViewer.Height ( int  height)

Specifies the type%'s vertical height, measured in pixels.

Parameters
heightin pixels

Reimplemented from com.google.appinventor.components.runtime.AndroidViewComponent.

Definition at line 258 of file WebViewer.java.

◆ HomeUrl() [1/2]

String com.google.appinventor.components.runtime.WebViewer.HomeUrl ( )

Returns the URL of the page the WebVewier should load

Returns
URL of the page the WebVewier should load

Definition at line 275 of file WebViewer.java.

◆ HomeUrl() [2/2]

void com.google.appinventor.components.runtime.WebViewer.HomeUrl ( String  url)

Specifies the URL of the page the WebViewer should initially open to. Setting this will load the page.

Parameters
urlURL of the page the WebVewier should load

Definition at line 288 of file WebViewer.java.

◆ IgnoreSslErrors() [1/2]

boolean com.google.appinventor.components.runtime.WebViewer.IgnoreSslErrors ( )

Determine whether or not to ignore SSL errors. Set to true{:.logic.block} to ignore errors. Use this to accept self signed certificates from websites.

Returns
true or false

Definition at line 358 of file WebViewer.java.

◆ IgnoreSslErrors() [2/2]

void com.google.appinventor.components.runtime.WebViewer.IgnoreSslErrors ( boolean  ignoreSslErrors)

Determines whether or not to ignore SSL Errors

@suppressdoc

Parameters
ignoreSslErrorsset to true to ignore SSL errors

Definition at line 371 of file WebViewer.java.

◆ PageLoaded()

void com.google.appinventor.components.runtime.WebViewer.PageLoaded ( String  url)

Definition at line 575 of file WebViewer.java.

◆ PromptforPermission() [1/2]

boolean com.google.appinventor.components.runtime.WebViewer.PromptforPermission ( )

Determine if the user should be prompted for permission to use the geolocation API while in the webviewer.

Returns
true if prompting is required. False assumes permission is granted.

Definition at line 482 of file WebViewer.java.

◆ PromptforPermission() [2/2]

void com.google.appinventor.components.runtime.WebViewer.PromptforPermission ( boolean  prompt)

Determine if the user should be prompted for permission to use the geolocation API while in the WebViewer. If true{:.logic.block}, prompt the user of the WebViewer to give permission to access the geolocation API. If false{:.logic.block}, assume permission is granted.

Parameters
promptset to true to require prompting. False assumes permission is granted.

Definition at line 498 of file WebViewer.java.

◆ Reload()

void com.google.appinventor.components.runtime.WebViewer.Reload ( )

Reload the current page.

Definition at line 454 of file WebViewer.java.

◆ RunJavaScript()

void com.google.appinventor.components.runtime.WebViewer.RunJavaScript ( String  js)

Run JavaScript in the current page.

Definition at line 553 of file WebViewer.java.

◆ StopLoading()

void com.google.appinventor.components.runtime.WebViewer.StopLoading ( )

Stop loading a page.

Definition at line 445 of file WebViewer.java.

◆ UsesLocation()

void com.google.appinventor.components.runtime.WebViewer.UsesLocation ( boolean  uses)

Specifies whether or not this WebViewer can access the JavaScript geolocation API.

Parameters
uses– Whether or not the API is available

Definition at line 469 of file WebViewer.java.

◆ WebViewString() [1/2]

String com.google.appinventor.components.runtime.WebViewer.WebViewString ( )

Gets the WebView's String, which is viewable through Javascript in the WebView as the window.AppInventor object.

Returns
string

Definition at line 186 of file WebViewer.java.

◆ WebViewString() [2/2]

void com.google.appinventor.components.runtime.WebViewer.WebViewString ( String  newString)

Sets the web view string

@suppressdoc

Definition at line 196 of file WebViewer.java.

◆ WebViewStringChange()

void com.google.appinventor.components.runtime.WebViewer.WebViewStringChange ( String  value)

Event that runs when the AppInventor.setWebViewString method is called from JavaScript. The new WebViewString() is given by the value{:.variable.block} parameter.

Parameters
value

Definition at line 565 of file WebViewer.java.

◆ Width()

void com.google.appinventor.components.runtime.WebViewer.Width ( int  width)

Specifies the horizontal width of the type%, measured in pixels.

Parameters
widthin pixels

Reimplemented from com.google.appinventor.components.runtime.AndroidViewComponent.

Definition at line 245 of file WebViewer.java.


The documentation for this class was generated from the following file: