Skip to content

Commit eeaee37

Browse files
author
张永超
committed
update guide code style
1 parent c4b24d6 commit eeaee37

File tree

1 file changed

+112
-81
lines changed

1 file changed

+112
-81
lines changed

Diff for: QuickStart.md

+112-81
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
使用 `git` 命令或者熟悉的 `git` 客户端将 Myna 克隆到本地:
88

9-
git clone https://github.com/TalkingData/Myna.git
9+
```st
10+
git clone https://github.com/TalkingData/Myna.git
11+
```
1012

1113
### Demo App
1214

@@ -33,84 +35,101 @@ Google 将 Google Play Service 中和用户情景感知相关的服务和功能
3335

3436
在应用自定义的 `Application` 派生类或者某个 `Activity``onCreate` 方法中调用下面的接口进行初始化:
3537

36-
@Override
37-
public void onCreate() {
38-
super.onCreate();
39-
context = this;
40-
MynaApi.init(this, new MyInitCallback(), new MyCallback(), MynaApi.TALKINGDATA);
41-
}
38+
```java
39+
@Override
40+
public void onCreate() {
41+
super.onCreate();
42+
context = this;
43+
MynaApi.init(this, new MyInitCallback(), new MyCallback(), MynaApi.TALKINGDATA);
44+
}
45+
```
4246

4347
初始化的时候,需要传入一个实现了接口 `MynaInitCallbacks` 的类的实例作为回调,这样将可以在 Myna 初始化成功或者失败时做不同的处理。接口 `MynaInitCallbacks` 的定义为:
4448

45-
/**
46-
* Define resultCallback methods to handle different initialization results.
47-
*/
48-
public interface MynaInitCallback {
49-
50-
/**
51-
* Called when Myna is successfully initialized.
52-
*/
53-
void onSucceeded();
54-
55-
/**
56-
* Called when Myna failed to initialize.
57-
*/
58-
void onFailed(MynaResult error);
59-
}
49+
```java
50+
/**
51+
* Define resultCallback methods to handle different initialization results.
52+
*/
53+
public interface MynaInitCallback {
6054

55+
/**
56+
* Called when Myna is successfully initialized.
57+
*/
58+
void onSucceeded();
59+
60+
/**
61+
* Called when Myna failed to initialize.
62+
*/
63+
void onFailed(MynaResult error);
64+
}
65+
```
6166
`MynaResultCallback` 用来返回识别结果:
62-
63-
public interface MynaResultCallback<R extends MynaResultInterface> {
67+
68+
```java
69+
public interface MynaResultCallback<R extends MynaResultInterface> {
6470
void onResult(@NonNull R var1);
65-
}
71+
}
72+
```
6673

6774
通过下面的接口可以获取 Myna 的初始化状态:
6875

69-
/**
70-
* Get the status of Myna initialization
71-
*/
72-
public static boolean isInitialized()
76+
```java
77+
/**
78+
* Get the status of Myna initialization
79+
*/
80+
public static boolean isInitialized()
81+
```
7382

7483
#### 开始和停止
7584

7685
初始化后,就可以调用 `start``stop` 接口接收和停止识别算法的运行并获得识别结果。
7786

78-
/**
79-
* Stop all background tasks
80-
*/
81-
public static void stop(){
82-
MynaHelper.stop();
83-
}
84-
85-
/**
86-
* Start to recognize
87-
*/
88-
public static void start(){
89-
MynaHelper.start();
90-
}
87+
```java
88+
/**
89+
* Stop all background tasks
90+
*/
91+
public static void stop(){
92+
MynaHelper.stop();
93+
}
94+
95+
/**
96+
* Start to recognize
97+
*/
98+
public static void start(){
99+
MynaHelper.start();
100+
}
101+
```
91102

92103
### 使用 Google Awareness API
93104

94105
如果希望使用 Google Awareness API 提供的实时行为识别能力,在初始化时:
95106

96-
MynaApi.init(this, new MyInitCallback(), new MyCallback(), MynaApi.GOOGLE);
107+
```java
108+
MynaApi.init(this, new MyInitCallback(), new MyCallback(), MynaApi.GOOGLE);
109+
```
97110

98111
需要注意的是,这是还需要额外进行下面的配置:
99112

100113
- 参考 [Android 开发者需要知道的 Google Awareness API](http://mp.weixin.qq.com/s?__biz=MjM5NzQ3NDg0Mg==&mid=2653096725&idx=1&sn=f6686df351aabe957a450c2fa1b01596&mpshare=1&scene=1&srcid=10311xdjSUJveY5gTtuLLQw2#rd) 文章申请 App key 并创建用于自己应用的 Credential。
101114
-`AndroidManifest.xml``application` 块中添加下面的声明:
102115

103-
<meta-data
104-
android:name="com.google.android.awareness.API_KEY"
105-
android:value="申请的 App Key"/>
106-
116+
```xml
117+
<meta-data
118+
android:name="com.google.android.awareness.API_KEY"
119+
android:value="申请的 App Key"/>
120+
```
121+
107122
- 添加下面的 Permission:
108123

109-
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
124+
```xml
125+
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
126+
```
110127

111128
- 在应用 module 的 `build.gradle` 文件中,添加下面的依赖:
112129

113-
compile 'com.google.android.gms:play-services-awareness:9.8.0'
130+
```st
131+
compile 'com.google.android.gms:play-services-awareness:9.8.0'
132+
```
114133

115134
### 面向数据科学家的接口
116135

@@ -120,53 +139,65 @@ Google 将 Google Play Service 中和用户情景感知相关的服务和功能
120139

121140
#### 添加新的传感器类型订阅:
122141

123-
/**
124-
* Add a sensor into the chosen sensor list.
125-
* @param sensorType sensorType
126-
*/
127-
public synchronized void addSensorType(int sensorType)
142+
```java
143+
/**
144+
* Add a sensor into the chosen sensor list.
145+
* @param sensorType sensorType
146+
*/
147+
public synchronized void addSensorType(int sensorType)
148+
```
128149

129150
#### 移除已经订阅的传感器类型:
130151

131-
/**
132-
* Remove a sensor from the chosen sensor list.
133-
* @param sensorType The type of the sensor to be removed.
134-
*/
135-
public synchronized void removeSensorType(int sensorType)
152+
```java
153+
/**
154+
* Remove a sensor from the chosen sensor list.
155+
* @param sensorType The type of the sensor to be removed.
156+
*/
157+
public synchronized void removeSensorType(int sensorType)
158+
```
136159

137160
#### 设置采样的间隔时间(反映采样频率,单位毫秒):
138161

139-
/**
140-
* Set sampling duration.
141-
* @param duration Sampling duration
142-
*/
143-
public void setSamplingDuration(int duration)
162+
```java
163+
/**
164+
* Set sampling duration.
165+
* @param duration Sampling duration
166+
*/
167+
public void setSamplingDuration(int duration)
168+
```
144169

145170
##### 设置 batch size:
146171

147-
/**
148-
* Set total count of the data points for each recognition.
149-
* @param pointCount Total count of the data points.
150-
*/
151-
public void setSamplingPointCount
172+
```java
173+
/**
174+
* Set total count of the data points for each recognition.
175+
* @param pointCount Total count of the data points.
176+
*/
177+
public void setSamplingPointCount
178+
```
152179

153180
Myna 支持同时配置多个识别器(MynaRecognizerInterface 派生类的实例),也就是 `Recognizer`,而且,在运行时,可以随时移除已经添加的某个 recognizer config:
154181

155-
/**
156-
* Add a new recognition configuration to be executed later
157-
*/
158-
public static void addRecognizer(MynaRecognizerInterface recognizer)
182+
```java
183+
/**
184+
* Add a new recognition configuration to be executed later
185+
*/
186+
public static void addRecognizer(MynaRecognizerInterface recognizer)
159187

160-
/**
161-
* Remove a new recognition configuration to be executed later
162-
*/
163-
public static void removeRecognizer(int configId)
188+
/**
189+
* Remove a new recognition configuration to be executed later
190+
*/
191+
public static void removeRecognizer(int configId)
192+
```
164193

165194
如果想完全重置 Myna 运行环境,需要运行:
166195

167-
/**
168-
* Clean Myna env
169-
*/
170-
public static void cleanUp(Context ctx)
196+
```java
197+
/**
198+
* Clean Myna env
199+
*/
200+
public static void cleanUp(Context ctx)
201+
```
171202

172203
清理环境后,再次启动 Myna 需要重新初始化。

0 commit comments

Comments
 (0)