Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e797a63

Browse files
Google ML Kitzhouyiself
Google ML Kit
authored andcommitted
Update SDK version for the entity extraction demo.
PiperOrigin-RevId: 713941928 Change-Id: Ie3c502598ce6880499554344c7f202ccec8a267e
1 parent 3307e59 commit e797a63

File tree

4 files changed

+37
-53
lines changed

4 files changed

+37
-53
lines changed

‎android/entityextraction/app/build.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88

99
defaultConfig {
1010
applicationId "com.google.mlkit.samples.nl.entityextraction"
11-
minSdkVersion 19
11+
minSdkVersion 26
1212
targetSdkVersion 34
1313
multiDexEnabled true
1414
versionCode 1
@@ -46,7 +46,7 @@ dependencies {
4646
implementation project(':internal:chooserx')
4747
implementation 'androidx.appcompat:appcompat:1.1.0'
4848
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
49-
implementation 'com.google.mlkit:entity-extraction:16.0.0-beta5'
49+
implementation 'com.google.mlkit:entity-extraction:16.0.0-beta6'
5050

5151
// Optional dependency used for the Snackbar
5252
implementation 'com.google.android.material:material:1.2.0'

‎android/entityextraction/app/src/main/java/com/google/mlkit/samples/nl/entityextraction/kotlin/MainActivityKotlin.kt‎

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import java.text.DateFormat
2525
import java.util.Date
2626
import java.util.Locale
2727

28-
/** Default launcher activity. */
28+
/** Default launcher activity. */
2929
class MainActivityKotlin : AppCompatActivity() {
3030

3131
companion object {
@@ -38,8 +38,7 @@ class MainActivityKotlin : AppCompatActivity() {
3838
}
3939
}
4040

41-
@ModelIdentifier
42-
private var currentModel: String = EntityExtractorOptions.ENGLISH
41+
@ModelIdentifier private var currentModel: String = EntityExtractorOptions.ENGLISH
4342

4443
private lateinit var entityExtractor: EntityExtractor
4544
private lateinit var currentModelView: TextView
@@ -50,15 +49,16 @@ class MainActivityKotlin : AppCompatActivity() {
5049
super.onCreate(savedInstanceState)
5150
setContentView(R.layout.activity_main)
5251

53-
currentModel = savedInstanceState?.getString(CURRENT_MODEL_KEY, EntityExtractorOptions.ENGLISH)
54-
?: EntityExtractorOptions.ENGLISH
52+
currentModel =
53+
savedInstanceState?.getString(CURRENT_MODEL_KEY, EntityExtractorOptions.ENGLISH)
54+
?: EntityExtractorOptions.ENGLISH
5555

5656
val options = EntityExtractorOptions.Builder(currentModel).build()
5757
entityExtractor = EntityExtraction.getClient(options)
5858
lifecycle.addObserver(entityExtractor)
5959

6060
currentModelView = findViewById(R.id.current_model)
61-
currentModelView.text = getString(R.string.current_model, currentModel.toUpperCase(Locale.US))
61+
currentModelView.text = getString(R.string.current_model, currentModel.uppercase(Locale.US))
6262
val currentLocaleView: TextView = findViewById(R.id.current_locale)
6363
currentLocaleView.text = getString(R.string.current_locale, Locale.getDefault())
6464
input = findViewById(R.id.text_input)
@@ -67,10 +67,7 @@ class MainActivityKotlin : AppCompatActivity() {
6767
findViewById<Button>(R.id.button).setOnClickListener {
6868
val newInput = input.text.toString()
6969
if (newInput.isEmpty()) {
70-
Toast.makeText(
71-
this@MainActivityKotlin,
72-
R.string.empty_input, Toast.LENGTH_LONG
73-
).show()
70+
Toast.makeText(this@MainActivityKotlin, R.string.empty_input, Toast.LENGTH_LONG).show()
7471
return@setOnClickListener
7572
}
7673
extractEntities(newInput)
@@ -81,13 +78,7 @@ class MainActivityKotlin : AppCompatActivity() {
8178
output.setText(R.string.wait_message)
8279
entityExtractor
8380
.downloadModelIfNeeded()
84-
.onSuccessTask {
85-
entityExtractor.annotate(
86-
getEntityExtractionParams(
87-
input
88-
)
89-
)
90-
}
81+
.onSuccessTask { entityExtractor.annotate(getEntityExtractionParams(input)) }
9182
.addOnFailureListener { e: Exception? ->
9283
Log.e(TAG, "Annotation failed", e)
9384
output.text = getString(R.string.entity_extraction_error)
@@ -116,10 +107,7 @@ class MainActivityKotlin : AppCompatActivity() {
116107

117108
override fun onOptionsItemSelected(item: MenuItem): Boolean {
118109
if (item.itemId == R.id.action_btn) {
119-
startActivityForResult(
120-
Intent(this, ModelsActivityKotlin::class.java),
121-
REQUEST_CODE
122-
)
110+
startActivityForResult(Intent(this, ModelsActivityKotlin::class.java), REQUEST_CODE)
123111
return true
124112
}
125113
return super.onOptionsItemSelected(item)
@@ -138,7 +126,7 @@ class MainActivityKotlin : AppCompatActivity() {
138126
if (newModel != null) {
139127
currentModel = newModel
140128
}
141-
currentModelView.text = getString(R.string.current_model, currentModel.toUpperCase(Locale.US))
129+
currentModelView.text = getString(R.string.current_model, currentModel.uppercase(Locale.US))
142130
entityExtractor =
143131
EntityExtraction.getClient(EntityExtractorOptions.Builder(currentModel).build())
144132
}
@@ -174,7 +162,7 @@ class MainActivityKotlin : AppCompatActivity() {
174162
getString(
175163
R.string.phone_entity_info_formatted,
176164
annotatedText,
177-
PhoneNumberUtils.formatNumber(annotatedText)
165+
PhoneNumberUtils.formatNumber(annotatedText),
178166
)
179167
)
180168
}
@@ -188,14 +176,15 @@ class MainActivityKotlin : AppCompatActivity() {
188176
}
189177

190178
private fun displayDateTimeInfo(entity: Entity, annotatedText: String) {
191-
val dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)
192-
.format(Date(entity.asDateTimeEntity()!!.timestampMillis))
179+
val dateTimeFormat =
180+
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)
181+
.format(Date(entity.asDateTimeEntity()!!.timestampMillis))
193182
output.append(
194183
getString(
195184
R.string.date_time_entity_info,
196185
annotatedText,
197186
dateTimeFormat,
198-
convertGranularityToString(entity)
187+
convertGranularityToString(entity),
199188
)
200189
)
201190
}
@@ -221,7 +210,7 @@ class MainActivityKotlin : AppCompatActivity() {
221210
R.string.tracking_number_entity_info,
222211
annotatedText,
223212
trackingNumberEntity!!.parcelCarrier,
224-
trackingNumberEntity.parcelTrackingNumber
213+
trackingNumberEntity.parcelTrackingNumber,
225214
)
226215
)
227216
}
@@ -233,15 +222,13 @@ class MainActivityKotlin : AppCompatActivity() {
233222
R.string.payment_card_entity_info,
234223
annotatedText,
235224
paymentCardEntity!!.paymentCardNetwork,
236-
paymentCardEntity.paymentCardNumber
225+
paymentCardEntity.paymentCardNumber,
237226
)
238227
)
239228
}
240229

241230
private fun displayIsbnInfo(entity: Entity, annotatedText: String) {
242-
output.append(
243-
getString(R.string.isbn_entity_info, annotatedText, entity.asIsbnEntity()!!.isbn)
244-
)
231+
output.append(getString(R.string.isbn_entity_info, annotatedText, entity.asIsbnEntity()!!.isbn))
245232
}
246233

247234
private fun displayIbanInfo(entity: Entity, annotatedText: String) {
@@ -251,7 +238,7 @@ class MainActivityKotlin : AppCompatActivity() {
251238
R.string.iban_entity_info,
252239
annotatedText,
253240
ibanEntity!!.iban,
254-
ibanEntity.ibanCountryCode
241+
ibanEntity.ibanCountryCode,
255242
)
256243
)
257244
}
@@ -263,7 +250,7 @@ class MainActivityKotlin : AppCompatActivity() {
263250
R.string.flight_number_entity_info,
264251
annotatedText,
265252
flightNumberEntity!!.airlineCode,
266-
flightNumberEntity.flightNumber
253+
flightNumberEntity.flightNumber,
267254
)
268255
)
269256
}
@@ -276,7 +263,7 @@ class MainActivityKotlin : AppCompatActivity() {
276263
annotatedText,
277264
moneyEntity!!.unnormalizedCurrency,
278265
moneyEntity.integerPart,
279-
moneyEntity.fractionalPart
266+
moneyEntity.fractionalPart,
280267
)
281268
)
282269
}

‎android/entityextraction/app/src/main/java/com/google/mlkit/samples/nl/entityextraction/kotlin/ModelsActivityKotlin.kt‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ class ModelsActivityKotlin : AppCompatActivity() {
4040
val languageAdapter = LanguageAdapter(languages)
4141
listView.adapter = languageAdapter
4242

43-
listView.onItemClickListener =
44-
OnItemClickListener { _, _, position, _ ->
45-
val intent = Intent(this@ModelsActivityKotlin, MainActivityKotlin::class.java)
46-
intent.putExtra(
47-
MODEL_KEY,
48-
listView.getItemAtPosition(position).toString()
49-
)
50-
setResult(Activity.RESULT_OK, intent)
51-
finish()
52-
}
43+
listView.onItemClickListener = OnItemClickListener { _, _, position, _ ->
44+
val intent = Intent(this@ModelsActivityKotlin, MainActivityKotlin::class.java)
45+
intent.putExtra(MODEL_KEY, listView.getItemAtPosition(position).toString())
46+
setResult(Activity.RESULT_OK, intent)
47+
finish()
48+
}
5349
}
5450

5551
internal inner class LanguageAdapter(private val languageList: List<String>) : BaseAdapter() {
@@ -145,14 +141,15 @@ class ModelsActivityKotlin : AppCompatActivity() {
145141
}
146142
}
147143

148-
private fun getSnackbarMessage(): String = resources.getQuantityString(
149-
R.plurals.snackbar_message,
150-
downloadingModels.size,
151-
getFormattedListOfDownloadingModels()
152-
)
144+
private fun getSnackbarMessage(): String =
145+
resources.getQuantityString(
146+
R.plurals.snackbar_message,
147+
downloadingModels.size,
148+
getFormattedListOfDownloadingModels(),
149+
)
153150

154151
private fun getFormattedListOfDownloadingModels(): String {
155-
return downloadingModels.map { it.toUpperCase(Locale.US) }.joinToString { ", " }
152+
return downloadingModels.map { it.uppercase(Locale.US) }.joinToString { ", " }
156153
}
157154
}
158155
}

‎android/entityextraction/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.9.0'
2+
ext.kotlin_version = '2.1.0'
33

44
repositories {
55
google()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /