-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement GPS usage icon modified layout improvements
- Loading branch information
1 parent
e5c8256
commit 393bef7
Showing
13 changed files
with
392 additions
and
221 deletions.
There are no files selected for viewing
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
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
59 changes: 59 additions & 0 deletions
59
app/src/main/java/org/tensorflow/lite/examples/soundclassifier/Location.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.tensorflow.lite.examples.soundclassifier; | ||
|
||
import android.Manifest; | ||
import android.content.Context; | ||
import android.content.pm.PackageManager; | ||
import android.location.LocationListener; | ||
import android.location.LocationManager; | ||
import android.os.Bundle; | ||
import android.widget.Toast; | ||
|
||
import androidx.core.app.ActivityCompat; | ||
|
||
public class Location { | ||
|
||
private static LocationListener locationListenerGPS; | ||
|
||
static void stopLocation(Context context){ | ||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | ||
if (locationListenerGPS!=null) locationManager.removeUpdates(locationListenerGPS); | ||
locationListenerGPS=null; | ||
} | ||
|
||
static void requestLocation(Context context, SoundClassifier soundClassifier) { | ||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && checkLocationProvider(context)) { | ||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | ||
if (locationListenerGPS==null) locationListenerGPS = new LocationListener() { | ||
@Override | ||
public void onLocationChanged(android.location.Location location) { | ||
soundClassifier.runMetaInterpreter(location); | ||
} | ||
|
||
@Deprecated | ||
@Override | ||
public void onStatusChanged(String provider, int status, Bundle extras) { | ||
} | ||
|
||
@Override | ||
public void onProviderEnabled(String provider) { | ||
} | ||
|
||
@Override | ||
public void onProviderDisabled(String provider) { | ||
} | ||
}; | ||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, locationListenerGPS); | ||
} | ||
} | ||
|
||
public static boolean checkLocationProvider(Context context) { | ||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | ||
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ | ||
Toast.makeText(context, "Error no GPS", Toast.LENGTH_SHORT).show(); | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.