package com.SalmanDev.OriginalToast; import android.content.Context; import android.util.Log; import android.widget.Toast; import android.text.Html; import android.os.Build; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.annotations.DesignerComponent; import com.google.appinventor.components.annotations.DesignerProperty; import com.google.appinventor.components.annotations.PropertyCategory; import com.google.appinventor.components.annotations.SimpleObject; import com.google.appinventor.components.annotations.SimpleFunction; import com.google.appinventor.components.annotations.SimpleEvent; import com.google.appinventor.components.annotations.SimpleProperty; import com.google.appinventor.components.common.ComponentCategory; import com.google.appinventor.components.common.PropertyTypeConstants; import com.google.appinventor.components.common.HtmlEntities; import com.google.appinventor.components.runtime.errors.YailRuntimeError; @DesignerComponent(version = 1, description = "Created by Salman Developer", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "https://img.icons8.com/ios-filled/16/000000/source-code.png") @SimpleObject(external = true) public class OriginalToast extends AndroidNonvisibleComponent { private ComponentContainer container; private Context context; private int duration; private String durationLength; private boolean htmlFormat; private String dataText; public OriginalToast(ComponentContainer container) { super(container.$form()); this.container = container; context = (Context) container.$context(); } @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXTAREA, defaultValue = "SHORT") @SimpleProperty public void Duration(String length) { durationLength = length; if (length.equalsIgnoreCase("SHORT")) { duration = Toast.LENGTH_SHORT; } else if (length.equalsIgnoreCase("LONG")) { duration = Toast.LENGTH_LONG; } else { throw new YailRuntimeError("Sorry, you can only use LONG or SHORT to set the duration of the toast", "Error"); } } @SimpleProperty(category = PropertyCategory.BEHAVIOR) public String Duration() { return durationLength; } @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False") @SimpleProperty public void HTMLFormat(boolean fmt) { htmlFormat = fmt; } @SimpleProperty(category = PropertyCategory.APPEARANCE) public boolean HTMLFormat() { return htmlFormat; } @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXTAREA, defaultValue = "") @SimpleProperty public void Text(String text) { dataText = text; } @SimpleProperty(category = PropertyCategory.APPEARANCE) public String Text() { return dataText; } @SimpleFunction(description = "") public void ShowToast() { if (htmlFormat) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Toast.makeText(context, Html.fromHtml(dataText, Html.FROM_HTML_MODE_LEGACY), duration).show(); } else { Toast.makeText(context, Html.fromHtml(dataText), duration).show(); } } else { Toast.makeText(context, dataText, duration).show(); } } }