List of usage examples for android.webkit WebView setWebContentsDebuggingEnabled
public static void setWebContentsDebuggingEnabled(boolean enabled)
From source file:com.example.user.anniefyppostcard.fragments.AbstractArchitectCamFragmentV4.java
@SuppressLint("NewApi") @Override/* www .j a va 2s . com*/ public void onActivityCreated(final Bundle bundle) { super.onActivityCreated(bundle); // set architectView, important for upcoming lifecycle calls this.architectView = (ArchitectView) this.getView().findViewById(getArchitectViewId()); // pass license key to architectView while creating it final StartupConfiguration config = new StartupConfiguration(this.getWikitudeSDKLicenseKey(), ArchitectView.getSupportedFeaturesForDevice(getActivity())); // forwards mandatory life-cycle-events, unfortunately there is no onPostCreate() event in fragments so we have to call it that way try { /* first mandatory life-cycle notification */ this.architectView.onCreate(config); this.architectView.onPostCreate(); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getActivity().getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT) .show(); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); } /* * this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml * If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. * You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. * Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } try { // load architectView's content this.architectView.load(this.getARchitectWorldPath()); if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) { // set the culling distance - meaning: the maximum distance to render geo-content this.architectView.setCullingDistance(this.getInitialCullingDistanceMeters()); } } catch (IOException e) { // unexpected, if error occurs here your path is invalid e.printStackTrace(); } // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { if (location != null) { AbstractArchitectCamFragmentV4.this.lastKnownLocaton = location; if (AbstractArchitectCamFragmentV4.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener this.sensorAccuracyListener = this.getSensorAccuracyListener(); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null) { this.architectView.registerUrlListener(this.getUrlListener()); } // locationProvider used to fetch user position this.locationProvider = this.getLocationProvider(this.locationListener); }
From source file:com.wikitude.samples.AbstractArchitectCamFragmentV4.java
@SuppressLint("NewApi") @Override// w w w .ja va 2 s.co m public void onActivityCreated(final Bundle bundle) { super.onActivityCreated(bundle); // set architectView, important for upcoming lifecycle calls this.architectView = (ArchitectView) this.getView().findViewById(getArchitectViewId()); // pass license key to architectView while creating it final ArchitectStartupConfiguration config = new ArchitectStartupConfiguration(); config.setLicenseKey(this.getWikitudeSDKLicenseKey()); config.setFeatures(ArchitectView.getSupportedFeaturesForDevice(getActivity())); config.setCameraResolution(CameraSettings.CameraResolution.SD_640x480); // forwards mandatory life-cycle-events, unfortunately there is no onPostCreate() event in fragments so we have to call it that way try { /* first mandatory life-cycle notification */ this.architectView.onCreate(config); this.architectView.onPostCreate(); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getActivity().getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT) .show(); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); } /* * this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml * If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. * You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. * Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } try { // load architectView's content this.architectView.load(this.getARchitectWorldPath()); if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) { // set the culling distance - meaning: the maximum distance to render geo-content this.architectView.setCullingDistance(this.getInitialCullingDistanceMeters()); } } catch (IOException e) { // unexpected, if error occurs here your path is invalid e.printStackTrace(); } // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { if (location != null) { AbstractArchitectCamFragmentV4.this.lastKnownLocaton = location; if (AbstractArchitectCamFragmentV4.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener this.sensorAccuracyListener = this.getSensorAccuracyListener(); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null) { this.architectView.registerUrlListener(this.getUrlListener()); } // locationProvider used to fetch user position this.locationProvider = this.getLocationProvider(this.locationListener); }
From source file:com.wikitude.virtualhome.AugmentedActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_augmented); this.setTitle("AR Virtual Home"); markerPresent = getIntent().getStringExtra("MarkerPresent"); imagePath = getIntent().getStringExtra("ImagePath"); productID = getIntent().getStringExtra("productid"); PastTransaction = getIntent().getStringArrayExtra("PastTransaction"); System.out.println("array length" + PastTransaction.length); Log.e(TAG, "VIRTUALHOME: User has marker?" + markerPresent); Log.e(TAG, "VIRTUALHOME: User selected image path:" + imagePath); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); }/*w w w . j a v a2s .c o m*/ } this.architectView = (ArchitectView) this.findViewById(R.id.architectView); // To use the Wikitude Android SDK you need to provide a valid license key to the onCreate lifecycle-method of the ArchitectView. // This can either be done directly by providing the key as a string and the call the onCreate(final String key) method or creating an // StartupConfiguration object, passing it the license as a string and then call the onCreate(final StartupConfiguration config) method. // Please refer to the AbstractArchitectCamActivity of the SDK Examples project for a practical example of how to set the license key. final StartupConfiguration config = new StartupConfiguration(WIKITUDE_5_0_SDK_KEY, StartupConfiguration.Features.Tracking2D, StartupConfiguration.CameraPosition.BACK); try { this.architectView.onCreate(config); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT).show(); Log.e(this.getClass().getName(), "VIRTUALHOME: Exception in ArchitectView.onCreate()", rex); } Log.e(this.getClass().getName(), " VIRTUALHOME: Assigning UrlListener"); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null && this.architectView != null) { Log.e(this.getClass().getName(), " VIRTUALHOME: Call registerUrlListener"); this.architectView.registerUrlListener(this.urlListener); } }
From source file:org.eyeseetea.malariacare.MonitorActivity.java
private WebView initMonitor() { webView = (WebView) findViewById(R.id.dashboard_monitor); //Init webView settings if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); }/* w w w . j a v a 2s. co m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } webView.getSettings().setJavaScriptEnabled(true); return webView; }
From source file:com.msopentech.thali.utilities.android.AndroidXmlHttpRequestTestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); webView = new WebView(this); //TODO: Oh, this is all a huge security hole. webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setDatabaseEnabled(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.getSettings().setAllowContentAccess(true); webView.getSettings().setLoadsImagesAutomatically(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); }//from ww w. j av a 2s .c om webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e("xmlhttptest", "errorCode: " + errorCode + ", description: " + description + ", failingUrl: " + failingUrl); super.onReceivedError(view, errorCode, description, failingUrl); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { Log.e("xmlhttptest", consoleMessage.message() + " - " + consoleMessage.messageLevel().toString() + " - " + consoleMessage.lineNumber() + " - " + consoleMessage.sourceId()); return false; } }); bridgeManager = new AndroidBridgeManager(this, webView); }
From source file:de.htw.ar.treasurehuntar.AbstractArchitectActivity.java
/** * Called when the activity is first created. *///from www . j av a2 s. co m @SuppressLint("NewApi") @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // pressing volume up/down should cause music volume changes this.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.setContentView(this.getContentViewId()); this.setTitle(this.getActivityTitle()); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Log.i("architect", "create"); mGestureDetector = createGestureDetector(this); // // this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml // If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. // You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. // Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } // set AR-view for life-cycle notifications etc. this.architectView = (ArchitectView) this.findViewById(this.getArchitectViewId()); // pass SDK key if you have one, this one is only valid for this package identifier and must not be used somewhere else final ArchitectConfig config = new ArchitectConfig(this.getWikitudeSDKLicenseKey()); try { // first mandatory life-cycle notification this.architectView.onCreate(config); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT).show(); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); } // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener this.sensorAccuracyListener = this.getSensorAccuracyListener(); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null && this.architectView != null) { this.architectView.registerUrlListener(this.getUrlListener()); } // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { // forward location updates fired by LocationProvider to architectView, you can set lat/lon from any location-strategy if (location != null) { Log.i("location", location.toString()); // sore last location as member, in case it is needed somewhere (in e.g. your adjusted project) AbstractArchitectActivity.this.lastKnownLocation = location; if (AbstractArchitectActivity.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { AbstractArchitectActivity.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { AbstractArchitectActivity.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // locationProvider used to fetch user position this.locationProvider = new LocationProvider(this, this.locationListener); }
From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java
/** Called when the activity is first created. */ @SuppressLint("NewApi") @Override//from w w w. ja va 2s . co m public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); /* pressing volume up/down should cause music volume changes */ this.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.setTitle(this.getActivityTitle()); /* * this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml * If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. * You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. * Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } kmlFile = getIntent().getData(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.CAMERA, android.Manifest.permission.ACCESS_FINE_LOCATION }, 101); } else { try { this.setContentView(this.getContentViewId()); initArView(); } catch (Exception rex) { this.architectView = null; AbstractArchitectCamActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(AbstractArchitectCamActivity.this, "AR not supported by this device.", Toast.LENGTH_LONG).show(); } }); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); finish(); } } }
From source file:de.storyquest.client.ContentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // enable immersive mode getWindow().getDecorView()// w w w . ja v a2s. c o m .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); getWindow().addFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); // load initial layout setContentView(R.layout.activity_content); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); View header = navigationView.getHeaderView(0); // apply theme try { Drawable d = Drawable.createFromStream(getAssets().open("sidebar.jpg"), null); navigationView.setBackground(d); } catch (Exception e) { throw new RuntimeException(e); } // wire the drawer open event to the character sheet refresh DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer != null) { drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); execJavaScriptInCharactersheet("if(typeof refresh!='undefined')refresh()"); } }); } // get extra data with bookmark to load Intent intent = getIntent(); if (intent.hasExtra(BOOKMARKID)) bookmarkId = intent.getStringExtra(BOOKMARKID); // set the cover image from assets ImageView coverImage = (ImageView) header.findViewById(R.id.coverImage); try { InputStream ims = getAssets().open("cover.png"); Drawable d = Drawable.createFromStream(ims, null); coverImage.setImageDrawable(d); } catch (Exception e) { throw new RuntimeException("Error loading cover image. Is 'cover.png' available in assets?", e); } // make the web content debuggable from external chrome tools WebView.setWebContentsDebuggingEnabled(true); // enable script interfaces scriptSystem = new ScriptSystem(this); scriptStorage = new ScriptStorage(this, getApplicationContext().getSharedPreferences(ScriptStorage.CONTEXT, Context.MODE_PRIVATE)); scriptSound = new ScriptSound(this); scriptGameServices = new ScriptGameServices(this); // setup character webview character = (WebView) header.findViewById(R.id.characterView); character.getSettings().setJavaScriptEnabled(true); character.getSettings().setDomStorageEnabled(true); character.getSettings().setAllowFileAccess(true); character.getSettings().setAppCacheEnabled(true); character.addJavascriptInterface(scriptSystem, "sqSystem"); character.addJavascriptInterface(scriptStorage, "nativeStorage"); character.addJavascriptInterface(scriptSound, "sqSound"); character.addJavascriptInterface(scriptGameServices, "sqGameServices"); character.loadUrl("file:///android_asset/character.html"); // setup web view web = (WebView) findViewById(R.id.webView); web.getSettings().setJavaScriptEnabled(true); web.getSettings().setDomStorageEnabled(true); web.getSettings().setAllowFileAccess(true); web.getSettings().setAppCacheEnabled(true); web.addJavascriptInterface(scriptSystem, "sqSystem"); web.addJavascriptInterface(scriptStorage, "nativeStorage"); web.addJavascriptInterface(scriptSound, "sqSound"); web.addJavascriptInterface(scriptGameServices, "sqGameServices"); // adding event overrides for the web view web.setWebChromeClient(new WebChromeClient()); web.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String urlText) { if (urlText.startsWith("http")) { // Could be cleverer and use a regex Log.d(LOGTAG, "Opening standard web intent window for " + urlText); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlText)); startActivity(i); return true; } else { Log.d(LOGTAG, "Loading in webview: " + urlText); web.loadUrl(urlText); return true; } } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { Log.d(LOGTAG, "Page rendering started: " + url + "."); displaySpinner(R.string.loading); super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { Log.d(LOGTAG, "Page rendering finished: " + url + "."); hideSpinner(); if (bookmarkId != null && url.startsWith("file:///android_asset/content.html")) { Log.i(LOGTAG, "Loading bookmark " + bookmarkId + "."); execJavaScriptInContent("loadBookmark('" + bookmarkId + "')"); bookmarkId = null; } super.onPageFinished(view, url); } @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { Log.d(LOGTAG, "Intercepted call: " + url + "."); return null; } }); web.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cm) { Log.d(LOGTAG, cm.message() + " - from line " + cm.lineNumber() + " of " + cm.sourceId()); return true; } }); web.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); web.requestFocus(View.FOCUS_DOWN); // finally loading content bootstrap Log.i(LOGTAG, "Loading index.html"); web.loadUrl("file:///android_asset/index.html"); }
From source file:org.eyeseetea.malariacare.fragments.MonitorFragment.java
public WebView initWebView() { webView = (WebView) getActivity().findViewById(R.id.dashboard_monitor); //Init webView settings if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); }//from w w w . jav a 2 s . co m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } webView.getSettings().setJavaScriptEnabled(true); return webView; }
From source file:org.tomahawk.libtomahawk.resolver.ScriptAccount.java
public ScriptAccount(String path, boolean manuallyInstalled) { String prefix = manuallyInstalled ? "file://" : "file:///android_asset"; mPath = prefix + path;/*w w w . ja v a 2s . co m*/ mManuallyInstalled = manuallyInstalled; String[] parts = mPath.split("/"); mName = parts[parts.length - 1]; try { InputStream inputStream; if (mManuallyInstalled) { File metadataFile = new File(path + File.separator + "content" + File.separator + "metadata.json"); inputStream = new FileInputStream(metadataFile); } else { inputStream = TomahawkApp.getContext().getAssets() .open(path.substring(1) + "/content/metadata.json"); } String metadataString = IOUtils.toString(inputStream, Charsets.UTF_8); mMetaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class); if (mMetaData == null) { Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } } catch (IOException e) { Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage()); Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } mWebView = new WebView(TomahawkApp.getContext()); WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { //noinspection deprecation settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath()); } settings.setDomStorageEnabled(true); mWebView.setWebChromeClient(new TomahawkWebChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { //initalize WebView String data = "<!DOCTYPE html>" + "<html>" + "<head><title>" + mName + "</title></head>" + "<body>" + "<script src=\"file:///android_asset/js/rsvp-latest.min.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/cryptojs-core.js" + "\" type=\"text/javascript\"></script>"; if (mMetaData.manifest.scripts != null) { for (String scriptPath : mMetaData.manifest.scripts) { data += "<script src=\"" + mPath + "/content/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } try { String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs"); for (String scriptPath : cryptoJsScripts) { data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } catch (IOException e) { Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage()); } data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk-infosystem.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk_android_post.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"" + mPath + "/content/" + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>"; mWebView.setWebViewClient(new ScriptWebViewClient(ScriptAccount.this)); mWebView.addJavascriptInterface(new ScriptInterface(ScriptAccount.this), SCRIPT_INTERFACE_NAME); mWebView.loadDataWithBaseURL("file:///android_asset/test.html", data, "text/html", null, null); } }); }