use of android.webkit.WebViewClient in project 91Pop by DanteAndroid.
the class Browse91PornActivity method onCreate.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browse91_porn);
ButterKnife.bind(this);
initAppBar();
isNightModel = dataManager.isOpenNightMode();
historyIdStack = new Stack<>();
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setAppCachePath(AppCacheUtils.getRxCacheDir(context).getAbsolutePath());
mWebView.setWebChromeClient(new InjectedChromeClient("HostApp", HostJsScope.class));
mWebView.setBackgroundColor(0);
mWebView.setBackgroundResource(0);
mWebView.setVisibility(View.INVISIBLE);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("tid=")) {
int starIndex = url.indexOf("tid=");
String tidStr = StringUtils.subString(url, starIndex + 4, starIndex + 10);
if (!TextUtils.isEmpty(tidStr) && TextUtils.isDigitsOnly(tidStr)) {
Long id = Long.parseLong(tidStr);
presenter.loadContent(id, isNightModel);
historyIdStack.push(id);
} else {
Logger.t(TAG).d(tidStr);
showMessage("暂不支持直接打开此链接", TastyToast.INFO);
}
}
return true;
}
});
AppUtils.setColorSchemeColors(context, swipeLayout);
forum91PronItem = (Forum91PronItem) getIntent().getSerializableExtra(Keys.KEY_INTENT_BROWSE_FORUM_91_PORN_ITEM);
presenter.loadContent(forum91PronItem.getTid(), isNightModel);
historyIdStack.push(forum91PronItem.getTid());
imageList = new ArrayList<>();
boolean needShowTip = dataManager.isViewPorn91ForumContentShowTip();
if (needShowTip) {
// showTipDialog();
}
fabFunction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOpenNewForum();
}
});
}
use of android.webkit.WebViewClient in project caronae-android by caronae.
the class FAQFrag method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_faq, container, false);
ButterKnife.bind(this, view);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(Constants.CARONAE_URL_BASE + "faq.html?mobile");
return view;
}
use of android.webkit.WebViewClient in project Diaspora-Webclient by voidcode.
the class ShareActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isNetworkAvailable()) {
if (!this.main_domain.equals("")) {
WebSettings settings = mWeb.getSettings();
// set Javascript
settings.setJavaScriptEnabled(true);
// settings.setRenderPriority(RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_NORMAL);
// set cache size to 8mb by default.
// settings.setAppCacheMaxSize(1024*1024*8);
// settings.setDomStorageEnabled(true);
// settings.setAppCachePath("/data/data/com.voidcode.diasporawebclient/cache");
// settings.setAllowFileAccess(true);
// settings.setAppCacheEnabled(true);
// settings.setBuiltInZoomControls(true);
// load: open new messages
mWeb.loadUrl("https://" + main_domain + "/status_messages/new");
// when you are on eg your default browser and choose 'share with',
// and then choose 'Diaspora-Webclient' it goto here
Intent intent = getIntent();
final Bundle extras = intent.getExtras();
String action = intent.getAction();
if (// if user has
Intent.ACTION_SEND.equals(action)) {
mWeb.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
if (mProgress.isShowing()) {
mProgress.dismiss();
}
// this have to be intent
if (extras.containsKey(Intent.EXTRA_TEXT) && extras.containsKey(Intent.EXTRA_SUBJECT)) {
// get url on the site user will share
final String extraText = (String) extras.get(Intent.EXTRA_TEXT);
// get the url�s title
final String extraSubject = (String) extras.get(Intent.EXTRA_SUBJECT);
// inject share pageurl into 'textarea' via javascript
mWeb.loadUrl("javascript:(function() { " + // make more space to user-message
"document.getElementsByTagName('textarea')[0].style.height='110px'; " + // inject formate bookmark
"document.getElementsByTagName('textarea')[0].innerHTML = '[" + extraSubject + "](" + extraText + ") #bookmark '; " + "})()");
}
}
});
}
} else {
this.finish();
startActivity(new Intent(this, SetupInternetActivity.class));
}
}
}
use of android.webkit.WebViewClient in project Diaspora-Webclient by voidcode.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isNetworkAvailable()) {
// load main domain�s rooturl
SharedPreferences preferences = getSharedPreferences(SETTINGS_FILENAME, MODE_PRIVATE);
this.main_domain = preferences.getString("currentpod", "");
// set the home screen
setContentView(R.layout.main);
mWeb = (WebView) findViewById(R.id.webView_main);
// --------------------------------------------------------------------------//
// start up the webbrowser------------------------------------------------START
// --------------------------------------------------------------------------//
WebSettings settings = mWeb.getSettings();
// set Javascript
settings.setJavaScriptEnabled(true);
// settings.setRenderPriority(RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_NORMAL);
// adds JSInterface class to webview
if (userHasEnableTranslate()) {
mWeb.addJavascriptInterface(new JSInterface(), "jsinterface");
}
// fix to bug 2: cannot reshare
// see: https://github.com/voidcode/Diaspora-Webclient/issues/2
mWeb.setWebChromeClient(new WebChromeClient() {
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
return super.onJsAlert(view, url, message, result);
}
});
mWeb.setWebViewClient(new WebViewClient() {
private String googleapikey;
private String defaultlanguage;
private Matcher matcher;
private Pattern pattern = Pattern.compile("^(https?)://" + main_domain + "[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
// load url
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// this see if the user is trying to open a internel or externel link
if (// if internel(on main_domain) eks: joindiaspora.com
pattern.matcher(url).matches()) {
view.loadUrl(url);
return true;
} else // if user try to open a externel link, then open it in the default webbrowser.
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
return true;
}
}
public void onPageFinished(WebView view, String url) {
// when finish loading page
if (mProgress.isShowing()) {
mProgress.dismiss();
} else {
if (// adds translate link to all post
userHasEnableTranslate()) {
SharedPreferences preferences = getSharedPreferences(TRANSLATE_FILENAME, MODE_PRIVATE);
this.googleapikey = preferences.getString("googleapikey", "microsoft-translator");
// default-language=english
this.defaultlanguage = preferences.getString("defaultlanguage", "en");
// Inject google translate link via javascript into all posts
mWeb.loadUrl("javascript:(function() { " + // get variables "var i=0; "+
"var ltrs=document.getElementsByClassName('ltr'); " + // loop: adds translate buttons to all 'ltr' tags
"for(i=0;i<ltrs.length;i++) " + "{" + // makes new div
"var btn = document.createElement('div'); " + // retrive select post
"var selectpost = encodeURIComponent(ltrs.item(i).innerHTML); " + // "var selectpost = 'google is a search '; "+
"btn.setAttribute('onclick','alert(window.jsinterface.Translate( \"" + main_domain + "\", \"" + this.googleapikey + "\", \"" + this.defaultlanguage + // adds onclick-handler
"\", \"'+selectpost+'\" ));'); " + // adds style
"btn.setAttribute('style','margin:15px 0px 15px 0px;'); " + // adds id
"btn.id='btn_translate_id_'+i; " + // title on link.
"btn.innerHTML='Translate this post'; " + // append new button to post '.ltr'
"ltrs.item(i).appendChild(btn); " + "} " + "})()");
}
}
}
});
// then open SettingsActivity
if (this.main_domain.equals("")) {
startActivity(new Intent(this, PodSettingsActivity.class));
} else {
mProgress = ProgressDialog.show(this, "Stream", "Please wait a moment...");
// goto start or logon pages
this.mWeb.loadUrl("https://" + main_domain + "/stream");
// goto users stream
Toast.makeText(this, "Pod: " + main_domain, Toast.LENGTH_SHORT).show();
}
} else {
// if user don�t have internet
this.finish();
startActivity(new Intent(this, SetupInternetActivity.class));
}
}
use of android.webkit.WebViewClient in project android-classyshark by google.
the class SourceViewerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_source_viewer);
getWindow().getDecorView().setBackgroundColor(Color.BLACK);
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(0xff606060));
String result = "";
try {
String name = getIntent().getStringExtra(ClassesListActivity.SELECTED_CLASS_NAME);
String barName = name.substring(name.lastIndexOf(".") + 1);
bar.setTitle((Html.fromHtml("<font color=\"#FFFF80\">" + barName + "</font>")));
result = getIntent().getStringExtra(ClassesListActivity.SELECTED_CLASS_DUMP);
} catch (Exception e) {
e.printStackTrace();
}
sourceCodeText = result;
sourceCodeText = HtmlEscapers.htmlEscaper().escape(sourceCodeText);
WebView webView = (WebView) findViewById(R.id.source_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDefaultTextEncodingName("utf-8");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
}
});
webView.loadDataWithBaseURL("file:///android_asset/", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><script src=\"run_prettify.js?skin=sons-of-obsidian\"></script></head><body bgcolor=\"#000000\"><pre class=\"prettyprint \">" + sourceCodeText + "</pre></body></html>", "text/html", "UTF-8", null);
}
Aggregations