List of usage examples for android.webkit WebView loadDataWithBaseURL
public void loadDataWithBaseURL(@Nullable String baseUrl, String data, @Nullable String mimeType, @Nullable String encoding, @Nullable String historyUrl)
From source file:com.prasanna.android.stacknetwork.FullscreenTextActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override//from w w w . ja v a 2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.code_full_screen); getActionBar().hide(); CharSequence text = getIntent().getCharSequenceExtra(StringConstants.TEXT); WebView webView = (WebView) findViewById(R.id.fullScreenText); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadDataWithBaseURL(BASE_URL, CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX, HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null); }
From source file:com.wuman.oauth.samples.ui.HtmlLicensesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.licenses);//from ww w.ja v a2 s . co m requestWindowFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.html_dialog_layout); WebView wv = (WebView) findViewById(R.id.wv); String content = getContentFromResource(this, R.raw.licenses).replaceAll("<app_name>", getString(R.string.app_name_long)); try { wv.loadDataWithBaseURL("file:///android_asset/", content, null, "utf-8", null); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:net.wespot.pim.view.InqDescriptionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final View rootView = inflater.inflate(R.layout.fragment_section_description, container, false); WebView webView = (WebView) rootView.findViewById(R.id.description_description); TextView title = (TextView) rootView.findViewById(R.id.title_description); title.setText(R.string.inquiry_title_description); webView.setBackgroundColor(0x00000000); webView.loadDataWithBaseURL(null, INQ.inquiry.getCurrentInquiry().getDescription(), Constants.MIME_TYPE, Constants.ENCONDING, null);/*from w w w . ja v a2 s . c o m*/ return rootView; }
From source file:com.barryku.android.boxnet.BrowseActivity.java
private void loadFolder(String folderId) { String browseUri = BOX_INTENT_SCHEME + "://" + BOX_INTENT_BROWSE + "/"; String uploadUri = BOX_INTENT_SCHEME + "://" + BOX_INTENT_UPLOAD + "/"; ;/*www . ja v a 2s . c o m*/ String downloadUri = DOWNLOAD_URI + authToken + "/"; String homeUrl = browseUri + 0; if (folderId == null || folderId.equals("")) folderId = "0"; Log.d(LOG_TAG, "loading folder:" + folderId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = prefs.edit(); editor.putString(LAST_VIEWED_FOLDER, folderId); editor.commit(); RestTemplate rest = RestUtil.getRestTemplate(); String requestUri = restUri + "get_account_tree¶ms[]=nozip¶ms[]=onelevel&folder_id={folderId}"; AccountTree response = rest.getForObject(requestUri, AccountTree.class, apiKey, authToken, folderId); //authToken expires at certain interval which will require authentication again if (!STATUS_LISTING_OK.equals(response.getStatus())) { Log.d(LOG_TAG, "authToken no longer works"); clearPreferences(prefs); } StringBuilder sb = new StringBuilder(); if (response == null) { sb.append("no data found"); } else { if (!"0".equals(folderId)) { sb.append("<a href=\"").append(homeUrl).append("\">").append("<img src=\"").append(IMG_HOME_URL) .append("\"> ").append("return to home").append("</a><br>"); } if (response.getFolders() != null) { for (FolderItem folder : response.getFolders()) { sb.append("<a href=\"").append(browseUri).append(folder.getId()).append("\">") .append("<img src=\"").append(IMG_FOLDER_URL).append("\"> ").append(folder.getName()) .append("</a><br>"); } } if (response.getFiles() != null) { for (FileItem file : response.getFiles()) { sb.append("<a href=\"").append(downloadUri).append(file.getId()).append("\">") .append(file.getName()).append("</a><br/>"); } } sb.append("<br/><br/><a href=\"").append(uploadUri).append(folderId).append("\">") .append("upload file ").append("<img src=\"").append(IMG_UPLOAD_URL).append("\"></a>"); final WebView detailResult = (WebView) findViewById(R.id.browseView); detailResult.getSettings().setBuiltInZoomControls(true); detailResult.loadDataWithBaseURL("fake://notused", "<html><body>" + sb.toString() + "</body></html>", "text/html", "UTF-8", ""); } }
From source file:net.meiolania.apps.habrahabr.fragments.qa.QaShowFragment.java
@Override public void onLoadFinished(Loader<QaFullData> loader, QaFullData data) { if (getSherlockActivity() != null) { WebView content = (WebView) getSherlockActivity().findViewById(R.id.qa_content); content.getSettings().setPluginsEnabled(true); content.getSettings().setBuiltInZoomControls(true); content.getSettings().setSupportZoom(true); content.loadDataWithBaseURL("", data.getContent(), "text/html", "UTF-8", null); }/*from www .j a v a 2 s. c om*/ this.data = data; hideProgressDialog(); }
From source file:net.meiolania.apps.habrahabr.fragments.posts.PostShowFragment.java
@Override public void onLoadFinished(Loader<PostsFullData> loader, PostsFullData data) { if (getSherlockActivity() != null) { WebView content = (WebView) getSherlockActivity().findViewById(R.id.post_content); content.getSettings().setPluginsEnabled(true); content.getSettings().setSupportZoom(true); content.getSettings().setBuiltInZoomControls(true); content.loadDataWithBaseURL("", data.getContent(), "text/html", "UTF-8", null); }// w ww .jav a 2 s . co m this.data = data; hideProgressDialog(); }
From source file:net.naonedbus.fragment.impl.VersionsFragment.java
@Override protected void bindView(final View view, final Bundle savedInstanceState) { try {/* w ww . ja va 2s . c o m*/ final WebView wv = (WebView) view.findViewById(R.id.webView); wv.setBackgroundColor(getResources().getColor(R.color.activity_background_light)); final String content = IOUtils.toString(getResources().openRawResource(R.raw.version), ENCODING); // Problme d'encodage avec le loadData. wv.loadDataWithBaseURL("fake://not/needed", content, "text/html", ENCODING, ""); } catch (final NotFoundException e) { Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e); } catch (final IOException e) { Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e); } // if (mUpgradeError) { // InfoDialogUtils.show(this, R.string.error_title_upgrade, // R.string.error_summary_upgrade); // } }
From source file:net.naonedbus.fragment.impl.WebViewFragment.java
@Override protected void bindView(final View view, final Bundle savedInstanceState) { try {//from w ww .j a va 2 s.c om final WebView wv = (WebView) view.findViewById(R.id.webView); wv.setBackgroundColor(getResources().getColor(R.color.activity_background_light)); final int rawId = getArguments().getInt(PARAM_RAW_ID); final String content = IOUtils.toString(getResources().openRawResource(rawId), ENCODING); // Problme d'encodage avec le loadData. wv.loadDataWithBaseURL("fake://not/needed", content, "text/html", ENCODING, ""); } catch (final NotFoundException e) { Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e); } catch (final IOException e) { Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e); } }
From source file:com.sonnychen.aviationhk.views.MetarFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.v("METAR-UI", "Starting"); // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_metar, container, false); // ((TextView) view.findViewById(R.id.metar)).setText(BaseApplication.Data.METAR_Code); WebView metar = ((WebView) view.findViewById(R.id.metar_html)); metar.setInitialScale(1);//from w w w .j av a2 s. c om metar.getSettings().setJavaScriptEnabled(false); metar.getSettings().setLoadWithOverviewMode(true); metar.getSettings().setUseWideViewPort(true); metar.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); metar.setScrollbarFadingEnabled(false); metar.loadDataWithBaseURL("", BaseApplication.Data.METAR_HTML + "<p><p>" + BaseApplication.Data.TAF_HTML + "<p><pre>" + BaseApplication.Data.SIGMET_Code + "</pre>", "text/html", "UTF-8", ""); // ((TextView) view.findViewById(R.id.taf)).setText(BaseApplication.Data.TAF_Code); // ((TextView) view.findViewById(R.id.sigmet)).setText(BaseApplication.Data.SIGMET_Code); return view; }
From source file:org.mozilla.focus.browser.LocalizedContent.java
/** * Load the content for focus:about//from w ww .jav a 2 s . c o m */ private static void loadAbout(@NonNull final WebView webView) { final Context context = webView.getContext(); final Resources resources = Locales.getLocalizedResources(context); final Map<String, String> substitutionMap = new ArrayMap<>(); final String appName = context.getResources().getString(R.string.app_name); final String learnMoreURL = SupportUtils.getManifestoURL(); String aboutVersion = ""; try { final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); aboutVersion = String.format("%s (Build #%s)", packageInfo.versionName, packageInfo.versionCode); } catch (PackageManager.NameNotFoundException e) { // Nothing to do if we can't find the package name. } substitutionMap.put("%about-version%", aboutVersion); final String aboutContent = resources.getString(R.string.about_content, appName, learnMoreURL); substitutionMap.put("%about-content%", aboutContent); final String wordmark = HtmlLoader.loadPngAsDataURI(context, R.drawable.wordmark); substitutionMap.put("%wordmark%", wordmark); putLayoutDirectionIntoMap(webView, substitutionMap); final String data = HtmlLoader.loadResourceFile(context, R.raw.about, substitutionMap); // We use a file:/// base URL so that we have the right origin to load file:/// css and image resources. webView.loadDataWithBaseURL("file:///android_res/raw/about.html", data, "text/html", "UTF-8", null); }