Skip to content

Instantly share code, notes, and snippets.

View Lavanyagaur22's full-sized avatar
🚩

Lavanya gaur Lavanyagaur22

🚩
View GitHub Profile
public static ArrayList<Float> final_faces_array(float percent, float[] arr, float comparable_percent) {
float len = arr.length; //length of array
float min_no = (percent / 100) *len; //number of faces wanted
float last_face = 0;
float secondlast_face = 0;
//maintain an arraylist because if we keep an array we would have to initialize it with the size which can be max = len, but in case
//the number of elements are less then array space is wasted.
ArrayList<Float> faceslist = new ArrayList<>();
for (int i = 0; i < min_no; i++)
...
try {
fusedLocationProviderClient.requestLocationUpdates(
locationRequest, locationCallback, Looper.myLooper())
} catch (se: SecurityException) {
Log.e(TAG, "Lost location permissions. Couldn't remove updates. $se")
//Create a function to request necessary permissions from the app.
checkAndStartLocationUpdates()
}
val removeTask = fusedLocationProviderClient.removeLocationUpdates(locationCallback)
removeTask.addOnCompleteListener { task ->
if (task.isSuccessful) {
Log.d(TAG, "Location Callback removed.")
stopSelf()
} else {
Log.d(TAG, "Failed to remove Location Callback.")
}
}
locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
super.onLocationResult(locationResult)
if (locationResult?.lastLocation != null) {
// Get the currentLocation from the locationResult object.
currentLocation = locationResult.lastLocation
// Notify our Activity that a new location was added.
// Sets the desired interval for active location updates. This interval is inexact. You
// may not receive updates at all if no location sources are available, or you may
// receive them less frequently than requested. You may also receive updates more
// frequently than requested if other applications are requesting location at a more
// frequent interval.
locationRequest = LocationRequest().apply {
// Sets the desired interval for active location updates.
interval = TimeUnit.SECONDS.toMillis(60)
// FusedLocationProviderClient - MainActivity class for receiving location updates.
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
// LocationRequest - Requirements for the location updates, i.e., how often you
// should receive updates, the priority, etc.
private lateinit var locationRequest: LocationRequest
// LocationCallback - Called when FusedLocationProviderClient has a new Location.
private lateinit var locationCallback: LocationCallback
// FusedLocationProviderClient - MainActivity class for receiving location updates.
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
override fun onCreate(savedInstanceState: Bundle?) {
// ...
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
}
fusedLocationProviderClient.lastLocation.apply {
addOnFailureListener{
//Handle the failure of the call. You can show an error dialogue or a toast stating the failure in receiving location.
}
addOnSuccessListener {
//Got last known location. (Can be null sometimes)
//You ca extract the details from the client, like the latitude and longitude of the place and use it accordingly.
myLat = it.latitude
myLong = it.longitude
private lateinit var fusedLocationClient: FusedLocationProviderClient
override fun onCreate(savedInstanceState: Bundle?) {
// ...
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
}
//detector is an instane of FirebaseVisionTextRecognizer
detector.processImage(image)
.addOnSuccessListener { firebaseVisionText ->
// Task completed successfully
for (block in firebaseVisionText.textBlocks) {
val blockText = block.text
val blockFrame = block.boundingBox
for (line in block.lines) {