use of android.webkit.WebView in project android_frameworks_base by ParanoidAndroid.
the class ReliabilityTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(LOGTAG, "onCreate, inst=" + Integer.toHexString(hashCode()));
LinearLayout contentView = new LinearLayout(this);
contentView.setOrientation(LinearLayout.VERTICAL);
setContentView(contentView);
setTitle("Idle");
webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
webViewClient = new SimpleWebViewClient();
chromeClient = new SimpleChromeClient();
webView.setWebViewClient(webViewClient);
webView.setWebChromeClient(chromeClient);
contentView.addView(webView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case MSG_TIMEOUT:
handleTimeout();
return;
case MSG_NAVIGATE:
manualDelay = msg.arg2;
navigate(msg.getData().getString(MSG_NAV_URL), msg.arg1);
logTime = msg.getData().getBoolean(MSG_NAV_LOGTIME);
return;
}
}
};
pageDoneLock = new Object();
}
use of android.webkit.WebView in project android_frameworks_base by ParanoidAndroid.
the class TestShellActivity method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_PROGRESS);
LinearLayout contentView = new LinearLayout(this);
contentView.setOrientation(LinearLayout.VERTICAL);
setContentView(contentView);
CookieManager.setAcceptFileSchemeCookies(true);
mWebView = new WebView(this);
mWebViewClassic = WebViewClassic.fromWebView(mWebView);
mEventSender = new WebViewEventSender(mWebView);
mCallbackProxy = new CallbackProxy(mEventSender, this);
mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController");
mWebView.addJavascriptInterface(mCallbackProxy, "eventSender");
setupWebViewForLayoutTests(mWebView, mCallbackProxy);
contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
// Expose window.gc function to JavaScript. JSC build exposes
// this function by default, but V8 requires the flag to turn it on.
// WebView::setJsFlags is noop in JSC build.
mWebViewClassic.setJsFlags("--expose_gc");
mHandler = new AsyncHandler();
Intent intent = getIntent();
if (intent != null) {
executeIntent(intent);
}
// This is asynchronous, but it gets processed by WebCore before it starts loading pages.
mWebViewClassic.setUseMockDeviceOrientation();
}
use of android.webkit.WebView in project android_frameworks_base by ParanoidAndroid.
the class ProfileActivity method onCreate.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mInspectButton = (Button) findViewById(R.id.inspect);
mCaptureButton = (ToggleButton) findViewById(R.id.capture);
mVelocitySpinner = (Spinner) findViewById(R.id.velocity);
mMovementSpinner = (Spinner) findViewById(R.id.movement);
mUrl = (EditText) findViewById(R.id.url);
mWeb = (ProfiledWebView) findViewById(R.id.web);
setCallback(new ProfileCallback() {
@SuppressWarnings("unchecked")
@Override
public void profileCallback(RunData data) {
new StoreFileTask().execute(new Pair<String, RunData>(TEMP_FILENAME, data));
Log.d("ProfileActivity", "stored " + data.frames.length + " frames in file");
setTestingState(TestingState.STOP_TESTING);
}
});
// Inspect button (opens PlaybackActivity)
mInspectButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ProfileActivity.this, PlaybackActivity.class));
}
});
// Velocity spinner
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.velocity_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mVelocitySpinner.setAdapter(adapter);
mVelocitySpinner.setOnItemSelectedListener(new VelocitySelectedListener());
mVelocitySpinner.setSelection(3);
// Movement spinner
String[] content = { getResources().getString(R.string.movement_auto_scroll), getResources().getString(R.string.movement_manual), getResources().getString(R.string.movement_timed) };
adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, content);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mMovementSpinner.setAdapter(adapter);
mMovementSpinner.setOnItemSelectedListener(new MovementSelectedListener());
mMovementSpinner.setSelection(0);
// Capture toggle button
mCaptureButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mCaptureButton.isChecked()) {
startViewProfiling(false);
} else {
mWeb.stopScrollTest();
}
}
});
// Custom profiling WebView
mWeb.init(this);
mWeb.setWebViewClient(new LoggingWebViewClient());
// URL text entry
mUrl.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
String url = mUrl.getText().toString();
mWeb.loadUrl(url);
mWeb.requestFocus();
return true;
}
});
setTestingState(TestingState.NOT_TESTING);
}
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 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