use of android.webkit.WebSettings 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.WebSettings in project Awful.apk by Awful.
the class AwfulWebView method init.
/**
* Do the basic configuration for the app's WebViews.
*/
private void init() {
AwfulPreferences prefs = AwfulPreferences.getInstance();
WebSettings webSettings = getSettings();
setWebChromeClient(new LoggingWebChromeClient());
// explicitly setting this since some people are complaining the screen stays on until they toggle it on and off
setKeepScreenOn(false);
setBackgroundColor(Color.TRANSPARENT);
setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webSettings.setJavaScriptEnabled(true);
webSettings.setDefaultFontSize(prefs.postFontSizeSp);
webSettings.setDefaultFixedFontSize(prefs.postFixedFontSizeSp);
webSettings.setDomStorageEnabled(true);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (DEBUG) {
WebView.setWebContentsDebuggingEnabled(true);
}
if (prefs.inlineWebm || prefs.inlineVines) {
webSettings.setMediaPlaybackRequiresUserGesture(false);
}
if (prefs.inlineTweets) {
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
}
}
use of android.webkit.WebSettings 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.WebSettings 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.WebSettings in project cordova-android-chromeview by thedracle.
the class InAppBrowser method showWebPage.
/**
* Display a new browser with the specified URL.
*
* @param url The url to load.
* @param jsonObject
*/
public String showWebPage(final String url, HashMap<String, Boolean> features) {
// Determine if we should hide the location bar.
showLocationBar = true;
openWindowHidden = false;
if (features != null) {
Boolean show = features.get(LOCATION);
if (show != null) {
showLocationBar = show.booleanValue();
}
Boolean hidden = features.get(HIDDEN);
if (hidden != null) {
openWindowHidden = hidden.booleanValue();
}
}
final CordovaWebView thatWebView = this.webView;
// Create dialog in new thread
Runnable runnable = new Runnable() {
/**
* Convert our DIP units to Pixels
*
* @return int
*/
private int dpToPixels(int dipValue) {
int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics());
return value;
}
public void run() {
// Let's create the main dialog
dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
try {
JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT);
sendUpdate(obj, false);
} catch (JSONException e) {
Log.d(LOG_TAG, "Should never happen");
}
}
});
// Main container layout
LinearLayout main = new LinearLayout(cordova.getActivity());
main.setOrientation(LinearLayout.VERTICAL);
// Toolbar layout
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
toolbar.setHorizontalGravity(Gravity.LEFT);
toolbar.setVerticalGravity(Gravity.TOP);
// Action Button Container layout
RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
actionButtonContainer.setId(1);
// Back button
Button back = new Button(cordova.getActivity());
RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
back.setLayoutParams(backLayoutParams);
back.setContentDescription("Back Button");
back.setId(2);
back.setText("<");
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
goBack();
}
});
// Forward button
Button forward = new Button(cordova.getActivity());
RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
forward.setLayoutParams(forwardLayoutParams);
forward.setContentDescription("Forward Button");
forward.setId(3);
forward.setText(">");
forward.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
goForward();
}
});
// Edit Text Box
edittext = new EditText(cordova.getActivity());
RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
edittext.setLayoutParams(textLayoutParams);
edittext.setId(4);
edittext.setSingleLine(true);
edittext.setText(url);
edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
// Will not except input... Makes the text NON-EDITABLE
edittext.setInputType(InputType.TYPE_NULL);
edittext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
navigate(edittext.getText().toString());
return true;
}
return false;
}
});
// Close button
Button close = new Button(cordova.getActivity());
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
close.setLayoutParams(closeLayoutParams);
forward.setContentDescription("Close Button");
close.setId(5);
close.setText(buttonLabel);
close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
closeDialog();
}
});
// WebView
inAppWebView = new WebView(cordova.getActivity());
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
inAppWebView.setWebViewClient(client);
WebSettings settings = inAppWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setBuiltInZoomControls(true);
/**
* We need to be careful of this line as a future Android release may deprecate it out of existence.
* Can't replace it with the API 8 level call right now as our minimum SDK is 7 until May 2013
*/
// @TODO: replace with settings.setPluginState(android.webkit.WebSettings.PluginState.ON)
settings.setPluginsEnabled(true);
// Toggle whether this is enabled or not!
Bundle appSettings = cordova.getActivity().getIntent().getExtras();
boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
if (enableDatabase) {
String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath);
settings.setDatabaseEnabled(true);
}
settings.setDomStorageEnabled(true);
inAppWebView.loadUrl(url);
inAppWebView.setId(6);
inAppWebView.getSettings().setLoadWithOverviewMode(true);
inAppWebView.getSettings().setUseWideViewPort(true);
inAppWebView.requestFocus();
inAppWebView.requestFocusFromTouch();
// Add the back and forward buttons to our action button container layout
actionButtonContainer.addView(back);
actionButtonContainer.addView(forward);
// Add the views to our toolbar
toolbar.addView(actionButtonContainer);
toolbar.addView(edittext);
toolbar.addView(close);
// Don't add the toolbar if its been disabled
if (getShowLocationBar()) {
// Add our toolbar to our main view/layout
main.addView(toolbar);
}
// Add our webview to our main view/layout
main.addView(inAppWebView);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.setContentView(main);
dialog.show();
dialog.getWindow().setAttributes(lp);
// Show() needs to be called to cause the URL to be loaded
if (openWindowHidden) {
dialog.hide();
}
}
};
this.cordova.getActivity().runOnUiThread(runnable);
return "";
}
Aggregations