List of usage examples for android.webkit WebView setWebViewClient
public void setWebViewClient(WebViewClient client)
From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java
public void oAuthRequest(String hostAndPath, String clientId, String scope) { Activity activity = getActivity();/*from ww w .j ava 2 s .c om*/ if (activity == null) { return; } byte[] buf = new byte[16]; new Random().nextBytes(buf); mOAuthState = new String(Hex.encode(buf)); mOAuthCode = null; final Dialog auth_dialog = new Dialog(activity); auth_dialog.setContentView(R.layout.oauth_webview); WebView web = (WebView) auth_dialog.findViewById(R.id.web_view); web.getSettings().setSaveFormData(false); web.getSettings().setUserAgentString("OpenKeychain " + BuildConfig.VERSION_NAME); web.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri = Uri.parse(url); if ("oauth-openkeychain".equals(uri.getScheme())) { if (mOAuthCode != null) { return true; } if (uri.getQueryParameter("error") != null) { Log.i(Constants.TAG, "got oauth error: " + uri.getQueryParameter("error")); auth_dialog.dismiss(); return true; } // check if mOAuthState == queryParam[state] mOAuthCode = uri.getQueryParameter("code"); auth_dialog.dismiss(); return true; } // don't surf away from github! if (!"github.com".equals(uri.getHost())) { auth_dialog.dismiss(); return true; } return false; } }); auth_dialog.setTitle(R.string.linked_webview_title_github); auth_dialog.setCancelable(true); auth_dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { step1GetOAuthToken(); } }); auth_dialog.show(); web.loadUrl("https://" + hostAndPath + "?client_id=" + clientId + "&scope=" + scope + "&redirect_uri=oauth-openkeychain://linked/" + "&state=" + mOAuthState); }
From source file:at.maui.cheapcast.fragment.DonationsFragment.java
/** * Build view for Flattr. see Flattr API for more information: * http://developers.flattr.net/button///from ww w .j ava 2s. c om */ @SuppressLint("SetJavaScriptEnabled") @TargetApi(11) private void buildFlattrView() { final FrameLayout mLoadingFrame; final WebView mFlattrWebview; mFlattrWebview = (WebView) getActivity().findViewById(R.id.donations__flattr_webview); mLoadingFrame = (FrameLayout) getActivity().findViewById(R.id.donations__loading_frame); // disable hardware acceleration for this webview to get transparent background working if (Build.VERSION.SDK_INT >= 11) { mFlattrWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // define own webview client to override loading behaviour mFlattrWebview.setWebViewClient(new WebViewClient() { /** * Open all links in browser, not in webview */ @Override public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } return false; } /** * Links in the flattr iframe should load in the browser not in the iframe itself, * http:/ * /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the * -browser */ @Override public void onLoadResource(WebView view, String url) { if (url.contains("flattr")) { HitTestResult result = view.getHitTestResult(); if (result != null && result.getType() > 0) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } view.stopLoading(); } } } /** * After loading is done, remove frame with progress circle */ @Override public void onPageFinished(WebView view, String url) { // remove loading frame, show webview if (mLoadingFrame.getVisibility() == View.VISIBLE) { mLoadingFrame.setVisibility(View.GONE); mFlattrWebview.setVisibility(View.VISIBLE); } } }); // get flattr values from xml config String projectUrl = mFlattrProjectUrl; String flattrUrl = this.mFlattrUrl; // make text white and background transparent String htmlStart = "<html> <head><style type='text/css'>*{color: #FFFFFF; background-color: transparent;}</style>"; // https is not working in android 2.1 and 2.2 String flattrScheme; if (Build.VERSION.SDK_INT >= 9) { flattrScheme = "https://"; } else { flattrScheme = "http://"; } // set url of flattr link mFlattrUrlTextView = (TextView) getActivity().findViewById(R.id.donations__flattr_url); mFlattrUrlTextView.setText(flattrScheme + flattrUrl); String flattrJavascript = "<script type='text/javascript'>" + "/* <![CDATA[ */" + "(function() {" + "var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];" + "s.type = 'text/javascript';" + "s.async = true;" + "s.src = '" + flattrScheme + "api.flattr.com/js/0.6/load.js?mode=auto';" + "t.parentNode.insertBefore(s, t);" + "})();" + "/* ]]> */" + "</script>"; String htmlMiddle = "</head> <body> <div align='center'>"; String flattrHtml = "<a class='FlattrButton' style='display:none;' href='" + projectUrl + "' target='_blank'></a> <noscript><a href='" + flattrScheme + flattrUrl + "' target='_blank'> <img src='" + flattrScheme + "api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0' /></a></noscript>"; String htmlEnd = "</div> </body> </html>"; String flattrCode = htmlStart + flattrJavascript + htmlMiddle + flattrHtml + htmlEnd; mFlattrWebview.getSettings().setJavaScriptEnabled(true); mFlattrWebview.loadData(flattrCode, "text/html", "utf-8"); // disable scroll on touch mFlattrWebview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // already handled (returns true) when moving return (motionEvent.getAction() == MotionEvent.ACTION_MOVE); } }); // make background of webview transparent // has to be called AFTER loadData // http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2 mFlattrWebview.setBackgroundColor(0x00000000); }
From source file:com.near.chimerarevo.fragments.CommentsFragment.java
@SuppressLint("SetJavaScriptEnabled") private void loadDisqusOAuth() { if (getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "").length() > 1) { RequestBody formBody = new FormEncodingBuilder().add("grant_type", "refresh_token") .add("client_id", Constants.DISQUS_API_KEY).add("client_secret", Constants.DISQUS_API_SECRET) .add("refresh_token", getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "")) .build();// ww w . java2 s. com Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody).tag(FRAGMENT_TAG) .build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); return; } final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.webview_layout); dialog.setCancelable(true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) CookieManager.getInstance().removeAllCookies(null); else { CookieSyncManager.createInstance(getActivity()); CookieManager.getInstance().removeAllCookie(); } WebView wv = (WebView) dialog.findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setSaveFormData(false); wv.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); dialog.findViewById(R.id.progressContainer).setVisibility(View.GONE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.VISIBLE); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); dialog.findViewById(R.id.progressContainer).setVisibility(View.VISIBLE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.GONE); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { boolean state = super.shouldOverrideUrlLoading(view, url); if (url.contains(Constants.SITE_URL)) { String code = url.split("code=")[1]; RequestBody formBody = new FormEncodingBuilder().add("grant_type", "authorization_code") .add("client_id", Constants.DISQUS_API_KEY) .add("client_secret", Constants.DISQUS_API_SECRET) .add("redirect_uri", Constants.SITE_URL).add("code", code).build(); Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody) .tag(FRAGMENT_TAG).build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); dialog.dismiss(); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); } return state; } @Override public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) { handler.proceed(); } }); wv.loadUrl(URLUtils.getDisqusAuthUrl()); isDialogOpen = true; mFab.hide(); dialog.show(); }
From source file:eu.vranckaert.worktime.utils.donations.DonationsFragment.java
/** * Build view for Flattr. see Flattr API for more information: * http://developers.flattr.net/button///ww w .j a v a 2 s . c o m */ @SuppressLint("SetJavaScriptEnabled") @TargetApi(11) private void buildFlattrView() { final FrameLayout mLoadingFrame; final WebView mFlattrWebview; mFlattrWebview = (WebView) getActivity().findViewById(R.id.donations__flattr_webview); mLoadingFrame = (FrameLayout) getActivity().findViewById(R.id.donations__loading_frame); // disable hardware acceleration for this webview to get transparent background working if (Build.VERSION.SDK_INT >= 11) { mFlattrWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // define own webview client to override loading behaviour mFlattrWebview.setWebViewClient(new WebViewClient() { /** * Open all links in browser, not in webview */ @Override public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString))); return false; } /** * Links in the flattr iframe should load in the browser not in the iframe itself, * http:/ * /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the * -browser */ @Override public void onLoadResource(WebView view, String url) { if (url.contains("flattr")) { HitTestResult result = view.getHitTestResult(); if (result != null && result.getType() > 0) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); view.stopLoading(); } } } /** * After loading is done, remove frame with progress circle */ @Override public void onPageFinished(WebView view, String url) { // remove loading frame, show webview if (mLoadingFrame.getVisibility() == View.VISIBLE) { mLoadingFrame.setVisibility(View.GONE); mFlattrWebview.setVisibility(View.VISIBLE); } } }); // get flattr values from xml config String projectUrl = DonationsUtils.getResourceString(getActivity(), "donations__flattr_project_url"); String flattrUrl = DonationsUtils.getResourceString(getActivity(), "donations__flattr_url"); // make text white and background transparent String htmlStart = "<html> <head><style type='text/css'>*{color: #FFFFFF; background-color: transparent;}</style>"; // https is not working in android 2.1 and 2.2 String flattrScheme; if (Build.VERSION.SDK_INT >= 9) { flattrScheme = "https://"; } else { flattrScheme = "http://"; } // set url of flattr link mFlattrUrl = (TextView) getActivity().findViewById(R.id.donations__flattr_url); mFlattrUrl.setText(flattrScheme + flattrUrl); String flattrJavascript = "<script type='text/javascript'>" + "/* <![CDATA[ */" + "(function() {" + "var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];" + "s.type = 'text/javascript';" + "s.async = true;" + "s.src = '" + flattrScheme + "api.flattr.com/js/0.6/load.js?mode=auto';" + "t.parentNode.insertBefore(s, t);" + "})();" + "/* ]]> */" + "</script>"; String htmlMiddle = "</head> <body> <div align='center'>"; String flattrHtml = "<a class='FlattrButton' style='display:none;' href='" + projectUrl + "' target='_blank'></a> <noscript><a href='" + flattrScheme + flattrUrl + "' target='_blank'> <img src='" + flattrScheme + "api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0' /></a></noscript>"; String htmlEnd = "</div> </body> </html>"; String flattrCode = htmlStart + flattrJavascript + htmlMiddle + flattrHtml + htmlEnd; mFlattrWebview.getSettings().setJavaScriptEnabled(true); mFlattrWebview.loadData(flattrCode, "text/html", "utf-8"); // make background of webview transparent // has to be called AFTER loadData // http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2 mFlattrWebview.setBackgroundColor(0x00000000); }
From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java
private void configureWebView(WebView webView, WebChromeClient webChromeClient, CustomWebViewClient customWebViewClient) { //Set the properties WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setSupportZoom(true); //Zoom Control on web (You don't need this if ROM supports Multi-Touch webSettings.setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM webSettings.setDomStorageEnabled(true); webSettings.setPluginsEnabled(true); webSettings.setUseWideViewPort(true); //normal viewport (such as a normal desktop browser) webView.setWebChromeClient(webChromeClient); webView.setWebViewClient(customWebViewClient); }
From source file:org.ciasaboark.tacere.activity.AboutLicenseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about_activity_license); // Show the Up button in the action bar. setupActionBar();//from w w w. j a v a 2 s.c o m WebView wv = (WebView) findViewById(R.id.webView1); String htmlData = ""; try { BufferedReader br = new BufferedReader(new InputStreamReader(getAssets().open("license.html"))); String line; while ((line = br.readLine()) != null) { htmlData += line; } } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } int colorInt = getResources().getColor(R.color.link_color); String hexColor = String.format("#%06X", (0xFFFFFF & colorInt)); while (htmlData.contains("LINKCOLOR")) { htmlData = htmlData.replace("LINKCOLOR", hexColor); } wv.loadData(htmlData, "text/html", "UTF8"); // All links should open in the default browser, not this WebView wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } }); wv.setBackgroundColor(0x00000000); wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); }
From source file:com.blogspot.holbohistorier.readonfree.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override// w w w . j av a2s. c o m public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
From source file:org.zeroxlab.zeroxbenchmark.Benchmark.java
private void initViews() { /*/*from w ww .j a v a2 s . co m*/ mRun = (Button)findViewById(R.id.btn_run); mRun.setOnClickListener(this); mShow = (Button)findViewById(R.id.btn_show); mShow.setOnClickListener(this); mShow.setClickable(false); mLinearLayout = (LinearLayout)findViewById(R.id.list_container); mMainView = (LinearLayout)findViewById(R.id.main_view); mBannerInfo = (TextView)findViewById(R.id.banner_info); mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com"); */ mTabHost = getTabHost(); int length = mCases.size(); mCheckList = new CheckBox[length]; mDesc = new TextView[length]; for (int i = 0; i < length; i++) { mCheckList[i] = new CheckBox(this); mCheckList[i].setText(mCases.get(i).getTitle()); mDesc[i] = new TextView(this); mDesc[i].setText(mCases.get(i).getDescription()); mDesc[i].setTextSize(mDesc[i].getTextSize() - 2); mDesc[i].setPadding(42, 0, 10, 10); } TabContentFactory mTCF = new TabContentFactory() { public View createTabContent(String tag) { ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); wrapContent.gravity = Gravity.CENTER; LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); weightedFillWrap.weight = 1; if (tag.equals(MAIN)) { LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this); mMainViewContainer.setOrientation(1); ImageView mIconView = new ImageView(Benchmark.this); mIconView.setImageResource(R.drawable.icon); TextView mBannerInfo = new TextView(Benchmark.this); mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:"); d2CheckBox = new CheckBox(Benchmark.this); d2CheckBox.setText(D2); d2CheckBox.setOnClickListener(Benchmark.this); d3CheckBox = new CheckBox(Benchmark.this); d3CheckBox.setText(D3); d3CheckBox.setOnClickListener(Benchmark.this); mathCheckBox = new CheckBox(Benchmark.this); mathCheckBox.setText(MATH); mathCheckBox.setOnClickListener(Benchmark.this); vmCheckBox = new CheckBox(Benchmark.this); vmCheckBox.setText(VM); vmCheckBox.setOnClickListener(Benchmark.this); nativeCheckBox = new CheckBox(Benchmark.this); nativeCheckBox.setText(NATIVE); nativeCheckBox.setOnClickListener(Benchmark.this); miscCheckBox = new CheckBox(Benchmark.this); miscCheckBox.setText(MISC); miscCheckBox.setOnClickListener(Benchmark.this); TextView mWebInfo = new TextView(Benchmark.this); mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com"); LinearLayout mButtonContainer = new LinearLayout(Benchmark.this); mRun = new Button(Benchmark.this); mShow = new Button(Benchmark.this); mRun.setText("Run"); mShow.setText("Show"); mRun.setOnClickListener(Benchmark.this); mShow.setOnClickListener(Benchmark.this); mButtonContainer.addView(mRun, weightedFillWrap); mButtonContainer.addView(mShow, weightedFillWrap); WebView mTracker = new WebView(Benchmark.this); mTracker.clearCache(true); mTracker.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url); } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "Track err: " + description); } }); mTracker.loadUrl(trackerUrl); mMainViewContainer.addView(mIconView, wrapContent); mMainViewContainer.addView(mBannerInfo); mMainViewContainer.addView(mathCheckBox); mMainViewContainer.addView(d2CheckBox); mMainViewContainer.addView(d3CheckBox); mMainViewContainer.addView(vmCheckBox); mMainViewContainer.addView(nativeCheckBox); mMainViewContainer.addView(miscCheckBox); mMainViewContainer.addView(mWebInfo); mMainViewContainer.addView(mButtonContainer, fillWrap); mMainViewContainer.addView(mTracker, 0, 0); mListScroll.addView(mMainViewContainer, fillParent); mMainView.addView(mListScroll, fillWrap); return mMainView; } LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mListContainer = new LinearLayout(Benchmark.this); mListContainer.setOrientation(1); mListScroll.addView(mListContainer, fillParent); mMainView.addView(mListScroll, fillWrap); boolean gray = true; int length = mCases.size(); Log.i(TAG, "L: " + length); Log.i(TAG, "TCF: " + tag); for (int i = 0; i < length; i++) { if (!mCategory.get(tag).contains(mCases.get(i))) continue; Log.i(TAG, "Add: " + i); mListContainer.addView(mCheckList[i], fillWrap); mListContainer.addView(mDesc[i], fillWrap); if (gray) { int color = 0xFF333333; //ARGB mCheckList[i].setBackgroundColor(color); mDesc[i].setBackgroundColor(color); } gray = !gray; } return mMainView; } }; mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(NATIVE) .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc)) .setContent(mTCF)); }
From source file:org.ciasaboark.tacere.activity.fragment.AboutLicenseFragment.java
private void initViews() { // Show the Up button in the action bar. // setupActionBar(); WebView wv = (WebView) rootView.findViewById(R.id.webView1); String htmlData = ""; try {/* w ww . j ava2s .c o m*/ BufferedReader br = new BufferedReader(new InputStreamReader(context.getAssets().open("license.html"))); String line; while ((line = br.readLine()) != null) { htmlData += line; } } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } int colorInt = getResources().getColor(R.color.link_color); String hexColor = String.format("#%06X", (0xFFFFFF & colorInt)); while (htmlData.contains("LINKCOLOR")) { htmlData = htmlData.replace("LINKCOLOR", hexColor); } wv.loadData(htmlData, "text/html", "UTF8"); // All links should open in the default browser, not this WebView wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } }); wv.setBackgroundColor(0x00000000); wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); }
From source file:com.sonymobile.dronecontrol.activity.MainActivity.java
private void loadLicense() { View view = getLayoutInflater().inflate(R.layout.licenses, null); Dialog dialog = new AlertDialog.Builder(this).setPositiveButton(R.string.settings_button_ok, null) .setView(view).setTitle(getString(R.string.settings_item_licenses)).create(); final WebView webView = (WebView) view.findViewById(R.id.license_view); final ProgressBar webProgress = (ProgressBar) view.findViewById(R.id.license_progress); webProgress.setVisibility(View.VISIBLE); dialog.setOnDismissListener(new OnDismissListener() { @Override//w w w. ja v a 2 s .c om public void onDismiss(DialogInterface dialog) { webView.stopLoading(); } }); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onScaleChanged(WebView view, float oldScale, float newScale) { super.onScaleChanged(view, oldScale, newScale); webProgress.setVisibility(View.GONE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); webProgress.setVisibility(View.GONE); } }); webView.loadUrl("file:///android_asset/licenses.html"); dialog.show(); }