The code below renders the following text in both Android Views and in Jetpack Compose UI.
Contact our team on 555 555 555 Opt 3 to activate.
The code below renders the following text in both Android Views and in Jetpack Compose UI.
Contact our team on 555 555 555 Opt 3 to activate.
| import androidx.compose.animation.core.FastOutSlowInEasing | |
| import androidx.compose.animation.core.animateFloatAsState | |
| import androidx.compose.animation.core.tween | |
| import androidx.compose.foundation.background | |
| import androidx.compose.foundation.layout.BoxWithConstraints | |
| import androidx.compose.foundation.layout.Column | |
| import androidx.compose.foundation.layout.Row | |
| import androidx.compose.foundation.layout.RowScope | |
| import androidx.compose.foundation.layout.fillMaxHeight | |
| import androidx.compose.foundation.layout.fillMaxSize | 
| import android.graphics.Typeface | |
| import androidx.compose.foundation.Canvas | |
| import androidx.compose.foundation.background | |
| import androidx.compose.foundation.layout.BoxWithConstraints | |
| import androidx.compose.foundation.layout.Column | |
| import androidx.compose.foundation.layout.Row | |
| import androidx.compose.foundation.layout.RowScope | |
| import androidx.compose.foundation.layout.fillMaxHeight | |
| import androidx.compose.foundation.layout.fillMaxWidth | |
| import androidx.compose.runtime.Composable | 
| private lateinit var mViewModel: CloudAutoMLViewModel | |
| override fun onCreate(icicle: Bundle?) { | |
| super.onCreate(icicle) | |
| mViewModel = ViewModelProviders.of(this).get(CloudAutoMLViewModel::class.java) | |
| mViewModel.subscribeClassifications() | |
| .observe(this, Observer<Resource<Pair<Int, String>, Throwable>> { resource -> | |
| when (resource) { | |
| is LoadingResource -> { | 
| override fun onNewItem(faceId: Int, item: Face) { | |
| mFaceGraphic = FaceGraphic(faceId, mGraphicOverlay) | |
| mDetector.lastFrame?.let { frame -> | |
| // Lets try and find out who this face belongs to | |
| mViewModel.classify(faceId, frame.convertToByteArray()) | |
| } | |
| } | 
| companion object { | |
| private const val PROJECT = "devnibbles" | |
| private const val LOCATION = "us-central1" | |
| private const val MODEL = "ICN3704829353327390855" | |
| private const val SERVICE_ACCOUNT_JSON = "<insert json here>" | |
| } | |
| private val mServiceCredentials = ServiceAccountCredentials | |
| .fromStream(ByteArrayInputStream(SERVICE_ACCOUNT_JSON.toByteArray(Charset.defaultCharset()))) | |
| .createScoped(mutableListOf("https://www.googleapis.com/auth/cloud-platform")) | 
| companion object { | |
| private const val PROJECT = "devnibbles" | |
| private const val LOCATION = "us-central1" | |
| private const val MODEL = "ICN3704829353327390855" | |
| private const val ACCESS_TOKEN = "<insert token here>" | |
| } | |
| fun classifyUsingRetrofit(faceId: Int, imageBytes: ByteArray) { | |
| launch(errorHandler) { | |
| // Show loading indicator while we wait for the request. | 
| private fun getRESTService(): CloudAutoMLService { | |
| val gsonFactory = GsonConverterFactory | |
| .create(GsonBuilder().create()) | |
| val networkClient = OkHttpClient.Builder() | |
| .addInterceptor(HttpLoggingInterceptor().apply { | |
| level = HttpLoggingInterceptor.Level.BODY | |
| }) | |
| .build() | 
| // Expected json payload for webservice. | |
| // { | |
| // "payload": { | |
| // "image": { | |
| // "imageBytes": "YOUR_IMAGE_BYTE" | |
| // } | |
| // } | |
| // } | |
| data class CloudAutoMLModel(val payload: Payload) | 
| // Expected json response from webservice | |
| //{ | |
| // "payload": [ | |
| // { | |
| // "classification": { | |
| // "score": 0.87991875 | |
| // }, | |
| // "displayName": "Andy" | |
| // } | |
| // ] |