Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ client.getImageInformation(file, new CloudSightCallback() {
}

@Override
public void imageRecognised(CloudSightResponse response) {
public void imageRecognized(CloudSightResponse response) {
Log.d("CloudSight ", "Recognition process finished");
}

@Override
public void recognitionFail(String reason) {
public void imageRecognitionFailed(String reason) {
Log.d("CloudSight ", "Recognition process fail by reason");
}

@Override
public void onFail(Throwable throwable) {
public void onFailure(Throwable throwable) {
Log.d("CloudSight ", "Recognition request fail");
}
});
Expand All @@ -85,17 +85,17 @@ client.getImageInformation(url, new CloudSightCallback() {
}

@Override
public void imageRecognised(CloudSightResponse response) {
public void imageRecognized(CloudSightResponse response) {
Log.d("CloudSight ", "Recognition process finished");
}

@Override
public void recognitionFail(String reason) {
public void imageRecognitionFailed(String reason) {
Log.d("CloudSight ", "Recognition process fail by reason");
}

@Override
public void onFail(Throwable throwable) {
public void onFailure(Throwable throwable) {
Log.d("CloudSight ", "Recognition request fail");
}
});
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions androidsdk/src/main/res/values/strings.xml

This file was deleted.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(':androidsdk')
implementation project(':cloudsight')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/ai/cloudsight/demoapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ public void imageUploaded(CloudSightResponse response) {
}

@Override
public void imageRecognised(CloudSightResponse response) {
public void imageRecognized(CloudSightResponse response) {
statusTextView.setText("Status: " + response.getStatus());
resultTextView.setText("Result: " + response.getName());
}

@Override
public void recognitionFail(String reason) {
public void imageRecognitionFailed(String reason) {
statusTextView.setText("Status: " + reason);

}

@Override
public void onFail(Throwable throwable) {
public void onFailure(Throwable throwable) {
statusTextView.setText("Status: " + throwable.getLocalizedMessage());
}
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BasicAuthInterceptor(String user, String password) {
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request authenticatedRequest = request.newBuilder()
.header("Authorization ", credentials).build();
.header("Authorization ", credentials).build(); // Are these encrypted somehow similar to CamFind? Can they be so our users don't have to worry about security?
return chain.proceed(authenticatedRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import retrofit2.http.Part;
import retrofit2.http.Path;

public interface CloudsSightApi {
public interface CloudSightApi {

@Headers("User-Agent: Android")
@Headers("User-Agent: Android") // This we'll want to use the device-specific user-agent. This is super important, especially for ad providers.
@Multipart
@POST("/v1/images")
Call<CloudSightResponse> recognitionByImageFile(
@Part("locale") RequestBody locale,
@Part("locale") RequestBody locale, // Again, optional. :-)
@Part("image\"; filename=\"myfile.jpg\" ") RequestBody file);

@Multipart
@POST("/v1/images")
Call<CloudSightResponse> recognitionByUrl(
Call<CloudSightResponse> recognitionByRemoteImageUrl(
@Part("locale")
RequestBody locale,
RequestBody locale, // Again, optional. :-)
@Part("remote_image_url")
RequestBody imageUrl);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ai.cloudsight.androidsdk;

public interface CloudSightCallback {

void imageUploaded(CloudSightResponse response);
void imageRecognized(CloudSightResponse response);
void imageRecognitionFailed(String reason);
void onFailure(Throwable response);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,58 @@ private static CloudSightClient getInstance() {
return ourInstance;
}

private String locale = "en-Us";

// `locale` is optional - is there a way to make this an optional setting?
private String locale = "en-US";
public void setLocale(String locale){
this.locale = locale;
}

public CloudSightClient init(@NonNull String apiKey) {
CloudSightClient.getInstance().cloudsSightApi = NetworkService.getInstance(apiKey)
.getCloudsSightApi();
CloudSightClient.getInstance().cloudSightApi = NetworkService.getInstance(apiKey)
.getCloudSightApi();
return CloudSightClient.getInstance();
}

public CloudSightClient init(@NonNull String consumerKey, @NonNull String consumerSecret) {
CloudSightClient.getInstance().cloudsSightApi = NetworkService.getInstance(consumerKey, consumerSecret)
.getCloudsSightApi();
CloudSightClient.getInstance().cloudSightApi = NetworkService.getInstance(consumerKey, consumerSecret)
.getCloudSightApi();
return CloudSightClient.getInstance();
}

private CloudsSightApi cloudsSightApi;
private CloudSightApi cloudSightApi;

public void getImageInformation(File imageFile, final CloudSightCallback callback) {

RequestBody localeRequest = RequestBody.create(MediaType.parse("text/plain"), locale);
RequestBody image = RequestBody.create(MediaType.parse("multipart/form-data"), imageFile);


cloudsSightApi.recognitionByImageFile(localeRequest, image)
cloudSightApi.recognitionByImageFile(localeRequest, image)
.enqueue(new Callback<CloudSightResponse>() {
@Override
public void onResponse(Call<CloudSightResponse> call, Response<CloudSightResponse> response) {
if (response.isSuccessful()) {
callback.imageUploaded(response.body());
assert response.body() != null;
checkResponse(response.body(), callback);
}else {
callback.recognitionFail(response.errorBody().toString());
} else {
callback.imageRecognitionFailed(response.errorBody().toString());
}
}

@Override
public void onFailure(Call<CloudSightResponse> call, Throwable t) {
callback.onFail(t);
callback.onFailure(t);
}
});
}


public void getImageInformation(String url, final CloudSightCallback callback) {
public void getImageInformation(String remoteImageUrl, final CloudSightCallback callback) {

RequestBody localeRequest = RequestBody.create(MediaType.parse("text/plain"), locale);
RequestBody image = RequestBody.create(MediaType.parse("text/plain"), url);
RequestBody image = RequestBody.create(MediaType.parse("text/plain"), remoteImageUrl);

cloudsSightApi.recognitionByUrl(localeRequest, image)
cloudSightApi.recognitionByRemoteImageUrl(localeRequest, image)
.enqueue(new Callback<CloudSightResponse>() {
@Override
public void onResponse(Call<CloudSightResponse> call, Response<CloudSightResponse> response) {
Expand All @@ -80,7 +79,7 @@ public void onResponse(Call<CloudSightResponse> call, Response<CloudSightRespons

@Override
public void onFailure(Call<CloudSightResponse> call, Throwable t) {
callback.onFail(t);
callback.onFailure(t);
}
});

Expand All @@ -91,25 +90,25 @@ private void checkResponse(CloudSightResponse response, final CloudSightCallback
try {
switch (RecognitionStatus.valueOf(response.getStatus().toLowerCase())) {
case COMPLETED:
callback.imageRecognised(response);
callback.imageRecognized(response);
break;
case SKIPPED:
callback.recognitionFail(response.getReason());
callback.imageRecognitionFailed(response.getReason());
break;
case TIMEOUT:
case NOT_FOUND:
callback.recognitionFail(response.getStatus());
callback.imageRecognitionFailed(response.getStatus());
break;
case NOT_COMPLETED:
getInformationByToken(response.getToken(), callback);
}
} catch (IllegalArgumentException e) {
callback.recognitionFail("Failed response status");
callback.imageRecognitionFailed("Unhandled response status");
}
}

private void getInformationByToken(String token, final CloudSightCallback callback) {
cloudsSightApi.getInfoByToken(token)
cloudSightApi.getInfoByToken(token)
.enqueue(new Callback<CloudSightResponse>() {
@Override
public void onResponse(Call<CloudSightResponse> call, Response<CloudSightResponse> response) {
Expand All @@ -119,7 +118,7 @@ public void onResponse(Call<CloudSightResponse> call, Response<CloudSightRespons

@Override
public void onFailure(Call<CloudSightResponse> call, Throwable t) {
callback.onFail(t);
callback.onFailure(t);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@

public class NetworkService {

private static final String CLOUDSIGHT_URL = "https://api.cloudsight.ai";


private static final String CLOUDSIGHT_URL = "https://api.cloudsight.ai"; // Could this be some kind of 'configuration variable'?
private static NetworkService mInstance;


private Retrofit mRetrofit;

private NetworkService(final String apiKey) {
Expand All @@ -27,7 +23,7 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();

Request request = original.newBuilder()
.addHeader("authorization", "CloudSight " + apiKey)
.addHeader("Authorization", "CloudSight " + apiKey)
.method(original.method(), original.body())
.build();

Expand All @@ -44,23 +40,19 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
.build();
}


private NetworkService(String consumerKey, String consumerSecret) {


OkHttpClient httpClient = new OkHttpClient.Builder()
.addInterceptor(new BasicAuthInterceptor(consumerKey, consumerSecret))
.build();


mRetrofit = new Retrofit.Builder()
.baseUrl(CLOUDSIGHT_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient)
.build();
}


public static NetworkService getInstance(String apiKey) {
if (mInstance == null) {
mInstance = new NetworkService(apiKey);
Expand All @@ -75,7 +67,7 @@ public static NetworkService getInstance(String consumerKey, String consumerSecr
return mInstance;
}

public CloudsSightApi getCloudsSightApi() {
return mRetrofit.create(CloudsSightApi.class);
public CloudSightApi getCloudSightApi() {
return mRetrofit.create(CloudSightApi.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public enum RecognitionStatus {
NOT_FOUND("not found"),
NOT_COMPLETED("not completed");


private String status;

RecognitionStatus(String status) {
Expand Down
3 changes: 3 additions & 0 deletions cloudsight/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">CloudSight Android SDK v1.0</string>
</resources>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':androidsdk'
include ':app', ':cloudsight'