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." +
"
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, "");
}
}