Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet158/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   154   155   156   157   158   159   160   161   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

185
CHAPTER 8: APIs
Add the callback implementation. Here’s an example:
/**
* Use this to save and manipulate the map once
* available.
*/
override fun onMapReady(map: GoogleMap) {
// Add a marker in Austin, TX and move the camera
val austin = LatLng(30.284935, -97.735464)
map.addMarker(MarkerOptions().position(austin).
title("Marker in Austin"))
map.moveCamera(CameraUpdateFactory.
newLatLng(austin))
}
If Google Play Services is not installed on the device, the user automatically gets prompted 
to install it. The map object can, of course, be saved as a class object field, and you can do 
lots of interesting things with it, including adding markers, lines, zoom, movement,
and more. The possibilities are described in the online API documentation for
com.google.android.gms.maps.GoogleMap.
Preferences
Preferences allow the user to change the way the app performs certain parts of its 
functionalities. Contrary to the input given by the user during the app’s functional workflows, 
preferences are less likely to be changed, so the access to preferences is usually provided 
by a single preferences entry in the app’s menu.
You as a developer might decide to develop special activities for preferences from scratch, 
but you don’t have to do this. In fact, the Preferences API provided by the Android OS is quite 
versatile and allows you to present a preferences or settings dialog in a standard way, letting 
your app appear more professional. Also, you don’t have to implement the GUI yourself.
To start with an example preferences workflow, create a class like this:
class MySettingsFragment : PreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
companion object {
val DELETE_LIMIT = "pref_key_delete_limit"
val LIST = "pref_key_list"
val RINGTONE = "pref_key_ringtone"
}
override fun onSharedPreferenceChanged(
sharedPreferences: SharedPreferences?,
key: String?) {
sharedPreferences?.run {
when(key) {
DELETE_LIMIT -> {
findPreference(key).summary =
getString(key, "") ?: "10"
}



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   154   155   156   157   158   159   160   161   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling