Geofencing + Places SDK for Android with Kotlin | Masterclass | Stevdza - San | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Geofencing + Places SDK for Android with Kotlin | Masterclass

teacher avatar Stevdza - San, Android Developer & UX/UI Designer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

67 Lessons (8h 57m)
    • 1. Introduction

      3:29
    • 2. Dependency Overview

      2:18
    • 3. Application Design Preview

      3:27
    • 4. Geofencing API Limitations

      12:24
    • 5. This Project is on Github

      0:30
    • 6. About Places API

      10:07
    • 7. Place IDs

      3:58
    • 8. Place Types & Data Fields

      5:03
    • 9. Session Tokens

      2:10
    • 10. Connect the Project with Google Cloud Platform

      5:29
    • 11. Generate Release API Key

      6:20
    • 12. Autocomplete Widget - Fragment

      13:49
    • 13. Autocomplete Widget - Activity

      7:27
    • 14. Constrain Autocomplete Results

      8:32
    • 15. Get the Current Location

      7:14
    • 16. Get a Place by ID

      8:28
    • 17. Get Place Photos

      6:24
    • 18. Get Introduced with Application Design

      4:30
    • 19. Implement Navigation Component

      8:48
    • 20. Design PermissionFragment Layout

      6:39
    • 21. Create Permissions object

      7:49
    • 22. Create DataStoreRepository

      7:31
    • 23. Create SharedViewModel

      4:34
    • 24. PermissionFragment

      16:50
    • 25. Connect the Project with Google Cloud Platform

      9:21
    • 26. Design Step1Fragment Layout

      10:14
    • 27. Step1Fragment - Part 1

      16:17
    • 28. Step1Fragment - Part 2

      8:51
    • 29. Create Step1Bindings

      14:42
    • 30. Handle the ProgressBar

      6:15
    • 31. Design Step2Fragment Layout

      11:20
    • 32. Step2Fragment - Part 1

      12:50
    • 33. Create PredictionsAdapter

      15:46
    • 34. Step2Fragment - Part 2

      8:35
    • 35. AutocompletePrediction - Click Listener

      14:58
    • 36. Create NetworkListener

      8:24
    • 37. Step2Fragment - Error Handling

      12:08
    • 38. Step2Fragment - RecyclerView Item Animation

      4:23
    • 39. Display Google Attribution

      2:16
    • 40. Design Step3Fragment Layout

      6:57
    • 41. Implement Step3Fragment

      13:45
    • 42. Change Map Style

      3:15
    • 43. Design MapsFragment Layout

      5:45
    • 44. zoomToSelectedLocation - MapsFragment

      8:49
    • 45. Setup ROOM Database

      13:54
    • 46. Inject GeofenceRepository

      2:53
    • 47. Draw a Circle on the Map

      13:55
    • 48. zoomToGeofence - MapsFragment

      9:21
    • 49. Take a Map Snapshot

      4:12
    • 50. Add a Geofence to the Database

      6:11
    • 51. readDatabase - MapsFragment

      7:34
    • 52. Create GeofenceBroadcastReceiver

      11:40
    • 53. Start a Geofence

      14:16
    • 54. Reset Shared Values

      6:08
    • 55. Design GeofencesFragment Layout

      5:07
    • 56. Design geofences_row_layout

      11:18
    • 57. Motion Layout - geofences_row_layout

      4:27
    • 58. Create GeofencesAdapter

      9:06
    • 59. Display Geofences in a RecyclerView

      5:28
    • 60. delete_imageView - Handle Click Event

      6:21
    • 61. removeItem - GeofencesAdapter

      15:51
    • 62. snapshot_imageView - Handle Click Event

      8:11
    • 63. Animate geofence_recyclerView

      2:02
    • 64. Transition Animations - Navigation Component

      13:02
    • 65. Final Word

      1:48
    • 66. Step1Fragment - App Crash Fixed

      2:00
    • 67. jcenter() Migration, Easy Permissions, Dependency Update

      3:14
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

81

Students

--

Projects

About This Class

Hello there and welcome to my course, in this course I'm going to teach you everything you need to know to implement Geofence API in your project. And not just that, as a Bonus I'm going to teach you how to integrate Places SDK for Android as well.

Now this is not the course where you will learn just the theory, this is the course where you will combine theory with practice, and also create one Android application which will use both Geofence API and Places SDK. First I'm going to start this course by introducing you with Places SDK for android. You will learn how to connect your project with the Google Cloud platform, and generate an API key as well. After that you will learn more about Places Autocomplete widget, how we can use it to receive different kind of places as a response. Also how to get more details about the specific place, then how to get places information around your current location, and place photos as well. Plus You will learn more about place ID's, place types, data fields and session tokens.

Now after you get fully introduced with Places SDK for android, we are going to start building our Geofence app. And for those of you who are not familiar, Geofence API combines awareness of the user's current location with awareness of the user's proximity to locations that may be of interest. So basically in our application which we are going to create, we will have a good looking flow to get more information from a user regarding the creation of a Geofence. We will be able to create multiple geofences in our app and get notified whenever we ENTER/EXIT OR STAY within the Geofence for a specified amount of time.

Now I have already prepared design project which we are going to use in this course, so you don't have to worry about that. Also that design project will be available to you for FREE along with the source code of the project on which we are going to work on. The source code will be available on my Github profile.

So, our app will use the most popular Android Architecture components like: ROOM database, Dagger-Hilt dependency Injection library, Navigation Component, View Model, Live Data, Data Store Preference, View Binding, Data Binding, Kotlin Coroutines, Flow and many more...

We are going to follow the principle of a single activity and multiple fragments. Our application will have six different fragments. And we will also use nested navigation graph in our app.

Now, all my courses are well organized, very informative, and they will provide you with all the necessary knowledge you need to work with the latest android API levels. Plus at the end of the course we will have one special section where I'm going to occasionally upload some course updates, like bug fixes and code cleanups. And that way this course will always be up-to-date.

Now what I want here, I want to include you in this project of mine. I want to make you think, like a real developer. After we finish this course and building our app, I expect you to look into the code again and suggest what else could be improved in the app which we are going to create. You can also report some bugs if you find, and even suggest a solution by yourself if you have one.

Anyhow, there is a 9hours of high quality content waiting for you.

So what are you waiting for, let's get started developers!

Meet Your Teacher

Teacher Profile Image

Stevdza - San

Android Developer & UX/UI Designer

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: Hello there and welcome to my course. In this course I'm going to teach you everything you need to know to implement the geofence API in your project and they're not adjust that. As a bonus, I'm going to teach you how to integrate Places SDK for Android as well. Now, this is not a course where you will learn that in just a theory. This is the course where you will combine the theory with the practice and also create one or Android application which will use both the geofence API and the places SDK. First, I'm going to start this course by introducing new with places SDK for Android. You will learn how to connect your project with the Google Cloud Platform and generate an API key as well. After that, you will learn more about the places that auto complete widget and how we can use it to receive a different kind of places as a response. Next, you will learn how to get more details about the specific place, then how to get places information around your current location and place photos as well. Plus, you will learn more about the place IDs, plays types, data fields, and their session tokens. Now, after you get fully introduced with a places SDK for Android, we're going to start building our geofence application. And therefore, those of you who are not familiar. Geofence API combines awareness of the user's current location with awareness of their users proximity to location that may be of interest. So we're basically in our application which we are going to create, we will have our good-looking flow to get more information from a user regarding the creation of a geofence, we will be able to create multiple GeoFences in our application and get notified whenever we enter, exit or stay within the geofence for a specified amount of time. Now, I have already prepared a design project, which we're going to use that in this course. So you don't have to worry about that. Also, that design project that will be available for you to download for free along with the source code of this project on which we are going to work on in the source code that will be available on my GitHub profile. So our application, we'll use the most popular Android architecture components like a Room database, dagger, a hill dependency injection library, navigation component, view model, live data, datastore preference, view binding, data binding causing coroutines flow and many more. We're going to follow the principle of a single activity and the multiple fragments, our application, we will have a six different fragments and we will also use a nested navigation graph in our application. Now, all my courses are a well-organized, a very informative, and that they will provide you with all the necessary knowledge you need to work with the latest Android API levels. Plus, at the end of this course, we will have a one, a special section where I'm going to occasionally upload some course updates like bug fixes and the court clean-ups. And that way these squares will always be up-to-date. Okay, so lastly, I want to include you in this project of mine. I want to make your thing like a real developer. After we finish this course and building our application, I expect you to look into the code again and the suggests that what else could be improved in this application which we are going to create. And you can also report some bugs if you find and even suggests the solution by yourself. If you have one. Anyhow, there is a nine hours of a high-quality content there waiting for you. And what are you waiting for? Let's get started. Developers. 2. Dependency Overview: Hello there and welcome back. So in this video, I'm going to show you all the dependencies and plugins which we are using in our project. So first, on the top of our Gradle build file application module, you can see that we have a plugin select Katlyn kept, then a dagger a hill, then are safe. Args and Kotlin power supplies as well. Then down below, if we scroll, you will see that we have a view binding in that data binding enabled as well. Then finally down below we have our dependencies. So we have some lifecycle dependencies that some coroutine dependencies. We also have added here a coil image loading library. Then down below we have our places as decay of course, then we have it easy permissions and easy permissions is a one amazing library for handling a runtime permissions in your products. Then we have a room library, then we have a day or he'll library. After that, we have a data store n. Finally, we have this map utils library, and there are certain classes which we're going to use from this util library to calculate some things and you'll see, so in the next Gradle build file here we have a class pass for our dagger here Library in for our navigation safe args, and this is our Android manifest file. So here, our application, we will have only two permissions, access final coercion and access and background location. So from API level 29, if you want to access a background location from your application, and then you need to declare in the request the runtime permission for a background location. And of course, if you are using an API levels lower than at 29, then this background location is automatically granted. But for new API devices, you will need to request the runtime permission for our background location as well. Here, as you can see inside our application, we have our broadcast receiver, which we are going to use. Then down below we have declared our Google Maps API key as well. And we're going to have only a single activity and the multiple fragments and our activity will be available only in this portrait mode. And now you saw what the dependencies, which we're going to do is inside our project and what the permissions we are going to need as well. And for this video, and that'll be all. 3. Application Design Preview: Hello there and welcome back. So in this video, I want to show you our application design. And I feel design this application using Adobe XD. So our application I will have a single activity in multiple fragments. And in this design projects, you can see that we're going to have a six different fragments. So, uh, later in this course. So we might add some more views in those are fragments. But for now this is how our designer should look like. So first here we have permission fragment, and this will be a first destination inside our navigation component. So whenever we first time allowing our application, this permission fragment that will be shown, and basically from here, we will be able to grant fine location permission to our application. So we're not going to request both of those are permissions, like a final location and beggar on location permission at the same time, because that's against the new permission rules. So you need to request those permissions sequentially one by one. And here we went to request only one permission, which is a final location permission. And after regret that permission, then we're going to immediately navigate to step one fragment. And that's only when we launched our application for the first time. When we launch our application for the second time after we grant this permission, then we're not going to cities permission fragment. Instead that we're going to immediately switch to our maps foramen here. But if you are running this location for the first time, then you're going to get to Step 1 after permissions fragment. And here you'll have an option to select the name of your a geofence, which you want to add inside your application and inside this fragment also in the background. Now we're going to request location from our user so we can extract the country code from our user. And we're going to use that country code to restrict this auto-complete widget from our places as decay. And you will learn more about this autocomplete widgets later in their scores. Anyway, once you go and click Next here, you will be able to go to this second step. Then from here, you will have the option to select which city or which city you want to add your geofence. And you can just select whatever city you want. And after that, you can just go to this third step where you have an option to select the radius of your geofence. The minimum value will be 500 meters and the maximum value will be ten kilometers. So of course you can change those values if you want. That's on you. And after you click Done, you'll get to this some maps fragment. And from there you will see one, our TextView message, which will say a long press on the map to add the geofence. And then you will have to basically zooming and see whatever you want to add that the geofence. And the first time you long press here on the map to add the geofence, you will be prompted to grant a runtime permission for a background location because otherwise, you will not be able to use this geofence API. And after you successfully add that the geofence, then inside this GeoFences fragment, you will have a list of all the GeoFences which you have added to your map. And of course here you can see some more information about those GeoFences like this snapshot than a geofence name, location, coordinates, and the radius. And of course, we're going to implement here MotionLayout so we can now remove those GeoFences one by one. And basically that's how our application design will look like. And of course, this design project will be available for download. So don't worry in and if you wish to learn how to design your Android applications, then you should check out my other course about the material design for enjoyed and for this video. And that'll be all. 4. Geofencing API Limitations: Hello there and welcome back. So in this video, I'm going to show you how our final application will look like. And the after that, I'm going to talk about some geofence API limitations. So the first thing I'm going to run this application for the first time on my Android emulator. So as you can see, when we run our application for the first time, we're going to see this fragment, which will ask us to grant our replication this permission in here. Basically we are requesting a fine location permission from our user and not both of those permissions like final location in the background location. So we're going to request that those runtime permissions sequentially, like the official Android documentation says in 1st here we're going to request only final location permission. So click Continue button. And then here is can see you will be able to allow this permission or deny. So if you click the NIH, of course, you will not be able to proceed. And basically you will be prompted to open up application settings to enable that permission manually. But in this case I'm going to allow this permission. Okay, so now we have received this toast message that our permission was a successfully granted. And now if I click Continue button, step one fragment that we'll start. And as you can see, this navigation flow from our permission for a man to step one fragment will be only when you are first time installing this application and the next time you run this application, you will not see this permission fragment nor this step 1 instead maps fragment that will be shown. Nevertheless, this is the first time we're running these applications. So here we have an option to name our geofence, okay? And here let's just name this a geofence for example. And we will type the name of my YouTube channel. Now, cane. I'm going to press Next. Then here on our step 2 fragment, we have this auto complete widget from our places as decay. And we have a programmatically design this auto complete widget to fit our needs. Next, let's hear a type. For example, some city I'm going to type or Belgrade, our case or Belgrade. Select that. And now we will be able to go to our step three. So let's click Next. And from here we need to select the radius of our geofence. So for this case, I'm going to select that 500 meters, but of course you can't change that to up to thank you all mutters, solid. Just a switch that to 500 meters and click Done. So after that, as you can see, we have received this text or message which says a long press to add the geofence on the map. And of course, we have successfully zoomed in to our current user's location, which is a Belgrade, of course, here I have said this location to being a valid grade in here also we have one route, and after that, I'm going to start this route to see if we're willing to receive notification whenever we enter, exit or dwell inside our a geofence. So the first thing you can see that we have a two floating action buttons here. And this bigger floating action button will are basically navigate us to our step one fragment to add another geofence. And if we press this smaller floating action button, we're going to open up our GeoFences fragment. We are, we are going to see all our GeoFences. So if I open that up, you're going to see this message that says no geofence found and this message will disappear when we add our first geofence. Now if I try and long press here on the map, I'm going to get prompted to give our application our background location permission. So only if we allow this permission, we will be able to start our geofence. So I'm going to just select these keep while in use access. So I'm not going to grant that in here. We're going to receive a message that says Background location permission is essential to this application. And without it, we will not be able to provide you with our service. And if you click Okay, then you will be basically prompted to go to application settings to enable that permission manually. And I'm going to click Cancel for now. And I'm going to zoom in here OK. To our location, right? So I'm going to start this route with a speed of one x just for a second. Okay? And here, let me just zoom in a little bit more. And I'm going to add this geofence right here. So I have a long press on the map and I need to grant this permission first. So let's click Okay, now let's allow that all the time. And now let's long press here. Are OK. And now you just wait until this geofence starts. And immediately after it starts, we went to receive this notification geofence exit. So that means that currently we have our user's current location outside of this geofence. And now I'm going to increase this playback speed or this speed route to a five x. So we can actually see how our device is getting inside this a geofence. And then after we get inside this geofence, we're going to receive another notification I, which says enter. And after spending five seconds inside this a geofence, we're going to receive another notification, dwell. Okay, so they just wait. Okay, so here it is, enter and after five seconds, dwell. So dwell basically means that we're going to be inside this geofence for a certain amount of time. And we can specify that time. I have specified that time, 25 seconds only. So we can actually see that notification here. And I'm going to start this route again. But this time I'm going to close this application and I'm going to remove this notification or k from here. So now I'm going to basically remove this application and I'm going to start a Google Maps. Okay, so as you can see, our application is currently closed, and here we are inside our Google Maps application and not our application. Our application is closed. And the Nevertheless, in a couple of seconds, you're going to see that we are going to receive a new notification that we have entered our geofence. So let's just wait a little bit. Okay, so here it is, amplification Enter and now after five seconds notification as well. All right, perfect. So now we can wait a few seconds more so we can leave this and geofence and you will see that we are going to receive exit the notification. So let's just wait a few seconds more, our case, so here it is. I'm notification exit. So basically we have exit, our geofence. So I'm going to stop this route now we don't need that at this moment. And you saw that basically we have closed our application and we have opened the only our Google Maps. Okay, So now let me just run this application one more time now. Okay, Let's open now this GeoFences fragment. And here we have our geofence. Okay, so here the name of our geofence here we have a snapshot of our geofence. Then we have a location coordinates in the radius. In of course here we can just Remove this and geofence by clicking this button. Or we can select this GeoFences snapshot and we can zoom into our geofence solid. Just select that. And as you can see, we have a immediately zoom into that. Same a geofence on our eye will go map. So basically this is how our application will work. And now I'm going to talk about some geofence API limitations. So basically, from API level 2019, there are a few changes which were made when we are talking about allocation on our device, specifically a background location. So from now on, we will not be able to use beggar and location are constantly for our application. And basically if we tried to start our route again without having our application opened or any other application like a Google Maps, then we will not be able to receive that the geofence notification. Okay. So we're going to be able to receive our notification from a geofence even if our application is closed or dead. But we need to open up some other application which has Google Maps, okay? And only then we will be able to receive our information from the bare ground from our geofence API and show a notification end if we close all of those applications and we will not be able to receive those geofence notifications. You might be wondering about how can you use our geofence API properly? Well, there is one way. And for that, let me just open this web browser and you can access this page on the specific link. So in order to use their background location fourth time, now without needing to open some other Google Map publication like just we did, then you need to request a special background location permission. In here it says that you can submit your application for feedback on occasionally in the background x is by completing this location permission declaration form in a play console. So basically you need to upload your application to a place console. And from there you just need to feel this forum. And after that, they will basically send you a message to approve your application. But there are a few more requirements which you need to complete. So here it says that, uh, your application there should not request access to a location in the background unless it's required. And if your application requests access to location in the background, but it's not critical to your application's core functionality, then you must remove it from your app and or implement location accessing the foreground, such as when your applications activity is visible to users. So here if you open this timeline down below, you're going to see that from January 18th, 2021 or new applications first published the after April 16th, 2020, submitted to a Google played that access location in the background, we will need to be approved before they can go live in from the sun March 2009, all existing applications that access location in the background we will need to be approved or app updates may be blocked and your application may be removed from Google Play. So basically, in order to use the geofence API full time without any restrictions, you're going to need to fill out that form from a Google Play Console. And from there you need to describe your application in a few more information. Down below, you also have some guidelines. So for example, before you start, you should review best practices for accessing location. Then also you can consider alternatives to accessing location in the background and make access to a location in the background clear to your zone. So basically, our application is a well-designed and its core functionality requires a beggar on location permission because we are using a geo fencing API and without a background location permission, we will not be able to provide that functionality to our users. So there is a good hypermobility that your application and will be approved if you'll follow all those guidelines. And down below you can see that you also need to provide a video demonstration of your application. You can just record your application how it works, and just describe what information and you're going to receive or get from users, how you're going to request those runtime permissions and basically some other information which you can find here as well. So be sure to check out this link and you can read more about it. So this application which we're going to create will work perfectly fine, except when we're not using any application which has a Google Maps in a foreground, even though we are using a background location permission, our functionality is kinda restricted and we will need basically to fill up and send this form to our place console so they can now review and approve our application. After that, we will be able to use our geofence API in our applications with all its functionalities. So there is one more thing are important for a geofencing API, which you should know, and that is the number of GeoFences which you can create in your applications per user, and that number is 100. But nevertheless, if you are going to use more than 100 GeoFences, then you should create a different logic for your application. Anyway, geofence API is great API and you can create them many different useful applications. You can also create a semi parent-child application where you can where you can send a notification to apparent whenever child leaves or enter a summer geofence and in your score so you will get all the necessary logic tool, create, and handle. Geofence isn't in your application, but of course, so don't be scared. If you need to request this special permission as you just need to create an account on a play console, upload your application there, fill out this permission declaration form and just wait until they approve it. So for more information, feel free to visit the selling and therefore this video that will be all. 5. This Project is on Github: Hello there and welcome back. So this is going to be a really quick video because I just wanted to share with you this geofence application, which is uploaded on my GitHub profile. So you can see you can access this repository on this link. So on my GitHub profile slash geofence application. And here you can just download this project. You can look into this source code, compare it to your own, and basically do whatever you want. So that'll be all for this video. 6. About Places API: Hello there and welcome back. In this video, I'm going to give you more details about a place as SDK for Android. And I will introduce you with that API in general in their show you what functionalities this same API has to offer. So here inside my web browser, I have opened the page for official documentation for our places, SDK for Android. And they're here, we're going to read this documentation together to see some more information about that. So for those of you who are still getting to know these places as decay, it's basically a library that allows you to build a location aware applications that the respond contextually to the local businesses and the other places near the user's device. So we're basically a Places API is a one and a huge database which consists of a large number of places like businesses and the other points of interests. And they're basically using these places as decay. We are basically querying data, huge database to search for something specific locations which are available around us. So this SDK provides us two main interfaces, places and the auto-complete. So places provides programmatic access to Google database or for local place in their business information, as well as the device's current place. And using these places interface, we can basically get a lot of information about those places around us. And you will see about that in the future videos of this course. And also we have this auto-complete, which is basically a pre-made widget that returns the place predictions in response to user search queries in, I'm going to talk about this auto-complete details in some of the next videos. But for now, what you should know is that this autocomplete offers you a way to query that huge Places API, database and the receive some location predictions so while you type. Okay, So we're down below here we can see this APR overview. So as I already mentioned that we can use this AutoComplete functionality. Then we have this occur in place, which basically returns a list of places where the user's device is a less known to be located along with an indication of the relative likelihood for each place. Then we have a place details which returns play more detailed information about the place. Then we have a place, photos which returns are high-quality images of a place. And finally, we kept our place IVs, which is basically our unique ID for one or more places for retrieval of place information on demand. So basically, each and every place or a location or a business or some other point of interest have a unique place ID. And I'm going to talk about place ideas in some of the next videos. So for you to use this. Places SDK for a Android, you will need to create a project inside the Google Cloud Platform. So as you can see, this is a Google Cloud Platform and hearing to create the project and the enable our billing account. So I'm going to talk about creating the project on their Google Cloud Platform is on the next videos. And also I'm going to show you how you can automatically create that account from your Android Studio by just generating one link. And you will see about that later when we start experimenting with some of those functionalities of Places API. So one important thing for places SDK for Android is that you will need to enable billing account to your Google Cloud Platform. So places SDK for Android is a paid service, and that's why you will need to create a billing account in Google Cloud, the platform as well. And don't worry, I'm going to show you how to do that as well. So even though this is a paid service, there is a catch. So here it says that for each billing account for a qualifying Google Maps or platform SKUs to a 100 dollar Google Maps platform credit is available each month and the automatically applied to their qualifying SKUs. So what that means that each and every month you are going to get a free $200 credit for your Google Cloud Platform account. And while I was working with places SDK for Android, I spent over a month testing geofence application using these places as decay, and I didn't spend even a $100. So that means that the $200 are free credits, which you're going to get every month. And that's more than enough credits for you to experiment whatever you want with your project. And of course, if you are planning to publish your application on Play Store and have a thousands of user, then you would probably need to pay more for these service. But for some basic usage, those $200 credits are enough. And here it says that usage in billing works under the pay as you go model. So that means that you will pay only the things you will span there. You will not pay anything if you don't spend, those are $200 of credits. So only if you spend all of those to a 100 dollar credits, then you're going to get to build and butter, don't worry. You're not going to spend those that are a $100 credits that easily. And down below in this documentation, we can also check some pricing. So here you can see how many requests you will need to spend to get billed. For example, $3. So for example, here we have contact data. So for using the only contact data, you will get billed only $3 per 100 thousand requests. And the down below we can check some other data like atmosphere, data like autocomplete and so on. So for example, here we're going to get billed to $0.83 per, per 1000 requests. And if you have more than 100 thousand requests, then you're going to get built a little bit less, for example, to 0.27 per 100 requests and so on. So you can check those details. Furthermore, I'm not going to stick with that any longer. But the main thing here is that those 203 credits are more than enough for you to work on any project you want. And of course, on Google Cloud Platform, you can just Check how much have you spent. So here inside my Google Cloud Platform, I can show you my your billing in basically, in the previous month, I hear a spend and $92.61 for the whole month. And as I already mentioned, we have a $210 credits free every month. And I have spent almost 50 percent and I have used this API so much for over a month. So that means that you don't have to worry about spending those $200 credits because it's a lot. And of course on your Google Cloud Platform, you can check in real time how much credit so you are spending, so you don't have to worry about that. And also there is a way for setting a limit on how many or how much money can you spend that daily. Also, there is a way to manage your cost or through Google Maps platform APIs. And you can set a daily quota limits on all requests to any billable API. So here when I open this sewing so Cloud Platform console, then you need to select your project. And I'm going to select this geofence demo which I have been working on. Then on the left side here I can select quarters, and here I need to select which API I wanted to check. So for example, I want to limit this Places API I'm in here. I need to open this so requests table. And here I can see how many requests him I used per day. So for example, here you can see that the most requests I sent on February 22, and it was almost one hundred, ten hundred and two hundred requests. And down below, if I scroll, we can see that here we have some elements. So here we have our requests per minute, and those requests are limited to 6 thousand, but we can also limit the requests per day. So we can limit, for example, one hundred and five hundred requests per day. In here, I can just enter the number which I want. So just uncheck this option in here. I can write, for example, one hundred and five hundred requests and just check these confirmation option and click Save. So that way you can control how many requests you are using per day. And that that way you will not be able to send more than one hundred and five hundred requests per day for these Places API. But of course, I'm going to set that to our emitted because I will not be able to spend more than that. But I just wanted to show you a way for you to basically limit your API so you don't get billed at the end of the month. But of course, as I already mentioned, that you're going to have a $200 so for free credits every month for your project. And that's a lot. So that'll be all for this introduction videos. So we're now you have learned what these Places API actually is, how it's working, what functionality does it have? Also, I have shown you how to limit your API, your search. Also, you have learned that for this Places API, you're going to need to have a billing account. And I'm going to show you how to create that billing account once we create a new Google Cloud project here, and we connect that to our Android Studio. And for this video that for you all. 7. Place IDs: Hello there and welcome back. So why in this video we're going to read the documentation for our place ideas together. So basically before we actually start experimenting with places SDK for a android inside our Android Studio. I want to read this documentation together so we can see and learn some more things about these places as decay in general. So Place IDs, so Place IDs uniquely identify a place in the rural places database and on Google Maps. So each and every place on a Google map is associated with some a unique place ID. And basically you can type here and that unique ID and you can search for a specific location. Down below you can see some examples of how this place ID should look like in the length of this identifier may vary. So for example, you can have a shorter or a longer place IV depends on the actual location. So we'll place IDs are available for most locations, including their businesses, landmarks, arcs, and the intersections. And also it is possible for the same place or location to have a multiple different place IDs in place ideas may change over time as well. You can also use the same place ID across the Places API in number of Google Maps platform APIs like Places API, Maps, JavaScript API, Maps, geocoding, Maps, embedded, and the Roads API. There is also one important thing which you should note. So a place IDs are exempt from other caching restrictions started in this 3.2.3 B section, or for Google Maps or platform Terms of Service. So let me just open this section so we can read that together and also place IDs are exempt from other caching restrictions. Starting this 3.2.38, this time of Google Maps platform Terms of Service. So now let's read those paragraphs. So let me just find that 3.2 or 0.3 or k. So restrictions against nice choosing the service. So a and B here it says no scrapping. And here it says that a customer will not export, extract, or otherwise scraped by Google Maps or content for you is the outside of the service. So for example, our customer will not prefetch, index, store, reshare, or rehost their Google Maps or content outside the services or bulk download Google Maps, tiles or Street View images, geocodes, directions and distance matrix results are roads information and places information, elevation of values that time zone details, copy and save our business names, addresses, or a user reviews or use Google Maps or content with a text-to-speech or services. And section B here it says and no caching, so a customer will not care. So Google Maps or content, except as expressly permitted under the maps or services specific terms. So what it means that you as a customer will not be able to scrap those are information. So you will not be able to store those information which you get from these Places API. But as you can see, these place ID is exempt from that. So you can store this place ID locally. For example, in the, you can use this same place idea later. Search for that same location. So that's kind of a workaround for this legal issue. So those were some of the important information about the place ID that you should remember. And now you have learned about this place ID 1, that is, and how to use it in your application. And of course, later in this course. So we're going to use a place IDs to basically fetch the data from a Places API. So well, that'll be all for this video. 8. Place Types & Data Fields: Hello there and welcome back. So in this video we're going to read the documentation for a place types and their place data fields. So it is important to know what kind of place types in that place data fields. This places the SDK has to offer. And here as you can see, it says that there are three tables for a place types. In the first table lists the types that are supported for a place searches and can be returned with a place details results and as a part of auto-complete place predictions. Then we have a table to which lists additional types that can be returned with a place details the results, and there is a part of auto-complete place predictions. And the table three lists types that you can use in a place autocomplete requests only. So if we scroll down below, you will see that this first table is used in the following ways. So as a part of a place details response, then as a part of auto-complete place prediction and in the type parameter of a place searches, for example, to restrict the results to all places matching the specified type. And that there is a lot of types here which you can see. So for example, accounting, airport lawyer or library, bank, bar, cafe, museum, park, parking, casino polys, sparse stadium storage and so on. So you can check this documentation NC, the whole list. Then down below we have additional types returned by the places Service, which is a table tool and it's used in the following ways. So as the part of the result of a Place Details request or anywhere a place result is returned then as a part of auto-complete place prediction and to denote address components. And down below you can see this second table is a little bit smaller. So we have, for example, continent, premise room, route floor, food shelter, geocode, landmark, neighborhood, and so on. And finally we have a table 3. So here we can see a types that are supported in a place, autocomplete requests. Here it is said that you may restrict the results from a place that autocomplete to request to be of a certain type of bypassing a type spirometer. So our later in this course, when I show you how to use place autocomplete, then you will see that you can restrict the actual types or details which you want to retrieve for these places as the key. And the down below, as you can see, the supported types for this table 3 is a geocode address then establishment, which instructs the place autocomplete service to return only business results, for example, then we have our regions, and finally we have our cities, Sowell. You can see here that there are so many supported types for our places SDK. And that's why I said in the first video of this course that these places as decay is one huge database which consists of basically all places around the world. Next, we're going to read this documentation for a place data fields. So a place data fields and define the types of plays data to return when a requesting a place details. And down below we can see some are basic data. So here we can find the fields which may differ from API to API. So for example, here we have places library Maps, JavaScript API. Then we have places SDK for Android and iOS, but we're going to focus on Android for now. And as you can see inside this table for basic data, we can find some fields like address components, then our business status than address, then a view port, then a lat long than a name, photo metadata's IDs plus code types and the UTC offset and the one we start working with our auto complete widget. Then you will see that we can restrict what fields we want to use from our places. There's decay, for example, we can only set to search different addresses and nothing else or just the lat long information. Then down below we can see some eye contact data fields. And here we have our phone number, opening hours, and the website URI. Then down below we have an atmosphere data fields. And here we can find a price level rating in the user ratings total, and that this data is used for some business occasions. And the down below, as you can see, this fine current place function does not support the following fields like address components, opening hours, phone number, and website URI and the UTC offset. And this final current place functioning is a part of places client class, which we're going to cover in some of the next videos, of course. So for this video, that will be all. And now you saw what plays types and the data fields we have with our places as decay. 9. Session Tokens: Hello there and welcome back. So we're in this video. I want to introduce you with session tokens. And session tokens are important when we are talking about place autocomplete because it uses a session tokens to group the query and the selection phases of our user autocomplete search into a discrete session for billing purposes. So the session begins when the user starts typing a query and the concludes when they select a place in call to place details is made. So each session you can have a multiple autocomplete queries followed by one place selection and API keys used for each request within a session must belong to the same Google Cloud Console project. And once a session, Here's a concluded that token is no longer valid and your Application Master generate a refresh token for each session. And down below we can see some are guidelines for our session tokens. So I use a session tokens for all autocomplete sessions, generate a refresh token for each session. Ensure that the API key is used for all auto-complete in place details that requests within a session belongs to the same Google Cloud console project and be sure to pass a unique session token for each new session. And down below we can see some example. So as the user types a query in autocomplete to request these called the every few keystrokes and not per character, and a list of possible results is returned. And there when the user makes a selection from the result list, then the selection accounts as a request and all the requests made during the surge are bundled and counted as a single request. And down below, as you can see, if you want to create a session token, then you need to call this autocomplete session token and it's a method name their new instance. And don't worry if this concept of session tokens is a confusing at the moment because I, once we start working with our place autocomplete, then everything will make more sense. And for now, I just wanted to read this documentation together with you so you can get introduced with this concept of a session tokens. And that'll be all for this video. 10. Connect the Project with Google Cloud Platform: Hello there and welcome back. So in this video, I'm going to show you how to connect your Android Studio project with Google Cloud Platform. So in order to use Maps, SDK, and Places API, you're going to need to connect your Android Studio project with Google Cloud Platform. Also, you're going to need to generate some API keys and of course, that create a billing account. So the creation of a billing account will be covered in some of the next videos. And for now we're going to focus on connecting our Android Studio project with Google Cloud Platform and generating, debug your API key. Well, there are two ways of connecting your Android Studio project with the Google Cloud Platform. So the first way is the manual way and you can just navigate to Google Cloud Platform website. And from there you can just manually create one simple project. In the other way is an easier way. So basically, we can create Google Cloud Platform project using our Endrew in Studio. And then now I'm going to open up Android Studio. So here I have just created a simple project with one activity. And then now I'm going to create one more fragment inside our project. And that fragment that will hold the Google Map. So let's go to a foramen here and from templates, and we're going to select Google Map fragment. So Google Maps or fragments or select this template. And the reason why we are going to select this template because there are certain files which will be generated automatically for us. And now let's create that maps fragment. I'm going to leave that as it is and click Finish. Okay, So now as you can see, some files were automatically generated for us. So we have our maps fragment and also we have received a new file name, the Google Maps API XML. And inside this file, as you can see, there is one more string which needs to be filled with our API key from a Google Cloud Platform. And also this Google map template for our fragment has generated the one important link for us, which we're going to use to basically create our project in connected with Google Cloud Platform very easily. So here we just need to copy this selling. Let me just copy this link or, kay? And now I'm going to paste that link on my web browser and just press enter. So this link will redirect us to our Google Cloud Platform, our website. So just the weight a little bit. And from here you can select all your projects. So if you have a manually created some project, then you can select that right here. But I'm not going to select hear anything. I'm going to just click continue because we want to start from the beginning of course. And the now we need to click this button which says create an API key. And the API key will be a debugger API key. So there are two types of API keys, debug API key and the release API key. So the main difference between those two API keys is that and debug your API key cannot be used in a production. So it can be used only while our testing your application. And if you want to publish your application and use it on a real devices, then you're going to need to generate a release API key as well. And I'm going to cover generating a release API key in the next video. For now, we have just created a simple project on our Google Cloud platform, and we have successfully connected that project with our Android Studio. And of course, this API key was automatically generated for us. And these API key is a debug API key. So this is the actual key and we can just copy that. And now we need to get back to Android Studio here, where it says your key here, we need to replace that text with our actual API key. So now we have basically added that API key and we can freely use Google Maps on our application. So if you don't add this API key, then you will not be able to use Google Maps on your application. And now let me just switch this to a project views so I can show you or something. So here as you can see inside our source directory, we have two directories. We have a debug and release. So both of those folders have this file. So as you can see, they are basically named the same. But if we open up this release aversion, you all see that basically another, a different file and we have basically created this API key for our IV bag. And in the next video I'm going to show you how to generate the release API key as well, so you can use this application into production. But of course I'm going to close that now. I just wanted to show you that there are two separate files which needs to be populated with those API keys. And now we have basically connected our project with the Google Cloud Platform and we hear a generated those data debug API key. And we have in whichever base that, that API key right here, which is fine. And now we can use our Google Maps. We know any issue and this is our maps fragment. We're going to modify this maps fragment in some of the next videos. For now, I just wanted to show you how to basically connect this project with Google Cloud Platform in how to generate a debug API key. So in the next video, we're going to generate a release API key as well. And the after that, we're going to continue exploring some places API functionalities so you can get introduced. So that'll be all for this video. 11. Generate Release API Key: Hello there and welcome back. So why in the previous video, we have connected our Android Studio project with Google Cloud Platform. And we have also generated this debugger API key for using a Google map, of course. And in this video I'm going to show you how to generate release API key. So a debug API key is only used for Android emulator and for testing these application. But if you want to use this application in production in, on a real devices, then you would need to generate release API key as well. So the first step in generating release API key, we need to build our release aversion. So here inside our Android Studio project, we need to go to Build menu, then generate, sign there bundle or APK. In here we can select the Android app bundle or APK. I'm going to select the APK for now, but you can choose anything you want. And here we need to select the path where we want to store our key. So since we don't have our key yet, we need to create a new one. So click Create New. And here first we need to select the KeyStore path. So I'm going to select my documents directory from here. Okay? In the name of this file will be, for example, it's a places demo, Okay, click Okay. So for the password, I'm going to select one. I'm going to repeat the password here for a key alias, I'm going to select, for example, key 001 and this password there should not be the same as the first one. Okay, here we can type for example, our name and any other information. So I'm going to just leave that as it is for now and click Okay, in here, I can just remember the password and click Next. Then here I'm going to select the release version. And from here I can select both of those signature versions. And now click Finish. So now our weight a little bit, and this release APK file will be generated for you. Okay, so now that our APK was successfully generated, we can proceed to next step. And now I'm going to open up a web browser, and I'm going to open up this URL. So what developers dot google.com slash, maps slash and documentation slash enjoyed forward slash sdk slash. I get four slash API for our slash key. Okay, so this is the actual documentation where we can see how we can generate a release a certificate. And now that we have generated our APK file, we can proceed next and we need to create or generate sha-1 fingerprint. So to regenerate that, we're going to need to basically copy this command. And now I'm going to just copy that. So let me just click this button and it will open up our Android Studio. So now let's open the terminal down below, and I'm going to hit Control V to paste this line of code and they're willing to replace those two values. So the first value is this one which says you're a KeyStore name. So here we need to copy and paste the full path where we have generated our key store. And then now I'm going to open up File Explorer and I'm going to locate my documents directory. Okay, So here it is. And I need to copy this full path. Now came in here, I need to paste that. And also I need to write the actual name of our KeyStore file. So places demo dot j, k, s. That's the name of my file in here where it says alias. I need to type a key Z11 because that's the actual alias which I have chose. So ky 0, 1. So this is the actual command is so key to all space forward slash at least space, forest slash v space for a slash key store space than the actual path that where we have saved our key store In the name of our key store with its extension JK AS then a space for a slash alias, space key 01, because that's my alias. And now press Enter, and it will prompt you to enter the actual password for your key store and just enter that password which you have already chose and press Enter. And now sha-1 fingerprint will be generated with other ones, but we need to copy this one. So sha-1 with me just copy that. Ok, click Copy. And now we open up our Google Cloud Platform and we need to create a new API key, which will represent release API key. So just click here or this plus button. So create credentials, choose an API key and the weight moment here you will see a message that says API key created. So I'll just click this restrict key button and it will open up this second API key. And from here we need to restrict our application to Android applications. And the down below where it says restrict users to your Android apps. We need to select this button which says add an item. And here we need to add to information. So the first one is the actual package of our project. In the second one is a sha-1 or fingerprint. So just paste that fingerprint which we have just generated with our KeyStore and the actual package name. So I can just check out my package name. Okay, So my package name is that com dot example dot the places demo. So com dot example dot places a demo and click Done. Okay, perfect. And the after that you just need to click this Save button and of course copy this release API key are okay, click save, and there we go. So now you have successfully created, generated your release API key as well. And now we can open up our Android Studio project. And we can open up this release a version of our Google Maps API file. And here we can paste our new API key K, and there you go. So now we have successfully generated both of those API keys. And in the next video before we actually continue experimenting some places API functionalities, we're going to create a billing account or on our Google Cloud platform as well. So that'll be all for this video. 12. Autocomplete Widget - Fragment: Hello there and welcome back. So in the previous videos, we have connected our Android Studio project with Google Cloud Platform, and we have also generated the debug in their release, their API keys. And in this video I want to show you how to implement autocomplete widget inside your application. So first, let me just close all of that. And first I'm going to create here a new fragment, which will represent the full fragment inside our navigation host. So for that, I'm going to open up this and irrigation and I'm going to create a new navigation resource file named our nav graph for example, because this file will represent the navigation graph for our navigation component. So press Okay, click Okay to add those dependencies for navigation component. And now just wait a little bit and we're going to create a new fragment now. Okay, perfect. So now let's create a new destination here and there we're going to select the Fragment Blank. I'm going to name this fragment, for example, our first frame and click finish our case. So this fragment will be a default destination inside our navigation graph. And now let me just open this first frame it and I'm going to remove this unnecessary code from here. We're going to leave it just this onCreate view function. Well, we already have this fragment maps which we have created with this default Maps template. And we needed that maps a template in order to generate those debugging the release XML files. So for now I'm going to close that and we're going to focus on our first fragment. So now inside our main activity, I'm going to add here a nav Host Fragment so we can host our destinations from our navigation graph. So just drag and drop that right here and select this navigation graph file. And let's just constrain this nav Host Fragment and with apparent horizontally and vertically our k here we can change this ID to say for example, nav, Host Fragment are okay, perfect. And now default the destination inside our activity will be our first fragment. So let's open up our first fragment to layout our case. So here it is. I'm going to change here our author element will be a constraint layout, and I'm going to remove this default TextView. And here inside our first fragment that we're going to add our auto complete widget. So before we do that, I want to open the official documentation for our autocomplete. In here it says that this autocomplete service in the places or SDK for Android returns place predictions in response to user search queries. So as the user types, the autocomplete service returns suggestions for places such as businesses, addresses, plus codes, and the points of interests. So well, we can use this auto-complete in multiple ways. The first way is the easiest one, and basically it represents already made the auto complete widget, which will save our development time and ensure a consistent user experience. And the second way represents a manual way where we can customize this autocomplete by our cells. And I'm going to focus on this first one and we're going to customize this auto-complete. Widget when we actually start working on our geo fencing application. So down below, when we scroll, you all see this example of how this auto complete widget that looks like. So it's basically a search dialog with a built-in autocomplete functionality. And when a user searches are some terms, then the widget presents a list of predicted places to choose from. And when the user makes us selection on one of those places, then a place instance is returned, which are your application can then use to get into the details about the selected place. So why there are two ways of adding these auto-complete to widget by using this autocomplete support fragment or by using this intent to launch the autocomplete activity. And now we're going to focus on this first way by using this autocomplete support fragment and that we use that we need to just add this XML element fragment with the name of a com dot google.png. Lot libraries, not places, not widget, daughter, autocomplete support fragment. So we can just copy that now and let's add it to our first fragment here. Okay, perfect. And now you will see that here we have an error and that's because we haven't added the dependency for our places SDK for Android. So let's open up our Gradle build file here. Let's scroll down below. And the now instead is documentation and we're going to choose this get started page in from here. We're going to scroll down below and we need to copy this dependency. So let's copy this one, and let's add our places SDK dependency. So let's sing the project now. Okay, perfect. So let's close that now. And as you can see, this error now disappeared. So now let's constraint our auto complete widget on the left, right, and the thought came. And now let me just run the app so we can see if we're going to see our auto complete widget at all, our case. So here as you can see, we have our autocomplete search widget, but if we click on debt, our application will crash. And that's because we haven't implemented any code yet. So let's open up that documentation from earlier. And now as you can see by default, so these auto-complete there we did. He has no border or background. So if you want to add their background, you will have to place this auto complete widget inside that card view, for example. And then on their current view you can modify those properties like background color or stroke, radius and so on. So the next thing that we need to add the place selection, a listener to our fragment. So I'm going to just copy this whole code and add that inside our first fragment. But before we do that, I want to enable our view binding inside my project. So here let's add the view binding to true. And let's sing the project are okay, perfect. And now from our first fragment that we're going to use our view binding. So here we're going to create the two variables. The first one will be a var, so we can actually modify its value. And here I'm going to add underscore binding. And the type here should be a fragment. First the binding in its initial value will be null. Then we're going to create a read-only variable, binding end. We're going to use a getter to get the value of our underscore binding. And of course I'm going to add a double bang operator in here. I just want to call underscore binding in. Then I'm going to call a fragment first binding. And we're going to inflate our layout end. Instead of this hard-coded layout, I'm going to just pass the actual LayoutInflater here. We also need to return binding daughter Ruth, and we need to override here on this Troy view so we can avoid them memory leaks and set underscore binding to now after our fragment is destroyed, of course, we can also remove this question mark. We don't need that. And now let's paste that code. We're tree here we just copied. Okay, so here I'm going to just import this log, then this place selection listener than a place autocomplete support fragment, we can replace this tag with just the tag, and we're going to import this condo, the rule dot enjoy the GMS common API. Okay, So now here, as you can see, we have a warning and instead of this support fragment manager, we need to call child FragmentManager in here. I'm going to remove this line of code and here as well. And now let's run our application and see what will happen. Okay, so let's click on this, autocomplete the widget. And now as you can see, this fragment have appeared in here. We have this powered by Google text in here. We have our search widget in from here, of course, so we can type anything we want and search for us someplace. So let's try and type here something. And as you can see, as soon as I type, one character data fragment disappeared and there, why is that? So let's first check our logcat in here. As you can see, if we type tag, then we're going to see an arrow that says status, status code. This API project is not authorized to use this API and it's because we still haven't enabled our places as the K or now our Google Cloud Platform. So let's open up a web browser and you need to log into your Google Cloud Platform console. Then you need to select your project. And from here, you need to go to APIs and services than the library. And then from here, we need to find that Places API. So let's open that up. And as you can see, these maps SDK for Android was that automatically enabled for us when we actually created this project with data link, which was provided inside our Android Studio. And now we need to enable our Places API. So let's click this button, enable our case. So let's just wait a moment and our Places API is now enabled for our project. So now we can run this application again and see if everything's going to work fine. So let's open this log kit. Let's click on our auto complete widget. Then this widget will appear or this fragment in from here, for example, we can search or some place I'm going to type here, for example, Belgrade. Now as you can see, we have another error. So now we have a status code that says you must enable a building, or now we're Cloud platform, and then now it is time for us to create a billing account. So let's open up our Google Cloud Platform. From here I'm going to select the billing. And it says that this project has no billing account and we can link our billing accounts. So click here, and I have already made my billing account here, so I'm going to slay that account. But for you, you would need to set up this account and you're going to see this option to create a new billing account. From there, you just need to basically add your credit card information in case you exceed that $200 free credits for a month, then you're going to get billed on your credit card. But of course, I already talked about how you can limit your API to not go over a certain amount of requests and so on. So you can just create here a new billing account and link dead. So I'm going to select this account which I have already made and I'm going to click Set Account. And now our billing account is linked to our project now. Okay, and now let's open up our Android Studio project and let's run our app to see if everything's going to work fine. So here let's just type, for example, Berlin. So as you can see, even if I type the two character, I saw this Berlin in the first item of this list. And as you can see, it works perfectly fine. So now let's see what will happen if we just select that one of those items. So let's click for example here. And now let's open up our logcat in here. As you can see, we can see the name of this place, which is the Berlin. In here we can see the actual place IV. And of course we have already talked about place ideas. And you already know that each place ID is the unique identifier for each location on Google Map and inside our own place selected function here, in this place selected listener. And we have implemented this one simple line of code where we have logged the name of our place in the actual ID. And that's basically how you can enable this auto complete widget inside your application using this autocomplete support fragment. And as you can see, it is very easy to set up this auto complete widget. You just basically need to add this one XML element, autocomplete support fragment. And then you just need to initialize these places as the k. And then after that, you need to, I get the reference of autocomplete fragment and then you just need to add on Place, select the listener to listen. When you select one of those places from the list in here, of course, as you can see, we have used this function set place fields to actually set the fields which we want to see inside this auto complete widget list. And as you can see here, we have called this set place fields that function. So we can actually limit the fields which we want to receive from our Places API. And we have basically listed the only two fields, ID, name. And that's the actual information which we have received from our log. But of course, if you want to add some different fields, you can just add, for example, and dress wet longer Business Status, opening hours and so on. So as you can see, you have many of those and we have already seen in those fields on our official enjoy the documentation for that. So that'll be all for this video. So now basically we have a successfully implemented our auto complete widget inside our fragment, I have also shown you how to enable our Places API from Google Cloud Platform in how to add the billing account. So of course, these places, SDK for Android is a paid service, and that's why you need to add billing account. But as I already mentioned in some of the previous videos, every month you're going to get that to a $100 of free credits. That that's more than enough for you to basically work on any project you want. And of course, if you want to publish your application so that thousands of users cannot access your replication and use that service, then you will have to pay for that. But for some are simpler projects, you'll have more than enough credits to work on, and that'll be all for this video. 13. Autocomplete Widget - Activity: Hello there and welcome back. So willing to previous video, we have implemented our autocomplete support fragment. And as you can see, this is how our application that looks like so far. So here we have this auto complete widget. And then whenever I press on this autocomplete that widget, then a new fragment here will appear. From here, we can just type any place we want to search. So for example, I can type here Belgrade, and then I can just select the one of those places or predictions from this auto-complete list. And inside our first fragment that we have defined there, which fields do we want to retrieve from our autocomplete? And here we have defined it. We need to get the ID and the name and the In this video, I'm going to show you another way of implementing this AutoComplete functionality. And this time I'm going to do that with activity. So why there will be a timer when you don't want to use this autocomplete support fragment. And for example, you want to trigger that the autocomplete functionality from some button or icon. And in that case, we need to implement autocomplete the activity. So let's just open this, the official documentation so we can take that out. And here as you can see, this is an actual option number two. So this option number 2 suggests that you should use the intent to launch this. So autocomplete activity. So if you want your app to use a different navigation flow, for example, to trigger autocomplete experience from an icon rather than a search field, then your app, I can launch a autocomplete the biasing in intent. So these are steps that are needed if you're embedding a fragment like we did in the previous video. But now we just want to remove this embedded fragment or we can just forget about that at this moment. So here it says that you shouldn't Cloud Launcher autocomplete activity directly. Instead you should use the intent launch these auto-complete. And down below we can see one example code which we're going to copy in order to show you how this can be achieved. So before we actually start to implementing these code that I just want to create one menu and that menu will be used there from our main activity. So let's first here, create a new menu resource file. So right here, and I'm going to name this file our main menu. So click Okay, and here we're going to only add one simple item. So the actual icon will be a search icon. The actual ID can be Menu. Search, show as action can be if a room, so it will be visible and the title can be a search and color of this icon can be white, now k. So here I'm going to add this target API attributes so we can avoid this, a warning. Okay, perfect. And this is how our menu icon should look like and it will be attached to our action bar on our activity. So let's open up our main activity. And here first, I want to initialize this menu. So I'm going to override on Create. Options manual. And here I want to use a menu inflater to inflate our menu which we just created and hearing to pass our resource. So our menu.html main menu in here, we need to pass a menu as a second parameter. So now let's run our app to see if this search icon will show on our action bar. Okay, so now we can see this search icon. And the next thing Let's go to this documentation again and I'm going to copy this part of the code, and I'm going to paste that code for now right here in say, the onCreate method. And now let's suggest import all of those classes. So all plus enter our k. Perfect, Let's get back to a web browser. So when using an intent to launch this autocomplete the widget, you can choose from overlay or a full screen display modes. And as you can see, those are the screenshots in this first one represents the overlay mode, in the second one represents our full-screen mode. And of course at that code which we have, which we have a copied earlier, is using this for screen mode, which is this second screenshot. But later we can change that to this overlay mode as well if we want our case, let's go down below and also we need to override their onActivityResult function. So I'm going to copy this part of the code as well. And I'm going to open up by Android Studio and also override this function. So on activity result, now let me just put this autocomplete to request code on the top of our activity. For example, right here are k here. Let's just import this intent, then activity, then we can also this log then autocomplete activity. So all placenta or K here I can type, for example, main activity. I can do that here as well. Perfect. In here, I can just convert that to a string. And basically our activity result when we select one of those items from the list or from our autocomplete to Egypt, then this function will be triggered. In here we're going to check if the result is okay. And if it is, then we're going to log this place ID in place name from our auto complete widget as we did in the previous video, like you already saw. And there is only one more thing which I want to do here. So I want to override on options, items selected, and here I want to type when item dot item ID is, for example, let's say our dot id.me search. So when we select our search menu from our ActionBar, then I want to start this intend. So let's just paste this code right here, and also those fields. Okay, perfect. And now let's run our application to see how this autocomplete activity we'll now work. So now as you can see when I press this search icon, then this on options items selected function will be called. And we're going to start our activity for result. And there we go. So this is our autocomplete activity widget, which represents full screen mode. And here we can just type anything we want. And we can select one of those places. And when we select that, we're going to open up our logcat. And here if I type main activity, then we're going to see that we have a logged this place and that place ID. So it is working perfectly fine. And let me just show you that we can also use another mode, which is an overlay mode. So let's start our application again so we can see how well that they look like now. And now when I press this search icon, we're going to see our overlay mode. So this overlay mode is almost the same as our first autocomplete support fragment like this one. So as you can see, they, so they are the same. And now you have learned how to use this auto-complete as an activity and also as autocomplete support fragment as well. So if we check this documentation, you will see it there also, there is a third way of using this autocomplete to Egypt programmatically by yourself. And in that case, you would need to handle data searcher widget by yourself. But I'm going to show you this third way when we actually start implementing in creating our geofence application. For now, it's enough for you to know those two main ways of using autocomplete to support fragment and launching this autocomplete with any intent. So it's very easy as you can see, and that'll be all for this video. 14. Constrain Autocomplete Results: Hello there and welcome back. So in the previous videos, I've shown you two ways of implementing auto complete widget. So you saw our first way of implementing autocomplete support fragment in the other way by using activity to launch our auto complete widget. And of course, there is a third way of implementing a autocomplete programmatically and customizing it by ourselves. And we're going to talk about that third way when we actually start creating our geo fencing application. And you will see about that. And in this video, I wanted to show you how we can constrain and restrict the actual result which we are going to receive from our auto complete widget. So here if we open up this official documentation, you will see that there are multiple ways or for restricting or a limiting the actual result which we can receive on our auto complete widget. So what to constrain the results? We can, it was a this set location buyers function to prefer a results within the defined the region. Then we can use this set location restriction function to only show our results. So we think that they find the region. So as you can see this first function set location bias, we'll just prefer the results from one region. But if we use this set location restriction function, then it will limit basically the actual result which we can get. Then also we can use this set type filter, which we have already seen in the previous videos, where we can define what filter types so we can use to get the results from our autocomplete widgets. And of course, there is one more function named a set countries, which will allow us to basically eliminate the countries which we want to search from our autocomplete rigid and their countries must be passed as a two character with this ISO or 31, 66, 1 alpha 2 compatible country code. So while it's scroll down below, so you can see some examples here in this documentation. And here we can see a set location bias function. And inside we're passing a rectangular bounce object. And inside that where best singer to LatLng objects or two locations. So the first LatLng object in most cases here is represented by north or east point. And the second LatLng object is presented by Southwest point. And by choosing those two points, we can imagine in our header 2, we are drawing a rectangle to connect those two dots. And that way we can define a region R came. And then down below we have this example of using a set location restriction function and basically is the same as the previous example. But the main difference between those two function, between the set location bias and the set location restriction is that this set location bias function will just prefer the result from this region which we have specified and that this set location restriction of function, we'll align with the results from this specific region. Okay, so next let's scroll down below, and here we have our filter results by place time, So well, we can also filter auto-complete results to a specific place type. And then we can call our set type filter function to set the filter to use. And then we can pass the filter to a fragment or intent. And the down below we can see two examples or for using this set type filter with our autocomplete support fragment and with our intent. So we're now I'm going to open up Android Studio and we are going to apply this type filter to our autocomplete support fragment. So as you can see here down below, I'm going to call autocomplete fragment, then a set type filter in here I'm going to call a type filter. And here as you can see, we have multiple type field or a slight curve. Cities, geocode, address, establishment or regions in here, for example, we can choose address, and now let's run our app. So now let's click on our search widget here or on our auto complete widget in here. For example, if we type our Belgrade, as you can see, we're not going to see the actual city. Instead, we're going to see an address in here. For example, we can search some address in a Belgrade. And now as you can see this autocomplete, the widget is primarily focused on addresses and they're not cities as before. And of course now we can replace this with cities. And let's now open our app again. And now if we try and search here for Belgrade, for example, as you can see, it will display only the city and not the actual addresses. So there is only one more thing which I want to show you here. So as you can see here, we have specified that we want to be able to receive IDs and the names. Of course, we can specify some more fields. But for example, let's try and removing this name and let's see what will happen if we tried to click on one of those items from the list and what message we're going to see inside our logcat. Okay, so let's here type in search, for example, for Belgrade as well. So click here. And now as you can see, for the city, you're going to receive a null and for the ID you are going to receive a place ID. So if you want to see, for example, name, then you would need to specify that as a field here. And if you don't specify data field here, then you will not be able to retrieve that information for a places API. And of course now we can get back here and there, just undo. And of course we can use multiple fields like lat, long address, business status, ID, name, opening hours, phone number, and so on. And finally, I want to show you how you can filter results by a country. So if we scroll down below, we're going to see one simple example. So what or filter auto-complete results to up to five countries. We need to call set countries function to set the country code. And as you can see, this is just one example and we need to use those two character country codes. Example. Let me just use this function right here. So autocomplete fragment dot, dot set countries. And here as you can see, we can pass some multiple strings. So for example, here I can type RS, which is referring to my country, Serbia. And the now let me just start this application so I can show you that whenever we type some city, it will not show us the results of each and every city on the planet. Instead, it will show us only the results or the cities from my country. So here, as you can see, if I type per Berlin for example, and nothing will happen and we're not going to receive annual result because we have restricted our auto complete widget to only Serbia as a country. And here if I type are Belgrade for example. As you can see, we can see that so well now you might be wondering, why is this so important? Why is it important for us to actually restrict countries or a type filters or regions? Well, the first and main reason is because with this, with those location restrictions, with countries and so on, we can increase the overall performance of our autocomplete widgets. And also we can reduce the coast of these places. Api service. So for example, if we restrict our auto complete widget to only one country or two, maybe one region. Then whenever we search here in our auto complete widget, then we're going to spend less on our Places API service. And for example, if you don't restrict your auto complete widget with any country or location or even a type filter, then the overall performance of this auto complete widget will be lower. And of course, the cost of this service will increase. So those were the two main reasons why you should always restrict or limit your auto complete widget to certain countries or locations. And of course, type filters. And it's always a good practice to get the user's location before you actually implement the auto complete widget. And in that case, you can just use that user's location to set the limit or this restriction for auto complete widget. And that way you can increase the overall performance and you can reduce the cost of the service Savoir. That will be all for this video. 15. Get the Current Location: Hello there and welcome back. So in this video, I'm going to show you how to get the current place. So using a places as the k and also how you can discover the place at the devices currently reported location and examples of those places, our local businesses are points of interest in the geographical locations Savoir down below in this documentation, we can see that if we want to use this fine current place, some of these places client, then we need to declare this axis fine location permission. And there we also need to request a runtime permission for that. So while it's scroll down below, and here you can see the steps which we need to take in order to implement this functionality. So the first thing you need to check, if you have this permission and if you don't, you need to request the runtime permission for access. Final question. Then you need to create fine current place the request and the pass our list of place fields which you want to yours. Then you need to qualify and current place function and you need to pass a fine current place request from the second step. And of course finally, you will be able to get the list of place or likelihoods from the current place a response. And here you can see that this fine current place function does not support the following fields like address components, opening hours, phone number, UTC offset, and their website URI. So our fields correspond to play search results and they are divided into 3 billion categories. So basic contact and atmosphere and the basic fields are built at the base rate and incur no additional charges while eye contact and the atmosphere or fields are billed at a higher rate. And of course, we have already talked about usage and doing so here in this recommendation you can see much. You will be billed for a 1000 requests per, per each SKU. So for example, for contact data here we have a tree USD per one hundred, ten hundred. If you are requesting 100 thousand requests per month, then down below for atmosphere data, we can see some different values and so on. And of course here you can see what types of fields do we have inside the basic data, then inside that contact data and atmosphere data as well. But of course, I have already mentioned the so if you want to use this places SDK for a smaller projects in for testing purposes, then those $200 free credits will be enough for you to work with it. So the API will return a fine current place response in a task. And that response will contain a list of a place the likelihood objects representing at places where the device is likely to be located. And for each place, the result includes indication of the likelihood that the place is the right one. So the list may be empty if there is no known place corresponding to the given a device location. And down below in this documentation we can see one example code which we're going to copy and implementing our project so I can show you how well this functionality work. So I have copied that and now I'm going to open up Android Studio. And down below I need to create a new function. So private fund get current place Locations. And here I'm going to paste that code. So here I'm going to just replace those tags are Canaanites, the import, all those classes. So all plus enter, our K or plus Enter and here and here. So here instead of this, I'm going to use the require context. And here I need to set the places client is a global variable. So let's just define this as a global variable and let's make it private. Okay, perfect. So first, inside this function, we are defining what place fields do we want to use. In here we have defined only a name, but of course we can define many other different fields. For now we're going to use only the name. Then down below we are defining our fine current place request. In here we're passing our place fields which we have already defined. So after that, we are checking if our application I have this axis final cation permission. And if it has, then we are basically retrieving the list of all those places around us. And if we don't have permission, we just want to request one. So I want to pass here an array of just the one permission. So our manifest dot permission dot axis final cation in here for the request code, I can just type for example number one. Okay, perfect. So now I'm going to call this function inside our onCreate view function. So for example, right here. Okay, Okay, So now let's run our app and as you can see, our application and just crashed. Okay, So I think I know why I'm, so here I'm going to lazily initialized that. So places client, we're going to initialize this places client inside our own CreateView. So now we need to initialize these places client below this initialization, our case. So we're now everything should work just fine. So we're calling this getc are in place Locations function at the bottom of our onCreate view. And now let's run our app and let's see if everything is going to work fine. So let's observe this tag from our logcat. And as you can see, as soon as we run our application, we are requesting a runtime permission for a device's location, and now we're going to allow that. Okay, so now we gave our application this location permission. And now if I run my application again, then this obligation or we'll have the permission. And here instead our logcat, we have a list of all places around our current device's location. So here we have printed the name of that place, ended the likelihood. And of course, my current location is invalid grade. So as you can see, I have set up this allocation to be in Belgrade and that's why we are receiving those exact results. So basically, that's how you can get the places around you. In here, of course, we can use different fields. So for example, we can use lat, long address, id, name, or basically anything else. But of course, we would need to modify our places fields here as well. In here we have only specified the actual name, but of course we can specify multiple fields as well. And basically that's how you are able to get the list of places around your location and the inside is documentation. You can also see that the likelihood provides our relative probability of the place being the best match within the list of return place for a single request. And you cannot compare likelihoods across different requests in the value of the likelihood there will be between 01. So that's why you're seeing those values inside our logcat. So those values represent the likelihood between 01. And of course, those are all the locations around the my current location on this Android emulator. And now you can see how easy it is to actually request those information from our places as decay and the Tokyo for this video. 16. Get a Place by ID: Hello there and welcome back. So in the previous video, I have shown you how to get multiple places around your current location. And in this video, I'm going to show you how to get the place details as well, and also how to get Place Details. Bye, specifying a place ID. So other places SDK for Android provides you application with territory information about places. And to x is this information for a specific place. You can use the place ID, a stable identifier that uniquely identifies a place. So we're down below, you can see that there are two ways of getting a place information around your current location. And in the previous video, we have used this fine current place function to get more details about the locations around our current location. And the, In this video, I'm going to show you how to use this second function, fetch place, which will allow us to basically search for a specific place by specifying place ID. So we're going to be able to get the same results or the same details about one specific location with both of those functions. And they, when you request a place, you must specify which types of place data to return. And basically, you can do that with the list of place fields. And down below you can see a list of place fields which you can use. And of course, this fine current place and fetch place functions support a different sets of data. So that's the main difference between them. So a fine current place does not support the following fields like place address component, opening hours, phone number, UTC offset, and website URI. And down below, if we scroll, we can see what functions we can use with this fetch places or fetch place function. So we can get lots of details about specific location. And if we scroll down below, we're going to see some examples. So down below we can see one code example of how we can get a place information by specifying place ID. And now I'm going to just copy this code. I'm going to open our Android Studio. And just below this function which we calculated in the previous video, I'm going to create a new function. So private fun, and I'm going to name this function, Get details with place ID. And I'm going to paste this code which we just copied our k. And here I'm going to replace this with just a simple tag. And instead of hard-coding this place ID, I'm going to add the parameter in this function for that place ID of a type string, of course, okay, and here is a place fields. I can add some more a place fields. So we want to get some more information. For example, place feel dot address or maybe a place, field, business status. So for example, I'm going to guess those are for information from our, from our location k. I'm going to remove this line of code. And here I'm going to add a comma, then address. Then here I'm going to call place dot address, then a comma, then a business status than place dot Business Status. Okay, perfect. So now basically I want to call this function inside our get current place Locations function. So inside our own complete listener right here. For this first if block, so maybe right here and a here we need to pass a one ID. So we need to get the one place ID. And as you already know this, I get current place allocations function will retrieve a list of multiple occasions surround our current location. And I just want to grab one place ID and not all of them. So here I can call, for example, a response dot Place likelihoods. Then here I can specify, for example, the first item inside of this list. Then here I can get the place, then an ID, and I can convert that to a string. And of course, if we need to pass the ID here to our guest details with place ID function. We also need to specify here I knew ID or a new field. So place dot, fill dot ID, because if we don't specify here that we are going to retrieve ID from all our locations, then our ID will be null. And that's why you need to remember to place this field right here so we can pass our ID to our next function. So now basically whenever we fetch this data from our gate current place Locations function, we're going to get the first item in from that item, we can extract some details like her name, address, and business status. So of course, so we could do the same thing from our first function, but I just wanted to show you that you can use this another function called the fetch place, where you can pass your place ID along with the lowest place fields and of course, fetch the result. So now I'm going to run this application and I'm going to observe our logcat. Okay? All right, so we have chosen the first location or from our list. So this log was printed from our new function and get details with place ID. And we have fetched the first location which is a cafe DKA. And as you can see, this is the first item here. Okay, So down below we can see its name, then its address, then a city than our country in our business status, which says operational. And if we check our official documentation, let me see our k right here. We can see that this get to business status method can return a three different values. So operational, closed at temporarily and close there permanently. And in our case, we have received an operational, which means that that current location or a business is actually working. And of course, the inset, our new function. We can specify some other different fields. For example, I can specify place field dot at sea opening hours. And here we can add a comma, then add opening hours. And here I can specify place the opening hours. And now let's run our app again. And now as you can see, we can see this opening hours. So here it says that it's open then at time of weeks, so Sunday, then if we scroll all the way on the right, we can see weekday. So here, Monday open 24 hours, Tuesday, 24 hours, Wednesday the same, Thursday, the same Friday, the same. So basically it's working seven days a week. And if you're confused now, you already saw in these recommendation one message that says that some of those fields like her address components, opening hours, phone number and UTC offset and this website URI are not supported, but those are fields are not supported for our fine current place function. But in this case we have used the fetch place function and we were able to get the opening hours. So those fields are only apply the four hour current place function, which we have used in the previous video. But now we have used this fetch place function. And you already saw how we can basically retrieve a place details with this fetch place function in here, we only need to specify basically a place ID, which is a unique identifier for each and every place in the world, and of course a place fields. So you can, for example, save some location or ideas from this first function. And you can save them a locally or on your server so you can store those ideas. There is no any legal issue about that and that those same ideas you can later use to fetch some are more details about that place using this fetch plays function. So I'm going to just reformat this code a little bit, king. So something like that. And now you have seen how to use both of those functions. So a fetch place and find their current place function as well. And for this video, that will be all. 17. Get Place Photos: Hello there and welcome back. In this video, I'm going to show you how to fetch and display place photo from a certain location around you. So here instead is official documentation. We can see that you can use a places SDK for Android to request a place photo to display in your application, and photos are returned by the photos. Surveys come from variety of sources, including a business owners and the user contributed photos. So there are a few steps which you need to take in order to show in this play place photo. So you can fetch the photo either with fetched place or a fine current place function. And you also need to be sure to include the photo metadata field in your request. And of course, in this unsuccessful listener, you can specify the maximum width, the height of the image, and the maximum width and height of a single photon can be 1600 pixels. And down below we can see an example of how can we implement this logic. And I'm going to copy this code for now, and I'm going to open up Android Studio. So we're going to continue from our previous video and down below, I'm going to implement that this code inside our second function get details with place ID. So we can fetch the photo either with fetch place function or with fine current place function. And in this case I'm going to focus on this second one. So I'll fetch place. And inside this ad on success listener, we need to paste that code which we have just copied. So I'm going to leave here small place, our case. So I'm going to paste the code here. Okay, So let me just import all those things here. Let's add the egg as well. And here I'm going to remove this fetch place function because we don't mean that we are currently at that function or inside that function in here, I can remove this line of code as well. And I can also remove this place ID. We're going to get it from the function or from the parameters of this function. So get details with place ID. I'm going to remove those fields or that a single field as well, and that this line of code as well. So here I'm going to just leave this photo metadata and down below this photo request and this fetch photo function. So let me just terraform code a little bit. Okay, so as you can see inside this function and get details with place ID inside this on success listener of our fetch place function, we have basically paste that from our documentation. And from there basically we are getting a photon metadata and we are also creating a photo requests where we are specifying the maximum width and height of our image. So those two are optional. And then we are calling our fetch photo function of our places client to pass this photo request. And there we have a tallest nurse on success and on failure. And if this task is successful, then we're fetching that the bitmap. And we want to basically added that bitmap to our image view. And now I'm going to basically go to our fragment first layout in here. I just want to add that one simple image view which we can use to actually fetch in this play. Image from one location. Let me just constraint that. Okay. All right, and here I can add binding that image view to set image bitmap. And here I'm passing that bitmap. So there is two more important things which we need to do. So here inside the displays fields, instead our get details with place ID function, I will need to specify a one more field in order to display that photo. So we need to use place field dot photon metadata's. And I'm going to also need to add this field inside this first function. So we're right here because as you already know, I'm using this, get details with place ID function from this I get current place Locations and that's why I need to add this place in both of those functions. And as you can see, this getting details with place ID is called from this first function. And there we have basically passed this single place ID. And from this function, we are using that ID to fetch that specific location details. And also if there's a task is successful. So if this fetch place function returns a successful result, then we are displaying that single place with some of its details. And after that, we are basically getting that photo metadata and we want to display that photo inside our image view. So I know that this can be a little bit confusing because those functions are a little bit longer. But don't worry, you just need to read one of those functions from the start and the everything will make more sense to you. So now what I'm going to do, I'm going to run this application and we're going to see if, uh, we're going to receive one photo metadata. So I'm going to run the app. And as you can see, we have received a message that says, uh, no photon metadata. So that means that we have found this place. So in today's computers and this current place does not have any image. So it can happen. And in that case we are not going to receive any image. And now I'm going to just change some place. So for example, inside this first function, get current place locations. I need to pass a different place ID. So for example, I'm going to type for number 2. So this is the third item in the list or the third place in the list, then I want to fetch its ID and see if I'm going to receive now a new image. So let's run our app again. Okay, so now as you can see, we have basically used this plays stadium and we have also fetch that photo. So that means that this current place have a photon and we were able to display that same photo inside our application. So as you can see, it looks something like that. So it's very easy. And of course, here as you can see, we have used the first image of that location. But of course, you have a multiple images, and of course you can display a list of multiple images, but in this case, we just needed the only one. So the first image inside this list and the tubule for this video. So now you have learned how to successfully fetched in this play allocation image. 18. Get Introduced with Application Design: Hello there and welcome back. So why in the previous videos, I introduced to you with places SDK for Android, and now it is time for us to start developing our geo fencing application. And I have already designed this application and how it should look like. So this is just a simple preview, of course, and that we might change this design in the future. But generally this is how our application should look like. So as you can see for now, we have six different fragments and we're going to have a single activity. The first fragment is a permission fragment, and this is where we want to request permission for our final cation from our users. So when we run our application for the first time, this permission fragment will be shown. And if we're given the permission to our application, then this permission fragment will not be shown anymore. And the after we give our application this permission, the first time we run our application, we're going to get navigated to this step one fragment. And as you can see here, we're going to have a three steps or three step fragments. So in the first step here, we're going to need to name our geofence. So here we can just basically enter any name we want. And also in the background of this step one fragment. And we're going to fetch the current user's location using a places as the K. And the now you might be wondering, why should we do that? Well, is because I want to get the user's country code and the debt country code, we're going to send to our step-2 fragment. And as you can see in our step 2 fragment, we have this auto complete widget, which we're going to customize by ourselves, as I already mentioned in the previous videos. And we're going to use the country code from our step one fragment. Limit the usage of our autocomplete the widget from a step to fragment. And that way we're going to increase the performance. And we're going to let the user choose only the cities inside the country. And by eliminating this, autocomplete the widget to a certain country, we're going to allow our users to search only their country because that's a logical way to add a geofence is only in the country you're living in. And after you select here summer city from your country, then you can get to step 3 fragment. And from there, you need to select the radius of your geofence. So here the minimum value will be 500 meters. Next thing we'll value will be ten kilometers. So of course, you can customize those values as you want. This is just my personal preference. And of course, after a user press Done and choose this radius, then we're going to get to our maps fragment. And in our maps fragment, we're going to this play as simple a TextView, which will say something like a long press on the map to add a G or fans in the first time the user long press on the map. But we're going to ask the user for another permission, which will be a background location permission. And only if a user grand thus the permission of background location, then we can add this geofence. And of course, we will be able to add multiple GeoFences to our application. And inside our maps fragment that we're going to have a two main floating action buttons. So the first, the bigger floating action button, will navigate our user to step one fragment to add a new geofence in the second floating action button, a wheel or navigating the user towards GeoFences fragment, where our user will be able to see a list of added the GeoFences. And from there, a user can see some details about all the GeoFences which has added like the location, coordinates in the radius and of course, the geofence name. And also a user will be able to delete those are GeoFences from there by swiping those items on the left side and clicking this Delete button and that this functionality will be implemented using emotionally out. So that's another good animation inside this application. And basically that's how our application should look like. So we should be able to have six different fragments and single activity. So now that you know how our application looks like, from the next video, we're going to start working with our application. And that FOB all for this video. 19. Implement Navigation Component: Hello there and welcome back. So we're in the previous video. You have seen this design in which I created in say the Adobe XD. And of course that this design will be available in this course for you to download if you want. And the now it is time for us to start developing our geofence application. So the first thing which we are going to do inside our project, we're going to implement and navigation component with all its destinations. So let me just open on my Android Studio project. And here as you can see, this is just a simple Android Studio project with a single activity, which is a main activity. And here I have just changed some colors. So instead of a purple, I have added this blue color, and now I want to start implementing our navigation component. So the first thing I need to create a navigation graph. So let's add here a new navigation resource file. And I'm going to name this file and nav underscore graph. Ok, click OK. And now we need to add a navigation component and dependencies. So just click okay, All right, so let's get back here. And as you already know, we only have a single activity and that single activity will host the, all our fragments. And now we need to start building or creating those fragments. So the first fragment which we are going to create is our permission fragment. So let's click here, create new destination. And we're going to choose a frame and blank template. Click Next, and I'm going to name this frame and permission fragment now click Finish now. Okay, perfect. So with this permission fragment will be a default to this nation inside our navigation graph. And the next time we're going to add maps fragment. So let's create a new destination here. And from here I want to select this Google Maps fragment template because it will be easier for us to actually connect our project with Google Cloud Platform. And I'm going to do that in some of the next videos. For now, let's just focus on our navigation components. So click Next. I'm going to leave the name of this fragment to a maps fragments. Click Finish. Okay, I'm going to place this fragment right here on the right side of our permission fragment. And the now I want to add three different fragments, which will present three different steps in creating a geofence. So I'm going to use a frame and blank, of course. And this fragment will be named the step one fragment. Click finish our K. Let me just play that here. Next, let's create a new destination. So again, Fragment Blank, and this time step to fragment, click Finish. Okay, perfect. And finally I need to add step three frames and click Finish. Okay, so now what I'm going to do, I'm going to create a nested navigation graph inside our navigation graph. And that new nested navigation graph will contain those three steps are fragments. So I'm going to open up this XML code. And as you can see here, we have our step one, step two, and step three fragments in here, I want to add a new tag, which is a navigation. So this will be. Our nested navigation, and here we need to add the ID. So the ID of this nested navigation graph will be add geofence graph and the start destination of this semester navigation will be our step one fragment. Okay, so here let me just close this tag. Okay, Perfect. And inside this navigation, I'm going to cut and paste those three fragments. So it should look something like that. Also, there is an easier way. So I'm going to undo everything from here now. And I'm going to show you the easier way. So here from our navigation graph, I'm going to just put those fragments right here. Okay? Now I'm going to select all of those three fragments, and I'm going to click this button which says a group into nested graph. So click this button. And now as you can see, we have received our nested navigation graph. So if we open up this XML, we're going to see that here our ID is navigation and they want to press Control plus a shift to rename that to add underscore geofence graph. So click Refactor and the here to the full destination will be step one fragment instead of step 3 fragment. And of course I can just move this fragment on the top here. Then I can move a fragment or a step to fragment below our step 1. So that's the order which I want to have. And I can also press all control plus L two reformer this code now. Okay, perfect. So as you can see, when I click on this semester navigation graph, we're going to see only those are three fragments which are a nested array irrigation graph. So let me just move them right here. And if I press this, our earth navigation, I'm going to see our permission fragment, our maps fragment, and our nested navigation graph. So there is only one more fragmented which I want to add. That is our geofence or GeoFences fragment. So let's create another one in here. I'm going to rename that to GeoFences fragment. Okay, click Finish. And these are GeoFences fragment will basically hold the list of all our GeoFences. Okay, so now I'm going to connect some of those iframes in the future of this course. So we're going to create some more global or actions and you'll see about that. So for now, I want to connect this permission fragment to maps fragment. And here I'm going to check this option pop-up to inclusive. And here I'm going to select the permission fragment. So the next thing I want to connect these maps fragment with both GeoFences fragment and that this nested navigation graph. So let me just connect this with the GeoFences frame and end with this ad geofence and graph as well. And here I'm going to connect our GeoFences fragment to our maps fragment in here. I'm going to check this alone single top option, then a pop-up to inclusive. And here I want to select the GeoFences, frame it as well. Okay, so that's how our navigation graph will look like. And now I'm going to open up this ad, the geofence graph or our nested navigation graph. So you can just double-click on that. And here I'm going to connect our step one fragment to our step 2 fragment. And here I'm going to check this pop-up to inclusive option. And here I'm going to select the step one fragment, and then I'm going to connect the step 2, step 3 fragment. Here also I'm going to check this option and here select the step to fragment. And I want to connect the back step two fragments with step one. And here also check this option and choose a step to fragment and hero, I want to also connect our step 3 fragment with step two fragment in here, check this option and select the step 3 frame. And so for now, that's how our navigation graph will look like. And as I already mentioned in the future of this course, I'm going to also add a few more actions, which will be global actions. So for now we don't have any global actions, but later we're going to need them in for now, this is how our navigation graph will look like. So before we end this video, I just want to open each and every fragment which we have created and I want to clean it up. So first, let's start with our permission fragment. So we're not going to need any of those generated code. We only need our onCreate view function. So let's remove everything from here. Okay, Let's open our GeoFences fragments. So let's remove everything from here as well. Perfect. Okay, So here, as you can see in rstudio is a warning us that we have a typo. So press all plus enter in here. Let's save this. So GeoFences to a project level dictionary. So we don't see this a warning anymore. Okay, Let's close this fragment. Now let's open up step one fragment. Let's remove all of that, our K, and that next we have step two fragment. Let's remove all of that as well. Perfect. Let's close that and let's open up our step 3 fragment. Okay, Let's remove all of that and companion object here as well. Perfect. And let's close that now. Let's open up our maps fragment. And for now, I'm not going to change here anything, but later we're going to modify this maps regnant as well. So that'll be all for this video. So while we have a successfully implemented that whenever radiation component, we have created the order fragments which we're going to need. And also we have created a nested navigation graph. So that'll be all for this video. 20. Design PermissionFragment Layout: Hello there and welcome back so well, in the previous video, we have implemented our navigation component. So we have created the six different fragments which we're going to need for our application. And in this video, I want to start and design our permissions fragment first. So before we actually design our permission fragment, I just want to open up activity main layout here, and I want to remove this default TextView, and I want to search for an Add Host Fragment, our case. So just drag and drop that right here on the screen. And then let's select our navigation graph, which we have just created in the previous video, our k Perfect. Now let's connect this net Host Fragment constraints horizontally or vertically with apparent our K perfect. In here, I can just rename this nav Host Fragment to say for example, nav Host Fragment as the ID. So clicker refactor our K perfect. And now we can open up our fragment permission layout. So here it is. And inside our layout, I want to change this Sir Arthur layout to constraint layout. And I'm going to remove this default TextView. So before we actually start designing our permission fragment, I'm going to open up Adobe XD design projects so we can actually see how our permission fragment should look like. And here as you can see, we will have only one ImageView. Then a down below we're going to have a two TextViews in the One Button. So first we're going to start with this button, and then let's just add here a new button are calleds connect the left, right, and bottom constraint. So all of those constraints should have a margin of 32. And let's increase in the layout width to 0 dp so it can match the constraints. The layout height for this button, I'm going to set to 70 BP. Okay, so it should look like that. And here I can just open this layout and here I can press Shift F6 to change the ID of this button. And I can name this button, Continue button. Okay, so clicker refactor, Perfect. In here I can just write continue. All right, so the next thing you will need to add the text view so you can see we will have a two TextViews in here. I'm going to copy this description from our design. And here I'm going to open up our values directory then are strings. And the here I'm going to add a new string. So the name of this string can be a permission description. In here I'm going to paste the texts which I have just copied from my design now. Okay, so let's open up our frame and permission. Now in here I'm going to add our text view. So the TextView should be constrained to a button down below, and the left and right constraint should be connected to this button as well. So the bottom margin should be, for example, it's a 48 DP. So something like that. I'll lay out the way it should be a match constraint. And the, let me just open this up in here. I'm going to write or change this ID, so Shift plus F6 and I'm going to change that to permission description, text view or K clicker refactor in here. And we could just link that text which we have just Pasted inside our strings.XML, I'm going to choose a text alignment to center. Then our text color should be black, text size should be 16. Sp. Text style can be Italica case or something like that. And next, we need to add one more. A TextView are above this permission description text view. So let's connect that text view right here. And to our texts on the bottom are k. So the bottom margin here can be a DP now k, So layout which should be 0 DP or match constraint. Here I'm going to just change the ID of this second TextView. And here I can write permission required text view clicker effector. In here we can just write permission required and I can just extract this string in Maya strings a resource file. So just press Alt plus Enter, Enter, Enter, Enter. And here we can do the same for our Continue button. So 0 plus Enter, then enter. But here for the resource name and willing to change it to something different because these Continue button is a reserved keyword in here I'm going to write Continue button, click. Okay. All right, So that's fine. So for our permission, require that a TextView, we're going to add the text alignment to center. Then our text color should be read, then our text size should be 26. Sp text style can be involved, and that's okay for now. So it should look pretty much the same as in our design. It's just a different red color and I'm going to open up that color. So I'm going to copy this color code and I'm going to just replace this color to a new red color. And I'm going to replace this image color to this new red color from our project now. Okay, perfect. And now I'm going to select this image or this vector file, and I'm going to export that is SVG. And I'm going to import that into my Android Studio project. So don't worry, this image or this file will be available for you to download from this course in a different format like SVG or P and G and so on. So now let's open up our Android Studio project. And here inside our drawable directory, I want to create a new vector asset. And I'm going to select the local file, then I'm going to choose my desktop. So let me just select here on desktop are k, here it is. And here I'm going to select this welcome image. Okay, perfect. I'm going to click Next and Finish. And now inside our permission fragment, I'm going to add one image view. And I'm going to select that vector which we have just imported. So click Okay. And let me just connect these bottom constraint to this text and the left and right constraint to this text as well. So the bottom margin here can be, for example, 100. Okay, perfect. And let me just hear, change the ID of this image view to something different. So Shift plus F6 and let's say here are welcome underscore ImageView. So clicker effector. I'm going to reform this code a little bit, and that's how our permission fragment layout will look like. So that'll be all for this video. And in the next video, we're going to continue working on our application. 21. Create Permissions object: Hello there and welcome back. So why in the previous video, we have designed our fragment permission layout. And before we actually go into our permission fragment file and start implementing some logic, I want to create one helper class for a handling runtime permissions. So for handling a runtime permissions. So we're going to use a 1 third party library called the easy permissions. So you can access this GitHub repository on this link here and down below, as you can see, you can read more about this exact library and you only need this one dependency. So you just need to add that into your project. And you can use this library to easily request and handle all runtime permissions for your project. So inside our Android Studio, I have already added this easy permissions dependency. And the now I want to create one are basically helper class in which we are going to create a few functions. And those functions will check in the request, the runtime permissions for us. So first here I want to create a new package and this packet should be named your teal. And inside this package first I want to create a new object name, constants. And the inside is object. I want to declare all my constants for this project. So before we actually start implementing some permissions, I want to create here a two constants. And those two constants will be always there is a request code for our permissions. So our application, we'll have a two permissions. And as you can see here, we have our fine permission in the background location permission. So let me just to remove those comments. Those comments were automatically generated for us when we actually created our maps fragment. So you need to declare those two permissions for your application because we're going to need those tool. Next here I want to declare a two constants. So cons val in the first one should be named that permission underscore a location underscore request underscore code, and it will have the value of one. And next we're going to add one more constant named the permission under score of background and underscore location and their score request underscore code editor will have the value of number two. So those two constants will represent request call for each one of those permissions. And then now incidence, so util package, I want to create one more Kotlin object. In this time these objects should be named the permissions. Oh, okay, so first, I want to create two functions for our final location permission in the first function should check if our application or has this final permission in the second function should request the location permission if we don't hear it. So let's create the first function has a location permission, and this function will take only one parameter and that is context. Okay, so here I'm going to use our easy permissions. So the s1 dot has permissions in hearing to pass the context is the first parameter and the second one, I need to pass our actual permission which we want to check. And that is. Our final cation. So this manifest android dot permission data access final cation. And basically that's all we need to write to actually check if our application has this access final location permission. And down below we need to create another function named the request location permission. And it will take one parameter and it is a fragment. And the hearing to also call our easy permissions, then request permission or request permissions. And here is the first parameter we need to pass our fragment or activity. In this case, we're going to pass foramen because we're going to use this function from our fragment. So let's pass the frame is the first parameter. Then as a second one, we need to pass a rationale. And that is a simple text message which will be shown to our user if our user denies this permission. So here I'm going to say this application cannot work without our location permission. Then as the third parameter, we need to add the actual request code. And we have already defined that the request code. So let's use our constant. So permission, location, request code, and let's just import ads. So that's our request code for our location permission, for our final location permission. And the final parameter here is the actual permission. So let's use manifest. So this android dot permission though that the axis fine location. And that's all we need to write to actually request and check if we have this permission. So now I want to create two more functions for checking in requesting a background location permission this time. So our background location permission is required only if you're using API level greater than enjoyed the queue version. So here I'm going to just copy those two functions and rename them. So here I'm going to rename this function two has a background location permission and this, I'm going to rename to request background location permission. Here I'm going to change this constant to beg round location permission. I came here, I'm going to change that to access our background location. And here also I'm going to change that to access background location. So here as you can see, we have some warning and that means that we need to add this require API queue annotation. Or we can surround our code with this if a block. So I'm going to surround our code with this if block. So only if our enjoy the aversion is equal or greater than this version called Q, which is API level 29, then we're going to request that permission. And if you are using API level lower than 29, then you actually don't need this permission. So here I'm going to also press all plus center and surround this code with this if block. And that there is one more thing which I want to add here. So our two functions for checking if we have that permission, like he has location permission and he has background location permission should return a Boolean value. And instead of using this angle brackets, I'm going to just add here equals sign. And basically this function will return true if we have the permission and it will return false if we don't have it. And of course for our second that he has beggar on location permission function. I'm going to return here, true at the end. And here I'm going to just add the Boolean value as a return type. And here I want to also add the return and it will return, again, true if we have this permission and false if we don't have it. And of course, if we are using devices lower than API level 29, then this if block we'll skip and this function will return true, which is basically like we have already granted this beggar and location permission. And down below for this iteration error message, I can change this message to something different because this is a beggar and location permission. And here I can write, for example, background location permission is essential to this application. Without it, we will not be able to provide you with our service, and that'll be all for our permissions object. So this object will have all the necessary function to check if we have those two permissions and to request those permissions as well. So as I already mentioned, this first permission location permission or access vinyl cation is a mandatory and this background location permission is required only if you're using an API level 29 in higher end that those functions are public because we're going to use them from our fragments later in this course. So for now, that will be all. 22. Create DataStoreRepository: Hello there and welcome back. So wanting the previous video, we created our permissions object. Where are we here? They're fine for different functions to functions for checking our location permissions and the two functions for requesting permissions. So now in this video, I want to create Datastore repository. And for those of you who are not familiar with the data store, it's basically a new data storage ocean, which should be a replacement for an all the SharedPreferences. And if you want to get more details about datastore, you should check the official Android developers documentation. So jetpack Datastore is a data storage solution that allows you to store a key and a value pairs or a typed objects with a protocol buffers. So data store uses a Katlyn coroutines and flow to store data asynchronously, consistently in the transactionally. So if you're using all the SharedPreferences, your should migrate to a data store instead. So data store is used to basically store some a small amount of data locally on our, with our application. And if you're wondering, why do we need that data, store it inside our application? Well, we need a data store for only one reason, and that is to save or just the one simple Boolean value. And that Boolean value should be used to check if we have launched our application for the first time or not. And that Boolean value will be used later in our application to implement some different logic. So for now, that's all you need to know. And then now I'm going to create a new datastore repository class where we're going to implement our datastore. So now I'm going to create here a new class. So let's create here a new Kotlin class name there, store, repository, click Enter. And our class will have only one parameter here, and that is a context. So contexts. All right, so our data store repository, we'll have two options here to read and store our Boolean value. So before we actually continue, I just want to open up our constants object in here. I need to declare two more constants for our Datastore repository. So the first constant should be named the preference name. And here I'm going to write geofence underscore DB in here. I can press Enter to save this a geofence words to a project level, a dictionary. Okay, In the second constant should be named preference first lounge. And here I'm going to write first lounge, our case. So we're going to need those two constants inside our data store repository. So let's close that for now. So inside our class I want to create a new object, so private object, and I'm going to name this object preference key. And here I'm going to create a new variable named the first lounge. In here, I'm going to use this Boolean preferences key. And here we need to pass the actual key, which will be used along with a Boolean value. So here I'm going to use the constant which I have already defined. Preference, first lounge all to a center. So this variable, first Lounge will have the type of preferences, the dot key. And this key will be used to basically save and read the value from our data store. And then now I'm going to create an extension on our context with the name of a data store. And I'm going to use a delegate to delegate that to Preferences datastore now, okay, and here, and it'll pass the name of our data store. So preference name, and that's the constant which we have defined inside our constants object. So down below that I need to create another variable named the data store. Here is a type I'm going to choose the data store in hearing me to pass that preferences. So Android X dot a datastore and preferences dot core. And here I'm going to call our contexts dot data store. And of course I can just cut and paste this extension on the top of our outside of our class. So right here and down below, I need to create a function which will basically store or save a Boolean value in our data store. So here I'm going to use a suspend keyword because this function will basically use coroutines. So the name should be a save first lounge. And here as the perimeter, I'm going to add first launch or Boolean value of k. So we're going to have only one parameter and that is a Boolean value. And here inside them when to call a data store dot edit. So here I'm going to write preference, and down below I need to call this preference. Then here I'm going to pass preference qi dot first lounge. So that's the key which we're going to need and the value should be first Lounge from the perimeters of this function. So now basically, as you can see, we're going to store inside the data store aisle value of first launch, which is a Boolean value which we're going to pass in the parameters of this function. And the key will be the key which we have already defined in this preference key objects. So right here and here we have used the constant for the name of our preference key. So if we open up this constant or constants object, we're going to see those two are constants. So down below we need to create one variable which will have the type of flow, and that variable should basically read the value from our data store. So let's create here a new variable name there, read first lounge. In here. The type should be a flow of a type volume in here I'm going to call data, store data in here first I'm going to call a catch block. So here I'm going to write the exception. So if there is an exception of a type IO exception, then I can just emit an empty preferences. And in Else block I can just throw an exception. Okay, Perfect. And down below I'm going to call a map. And here I can just name this preference in here I can create a new variable named our first lounge in here. I'm going to use this preference with the actual key which we have already defined. So first lounge and here I'm going to use Elvis operator. So if there is no any value, the default value can be true. Here I'm going to return this first launch our Boolean value. Okay, so here I have one warning and I think that I have imported the wrong class here. So as you can see, I have used the Java util concurrent flow. I need to delete that and into import another important. So in this case we need to use this Katlyn coroutines flow, okay, and now that error will disappear. Okay, perfect. And that's basically how our class should look like. So this is our data store repository. Now we have there find constants for our preference name and for preference first lounge. So this will be the actual key for our value. And our value will have a type of a boolean, which we have already defined here. So Boolean preference key, and we have defined the two functionalities to basically save a new value inside our data store and also to read our value from data store as well. So for now, that will be all for our data store repository. And in the next video before we start to actually implementing some logic inside our permission fragment, we're going to create a shared view model. So that's all for this video. 23. Create SharedViewModel: Hello there and welcome back. So in the previous video, we have created our Datastore repository and we have implemented the all the necessary logic which we are going to need for our data store to actually read and the write a simple Boolean value to our data store. So for now this is how our Datastore repository will look like. And in this video I want to create a shared view model. So why do we actually need a shared view model? Well, we're going to use a single view model to share the values between a multiple fragments. So basically what we're going to do with that, the shared view model. So for example, let's say that we want to use the same shared view model instance, those steps fragments. And for example, when I hear enter the name and click Next, then I want to update one of variable inside our shared remodel. And also I want to share that value with all other fragments. So all other fragments will have the access to that variable which I have updated, for example, from our step one fragment and also, for example, from step two frames, we're going to update some values inside our shared remodel and all other fragments will have the access to those same values. And you will see how that will look like later in our application when we actually start creating some more logic. But for now let's just create a new ViewModel here. So for that I'm going to create a new package name, the view models. And here I'm going to create a new Kotlin class named a shared view model. Okay? So this model or this class should inherit from not ViewModel but Android ViewModel because we're going to need the application contexts. So let's just write here application. And also here we need to add that applications. So right there and here inside I can just write one variable named app in here. I can just get the application from the perimeters of our shared view model. So also what we need inside our shared view model, we need to inject our data store a repository which we have created in the previous video. And before we actually inject this data store inside our shared view model, here I need to do a few more things. So here I need to annotate this shared the model with the ViewModel scoped because this data store repository will be scoped to a life-cycle of our shared remodel in here also I want to inject. So let's use Inject annotation to inject the constructor with application context. Okay, So after that I'm going to open up our shared view model. And here I'm going to also annotate our shared the model with a hilt View Model Annotation. So this hilt view Modelling Notation will basically handle all injection to our view model. And we don't need to write any ViewModel Factory because this notation will handle everything behind the scenes and the heel, I'm willing to inject that Datastore repository. So let's use here Inject annotation, and let's inject here our data store in the constructor. So private Val data store a repository. Now, okay, Perfect. And down below I'm going to just L1 comment data store in here I'm going to create a new variable, read first lounge. Here I'm going to use this data store repository which we have injected inside our shared view model. In here we're going to call a read first lounge. And we want to convert this flow as a live data. And down below I'm going to create a function for saving our Boolean value inside our data store as well. So let's name this function saver first lounge in here. I'm going to pass one parameter. So first allowance of a type Boolean off course and the hearing side, I'm going to basically call our ViewModel scope to launch a coroutine and the protein should be launched on an IO dispatcher. So let's call this petrous dot io. And now I want to call here a data store repository dot save first lounge. And here I'm going to pass this Boolean value from the parameter, so this function, and of course, we're going to use those to one variable in one function from our fragments are later in this course. For now, I just wanted to create or inject that data store repository so we can use some of those functionalities from our repository. And later, of course, in this course, we're going to create multiple variables here which will share their values between multiple fragments. So later in this course, we're going to add some more codes inside our shared view model. But for now, that will be all. 24. PermissionFragment: Hello there and welcome back. So in the previous video we have a created their shared view model, which we're going to use in a multiple fragments in our application. And now that we have created the both shared remodel and datastore repository, and now we can continue and implement some logic inside our permission fragment. So the first thing which we need to do, we need to enable view binding in our project. And as you can see, I have already enabled the view binding and data binding as well. So we're now inside our permission fragment. I'm going to create here at two variables. The first variable will be a var or read and write variable. The name should be other score of binding. The type should be a fragment, permission binding, and its default value will be null. Then after that, I'm going to create a read-only variable named the binding end here I'm going to select getter to get the value of our unde