Search in sources :

Example 1 with GPSAlertDialogFragment

use of com.agup.gps.fragments.GPSAlertDialogFragment in project android-gps-test-tool by Esri.

the class GPSTesterActivityController method startLocation.

/**
	 * Start and reset everything
	 */
public void startLocation() {
    if (_locationManager == null) {
        if (_startButton != null) {
            _startButton.setTextColor(Color.RED);
            _startButton.setText("Stop");
        }
        _elapsedTimer.startTimer(1000, _elapsedTime);
        _initialGPSTime = _elapsedTimer.getElapsedtime();
        _initialNetworkTime = _elapsedTimer.getElapsedtime();
        _locationManager = (LocationManager) _activity.getSystemService(Context.LOCATION_SERVICE);
        final Boolean gpsProviderEnabled = _locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        final Boolean networkProviderEnabled = _locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        final Boolean gpsPreferences = _preferences.getBoolean("pref_key_gps", true);
        final Boolean networkPreferences = _preferences.getBoolean("pref_key_network", true);
        final Boolean useCriteria = _preferences.getBoolean("pref_key_useCriteria", false);
        //Check network availability on startup. This version of the app cannot use maps offline
        final Boolean isNetworkAvailable = CheckConnectivity.checkNow(_activity.getApplicationContext());
        final DialogFragment networkFragment = new NetworkAlertDialogFragment();
        if (useCriteria == true) {
            _imCriteria.setImageResource(R.drawable.greensphere31);
        } else {
            _imCriteria.setImageResource(R.drawable.redsphere31);
        }
        //			setMapListeners();
        setUI();
        setLocationManagerUI(gpsProviderEnabled, networkProviderEnabled);
        if (gpsProviderEnabled == true && gpsPreferences == true) {
            Log.d("GPSTester", "CHECK1 CHECK1 CHECK1");
            if (networkProviderEnabled == true && networkPreferences == true && isNetworkAvailable == true) {
                Log.d("GPSTester", "Startup: GPS enabled true. GPS prefs true. Network enabled. Network Prefs true");
                delayedStartLocationProvider(null, true);
                _imGPS.setImageResource(R.drawable.greensphere31);
                _imNetwork.setImageResource(R.drawable.greensphere31);
            } else {
                Log.d("GPSTester", "Startup: GPS enabled true. GPS prefs true. Network not enabled.");
                delayedStartLocationProvider(true, false);
                _imGPS.setImageResource(R.drawable.greensphere31);
                _imNetwork.setImageResource(R.drawable.redsphere31);
                displayToast("No network connection available.", Toast.LENGTH_LONG);
                //Inflate alert dialog
                networkFragment.show(_activity.getFragmentManager(), "NetworkAlert");
            }
        } else if (gpsProviderEnabled == true && gpsPreferences == false) {
            Log.d("GPSTester", "CHECK2 CHECK2 CHECK2");
            if (networkProviderEnabled == true && networkPreferences == true && isNetworkAvailable == true) {
                Log.d("GPSTester", "Startup: GPS enabled. GPS prefs false. Network enabled. Network Prefs true ");
                delayedStartLocationProvider(false, true);
                _imGPS.setImageResource(R.drawable.redsphere31);
                _imNetwork.setImageResource(R.drawable.greensphere31);
            } else {
                Log.d("GPSTester", "Startup: GPS enabled true. GPS prefs false. Network not enabled.");
                _imGPS.setImageResource(R.drawable.redsphere31);
                _imNetwork.setImageResource(R.drawable.redsphere31);
                displayToast("No network connection available.", Toast.LENGTH_LONG);
                //Inflate alert dialog
                networkFragment.show(_activity.getFragmentManager(), "NetworkAlert");
            }
        } else if (gpsProviderEnabled == false) {
            Log.d("GPSTester", "CHECK3 CHECK3 CHECK3");
            if (networkProviderEnabled == true && networkPreferences == true && isNetworkAvailable == true) {
                Log.d("GPSTester", "Startup: GPS not enabled. Network enabled. Network Prefs true.");
                delayedStartLocationProvider(false, true);
                _imGPS.setImageResource(R.drawable.redsphere31);
                _imNetwork.setImageResource(R.drawable.greensphere31);
            } else if (networkProviderEnabled == true && networkPreferences == false) {
                Log.d("GPSTester", "Startup: GPS not enabled. Network enabled. Network Prefs false.");
                _imGPS.setImageResource(R.drawable.redsphere31);
                _imNetwork.setImageResource(R.drawable.redsphere31);
                networkFragment.show(_activity.getFragmentManager(), "NetworkAlert");
            } else {
                Log.d("GPSTester", "Startup: check your GPS and network settings.");
                _imGPS.setImageResource(R.drawable.redsphere31);
                _imNetwork.setImageResource(R.drawable.redsphere31);
                networkFragment.show(_activity.getFragmentManager(), "NetworkAlert");
            }
            //Inflate alert dialog
            DialogFragment gpsFragment = new GPSAlertDialogFragment();
            gpsFragment.show(_activity.getFragmentManager(), "GPSAlert");
        }
    }
}
Also used : GPSAlertDialogFragment(com.agup.gps.fragments.GPSAlertDialogFragment) DialogFragment(android.app.DialogFragment) NetworkAlertDialogFragment(com.agup.gps.fragments.NetworkAlertDialogFragment) GPSAlertDialogFragment(com.agup.gps.fragments.GPSAlertDialogFragment) NetworkAlertDialogFragment(com.agup.gps.fragments.NetworkAlertDialogFragment)

Aggregations

DialogFragment (android.app.DialogFragment)1 GPSAlertDialogFragment (com.agup.gps.fragments.GPSAlertDialogFragment)1 NetworkAlertDialogFragment (com.agup.gps.fragments.NetworkAlertDialogFragment)1