This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FusedLocationProviderClient - MainActivity class for receiving location updates. | |
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient | |
override fun onCreate(savedInstanceState: Bundle?) { | |
// ... | |
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private lateinit var fusedLocationClient: FusedLocationProviderClient | |
override fun onCreate(savedInstanceState: Bundle?) { | |
// ... | |
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) { |
NewerOlder