wearscript / wearscript-android

JavaScript with Batteries Included for Google Glass
wearscript.com
215 stars 55 forks source link

allow link navigation #230

Closed christiangenco closed 10 years ago

christiangenco commented 10 years ago

When trying to navigate to a new URL like this:

window.location.href="glass2.html";

I was getting the error:

calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

I found the way to fix this on a StackOverflow comment.

christiangenco commented 10 years ago

Hmm, this doesn't seem to load WS callbacks in the new html page.

In glass2.html, for example, I have the line:

WS.sound('SUCCESS');

But on navigating to glass2.html with window.location.href="glass2.html" from glass.html, the success sound doesn't play.

scottgwald commented 10 years ago

Hi Christian,

Thanks. It is possible that this would work, but could you revise the PR with a version that compiles and then test it? You didn't import WebViewClient, so I assume you could not have compiled or tested this?

Thanks

christiangenco commented 10 years ago

Oops - updated. I'm working from a heavily modified local fork and just pushed the relevant bits through Github's online editor.

It definitely makes window.location.href="glass2.html" work, but I'm still having trouble figuring out how to reconnect the WS callbacks to the new page. Any suggestions?

christiangenco commented 10 years ago

Ahh I figured it out! I needed to be using Utils.getEventBus().post(new ScriptEvent(path)); (where path = (new File(Utils.dataPath() + "scripting/" + filename)).getAbsolutePath()), which I set up as a JavascriptInterface method.

Now from within HTML, I can change the view by calling:

WS.loadUrl('glass2.html');

If anyone else is interested in doing this, contact me and I'll assemble a pull request. It's just enough friction for me not to muster the impetus to push here by my own volition :p

scottgwald commented 10 years ago

I think making it work the way you tried the first time would be better. Something like this http://stackoverflow.com/questions/2378800/clicking-urls-opens-default-browser should work. If you feel like looking into that as a solution, we'd love to have your PR.