List of usage examples for android.webkit WebSettings setAllowFileAccess
public abstract void setAllowFileAccess(boolean allow);
From source file:org.microg.gms.auth.login.LoginActivity.java
@SuppressLint("SetJavaScriptEnabled") private static void prepareWebViewSettings(WebSettings settings) { settings.setUserAgentString(settings.getUserAgentString() + MAGIC_USER_AGENT); settings.setJavaScriptEnabled(true); settings.setSupportMultipleWindows(false); settings.setSaveFormData(false);/*from w w w . j a va 2 s .com*/ settings.setAllowFileAccess(false); settings.setDatabaseEnabled(false); settings.setNeedInitialFocus(false); settings.setUseWideViewPort(false); settings.setSupportZoom(false); settings.setJavaScriptCanOpenWindowsAutomatically(false); }
From source file:com.gh4a.FileViewerActivity.java
private void fillData(boolean highlight) { String data = new String(EncodingUtils.fromBase64(mContent.getContent())); WebView webView = (WebView) findViewById(R.id.web_view); WebSettings s = webView.getSettings(); s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); s.setAllowFileAccess(true); s.setBuiltInZoomControls(true);// w w w . j a v a 2 s . com s.setLightTouchEnabled(true); s.setLoadsImagesAutomatically(true); s.setPluginsEnabled(false); s.setSupportZoom(true); s.setSupportMultipleWindows(true); s.setJavaScriptEnabled(true); s.setUseWideViewPort(true); webView.setWebViewClient(webViewClient); if (FileUtils.isImage(mName)) { String htmlImage = StringUtils.highlightImage( "https://github.com/" + mRepoOwner + "/" + mRepoName + "/raw/" + mRef + "/" + mPath); webView.loadDataWithBaseURL("file:///android_asset/", htmlImage, "text/html", "utf-8", ""); } else { String highlighted = StringUtils.highlightSyntax(data, highlight, mName); webView.loadDataWithBaseURL("file:///android_asset/", highlighted, "text/html", "utf-8", ""); } }
From source file:com.github.snowdream.android.app.books.BookFragment.java
private void initUI(View rootview) { webView = (WebView) rootview.findViewById(R.id.webView); // progressbar = (SmoothProgressBar) rootview.findViewById(R.id.progressbar); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setSupportZoom(true);//www .j a v a 2 s . com webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); String appCachePath = getActivity().getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAppCacheEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // progressbar.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // progressbar.setVisibility(View.INVISIBLE); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); // progressbar.setVisibility(View.INVISIBLE); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); // The "loadAdOnCreate" and "testDevices" XML attributes no longer available. AdView adView = (AdView) rootview.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(TEST_DEVICE_ID).build(); adView.loadAd(adRequest); getView().setFocusableInTouchMode(true); getView().setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (webView.canGoBack() && keyCode == KeyEvent.KEYCODE_BACK) { webView.goBack(); return true; } return false; } }); }
From source file:com.pixate.freestyle.viewdemo.ViewDetailFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override// w ww .ja v a2s .c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_view_detail, container, false); if (mItem != null) { // set the views ViewSample viewSample = mItem.getViewSample(); final ViewGroup viewsHolder = (ViewGroup) rootView.findViewById(R.id.holder); viewSample.createViews(getActivity(), viewsHolder); // load the CSS styling for the sample String css = ViewsData.getCSS(getActivity(), mItem); // Set up syntax highlighting WebView cssView = (WebView) rootView.findViewById(R.id.css_style); WebSettings s = cssView.getSettings(); s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); s.setUseWideViewPort(false); s.setAllowFileAccess(true); s.setBuiltInZoomControls(true); s.setSupportZoom(true); s.setSupportMultipleWindows(false); s.setJavaScriptEnabled(true); StringBuilder contentString = new StringBuilder(); contentString.append("<html><head>"); contentString.append( "<link href='file:///android_asset/prettify/prettify.css' rel='stylesheet' type='text/css'/> "); contentString.append( "<script src='file:///android_asset/prettify/prettify.js' type='text/javascript'></script> "); contentString.append( "<script src='file:///android_asset/prettify/lang-css.js' type='text/javascript'></script> "); contentString.append("</head><body onload='prettyPrint()'><code class='prettyprint lang-css'>"); contentString.append(TextUtils.htmlEncode(css).replaceAll("\n", "<br>").replaceAll(" ", " ") .replaceAll("\t", " ")); contentString.append("</code> </html> "); cssView.getSettings().setUseWideViewPort(true); cssView.loadDataWithBaseURL("file:///android_asset/prettify/", contentString.toString(), "text/html", StringUtil.EMPTY, StringUtil.EMPTY); // to aid in styling the css text shows in the textview, set its // ID. Eventually will not be needed. if (!"css-style".equals(PixateFreestyle.getStyleId(cssView))) { PixateFreestyle.setStyleId(cssView, "css-style", true); } // Style viewSample.style(css); } return rootView; }
From source file:com.androzic.waypoint.WaypointInfo.java
@SuppressLint("NewApi") private void updateWaypointInfo(double lat, double lon) { Androzic application = Androzic.getApplication(); Activity activity = getActivity();/* w w w. j a v a2 s.c o m*/ Dialog dialog = getDialog(); View view = getView(); WebView description = (WebView) view.findViewById(R.id.description); if ("".equals(waypoint.description)) { description.setVisibility(View.GONE); } else { String descriptionHtml; try { TypedValue tv = new TypedValue(); Theme theme = activity.getTheme(); Resources resources = getResources(); theme.resolveAttribute(android.R.attr.textColorSecondary, tv, true); int secondaryColor = resources.getColor(tv.resourceId); String css = String.format( "<style type=\"text/css\">html,body{margin:0;background:transparent} *{color:#%06X}</style>\n", (secondaryColor & 0x00FFFFFF)); descriptionHtml = css + waypoint.description; description.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { view.setBackgroundColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); } }); description.setBackgroundColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) description.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); } catch (Resources.NotFoundException e) { description.setBackgroundColor(Color.LTGRAY); descriptionHtml = waypoint.description; } WebSettings settings = description.getSettings(); settings.setDefaultTextEncodingName("utf-8"); settings.setAllowFileAccess(true); Uri baseUrl = Uri.fromFile(new File(application.dataPath)); description.loadDataWithBaseURL(baseUrl.toString() + "/", descriptionHtml, "text/html", "utf-8", null); } String coords = StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude); ((TextView) view.findViewById(R.id.coordinates)).setText(coords); if (waypoint.altitude != Integer.MIN_VALUE) { ((TextView) view.findViewById(R.id.altitude)).setText(StringFormatter.elevationH(waypoint.altitude)); } double dist = Geo.distance(lat, lon, waypoint.latitude, waypoint.longitude); double bearing = Geo.bearing(lat, lon, waypoint.latitude, waypoint.longitude); bearing = application.fixDeclination(bearing); String distance = StringFormatter.distanceH(dist) + " " + StringFormatter.angleH(bearing); ((TextView) view.findViewById(R.id.distance)).setText(distance); if (waypoint.date != null) ((TextView) view.findViewById(R.id.date)) .setText(DateFormat.getDateFormat(activity).format(waypoint.date) + " " + DateFormat.getTimeFormat(activity).format(waypoint.date)); else ((TextView) view.findViewById(R.id.date)).setVisibility(View.GONE); dialog.setTitle(waypoint.name); }
From source file:com.ap.github.ui.activitys.LoginActivity.java
@SuppressLint("SetJavaScriptEnabled") private void initLoginWebView() { mLoginWebView.setVerticalScrollBarEnabled(false); mLoginWebView.setHorizontalScrollBarEnabled(false); mLoginWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); mLoginWebView.getSettings().setJavaScriptEnabled(true); mLoginWebView.setWebViewClient(new LoginWebViewClient(this)); WebSettings webSettings = mLoginWebView.getSettings(); webSettings.setUseWideViewPort(true); webSettings.setSupportZoom(false);/*from ww w .j a v a 2s.com*/ webSettings.setBuiltInZoomControls(false); webSettings.setAllowFileAccess(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setLoadsImagesAutomatically(true); }
From source file:com.androzic.waypoint.WaypointDetails.java
@SuppressLint("NewApi") private void updateWaypointDetails(double lat, double lon) { Androzic application = Androzic.getApplication(); AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.getSupportActionBar().setTitle(waypoint.name); View view = getView();//w ww .j a va 2 s. co m final TextView coordsView = (TextView) view.findViewById(R.id.coordinates); coordsView.requestFocus(); coordsView.setTag(Integer.valueOf(StringFormatter.coordinateFormat)); coordsView.setText(StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude)); coordsView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int format = ((Integer) coordsView.getTag()).intValue() + 1; if (format == 5) format = 0; coordsView.setText(StringFormatter.coordinates(format, " ", waypoint.latitude, waypoint.longitude)); coordsView.setTag(Integer.valueOf(format)); } }); if (waypoint.altitude != Integer.MIN_VALUE) { ((TextView) view.findViewById(R.id.altitude)) .setText("\u2336 " + StringFormatter.elevationH(waypoint.altitude)); view.findViewById(R.id.altitude).setVisibility(View.VISIBLE); } else { view.findViewById(R.id.altitude).setVisibility(View.GONE); } if (waypoint.proximity > 0) { ((TextView) view.findViewById(R.id.proximity)) .setText("~ " + StringFormatter.distanceH(waypoint.proximity)); view.findViewById(R.id.proximity).setVisibility(View.VISIBLE); } else { view.findViewById(R.id.proximity).setVisibility(View.GONE); } double dist = Geo.distance(lat, lon, waypoint.latitude, waypoint.longitude); double bearing = Geo.bearing(lat, lon, waypoint.latitude, waypoint.longitude); bearing = application.fixDeclination(bearing); String distance = StringFormatter.distanceH(dist) + " " + StringFormatter.angleH(bearing); ((TextView) view.findViewById(R.id.distance)).setText(distance); ((TextView) view.findViewById(R.id.waypointset)).setText(waypoint.set.name); if (waypoint.date != null) { view.findViewById(R.id.date_row).setVisibility(View.VISIBLE); ((TextView) view.findViewById(R.id.date)) .setText(DateFormat.getDateFormat(activity).format(waypoint.date) + " " + DateFormat.getTimeFormat(activity).format(waypoint.date)); } else { view.findViewById(R.id.date_row).setVisibility(View.GONE); } if ("".equals(waypoint.description)) { view.findViewById(R.id.description_row).setVisibility(View.GONE); } else { WebView description = (WebView) view.findViewById(R.id.description); String descriptionHtml; try { TypedValue tv = new TypedValue(); Theme theme = activity.getTheme(); Resources resources = getResources(); theme.resolveAttribute(android.R.attr.textColorPrimary, tv, true); int secondaryColor = resources.getColor(tv.resourceId); String css = String.format( "<style type=\"text/css\">html,body{margin:0;background:transparent} *{color:#%06X}</style>\n", (secondaryColor & 0x00FFFFFF)); descriptionHtml = css + waypoint.description; description.setWebViewClient(new WebViewClient() { @SuppressLint("NewApi") @Override public void onPageFinished(WebView view, String url) { view.setBackgroundColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); } }); description.setBackgroundColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) description.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); } catch (Resources.NotFoundException e) { description.setBackgroundColor(Color.LTGRAY); descriptionHtml = waypoint.description; } WebSettings settings = description.getSettings(); settings.setDefaultTextEncodingName("utf-8"); settings.setAllowFileAccess(true); Uri baseUrl = Uri.fromFile(new File(application.dataPath)); description.loadDataWithBaseURL(baseUrl.toString() + "/", descriptionHtml, "text/html", "utf-8", null); view.findViewById(R.id.description_row).setVisibility(View.VISIBLE); } }
From source file:com.usabusi.newsreader.ArticleFragment.java
/** * Sets up the UI. It consists if a single WebView. *//*from w w w . j ava2 s . co m*/ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mWebView = new WebView(getActivity()); //http://stackoverflow.com/questions/17259537/load-webview-from-cache WebSettings webSettings = mWebView.getSettings(); // Enable JavaScript webSettings.setJavaScriptEnabled(true); // enable javascript mWebView.setHorizontalScrollBarEnabled(false); webSettings.setAppCacheMaxSize(5 * 1024 * 1024); // 5MB webSettings.setAppCachePath(getActivity().getApplicationContext().getCacheDir().getAbsolutePath()); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default //http://stackoverflow.com/questions/25161720/url-opened-in-browser-instead-of-web-view mWebView.setVisibility(View.VISIBLE); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setBuiltInZoomControls(true); //final Activity activity = this; // Make WebClient mWebView.setWebViewClient(new WebViewClient() { // Trace Errors public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(getActivity().getApplicationContext(), description, Toast.LENGTH_SHORT).show(); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //http://developer.android.com/guide/webapps/webview.html#HandlingNavigation // view.loadUrl(url); // return true; return false; } }); loadWebView(); return mWebView; }
From source file:com.quarterfull.newsAndroid.NewsDetailFragment.java
@SuppressLint("SetJavaScriptEnabled") private void init_webView() { int backgroundColor = ColorHelper.getColorFromAttribute(getContext(), R.attr.news_detail_background_color); mWebView.setBackgroundColor(backgroundColor); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setDomStorageEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(false); webSettings.setSupportMultipleWindows(false); webSettings.setSupportZoom(false);// w w w . j a v a 2 s . c o m webSettings.setAppCacheEnabled(true); registerForContextMenu(mWebView); mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage cm) { Log.v(TAG, cm.message() + " at " + cm.sourceId() + ":" + cm.lineNumber()); return true; } @Override public void onProgressChanged(WebView view, int progress) { if (progress < 100 && mProgressbarWebView.getVisibility() == ProgressBar.GONE) { mProgressbarWebView.setVisibility(ProgressBar.VISIBLE); } mProgressbarWebView.setProgress(progress); if (progress == 100) { mProgressbarWebView.setVisibility(ProgressBar.GONE); //The following three lines are a workaround for websites which don't use a background color int bgColor = ContextCompat.getColor(getContext(), R.color.slider_listview_text_color_dark_theme); NewsDetailActivity ndActivity = ((NewsDetailActivity) getActivity()); mWebView.setBackgroundColor(bgColor); ndActivity.mViewPager.setBackgroundColor(bgColor); if (ThemeChooser.isDarkTheme(getActivity())) { mWebView.setBackgroundColor( ContextCompat.getColor(getContext(), android.R.color.transparent)); } } } }); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (changedUrl) { changedUrl = false; if (!url.equals("file:///android_asset/") && (urls.isEmpty() || !urls.get(0).equals(url))) { urls.add(0, url); Log.v(TAG, "Page finished (added): " + url); } } super.onPageStarted(view, url, favicon); } }); mWebView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (v.getId() == R.id.webview && event.getAction() == MotionEvent.ACTION_DOWN) { changedUrl = true; } return false; } }); }
From source file:com.rfo.basic.Web.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.v(LOGTAG, "onCreate"); super.onCreate(savedInstanceState); ContextManager cm = Basic.getContextManager(); cm.registerContext(ContextManager.ACTIVITY_WEB, this); cm.setCurrent(ContextManager.ACTIVITY_WEB); setContentView(R.layout.web);/* ww w .ja va 2 s. c o m*/ View v = findViewById(R.id.web_engine); Intent intent = getIntent(); int showStatusBar = intent.getIntExtra(EXTRA_SHOW_STATUSBAR, 0); int orientation = intent.getIntExtra(EXTRA_ORIENTATION, -1); showStatusBar = (showStatusBar == 0) ? WindowManager.LayoutParams.FLAG_FULLSCREEN // do not show status bar : WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; // show status bar getWindow().setFlags(showStatusBar, showStatusBar); setOrientation(orientation); engine = (WebView) v; WebSettings webSettings = engine.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setAppCacheEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setGeolocationEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); engine.addJavascriptInterface(new JavaScriptInterface(), "Android"); engine.setWebViewClient(new MyWebViewClient()); aWebView = new TheWebView(this); engine.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { //Required functionality here return super.onJsAlert(view, url, message, result); } }); }