HtmlLoader

Published on March 3, 2022

🏷️ Tags: #extensions

A non-visible extension that loads HTML content inside of a WebViewer. What's different between this and the NoFileHtml is that this can load snippets of code, and is open source.

Made with Niotron IDE at https://ide.niotron.com.

Current version: 1 Package name: com.gordonlu.htmlloader.aix

For more information, read this MIT App Inventor Community thread.

πŸ“– Documentation

Method blocks

ClearHtmlContent - Clears the content loaded in the given WebViewer. Note that it also clears all content, even the HomeUrl, of the WebViewer.

Parameters: webViewer = component

LoadHtmlContent - Loads the HTML content inside of the WebViewer. If you have already loaded HTML content, it will replace the former HTML content with this current content.

Parameters: webViewer = component, content = text

FAQ

Q1: What values does the content parameter accept?

A1: It accepts the following formats.

  • Plain texts:

Test

  • Snippets:

<div align = "center">Test

  • HTML:

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>My First Heading</h1>

<p>My first paragraph.</p>


</body>

</html>

  • HTML and JavaScript:

<!DOCTYPE html>

<html>

<body>


<h1>The Window Object</h1>

<h2>The open() Method</h2>


<p>Click the button to open a new browser window.</p>


<button onclick="myFunction()">Try it</button>

<script>

function myFunction() {

window.open("https://www.w3schools.com");

}

</script>

</body>

</html>

Q2: Can you provide the Java source code?

A2: Sure, it is here.

package com.gordonlu.htmlloader;


import android.app.Activity;

import android.content.Context;

import com.google.appinventor.components.annotations.*;

import com.google.appinventor.components.common.ComponentCategory;

import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;

import com.google.appinventor.components.runtime.ComponentContainer;

import com.google.appinventor.components.runtime.EventDispatcher;


import com.google.appinventor.components.runtime.AndroidViewComponent;

import android.webkit.WebView;

import android.view.View;


@DesignerComponent(

version = 1,

description = "A non-visible extension that loads HTML content into a WebViewer without uploading HTML files in assets." +

"<br><br>Made by Gordon Lu (AICODE).",

category = ComponentCategory.EXTENSION,

nonVisible = true,

iconName = "https://docs.google.com/drawings/d/e/2PACX-1vQCI87PHLBF0jb8QWyYmIRQSjjNW3EFXf-qpsWCvBYkUQ9vEgPAB8SpxcMpblxNpbIYrjCjLrRLIU2c/pub?w=16&h=16")


@SimpleObject(external = true)

//Libraries

@UsesLibraries(libraries = "")

//Permissions

@UsesPermissions(permissionNames = "android.permission.INTERNET")


public class HtmlLoader extends AndroidNonvisibleComponent {


//Activity and Context

private Context context;

private Activity activity;


public HtmlLoader(ComponentContainer container){

super(container.$form());

this.activity = container.$context();

this.context = container.$context();

}


@SimpleFunction(description = "Loads the HTML content into the given WebViewer.")

public void LoadHtmlContent(AndroidViewComponent webViewer, String content) {

View view = webViewer.getView();

WebView wv = (WebView) view;

final String mimeType = "text/html";

final String encoding = "UTF-8";

wv.loadDataWithBaseURL("", content, mimeType, encoding, "");

}

@SimpleFunction(description = "Clears the content loaded in the given WebViewer.")

public void ClearHtmlContent(AndroidViewComponent webViewer) {

LoadHtmlContent(webViewer, "");

}

}

TERMS AND CONDITIONS

By downloading or sharing my extension, you agree to follow these terms and conditions.

  1. Have fun using the extension!

  2. You are allowed to modify this extension, but please give credit to Gordon Lu (AICODE) by mentioning name, extension and a link to this webpage.

  3. This, along with the MIT App Inventor original post above, are the only authorized places to download this extension. As an organization, you are not allowed to host and advertize this extension on your website, document, tweet, blog, article or any software you made without my authorization. You are also reminded not to include a direct download link of this extension on your website without my permission. If you are interested in the actions listed above, please contact me via email. Do remember that if you violate term no. 3, AICODE has the right to flag your website, document, tweet, blog or article as a violation of copyright, or other legal actions will be taken. Please contact me if you find anyone do this.

However, you can copy the link of this webpage and share it to someone as a personal identity (not as an organization), or sharing it on these authorized forums: App Inventor, Kodular, Niotron, Appzard and Android Builder communities. The term organization includes schools, markets and app stores, companies and social groups. Thank you for your understanding.

Those organizations are authorized to advertize or host my extension:

  • Kodular admins

  • MIT App Inventor admins

  • Pura Vida Apps / Taifun Baer

  1. Selling this extension/product to anyone is not allowed unless authorized by AICODE.

  2. These terms and conditions are written and issued on December 20, 2021. AICODE has the total permission to edit these terms and conditions anytime.