Pro Android with Kotlin
Download 5.42 Mb. Pdf ko'rish
|
@de android telegram Pro Android with Kotlin Developing Modern Mobile
- Bu sahifa navigatsiya:
- Figure 8-6.
164
CHAPTER 8: APIs To generate such a quick contact badge, inside your layout file you must add the following: android:layout_width="60dp" android:layout_height="60dp" android:scaleType="centerCrop"/> In you code you must connect the badge to the following information you get from the contacts provider: the raw contact ID, the lookup key, and a thumbnail URI. The corresponding code might look like this: val id = row[ContactsContract.Contacts._ID] val lookup = row[ContactsContract.Contacts. LOOKUP_KEY] val photo = row[ContactsContract.Contacts. PHOTO_THUMBNAIL_URI] Here, the row, for example, is a map you get from a contacts content provider query. In this case, a query in Raw Contact is enough; you don’t need to also query the Data table. Figure 8-6. A quick contact badge 165 CHAPTER 8: APIs From here we configure the badge as follows, for example after you load the contact information by user interface activities: val contactUri = ContactsContract.Contacts.getLookupUri( id?.toLong()?:0, lookup) quickBadge.assignContactUri(contactUri) val thumbnail = loadContactPhotoThumbnail(photo.toString()) quickBadge.setImageBitmap(thumbnail) Here, the loadContactPhotoThumbnail() function loads the thumbnail image data. private fun loadContactPhotoThumbnail(photoData: String): Bitmap? { var afd: AssetFileDescriptor? = null try { val thumbUri = Uri.parse(photoData) afd = contentResolver. openAssetFileDescriptor(thumbUri, "r") afd?.apply { fileDescriptor?.apply { return BitmapFactory.decodeFileDescriptor( this, null, null) } } } catch (e: FileNotFoundException) { // Handle file not found errors ... } finally { afd?.close() } return null } Search Framework The search framework allows you to seamlessly add search functionality to your app and register your app as a searchable items provider in the Android OS. Talking of the user interface, you have two options. Opening a search dialog Adding a search widget to your UI via SearchView |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling