@@ -16,7 +16,7 @@ import androidx.annotation.RequiresApi
16
16
import androidx.appcompat.app.AppCompatActivity
17
17
import androidx.core.content.FileProvider
18
18
import androidx.lifecycle.lifecycleScope
19
- import kotlinx.android.synthetic.main.activity_face.*
19
+ import com.robotemi.sdk.sample.databinding.ActivityFaceBinding
20
20
import kotlinx.coroutines.Dispatchers
21
21
import kotlinx.coroutines.launch
22
22
import java.io.File
@@ -31,43 +31,46 @@ class FaceActivity : AppCompatActivity() {
31
31
private const val AUTHORITY = " ${BuildConfig .APPLICATION_ID } .provider"
32
32
}
33
33
34
+ private lateinit var binding: ActivityFaceBinding
35
+
34
36
override fun onCreate (savedInstanceState : Bundle ? ) {
35
37
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() }
38
41
39
42
40
- btnInsertFromLocalFile.setOnClickListener {
43
+ binding. btnInsertFromLocalFile.setOnClickListener {
41
44
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
42
45
insertFromLocalFile()
43
46
}
44
47
}
45
48
46
- btnInsertFromUrl.setOnClickListener {
49
+ binding. btnInsertFromUrl.setOnClickListener {
47
50
insertFromUrl()
48
51
}
49
52
50
- btnGetAllFaces.setOnClickListener {
53
+ binding. btnGetAllFaces.setOnClickListener {
51
54
queryAllFacesRegistered()
52
55
}
53
56
54
- btnGetAllFacesOfUid.setOnClickListener {
57
+ binding. btnGetAllFacesOfUid.setOnClickListener {
55
58
// queryAllFacesRegistered("uid = ?", arrayOf("0"))
56
59
// queryAllFacesRegistered("uid IN (?,?)", arrayOf("0", "2"))
57
60
// queryAllFacesRegistered("username = ?", arrayOf("Jane Doe"))
58
61
queryAllFacesRegistered(" username LIKE ?" , arrayOf(" %Ja%" )) // username contains Ja
59
62
}
60
63
61
- btnDeleteAllFaces.setOnClickListener {
64
+ binding. btnDeleteAllFaces.setOnClickListener {
62
65
deleteAll()
63
66
}
64
67
65
- btnDeleteAllFacesByUid.setOnClickListener {
68
+ binding. btnDeleteAllFacesByUid.setOnClickListener {
66
69
deleteAllByUid(" 1" , " 2" )
67
70
deleteAllByUsername(" Jane Doe" )
68
71
}
69
72
70
- btnInsertFromCamera.setOnClickListener {
73
+ binding. btnInsertFromCamera.setOnClickListener {
71
74
val photo = " photo.jpeg"
72
75
val photoFile = File (cacheDir, photo)
73
76
val uri = FileProvider .getUriForFile(this , AUTHORITY , photoFile)
@@ -78,13 +81,13 @@ class FaceActivity : AppCompatActivity() {
78
81
}
79
82
}
80
83
81
- btnInsertFromPhotoLibrary.setOnClickListener {
84
+ binding. btnInsertFromPhotoLibrary.setOnClickListener {
82
85
val intent = Intent (Intent .ACTION_PICK , MediaStore .Images .Media .EXTERNAL_CONTENT_URI )
83
86
intent.type = " image/*"
84
87
startActivityForResult(intent, REQUEST_IMAGE_PICKER )
85
88
}
86
89
87
- btnInsertFromContentProvider.setOnClickListener {
90
+ binding. btnInsertFromContentProvider.setOnClickListener {
88
91
lifecycleScope.launch(Dispatchers .IO ) {
89
92
val facesDir = File (filesDir, " faces" )
90
93
try {
@@ -127,10 +130,10 @@ class FaceActivity : AppCompatActivity() {
127
130
null
128
131
}
129
132
Log .d(" Insert" , " $retUri " )
130
- tvLog.text = " ${System .currentTimeMillis()} : Image set ready"
133
+ binding. tvLog.text = " ${System .currentTimeMillis()} : Image set ready"
131
134
} catch (e: IllegalArgumentException ) {
132
135
Log .e(" Insert" , " Insert Exception" , e)
133
- tvLog.text = " ${System .currentTimeMillis()} : Image set failed"
136
+ binding. tvLog.text = " ${System .currentTimeMillis()} : Image set failed"
134
137
}
135
138
}
136
139
}
@@ -143,7 +146,7 @@ class FaceActivity : AppCompatActivity() {
143
146
if (imageBitmap != null ) {
144
147
// Thumbnail will not be null if you doesn't set takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri)
145
148
val drawable = BitmapDrawable (imageBitmap)
146
- tvLog.background = drawable
149
+ binding. tvLog.background = drawable
147
150
}
148
151
149
152
val photo = " photo.jpeg"
@@ -159,10 +162,10 @@ class FaceActivity : AppCompatActivity() {
159
162
contentValues.put(" uri" , uri.toString())
160
163
try {
161
164
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"
163
166
} catch (e: IllegalArgumentException ) {
164
167
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"
166
169
}
167
170
} else if (requestCode == REQUEST_IMAGE_PICKER && resultCode == Activity .RESULT_OK ) {
168
171
Log .d(" Picker" , " $data " )
@@ -175,10 +178,10 @@ class FaceActivity : AppCompatActivity() {
175
178
grantUriPermission(" com.robotemi.face" , uri, Intent .FLAG_GRANT_READ_URI_PERMISSION )
176
179
try {
177
180
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"
179
182
} catch (e: IllegalArgumentException ) {
180
183
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"
182
185
}
183
186
}
184
187
}
@@ -197,10 +200,10 @@ class FaceActivity : AppCompatActivity() {
197
200
try {
198
201
val retUri = contentResolver.insert(Uri .parse(" content://com.robotemi.sdk.TemiSdkDocumentContentProvider/face" ), contentValues)
199
202
Log .d(" Insert" , " $retUri " )
200
- tvLog.text = " ${System .currentTimeMillis()} : Image set ready"
203
+ binding. tvLog.text = " ${System .currentTimeMillis()} : Image set ready"
201
204
} catch (e: IllegalArgumentException ) {
202
205
Log .e(" Insert" , " Insert Exception" , e)
203
- tvLog.text = " ${System .currentTimeMillis()} : Image set failed"
206
+ binding. tvLog.text = " ${System .currentTimeMillis()} : Image set failed"
204
207
}
205
208
}
206
209
}
@@ -223,10 +226,10 @@ class FaceActivity : AppCompatActivity() {
223
226
try {
224
227
val retUri = contentResolver.insert(Uri .parse(" content://com.robotemi.sdk.TemiSdkDocumentContentProvider/face" ), contentValues, bundle)
225
228
Log .d(" Insert" , " $retUri " )
226
- tvLog.text = " ${System .currentTimeMillis()} : Image set ready"
229
+ binding. tvLog.text = " ${System .currentTimeMillis()} : Image set ready"
227
230
} catch (e: IllegalArgumentException ) {
228
231
Log .e(" Insert" , " Insert Exception" , e)
229
- tvLog.text = " ${System .currentTimeMillis()} : Image set failed"
232
+ binding. tvLog.text = " ${System .currentTimeMillis()} : Image set failed"
230
233
}
231
234
}
232
235
@@ -278,7 +281,7 @@ class FaceActivity : AppCompatActivity() {
278
281
counter++
279
282
}
280
283
cursor.close()
281
- tvLog.text = string
284
+ binding. tvLog.text = string
282
285
Log .d(" Query" , " $indexOrUserName , $colCount " )
283
286
}
284
287
0 commit comments