Skip to content

Commit 187f753

Browse files
committed
Apply view binding
1 parent 8975875 commit 187f753

File tree

8 files changed

+577
-552
lines changed

8 files changed

+577
-552
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.6.21'
4+
ext.kotlin_version = '1.7.20'
55

66
repositories {
77
google()

sample/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
43

54
repositories {
65
mavenLocal()
@@ -10,7 +9,7 @@ repositories {
109
}
1110

1211
android {
13-
compileSdkVersion 33
12+
compileSdk 34
1413

1514
defaultConfig {
1615
applicationId "com.robotemi.sdk.sample"
@@ -39,6 +38,10 @@ android {
3938
lintOptions {
4039
abortOnError false
4140
}
41+
buildFeatures {
42+
buildConfig true
43+
viewBinding true
44+
}
4245
}
4346

4447
dependencies {

sample/src/main/java/com/robotemi/sdk/sample/FaceActivity.kt

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import androidx.annotation.RequiresApi
1616
import androidx.appcompat.app.AppCompatActivity
1717
import androidx.core.content.FileProvider
1818
import androidx.lifecycle.lifecycleScope
19-
import kotlinx.android.synthetic.main.activity_face.*
19+
import com.robotemi.sdk.sample.databinding.ActivityFaceBinding
2020
import kotlinx.coroutines.Dispatchers
2121
import kotlinx.coroutines.launch
2222
import java.io.File
@@ -31,43 +31,46 @@ class FaceActivity : AppCompatActivity() {
3131
private const val AUTHORITY = "${BuildConfig.APPLICATION_ID}.provider"
3232
}
3333

34+
private lateinit var binding: ActivityFaceBinding
35+
3436
override fun onCreate(savedInstanceState: Bundle?) {
3537
super.onCreate(savedInstanceState)
36-
setContentView(R.layout.activity_face)
37-
ibBack.setOnClickListener { finish() }
38+
binding = ActivityFaceBinding.inflate(layoutInflater)
39+
setContentView(binding.root)
40+
binding.ibBack.setOnClickListener { finish() }
3841

3942

40-
btnInsertFromLocalFile.setOnClickListener {
43+
binding.btnInsertFromLocalFile.setOnClickListener {
4144
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
4245
insertFromLocalFile()
4346
}
4447
}
4548

46-
btnInsertFromUrl.setOnClickListener {
49+
binding.btnInsertFromUrl.setOnClickListener {
4750
insertFromUrl()
4851
}
4952

50-
btnGetAllFaces.setOnClickListener {
53+
binding.btnGetAllFaces.setOnClickListener {
5154
queryAllFacesRegistered()
5255
}
5356

54-
btnGetAllFacesOfUid.setOnClickListener {
57+
binding.btnGetAllFacesOfUid.setOnClickListener {
5558
// queryAllFacesRegistered("uid = ?", arrayOf("0"))
5659
// queryAllFacesRegistered("uid IN (?,?)", arrayOf("0", "2"))
5760
// queryAllFacesRegistered("username = ?", arrayOf("Jane Doe"))
5861
queryAllFacesRegistered("username LIKE ?", arrayOf("%Ja%")) // username contains Ja
5962
}
6063

61-
btnDeleteAllFaces.setOnClickListener {
64+
binding.btnDeleteAllFaces.setOnClickListener {
6265
deleteAll()
6366
}
6467

65-
btnDeleteAllFacesByUid.setOnClickListener {
68+
binding.btnDeleteAllFacesByUid.setOnClickListener {
6669
deleteAllByUid("1", "2")
6770
deleteAllByUsername("Jane Doe")
6871
}
6972

70-
btnInsertFromCamera.setOnClickListener {
73+
binding.btnInsertFromCamera.setOnClickListener {
7174
val photo = "photo.jpeg"
7275
val photoFile = File(cacheDir, photo)
7376
val uri = FileProvider.getUriForFile(this, AUTHORITY, photoFile)
@@ -78,13 +81,13 @@ class FaceActivity : AppCompatActivity() {
7881
}
7982
}
8083

81-
btnInsertFromPhotoLibrary.setOnClickListener {
84+
binding.btnInsertFromPhotoLibrary.setOnClickListener {
8285
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
8386
intent.type = "image/*"
8487
startActivityForResult(intent, REQUEST_IMAGE_PICKER)
8588
}
8689

87-
btnInsertFromContentProvider.setOnClickListener {
90+
binding.btnInsertFromContentProvider.setOnClickListener {
8891
lifecycleScope.launch(Dispatchers.IO) {
8992
val facesDir = File(filesDir, "faces")
9093
try {
@@ -127,10 +130,10 @@ class FaceActivity : AppCompatActivity() {
127130
null
128131
}
129132
Log.d("Insert", "$retUri")
130-
tvLog.text = "${System.currentTimeMillis()}: Image set ready"
133+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set ready"
131134
} catch (e: IllegalArgumentException) {
132135
Log.e("Insert", "Insert Exception", e)
133-
tvLog.text = "${System.currentTimeMillis()}: Image set failed"
136+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set failed"
134137
}
135138
}
136139
}
@@ -143,7 +146,7 @@ class FaceActivity : AppCompatActivity() {
143146
if (imageBitmap != null) {
144147
// Thumbnail will not be null if you doesn't set takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri)
145148
val drawable = BitmapDrawable(imageBitmap)
146-
tvLog.background = drawable
149+
binding.tvLog.background = drawable
147150
}
148151

149152
val photo = "photo.jpeg"
@@ -159,10 +162,10 @@ class FaceActivity : AppCompatActivity() {
159162
contentValues.put("uri", uri.toString())
160163
try {
161164
val retUri = contentResolver.insert(Uri.parse("content://com.robotemi.sdk.TemiSdkDocumentContentProvider/face"), contentValues)
162-
tvLog.text = "${System.currentTimeMillis()}: Image set ready from camera"
165+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set ready from camera"
163166
} catch (e: IllegalArgumentException) {
164167
Log.e("Insert", "Insert Exception", e)
165-
tvLog.text = "${System.currentTimeMillis()}: Image set failed from camera"
168+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set failed from camera"
166169
}
167170
} else if (requestCode == REQUEST_IMAGE_PICKER && resultCode == Activity.RESULT_OK) {
168171
Log.d("Picker", "$data")
@@ -175,10 +178,10 @@ class FaceActivity : AppCompatActivity() {
175178
grantUriPermission("com.robotemi.face", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
176179
try {
177180
val retUri = contentResolver.insert(Uri.parse("content://com.robotemi.sdk.TemiSdkDocumentContentProvider/face"), contentValues)
178-
tvLog.text = "${System.currentTimeMillis()}: Image set ready from gallery"
181+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set ready from gallery"
179182
} catch (e: IllegalArgumentException) {
180183
Log.e("Insert", "Insert Exception", e)
181-
tvLog.text = "${System.currentTimeMillis()}: Image set failed from gallery"
184+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set failed from gallery"
182185
}
183186
}
184187
}
@@ -197,10 +200,10 @@ class FaceActivity : AppCompatActivity() {
197200
try {
198201
val retUri = contentResolver.insert(Uri.parse("content://com.robotemi.sdk.TemiSdkDocumentContentProvider/face"), contentValues)
199202
Log.d("Insert", "$retUri")
200-
tvLog.text = "${System.currentTimeMillis()}: Image set ready"
203+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set ready"
201204
} catch (e: IllegalArgumentException) {
202205
Log.e("Insert", "Insert Exception", e)
203-
tvLog.text = "${System.currentTimeMillis()}: Image set failed"
206+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set failed"
204207
}
205208
}
206209
}
@@ -223,10 +226,10 @@ class FaceActivity : AppCompatActivity() {
223226
try {
224227
val retUri = contentResolver.insert(Uri.parse("content://com.robotemi.sdk.TemiSdkDocumentContentProvider/face"), contentValues, bundle)
225228
Log.d("Insert", "$retUri")
226-
tvLog.text = "${System.currentTimeMillis()}: Image set ready"
229+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set ready"
227230
} catch (e: IllegalArgumentException) {
228231
Log.e("Insert", "Insert Exception", e)
229-
tvLog.text = "${System.currentTimeMillis()}: Image set failed"
232+
binding.tvLog.text = "${System.currentTimeMillis()}: Image set failed"
230233
}
231234
}
232235

@@ -278,7 +281,7 @@ class FaceActivity : AppCompatActivity() {
278281
counter++
279282
}
280283
cursor.close()
281-
tvLog.text = string
284+
binding.tvLog.text = string
282285
Log.d("Query", "$indexOrUserName, $colCount")
283286
}
284287

0 commit comments

Comments
 (0)