package com.gordonlu.circularprogress; 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.widget.ProgressBar; import android.view.View; import android.widget.FrameLayout; import android.graphics.drawable.Drawable; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuff; import android.content.res.ColorStateList; import android.widget.Button; @DesignerComponent( version = 2, description = "A non-visible extension that contains a circular running artifact that can be used to indicate loading.", 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 CircularProgress extends AndroidNonvisibleComponent { //Activity and Context private Context context; private Activity activity; public CircularProgress(ComponentContainer container){ super(container.$form()); this.activity = container.$context(); this.context = container.$context(); } @SimpleFunction(description = "Creates a circular progress in the arrangement.") public void InitializeProgress(AndroidViewComponent container, int id, int color) { View view = container.getView(); FrameLayout layout = (FrameLayout) view; ProgressBar progress = new ProgressBar(this.context); progress.setId(id); layout.addView(progress); progress.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); } @SimpleFunction(description = "Sets the color of the circular progress in the container, according to the given ID.") public void SetColor(AndroidViewComponent container, int id, int color) { View view = container.getView(); ProgressBar progress = view.findViewById(id); progress.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); } @SimpleFunction(description = "Sets the visibility of the circular progress in the container, according to the given ID.") public void SetVisibility(AndroidViewComponent container, int id, boolean visible) { View view = container.getView(); ProgressBar progress = view.findViewById(id); if (visible) { progress.setVisibility(View.VISIBLE); } else { progress.setVisibility(View.INVISIBLE); } } }