Example usage for android.webkit WebView loadData

List of usage examples for android.webkit WebView loadData

Introduction

In this page you can find the example usage for android.webkit WebView loadData.

Prototype

public void loadData(String data, @Nullable String mimeType, @Nullable String encoding) 

Source Link

Document

Loads the given data into this WebView using a 'data' scheme URL.

Usage

From source file:com.jwork.dhammapada.MainActivity.java

public void displayChangeLog() {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle("Changelog");

    WebView wv = new WebView(this);
    wv.loadData(getString(R.string.changelog_dialog_text), "text/html", "utf-8");
    wv.setScrollContainer(true);/*from w  ww  .java  2s  . c  o  m*/
    dialog.setView(wv);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Configuration.getInstance(MainActivity.this)
                            .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this));
                    dialog.dismiss();
                }
            });
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate It", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Configuration.getInstance(MainActivity.this)
                    .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this));
            dialog.dismiss();
            Uri uri = Uri.parse("market://details?id=" + MainActivity.this.getPackageName());
            Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
                MainActivity.this.startActivity(myAppLinkToMarket);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(MainActivity.this, "Failed to find Market application", Toast.LENGTH_LONG)
                        .show();
            }
        }
    });
    dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Donate", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Configuration.getInstance(MainActivity.this)
                    .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this));
            dialog.dismiss();
            openDonate();
        }
    });
    dialog.show();
}

From source file:org.videolan.vlc2.gui.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("VLC " + getVersion(getActivity()));

    View v = inflater.inflate(R.layout.about, container, false);

    mTabHost = (TabHost) v.findViewById(android.R.id.tabhost);
    mFlingViewGroup = (FlingViewGroup) v.findViewById(R.id.fling_view_group);

    WebView t = (WebView) v.findViewById(R.id.webview);
    String revision = Util.readAsset("revision.txt", "Unknown revision");
    t.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!", revision), "text/html", "UTF8");

    TextView link = (TextView) v.findViewById(R.id.main_link);
    link.setText(Html.fromHtml(this.getString(R.string.about_link)));

    String builddate = Util.readAsset("builddate.txt", "Unknown");
    String builder = Util.readAsset("builder.txt", "unknown");

    TextView compiled = (TextView) v.findViewById(R.id.main_compiled);
    compiled.setText(builder + " (" + builddate + ")");
    TextView textview_rev = (TextView) v.findViewById(R.id.main_revision);
    textview_rev.setText(getResources().getString(R.string.revision) + " " + revision + " (" + builddate + ")");

    final ImageView logo = (ImageView) v.findViewById(R.id.logo);
    logo.setOnClickListener(new OnClickListener() {
        @Override//  w  w w.  ja va2s  .  c  o  m
        public void onClick(View v) {
            AnimationSet anim = new AnimationSet(true);
            RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            rotate.setDuration(800);
            rotate.setInterpolator(new DecelerateInterpolator());
            anim.addAnimation(rotate);
            logo.startAnimation(anim);
        }
    });

    mTabHost.setup();

    addNewTab(mTabHost, "about", getResources().getString(R.string.about));
    addNewTab(mTabHost, "licence", getResources().getString(R.string.licence));

    mTabHost.setCurrentTab(mCurrentTab);
    mFlingViewGroup.snapToScreen(mCurrentTab);

    mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            mCurrentTab = mTabHost.getCurrentTab();
            mFlingViewGroup.smoothScrollTo(mCurrentTab);
        }
    });

    mFlingViewGroup.setOnViewSwitchedListener(new FlingViewGroup.ViewSwitchListener() {
        @Override
        public void onSwitching(float progress) {
        }

        @Override
        public void onSwitched(int position) {
            mTabHost.setCurrentTab(position);
        }

        @Override
        public void onTouchDown() {
        }

        @Override
        public void onTouchUp() {
        }

        @Override
        public void onTouchClick() {
        }

        @Override
        public void onBackSwitched() {
            MainActivity activity = (MainActivity) getActivity();
            activity.popSecondaryFragment();
        }
    });

    return v;
}

From source file:com.example.office.ui.mail.MailItemFragment.java

/**
 * Fills fragment content with email fields
 *
 * @param root Root view for current fragment
 *///from  w  w w  . ja  v  a  2  s  .  c o  m
private void displayMail(View root) {
    try {
        TextView subjectView = (TextView) root.findViewById(R.id.mail_fragment_subject);
        subjectView.setText(mail.getSubject());

        StringBuilder recipients = new StringBuilder(
                getActivity().getString(R.string.me_and_somebody_text_stub));
        if (mail.getRecipients() != null && mail.getRecipients().size() > 0) {
            for (Recipient r : mail.getRecipients()) {
                recipients.append(r.getName());
            }
        } else {
            recipients.append("<unknown>");
        }
        TextView participantsView = (TextView) root.findViewById(R.id.mail_fragment_participants);
        participantsView.setText(recipients.toString());

        TextView dateView = (TextView) root.findViewById(R.id.mail_fragment_date);
        dateView.setText("");

        WebView webview = (WebView) root.findViewById(R.id.mail_fragment_content);
        if (mail.getBody().getContentType() == BodyType.HTML) {
            webview.loadData(mail.getBody().getContent(), getActivity().getString(R.string.mime_type_text_html),
                    "utf8");
        } else {
            webview.loadData(mail.getBody().getContent(),
                    getActivity().getString(R.string.mime_type_text_plain), "utf8");
        }
    } catch (Exception e) {
        Logger.logApplicationException(e, getClass().getSimpleName() + ".displayMail(): Error.");
    }
}

From source file:com.geecko.QuickLyric.AboutActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    int[] themes = new int[] { R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red,
            R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo, R.style.Theme_QuickLyric_Green,
            R.style.Theme_QuickLyric_Lime, R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark };
    int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0"));
    boolean nightMode = sharedPref.getBoolean("pref_night_mode", false);
    if (nightMode && NightTimeVerifier.check(this))
        setTheme(R.style.Theme_QuickLyric_Night);
    else//from w ww .j  a  va  2s  .  co m
        setTheme(themes[themeNum]);
    TypedValue primaryColor = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true);
    setStatusBarColor(null);

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    Toolbar toolbar = new Toolbar(this);
    toolbar.setTitle(R.string.pref_about);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        toolbar.setElevation(8f);
    toolbar.setBackgroundColor(primaryColor.data);
    toolbar.setTitleTextColor(Color.WHITE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(null, null,
                primaryColor.data);
        this.setTaskDescription(taskDescription);
    }

    View.OnClickListener productTourAction = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setupDemoScreen();
        }
    };

    Element productTourElement = new Element().setTitle(getString(R.string.about_product_tour));
    productTourElement.setOnClickListener(productTourAction);
    Element crowdinElement = new Element().setTitle(getString(R.string.about_crowdin));
    crowdinElement
            .setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/quicklyric")));
    Element ossLicensesElement = new Element().setTitle("Open Source Licenses");
    ossLicensesElement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            WebView webView = new WebView(AboutActivity.this);
            String data = getResources().getString(R.string.open_source_librairies_licenses);
            webView.loadData(data, "text/html; charset=utf-8", "UTF-8");
            new AlertDialog.Builder(AboutActivity.this).setView(webView).show();
        }
    });
    Element tosElement = new Element().setTitle(getString(R.string.about_read_ToS));
    tosElement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            WebView webView = new WebView(AboutActivity.this);
            String data = getResources().getString(R.string.QL_EULA);
            webView.loadData(data, "text/html; charset=utf-8", "UTF-8");
            new AlertDialog.Builder(AboutActivity.this).setView(webView).show();
        }
    });
    Element cookElement = new Element().setTitle("Icon Designer");
    cookElement.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://cookicons.co/")));

    View aboutView = new AboutPage(this).setDescription("QuickLyric is made with love in Brussels, Belgium.") // FixMe
            .addEmail("contact@QuickLyric.be").addFacebook("QuickLyric").addGitHub("geecko86/QuickLyric")
            .addPlayStore("test").addTwitter("QuickLyric").addWebsite("http://www.quicklyric.be")
            .setImage(R.drawable.icon).addItem(productTourElement).addItem(crowdinElement).addItem(cookElement)
            .addItem(ossLicensesElement).addItem(tosElement).create();
    aboutView.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    linearLayout.addView(toolbar);
    linearLayout.addView(aboutView);
    setContentView(linearLayout);

    final Drawable upArrow;
    if (Build.VERSION.SDK_INT >= 21) {
        upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
        upArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    } else
        upArrow = getResources().getDrawable(R.drawable.ic_arrow_back);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(upArrow);
}

From source file:us.koller.todolist.Activities.InfoActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_info);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.info_activity_toolbar);
    setSupportActionBar(toolbar);/*from   ww w.ja  va 2 s .  com*/
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("");
    }

    initTheme(toolbar);

    final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
    scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            if (scrollView.getScrollY() != 0) {
                elevateToolbar(toolbar);
            } else {
                deelevateToolbar(toolbar);
            }
        }
    });

    TextView version = (TextView) findViewById(R.id.version);
    if (helper.lightCoordColor()) {
        version.setTextColor(ContextCompat.getColor(this, R.color.grey700));
    }
    version.setText(BuildConfig.VERSION_NAME);

    ImageView icon = (ImageView) findViewById(R.id.icon);
    Glide.with(this).load("http://todolist.koller.us/todolist_icon_512px").into(icon);

    //Glide license
    View license_item_1 = findViewById(R.id.license_item_1);
    ((TextView) license_item_1.findViewById(R.id.text)).setText(R.string.glide);
    license_item_1.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://github.com/bumptech/glide/blob/master/LICENSE")));
        }
    });
    license_item_1.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(
                    new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/bumptech/glide")));
        }
    });

    //MaterialNumberPicker license
    View license_item_2 = findViewById(R.id.license_item_2);
    ((TextView) license_item_2.findViewById(R.id.text)).setText(R.string.materialnumberpicker);
    license_item_2.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW).setData(
                    Uri.parse("https://github.com/KasualBusiness/MaterialNumberPicker/blob/master/LICENSE")));
        }
    });
    license_item_2.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://github.com/KasualBusiness/MaterialNumberPicker")));
        }
    });

    //Google Play Service Attribution
    View license_item_3 = findViewById(R.id.license_item_3);
    ((TextView) license_item_3.findViewById(R.id.text)).setText(R.string.google_play_servcie_attribution);
    license_item_3.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            WebView webView = new WebView(InfoActivity.this);
            webView.loadData(
                    GoogleApiAvailability.getInstance().getOpenSourceSoftwareLicenseInfo(InfoActivity.this),
                    "text/plain", "utf-8");

            AlertDialog dialog = new AlertDialog.Builder(InfoActivity.this)
                    .setTitle("Google Play Servcie Attribution").setView(webView).setPositiveButton("Ok", null)
                    .create();
            dialog.show();
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(helper.get(ThemeHelper.FAB_COLOR));
        }
    });
    license_item_3.findViewById(R.id.button).setVisibility(View.GONE);

    //Google Play Service Attribution
    View license_item_4 = findViewById(R.id.license_item_4);
    ((TextView) license_item_4.findViewById(R.id.text)).setText("Privacy Policy");
    license_item_4.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW).setData(
                    Uri.parse("https://github.com/kollerlukas/TODOList-Android-App/blob/master/PRIVACY.md")));
        }
    });
    license_item_4.findViewById(R.id.button).setVisibility(View.GONE);
}

From source file:com.money.manager.ex.about.AboutCreditsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    WebView webView = (WebView) getActivity().findViewById(R.id.about_thirdsparty_credits);

    //        webView.loadData(MmxFileUtils.getRawAsString(getActivity(), R.raw.credits_thirdparty), "text/html", "UTF-8");

    // Display Unicode characters.
    WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName("utf-8");

    webView.loadData(
            MmxFileUtils.getRawAsString(getActivity().getApplicationContext(), R.raw.credits_thirdparty),
            "text/html; charset=utf-8", null);
}

From source file:com.example.office.ui.calendar.EventFragment.java

/**
  * Fills fragment content with events/*from w ww  . ja  v  a2  s .  c  o m*/
  *
  * @param root Root view for current fragment
  */
private void displayEvent(View root) {
    try {
        //Populate fragment fields with event properties
        TextView subjectView = (TextView) root.findViewById(R.id.event_fragment_subject);
        subjectView.setText(event.getSubject());

        // Resolving Attendees
        TextView attendeesView = (TextView) root.findViewById(R.id.event_fragment_participants);
        StringBuilder attendeesStr = new StringBuilder(getActivity().getString(R.string.event_attendees));
        Collection<Attendee> attendees = event.getAttendees();
        if (attendees != null && !attendees.isEmpty()) {
            for (Attendee attendee : attendees) {
                if (!TextUtils.isEmpty(attendee.getName())) {
                    attendeesStr.append(attendee.getName())
                            .append(getActivity().getString(R.string.event_addressee_delimiter));
                }
            }
        }
        attendeesView.setText(attendeesStr.toString());

        // Resolving Start and end of the event
        TextView dateStartView = (TextView) root.findViewById(R.id.event_fragment_date_start);
        TextView dateEndView = (TextView) root.findViewById(R.id.event_fragment_date_end);
        Date start = event.getStart();
        Date end = event.getEnd();
        final String pattern = "yyyy-MM-dd HH:mm";
        final SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
        if (start != null && end != null) {
            dateStartView.setText(
                    String.format(getActivity().getString(R.string.event_date_start), formatter.format(start)));
            dateEndView.setText(
                    String.format(getActivity().getString(R.string.event_date_end), formatter.format(end)));
        }

        // resolving location
        TextView locationView = (TextView) root.findViewById(R.id.event_fragment_location);
        String location = "Location: ";
        if (event.getLocation() == null || TextUtils.isEmpty(event.getLocation().getDisplayName())) {
            location += "unknown";
        } else {
            location += event.getLocation().getDisplayName();
        }
        locationView.setText(location);

        //Resolving event message
        WebView webview = (WebView) root.findViewById(R.id.event_fragment_content);
        if (event.getBody().getContentType() == BodyType.HTML) {
            webview.loadData(event.getBody().getContent(),
                    getActivity().getString(R.string.mime_type_text_html), CharEncoding.UTF_8);
        } else {
            webview.loadData(event.getBody().getContent(),
                    getActivity().getString(R.string.mime_type_text_plain), CharEncoding.UTF_8);
        }
    } catch (Exception e) {
        Logger.logApplicationException(e, getClass().getSimpleName() + ".displayEvent(): Error.");
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java

public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//from w ww.j a v a 2  s .c o  m
    // TODO: hack to show object history in app feeds
    JSONObject appState = getAppState(context, content);
    if (appState != null) {
        content = appState;
    } else {
        Log.e(TAG, "Missing inner content, probably because of format changes");
    }

    boolean rendered = false;
    AppState ref = new AppState(content);
    String thumbnail = ref.getThumbnailImage();
    if (thumbnail != null) {
        rendered = true;
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        App.instance().objectImages.lazyLoadImage(thumbnail.hashCode(), thumbnail, imageView);
        frame.addView(imageView);
    }

    thumbnail = ref.getThumbnailText();
    if (thumbnail != null) {
        rendered = true;
        TextView valueTV = new TextView(context);
        valueTV.setText(thumbnail);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }

    thumbnail = ref.getThumbnailHtml();
    if (thumbnail != null) {
        rendered = true;
        WebView webview = new WebView(context);
        webview.loadData(thumbnail, "text/html", "UTF-8");
        webview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        Object o = frame.getTag(R.id.object_entry);
        webview.setOnTouchListener(new WebViewClickListener(frame, (Integer) o));
        frame.addView(webview);
    }

    if (!rendered) {
        String appName = content.optString(PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Welcome to " + appName + "!";
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }
}

From source file:com.jwork.spycamera.MainFragment.java

private void showHelp() {
    AlertDialog dialog = new AlertDialog.Builder(activity).create();
    dialog.setTitle(this.getString(R.string.help));

    WebView wv = new WebView(activity);
    wv.loadData(this.getString(R.string.help_html), "text/html", "utf-8");
    wv.setScrollContainer(true);/*from   w  ww. ja v a 2s  . c  o m*/
    dialog.setView(wv);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, this.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate It", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Uri uri = Uri.parse("market://details?id=" + activity.getPackageName());
            Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
                activity.startActivity(myAppLinkToMarket);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(activity, "Failed to find Market application", Toast.LENGTH_LONG).show();
            }
        }
    });
    dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Share It", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Utility.shareIt(activity);
        }
    });
    dialog.show();
}

From source file:com.kentph.ttcnextbus.CreateDatabaseActivity.java

private void showErrorPage() {
    setContentView(R.layout.activity_network);

    // The specified network connection is not available. Displays error message.
    WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.loadData(getResources().getString(R.string.connection_error), "text/html", null);
}