// This needs to run before the super's constructor. private static Context setGlobalPrefs(Context context, CordovaPreferences preferences) { LOG.d(TAG, "*** XWalkCordovaView.setGlobalPrefs start"); if (!hasSetStaticPref) { hasSetStaticPref = true; ApplicationInfo ai = null; try { ai = context .getPackageManager() .getApplicationInfo( context.getApplicationContext().getPackageName(), PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } boolean prefAnimatable = preferences == null ? false : preferences.getBoolean("CrosswalkAnimatable", false); boolean manifestAnimatable = ai.metaData == null ? false : ai.metaData.getBoolean("CrosswalkAnimatable"); // Selects between a TextureView (obeys framework transforms applied to view) or a SurfaceView // (better performance). XWalkPreferences.setValue( XWalkPreferences.ANIMATABLE_XWALK_VIEW, prefAnimatable || manifestAnimatable); if ((ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true); } XWalkPreferences.setValue(XWalkPreferences.JAVASCRIPT_CAN_OPEN_WINDOW, true); XWalkPreferences.setValue(XWalkPreferences.ALLOW_UNIVERSAL_ACCESS_FROM_FILE, true); } LOG.d(TAG, "*** XWalkCordovaView.setGlobalPrefs"); return context; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true); setContentView(R.layout.multi_texture_views); RelativeLayout parent = (RelativeLayout) findViewById(R.id.multi_texture_views); textDes = (TextView) findViewById(R.id.multiViews_des); textDes.setText( "This sample demonstrates Multiple TextureViews can be shown" + " in order. A,B,C views are TextureViews, D,E,F views are WebViews, " + "the sort order of A,B,C are the same with D,E,F when rotate or " + "restore the screen. Click \"Resize\" button to enlarge or reduce the views."); mResizeButton = (Button) findViewById(R.id.run_resize); LinearLayout btnLay = (LinearLayout) findViewById(R.id.toolbar2); btnLay.setY(180); btnLay.setX(550); root = (RelativeLayout) findViewById(R.id.root_views); for (int i = 0; i < 3; i++) { XWalkView xWalkView = new XWalkView(this, this); xWalkView.setX(i * 100); xWalkView.setY(130 + (i + 1) * 60); xWalkView.load( null, String.format( "<html><head><meta name='viewport' content='width=device-width'/></head>" + "<body style='background-color: %s;'><h1>%s</h1></body></html>", i % 2 == 0 ? "white" : "grey", i == 0 ? "A" : i == 1 ? "B" : "C")); root.addView(xWalkView, 200, 200); } for (int i = 3; i < 6; i++) { WebView webView = new WebView(this); webView.setX(i * 100); webView.setY(130 + (i + 1) * 60); webView.loadData( String.format( "<html><body style='background-color: %s'><h1>%s</h1></body></html>", i % 2 == 0 ? "white" : "grey", i == 3 ? "D" : i == 4 ? "E" : "F"), "text/html", "utf-8"); root.addView(webView, 200, 200); } setContentView(parent); mResizeButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (sizeFlag) { resize(root, 200, 200); sizeFlag = false; } else { resize(root, 400, 400); sizeFlag = true; } } }); }
@Nullable @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.main_fragment, container, false); this.xWalkWebView = (XWalkView) rootView.findViewById(R.id.xwalk_web_view); // turn on debugging XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true); final AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create(); mProgressBarDialog = ProgressDialog.show( this.getActivity(), getString(R.string.loading_title), getString(R.string.loading_text)); XWalkResourceClient myXWalkResourceClient = new XWalkResourceClient(this.xWalkWebView) { @Override public boolean shouldOverrideUrlLoading(XWalkView view, String url) { // Log.i(Constants.TAG, getString(R.string.url_click_log_text)); // view.load(url, null); // return true; return super.shouldOverrideUrlLoading(view, url); } @Override public void onLoadFinished(XWalkView view, String url) { Log.i(Constants.TAG, getString(R.string.url_load_finished_log_text) + url); if (mProgressBarDialog.isShowing()) { mProgressBarDialog.dismiss(); } super.onLoadFinished(view, url); } @Override public void onReceivedLoadError( XWalkView view, int errorCode, String description, String failingUrl) { Log.e(Constants.TAG, getString(R.string.error) + ": " + description); Toast.makeText( ETMainFragment.this.getActivity(), getString(R.string.error_toast) + description, Toast.LENGTH_SHORT) .show(); alertDialog.setTitle(getString(R.string.error)); alertDialog.setMessage(description); // TODO: possibly set click listener for positive button alertDialog.show(); super.onReceivedLoadError(view, errorCode, description, failingUrl); } }; xWalkWebView.setResourceClient(myXWalkResourceClient); // WebSettings settings = xWalkWebView.getSettings(); // settings.setJavaScriptEnabled(true); // xWalkWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); // // final AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create(); // mProgressBarDialog = ProgressDialog.show(this.getActivity(), // getString(R.string.loading_title), getString(R.string.loading_text)); // // xWalkWebView.setWebViewClient(new WebViewClient() { // public boolean shouldOverrideUrlLoading(WebView view, String url) { // Log.i(Constants.TAG, getString(R.string.url_click_log_text)); // view.loadUrl(url); // return true; // } // // public void onPageFinished(WebView view, String url) { // Log.i(Constants.TAG, getString(R.string.url_load_finished_log_text) + url); // if (mProgressBarDialog.isShowing()) { // mProgressBarDialog.dismiss(); // } // } // // public void onReceivedError(WebView view, int errorCode, String description, // String failingUrl) { // Log.e(Constants.TAG, getString(R.string.error) + ": " + description); // Toast.makeText(ETMainFragment.this.getActivity(), // getString(R.string.error_toast) + description, Toast.LENGTH_SHORT).show(); // alertDialog.setTitle(getString(R.string.error)); // alertDialog.setMessage(description); // //TODO: possibly set click listener for positive button // alertDialog.show(); // } // }); // xWalkWebView.loadUrl(Constants.URL); xWalkWebView.load(Constants.URL, null); return rootView; }
public void setRemoteDebug(boolean debug) { XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, debug); }