Skip to content

Commit 62efb78

Browse files
committed
Release 20.7.0: Custom recognition regions selection API
1 parent 3dd9d17 commit 62efb78

24 files changed

+888
-381
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ destTest/**
33
# Created by https://www.gitignore.io/api/java,android,androidstudio
44
# Edit at https://www.gitignore.io/?templates=java,android,androidstudio
55

6+
local.properties
7+
maven_push.gradle
8+
.idea/codeStyles
9+
610
### Android ###
711
# Built application files
812
*.apk

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 116 deletions
This file was deleted.

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ In detail, it's a set of SDKs for optical character recognition and document sca
1010

1111
It is easy to get started with Aspose.OCR Cloud, and there is nothing to install. Create an account at Aspose Cloud and get your application information, then you are ready to use [SDKs](#asposeocr-cloud-sdks)
1212

13-
## Release 20.4:
13+
## Release 20.7:
1414

15-
We are glad to introduce our new Android SDK.
15+
We released a feature of recognition regions selection.
1616

1717
## Features:
1818

@@ -30,21 +30,22 @@ Our API is completely independent of your operating system, database system, or
3030
## Example
3131

3232
```java
33-
Configuration.setAPI_KEY("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
34-
Configuration.setAPP_SID("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
33+
import com.aspose.ocr.api.*;
34+
35+
private static void setUpConfig() throws Exception {
36+
Configuration.setAPP_SID("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
37+
Configuration.setAPI_KEY("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
38+
}
3539

3640
public String RecognizeFromUrl(String url) {
37-
Call<ResponseBody> call = api.RecognizeFromUrl(url);
38-
Response<ResponseBody> res = call.execute();
39-
OCRResponse ocrResp = OCRResponse.Deserialize(res.body());
40-
return ocrResp.text;
41+
String urlToFile = "https://upload.wikimedia.org/wikipedia/commons/2/2f/Book_of_Abraham_FirstPage.png";
42+
OCRResponse ocrResponse = RecognizeFromUrl(urlToFile, Language.English);
43+
return ocrResponse.text;
4144
}
4245

4346
static String RecognizeFromContent(File f) {
44-
RequestBody requestBody = RequestBody.create( MediaType.parse("application/octet-stream"), f);
45-
Call<ResponseBody> call = api.RecognizeFromContent(requestBody);
46-
Response<ResponseBody> res = call.execute();
47-
OCRResponse ocrResp = OCRResponse.Deserialize(res.body());
47+
File f = new File(Configuration.getTestSrcDir(), "de_1.jpg");
48+
OCRResponse ocrResponse = RecognizeFromContent(f, Language.German);
4849
return ocrResp.text;
4950
}
5051
```
@@ -92,7 +93,7 @@ Add this dependency to your project's POM:
9293
<dependency>
9394
<groupId>com.aspose</groupId>
9495
<artifactId>aspose-ocr-cloud-android</artifactId>
95-
<version>20.4.0</version>
96+
<version>20.7.0</version>
9697
<type>aar</type>
9798
</dependency>
9899
```

app/src/main/java/aspose/ocr/cloud/sdk/android/MainActivity.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
import com.aspose.ocr.cloud.android.ApiClient;
2121
import com.aspose.ocr.cloud.android.Configuration;
22+
import com.aspose.ocr.cloud.android.api.Language;
23+
import com.aspose.ocr.cloud.android.api.OCRAPI;
2224
import com.aspose.ocr.cloud.android.api.OCRResponse;
23-
import com.aspose.ocr.cloud.android.api.OcrApi;
2425

2526
import java.io.FileNotFoundException;
2627
import java.io.IOException;
@@ -52,7 +53,7 @@ private void setUpConfig() throws Exception {
5253
private static final int IMAGE_PICK_CODE = 1000;
5354
private static final int PERMISSION_CODE = 1001;
5455

55-
private static OcrApi api;
56+
private static OCRAPI api;
5657
String url = "https://upload.wikimedia.org/wikipedia/commons/2/2f/Book_of_Abraham_FirstPage.png";
5758

5859
@Override
@@ -69,7 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {
6970
e.printStackTrace();
7071
}
7172

72-
api = new ApiClient().createService(OcrApi.class);
73+
api = new ApiClient().createService(OCRAPI.class);
7374

7475

7576
mImageView = findViewById(R.id.image_view);
@@ -137,23 +138,16 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
137138
inputStream.read(targetArray);
138139

139140
RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), targetArray);
140-
Call<ResponseBody> call = api.RecognizeFromContent(requestBody);
141141

142-
try {
143-
Response<ResponseBody> res = call.execute();
144-
ResponseBody answer = res.body();
142+
OCRResponse ocrResponse = api.RecognizeFromContent(requestBody, Language.English);
145143

146-
OCRResponse ocrResponse = OCRResponse.Deserialize(answer);
147-
String text = ocrResponse.text;
148144

149-
mChooseBtn.setVisibility(View.INVISIBLE);
150-
mTextView.setText(text);
151-
mImageView.setVisibility(View.INVISIBLE);
152-
mTextView.setVisibility(View.VISIBLE);
145+
String text = ocrResponse.text;
153146

154-
} catch (IOException e) {
155-
e.printStackTrace();
156-
}
147+
mChooseBtn.setVisibility(View.INVISIBLE);
148+
mTextView.setText(text);
149+
mImageView.setVisibility(View.INVISIBLE);
150+
mTextView.setVisibility(View.VISIBLE);
157151

158152
} catch (FileNotFoundException e) {
159153
e.printStackTrace();

aspose-ocr-cloud-android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ task createPom {
4646
project {
4747
groupId 'com.aspose'
4848
artifactId 'aspose-cloud-ocr-android'
49-
version '20.4.0'
49+
version '20.7.0'
5050
packaging 'aar'
5151
}
5252
}.withXml {

aspose-ocr-cloud-android/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.aspose</groupId>
55
<artifactId>aspose-cloud-ocr-android</artifactId>
6-
<version>20.4.0</version>
6+
<version>20.7.0</version>
77
<packaging>aar</packaging>
88
<description>Aspose Cloud OCR SDK for Android</description>
99

aspose-ocr-cloud-android/src/main/java/com/aspose/ocr/cloud/android/ApiClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
package com.aspose.ocr.cloud.android;
2929

30+
3031
import com.google.gson.Gson;
3132
import com.google.gson.JsonParseException;
3233

@@ -119,7 +120,7 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
119120
.addConverterFactory(GsonCustomConverterFactory.create(json.getGson()));
120121
}
121122

122-
static String getAccessToken( ){
123+
static String getAccessToken(){
123124

124125
OkHttpClient client = new OkHttpClient();
125126

aspose-ocr-cloud-android/src/main/java/com/aspose/ocr/cloud/android/Configuration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package com.aspose.ocr.cloud.android;
2828

2929
public class Configuration {
30+
3031
static String basePath = "https://api.aspose.cloud/v3.0";
3132
static String authPath = "https://api.aspose.cloud/connect/token";
3233
static String apiKey;
@@ -70,15 +71,15 @@ public static void setAPI_KEY(String apiKey){
7071
}
7172

7273
public static String getTestSrcDir() {
73-
return System.getProperty("user.dir") + "/../" + Configuration.srcTest;
74+
return System.getProperty("user.dir") + "/" + Configuration.srcTest;
7475
}
7576

7677
public static void setTestSrcDir(String testSrcDir) {
7778
Configuration.srcTest = testSrcDir;
7879
}
7980

8081
public static String getTestDstDir() {
81-
return System.getProperty("user.dir") + "/../" + Configuration.dstTest;
82+
return System.getProperty("user.dir") + "/" + Configuration.dstTest;
8283
}
8384

8485
public static void setTestDstDir(String testDstDir) {
Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
11
package com.aspose.ocr.cloud.android.api;
22

3-
import androidx.annotation.NonNull;
3+
import com.google.gson.JsonDeserializationContext;
4+
import com.google.gson.JsonDeserializer;
5+
import com.google.gson.JsonElement;
6+
import com.google.gson.JsonParseException;
7+
import com.google.gson.annotations.SerializedName;
8+
9+
import java.lang.reflect.Type;
410

511
public enum Language {
12+
@SerializedName("1")
613
English (1),
7-
French (2),
8-
German(2)
14+
15+
@SerializedName("2")
16+
German(2),
17+
18+
@SerializedName("3")
19+
French (3),
20+
21+
@SerializedName("4")
22+
Spanish (4),
23+
24+
@SerializedName("5")
25+
Portuguese (5),
26+
27+
@SerializedName("6")
28+
Italian (6)
929
;
1030

11-
private final int code;
31+
private final int key;
32+
33+
Language(int key) {
34+
this.key = key;
35+
}
1236

13-
private Language(int code) {
14-
this.code = code;
37+
public int getKey() {
38+
return this.key;
1539
}
1640

17-
public int getCode() {
18-
return this.code;
41+
public static Language fromKey(int key) {
42+
for(Language type : Language.values()) {
43+
if(type.getKey() == key) {
44+
return type;
45+
}
46+
}
47+
return null;
1948
}
2049

21-
@NonNull
2250
@Override
2351
public String toString() {
24-
return Integer.toString(this.code);
52+
return Integer.toString(this.key);
2553
}
2654
}

0 commit comments

Comments
 (0)