Hire everyone now it's time to actually use our colorful class.
So inside this main activity class I'm going to actually show you how you can create an entire class.
So what is an inner class and in that class is that that is the class that you create inside another
class.
So we have this main activity class here right.
This is our main I have the class inside this class.
I can create another class.
So let's scroll down here before the end in Kerley place of this main activity class.
I'm going to create another class and this class is going to be private what US private means that only
private means that only main and main activity class can actually create instances of type.
Actually it is in a class so private.
And here it is meant to be class right class.
Now I need to specify the name of this class.
So what is going to be the name.
The name is going to be colorization handler conduct colorization handler right.
And then here I just need to open and close this class by using these curly braces.
So this is an in class as simple as that.
But this class is going to actually implement an interface.
So what is that interface.
That interface is called actually unsichtbare change listener.
So after this class name I'm going to say implements colorization handler implements unsichtbare change
listener so because this class is actually conforming to this interface or it is implementing this interface
this class is in a class must provide an implementation for free methods that you have inside Ismir
interface.
The first one is going to be on start tracking touch.
So this it is going to be called whenever the user actually starts interacting with the search bar.
So now it's time to actually implement the second method which is going to be on progress changed.
So this method is going to be called when the use is actually when the progress is changed.
OK.
When the progress is being manipulated and it is being changed and the final effect is going to be on
stop on stop tracking touch.
So this is going to be called when they use that stops interacting with Cuba the method that are going
to use inside our application is this not only this one on progress changed.
This is the only method that we actually care about.
But we are not going to actually use these methods.
For example this unstarted I can touch or unstopped I can touch because it's not necessary to actually
work with these benefits but it's necessary to implement them.
Otherwise it's going to show us an error.
The compiler is going to be unsatisfied and it's going to show us an error and it's going to prevent
us to run the application.
So we must implement these methods.
So now let's go inside the curly braces of this unprogressive change in effect and let's see what we
are going to do next.
But before that let's actually let's our search bars.
You can see that the insight or activity or the limited example we have these freesheet parts right.
Let's allow these sequel's to know that they have actually a handler so that we can be notified when
the user is actually interacting with these parts.
Let's go to the main activity class.
Let's scroll to the top here and inside this uncreate.
This is actually here it is the best place to lead our sick birds know that they have a handler right
because this is going to be called as soon as the user runs the application.
So here I can actually say read bar that said on search bar change listener.
So here we must pass the listener right.
We already created a class in order to handle that right.
Colorization handler but we must first create an instance of type colorization handler class.
This is actually a private class and in a class right.
So after this line of code here that's just the listener for the spot in between and save the picture
in say this and create it.
And before this line of code that actually sets the search bar change listener I'm going to create an
instance of type colorization handler class I'm going to just refer to this class colorization handler
and the name of this instance is going to be colorization handler assignment operator new colorization
handler right semicolon.
So now we have an instance of type colorization handler class.
Here we created the actual instance and we assigned this instance to this valuable.
Right now I can't pass this instance to this set on Six-Party change listener which is going to play
the role of the listener when they use that interacts with the switchboard.
So I'm going to specify actually the listener for the green actually the green part and the Brucey parts
so green bar but sit on bar change.
Listener as it colorization handler again.
And finally the prusik part that said honestly pro-change change listener colorization handler.
That's it.
So now that we actually specified the handler for this sequence Albi and let these people know that
they have a handler whenever the user interacts with those six bottles inside a screen.
These misfits here for example the OnStar tracking touch MF'er the unprogressive a Meffert address and
start tracking change and start tracking.
Post-movie is going to be executed.
So we are going to use this method.
Unprogressive changed.
So let's go inside the curly braces of the Smif.
Let's see what we're going to do now.
Let's take a look at these arguments of this method on progress change.
The first one is the search bar.
So this is actually the actual search bar that is being manipulated.
The second argument is the progress the value of the progress of the bar and the first argument that
is going to be is very important is from user.
What does this mean.
This means that Vidur the user is actually interacting with the skipper or not.
OK.
This means that the user is actually interacting with the search bar.
So we have this value but in order to specify that whether the user started interacting with the secret
or not so we can't say enough from user and that open and close this if statement by using this calibrated.
This means that if this really is true this is from user is actually true then it's going to execute
the code inside this if statement.
So now it's time to go into the activity and illuminate examine here.
And I'm going to specify the progress value and the maximum value that these six bars can actually have.
So select is first search part which is going to be this this red color sick all right.
Select it.
And here you can see all these attributes here the farm Max progress.
So for the max attribute here just assign the value of 100 and then enter on your keyboard for the Proclus
attribute assign the value 0 and in person and then on your keyboard.
Selectees so you can see spot here.
For the max chip you assign a value 100 and for the progress zero into general keyboard and finally
select this first search bar for the max attribute assign the value 100 and for the progress attribute
assign the value 0 and that person interntional cheaper that's it.
Now it's time to go to our main activity class inside this if statement here.
I can't say if search bar so I am referring to this sitch But object this argument right.
Is equal to read search but right.
And then I just need to open and close this if they can by using curly braces.
So here I am a hundred and fifty percent sure that this sick part that they use it is interactive with
is actually let's see part right because I created an if statement for this.
So here I need to have an object of type colorful class.
So let's scroll to the top of the file here and below this variable declaration here for the Spaeth
map I'm going to create and actually another variable private.
And this time the data type of this value but it's going to be colorful colorful and the name of this
variable is going to be colorful semicolon.
Right.
Let's scroll down here and let's go inside these actually.
Let's go inside this unactivated resolved method here.
And before before actually setting the bitmap here as the image of the IMJ photo I'm going to actually
initialize my colorful variable that I actually create declared inside our main activity class so I
can say colorful assignment operator new color fool.
So now the constructor of this colorful class the custom constructor that we created inside this colorful
class is going to be called.
So you can see that we need to pass these arguments.
The first argument is going to be this actually bitmap which is a bitmap so we have the Spizz map right.
So I'm going to pass the map here.
Bitmap comma and then we need to specify the red color.
So because of the user here the n and active The result is going to be called as soon as the the camera
activity is actually being disappeared.
Here for the red color value I just want to pass the value zero point zero F because this is going to
be off the floor.
We must put the letter here.
Otherwise the compiler may think that we are we mean a double value not a float value.
So here I'm going to for the record I passed the value 0 and 0 again for the green color.
I'm going to get past the value zero point zero F comma.
And finally for the blue value I'm going to again pass the value zero point zero semicolon.
Right.
So here we initialized our colorful object inside is an activity result so you already know when this
method is being called right.
In the previous tutorials I actually showed you Venditte method is called.
So here inside this method I have initializing my colorful object with these values.
I passed the bitmap here the bitmap that we get from the bundle and then we specified the red color
the green color and the blue color.
We passed the value zero here.
So now let's scroll down here and let's go inside this on progress changed Meffert inside the colorization
handler class and let's go inside the statement that specifies if the part that is being interacted
with is actually there it's the red Six-Party.
So now that we have the colorful object here I can say colorful.
That sets the red color colorful that set red color value actually.
So here I am calling the setter method for these red colored value is this valuable that we have inside
these colorful class this if it needs a value of type float and let's go inside this colorful class.
So here it is the colorful class right.
Let's look at this settlement efforts of our.
Instance variables for example look at this method here.
Set red color value.
This method has an if statement that actually specifies if the argument read value is greater than or
equal to zero and that value is less than or equal to 1.
Only in that case we are going to assign this argument to this red colored value instance variable.
So inside this main activity class when I say colorful That said Rose colored right you must pass a
value between 0 and 1.
How we can do that.
So we have to progress right.
And we know that the maximum value is 100 and the progress the current progress is zero.
So here in order to have a value between 0 and 1 here we can say progress.
So I'm going.
I am referring to is progress value right.
Divided by 100.
So now the result of this operation is going to be of value between 0 and 1.
So now we can actually pass that value to the Smif etc cetera is colored value.
So after this line of code I can say now we need to specify the value of the Red Sea bar.
Right.
So I'm going to say let's see.
But that said progress so we need to specify the progress of the Red Sea.
But right now again we are going to have to progress which is going to be of value that is between 0
and 100 right here because the value of this of this colored value instance variable of this color for
instance is actually of value between 0 and 1.
We need to multiply this value by 100 so that we have a value between 0 and 100.
So here inside the apprentice's I can say 100 multiplied by.
So let me put a set of practices here and here I just need to refer to this colorful instance that gets
red colored value.
And now it's not an error.
If I hover over this area it says the result of this operation is actually of type float.
Right.
But this set progress Smurfette needs an argument of type integer.
So we must cast this operation the result of this operation to an integer value how we can do that first
first let's actually put this operation inside the to just put a of here and put this operation as you
can see 100 multiplied by colorful that get red colored value right.
So let's put this operation inside Apprentice's in this way and here inside these practices of this
set Procrustes Merfeld.
I can actually put a pair of practices here and I can put integers.
That's it.
Now we have no errors because this operation here is now inside the prentices and here the result of
this operation is going to be tested to an integer value.
And here we have no errors.
So that's the value of these red red switchboard.
That's progress.
And finally let's actually update our takes the view so takes the red colored value that text that actually
said text it.
I can easily refer to this colorful object that gets a red color value right.
And because it is going to be off the float and this takes some of it needs a value of that integer
to actually just convert this value to us three values we just put a concatenation operator and then
just two coats you're right.
That's it.
This is for our red spot.
Now let's create an elusive statement for the green search.
So I can say.
Else if so each part is equal to green bar.
Right.
I can open and close this elusive statement by using this curly braces.
So here it is going to be the same in the same scenario here.
Again we're going to refer to this colorful object that sets green color value.
And here I just need to divide the value of the progress by this 100.
That's it.
Now we need to actually update the value of the progress of the green search part so I can say green
search bar that said progress.
So here again we need to actually cast this object to an integer value and that here.
Let's actually put our operation inside Apprentice's 100 multiplied by.
Let's put another of parenthesis here.
Colorful dot gets green while you get green color value.
That's it.
As you can see we have no errors here.
So let's also update our takes.
Beauty is the green color value.
That set text.
And here I just type in color food that gets green colored value plus two coats.
Now we need to add also updates are actually are blue a search bar so after the curly brace of this
statement does create another LCF statement so LCF CPR is equal to blue CPR.
I just need to open and close this if they can by using its curly braces so colorful That said Green
set blue color value.
Progress divided by 100 and then I can say blue color value blue color.
A sequel actually pollutes the report that said progress and here I need to cast is of value to an integer
value.
Let's put another parenthesis here.
So here I can say 100.
Multiplied by.
Let's put another pair of pants this year in order to put this colorful dot get blue color value.
That's it.
Now we have no errors.
And finally we need to update our text so it takes the blue color value.
That said text.
And here I just need to refer to this colorful object that gets blue color value plus two coats.
So that's it.
This is very important.
Just pay attention here.
Finally we must update the value of our bitmap object right because when the user interacts with this
sequel's you want to change the color of each pixel of our image.
Right.
So in that is it.
This means that the bitmap is going to be updated.
So we need to actually update our bitmap so after the in curly brace of this LCF statement and I mean
say it is if from Use a statement here.
Right.
So before the adding curly brace of this if statement that specifies that if the interaction was actually
performed by the user or not here I can actually say bitmap.
That's the spirit here.
Bitmapped assignment operator here.
I'm going to refer to this colorful object that return actually call this method the return the colorized
the bitmap semi-colon.
Right and in here I just need to type in IMT for two dot image that set is actually the set image set
the image bitmap choose this Misfit's that image bitmap.
And I just need to pass bitmapped with this method.
So let's run our application now.
And let's see if this works or not.
So here you can say that our application is running on the simulator.
And let's take a picture here.
So here is our picture and let's accept it.
So here is our picture in place of this actually inside this image view.
But now when I am going to actually interact with these six bars our application is going to crash.
OK.
But here I want you to pause the video and use the debugging techniques that I taught you so far in
order to debug the application.
This is very important because later when you want to create your own Android apps or if you want to
create Android apps for the clients you're going to definitely encounter bugs.
Actually nasty box.
So you have to get actually get into the habit of debugging your applications.
And I want you to actually not to panic and start thinking about the source of the bug.
And if you don't know anything about the bug in Android.
Make sure to watch at twenty eight.
Their final part their of that it says debugging the app that I actually talk talked about debugging
Android applications by using the debugging techniques in Android studio.
So please post the video and debug the app yourself and when you're ready try to actually run actually
play the video again.
And here I'm going to let you know where is the source of the buck.
So now let me tell you that let me actually interact with these sequoias as you can see our application
crashed.
Right.
So let's go to Andrew it's you.
I told you you just need to click on Android monitor here and here you can see these red texts here.
Right.
If you scroll to the top it says a fatal exception made made means the error occurred on the mainframe.
And you can see these it takes here it says Return the colorized map and you have also this text that
it says on progress changed.
So let's click on this link here.
Main activity that over here so it says that the source of the error is this one here bitmap assignment
operator colorful that returned the colorized bitmap.
And here it says that we have this colorful that Jubba.
Let's go to the colorful Dobber class and here you can see that it says the error is occurring here.
So what's wrong with this line of code.
If there is something wrong with this line of code here here instead of passing bitmapped with and built
a bitmap height we must pass a row and column right because we must pass the specific rule and the specific
column.
And here we are going to actually specify the pixel color of that specific pixel right.
So that's it.
This is the source of the error if you run the application.
Now you can see that our application is going to work fine and properly.
Let me run on the application now.
Let's click on take a picture let's take a picture here.
Accepted.
And now let me interact with these words.
Now you can see that the color of this image is now red.
Let me interact with this one.
Now it is green.
Let me interact with this one.
Now it is actually this color.
Let me just for example in there interact is a green color you can see this green S'pore or this one
right.
That's it.
And you can also see that these actually takes views are also updated here.
So hopefully that makes sense.
And in the next tutorial we're going to continue building this application we're going to add another
functionality to this application.
For example I actually took a picture here and I for example changed the color of this image.
Now I want to save the picture into the internal memory so let's see how how we can do that in the next
story.
Thank you very much for watching.
If you have any questions about the concepts that I taught you in this lesson please post the discussion
in the course and then I'll do my best to answer all of your questions.