package com.gordonlu.checkboxutil; 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.AndroidViewComponent; import com.google.appinventor.components.runtime.ComponentContainer; import com.google.appinventor.components.runtime.EventDispatcher; import android.widget.CompoundButton; import android.view.View; import android.content.res.ColorStateList; import android.widget.TextView; import android.view.Gravity; import android.graphics.Typeface; @DesignerComponent( version = 1, description = "A non-visible extension that provides some tools to do with CheckBoxes, and provides additional methods to the built-in CheckBox component.

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 = "") public class CheckboxUtil extends AndroidNonvisibleComponent { //Activity and Context private Context context; private Activity activity; public CheckboxUtil(ComponentContainer container){ super(container.$form()); this.activity = container.$context(); this.context = container.$context(); } @SimpleFunction(description = "Changes the color of the checkbox.") public void ResetColor(AndroidViewComponent checkBox, int color) { View view = checkBox.getView(); CompoundButton c = (CompoundButton) view; c.setButtonTintList(ColorStateList.valueOf(color)); } @SimpleProperty(description = "A font block.") public String DefaultFont() { return "DEFAULT"; } @SimpleProperty(description = "A font block.") public String Serif() { return "SERIF"; } @SimpleProperty(description = "A font block.") public String SansSerif() { return "SANS SERIF"; } @SimpleProperty(description = "A font block.") public String Monospace() { return "MONOSPACE"; } @SimpleFunction(description = "Sets the font typeface of the CheckBox, including whether to bold, italicize, and the font of the TextBox." + " Use the blocks in the properties of this extension for the font parameter." + " If useCurrentFont is true, the font parameter will be ignored.") public void SetFontTypeface(AndroidViewComponent checkBox, boolean bold, boolean italic, String font, boolean useCurrentFont) { Typeface t = Typeface.DEFAULT; View view = checkBox.getView(); TextView tv = (TextView) view; if (useCurrentFont) { t = tv.getTypeface(); } else { if (font == "DEFAULT") { t = Typeface.DEFAULT; } else if (font == "SERIF") { t = Typeface.SERIF; } else if (font == "SANS SERIF") { t = Typeface.SANS_SERIF; } else if (font == "MONOSPACE") { t = Typeface.MONOSPACE; } } if (bold && italic) { tv.setTypeface(t, Typeface.BOLD_ITALIC); } else if (bold && !italic) { tv.setTypeface(t, Typeface.BOLD); } else if (italic && !bold) { tv.setTypeface(t, Typeface.ITALIC); } else { tv.setTypeface(t, Typeface.NORMAL); } } @SimpleFunction(description = "Sets the shadow for the text with the specified blur radius and color, and the specified distance from text position.") public void SetShadow(AndroidViewComponent checkBox, float radius, float dx, float dy, int color) { View view = checkBox.getView(); TextView edit = (TextView) view; edit.setShadowLayer(radius, dx, dy, color); } @SimpleFunction(description = "Justifies the text of the CheckBox.") public void JustifyText(AndroidViewComponent checkBox, boolean justify) { TextView text = (TextView) checkBox.getView(); if (justify) { text.setJustificationMode(1); } else { text.setJustificationMode(0); } } @SimpleFunction(description = "Checks whether the text of the CheckBox is justified.") public boolean IsTextJustified(AndroidViewComponent checkBox) { TextView text = (TextView) checkBox.getView(); if (text.getJustificationMode() == 1) { return true; } else { return false; } } }