i am made an extension
which is my first extension two months ago from
https://medium.com/@saitwalshreyash19/writing-your-first-app-inventor-2-extension-dc6d5d4ff824
by @shreyash now once i learnt some what on #open-source-development #extensions
now i want to input many colors
actual code
@SimpleFunction(description = "this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section")
public void SetGradientBackground3color(AndroidViewComponent component, Object orientation, int color1, int color2) {
// To set gradient colors as background, what we are actually going to
// do is create a new GradientDrawable object and set it as
// the background of the view. With this approach, it'd be possible to
// create gradients programmatically without editing the manifest
// file which is currently not supported in App Inventor 2.
// Getting the reference to the View of the parameter component using
// the getView() method of AndroidNonVisible class.
View view = component.getView();
// GradientDrawable is a subclass of Drawable class from Android
// support library. It is mostly used to create gradients.
// For more info visit: https://developer.android.com/reference/android/graphics/drawable/GradientDrawable
GradientDrawable gradientDrawable = new GradientDrawable(
(GradientDrawable.Orientation) orientation,
new int[] {color1, color2});
// Setting the gradientDrawable as the background of view.
view.setBackground(gradientDrawable);
}
how i converted to 3 colors
in this code at this line
GradientDrawable gradientDrawable = new GradientDrawable(
(GradientDrawable.Orientation) orientation,
new int[] {color1, color2});
i just changed
new int[] {color1, color2});
to
new int[] {color1, color2, color3});
and
@SimpleFunction(description = "this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section")
public void SetGradientBackground3color(AndroidViewComponent component, Object orientation, int color1, int color2) {
to
@SimpleFunction(description = "this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section")
public void SetGradientBackground3color(AndroidViewComponent component, Object orientation, int color1, int color2,int color3) {
for 3 colors it works perfectly
now my goal is to achieve unlimited colors
so what i did
i first
@SimpleFunction(description = "")
public void SetGradientBackground2color(AndroidViewComponent component, Object orientation,int color1, int color2) {
converted this line to
@SimpleFunction(description = "")
public void SetGradientBackground2color(AndroidViewComponent component, Object orientation, YailList colors) {
and for this i added
import com.google.appinventor.components.runtime.util.YailList;
this line as i need yail list
So what i need
but now i have a doubt how should i change my code now to put list here
new int[] {color1, color2});
please help
thanks