Welcome back and this video, we are going to start with the preparation for our project, so we're
not going to see too much yet, but it's really about getting things set up.
And we're going to use a lot of features that we have used before, a lot of code that we have used
before.
So there will be a lot of copy and pasting because it doesn't really make sense for me to type everything
in once again, because really it's just copy and pasting from other projects.
It's really just the same code that we are going to need, for example, for the permissions.
So it doesn't make sense to write everything in you because you know how to build up permissions for
using Dextre, then it's going to be the same thing for using a dialogue.
So when we want to display a dialogue, we're just going to use our custom dialogue once again.
So, no, you need to use a bunch of new code there.
It's going to be the same code again and again.
So you already see you can reuse a lot of the features that you have used in the past.
And that is super powerful because it really helps you to build applications a lot quicker.
And each time that you build something new, you will learn a bunch of new features that you can then
most likely reuse and other projects that you're going to work on.
So that's why it really makes sense to just go through many different projects, to practice a lot and
to just get started by building as many projects as possible, because then you can reuse a bunch of
the code or at least reuse a bunch of the thought process that you had so you can get quicker to a solution.
All right.
So I'd say let's just get started with an empty activity because, of course, we want to build as many
projects as possible.
And the quicker we start, the more we can get done.
So this one will be our weather app and then it's going to be API 21.
And let's finish.
So in this video, we're just going to set up the dependencies and then we're going to set up the permissions
so that we get access to the location of the user because we want to have the latitude and longitude
of the user in order to then later on display the weather at this location.
All right.
So let's get started by going to the gradle, because in there we're going to need a bunch of dependencies
here and build CRIDDLE.
And here I'm going to add them right before the test implementation.
So let's get started.
We will need the glue material.
So Android material.
This one here, because we're going to meet some of its designs and features them, the place services
location, so we want to have the location of the user.
And then finally, or at least for now, finally, we will also need Dextre.
So we're going to use Kaddoumi texta, which is going to be used for requesting permissions.
All right.
When we're at the topic of permissions, we, of course, need to go to our Android manifest and ask
for permissions here also, because otherwise, of course, it's not going to work.
So let's go to the application.
And then do the activity where I'm just going to set the screen orientation to be portrayed so the app
will always just display in portrait mode.
And then, of course, we are going to need the location so you can, of course, also add the Internet
requirements so users permission for Internet and everything, but I think we'll just going to do that
later on.
So here, access.
Find a location and then use this permission access course location.
So it's just going to be those two for now.
OK, fine location and location so that we get the location of the user.
All right.
By the way, we also need to sync our gradle, so let's do that so that we can access all of the third
party libraries that we have had it there.
So here in the gradle, we added those three and we, of course, need to sync our gradle file in order
to be able to use those features.
OK?
And the main activity, that's where pretty much everything will happen is going to be the heart of
our application here.
We will need to check if the location is enabled.
So what I'm going to do is I'm just going to use the same code that we have used many times already.
Whenever we had to get the location of the user, which is is location enabled, which will return a
boolean.
So what we do here is we create a location manager object, which will be the location service, and
then we return the result of his provider and able.
So this pretty much means is GPS enabled and that's what we're going to return to here.
OK, so is it either GPS or is it the network provider?
So I want to have this either or check because we can also get a bunch of information from the location
manager network provider.
So often enough this will be already good enough because we don't need to know the specific location
of the user by 50 feet or something like that.
But it's good enough if we have the information, let's say a thousand feet apart or maybe even 10000
feet away, for example, of an antenna is, I don't know, let's say ten thousand feet away.
It will still be rather precise when it comes to the temperature, the wind and everything.
And then for now, what we will do is in uncreate, we will check if the location is enabled or not.
So if it's not enabled is location and not enabled, then I want to write a little toast, which will
just tell the user that the.
Provider is turned off and he should please turn it on.
So this means please turn on your GPS, get your location providers turn off, please turn it on.
So that's what we're going to tell him if the location is not enabled.
All right.
And if it's not enabled, we can also directly redirect him to the settings where he can change those
settings.
OK, and here by we create an intent where we go to settings, action, location, source settings.
Which will allow us to then make the change, so activate the location.
So, for example, activate GPS and then if we have the provider activated, so if we have GPS or the
network provider here.
Then we want to write another toast saying your location provider is already on or turned on or something
like that.
OK, so this application isn't that complex yet, but we're just going to build it up step by step,
as you can see.
So the first thing was to even check if we have GPS or not before we do any fancy stuff, before we
do any downloading data and testing anything, because in order to display the weather for a current
location, we, of course, need to have the current location.
So it makes sense to start with getting the location of the user.
All right, and.
Let me run that once again, you can see the location providers already turned on and then in order
to test it, really, you also need to turn off location so you can go to the settings if you really
want to test it.
Then here, go to location.
Location and then turn off location.
Now let's test the application again just to see if it's going to.
And as you can see, that location is directly opened up, so it directly goes to this intent here,
which is the actual location source settings.
Let me show you once again.
So I started well, actually, let's move out.
Let's start once again.
And you could see it automatically opens up this application, so opens up this location settings and
you can directly turn on the location.
So if you really need some specific settings, you can go to those settings directly via an intent.
So this is super powerful stuff.
It is very useful in many different occasions.
I've recently installed an application which told me to activate six different settings.
So I had to go through my phone settings so many different times.
But the beauty was it led me directly to the right settings so I didn't have to search for them specifically.
But I could just click on change settings and then it would send me to those settings and I could change
that because this is one of the most annoying things that if you install an application at first of
all, asks you to do a ton of things and make changes to your phone and so forth without it guiding
you and helping you out because it's super frustrating.
And then you can just deactivate the application altogether or many users will do and they will uninstall
it.
So this is something that you have to be very careful with and also wary about when you need all of
those different permissions and those settings to be true and so forth.
But usually this is something that you can expect every phone user having active.
So usually people have the location services active.
All right, so I think this is a great point for a break now we have this feature and now let's go to
the next video where we are going to get the location, because so far we don't get the location.
We just check if the location is enabled.
All right.
So the next thing will, of course, be to use Dextre in order to ask for permissions and so forth.
All right.
So see you in the next one.