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 can't make an app without any resources! In this video we'll move the solitaire code into our Android project, and then we'll find some great card resources!
Resource Links
Lowercase Script
Windows
for /F %a in ('dir /L /B') do ren %a %a
Mac/Linux
for f in *; do mv "$f" "$f.tmp"; mv "$f.tmp" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
Related Links
Project Files
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
[MUSIC]
0:00
We've just covered a ton about Anko.
0:04
And Kotlin too for that matter.
0:07
I know this stuff can seem challenging,
but you're doing a great job at it.
0:09
And once you see your
finished solitaire app,
0:13
I'm sure you'll agree that
it was worth the challenge.
0:15
Anywho, let's get back
to our solitaire app.
0:17
First let's start fresh by closing
everything other than main activity.
0:21
And then deleting everything
in the onCreate function
0:28
except the call to super.
0:31
Next, before we can do anything involving
solitaire we'll need to get the code for
0:35
solitaire into our app.
0:39
To keep things simple let's just copy and
0:42
paste the code into a new package
inside our current package.
0:44
So right click on your package and
pick new Package and
0:49
for the name,
I'm going to pick no_Android.
0:55
But you can use whatever name you'd like.
1:01
I like this one because it reminds me
not to add any Android code to it.
1:04
Once we've got our new package,
all we need to do is copy and
1:08
paste all the code files for
our solitaire project Into this package.
1:11
If you don't already have the code files,
you can download a zipped folder of them
1:17
from the GitHub project linked
in the teacher's notes below.
1:20
So let's copy those files and then
paste them into our no_Android package.
1:24
And actually, we don't need the app.kt
file anymore, so let's delete it.
1:33
Next, to make our solitaire code
work with our Android code,
1:43
we'll need to add a package
directive to each of these files.
1:46
So starting with Card.kt,
let's add a couple lines at the top and
1:49
then add your package directive.
1:55
For me,
that's com.teamtreehouse.solitaire.
1:58
And notice that I didn't
add dot no android.
2:04
For this app, It's just a bit simpler
if everything is in the same package.
2:08
Now that does give us a warning,
2:13
that package directive
doesn't match file location.
2:15
But while the package directive and
the file location
2:19
are usually the same they're actually
two completely separate things.
2:22
So we don't need to worry
about this warning.
2:27
Now let's copy our package statement and
2:29
then go about adding it to
the rest of our solitaire files.
2:32
Finally let's right click on one
of the files tabs up here and
2:59
choose close all to clean up our windows.
3:03
Now that we've got our solitaire
code ready to use, before
3:08
we can get back to main activity, we'll
need to add in resources for our cards.
3:11
Luckily, I know where we can find some
excellent assets for our game and
3:16
not only do they look great but
they're also free.
3:20
They're from a game studio in
the Netherlands named Kenney and
3:23
they've got tons of great assets that
they share freely with the community.
3:25
If you're looking to make a game
sometime definitely check them out.
3:30
Anyway, follow the link in
the teacher's notes below
3:34
to get to the download page for
the board game pack.
3:37
Then we just need to download it,
Unzip it,
3:41
Then we can go into the PNG folder and
then the cards folder.
3:48
And there's the cards we need.
3:53
But before we add these to our project,
we need to make a small change.
3:55
Remember an Android resource files
aren't allowed to have capital letters.
4:00
So, we'll need to change these file
names to not have any capital letters.
4:06
To do this we just need to run
a simple script that can be found in
4:11
the teacher's notes below.
4:14
If you're on Windows,
copy the Windows version of the script and
4:16
then shift plus right click
inside the cards folder and
4:20
choose open command window here then
paste in the script and hit enter.
4:24
On the other hand, if you're on a Mac like
I am, then let's go to System Preferences
4:29
and then keyboard, then hit the shortcuts
tab and pick services on the left
4:37
and then check the box for
new terminal folder.
4:45
Now let's go back to our cards folder and
go up a level to the P and G folder.
4:51
Then let's right-click on the cards
folder and choose New Terminal at Folder.
4:58
Finally let's paste in the MAC
command from the teachers notes,
5:06
Hit enter and there we go.
5:13
If we go into our cards folder
now they're all lowercase.
5:17
Last but not least,
let's copy all of these cards and
5:21
paste them into our apps drawable folder.
5:24
We're not going to worry about
DPI differences for this app.
5:31
Great work.
5:36
We've got our code and
we've got our resources.
5:38
All that's left,
is putting it all together to make an app.
5:41
In the next video,
we'll finally start creating the UI.
5:44
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