‫Hello, my friends.
‫In this video we are going to add the main activity functionalities and we are going to link the main
‫activity layout with its functions.
‫So first of all, I need to initialize the widgets.
‫I have created a button here, a text view and an image view, so I need to add the button alt plus
‫enter to import the package of the button and I need to add the text view, text view and the image
‫view.
‫Image view plus enter to import the text view package and the image view package.
‫Now I need to create a static integer so public or private final static and this is a variable that
‫we are going to use but it of type, finance, static.
‫So it's about a constant variable you can name it and or you can imagine it like this capture equal
‫to 1 to 4
‫and the input image, input image, it's from Google.
‫M And so you see guys, it's from Google Dot ML kit.
‫So you see that we have imported directly that this package come Google ML Kit vision common and common
‫and input image input image.
‫I will name it as Firebase vision and what we are going to instantiate also a face detector.
‫So it's about face detector.
‫We can see that there are two, two or more, but face detector classes is.
‫Or are the face detector and face detector here?
‫This is an interface from ML Kit and this is an class from Android media.
‫Now we are going to use the face detector interface from the market.
‫So I need to import this line.
‫So don't import this, don't import the Android dot media and just import this interface.
‫You can specify it by importing this line, this package, and we can create an instance of this, this
‫class interface.
‫Later on, we are going to use that of polymorphism because we are making an an interface here and we
‫are going to use that polymorphism that we have discussed many in in Java tutorials and we will use
‫an instance of a face detector, but in other name we will discuss it later on.
‫Okay, let's initialize the widgets button equals find view by id r that id dot dot.
‫I think camera button.
‫These are the widgets from the main activity.
‫The image view is named as image view and the text is called text one text.
‫If you equal, find a view by ID artist id dot text one text one the image view equal find if you buy
‫ID of that ID dot image view.
‫Now we will start by Firebase app dot initialize let me let me see add dependency Firebase Common and
‫import.
‫So I will use the Firebase app.
‫And in order to use the Firebase app instance, I need to add the dependency.
‫So I will click on add dependency.
‫If we go to the gradle, you see guys that we are going or we have added this dependency so.
‫I will move it to here in order to be clearer to you.
‫There is a newer version we can use.
‫20 .1.1 So I will change it to 1 to 1 here.
‫And I am waiting for the Gradle to sync and download the model.
‫And here we go.
‫We have imported and implemented the library of Firebase Common.
‫Now we can use the Firebase App and initialize the application for this.
‫This is as a connection between the Firebase and your application.
‫Now no need to add or create and and a project on Firebase system when using the market as we see in
‫the QR code and the text recognition, no need to create a project these projects are used to, to,
‫for, for real time, for storage and for firestorm.
‫So when you need to connect with the database and get real information, right, information.
‫So you need to make a project on Firebase and link it with your app by downloading the file that we
‫have seen in the previous videos.
‫Now button here dot set or click listener you view on click listener and we are going to call a method
‫called Open File.
‫This method, we are going to make it next couple of minutes.
‫And the toast message we need to create a toast message telling the user.
‫App is started.
‫Now let's create this method inside the main activity and here open file and inside this I'm going to
‫direct you at to a class an object from this class a result dialog.
‫So we are going to display the data that we have scanned, the phase detection result into a dialogue.
‫For his old dialogue class that we have created before.
‫And what we are going to make are going to be in the media store,
‫the image capture.
‫I need to to take a pic.
‫And from the processing we are from the processing of this image, we are going to display the result
‫into a result dialogue.
‫So if intent dot to resolve activity, get active package manager does not equal to null.
‫I am checking if this does not equal to null, then what we are going to make?
‫We are going to start activity
‫for result
‫and we pass the intent and we request that image capture integer else.
‫But we are going to make are going to display toast message telling the user that it is failed.
‫And when using the START activity for result, we are going to override the own activity result method.
‫So on activity
‫result, activity result, what we are going to make, we are going to to pass the bundle to the face.
‫Also, we are going to process the image by calling a method face detection.
‫So what we will do to remove this, we will keep it and we will add the bundle instance from here.
‫Bundle equal to data to get extras.
‫Then the bitmap.
‫Bitmap.
‫Equal to a plus enter.
‫We are going to cast it as a bitmap.
‫Bundle dot.
‫Get data.
‫Now I will call a method called face detection.
‫Face detection process
‫and I will pass the bitmap.
‫And I will display those message telling the user that it is success.
‫Alt plus enter to create this method.
‫Or you can create like this public void face detection process.
‫It took into the parameter, the bitmap
‫instance.
‫So in the next video, we are going to continue with the phase detection process.