(light music)
(swooshing)
(keyboard typing)
I mentioned towards the end of the
last video that the Android Studio can also
compare entire directory trees
as well as comparing individual files.
Now if the directories don't have the same structure though
you will struggle to get any meaningful comparison from it
and that's why I suggested, or have suggested,
that you use same company domain as me
when creating the projects for this course.
Now to see why they should match
why not click on the activity.main.xml in the project pane
we can see the path to the file
with the project at the top up here.
Here you can see that it's app slash source
slash main slash res slash layout.
So if you want to compare resources in two different
projects you can actually just compare the res folder
and everything will work fine.
Now I've made a copy of this project earlier
so I'm going to click on the res folder here
and then I'm going to use compare with
from the view menu.
So this time we get something different.
It's a directory picker rather than
the file picker
so I can never get to the res folder from
the other project.
So I'm going to go ahead
and do that.
And I've got this on my desktop
and the calculator app,
source, main,
and res.
And now that I've selected that directory
I can click on open
so we can see that the Android Studio diff tool
displays the directory structure at the top
of the screen for both on the left hand side
and the right hand side
and the two same panes comparing the
currently-selected file in the bottom pane.
Now you may just get a message
or a screen that I've got saying nothing to show
because the diff tools only showing differences
so if that happens both directories are the same
as mine is here because
I've taken a copy of the project as it existed
at the end of the last video.
Now you can show all the files if you want to
by clicking on the equals button up here
and you can see that that's popped up.
That will show files that are the same
as well as ones that are different.
Now it doesn't bother displaying empty directories
so there's not really much else to see here
but if the projects contained other resources
that'd be available for comparing as well.
And once again it can be a good idea to use the
comp menu in the lower pane down here
to turn off code inspections in the highlighting
level menu.
Choosing syntax instead.
Just makes it a bit easier
and turns off all the red.
Alright so I'm going to close this
to get back to Android Studio.
And then I'm going to try
and do the same thing
but this time for the Java folder up here.
Java directory.
Now when I click on view you can see there's now
no compare to option.
Now it's tempting to try comparing the app
directory instead so going up one level here
and then if you go up to view,
compare with has got an option to do that
but I definitely advise against it.
The reason is there are a lot of files
in the build directories,
over 2,000 actually,
and we're not interesting in comparing any of them
so we just end up with a very confusing display.
Instead I suggest you actually compare
at packaged levels.
So in this case the academy.learnprogramming.calculator
now that's a bit boring
but we'll do it anyways.
So we'll click on that
and click on view, compare with,
and go to the same level project in the
copy that I've expanded on my computer.
So calculate, then it'll be app, source,
main, Java,
and I'm going to do academy.
I'm basically at that level.
If you're wondering which part that I'm actually testing
you can always see that from the path that you're
actually in.
So I'm going to go to learn programming,
and to calculator.
Click on open
and then I can click on equals if I want
to see all the files whether they're same
or different.
In this particular case it's a bit boring
because you've only go the one file.
But that would be a good way of doing it.
But instead what I'll do is I'll close this down
and I'm going to go into project view up here.
Select project,
and I'm actually going to do a comparison
from the app source main instead.
So I'm going to open the app, source,
and then main.
I'm going to select that, view, compare with,
and I'm going to go to my other version
and select main as well
so we're basically at the same level.
Click on open.
And you can see we're at app source main,
app source main,
and I can see the various files there if I wanted to.
No whenever directories match here the diff tool
will show the files side-by-side.
And you can click the file that you're interested in
to see it compare to the corresponding
file from the other project.
So I can actually just come over here
and select a file
and you can see that the other files actually
come up there.
Activity underscore main, scrolling down
a bit further.
IC launcher, you can see as I'm doing that,
the other side is automatically being opened
and we can compare the contents in both sides.
Now this works fine if the company domain
was the same for both projects
but often that may not be the case though
and it can actually cause problems.
The resources will still match,
that's because they both live in their slash main
slash res directory of source.
But the package name is used for the directory structure
and the package name comes from the company domain
that we used when we created the project.
So in this particular example
our main activity code file is
in the directory
main.java.academy.learnprogramming.calculator
and you can see that when a new directory is
been created for each part of the packaging name.
And we can see that a new package name
has been created for each.
So if you come back here
and actually have a look,
main, Java, you can see up here
we've got source main
Java academy learn programming calculator.
Now if I have a project named org.example.calcualtor
then obviously the directories won't match
and therefore I won't be able to compare the
Java source files.
So the solution to that in that case
is to chose the package directory
when starting the comparison.
So to show you what I mean I'm going to
compare the source code from this project
with the source from the YouTube app
from the previous version of this course.
So I'm in Android Studio
and I'm going to go back into Android view.
And I'm going to expand main Java
so I've got, you can see there that I've got
the Java package open.
Basically So that I can see the package name
in this case
academy.learnprogramming.calculator
then I'm going to use control D to
get the directory to choose a dialogue
and navigate to the YouTube directory.
And when I say basically set,
I need to click on that so
that's the folder that I'm actually comparing.
Then I'm going to do my control D
or command D on a Mac.
That's going to open up the dialogue,
the directory picker
and I'm going to navigate to the YouTube directory
of the other project.
So I'm going to go back to that file
the other application,
the other project,
we go to app, source, main, Java, com,
noticing the package is different here,
Tim Buchalka, YouTube Play.
So that's the equivalent level.
Now I'm going to click on open.
Now this is not a very sensible thing to do
because they're completely different projects
but it does show how you can match the source code files
from one project
with those form another.
So that's how to compare your source files
against the source code from the videos
all of which is available from the resources
for each video.
It is pretty straightforward,
particularly once you've done it a few times
and it's really only slightly more complicated
if you're using a different company domain name
to the one that I've used when you're
creating my version of the project.
And if you get problems with your layouts or code
and can't work out what the differences are
this diff tool can actually save a lot of time
and frustration.
Now the last thing that I'll mention is
that the control D or command D shortcut
only works if you've clicked on something in the
project pane.
Now if you're editing a file,
control D will duplicate the current line of code
so watch out for that.
Alright so let's finish the video here.
In the next video we're going to create the code
to make our calculator work.
So we'll see you in the next video.