use of android.webkit.WebSettings in project DMGameApp by xiaohaibin.
the class WebDetailsActivity method initWeb.
@SuppressLint("SetJavaScriptEnabled")
private void initWeb() {
WebSettings settings = webView.getSettings();
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (progressBar == null) {
return;
}
if (newProgress == 100) {
progressBar.setVisibility(View.GONE);
} else {
if (progressBar.getVisibility() == View.GONE) {
progressBar.setVisibility(View.VISIBLE);
}
progressBar.setProgress(newProgress);
}
}
});
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setUseWideViewPort(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setLoadWithOverviewMode(true);
// 隐藏缩放控件
settings.setDisplayZoomControls(false);
// 解决HTTPS协议下出现的mixed content问题
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setAppCachePath(getCacheDir().getPath());
settings.setAppCacheEnabled(true);
showWebData();
}
use of android.webkit.WebSettings in project Osmand by osmandapp.
the class ContextMenuHelper method showWiki.
private static void showWiki(final Context ctx, final SampleApplication app, final Amenity a, final String lang) {
String preferredLang = lang;
if (Algorithms.isEmpty(preferredLang)) {
preferredLang = SampleApplication.LANGUAGE;
}
final Dialog dialog = new Dialog(ctx, R.style.AppTheme);
final String title = Algorithms.isEmpty(lang) ? a.getName() : a.getName(lang);
LinearLayout ll = new LinearLayout(ctx);
ll.setOrientation(LinearLayout.VERTICAL);
final Toolbar topBar = new Toolbar(ctx);
topBar.setClickable(true);
Drawable back = app.getIconsCache().getIcon(R.drawable.ic_arrow_back);
topBar.setNavigationIcon(back);
topBar.setNavigationContentDescription(app.getString("access_shared_string_navigate_up"));
topBar.setTitle(title);
topBar.setBackgroundColor(ContextCompat.getColor(ctx, R.color.osmand_orange));
topBar.setTitleTextColor(ContextCompat.getColor(ctx, R.color.color_white));
String lng = a.getContentLanguage("content", preferredLang, "en");
if (Algorithms.isEmpty(lng)) {
lng = "en";
}
final String langSelected = lng;
String content = a.getDescription(langSelected);
final Button bottomBar = new Button(ctx);
bottomBar.setText(app.getString("read_full_article"));
bottomBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String article = "https://" + langSelected.toLowerCase() + ".wikipedia.org/wiki/" + title.replace(' ', '_');
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(article));
ctx.startActivity(i);
}
});
MenuItem mi = topBar.getMenu().add(langSelected.toUpperCase()).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
showPopupLangMenu(ctx, topBar, app, a, dialog, langSelected);
return true;
}
});
MenuItemCompat.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_ALWAYS);
topBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
dialog.dismiss();
}
});
final WebView wv = new WebView(ctx);
WebSettings settings = wv.getSettings();
settings.setDefaultTextEncodingName("utf-8");
// Zooming does not work ok here
settings.setBuiltInZoomControls(false);
settings.setDisplayZoomControls(false);
// Scale web view font size with system font size
float scale = ctx.getResources().getConfiguration().fontScale;
if (android.os.Build.VERSION.SDK_INT >= 14) {
settings.setTextZoom((int) (scale * 100f));
} else {
if (scale <= 0.7f) {
settings.setTextSize(WebSettings.TextSize.SMALLEST);
} else if (scale <= 0.85f) {
settings.setTextSize(WebSettings.TextSize.SMALLER);
} else if (scale <= 1.0f) {
settings.setTextSize(WebSettings.TextSize.NORMAL);
} else if (scale <= 1.15f) {
settings.setTextSize(WebSettings.TextSize.LARGER);
} else {
settings.setTextSize(WebSettings.TextSize.LARGEST);
}
}
wv.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);
// wv.loadUrl(OsMoService.SIGN_IN_URL + app.getSettings().OSMO_DEVICE_KEY.get());
ScrollView scrollView = new ScrollView(ctx);
ll.addView(topBar);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0);
lp.weight = 1;
ll.addView(scrollView, lp);
ll.addView(bottomBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
scrollView.addView(wv);
dialog.setContentView(ll);
wv.setFocusable(true);
wv.setFocusableInTouchMode(true);
wv.requestFocus(View.FOCUS_DOWN);
wv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
});
dialog.setCancelable(true);
dialog.show();
}
use of android.webkit.WebSettings in project Now by XunMengWinter.
the class WebActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
ButterKnife.bind(this);
mContext = this;
mUrl = getIntent().getStringExtra(EXTRA_URL);
mTitle = getIntent().getStringExtra(EXTRA_TITLE);
picUrl = getIntent().getStringExtra(EXTRA_PIC_URL);
summary = getIntent().getStringExtra(EXTRA_SUMMARY);
new Thread() {
@Override
public void run() {
super.run();
// }
try {
Drawable drawable = Glide.with(WebActivity.this).load(picUrl).submit(120, 120).get();
bitmap = ImageUtil.drawableToBitmap(drawable);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}.start();
mWebView.setWebChromeClient(new ChromeClient());
mWebView.setWebViewClient(new ViewClient());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(new PreferencesHelper(App.getInstance()).isJSEnabled());
webSettings.setLoadWithOverviewMode(true);
webSettings.setAppCacheEnabled(true);
webSettings.setAppCachePath(Constants.WEB_CACHE_DIR);
if (NowAppUtil.isWifiConnected())
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
else
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
mWebView.loadUrl(mUrl);
mWebView.setOnTouchListener(this);
setTitle(mTitle);
mFloatingActionButton.setVisibility(View.GONE);
}
use of android.webkit.WebSettings in project Memento-Calendar by alexstyl.
the class FacebookWebView method setup.
private void setup() {
((MementoApplication) getContext().getApplicationContext()).getApplicationModule().inject(this);
clearCache(false);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true);
addJavascriptInterface(new FacebookJavaScriptInterface(), "HTMLOUT");
client = new FBImportClient(this);
setWebViewClient(client);
}
use of android.webkit.WebSettings in project braintree_android by braintree.
the class ThreeDSecureWebViewUnitTest method init_setsWebSettings.
@Test
public void init_setsWebSettings() {
mThreeDSecureWebView.init(mActivity);
WebSettings settings = mThreeDSecureWebView.getSettings();
assertEquals(BraintreeHttpClient.getUserAgent(), settings.getUserAgentString());
assertEquals(WebSettings.LOAD_CACHE_ELSE_NETWORK, settings.getCacheMode());
assertTrue(settings.supportMultipleWindows());
assertTrue(settings.getJavaScriptEnabled());
assertTrue(settings.getBuiltInZoomControls());
assertFalse(settings.getDisplayZoomControls());
assertTrue(settings.getDomStorageEnabled());
assertTrue(settings.getDatabaseEnabled());
}
Aggregations