HtmlDialog

Additional

Language
Java
Version
v1.1.2 (Jan 11, 2016)
Created
Feb 10, 2015
Updated
Jan 12, 2016 (Retired)
Owner
Jason D. Jobes (jjobes)
Contributor
Jason D. Jobes (jjobes)
1
Activity
Badge
Generate
Download
Source code
APK file

Advertising

HtmlDialog

HtmlDialog is an Android library that simplifies the display of HTML in a DialogFragment. It is useful for displaying Open Source Licenses, EULAs, Terms of Service pages, etc. Tested on Android 4.0+.

Setup

To add this library to your project, add the following to your builde.gradle:

dependencies {
   compile project(':htmlDialog')
}

How to Use

(See SampleActivity for a more complete example)

new HtmlDialog.Builder(getFragmentManager())
    .setHtmlResId(R.raw.licenses)
    .build()
    .show();

To set the resource Id of your HTML file:

.setHtmlResId(int)

This is required. Pass in the resource Id of an HTML file that resides /res/raw/ in your main project. In the above example, R.raw.licenses refers to /res/raw/licenses.html in the main project.

To set the title of the dialog:

.setTitle(String)

By default, the dialog will have no title.

To show a negative button at the bottom of the dialog:

.setShowNegativeButton(true)

By default, no negative button is shown.

To specify the negative button text:

.setNegativeButtonText(String)

Make sure to call this if you are showing the negative button.

To show a positive button at the bottom of the dialog:

.setShowPositiveButton(true)

By default, no positive button is shown.

To specify the positive button text:

.setPositiveButtonText(String)

Make sure to call this if you are showing the positive button.

To force the user to click a button:

.setCancelable(false)

This is useful if you are displaying a license agreement.

To specify a listener:

.setListener(new HtmlDialogListener() {

    @Override
    public void onNegativeButtonPressed()
    {
        
    }

    @Override
    public void onPositiveButtonPressed()
    {
        
    }

    @Override
    public void onDialogCancel()
    {
        // This override is optional.
        // Called when the user presses the Back button
        // or touches outside the dialog.
    }
})

Contributing

Contributions are welcome. Please open up an issue in GitHub or submit a PR.

Changelog

v1.1.2

  • Update build.gradle

v1.1.1

  • Changed to Android Studio / Gradle project

v1.1.0

  • removed setShowCloseButton() and setCloseButtonText()
  • added setShowNegativeButton(), setNegativeButtonText()
  • added setShowPositiveButton(), setPositiveButtonText()
  • added setCancelable()
  • added setListener()
  • updated SampleActivity

v1.0.0

  • First release

License

Licensed under the Apache License, Version 2.0

Acknowledgements

This project is based off of Adam Speakman's AndroidLicensesPage.