Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
We need to make sure to follow the attribution requirements for our API. Let's add a clickable link to our app.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
We're super close to having
the bottom of our layout done.
0:00
There's just one more
thing we need to add.
0:03
If we go back to the developer page in
Dark Sky and look here in the overview.
0:05
Scroll down here to terms of service.
0:12
I'm not going to read this all, or
go through it section by section.
0:16
But before you use it in your app,
0:20
you should familiarize yourself with
any terms of service an API has.
0:22
The main one we need to
concern ourselves with for
0:26
Stormy is this attribution section.
0:29
In a nutshell, it states that we need to
display a Powered by Dark Sky message and,
0:32
if possible,
make the text open a given webpage.
0:38
Let's head back over to Android Studio,
add in the text view with the required
0:41
message and
make the text a link to their site.
0:46
So let's grab a new text view.
0:50
We can constrain it to the bottom.
0:55
To the left, or to the right.
0:58
Let's make this a little bit bigger.
1:02
We'll call this darkSkyAttribution.
1:06
For our default text we want
it to be Powered by Dark Sky.
1:13
And for the text color,
we want it to be our 50% white.
1:23
Okay, now we need to make this a link
to open up the Dark Sky website.
1:34
It's fairly simple to do but there
are some steps involved, so stick with me.
1:39
First, we need to add
the URL to our text and
1:44
the best way to do that is by
making this text a string resource.
1:47
So, let's go back up here.
1:53
We'll add a new resource.
1:58
We'll call it dark_sky_message, and
we'll put Powered by Dark SKy in there.
2:02
Now we need to head over
to the strings.xml file and
2:12
add the URL information to our resource.
2:15
So values, strings.
2:18
We see our string resource that we
just named dark_sky_message in here.
2:21
We need to wrap our message
text in an HTML anchor tag and
2:26
give the href value of the URL.
2:30
If you aren't familiar
with HTML anchor tags and
2:33
href values, I've put some information
in the teacher's notes about them.
2:37
To start with, we need to wrap
our anchor tag around the text.
2:41
We'll add an anchor tag there,
and our closing anchor tag.
2:49
Now we need to add the href and
2:55
url information from Dark Sky to
the opening of our anchor tag.
2:57
Come in here.
3:01
Href, and their URL is
3:04
https://darksky.net/poweredby.
3:08
Great!
3:15
That wasn't too painful.
3:17
And if we go back and run our app,
we should see our text as a link now.
3:19
And if we click on it, nothing happens.
3:31
Also looks like our degree symbol got out
of alignment here, so we'll fix that too.
3:34
Let's tackle that degree symbol first.
3:41
There it is, there isn't a constraint.
3:45
So we'll put the left to the right
of the temperature value.
3:47
Okay, so what's going on with our link?
3:52
Well, we still need to tell Android
to do something when we click on it.
3:55
There are a few different
ways we could go about this.
4:00
We could write an onClick listener for
instance.
4:04
But let me show you a way that only
takes a couple of lines of code
4:07
in MainActivity.
4:10
Let's head over there to set that up.
4:11
So we go over to MainActivity.
4:13
So here in our onCreate method,
right after we call the setContentView,
4:19
let's define a new TextView named darkSky.
4:24
We want to find the view by the ID that
we set a little bit ago, so findViewById.
4:32
I think it was darkSkyAttribution,
there it is.
4:40
Now we need to tell Android to enable
the links inside this text view object.
4:45
We can do that with
the set movement method.
4:50
So darkSky.setMovementMethod();.
4:54
This method takes a parameter,
a movement method.
4:59
There is a movement method named
link movement method that supports
5:02
clicking on links, and we'll want to get
that instance should we click on the link.
5:06
So LinkMovementMethod.getInstance,
and that's it.
5:11
Now we can run our app.
5:17
And when we click on the link,
we're taken to the Dark Sky site.
5:23
Pretty slick, eh?
5:30
Our layout is just about wrapped up.
5:32
And it's great that we have added
that attribution to Dark Sky.
5:34
That'll make the attorneys happy.
5:38
We're nearing completion of our
Stormy app and you're doing great.
5:40
The next step is to connect or
5:44
bind the data we are getting from
the Dark Sky API to our new interface.
5:46
Let's see how to do
that in the next stage.
5:50
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up