Commit 13188450 authored by Xavier's avatar Xavier
Browse files

two different javascript interfaces

parent ff785197
......@@ -5,12 +5,45 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<script type='text/javascript' src="interface.js"></script>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<link rel="stylesheet" href="theme/default/style.mobile.css" type="text/css">
<!--<script src="OpenLayers.mobile.js"></script>-->
<style>
html, body {
margin : 0;
padding : 0;
height : 100%;
width : 100%;
}
@media only screen and (max-width: 600px) {
html, body {
height : 117%;
}
}
#map {
width : 100%;
position : relative;
height : 100%;
}
.olControlAttribution {
position : absolute;
font-size : 10px;
bottom : 0 !important;
right : 0 !important;
background : rgba(0,0,0,0.1);
font-family : Arial;
padding : 2px 4px;
border-radius : 5px 0 0 0;
}
#title, #tags, #shortdesc {
display: none;
}
</style>
</head>
<body>
<div id="mapdiv"></div>
<div id="map"></div>
<script>
map = new OpenLayers.Map("mapdiv");
map = new OpenLayers.Map("map");
map.addLayer(new OpenLayers.Layer.OSM());
......
......@@ -61,8 +61,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:contentDescription="@string/dummy"
android:visibility="gone" >
android:contentDescription="@string/dummy" >
<ProgressBar
android:id="@+id/progressBarBrowser"
......
......@@ -31,6 +31,7 @@ import cs.si.stavor.simulator.Simulator;
import cs.si.stavor.web.MyResourceClient;
import cs.si.stavor.web.MyUIClient;
import cs.si.stavor.web.WebAppInterface;
import cs.si.stavor.web.WebAppInterfaceXwalk;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.app.DialogFragment;
......@@ -325,9 +326,10 @@ public class MainActivity extends ActionBarActivity implements
browserSettingsMap.setAllowFileAccessFromFileURLs(true);
browserSettingsMap.setAllowUniversalAccessFromFileURLs(true);
((StavorApplication)getApplication()).jsInterface = new WebAppInterface(this, simu.getSimulationResults());
xwalkView.addJavascriptInterface(((StavorApplication)getApplication()).jsInterface, "Android");
xwalkViewOrbit.addJavascriptInterface(((StavorApplication)getApplication()).jsInterface, "Android");
((StavorApplication)getApplication()).jsInterfaceXwalk = new WebAppInterfaceXwalk(this, simu.getSimulationResults());
xwalkView.addJavascriptInterface(((StavorApplication)getApplication()).jsInterfaceXwalk, "Android");
xwalkViewOrbit.addJavascriptInterface(((StavorApplication)getApplication()).jsInterfaceXwalk, "Android");
((StavorApplication)getApplication()).jsInterface = new WebAppInterface(this);
xwalkViewMap.addJavascriptInterface(((StavorApplication)getApplication()).jsInterface, "Android");
MissionReaderDbHelper db_help_tmp;
......@@ -361,7 +363,7 @@ public class MainActivity extends ActionBarActivity implements
this.simulator.reconstruct(this);
//Update javascriptInterface
((StavorApplication)getApplication()).jsInterface.reconstruct(this, simulator.getSimulationResults());
((StavorApplication)getApplication()).jsInterfaceXwalk.reconstruct(this, simulator.getSimulationResults());
//Install the Missions database if not installed yet and store database objects
((StavorApplication)getApplication()).db_help = dataFragment.getDbHelp();
......
......@@ -4,6 +4,7 @@ import com.commonsware.cwac.loaderex.SQLiteCursorLoader;
import cs.si.stavor.database.MissionReaderDbHelper;
import cs.si.stavor.web.WebAppInterface;
import cs.si.stavor.web.WebAppInterfaceXwalk;
import android.app.Application;
import android.database.sqlite.SQLiteDatabase;
......@@ -22,6 +23,7 @@ public class StavorApplication extends Application {
public int modelViewId = R.id.menu_views_ref_frame_xyz;
WebAppInterfaceXwalk jsInterfaceXwalk;
WebAppInterface jsInterface;
public void setSearchTerm(String searchTerm) {
......
package cs.si.stavor.fragments;
import org.xwalk.core.XWalkView;
import cs.si.stavor.R;
import cs.si.stavor.MainActivity;
import cs.si.stavor.model.Browsers;
......@@ -20,7 +18,6 @@ import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
* Fragment with the visualization browser for the map
......
package cs.si.stavor.web;
import cs.si.stavor.R;
import cs.si.stavor.MainActivity;
import cs.si.stavor.fragments.HudFragment;
import cs.si.stavor.fragments.OrbitFragment;
import cs.si.stavor.model.ModelSimulation;
import android.app.Activity;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
//import org.chromium.content.browser.JavascriptInterface;
import org.xwalk.core.JavascriptInterface;
/**
* JavaScript-to-Android bridge functions
* @author Xavier Gibert
......@@ -24,12 +13,10 @@ import org.xwalk.core.JavascriptInterface;
*/
public final class WebAppInterface {
Activity activity;
private ModelSimulation sim;
/** Instantiate the interface and set the context */
public WebAppInterface(Activity a, ModelSimulation s) {
public WebAppInterface(Activity a) {
activity = a;
sim = s;
}
/** Show a toast from the web page */
......@@ -38,32 +25,6 @@ public final class WebAppInterface {
Toast.makeText(activity.getApplicationContext(), toast, Toast.LENGTH_LONG).show();
}
/** Set loading progress (0-100) from the web page */
@JavascriptInterface
public void setProgress(final int progress) {
if(progress==100)
((MainActivity)activity).getSimulator().setBrowserLoaded(true);
activity.runOnUiThread( new Runnable() {
public void run() {
((MainActivity)activity).setBrowserProgressValue(progress * 100);
//activity.setProgress(progress * 100);
}
});
}
/** Set loading progress (0-100) from the web page */
@JavascriptInterface
public void setProgressOrbit(final int progress) {
if(progress==100)
((MainActivity)activity).getSimulator().setBrowserLoaded(true);
activity.runOnUiThread( new Runnable() {
public void run() {
((MainActivity)activity).setBrowserProgressValueOrbit(progress * 100);
//activity.setProgress(progress * 100);
}
});
}
/** Set loading progress (0-100) from the web page */
@JavascriptInterface
public void setProgressMap(final int progress) {
......@@ -76,48 +37,11 @@ public final class WebAppInterface {
}
});
}
/** Update the stats of the web page */
@JavascriptInterface
public void updateFPS(final String stats) {
activity.runOnUiThread( new Runnable() {
public void run() {
try{
((HudFragment)activity.getFragmentManager().findFragmentById(R.id.container)).updateFPS(stats);
}catch(Exception e){
}
try{
((OrbitFragment)activity.getFragmentManager().findFragmentById(R.id.container)).updateFPS(stats);
}catch(Exception e){
}
}
});
}
/** get orbit model initialization */
@JavascriptInterface
public String getInitializationOrbitJSON() {
return sim.getInitializationOrbitJSON();
}
/** get model initialization */
@JavascriptInterface
public String getInitializationJSON() {
return sim.getInitializationJSON();
}
/** get model state */
/*@JavascriptInterface
public String getStateJSON() {
return sim.getStateJSON();
}*/
public void reconstruct(Activity act,
ModelSimulation s) {
activity = act;
sim = s;
}
......
package cs.si.stavor.web;
import cs.si.stavor.R;
import cs.si.stavor.MainActivity;
import cs.si.stavor.fragments.HudFragment;
import cs.si.stavor.fragments.OrbitFragment;
import cs.si.stavor.model.ModelSimulation;
import android.app.Activity;
import android.widget.Toast;
//import org.chromium.content.browser.JavascriptInterface;
import org.xwalk.core.JavascriptInterface;
/**
* JavaScript-to-Android bridge functions
* @author Xavier Gibert
*
*/
public final class WebAppInterfaceXwalk {
Activity activity;
private ModelSimulation sim;
/** Instantiate the interface and set the context */
public WebAppInterfaceXwalk(Activity a, ModelSimulation s) {
activity = a;
sim = s;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(activity.getApplicationContext(), toast, Toast.LENGTH_LONG).show();
}
/** Set loading progress (0-100) from the web page */
@JavascriptInterface
public void setProgress(final int progress) {
if(progress==100)
((MainActivity)activity).getSimulator().setBrowserLoaded(true);
activity.runOnUiThread( new Runnable() {
public void run() {
((MainActivity)activity).setBrowserProgressValue(progress * 100);
//activity.setProgress(progress * 100);
}
});
}
/** Set loading progress (0-100) from the web page */
@JavascriptInterface
public void setProgressOrbit(final int progress) {
if(progress==100)
((MainActivity)activity).getSimulator().setBrowserLoaded(true);
activity.runOnUiThread( new Runnable() {
public void run() {
((MainActivity)activity).setBrowserProgressValueOrbit(progress * 100);
//activity.setProgress(progress * 100);
}
});
}
/** Update the stats of the web page */
@JavascriptInterface
public void updateFPS(final String stats) {
activity.runOnUiThread( new Runnable() {
public void run() {
try{
((HudFragment)activity.getFragmentManager().findFragmentById(R.id.container)).updateFPS(stats);
}catch(Exception e){
}
try{
((OrbitFragment)activity.getFragmentManager().findFragmentById(R.id.container)).updateFPS(stats);
}catch(Exception e){
}
}
});
}
/** get orbit model initialization */
@JavascriptInterface
public String getInitializationOrbitJSON() {
return sim.getInitializationOrbitJSON();
}
/** get model initialization */
@JavascriptInterface
public String getInitializationJSON() {
return sim.getInitializationJSON();
}
/** get model state */
/*@JavascriptInterface
public String getStateJSON() {
return sim.getStateJSON();
}*/
public void reconstruct(Activity act,
ModelSimulation s) {
activity = act;
sim = s;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment