|
@@ -1,76 +0,0 @@
|
|
|
-package com.flacksta.chef.journeygpstracker;
|
|
|
-
|
|
|
-import androidx.activity.result.ActivityResultLauncher;
|
|
|
-import androidx.activity.result.contract.ActivityResultContracts;
|
|
|
-import androidx.appcompat.app.AppCompatActivity;
|
|
|
-import androidx.core.content.ContextCompat;
|
|
|
-
|
|
|
-import android.Manifest;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.pm.PackageManager;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.util.Log;
|
|
|
-import android.widget.CompoundButton;
|
|
|
-import android.widget.Switch;
|
|
|
-
|
|
|
-public class MainActivity extends AppCompatActivity {
|
|
|
-
|
|
|
- final String TAG = "MainActivity";
|
|
|
- Context appContx = null;
|
|
|
- boolean locPermGranted = false;
|
|
|
-
|
|
|
- private Switch simpleSwitch;
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_main);
|
|
|
-
|
|
|
- appContx = getApplicationContext();
|
|
|
-
|
|
|
- final int hasPermission = ContextCompat.checkSelfPermission(appContx, Manifest.permission.ACCESS_FINE_LOCATION);
|
|
|
-
|
|
|
- if( hasPermission == PackageManager.PERMISSION_DENIED ) {
|
|
|
- Log.i(TAG, "Requesting permissions.....");
|
|
|
- locationPermissionRequest.launch(new String[]{
|
|
|
- Manifest.permission.ACCESS_FINE_LOCATION,
|
|
|
- Manifest.permission.ACCESS_COARSE_LOCATION
|
|
|
- });
|
|
|
- }
|
|
|
- else {
|
|
|
- Log.i(TAG, "Permissions already granted.");
|
|
|
- locPermGranted = true;
|
|
|
- }
|
|
|
-
|
|
|
- simpleSwitch = (Switch) findViewById(R.id.enableTrackingSwitch);
|
|
|
-
|
|
|
- simpleSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
- @Override
|
|
|
- public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
|
|
- Log.i(TAG,"State: " + Boolean.toString(b));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- ActivityResultLauncher<String[]> locationPermissionRequest =
|
|
|
- registerForActivityResult(new ActivityResultContracts
|
|
|
- .RequestMultiplePermissions(), result -> {
|
|
|
- Boolean fineLocationGranted = result.getOrDefault(
|
|
|
- Manifest.permission.ACCESS_FINE_LOCATION, false);
|
|
|
- Boolean coarseLocationGranted = result.getOrDefault(
|
|
|
- Manifest.permission.ACCESS_COARSE_LOCATION,false);
|
|
|
- if (fineLocationGranted != null && fineLocationGranted) {
|
|
|
- // Precise location access granted.
|
|
|
- Log.i(TAG,"Precise location granted");
|
|
|
- locPermGranted = true;
|
|
|
- } else if (coarseLocationGranted != null && coarseLocationGranted) {
|
|
|
- // Only approximate location access granted.
|
|
|
- Log.i(TAG,"approximate location granted");
|
|
|
- } else {
|
|
|
- Log.i(TAG,"NO location granted");
|
|
|
- // No location access granted.
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
-}
|