Skip to content

Commit

Permalink
Translate codelab: Add comments, fix method names
Browse files Browse the repository at this point in the history
  • Loading branch information
calren committed Jun 22, 2020
1 parent 5930be1 commit a9243bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion translate/starter/app/build.gradle
Expand Up @@ -64,7 +64,7 @@ dependencies {
def camerax_version = "1.0.0-beta05"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:$camerax_version"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha12"

// Add ML Kit dependencies
Expand Down
Expand Up @@ -94,11 +94,12 @@ class TextAnalyzer(
val croppedBitmap =
ImageUtils.rotateAndCrop(convertImageToBitmap, rotationDegrees, cropRect)

// TODO call recognizeTextOnDevice() once implemented
// TODO call recognizeText() once implemented
}

// TODO Implement recognizeTextOnDevice()
fun recognizeTextOnDevice() {}
fun recognizeText() {
// TODO Use ML Kit's TextRecognition to analyze frames from the camera live feed.
}

private fun getErrorMessage(exception: Exception): String? {
val mlKitException = exception as? MlKitException ?: return exception.message
Expand Down
Expand Up @@ -43,7 +43,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
// TODO Instantiate LanguageIdentification
val targetLang = MutableLiveData<Language>()
val sourceText = SmoothedMutableLiveData<String>(SMOOTHING_DURATION)
// We set desired crop percentages to avoid having the analyze the whole image from the live

// We set desired crop percentages to avoid having to analyze the whole image from the live
// camera feed. However, we are not guaranteed what aspect ratio we will get from the camera, so
// we use the first frame we get back from the camera to update these crop percentages based on
// the actual aspect ratio of images.
Expand Down Expand Up @@ -83,7 +84,10 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
}

private fun translate(): Task<String> {
// TODO
// TODO Take the source language value, target language value, and the source text and
// perform the translation.
// If the chosen target language model has not been downloaded to the device yet,
// call downloadModelIfNeeded() and then proceed with the translation.
return Tasks.forResult("") // replace this with your code
}

Expand Down

0 comments on commit a9243bd

Please sign in to comment.