Skip to content
Snippets Groups Projects
Commit 7a9500f8 authored by Xavier Gibert's avatar Xavier Gibert
Browse files

XWalk JavascriptInterface working, using chromium package.

parent e7ed34ac
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/panel_limit"
android:gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/commentsLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@color/grey2"
android:orientation="vertical" >
</LinearLayout>
<FrameLayout
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<layout.WrappingSlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:content="@+id/content"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewPanelTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="5dp"
android:text="@string/eg_sim_time"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white" />
<ProgressBar
android:id="@+id/progressBarPanelProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50" />
<LinearLayout
android:id="@+id/anglesLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewPanelRoll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.64"
android:text="@string/eg_roll"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" />
<TextView
android:id="@+id/textViewPanelPitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.51"
android:text="@string/eg_pitch"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" />
<TextView
android:id="@+id/textViewPanelYaw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.66"
android:text="@string/eg_yaw"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:id="@+id/velLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewPanelVel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5.01"
android:text="@string/eg_vel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" />
<TextView
android:id="@+id/textViewPanelAccel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2.33"
android:text="@string/eg_accel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" />
</LinearLayout>
<TextView
android:id="@+id/textViewPanelRadium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/eg_radium"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white" />
<TextView
android:id="@+id/textViewPanelMass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mass: 5000.000 Kg"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white" />
</LinearLayout>
</layout.WrappingSlidingDrawer>
</FrameLayout>
</RelativeLayout>
\ No newline at end of file
......@@ -17,10 +17,16 @@ import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.Toast;
/**
......@@ -51,16 +57,36 @@ public final class SphereFragment extends Fragment {
}
public ModelSimulation sim;
XWalkView browser;
LinearLayout commentsLayout;
@SuppressWarnings("deprecation")
@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled", "NewApi" })
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.sphere, container,
View rootView = inflater.inflate(R.layout.sphere_merged, container,
false);
SlidingDrawer drawer = (SlidingDrawer) rootView.findViewById(R.id.slidingDrawer1);
drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(browser.getLayoutParams());
layoutParams.height = browser.getLayoutParams().height/2;
browser.setLayoutParams(layoutParams);
}
});
drawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
public void onDrawerClosed() {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(browser.getLayoutParams());
layoutParams.height = LayoutParams.MATCH_PARENT;
browser.setLayoutParams(layoutParams);
}
});
//XWalkView browser = (XWalkView) rootView.findViewById(R.id.xbrowser);
XWalkView browser = new XWalkView(this.getActivity().getApplicationContext(), this.getActivity());
browser = new XWalkView(this.getActivity().getApplicationContext(), this.getActivity());
XWalkSettings browserSettings = browser.getSettings();
......@@ -87,15 +113,15 @@ public final class SphereFragment extends Fragment {
Toast.makeText(getActivity(), "Oh no! " + description, Toast.LENGTH_LONG).show();
}
});
*/
browser.addJavascriptInterface(new webclient.UAJscriptHandler(null), "unlockingandroid");
browser.addJavascriptInterface(new UANOOP() {}, "unlockingandroid");
browser.addJavascriptInterface(null, "unlockingandroid");
*/
sim = (ModelSimulation) getArguments().getSerializable(ARG_SIM_OBJ);
sim.setCurrentView(rootView);
//browser.addJavascriptInterface(new WebAppInterface(getActivity(), sim), "Android");
LinearLayout commentsLayout=(LinearLayout)rootView.findViewById(R.id.commentsLayout);
browser.addJavascriptInterface(new WebAppInterface(getActivity(), sim), "Android");
commentsLayout=(LinearLayout)rootView.findViewById(R.id.commentsLayout);
commentsLayout.addView(browser);
browser.loadUrl(Parameters.Web.STARTING_PAGE);
......
......@@ -136,14 +136,15 @@ public final class SphereFullFragment extends Fragment {
browser.setWebChromeClient(new webclient.UAChrome(null));
browser.setWebViewClient(new webclient.UAWebViewClient(null));
*/
browser.addJavascriptInterface(new webclient.UAJscriptHandler(null), "unlockingandroid");
browser.addJavascriptInterface(new UANOOP() {}, "unlockingandroid");
browser.addJavascriptInterface(null, "unlockingandroid");*/
browser.addJavascriptInterface(null, "unlockingandroid");
//sim = new ModelSimulation(container.getContext());
sim = (ModelSimulation) getArguments().getSerializable(ARG_SIM_OBJ);
sim.setCurrentView(rootView);
//browser.addJavascriptInterface(new WebAppInterface(getActivity(), sim), "Android");
browser.addJavascriptInterface(new WebAppInterface(getActivity(), sim), "Android");
browser.loadUrl(Parameters.Web.STARTING_PAGE);
......
package layout;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SlidingDrawer;
@SuppressWarnings("deprecation")
public class WrappingSlidingDrawer extends SlidingDrawer {
public WrappingSlidingDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
public WrappingSlidingDrawer(Context context, AttributeSet attrs) {
super(context, attrs);
int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
}
final View handle = getHandle();
final View content = getContent();
measureChild(handle, widthMeasureSpec, heightMeasureSpec);
if (mVertical) {
int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset;
content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode));
heightSpecSize = handle.getMeasuredHeight() + mTopOffset + content.getMeasuredHeight();
widthSpecSize = content.getMeasuredWidth();
if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth();
}
else {
int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec);
widthSpecSize = handle.getMeasuredWidth() + mTopOffset + content.getMeasuredWidth();
heightSpecSize = content.getMeasuredHeight();
if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight();
}
setMeasuredDimension(widthSpecSize, heightSpecSize);
}
private boolean mVertical;
private int mTopOffset;
}
......@@ -6,8 +6,10 @@ import model.ModelSimulation;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
import org.chromium.content.browser.JavascriptInterface;
//import android.webkit.JavascriptInterface; Used for WebView not XWalkView
public class WebAppInterface {
Activity activity;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment