Skip to content

Commit ab82503

Browse files
committed
Add codeblocks
1 parent dcb8700 commit ab82503

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

InkRecognition/app/src/main/java/com/azure/cognitiveservices/inkrecognitionsample/InkPointImplementor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22

33
import com.azure.ai.inkrecognizer.InkPoint;
44

5+
// <inkPointImplementation>
56
class InkPointImplementor implements InkPoint {
67

78
final private float x;
89
final private float y;
910

11+
// <createInkPoint>
1012
InkPointImplementor(float x, float y) {
1113
this.y = y;
1214
this.x = x;
1315
}
16+
// </createInkPoint>
1417

18+
// <getXCoordinate>
1519
public float getX() {
1620
return x;
1721
}
22+
// </getXCoordinate>
1823

24+
// <getYCoordinate>
1925
public float getY() {
2026
return y;
2127
}
28+
// </getYCoordinate>
2229

2330
}
31+
// </inkPointImplementation>

InkRecognition/app/src/main/java/com/azure/cognitiveservices/inkrecognitionsample/InkStrokeImplementor.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.ArrayList;
99
import java.util.List;
1010

11+
// <inkStrokeImplementation>
1112
class InkStrokeImplementor implements InkStroke {
1213

1314
final private long strokeId;
@@ -17,38 +18,51 @@ class InkStrokeImplementor implements InkStroke {
1718
private static int num = 0;
1819
private static final float INCH_TO_MM = 25.4f;
1920

21+
// <createInkStroke>
2022
InkStrokeImplementor() {
2123
this.strokeId = getNextNum();
2224
this.language = "en-US";
2325
this.kind = InkStrokeKind.UNKNOWN;
2426
}
27+
// </createInkStroke>
2528

26-
// Converts pixels to mm
29+
// <addInkPoint>
2730
public void addPoint(float x, float y, DisplayMetrics displayMetrics) {
31+
// Converts pixels to mm
2832
float xdpi = displayMetrics.xdpi;
2933
float ydpi = displayMetrics.ydpi;
3034
InkPointImplementor point = new InkPointImplementor(x / xdpi * INCH_TO_MM, y / ydpi * INCH_TO_MM);
3135
inkPoints.add(point);
3236
}
37+
// </addInkPoint>
3338

3439
private int getNextNum() {
3540
return ++num;
3641
}
3742

43+
// <getInkPoints>
3844
public Iterable<InkPoint> getInkPoints() {
3945
return inkPoints;
4046
}
47+
// </getInkPoints>
4148

49+
// <getInkStrokeKind>
4250
public InkStrokeKind getKind() {
4351
return kind;
4452
}
53+
// </getInkStrokeKind>
4554

55+
// <getInkStrokeId>
4656
public long getId() {
4757
return strokeId;
4858
}
59+
// </getInkStrokeId>
4960

61+
// <getInkStrokeLanguage>
5062
public String getLanguage() {
5163
return language;
5264
}
65+
// </getInkStrokeLanguage>
5366

54-
}
67+
}
68+
// </inkStrokeImplementation>

InkRecognition/app/src/main/java/com/azure/cognitiveservices/inkrecognitionsample/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import android.support.v7.app.AppCompatActivity;
55
import android.util.Log;
66

7+
// <MainActivity>
78
public class MainActivity extends AppCompatActivity {
89

910
private static final String TAG = "InkRecognizer";
1011

12+
// <createNoteTakerInstance>
1113
@Override
1214
protected void onCreate(Bundle savedInstanceState) {
1315
super.onCreate(savedInstanceState);
@@ -18,4 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
1820
Log.e(TAG, "Exception", e);
1921
}
2022
}
23+
// </createNoteTakerInstance>
24+
2125
}
26+
// </MainActivity>

InkRecognition/app/src/main/java/com/azure/cognitiveservices/inkrecognitionsample/NoteTaker.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class NoteTaker extends View {
3232
private static final String TAG = "InkRecognizer";
3333
private DisplayMetrics displayMetrics;
3434

35+
// <setPropertiesForNoteTaker>
3536
public NoteTaker(Context context) throws Exception {
3637
super(context);
3738
String appKey = "<SUBSCRIPTION_KEY>";
@@ -52,7 +53,9 @@ public NoteTaker(Context context) throws Exception {
5253
brush.setStrokeJoin(Paint.Join.ROUND);
5354
brush.setStrokeWidth(3.0f);
5455
}
56+
// </setPropertiesForNoteTaker>
5557

58+
// <timerToShowResults>
5659
private void startTimer() {
5760
//The next 2 variables are used for the inactivity timer which triggers recognition
5861
//after a certain period of inactivity.
@@ -71,34 +74,41 @@ public void onFinish() {
7174
}
7275
}.start();
7376
}
77+
// </timerToShowResults>
7478

79+
// <handleResponse>
7580
private static class recognizeInkTask extends AsyncTask<NoteTaker, Integer, NoteTaker> {
7681

7782
StringBuilder recognizedWords = new StringBuilder();
7883

84+
// <backgroundProcess>
7985
@Override
8086
protected NoteTaker doInBackground(NoteTaker... params) {
8187
NoteTaker noteTaker = null;
8288
try {
8389
noteTaker = params[0];
8490
if (noteTaker.strokes.size() != 0) {
8591
Mono<Response<InkRecognitionRoot>> response = noteTaker.inkRecognizerAsyncClient.recognizeInk(noteTaker.strokes);
86-
response.subscribe(r -> showResults(r), e -> e.printStackTrace());
92+
response.subscribe(r -> processResults(r), e -> e.printStackTrace());
8793
}
8894
} catch (Exception e) {
8995
e.printStackTrace();
9096
Log.e(TAG, "Error in fetching data from SDK", e);
9197
}
9298
return noteTaker;
9399
}
100+
// </backgroundProcess>
94101

102+
// <showResults>
95103
@Override
96104
protected void onPostExecute(NoteTaker noteTaker) {
97105
Toast toast = Toast.makeText(noteTaker.getContext(), recognizedWords.toString(), Toast.LENGTH_LONG);
98106
toast.show();
99107
}
108+
// </showResults>
100109

101-
private void showResults(Response<InkRecognitionRoot> response) {
110+
// <processResults>
111+
private void processResults(Response<InkRecognitionRoot> response) {
102112

103113
if (response.status == 200) {
104114

@@ -120,15 +130,20 @@ private void showResults(Response<InkRecognitionRoot> response) {
120130
}
121131

122132
}
133+
// </processResults>
123134

124135
}
136+
// </handleResponse>
125137

138+
// <cancelTimeCountdown>
126139
private void cancelTimer() {
127140
if (analysisTimer != null) {
128141
analysisTimer.cancel();
129142
}
130143
}
144+
// </cancelTimeCountdown>
131145

146+
// <processTouchEvents>
132147
@Override
133148
public boolean onTouchEvent(MotionEvent event) {
134149
float x = event.getX();
@@ -155,9 +170,12 @@ public boolean onTouchEvent(MotionEvent event) {
155170
postInvalidate();
156171
return false;
157172
}
173+
// </processTouchEvents>
158174

175+
// <onDrawVisuals>
159176
@Override
160177
protected void onDraw(Canvas canvas) {
161178
canvas.drawPath(path, brush);
162179
}
180+
// </onDrawVisuals>
163181
}

0 commit comments

Comments
 (0)