-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaiduApiAccess.java
More file actions
62 lines (51 loc) · 2.01 KB
/
BaiduApiAccess.java
File metadata and controls
62 lines (51 loc) · 2.01 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
/**
* for http://ai.baidu.com/docs#/Auth/top
*/
package cn.colintree.aix.ApiAccess;
import com.google.appinventor.components.annotations.DesignerComponent;
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.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.os.Handler;
import cn.colintree.aix.ApiAccess.util.baidu.AuthService;
@DesignerComponent(version = BaiduApiAccess.EXTENSION_VERSION,
description = "for http://ai.baidu.com/docs#/Auth/top",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "aiwebres/baidu-favicon-32.ico")
@SimpleObject(external = true)
public class BaiduApiAccess extends AndroidNonvisibleComponent {
public static final int EXTENSION_VERSION = 3;
private final Handler handler;
public BaiduApiAccess(ComponentContainer container) {
super(container.$form());
handler = new Handler();
}
@SimpleFunction
public String GetAuth(String apiKey, String securetKey) {
return AuthService.getAuth(apiKey, securetKey);
}
@SimpleFunction
public void GetAuthAsync(final String apiKey, final String securetKey) {
new Thread(new Runnable(){
@Override
public void run() {
final String auth = GetAuth(apiKey, securetKey);
handler.post(new Runnable(){
@Override
public void run() {
BaiduApiAccess.this.GotAuth(auth);
}
});
}
}).start();
}
@SimpleEvent
public void GotAuth(String auth) {
EventDispatcher.dispatchEvent(this, "GotAuth", auth);
}
}