use of android.webkit.WebView in project android-app-common-tasks by multidots.
the class ClientPostActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prevent_click);
Button btnShare = (Button) findViewById(R.id.btnShare);
WebView webview = (WebView) findViewById(R.id.webView);
webview.loadUrl("file:///android_asset/post.html");
// TextView tvCode = (TextView) findViewById(R.id.prevent_double_click_tv_code);
// tvCode.setText(
// " /**\n" +
// " * This is used for post data from API.\n" +
// " *\n" +
// " * @author Mayank\n" +
// " * @since 1.4\n" +
// " */\n" +
// "public class MyClientPost extends AsyncTask<Map<String, Object>, String, String> {\n" +
// "\n" +
// " public ProgressDialog dialog;\n" +
// " private String message;\n" +
// " private Context context;\n" +
// " private OnPostCallComplete onpostcallcomplete;\n" +
// " private JSONObject jsonResult;\n" +
// "\n" +
// " public MyClientPost(Context context, String progressMessage, OnPostCallComplete onPostCallComplete2) {\n" +
// " message = progressMessage;\n" +
// " this.context = context;\n" +
// " this.onpostcallcomplete = onPostCallComplete2;\n" +
// "\n" +
// " if (!(message.equals(\"\"))) {\n" +
// " dialog = new ProgressDialog(context);\n" +
// " dialog.setMessage(progressMessage);\n" +
// " }\n" +
// " }\n" +
// "\n" +
// " @Override\n" +
// " protected void onPreExecute() {\n" +
// " // TODO Auto-generated method stub\n" +
// " super.onPreExecute();\n" +
// " if (!(message.equals(\"\"))) {\n" +
// " dialog.setCancelable(false);\n" +
// " dialog.show();\n" +
// " }\n" +
// " }\n" +
// "\n" +
// " @Override\n" +
// " protected String doInBackground(Map<String, Object>... params) {\n" +
// " String result = null;\n" +
// "\n" +
// " if (!isCancelled()) {\n" +
// "\n" +
// " Map<String, Object> passed_params = params[0];\n" +
// " // API call URL\n" +
// " String serverUrl = (String) passed_params.get(\"url\");\n" +
// " Log.v(Utils.TAG, \"API url: \" + serverUrl);\n" +
// " // parameter data to send\n" +
// " @SuppressWarnings(\"unchecked\")\n" +
// " Map<String, String> methodParameter = (Map<String, String>) passed_params.get(\"method_parameters\");\n" +
// " try {\n" +
// " HttpClient client = new DefaultHttpClient();\n" +
// " HttpPost post = new HttpPost(serverUrl);\n" +
// "\n" +
// " Iterator<Entry<String, String>> iterator = methodParameter.entrySet().iterator();\n" +
// " List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(methodParameter.size());\n" +
// " while (iterator.hasNext()) {\n" +
// " Entry<String, String> param = iterator.next();\n" +
// " nameValuePairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));\n" +
// " }\n" +
// " Log.v(Utils.TAG, \"post latlng \" + nameValuePairs.toString());\n" +
// " UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nameValuePairs);\n" +
// " post.setEntity(entity);\n" +
// " HttpResponse response = client.execute(post);\n" +
// " HttpEntity resp_entity = response.getEntity();\n" +
// " result = EntityUtils.toString(resp_entity);\n" +
// " // System.out.println(\"result in post 80: \"+result);\n" +
// " if (response.getStatusLine().getStatusCode() != 200) {\n" +
// " Log.v(Utils.TAG, \"post status code \" + response.getStatusLine().getStatusCode());\n" +
// " jsonResult = new JSONObject();\n" +
// " jsonResult.put(\"response_code\", \"9999\");\n" +
// " jsonResult.put(\"response_message\", \"85 Server error occurred while processing request. Please try again.\");\n" +
// " result = jsonResult.toString();\n" +
// " return result;\n" +
// " }\n" +
// " } catch (Exception e) {\n" +
// " Log.v(Utils.TAG, \"post exception \" + e.getMessage());\n" +
// " try {\n" +
// " jsonResult = new JSONObject();\n" +
// " jsonResult.put(\"response_code\", \"9999\");\n" +
// " jsonResult.put(\"response_message\", \"94 Server error occurred while processing request. Please try again.\");\n" +
// " result = jsonResult.toString();\n" +
// " return result;\n" +
// " } catch (JSONException jsone) {\n" +
// " jsone.printStackTrace();\n" +
// " }\n" +
// " }\n" +
// " }\n" +
// " //System.out.println(\"result in post: \"+result);\n" +
// " return result;\n" +
// " }\n" +
// "\n" +
// " @Override\n" +
// " protected void onPostExecute(String result) {\n" +
// " // TODO Auto-generated method stub\n" +
// " super.onPostExecute(result);\n" +
// " if (!(message.equals(\"\"))) {\n" +
// " if (dialog != null) {\n" +
// " dialog.hide();\n" +
// " dialog.dismiss();\n" +
// " }\n" +
// " }\n" +
// " System.out.println(\"result in onPostExecute: \" + result);\n" +
// " try {\n" +
// " onpostcallcomplete.response(result);\n" +
// " } catch (JSONException e) {\n" +
// " e.printStackTrace();\n" +
// " }\n" +
// " }\n" +
// "\n" +
// " public interface OnPostCallComplete {\n" +
// " public void response(String result) throws JSONException;\n" +
// " }\n" +
// "}");
btnShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Common.openShareDialog(ClientPostActivity.this, "Client Get", "", "http://www.paste.org/77942", "Get Data From API");
}
});
}
use of android.webkit.WebView in project Jota-Text-Editor-old by jiro-aqua.
the class AboutActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
String url = DEFAULT_PAGE;
Intent it = getIntent();
if (it != null) {
Bundle extras = it.getExtras();
if (extras != null) {
String iturl = extras.getString(EXTRA_URL);
if (iturl != null) {
url = iturl;
}
String ittitle = extras.getString(EXTRA_TITLE);
if (ittitle != null) {
setTitle(ittitle);
}
} else {
url = getString(R.string.about_url);
setTitle(R.string.about_title);
}
}
WebView webview = (WebView) findViewById(R.id.WebView01);
webview.loadUrl(url);
mjsobj = new JsCallbackObj();
webview.addJavascriptInterface(mjsobj, "jscallback");
webview.getSettings().setJavaScriptEnabled(true);
webview.setFocusable(true);
webview.setFocusableInTouchMode(true);
}
use of android.webkit.WebView in project android by cSploit.
the class HijackerWebView method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
Boolean isDark = themePrefs.getBoolean("isDark", false);
if (isDark)
setTheme(R.style.DarkTheme);
else
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
supportRequestWindowFeature(Window.FEATURE_PROGRESS);
setTitle(System.getCurrentTarget() + " > MITM > Session Hijacker");
setContentView(R.layout.plugin_mitm_hijacker_webview);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mProgressBar = (ProgressBar) findViewById(R.id.webprogress);
mURLet = (EditText) findViewById(R.id.url);
mProgressBar.setVisibility(View.GONE);
mProgressBar.setMax(100);
mSettings = mWebView.getSettings();
mSettings.setJavaScriptEnabled(true);
mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
mSettings.setBuiltInZoomControls(true);
mSettings.setAppCacheEnabled(false);
mSettings.setUserAgentString(DEFAULT_USER_AGENT);
mSettings.setUseWideViewPort(true);
mURLet.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
mWebView.loadUrl(mURLet.getText().toString());
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
mWebView.requestFocus();
return true;
}
return false;
}
});
mURLet.setOnKeyListener(new EditText.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
mWebView.loadUrl(mURLet.getText().toString());
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
mWebView.requestFocus();
return true;
}
return false;
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
mURLet.setText(url);
return true;
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if ((mWebView != null) && (mURLet != null) && (progress == 0))
;
{
getSupportActionBar().setSubtitle(mWebView.getUrl());
mURLet.setText(mWebView.getUrl());
}
if (mProgressBar != null) {
mProgressBar.setVisibility(View.VISIBLE);
// Normalize our progress along the progress bar's scale
mProgressBar.setProgress(progress);
if (progress == 100) {
mProgressBar.setVisibility(View.GONE);
}
}
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager cm = CookieManager.getInstance();
cm.flush();
} else {
CookieSyncManager.createInstance(this);
CookieManager.getInstance().removeAllCookie();
}
Session session = (Session) System.getCustomData();
if (session != null) {
String domain = null, rawcookie = null;
for (HttpCookie cookie : session.mCookies.values()) {
domain = cookie.getDomain();
rawcookie = cookie.getName() + "=" + cookie.getValue() + "; domain=" + domain + "; path=/" + (session.mHTTPS ? ";secure" : "");
CookieManager.getInstance().setCookie(domain, rawcookie);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager cm = CookieManager.getInstance();
cm.flush();
} else {
CookieSyncManager.getInstance().startSync();
}
if (session.mUserAgent != null && session.mUserAgent.isEmpty() == false)
mSettings.setUserAgentString(session.mUserAgent);
String url = (session.mHTTPS ? "https" : "http") + "://";
if (domain != null && !Patterns.IP_ADDRESS.matcher(domain).matches())
url += "www.";
url += domain;
mWebView.loadUrl(url);
mWebView.requestFocus();
}
}
use of android.webkit.WebView in project scdl by passy.
the class ChangeLog method getDialog.
private AlertDialog getDialog(final boolean full) {
final WebView wv = new WebView(context);
wv.setBackgroundColor(Color.WHITE);
wv.loadDataWithBaseURL(null, this.getLog(full), "text/html", "UTF-8", null);
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getResources().getString(full ? R.string.changelog_full_title : R.string.changelog_title)).setView(wv).setCancelable(false).setPositiveButton(context.getResources().getString(R.string.changelog_ok_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel();
}
});
return builder.create();
}
use of android.webkit.WebView in project superCleanMaster by joyoyao.
the class DeciveInfoFragment 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