Hello this is mortiser Cordy.
And in this story are you going to implement this on parchment and inside this floating.
You said riskless.
So let's go inside this method here.
First of all I'm going to paste some valuables and you can see that these are the variables that I pasted
here.
The first one is of type integer.
The name of this but is start ex-POWs.
So you can see that I'm not initializing these variables here.
Just declaring these variables here.
And we have this fun in the start of why pose pose means position.
OK.
The float here.
Start touch x float start.
Touch y.
So now let's see how we are going to initialize these variables.
So let's start with this start X-posts.
We can actually either initialize it here in line one hundred and fifty five or we can actually initialize
it after we declared are valuable.
So I can say start's x post assignment operator.
And here I just need to refer to the parameters of the window manager but there is a problem here.
The parameters of the window manager is actually created inside the uncreate Meffert and we cannot access
those parameters from the untouched method.
So if I scroll to the top here we can see that we actually created these parameters of the window manager
here inside this and create it.
So in order to solve this problem we need to declare this valuable inside our class.
So here inside this class I'm going to say private and his name is going to be its type is going to
be window manager that lay out Putnam's.
This is just the type and the name.
Let's change the name.
Name it as window manager or w the palms acase semicolon.
So now let's delete this value here inside and create it.
And instead let's just refer to W.T. problems.
Now we can access these parameters from our attachment.
So here we have a problem.
We need to change these parameters to W.T. perhaps or window manager problems.
So let's change the name of these variables.
The W.T. posts here.
The pumps.
So now as you can see this process is called refactoring.
We are changing our codes for the builder.
Right.
It's called refactoring.
It's really useful in your when you are creating your own projects or your own and reallocations.
Make sure to always repackage your code to make it better make it simpler make it more meaningful.
OK so now let's scroll down here.
Let's go inside the untouched Merfeld.
So here start ex-post right.
Assignment operator.
Now I can refer to W to deep harams that X Seneca's and this way we can access the start exposition
of the window manager that holds or contains the floating Veach.
So now we can say start why PPOs assignment operator w the palms.
That's why semicolon.
Now let's initialize our start.
Touch x.
So let's say start X assignment operator.
So we have an argument here event which is of a motion event we can access the position of the touch
x the start to touch x from this event which is of motion even so we can see event that gets RA X semicolon.
Notice that the difference between Start exposition and the start to touch x is that the start exposition
is going to give you the position of the floating widget on the screen X. But this Tut tut X is going
to be when user for example starts touching the floating widget on the screen.
Does it start to touch x is going to hold that starting to touch a static position that the user has
started touching.
And then for example the user wants to for example change the place of a widget or on the screen.
So here we say events that get a raw x and B have to start to touch y.
So start touch y assignment operator event that get RA y semicolon.
So there is a problem here.
Sure it does.
So as you can see instead of assignment operator I put a minus here.
So Vinita with the assignment operator here.
OK so why do you want to access these values here.
For example accessing the starting exposition of our widget or accessing the start in y position our
widget or starting touch x because we want to drag our widget over on the screen we need to access these
values.
Let me show you the emulator so here it is my vision on the screen and then I want to drag this image
here over on the screen.
You can see that we need to access the starting position of this widget.
You need to access this starting touching position of this widget.
So while this happens how we can drag this image over on the screen by using the action down.
So when I start touching this image and when I start moving this image here over on the screen or over
other apps I am using the action down event.
So let's go back to android studio and here after declaring these variables here let's create a suite
statement let's say that we have a switch statement and this switch statement is going to switch between
the values of the event that gets action.
So if you want to get the action of the event that is related to the touch of the user right.
So now let's Cotts these values.
Here we are initializing our valuables our local valuables.
Let's cut them and paste them here.
Let's go inside the switch statement and let's create a case motion event motion event that's action
down.
So let's choose this fun action down colon and let's say let's actually paste these values here initializing
our local variables.
Now we can say that when the action is down when this user starts actually touching the the widget in
order to change the position of the widget over on the screen we can return true from this untouched
method so we can see your return true.
So the action down means that the user has started touching the widget on the screen in order to move
it.
So let's create a comment here let's say that these two variables here at the start exposition and is
that why position here we want to access the start
position of widgets and these two variables starts to touch x and start touchpoint you want to access
the start touching position that starts touching position
of widgets.
So now we want to return to return true means that the user has started actually touching the widget
in order to move it.
Now let's create another case statement.
Now we have case motion event that action up on the line of Colin.
Now here this action up means that the user has lifted his or her finger from the Wii Fit on the screen
in order to let the app know that that touching or dragging the widget on the screen is now finished.
So the action up is going to.
In other words this means that we want to get the touching or drying process is now finished.
It's called Action up.
So now let me paste two lines of code here.
As you can see I pasted this to valuables here.
The first one is of type integer and the name is start to end exposition.
So the moment the user starts touching the widget and the moment the user start lifting his or her finger
from the widget on the screen.
It is going to be a defense for the x value start to an exposition a difference between the starting
position and the end position.
So if you want to access that value so if put an assignment operator and we are we want to actually
cast this to an integer value because the event that gets X is going to get was a float value and if
would prefer to see a good event that gets right eats is going to give us the current position or the
kind of touch position of the widget on the screen minus so minus start to touch exposition.
So this thought exposition is the starting position of the widget that is being touched for the first
day for example the user wants to change the position of the widget on the screen.
Right.
So we want to access that value.
The moment these are the users start touching the widget.
And here we have the current position for example the user has changed the position of the visit.
So now we have the current position of the widget minus this thought X touch they start to touch x.
So that's different now we have the difference between the end and the start the exposition.
Right.
So now we want to assign this value to this variable but we have an error here.
This means that variable starts touchbacks might not have been initialized.
So let's actually give them an initial value these valuables inside these on top of it.
Let's give them zero as the value as the initial value or the default value.
Now here the error is gone but here let's give these variables a meaningful name for example start to
end X..
Difference is more meaningful starts to an X difference.
And starts to end.
Why the difference in set of polls.
Let's just type in here difference.
So now this variable holds the difference between the end and the start that value.
So why do you want to access this value because we want to actually specify the user has clicked on
the widget or not.
Why.
So let me create an if statement and then I'm going explain more.
So here it is the if statements that I pasted here for this case motion events that action of I am saying
that if start to and X the fence is less than 5.
So let me show you the emulator.
So here it is our widget.
Right.
And now I want to actually change the position of this widget for example on the x axis from left to
right or from right to left the starting position is here and the end position is here.
Right.
So now that we have this difference the start of and X difference.
Sometimes when the user actually clicks on this widget it may actually change it.
For example the user may change the position of the spirit a little bit.
So we want to get that difference in order to say that maybe the user has clicked the visit in order
to change the collapsed state into the expanded state.
Right.
Sometimes touching means clicking.
Or for example the user clicks and is a widget and this widget moves a little bit here.
So we want to say that if this visit moves a little bit here then that is called clicking.
So it's really good for you to learn this technique.
It really helps you in order to create such applications in Android.
So let's go back to android studio.
So that's why I created this statement.
I am saying if start to end X difference.
So let me show the emulator so that the x axis is here right on the on the horizontal axis and we have
this starts to end why difference.
So here this is the y axis.
So now we are saying that if start to an X difference is less than 5.
And the analytical operator starts to end.
Why friends is again less than five then it is called collisions because there it is actually changed
a little bit here on the screen so we can consider it as a click if you want to you can manipulate the
display value by the way.
But 5 is actually good here.
Inside this statement We have another statement and in a statement actually we are saying that it is
it collapsed.
So we're calling MFL that we have not created yet inside our class we are going to create this method
in a moment but this is going to return true if the widget is actually in a collapsed state.
If it is true then it's going to go inside the curly braces of this statement and it's going to say
collapsed view.
That said visibility view that we don't want to see the collapsed view anymore.
So when I actually change the place of this visit a little bit here for example here.
Now it's changed to the expanded state.
Right.
So that's it.
And here we can see that the collapsed view is gone.
And the expanded view is visible.
So let me click on this close button again.
So now let me just click on this visit here.
Now you can see that the collapse is gone.
And the expanded view is visible.
So now let's create this Nefert inside our class is we just collapsed.
So he'll just scroll down here.
So before so after the end in Crilley brace of these touch my feet here and inside this class floating
views service class I am going to just type in here.
Private's Boullion and in Aimee's is when it collapsed I put a pair of apprentices here and I just opened
and closed this method by using these curly braces.
So now let's just say return collapsed.
You got get visibility is equal to view that visible semicolon.
If the visibility of the collapsed view is actually visible and it is on the screen then this means
that the widget is actually collapsed right there.
And this it is going to return true.
Otherwise the Smurfette is going to return false.
So here you can see that the error is gone.
So now let's go back to our switch statement here.
And we have this action up and this statement so after the ending really brace of this if statement
or this outer loop statement we can return TRUE return to semicolon.
Finally here we need to specify the final case statement.
It is going to be Moshin event that action move.
So let's just say if in here case motion even motion event that action move this one colon.
So now it's time to update the position of our widget the floating widget on the screen.
First of all you need to specify the parameters our window manager.
So we have this W.T. pardon's that X we want to update disvalue.
Right.
Because it is actually action move action move means that the user is dragging the floating widget on
the screen.
The action movie is going to be caught.
So here we see WRAMC that X assignment operator.
So first we have the starting exposition of our widget.
So if you're going to say start x posts plus So now we want to cast our value to an integer value.
So it's a part of Prentice's integer.
And let's put another prof practice year.
So let's say event
gets RA x.
So now we have the current position of our widgets on the screen.
Touching that dragging process is now finished.
Now we have the current position the current touch value they get for X the CANNOT TOUCH value of the
X of our floating better than the screen.
And we want to get the difference if we want to say minus start touch x semicolon.
So if you want to say start exposition the initial position of our widget on the screen plus there result
of this operation here event that gets raw eggs the kind of touch position minus this tarting touch
position and we are casting this value to an integer value.
And finally this value is going to be assigned to this window manager programs that acts in this way
we can update the position of our floating widget on the screen.
So this is the formula here.
You can use this formula in any apps you want.
For example you want to change the position of a specific widget or a component on the screen.
You can use actually this formula here and let's say that we have the perhaps that why don't we want
to use this formula.
So put an assignment operator.
Now we say start with voice position plus.
Let's test this to an integer value.
And let's put up her Apprentice's again event that gets raw Voi minus 13 touch y semicolon.
But we can say the window manager that up date we are calling this Meffert update view lay out.
So this if it needs two arguments the first one is going to be the view the floating period.
So we passed the floating widget comma and finally we need to pass the parameters so we updated the
x and y coordinates of our window manager here write the parameters.
So if you want to pass the w the Pops.
And finally we are going to return true from this case return TRUE semicolon.
So we passed these values here but we have another error.
This it on touch move it needs to return a boolean value.
But we created a switch statement and only one of these case statements of the switch statement is actually
executed.
The boolean value is going to be returned for example.
True but as a whole inside the curly braces of the Smurfette untouched we need to return a boolean value.
So let's say just return false.
Let's say before the end curly brace of this unperson for let's say return for Senechal.
So let me sum in space here.
That's it.
This is our untouched method and that's enough for this tutorial.
And if you have any questions about these concepts that you've learned so far about implementing this
untouched method please post the discussion in the course and then I'll do my best to answer all of
your questions in the next tutorial.
We are going to implement the and destroy method here inside our class so that we can make sure the
widget meant that a service is actually stopped we can make sure that the memory is also emptied.
And we do not encounter memory problems later.
And our app is actually published.
So thank you very much for watching.
And I look forward to seeing you in the next tutorial.