Skip to content

Latest commit

 

History

History
92 lines (53 loc) · 3.15 KB

basics.rst

File metadata and controls

92 lines (53 loc) · 3.15 KB

Basics

In your Javascript environment, an object WS is initialized and injected for you with the methods below. WearScripts run on Glass in a WebView which supports standard browser functionality (e.g., dom manipulation, html5 canvas, cookies, local storage, etc.).

To start WearScript from the "Ok Glass" menu say "Ok Glass, Wear a Script". You can also tap the "Ok Glass" card and scroll to the "Wear a Script" card. Tap playground to connect to the playground, scroll to see other options (e.g., Stop, Setup, Gist Sync, etc.).

scriptVersion(int version) : boolean
Checks if the webview is running on a specific version.
if (WS.scriptVersion(1)) return;
say(String message) : void
Uses Text-to-Speach to read text
WS.say('Welcome to wearscript');
serverConnect(String server, Function callback) : void

Connects to the WearScript server, if given '{{WSUrl}}' as the server it will substitute the user configured server. Some commands require a server connection.

  • Callback takes no parameters and is called when a connection is made, if there is a reconnection it will be called again.
WS.serverConnect('{{WSUrl}}', function () {
    WS.say('connected');
});
log(String message) : void
Log a message to the Android log and the JavaScript console of the webapp (if connected to a server).
WS.log('Welcome to wearscript');
sound(String type) : void
Play a stock sound on Glass. One of TAP, DISALLOWED, DISMISSED, ERROR, SELECTED, SUCCESS.
WS.sound('SUCCESS');
shutdown() : void
Shuts down wearscript
WS.shutdown();
activityCreate() : void
Creates a new activity in the foreground and replaces any existing activity (useful for bringing window to the foreground)
WS.activityCreate();
activityDestroy() : void
Destroys the current activity.
WS.activityDestroy();
wake() : void
Wake the screen if it is off, shows whatever was there before (good in combination with WS.activityCreate() to bring it forward).
WS.wake();
liveCardCreate(boolean nonSilent, double period) : void
Creates a live card of your activity, if nonSilent is true then the live card is given focus. Live cards are updated by polling the current activity, creating a rendering, and drawing on the card. The poll rate is set by the period. Live cards can be clicked to open a menu that allows for opening the activity or closing it.
liveCardDestroy() : void
Destroys the live card.
displayWebView() : void
Display the WebView activity (this is the default, reserved for future use when we may have alternate views).