Okay, Good morning. Let's get started.
Um, so first off, We are at A.
Okay, so we'll talk about. Yes, and I will get to your question in a little bit.
So we're sitting here at lecture 16.
So we have, we have this week one week, two weeks.
We have four weeks left.
So, of classes in that time. So without tutorial eight has come out now, there are two more tutorials and Simon three has come out and there's one last assignment.
So assignment for, we're kind of up against a pretty hard deadline with that. In terms of.
Can you see the.
My drop down menu, my drop down calendar, does that show in the split screen share. Okay, so.
So right now the due date for the assignment for is the eighth of April, and that's the last day of classes. So I really, and then the exam is, um, is on the 14th.
So I really need to present the solutions for assignment for here on April 8, so I will get you assignment, last the last assignment out by the 23rd which is what assignment three is do I can give you a bit of extra time for turning the assignment three.
We can discuss that, but really make sure you know this assignment three an assignment for so make sure to keep on top of things.
But, uh, but yeah so today I want to. So first I want to talk about assignment three and then we'll talk about tutorial eight. So and hold on to your question.
Assignment three here.
There's, you know the validator page as before.
There's the template as before.
And there's the code so tech This is the last text analyzer will give you.
Well, unless it shows up in the final haven't decided but, uh, but yeah that so.
So, this, this is basically the other Android one with all the stuff from the tutorial that you're supposed to implement implemented here. So it's, you know, so there's, you know, now we have with a few little, you know, we've got the, you know, lifecycle
events, we've got, you know all the analysis functions.
Knows are in line because Caitlyn is stupid about in line, you know, so anonymous functions and maps as far as I can tell, don't mix well, I haven't gotten it to successfully work, I can do anonymous functions I can do maps, but doing them both together
just, it's probably some syntactic trick if anyone wants to play with it and show me how to do it I'll be great was like Wow, That's really annoying.
And this also saves the instant state so when you rotate it, you know, save the state so.
So it has all the bells and whistles there but now I want you to basic going, going a little more depth with this So comparing some syntax stuff, but most of this is, you know, but these are all little changes I want you to, mainly make to this, and asking
how your stuff works. So again, make sure this is designed to help you make sure you really understand this code at this point you should understand it but if you don't, this may be a bit hard.
So if you look through the assignment if you have questions I'm happy to answer them.
But I wasn't planning on going through this I kind of see this stuff is basically done.
I'm
new stuff, however, tutorial eight.
So let me. So, oh by the way when you run text analyzer six. You'll notice that, it'll say please choose it analysis mode knows how much the left.
And you know, You're gonna be changing messing with this layout.
Let me close this and let's begin.
So here is
you.
Okay, how I messed up my simulator that we sat. Oh, there we go. Okay.
Let's see if I can get that running.
But the idea of this one is we've been talking about.
So this is supposed to be the same as the drag demo from.
Let's go back here.
Track demo is from.
This is drag demo today. So here's drag demo to remember it wasn't very long, but this had a box, and a circle and you had to drag the circle to the box and then it said yes to success.
Same thing. But that an Android.
cc drag the circle into the box. We at works, straightforward. Right.
Not so straightforward. I finally figured out my geometry pain that without having to weird constants that took me way longer than I wanted to, but let me walk you through this year.
So,
what we is yes and now it's this is just one thing here will show you here.
So this was divided, remember this is the old one that knows a movable circle success message and we just couldn't quite combine all this here, code here is a bit messier.
So, first off we have our circle and square resources, or we maybe I sweat which is an you know an oval and a rectangle. So we make these shapes that we instantiate them.
In our view, we have our status message, which is sitting in the middle of the screen because it's at the bottom top no start an end of the parents so that puts it right in the center of the screen.
And then we have a circle, you know, a circle and a square. And these both have you know this is 100 by 100 display pixels. This is 150 by 150. Oh by the way, one reason you use dp in Android is the display pixels is basically a unit of measurement.
And then we've given a bit of margin to the
table here the market is top and start so it's the upper left. And this one's in the bottom right so it's bottom finance was not all squished Oh with the corner of the bottom writers which in the corner top left, we make our squares.
And we referenced the global resources here this squared circle so we've, we've talked about this before, but then we get to the main code.
And the main code here.
This part is just, you know, call this call the on create instance we sit you know set the content views we reverse the layout. We have our,
you know, we find the five view ID here for the red circle.
We assign a touch listener track circle onto the red circle so when you touch the circle it does something, and we update the status one so we have all these initialized.
And we've assigned to listener. So the on touch listeners, the one that does all the work.
And what it does is just know it overrides the odd touch function checks to see that we actually gotten event and we have a valid view, so we don't have to worry about these silly question marks anymore.
And the rest of this function. And then we get the action and the raw x and y coordinates of the event.
And then we have to. So now this is where
things get annoying.
Before that, otherwise a question about it says make the square outline green Do you mean out a green border around the blue.
What I mean for this question is, You notice this square is.
This is a blue border square and this is a red circle, you know, red solid circle, red, make both of those green.
That's all it means that that's what I mean for it.
So just just just make whatever is blue here, green and make the circle green because you're going instead make a red square in the center, which we will discuss in a second.
So, but, going back to the code where was I okay so going through here. So we have this.
So, going back here What did we have to do in order to set this up what what would we track it. So the movable circle was all we did to have the circle move.
It was ridiculously simple we said we do a circle we filled with color blue. We made it size, and then we said, If
you know if the position of x is less than zero, Then we do the start location always locations so start location is this.
We're starting
here start your start location here. Start location is passed in from here based on the geometry or so, we have the center of the screen.
What else on the screen but it was just width and height we kind of got it down to the bottom.
We all were this year and then we.
But then all we did to move the circle, was when, When the gesture change, we just set the location of the circle.
You know the self location is here, we just said that to be whatever the location was of the track. So it completely. It was exactly mirror. Now notice what that means is that the coordinate that's past in is the center of it is where the personal touched.
And this location here The location is the location of the circle, the coordinates of it is the center of the circle.
So.
So, in the location of us it's topical is it center, and an Android The location is this top left corner.
Now you might go like, Well, you know, why is the center a good idea because oh look at the code. This is all like clean.
And then we go over here.
And it's this mass is horrible mess.
It's horrible mess. Also, I'm also what I'm praying locations I didn't have to coordinate translation, I didn't have to figure out where it is relative the screen are the things that just that just worked.
Maybe just a more complicated you might do something but things are a little more saying here.
I had to do some nastiness. So specifically what I had to do is, so if you use x and y, there is an event x and event wide which is the location in the view, but that gets messed up the moment your drag is outside the circle.
So, as far as I can tell, this raw x rah rah, rah why corresponds more to
what is used in Swift UI is a coordinates, but we have.
So you have these coordinates here x and y, that's the raw x and y as opposed to translate the view which this thing happened. And then we have to do some translation of the circle.
So we have to do is first find the screen local circle screen locations that right so circle get location on screen.
So this, so we get the location on screen so where is the circle on the screen.
And then there is this x and y which is the circles.
You know, position for us wanting to move it around on, you know, when we.
This position is within the enclosing view, which is in this case, is this window here that's below the title bar and below this little menu thing, you know, little status bar and the title bar for the application.
We're getting coordinates in this area, which isn't the same as that.
So we have to correct it.
So what we do. So our correction is specifically, we get the location on the screen, we figure out the offset between the screen location of the circle, and the one in our regular coordinates.
So we set that up as an offset now, in principle, this should be constant.
So we could set this somewhere else, but you can't set it here in on create, because if you do the positions are all zero because they're not an actually been drawn on the screen yet.
And there's some way to initialize later.
But it's just painful let's just calculated here. not like this is going to take many cycles.
So we count, so I calculate the offset each time to figure out where it is. And then, if the action was a move now we need to update the position of the circle.
So we see red circle x and y is equal to x and y these raw events, but with this little offset so first we have to adjust for the difference between screen location, and these coordinates with do a little bit of coordinate transformation there, and we
have to offset it to the center of the circle.
Because we of course are sitting there doing the top left.
So it was this was me, it's not too messy here.
But it's annoying. And I have do the same thing for the square, to find out where the center of the, you know, to get the coordinates of the center of the square.
so here you know again screen locate you know get to allocate this interest first that I got a call get location on screen which fills in that interview with to coordinates, and the x value I know basically calculate the center of the square with this
center, you know x&y with these two values. And then I can do the same calculation.
I did before, as I did in Swift you on it.
You're dating.
I don't know what do you all think of this does this, this, it blew my mind how hard it was for me to figure this out.
And it's not like clearly document was like me most the time it seems like people to sort. Well, I think what happens most the time and Android is your normally implementing drag and drop yourself.
There are standard
things for implementing drag and drop and so like if you move an object to another place and dragging me all the listeners and stuff there's all this complicated but it's like, I just want to move something on the screen following your finger.
But it costs to introduce with your headset.
Yeah, I hear you. But, sorry, the next course is all Android so gotta get you up on this sort of stuff but this just gives you an idea like it's like there's nothing, ostensibly wrong with what Andrew Android does, there's nothing wrong.
But little decisions have interesting implications, such as the location of, you know, when you put something the location of what's the x&y, what is x and y.
For a view
in Swift, right, it's the center.
Here is the top left, top left makes sense from an implementation standpoint because you know top left there and then you get the width and height and stuff like that but what are you going to do when you move it around.
You're going to be, you have to almost always like it where is it going to be centers and all of a sudden you have to do these translations.
Would you will extract away, there's lots of ways to make helper function is but it just is annoying.
So, just in the future, at some point, you find yourself designing API's.
Right, non trivial code using your API's and see what it looks like.
If you can do something that makes the other people's code cleaner that makes us a library or framework designers network job a little messier.
Make your code Messier still their code is cleaner,
because that's all these calculations have to be done at some by someone. The differences in Swift UI, the swift UI framework takes care of it. They did all these transformations for you.
Here, we have to do it.
But otherwise, this is.
No, this works.
So what I'm looking for you to do in this tutorial is
check you know how does this, you know, so I have some question how this could turn the center of the square you know has buried it to all three so how, what is the difference between how the circle and square draw on the screen.
So just like how did we get a circle versus how do we get a square while our circle move what happens. So, these are all things you should understand.
And then change the initials text to say welcome the action so the virtual New START starting the circle. Remove the towel bar saying drag them with three, move the status text the left top just exported via via sees.
So, make the circle and the square outline green. So adding a color.
Because, make a new square in the center that is solid red color let's, let's make sure it's positioned in specified in coordinates, one through five here.
If you, if you have the understanding of what's going on here, shouldn't be hard.
Six.
That's going to be a little bit of work.
That's basically worth all the points here and this is a little programming exercise and look at it.
So, what this, what this is saying is I want you to make. So both of these will be green.
The version, your house, and you're going to have a red square right in the center here, and the status bar would have been moved up to the top.
So you're going to have this red square here and so now if you just drag it here. That way if you just do a drag.
You just do a dragon.
Why are you not tracking. There we go. So we just do a drag here like this, it'll work the same as before.
But if you drag here and let go.
Now the ball should be trapped in the square that will be here, and you try dragging, it'll be stuck here, even if you move it outside of their ongoing boo boo boo boo.
It was bounce off the sides.
And it will leave you start the out.
So that's.
So you have to create a boundary. So what, so what you're having to do is, you're creating a boundary based on the coordinates of the square, exactly, you're making your square and then you're making the circle so that it can't get out.
So that means that you have to change the drive so that normally you're updating this coordinates here, you're going to have to do further calculations like, Oh, I'm trapped, so I probably have a flag of some kind of thing, and my trapped or not.
And if I am trapped, then drives will be cut off here I'll have to clip the, the movement to the edge of the circle, the square. But if it's not trapped then you do the normal falling and let it go here.
So, you're going to get to have fun with coordinates.
And you might want to refactor this code some make some separate functions or something because, yeah.
So I'll be interested to see, I don't think it'll be that hard but it should take you a little bit of work, and
should be trapped in the inner edge of the outer edge or any of these.
I think what I said was is so it's solid red. So, you're going to want to make it so that no part of the circle should get outside of the solid red square.
So it should be firmly trapped inside so the edge.
Edge should be going in there and knock it out so the rest of these tasks, should not be hard at all.
This one will take you a bit of time to implement shouldn't be too bad, but it's a little puzzle.
And if you can do this, then you should be understanding how these coordinates work.
Any other questions
about this.
Oh.
So what make sure there's new squares in the Sarah's. So what I, what I mean by five it position, especially in quizzing coordinates, is I don't want to notice the position of the Circle in the Square is not hard coded.
Here at all.
What you want to do is use the same trick to position the new square, as this, as the status bar was put in the center.
Yeah, so I don't want hard code. I don't want any hard coded coordinates, I should not see this and go like it because again those hardcore coordinates.
If you flip the orientation of the device, or you write on a different device, it will work right.
So that's why I'm saying don't it shouldn't be biasing so I will tell you when you're working in Android here, when you're doing the layout work in the code review or work in the split view.
So you can see your you know changes as you do them, don't work in the pure design view.
That's not going to get you far
yeah just yeah just use alignment. Exactly.
You basically you should just be able to do it all with the constrained start top all the things that are in here right now.
Um,
if there are any other questions I can move on to some other material.
They haven't talked about intense, which is why I want to start talking about next week, we're getting at the winning in a funny part of the semester where like, I can start getting more and more advanced things putting it put in, but I've got it like
I want to make sure I'm not losing you all with the material.
But there's a few more things I want to show you my Android.
So one thing we have not talked about, notice one cute cute thing here is it does this little thing in the wardrobe is a circle. This is a square
actually showing you what you're producing by the shape.
But there's a whole lot of files here to the causal Yeah, we've got know that well this, this stuff is all for testing.
Yeah, so now you know here, this is you know shows you what's an activity. These are for these two are for holding directories for implementing tests.
Testing is something that is much more covered in the classes like 3000 for software engineering, that's beyond the scope of what I'm going to talk about.
That's what I would say have that much expertise in this. this again it's just a generated thing, I wouldn't worry about that.
These generated ones.
This is all part of the build process that generates lots of intermediate files.
Mostly, building more those draw well here's where we put the circle, It's where.
Notice this launcher background launcher foreground.
Where's the icon for your when you, when you put it into this into the, let's see. Can I do this year.
So you see these icons here are little Android head and this background.
That's, this is where they are. This is the background is the foreground and it gets maps to a circle by the
by the Android framework so if you wanted to change these your car these done you notice it's just, it's actually an XML file.
That's what's making this grid.
And the same thing with this, you know, it's just there so.
So if you want to make a new icon. Go ahead.
I'm layout, that's our main layout, if you want to have different activities.
But here we're taught that values is where we have things like colors and strings so if you want to internationalize your code.
This is where it is.
I could really use this more in my code like the same right so you can have all the strings here the idea is that the change languages use changes filing you're changing you know the part of your coaches unnamed resources for everything.
colors here the main colors.
And then we have our themes.
You know, for, for night.
And they have slightly different colors. You can customize a theme here remember if we want to move the app bar from it. We had a couple of lines here to turn that off.
Why is our premier good.
So, so we have these, so this is where we set up the themes he knows the themes. These are used by the Android widgets, they will choose to draw things in these certain colors.
So these you know these are named color private coverage variants so if you change these it changes the theme.
Oh that's nice, other colors also here.
I'm get resources go about that.
But there's one part that we've definitely been avoiding, which is this is actually pretty important.
This is the Android manifest.
So this, this is what tells it how to run it.
And so there's. Well, first of all, you know, isn't XML, it's our general declaration. We have a method you know we're saying this thing manifests, so that's that's here.
And then we're telling the namespace. It's another, it's an Android manifest so we give this HTTP URL, which doesn't exist on the web. Currently, but a funny name of the package.
So this is what's defined when you change your app you notice you have at the top of.
Where is my.
I have too many.
So if you go to activity main here, you notice how it says,
you know it doesn't say it here, it says this is separate. it says it in.
We go to main activity, we have a thing saying package. So by basically by defining packages we're defining name spaces which are places where you have can access, you have the names you're like okay these are the names everything but particularly separate
packages.
If you want to be able to have, like, if I want to have different versions of on create.
I really know, you know, what not was on creates part of main active. If I want to have separate main activities. So I can only have one main activity in a given package.
Because packages are one set of names, but if you have separate packages, they could all have, you know, each separate package could each have their own main activity.
So that's this package declaration is very important. It is set up by the manifest. This is what saying, okay, everything we're doing here is in this package.
This was a manifest for this application so then in the application we now define we defined an application here and notice in an application.
This is an app, the thing chorus minus on you click on here, it saying, you know, things that Android cares about like, Are you allowed to backup this app.
What's its icon.
You know, just be good.
Right.
goto.
I think. So these are the icons, as I recall.
These I think are generated automatically by the build thing, using the IC launcher background IC launcher foreground, but I haven't played with it so much.
But I'm pretty sure these are all automatically generated from combining these two but I haven't.
I'd have to check that.
Oh, but going back to the manifest. So manifest as a reference. It's, it's not so much all the code, it's more the guide to what the system needs so so here it says, you know, here's the icon, you know, IC launcher.
Here's it no rap if you want to round icon here it is, rapping Oh, IC launcher around
a look up MIT map out later.
I'll get back get back to you on that.
Of course, here's the labels that's name that's gonna be under these things so see this is all telling us how do we set up things in the launcher.
Then we say what theme we're going to use with a theme, you know, drag demos, you know, Greg demo three. That's the style. I think that's defined here, right here theme drag demo three.
If you do this one.
Both these themes have the same have the same name. So, it can show the framework and choose whether you're in dark or light mode.
But,
and then we have this.
We have an activity.
So you can have multiple activities in Android up by default you have to have at least one, because that's the thing that's going to get run.
And in this activity. This activity is named main activity. This is in that dock main activity is a direct reference to the class
to this class here, you know, we say class main activity.
That's what this is referencing.
Is there a functional purpose for having multiple activities. Definitely, um basically if your app can incorporate different functionality. You can think of is different modes, or different things like you can think of one, you know, an app that allows
for what the big reason you want to use different activities, is because you're going to be called in different ways.
So when we define this activity we give it a name, and that's and that's you know basically specifying the code of the class that's going to be defined by this under an export it.
True. So what this means is, other apps and Android can call this activity. They can be externally invoked as opposed to an internal activity, which you might want to just divide your application up into different parts and just have them call each other
and be separate.
You say for different screens or different, you know, modules and whatever.
Could you have separate functionality if you rotate the screen. I'm definitely. Um, but you would have to you then probably
you can launch different activities where when you rotate the screen, but I don't think
I'll explain what this.
You could well you certainly can detect it and have and watch different things when that happens. But the real trick here is this thing called intense.
So.
so there's a special thing so intense really are away from messages to be sent between apps, or even within the same app.
It's an entirely separate thing from classic Unix mechanisms. In fact has its own kernel level mechanism for making this happen, it's actually very
actually very efficient because it does some tricks with, you know, shared memory and stuff is designed for high volume things and in fact under the hood Android is firing off intense between inside of apps, all the time.
There are.
This is a huge thing, but it's also used for very basic things like here.
This is saying, so you have an intent.
So this intent filter is telling that same, we are willing to take
these kind of intense. This is what we're willing so. So,
this is saying that we are willing to respond to be action. Run basically main, which is in the category of this launcher thing so. So what this this is all defined in the Android framework is saying that when you click on an app, you're basically saying,
I want to do the main thing, you know, and I want to, you know, I want to do the main activity and this is something that launch, this is something that launchers do so.
So it allows it to run. It's made out, and you know I didn't tell it to run, you know, the main activity so.
What's up y'all to have that much time.
So next class will start going over intense and I'll show you the.
I have some cover like for example when you run. If I want to go here, so whenever I click on an activity here. I, I'm running an app. And I'm actually doing is sending a Nintendo I'm telling the launcher app to send you know, I basically do the launcher
main activity.
And these apps are set to receive it, if they aren't set to receive it, you wouldn't be able to start it, but there's other ways of getting one app to start another.
Whenever you just change these default apps or something what you're really doing is changing how intense are set.
That's the level at which you're doing its thing. Okay one app.
Oh.
intense or an Android specific thing, iOS has other mechanisms.
And they're much more.
The intent mechanisms the break general mechanism for IPC, because Android apps are designed to really talk to each other, and the structure for apps is really that an app can be a collection of functionality and really you're going to have this little
function I have this one app called this app functionality and this app and they can all talk to each other, these things incorporate keyboards and stuff it's, it's a very nice composition oriented software engineering strategy iOS is not designed that
way instead of having these very general mechanisms and much more specific mechanisms, I want to open a URL double bind API to a URL.
Because you're not supposed to have.
Notice that an iOS apps are really separate entities, you can't really just change it and when you want to do it, you're really doing it as provided by the operating system in very specific ways.
In practice, and Android with the permission mechanism, which is, is a general mechanism but of course you use it in very specific ways and iOS you just use the API for that specific thing.
And that's why it's much more limited I mean you can do much more general things up.
on iOS and Android. There are no jails.
There's nothing like really elaborate sense of permissions of who can send which messages do on iOS, it's like you're just separate.
If you need to talk to each other you go through me.
And I will tell you the things you can send to each other messages, the requests, you can make in Android is like, oh here's this general thing will find all these different ways you can talk to each other and you know.
And that's how you can replace system components in Android. You know it's become harder and harder nowadays because they've walked down the permissions, because people started abusing it but traditionally an Android you could replace almost any component
of the operating system to do anything, and as because they expose this is all built in the spring general mechanism.
How about in Windows.
On Windows there's, there's no.
So.
that's really what it is is your Windows, Mac OS, there's general communication between apps
iOS has communicate for a specific purpose of Android. It's very general but there's an elaborate permission maximum decide who can do what Windows, Mac OS may look into it anything.
Mostly.
So it's an
intense or a cool mechanism.
It leads to a lot of
this there's some nice things that has, but in practice has become more and more locked down in order to improve security of Android, making the flexibility of intensive they originally were envision much less Apple a modern Android devices.
Anyway, I think I've covered enough stuff I would like to check off people for their tutorials and answer specific questions. And on Friday we will start playing with intense.
Well, so the last questions.