Search in sources :

Example 1 with IncidentFragment

use of com.example.first_responder_app.fragments.IncidentFragment in project FirstResponse by mattpost1700.

the class MainActivity method onRequestPermissionsResult.

/**
 * Checks if permissions were granted or not.
 * If so continue program where it left off.
 * @param requestCode
 * @param permissions
 * @param grantResults
 */
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    Log.d(TAG, "onRequestPermissionsResult: " + requestCode);
    switch(requestCode) {
        case ACCESS_LOCATION_MAIN:
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                updateETA();
                Log.d(TAG, "onRequestPermissionsResult: PERMISSION GRANTED Main");
            // Permission is granted. Continue the action or workflow
            // in your app.
            } else {
                Log.d(TAG, "onRequestPermissionsResult: PERMISSION DENIED Main");
            // Explain to the user that the feature is unavailable because
            // the features requires a permission that the user has denied.
            // At the same time, respect the user's decision. Don't link to
            // system settings in an effort to convince the user to change
            // their decision.
            }
            return;
        case ACCESS_LOCATION_FRAGMENT:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                Fragment fragment = fragmentManager.getPrimaryNavigationFragment();
                if (fragment != null) {
                    IncidentFragment incidentFragment = (IncidentFragment) fragment.getChildFragmentManager().getPrimaryNavigationFragment();
                    if (incidentFragment != null)
                        incidentFragment.setupLocationListener();
                }
                Log.d(TAG, "onRequestPermissionsResult: PERMISSION GRANTED");
            // Permission is granted. Continue the action or workflow
            // in your app.
            } else {
                Log.d(TAG, "onRequestPermissionsResult: PERMISSION DENIED");
            // Explain to the user that the feature is unavailable because
            // the features requires a permission that the user has denied.
            // At the same time, respect the user's decision. Don't link to
            // system settings in an effort to convince the user to change
            // their decision.
            }
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Fragment(androidx.fragment.app.Fragment) NavHostFragment(androidx.navigation.fragment.NavHostFragment) IncidentFragment(com.example.first_responder_app.fragments.IncidentFragment) IncidentFragment(com.example.first_responder_app.fragments.IncidentFragment)

Aggregations

Fragment (androidx.fragment.app.Fragment)1 FragmentManager (androidx.fragment.app.FragmentManager)1 NavHostFragment (androidx.navigation.fragment.NavHostFragment)1 IncidentFragment (com.example.first_responder_app.fragments.IncidentFragment)1