This workshop will be retired on May 1, 2025.
Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we'll complete the link and see it in action!
Formatting Functions
private String formatDataString(String dataString) {
int indexOfSlash = dataString.lastIndexOf("/");
String urlEnd = dataString.substring(indexOfSlash + 1);
String[] words = urlEnd.split("-");
String finalString = "";
for (String word : words) {
word = capitalizeWord(word);
finalString += word + " ";
}
return finalString.substring(0, finalString.length() - 1);
}
private String capitalizeWord(String word) {
return Character.toUpperCase(word.charAt(0)) + word.substring(1);
}
Related Links
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 just updated main activities intent
filter to make sure that we receive
0:00
any intense pointing to
the tree house tracks page.
0:04
Now we've just got to handle the intent
and display which track the user selected.
0:07
But before we get to main activity,
let's update the layout.
0:11
Let's open up activity main.xml.
0:15
And then the first thing we should
do is add an ID to our text view.
0:20
I'll name mine textView.
0:30
Next let's update the text to start
by saying no tracks selected.
0:33
Then let's update the text
size to be 24 S.P.
0:43
And finally let's place our text
view in the center of the layout.
0:48
By setting the layout center and
parent tag to true.
0:58
Now that we've updated the layout,
let's head over to main activity and
1:05
handle that intent.
1:08
Since the plane is to update
the text in the text view,
1:11
let's start by creating a variable for
our text view.
1:14
TextView, we'll call it
textView = (TextView)
1:19
findViewById(R.id.textView).
1:26
Then let's create a variable to store
the intent that started the activity.
1:31
Intent_intent Equals getIntent.
1:37
Next we need to check that this
intent has the same view action
1:43
we specified in the intent filter.
1:47
If
intent.getAction().equals(Intent.ACTION_V-
1:50
IEW)) And
1:59
if it does then the intense data string
property should contain the selected URL.
2:03
So inside the if statement,
let's start by toasting the data string.
2:09
But first let's create a variable for it,
2:12
string dataString =
intent.getDataString() and
2:16
then let's toast it by using the toast
option that says Create a new toast.
2:21
Now if the user clicks on one
of the Treehouse tracks and
2:32
chooses to open it in our app.
2:35
They'll get a toast of the URL, but
it doesn't yet update the TextView.
2:38
To do this, we just need to strip
out the last part of the URL and
2:43
then format it to look more
like normal text than the URL.
2:47
Since that's not really what this workshop
is about, I've got a couple of functions
2:50
down below in the teacher's notes to
let us skip ahead to the good part.
2:54
So let's copy and paste those in.
2:58
And then all that's left to do is call
3:00
textView.setText and
pass in the formatted data string.
3:03
So we just call formatDataString
while passing in our data string.
3:10
Awesome.
3:16
Now let's run the app.
3:17
And instead of doing anything in the app,
let's open up the browser,
3:22
and navigate to Teamtreehouse.com/tracks.
3:26
And look, we've got a choice to
open it with our DeepLinks app, but
3:29
let's choose Browser for this first one.
3:34
Once we've got to the page,
let's pick our favorite track.
3:43
Clearly the Android track and
3:48
then choose to open it in our
deep links app and there we go.
3:51
That's the URL I click and
that's the track I picked.
3:56
Nice.
3:59
Adding deep links to your app can be
a great way to get users more engaged and
4:00
just provide an overall better experience.
4:04
If you'd like to see more with the planes.
4:07
Check out some of the links below in
the teacher's notes until next time.
4:09
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