use of android.webkit.WebChromeClient in project materialistic by hidroh.
the class SubmitActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppUtils.setStatusBarColor(getWindow(), ContextCompat.getColor(this, R.color.blackT12));
setContentView(R.layout.activity_submit);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
//noinspection ConstantConditions
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP);
mTitleLayout = (TextInputLayout) findViewById(R.id.textinput_title);
mContentLayout = (TextInputLayout) findViewById(R.id.textinput_content);
mTitleEditText = (TextView) findViewById(R.id.edittext_title);
mContentEditText = (TextView) findViewById(R.id.edittext_content);
String text, subject;
if (savedInstanceState == null) {
subject = getIntent().getStringExtra(Intent.EXTRA_SUBJECT);
text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
} else {
subject = savedInstanceState.getString(STATE_SUBJECT);
text = savedInstanceState.getString(STATE_TEXT);
}
mTitleEditText.setText(subject);
mContentEditText.setText(text);
if (TextUtils.isEmpty(subject)) {
if (isUrl(text)) {
WebView webView = new WebView(this);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
if (mTitleEditText.length() == 0) {
mTitleEditText.setText(title);
}
}
});
webView.loadUrl(text);
} else if (!TextUtils.isEmpty(text)) {
extractUrl(text);
}
}
}
use of android.webkit.WebChromeClient in project materialistic by hidroh.
the class ReleaseNotesActivity method onCreate.
@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_release);
findViewById(R.id.button_ok).setOnClickListener(v -> finish());
findViewById(R.id.button_rate).setOnClickListener(v -> {
AppUtils.openPlayStore(this);
finish();
});
WebView webView = (WebView) findViewById(R.id.web_view);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.setBackgroundColor(Color.TRANSPARENT);
webView.loadDataWithBaseURL(null, getString(R.string.release_notes, AppUtils.toHtmlColor(this, android.R.attr.textColorPrimary), AppUtils.toHtmlColor(this, android.R.attr.textColorLink)), "text/html", "UTF-8", null);
Preferences.setReleaseNotesSeen(this);
}
use of android.webkit.WebChromeClient in project okhttp-OkGo by jeasonlzy.
the class WebActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
String url = getIntent().getStringExtra(URL);
String title = getIntent().getStringExtra(TITLE);
initToolBar(toolbar, true, title);
pb.setMax(100);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
pb.setProgress(newProgress);
if (newProgress >= 100) {
pb.setVisibility(View.GONE);
}
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl(url);
}
use of android.webkit.WebChromeClient in project Klyph by jonathangerbaud.
the class FaqActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
setTitle(R.string.menu_faq);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
setProgress(progress * 1000);
}
});
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(FaqActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
webView.loadUrl(FAQ_URL);
}
use of android.webkit.WebChromeClient in project superCleanMaster by joyoyao.
the class RelaxFragment method initWebview.
private void initWebview() {
// TODO Auto-generated method stub
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// 设置可以访问文件
webSettings.setAllowFileAccess(true);
// 设置可以支持缩放
webSettings.setSupportZoom(true);
// 设置默认缩放方式尺寸是far
webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
// 设置出现缩放工具
webSettings.setBuiltInZoomControls(false);
webSettings.setDefaultFontSize(20);
// 访问assets目录下的文件
mWebView.loadUrl("http://girl-atlas.com");
// 设置WebViewClient
mWebView.setWebViewClient(new WebViewClient() {
// url拦截
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// 使用自己的WebView组件来响应Url加载事件,而不是使用默认浏览器器加载页面
view.loadUrl(url);
// 相应完成返回true
return true;
// return super.shouldOverrideUrlLoading(view, url);
}
// 页面开始加载
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
mProgressBar.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
// 页面加载完成
@Override
public void onPageFinished(WebView view, String url) {
mProgressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
// WebView加载的所有资源url
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
// 设置WebChromeClient
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public // 处理javascript中的alert
boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
return super.onJsAlert(view, url, message, result);
}
;
@Override
public // 处理javascript中的confirm
boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
return super.onJsConfirm(view, url, message, result);
}
;
@Override
public // 处理javascript中的prompt
boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) {
return super.onJsPrompt(view, url, message, defaultValue, result);
}
;
// 设置网页加载的进度条
@Override
public void onProgressChanged(WebView view, int newProgress) {
mProgressBar.setProgress(newProgress);
super.onProgressChanged(view, newProgress);
}
// 设置程序的Title
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
}
});
mWebView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
// 表示按返回键
// 后退
mWebView.goBack();
// 已处理
return true;
}
}
return false;
}
});
}
Aggregations