1 00:00:00,108 --> 00:00:01,191 (light music) 2 00:00:01,191 --> 00:00:02,572 (swooshing) 3 00:00:02,572 --> 00:00:04,517 (keyboard typing) 4 00:00:04,517 --> 00:00:06,410 I mentioned towards the end of the 5 00:00:06,410 --> 00:00:08,921 last video that the Android Studio can also 6 00:00:08,921 --> 00:00:10,467 compare entire directory trees 7 00:00:10,467 --> 00:00:14,220 as well as comparing individual files. 8 00:00:14,220 --> 00:00:16,707 Now if the directories don't have the same structure though 9 00:00:16,707 --> 00:00:20,777 you will struggle to get any meaningful comparison from it 10 00:00:20,777 --> 00:00:23,610 and that's why I suggested, or have suggested, 11 00:00:23,610 --> 00:00:26,270 that you use same company domain as me 12 00:00:26,270 --> 00:00:29,080 when creating the projects for this course. 13 00:00:29,080 --> 00:00:31,130 Now to see why they should match 14 00:00:31,130 --> 00:00:35,140 why not click on the activity.main.xml in the project pane 15 00:00:35,140 --> 00:00:37,320 we can see the path to the file 16 00:00:37,320 --> 00:00:39,330 with the project at the top up here. 17 00:00:39,330 --> 00:00:41,600 Here you can see that it's app slash source 18 00:00:41,600 --> 00:00:45,410 slash main slash res slash layout. 19 00:00:45,410 --> 00:00:47,760 So if you want to compare resources in two different 20 00:00:47,760 --> 00:00:50,675 projects you can actually just compare the res folder 21 00:00:50,675 --> 00:00:53,130 and everything will work fine. 22 00:00:53,130 --> 00:00:55,900 Now I've made a copy of this project earlier 23 00:00:55,900 --> 00:00:59,630 so I'm going to click on the res folder here 24 00:00:59,630 --> 00:01:01,130 and then I'm going to use compare with 25 00:01:01,130 --> 00:01:02,143 from the view menu. 26 00:01:06,090 --> 00:01:08,220 So this time we get something different. 27 00:01:08,220 --> 00:01:09,750 It's a directory picker rather than 28 00:01:09,750 --> 00:01:10,950 the file picker 29 00:01:10,950 --> 00:01:12,800 so I can never get to the res folder from 30 00:01:12,800 --> 00:01:13,633 the other project. 31 00:01:13,633 --> 00:01:14,466 So I'm going to go ahead 32 00:01:14,466 --> 00:01:15,299 and do that. 33 00:01:16,784 --> 00:01:19,150 And I've got this on my desktop 34 00:01:19,150 --> 00:01:20,787 and the calculator app, 35 00:01:20,787 --> 00:01:23,770 source, main, 36 00:01:23,770 --> 00:01:24,633 and res. 37 00:01:25,840 --> 00:01:27,410 And now that I've selected that directory 38 00:01:27,410 --> 00:01:28,360 I can click on open 39 00:01:30,030 --> 00:01:32,460 so we can see that the Android Studio diff tool 40 00:01:32,460 --> 00:01:34,490 displays the directory structure at the top 41 00:01:34,490 --> 00:01:36,700 of the screen for both on the left hand side 42 00:01:36,700 --> 00:01:37,979 and the right hand side 43 00:01:37,979 --> 00:01:40,420 and the two same panes comparing the 44 00:01:40,420 --> 00:01:43,660 currently-selected file in the bottom pane. 45 00:01:43,660 --> 00:01:45,830 Now you may just get a message 46 00:01:45,830 --> 00:01:48,203 or a screen that I've got saying nothing to show 47 00:01:48,203 --> 00:01:50,559 because the diff tools only showing differences 48 00:01:50,559 --> 00:01:53,520 so if that happens both directories are the same 49 00:01:53,520 --> 00:01:55,070 as mine is here because 50 00:01:55,070 --> 00:01:57,147 I've taken a copy of the project as it existed 51 00:01:57,147 --> 00:01:59,220 at the end of the last video. 52 00:01:59,220 --> 00:02:01,027 Now you can show all the files if you want to 53 00:02:01,027 --> 00:02:04,140 by clicking on the equals button up here 54 00:02:05,641 --> 00:02:07,500 and you can see that that's popped up. 55 00:02:07,500 --> 00:02:09,210 That will show files that are the same 56 00:02:09,210 --> 00:02:11,250 as well as ones that are different. 57 00:02:11,250 --> 00:02:13,923 Now it doesn't bother displaying empty directories 58 00:02:13,923 --> 00:02:16,590 so there's not really much else to see here 59 00:02:16,590 --> 00:02:19,240 but if the projects contained other resources 60 00:02:19,240 --> 00:02:22,290 that'd be available for comparing as well. 61 00:02:22,290 --> 00:02:24,800 And once again it can be a good idea to use the 62 00:02:24,800 --> 00:02:27,848 comp menu in the lower pane down here 63 00:02:27,848 --> 00:02:30,770 to turn off code inspections in the highlighting 64 00:02:30,770 --> 00:02:31,969 level menu. 65 00:02:31,969 --> 00:02:34,470 Choosing syntax instead. 66 00:02:34,470 --> 00:02:36,400 Just makes it a bit easier 67 00:02:36,400 --> 00:02:38,430 and turns off all the red. 68 00:02:38,430 --> 00:02:39,400 Alright so I'm going to close this 69 00:02:39,400 --> 00:02:41,003 to get back to Android Studio. 70 00:02:42,100 --> 00:02:42,933 And then I'm going to try 71 00:02:42,933 --> 00:02:43,766 and do the same thing 72 00:02:43,766 --> 00:02:46,210 but this time for the Java folder up here. 73 00:02:46,210 --> 00:02:47,750 Java directory. 74 00:02:47,750 --> 00:02:50,401 Now when I click on view you can see there's now 75 00:02:50,401 --> 00:02:52,720 no compare to option. 76 00:02:52,720 --> 00:02:54,680 Now it's tempting to try comparing the app 77 00:02:54,680 --> 00:02:57,007 directory instead so going up one level here 78 00:02:57,007 --> 00:02:59,300 and then if you go up to view, 79 00:02:59,300 --> 00:03:01,508 compare with has got an option to do that 80 00:03:01,508 --> 00:03:04,530 but I definitely advise against it. 81 00:03:04,530 --> 00:03:06,110 The reason is there are a lot of files 82 00:03:06,110 --> 00:03:07,230 in the build directories, 83 00:03:07,230 --> 00:03:08,830 over 2,000 actually, 84 00:03:08,830 --> 00:03:11,160 and we're not interesting in comparing any of them 85 00:03:11,160 --> 00:03:13,730 so we just end up with a very confusing display. 86 00:03:13,730 --> 00:03:15,843 Instead I suggest you actually compare 87 00:03:15,843 --> 00:03:18,160 at packaged levels. 88 00:03:18,160 --> 00:03:22,450 So in this case the academy.learnprogramming.calculator 89 00:03:22,450 --> 00:03:23,490 now that's a bit boring 90 00:03:23,490 --> 00:03:24,610 but we'll do it anyways. 91 00:03:24,610 --> 00:03:25,477 So we'll click on that 92 00:03:25,477 --> 00:03:28,307 and click on view, compare with, 93 00:03:28,307 --> 00:03:32,000 and go to the same level project in the 94 00:03:32,000 --> 00:03:34,600 copy that I've expanded on my computer. 95 00:03:34,600 --> 00:03:39,600 So calculate, then it'll be app, source, 96 00:03:40,350 --> 00:03:42,400 main, Java, 97 00:03:42,400 --> 00:03:44,085 and I'm going to do academy. 98 00:03:44,085 --> 00:03:46,900 I'm basically at that level. 99 00:03:46,900 --> 00:03:49,748 If you're wondering which part that I'm actually testing 100 00:03:49,748 --> 00:03:51,750 you can always see that from the path that you're 101 00:03:51,750 --> 00:03:52,583 actually in. 102 00:03:52,583 --> 00:03:54,070 So I'm going to go to learn programming, 103 00:03:54,070 --> 00:03:55,940 and to calculator. 104 00:03:55,940 --> 00:03:56,773 Click on open 105 00:03:58,140 --> 00:03:59,880 and then I can click on equals if I want 106 00:03:59,880 --> 00:04:01,357 to see all the files whether they're same 107 00:04:01,357 --> 00:04:02,880 or different. 108 00:04:02,880 --> 00:04:04,600 In this particular case it's a bit boring 109 00:04:04,600 --> 00:04:06,850 because you've only go the one file. 110 00:04:06,850 --> 00:04:08,110 But that would be a good way of doing it. 111 00:04:08,110 --> 00:04:10,444 But instead what I'll do is I'll close this down 112 00:04:10,444 --> 00:04:14,290 and I'm going to go into project view up here. 113 00:04:14,290 --> 00:04:15,460 Select project, 114 00:04:15,460 --> 00:04:17,690 and I'm actually going to do a comparison 115 00:04:17,690 --> 00:04:19,250 from the app source main instead. 116 00:04:19,250 --> 00:04:21,630 So I'm going to open the app, source, 117 00:04:21,630 --> 00:04:22,463 and then main. 118 00:04:23,632 --> 00:04:25,780 I'm going to select that, view, compare with, 119 00:04:25,780 --> 00:04:28,323 and I'm going to go to my other version 120 00:04:28,323 --> 00:04:30,190 and select main as well 121 00:04:30,190 --> 00:04:32,520 so we're basically at the same level. 122 00:04:32,520 --> 00:04:33,353 Click on open. 123 00:04:34,660 --> 00:04:36,290 And you can see we're at app source main, 124 00:04:36,290 --> 00:04:38,159 app source main, 125 00:04:38,159 --> 00:04:41,220 and I can see the various files there if I wanted to. 126 00:04:41,220 --> 00:04:43,244 No whenever directories match here the diff tool 127 00:04:43,244 --> 00:04:45,737 will show the files side-by-side. 128 00:04:45,737 --> 00:04:47,740 And you can click the file that you're interested in 129 00:04:47,740 --> 00:04:49,690 to see it compare to the corresponding 130 00:04:50,726 --> 00:04:52,166 file from the other project. 131 00:04:52,166 --> 00:04:52,999 So I can actually just come over here 132 00:04:52,999 --> 00:04:54,590 and select a file 133 00:04:54,590 --> 00:04:55,930 and you can see that the other files actually 134 00:04:55,930 --> 00:04:56,940 come up there. 135 00:04:56,940 --> 00:04:59,790 Activity underscore main, scrolling down 136 00:04:59,790 --> 00:05:01,120 a bit further. 137 00:05:01,120 --> 00:05:03,150 IC launcher, you can see as I'm doing that, 138 00:05:03,150 --> 00:05:05,330 the other side is automatically being opened 139 00:05:05,330 --> 00:05:08,260 and we can compare the contents in both sides. 140 00:05:08,260 --> 00:05:10,720 Now this works fine if the company domain 141 00:05:10,720 --> 00:05:12,660 was the same for both projects 142 00:05:12,660 --> 00:05:15,010 but often that may not be the case though 143 00:05:15,010 --> 00:05:17,360 and it can actually cause problems. 144 00:05:17,360 --> 00:05:18,636 The resources will still match, 145 00:05:18,636 --> 00:05:21,230 that's because they both live in their slash main 146 00:05:21,230 --> 00:05:23,548 slash res directory of source. 147 00:05:23,548 --> 00:05:27,570 But the package name is used for the directory structure 148 00:05:27,570 --> 00:05:30,200 and the package name comes from the company domain 149 00:05:30,200 --> 00:05:32,580 that we used when we created the project. 150 00:05:32,580 --> 00:05:34,200 So in this particular example 151 00:05:34,200 --> 00:05:36,280 our main activity code file is 152 00:05:36,280 --> 00:05:37,290 in the directory 153 00:05:37,290 --> 00:05:42,290 main.java.academy.learnprogramming.calculator 154 00:05:42,300 --> 00:05:43,860 and you can see that when a new directory is 155 00:05:43,860 --> 00:05:45,790 been created for each part of the packaging name. 156 00:05:45,790 --> 00:05:48,500 And we can see that a new package name 157 00:05:48,500 --> 00:05:50,820 has been created for each. 158 00:05:50,820 --> 00:05:51,653 So if you come back here 159 00:05:51,653 --> 00:05:53,310 and actually have a look, 160 00:05:53,310 --> 00:05:58,310 main, Java, you can see up here 161 00:05:58,420 --> 00:05:59,380 we've got source main 162 00:05:59,380 --> 00:06:02,380 Java academy learn programming calculator. 163 00:06:02,380 --> 00:06:05,318 Now if I have a project named org.example.calcualtor 164 00:06:05,318 --> 00:06:08,030 then obviously the directories won't match 165 00:06:08,030 --> 00:06:09,560 and therefore I won't be able to compare the 166 00:06:09,560 --> 00:06:11,059 Java source files. 167 00:06:11,059 --> 00:06:13,530 So the solution to that in that case 168 00:06:13,530 --> 00:06:15,192 is to chose the package directory 169 00:06:15,192 --> 00:06:17,093 when starting the comparison. 170 00:06:18,200 --> 00:06:19,530 So to show you what I mean I'm going to 171 00:06:19,530 --> 00:06:22,290 compare the source code from this project 172 00:06:22,290 --> 00:06:24,190 with the source from the YouTube app 173 00:06:24,190 --> 00:06:26,610 from the previous version of this course. 174 00:06:26,610 --> 00:06:27,930 So I'm in Android Studio 175 00:06:27,930 --> 00:06:30,388 and I'm going to go back into Android view. 176 00:06:30,388 --> 00:06:34,230 And I'm going to expand main Java 177 00:06:34,230 --> 00:06:36,490 so I've got, you can see there that I've got 178 00:06:36,490 --> 00:06:38,300 the Java package open. 179 00:06:38,300 --> 00:06:39,960 Basically So that I can see the package name 180 00:06:39,960 --> 00:06:41,000 in this case 181 00:06:41,000 --> 00:06:43,617 academy.learnprogramming.calculator 182 00:06:43,617 --> 00:06:45,490 then I'm going to use control D to 183 00:06:45,490 --> 00:06:47,640 get the directory to choose a dialogue 184 00:06:47,640 --> 00:06:50,613 and navigate to the YouTube directory. 185 00:06:51,505 --> 00:06:52,400 And when I say basically set, 186 00:06:52,400 --> 00:06:53,987 I need to click on that so 187 00:06:53,987 --> 00:06:56,800 that's the folder that I'm actually comparing. 188 00:06:56,800 --> 00:06:58,400 Then I'm going to do my control D 189 00:06:58,400 --> 00:06:59,830 or command D on a Mac. 190 00:06:59,830 --> 00:07:01,770 That's going to open up the dialogue, 191 00:07:01,770 --> 00:07:03,030 the directory picker 192 00:07:03,030 --> 00:07:05,690 and I'm going to navigate to the YouTube directory 193 00:07:05,690 --> 00:07:06,939 of the other project. 194 00:07:06,939 --> 00:07:09,540 So I'm going to go back to that file 195 00:07:09,540 --> 00:07:11,200 the other application, 196 00:07:11,200 --> 00:07:12,430 the other project, 197 00:07:12,430 --> 00:07:17,430 we go to app, source, main, Java, com, 198 00:07:17,603 --> 00:07:19,920 noticing the package is different here, 199 00:07:19,920 --> 00:07:21,750 Tim Buchalka, YouTube Play. 200 00:07:21,750 --> 00:07:23,770 So that's the equivalent level. 201 00:07:23,770 --> 00:07:25,320 Now I'm going to click on open. 202 00:07:26,956 --> 00:07:29,999 Now this is not a very sensible thing to do 203 00:07:29,999 --> 00:07:32,401 because they're completely different projects 204 00:07:32,401 --> 00:07:35,290 but it does show how you can match the source code files 205 00:07:35,290 --> 00:07:36,215 from one project 206 00:07:36,215 --> 00:07:38,050 with those form another. 207 00:07:38,050 --> 00:07:39,830 So that's how to compare your source files 208 00:07:39,830 --> 00:07:41,790 against the source code from the videos 209 00:07:41,790 --> 00:07:44,590 all of which is available from the resources 210 00:07:44,590 --> 00:07:45,940 for each video. 211 00:07:45,940 --> 00:07:47,460 It is pretty straightforward, 212 00:07:47,460 --> 00:07:49,660 particularly once you've done it a few times 213 00:07:49,660 --> 00:07:51,671 and it's really only slightly more complicated 214 00:07:51,671 --> 00:07:54,488 if you're using a different company domain name 215 00:07:54,488 --> 00:07:56,380 to the one that I've used when you're 216 00:07:56,380 --> 00:07:58,000 creating my version of the project. 217 00:07:58,000 --> 00:08:01,060 And if you get problems with your layouts or code 218 00:08:01,060 --> 00:08:02,821 and can't work out what the differences are 219 00:08:02,821 --> 00:08:05,340 this diff tool can actually save a lot of time 220 00:08:05,340 --> 00:08:06,660 and frustration. 221 00:08:06,660 --> 00:08:08,050 Now the last thing that I'll mention is 222 00:08:08,050 --> 00:08:10,399 that the control D or command D shortcut 223 00:08:10,399 --> 00:08:12,910 only works if you've clicked on something in the 224 00:08:12,910 --> 00:08:14,010 project pane. 225 00:08:14,010 --> 00:08:15,680 Now if you're editing a file, 226 00:08:15,680 --> 00:08:18,120 control D will duplicate the current line of code 227 00:08:18,120 --> 00:08:19,570 so watch out for that. 228 00:08:19,570 --> 00:08:21,380 Alright so let's finish the video here. 229 00:08:21,380 --> 00:08:23,290 In the next video we're going to create the code 230 00:08:23,290 --> 00:08:25,150 to make our calculator work. 231 00:08:25,150 --> 00:08:26,900 So we'll see you in the next video.