-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensionTemplate.java
More file actions
77 lines (64 loc) · 2.67 KB
/
ExtensionTemplate.java
File metadata and controls
77 lines (64 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package 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.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
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.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.*;
import android.util.Log;
@DesignerComponent(
version = ExtensionTemplate.VERSION,
description =
"A template for creating extensions.",
category = ComponentCategory.EXTENSION, nonVisible = true,
iconName = "appengine/src/com/google/appinventor/images/alexa.png") // change this to whatever icon you want for the extension
@SimpleObject(external = true)
public class ExtensionTemplate extends AndroidNonvisibleComponent implements Component {
public static final int VERSION = 1;
private ComponentContainer container;
// example variable for extension
private String exampleVar;
// defaults:
public static final String DEFAULT_EXAMPLE_VAR_VALUE = "default";
/**
* Constructor creates a new extension object with default values.
*/
public ExtensionTemplate(ComponentContainer container) {
super(container.$form());
this.container = container;
}
/*
* ******** Helper Methods (Private) ********
*/
// example method to show how to return a value from a method
private boolean exampleReturnTrue() {
return true;
}
// example method to show how to write a method with params
private int exampleEvaluateParams(int x, int y) {
return x + y;
}
/*
* ******** Getters and Setters ********
*/
// example for setting a variable value
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, // change to what type of variable you have
defaultValue = ExtensionTemplate.DEFAULT_EXAMPLE_VAR_VALUE)
@SimpleProperty(
description = "Test variable")
public void ExampleVar(String exampleVar) {
this.exampleVar = exampleVar;
}
// example for getting a variable value
@SimpleProperty(
category = PropertyCategory.BEHAVIOR, // set depending on what type of variable this is
description = "Gets value of exampleVar")
public String ExampleVar() {
return this.exampleVar;
}
}