‫Hello, my friends.
‫We are going to add the functionality for the widgets that we have initialized in the previous video.
‫So we need to allow the user to open the gallery and select one of the other images that he need to
‫extract the text from.
‫So we have created open gallery method.
‫I will start by creating intent, get intent equal, so the user will go to the gallery and start selecting
‫an image to extract the text from it.
‫You intent?
‫And intent dot action underscore get content.
‫This is the intent get intent dot set type to image.
‫So we are getting all the images.
‫Now another intent pick intent.
‫You intent?
‫Intent the action pic.
‫Android dot provider dot media store dot images dot media dot external content u r i.
‫This is how we access the external storage.
‫So pick and tend the set type also for images.
‫Intent.
‫Chooser.
‫Intent.
‫Equal intent.
‫Dot.
‫Create chooser.
‫Get intent.
‫And select.
‫Image.
‫Chooser.
‫Intent.
‫Not put extra to.
‫Intent.
‫Dot extra.
‫Initial.
‫Extra.
‫Initial
‫intent.
‫And the new intent array.
‫And here we pick and pick.
‫And this is how we choose the intense how we choose the that the functionality to open our gallery and
‫allow the user to select the image to start scanning.
‫Now start activity for result.
‫Choose your intent and.
‫Epic image.
‫This is the code pick image.
‫This is a request code.
‫So I will create this request.
‫The code for above.
‫Extract it, plus enter to create the package.
‫I will create a constant field here and I will put it.
‫One, two, three.
‫Okay.
‫So in this way we have created this request to append on activity result.
‫Now start an activity or start activity for a result request for from us to add on activity or on activity.
‫Result method.
‫Override on activity
‫result.
‫We need to override this method.
‫And now we need to start adding the data.
‫If request code equal equal to pic image.
‫I will put here.
‫If the data does not equal to null then.
‫Here.
‫I will start making a byte array.
‫Byte array.
‫But.
‫Array equal to new but
‫array xhr and string.
‫File path.
‫Here equal to not.
‫Then I will try.
‫I will surround it by try and catch.
‫So input image that we have created before equal to input image which is a mel kit dot vision the common
‫dot from file path because we are requesting the data from the gallery.
‫So we need to add this from file path that we have created here this and data dot get date.
‫This is how we add this.
‫From file path request us to add a catch clause which is an IO exception.
‫Input output exception.
‫So when reading from external data from external external file and external storage, we need to add
‫this exception.
‫We create a bitmap result.
‫Result you are equal to input image the get bitmap and turn.
‫Now we will use that glide library glide with main activity dot this to set the context dot load result
‫your eye and into the image of you.
‫So we are going to load that the selected image into the image view that we have created.
‫So after loading we need to start reading and processed text block.
‫So process that image.
‫So I will create a task task of text.
‫And a cold result.
‫So this is the task.
‫Plus, enter.
‫And this is a text of MLK.
‫Don't be confused.
‫So we are using all the data and all the the packages and the classes of MLK.
‫So these are the the classes that we are going to use in our applications.
‫So recognizer here, the process, the input image.
‫So here we have processed the image and add on success listener So after you process successfully the
‫the image make a call, the on success method and query and call the method that we are going to create.
‫Process text.
‫BLOCK and we will pass the text here.
‫Al Plus enter to create the method inside the main activity.
‫So here we have created the main and the main activity, this method.
‫Now I will create an on add on a failure listener.
‫New on failure listener where make a task filled with an exception.
‫So here we will display a toast message for the user telling him it has failed.
‫Now.
‫Okay.
‫Then we are doing everything fine.
‫And here I would remove the spaces.
‫So what we have done is creating a method here inside the on on activity result calling the method the
‫process text block.
‫If there is a recognizing of the input image if not display a failed message.
‫So.
‫Now we need to create the method process text block, which is here inside the main activity.
‫So start MLK text block, start m l get the process that text process, text block, string result the
‫result text equal to result or the text dot get text.
‫Now we need to make a for loop text dot text to block dot or block of result to get text.
‫Which is here, that text don't get text blocks.
‫So we are going to loop through all the blocks inside that this text and start extracting them into
‫individual text.
‫And then we need to add this block for the result text.
‫So we are going to extract the text from the image block text equals block the get text and text if
‫you don't view dot, append every line inside this image image.
‫So every single line inside the image will be extracted inside a block text and then the text of you,
‫after reaching the end of this line, will append a new line.
‫So this would go for will give us a new line and start adding the new data for the next line.
‫How to add this we will start by adding the point, a point
‫which is here point from the Android graphics point array block corner points equal to block dot get
‫corner points rectangle from android graphics block frame.
‫These are the graphics.
‫Let me separate them.
‫BLOCK frame.
‫Equal to block the get bounding box.
‫For.
‫Text the line
‫line for every block.
‫Dot get lines.
‫Strange line text.
‫Equal to line, don't get taxed.
‫So we are ending them to for every line in that inside this text, go and add them into the block and
‫add the line text to this text of.
‫So how to add this?
‫We are going to make point also in the same way point at a again and again point array of line, corner
‫points, equal line dot get corner points.
‫And then we are going to add the rectangle line frame which will be framing the text dot get bounding
‫box.
‫And inside this loop we have created a nested loop.
‫And inside this nested loop we are going to create another nested loop.
‫So for text dot element element inside for e for each element inside the line dot get elements array
‫go and create an element object of text element that type add the text view dot append a new space string
‫element text equal to element dot get text string.
‫Element.
‫Text equal to.
‫Element.
‫Dot.
‫Get.
‫Text.
‫View.
‫Dot.
‫Append element.
‫Text.
‫Okay.
‫So I have created this two times.
‫Oops.
‫And the last thing that we need to make is the same as before.
‫Point array element corner points equal to element dot get corner points correct angle of element frame
‫equal to element dot get bounding box.
‫This is how we use this method.
‫It's very simple.
‫We have created the process text block and we create all of these data.
‫Now we need to override some, some methods like on pose and compose.
‫I need to make a simple check if does not equal text, speech, text to speech, text to speech that
‫is speaking.
‫If it is not speaking, then make a super on post.
‫If it is speaking, don't pose anything.
‫So don't pose the text to speech when it is narrating the text if it is calling on post method, but
‫if it is on stop then make the stopping correct.
‫So till now we have successfully added and created a.