Example usage for android.location LocationManager GPS_PROVIDER

List of usage examples for android.location LocationManager GPS_PROVIDER

Introduction

In this page you can find the example usage for android.location LocationManager GPS_PROVIDER.

Prototype

String GPS_PROVIDER

To view the source code for android.location LocationManager GPS_PROVIDER.

Click Source Link

Document

Name of the GPS location provider.

Usage

From source file:com.scoreflex.Scoreflex.java

/**
 * Returns the Location as set in {@link setLocation(Location)} or the best
 * last known location of the {@link LocationManager} or null if permission
 * was not given./*w ww.j a v  a  2 s . c  o  m*/
 */

public static Location getLocation() {
    if (null != sLocation)
        return sLocation;

    Context applicationContext = getApplicationContext();

    if (applicationContext == null)
        return null;

    LocationManager locationManager = (LocationManager) applicationContext
            .getSystemService(Context.LOCATION_SERVICE);
    try {
        Location locations[] = { locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER),
                locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER),
                locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER), };

        Location best = null;
        for (int i = 0; i < locations.length; i++) {

            // If this location is null, discard
            if (null == locations[i])
                continue;

            // If we have no best yet, use this first location
            if (null == best) {
                best = locations[i];
                continue;
            }

            // If this location is significantly older, discard
            long timeDelta = locations[i].getTime() - best.getTime();
            if (timeDelta < -1000 * 60 * 2)
                continue;

            // If we have no accuracy, discard
            if (0 == locations[i].getAccuracy())
                continue;

            // If this location is less accurate, discard
            if (best.getAccuracy() < locations[i].getAccuracy())
                continue;

            best = locations[i];
        }

        return best;
    } catch (java.lang.SecurityException e) {
        // Missing permission;
        return null;
    }
}

From source file:com.nextgis.mobile.fragment.MapFragment.java

private void fillTextViews(Location location) {
    if (null == location) {
        setDefaultTextViews();/*from www.  j  a v a2  s. c  o  m*/
    } else {
        if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            String text = "";
            int satellites = location.getExtras() != null ? location.getExtras().getInt("satellites") : 0;
            if (satellites > 0)
                text += satellites;

            mStatusSource.setText(text);
            mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                    ContextCompat.getDrawable(getActivity(), R.drawable.ic_location), null, null, null);
        } else {
            mStatusSource.setText("");
            mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                    ContextCompat.getDrawable(getActivity(), R.drawable.ic_signal_wifi), null, null, null);
        }

        mStatusAccuracy.setText(String.format(Locale.getDefault(), "%.1f %s", location.getAccuracy(),
                getString(R.string.unit_meter)));
        mStatusAltitude.setText(String.format(Locale.getDefault(), "%.1f %s", location.getAltitude(),
                getString(R.string.unit_meter)));
        mStatusSpeed.setText(String.format(Locale.getDefault(), "%.1f %s/%s", location.getSpeed() * 3600 / 1000,
                getString(R.string.unit_kilometer), getString(R.string.unit_hour)));
        mStatusLatitude.setText(formatCoordinate(location.getLatitude(), R.string.latitude_caption_short));
        mStatusLongitude.setText(formatCoordinate(location.getLongitude(), R.string.longitude_caption_short));
    }
}

From source file:com.updetector.MainActivity.java

/** Make sure that GPS is enabled */
public void checkGPSEnabled() {
    if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Log.e(LOG_TAG, "GPS not enabled yet");
        /** Ask user to enable GPS */
        final AlertDialog enableGPS = new AlertDialog.Builder(this)
                .setTitle(Constants.APP_NAME + " needs access to GPS. Please enable GPS.")
                .setPositiveButton("Press here to enable GPS", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivityForResult(
                                new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                Constants.SENSOR_GPS);
                    }//www .  java 2s  . co  m
                }).setCancelable(false).create();
        /*.setNegativeButton("Skip", new DialogInterface.OnClickListener() {
           public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
           }
        })*/

        enableGPS.show();
    } else {
        Log.e(LOG_TAG, "GPS already enabled");
        //GPS already enabled
        checkBluetoothEnabled();
    }
}

From source file:com.aware.Aware_Preferences.java

/**
 * Location module settings UI/*  w  w w.ja  v a2 s  .c o  m*/
 */
private void locations() {
    final CheckBoxPreference location_gps = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_LOCATION_GPS);
    location_gps.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS).equals("true"));
    location_gps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE);
            List<String> providers = localMng.getAllProviders();

            if (!providers.contains(LocationManager.GPS_PROVIDER)) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                location_gps.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS,
                    location_gps.isChecked());
            if (location_gps.isChecked()) {
                framework.startLocations();
            } else {
                framework.stopLocations();
            }
            return true;
        }
    });

    final CheckBoxPreference location_network = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_LOCATION_NETWORK);
    location_network.setChecked(Aware
            .getSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK).equals("true"));
    location_network.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE);
            List<String> providers = localMng.getAllProviders();

            if (!providers.contains(LocationManager.NETWORK_PROVIDER)) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                location_gps.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK,
                    location_network.isChecked());
            if (location_network.isChecked()) {
                framework.startLocations();
            } else {
                framework.stopLocations();
            }
            return true;
        }
    });

    final EditTextPreference gpsInterval = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_LOCATION_GPS);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS).length() > 0) {
        gpsInterval
                .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS)
                        + " seconds");
    }
    gpsInterval.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS));
    gpsInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS,
                    (String) newValue);
            gpsInterval.setSummary((String) newValue + " seconds");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference networkInterval = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_LOCATION_NETWORK);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK).length() > 0) {
        networkInterval.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK)
                        + " seconds");
    }
    networkInterval
            .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK));
    networkInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK,
                    (String) newValue);
            networkInterval.setSummary((String) newValue + " seconds");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference gpsAccuracy = (EditTextPreference) findPreference(
            Aware_Preferences.MIN_LOCATION_GPS_ACCURACY);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY).length() > 0) {
        gpsAccuracy.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY)
                        + " meters");
    }
    gpsAccuracy.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY));
    gpsAccuracy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY,
                    (String) newValue);
            gpsAccuracy.setSummary((String) newValue + " meters");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference networkAccuracy = (EditTextPreference) findPreference(
            Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY)
            .length() > 0) {
        networkAccuracy.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY)
                        + " meters");
    }
    networkAccuracy.setText(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY));
    networkAccuracy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY,
                    (String) newValue);
            networkAccuracy.setSummary((String) newValue + " meters");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference expirateTime = (EditTextPreference) findPreference(
            Aware_Preferences.LOCATION_EXPIRATION_TIME);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME).length() > 0) {
        expirateTime.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME)
                        + " seconds");
    }
    expirateTime.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME));
    expirateTime.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME,
                    (String) newValue);
            expirateTime.setSummary((String) newValue + " seconds");
            framework.startLocations();
            return true;
        }
    });
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Registers for updates with selected location providers.
 * @param context/*from  www.j  a  v  a2  s  .  co  m*/
 */
protected void registerLocationProviders(Context context) {
    Set<String> providers = new HashSet<String>(
            mSharedPreferences.getStringSet(SettingsActivity.KEY_PREF_LOC_PROV, new HashSet<String>(Arrays
                    .asList(new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER }))));
    List<String> allProviders = mLocationManager.getAllProviders();

    mLocationManager.removeUpdates(this);

    ArrayList<String> removedProviders = new ArrayList<String>();
    for (String pr : providerLocations.keySet())
        if (!providers.contains(pr))
            removedProviders.add(pr);
    for (String pr : removedProviders)
        providerLocations.remove(pr);

    for (String pr : providers) {
        if (allProviders.indexOf(pr) >= 0) {
            if (!providerLocations.containsKey(pr)) {
                Location location = new Location("");
                providerLocations.put(pr, location);
            }
            if (!isStopped) {
                mLocationManager.requestLocationUpdates(pr, 0, 0, this);
                Log.d("MainActivity", "Registered with provider: " + pr);
            }
        } else {
            Log.w("MainActivity", "No " + pr
                    + " location provider found. Data display will not be available for this provider.");
        }
    }

    // if GPS is not selected, request location updates but don't store location
    if ((!providers.contains(LocationManager.GPS_PROVIDER)) && (!isStopped)
            && (allProviders.indexOf(LocationManager.GPS_PROVIDER) >= 0))
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}

From source file:com.davidmascharka.lips.TrackerActivity.java

/**
 * Unnecessary if you're not testing/evaluating
 * Prints out the sensor values and time at each data point
 */// www.  j ava2 s  .  c  o  m
private void printValues() {
    valuesWriter.print(accelerometerX + "," + accelerometerY + "," + accelerometerZ + "," + magneticX + ","
            + magneticY + "," + magneticZ + "," + light + "," + rotationX + "," + rotationY + "," + rotationZ
            + "," + orientation[0] + "," + orientation[1] + "," + orientation[2]);

    for (String key : wifiReadings.keySet()) {
        valuesWriter.print("," + wifiReadings.get(key));
    }

    if (location != null) {
        valuesWriter.print(
                "," + location.getLatitude() + "," + location.getLongitude() + "," + location.getAccuracy());
    } else {
        //@author Mahesh Gaya added permission if-statment
        if (ActivityCompat.checkSelfPermission(this,
                android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this,
                        android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this,
                        android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this,
                        android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            Log.i(TAG, "Permissions have NOT been granted. Requesting permissions.");
            requestMyPermissions();
        } else {
            Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network");
            location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        }
        if (location != null) {
            valuesWriter.print("," + location.getLatitude() + "," + location.getLongitude() + ","
                    + location.getAccuracy());
        } else {
            //@author Mahesh Gaya added permission if-statment
            if (ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.checkSelfPermission(this,
                            android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.checkSelfPermission(this,
                            android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.checkSelfPermission(this,
                            android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                Log.i(TAG, "Permissions have NOT been granted. Requesting permissions.");
                requestMyPermissions();
            } else {
                Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network");
                location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            }
            if (location != null) {
                valuesWriter.print("," + location.getLatitude() + "," + location.getLongitude() + ","
                        + location.getAccuracy());
            } else {
                valuesWriter.print(",?,?,?");
            }
        }
    }

    valuesWriter.print(" %" + (new Timestamp(System.currentTimeMillis())).toString());

    valuesWriter.print("\n\n");
    valuesWriter.flush();

}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Updates internal data structures when the user's selection of location providers has changed.
 * @param context//from   w w  w .ja va2 s .  c om
 */
protected static void updateLocationProviders(Context context) {
    // add overlays
    if (isMapViewReady) {
        Set<String> providers = mSharedPreferences.getStringSet(SettingsActivity.KEY_PREF_LOC_PROV,
                new HashSet<String>(Arrays.asList(
                        new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER })));

        updateLocationProviderStyles();

        mapCircles = new HashMap<String, Circle>();
        mapMarkers = new HashMap<String, Marker>();

        ArrayList<String> removedProviders = new ArrayList<String>();
        for (String pr : providerInvalidators.keySet())
            if (!providers.contains(pr))
                removedProviders.add(pr);
        for (String pr : removedProviders)
            providerInvalidators.remove(pr);

        Log.d("MainActivity", "Provider location cache: " + providerLocations.keySet().toString());

        Layers layers = mapMap.getLayerManager().getLayers();

        // remove all layers other than tile render layer from map
        for (int i = 0; i < layers.size();)
            if ((layers.get(i) instanceof TileRendererLayer) || (layers.get(i) instanceof TileDownloadLayer)) {
                i++;
            } else {
                layers.remove(i);
            }

        for (String pr : providers) {
            // no invalidator for GPS, which is invalidated through GPS status
            if ((!pr.equals(LocationManager.GPS_PROVIDER)) && (providerInvalidators.get(pr)) == null) {
                final String provider = pr;
                final Context ctx = context;
                providerInvalidators.put(pr, new Runnable() {
                    private String mProvider = provider;

                    @Override
                    public void run() {
                        if (isMapViewReady) {
                            Location location = providerLocations.get(mProvider);
                            if (location != null)
                                markLocationAsStale(location);
                            applyLocationProviderStyle(ctx, mProvider, LOCATION_PROVIDER_GRAY);
                        }
                    }
                });
            }

            String styleName = assignLocationProviderStyle(pr);
            LatLong latLong;
            float acc;
            boolean visible;
            if ((providerLocations.get(pr) != null) && (providerLocations.get(pr).getProvider() != "")) {
                latLong = new LatLong(providerLocations.get(pr).getLatitude(),
                        providerLocations.get(pr).getLongitude());
                if (providerLocations.get(pr).hasAccuracy())
                    acc = providerLocations.get(pr).getAccuracy();
                else
                    acc = 0;
                visible = true;
                if (isLocationStale(providerLocations.get(pr)))
                    styleName = LOCATION_PROVIDER_GRAY;
                Log.d("MainActivity", pr + " has " + latLong.toString());
            } else {
                latLong = new LatLong(0, 0);
                acc = 0;
                visible = false;
                Log.d("MainActivity", pr + " has no location, hiding");
            }

            // Circle layer
            Resources res = context.getResources();
            TypedArray style = res
                    .obtainTypedArray(res.getIdentifier(styleName, "array", context.getPackageName()));
            Paint fill = AndroidGraphicFactory.INSTANCE.createPaint();
            fill.setColor(style.getColor(STYLE_FILL, R.color.circle_gray_fill));
            fill.setStyle(Style.FILL);
            Paint stroke = AndroidGraphicFactory.INSTANCE.createPaint();
            stroke.setColor(style.getColor(STYLE_STROKE, R.color.circle_gray_stroke));
            stroke.setStrokeWidth(4); // FIXME: make this DPI-dependent
            stroke.setStyle(Style.STROKE);
            Circle circle = new Circle(latLong, acc, fill, stroke);
            mapCircles.put(pr, circle);
            layers.add(circle);
            circle.setVisible(visible);

            // Marker layer
            Drawable drawable = style.getDrawable(STYLE_MARKER);
            Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
            Marker marker = new Marker(latLong, bitmap, 0, -bitmap.getHeight() * 9 / 20);
            mapMarkers.put(pr, marker);
            layers.add(marker);
            marker.setVisible(visible);
            style.recycle();
        }

        // move layers into view
        updateMap();
    }
}

From source file:com.plusot.senselib.SenseMain.java

private void checkGPS() {
    if (PreferenceKey.GPSON.isTrue()) {
        final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            startUpDialogs("checkGPS.providerEnabled");
            return;
        }/*from ww  w.java  2s. co m*/
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.dialog_gps_on).setCancelable(true)
                .setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                RESULT_GPS);
                    }
                }).setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        //dialog.cancel();
                        startUpDialogs("checkGPS.dialog.negativeButton");
                    }
                }).setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface arg0) {
                        startUpDialogs("checkGPS.dialog.cancel");
                    }
                });
        final AlertDialog alert = builder.create();
        alert.show();
    } else
        startUpDialogs("checkGPS.gpsOff");
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Updates the list of styles to use for the location providers.
 * /*from w  w w .j  av  a  2  s .c  o  m*/
 * This method updates the internal list of styles to use for displaying
 * locations on the map, assigning a style to each location provider.
 * Styles that are defined in {@link SharedPreferences} are preserved. If
 * none are defined, the GPS location provider is assigned the red style
 * and the network location provider is assigned the blue style. The
 * passive location provider is not assigned a style, as it does not send
 * any locations of its own. Other location providers are assigned one of
 * the following styles: green, orange, purple. If there are more location
 * providers than styles, the same style (including red and blue) can be
 * assigned to multiple providers. The mapping is written to 
 * SharedPreferences so that it will be preserved even as available
 * location providers change.
 */
public static void updateLocationProviderStyles() {
    //FIXME: move code into assignLocationProviderStyle and use that
    List<String> allProviders = mLocationManager.getAllProviders();
    allProviders.remove(LocationManager.PASSIVE_PROVIDER);
    if (allProviders.contains(LocationManager.GPS_PROVIDER)) {
        providerStyles.put(LocationManager.GPS_PROVIDER,
                mSharedPreferences.getString(
                        SettingsActivity.KEY_PREF_LOC_PROV_STYLE + LocationManager.GPS_PROVIDER,
                        LOCATION_PROVIDER_RED));
        mAvailableProviderStyles.remove(LOCATION_PROVIDER_RED);
        allProviders.remove(LocationManager.GPS_PROVIDER);
    }
    if (allProviders.contains(LocationManager.NETWORK_PROVIDER)) {
        providerStyles.put(LocationManager.NETWORK_PROVIDER,
                mSharedPreferences.getString(
                        SettingsActivity.KEY_PREF_LOC_PROV_STYLE + LocationManager.NETWORK_PROVIDER,
                        LOCATION_PROVIDER_BLUE));
        mAvailableProviderStyles.remove(LOCATION_PROVIDER_BLUE);
        allProviders.remove(LocationManager.NETWORK_PROVIDER);
    }
    for (String prov : allProviders) {
        if (mAvailableProviderStyles.isEmpty())
            mAvailableProviderStyles.addAll(Arrays.asList(LOCATION_PROVIDER_STYLES));
        providerStyles.put(prov, mSharedPreferences.getString(SettingsActivity.KEY_PREF_LOC_PROV_STYLE + prov,
                mAvailableProviderStyles.get(0)));
        mAvailableProviderStyles.remove(providerStyles.get(prov));
    }
    ;
    SharedPreferences.Editor spEditor = mSharedPreferences.edit();
    for (String prov : providerStyles.keySet())
        spEditor.putString(SettingsActivity.KEY_PREF_LOC_PROV_STYLE + prov, providerStyles.get(prov));
    spEditor.commit();
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

@Override
protected void onResume() {
    super.onResume();
    Log.i("Activity", "Resume");

    if (needLocation) {
        Log.i("It is starting", "gps");
        if (mLocationManager != null) {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this);
        }/*from ww  w.j  av  a2  s  . com*/
        if (mErrorMessage != null) {
            if (mAlertDialog != null && !mAlertDialog.isShowing()) {
                createErrorDialog(mErrorMessage, EXIT);
            } else {
                return;
            }
        }
    }

    FormController formController = Collect.getInstance().getFormController();
    Collect.getInstance().getActivityLogger().open();

    if (mFormLoaderTask != null) {
        mFormLoaderTask.setFormLoaderListener(this);
        if (formController == null && mFormLoaderTask.getStatus() == AsyncTask.Status.FINISHED) {
            FormController fec = mFormLoaderTask.getFormController();
            if (fec != null) {
                loadingComplete(mFormLoaderTask);
            } else {
                dismissDialog(PROGRESS_DIALOG);
                FormLoaderTask t = mFormLoaderTask;
                mFormLoaderTask = null;
                t.cancel(true);
                t.destroy();
                // there is no formController -- fire MainMenu activity?
                startActivity(new Intent(this, MainMenuActivity.class));
            }
        }
    } else {
        if (formController == null) {
            // there is no formController -- fire MainMenu activity?
            startActivity(new Intent(this, MainMenuActivity.class));
            return;
        } else {
            refreshCurrentView();
        }
    }

    if (mSaveToDiskTask != null) {
        mSaveToDiskTask.setFormSavedListener(this);
    }

    // only check the buttons if it's enabled in preferences
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String navigation = sharedPreferences.getString(PreferencesActivity.KEY_NAVIGATION,
            PreferencesActivity.KEY_NAVIGATION);
    Boolean showButtons = false;
    if (navigation.contains(PreferencesActivity.NAVIGATION_BUTTONS)) {
        showButtons = true;
    }

    if (showButtons) {
        mBackButton.setVisibility(View.VISIBLE);
        mNextButton.setVisibility(View.VISIBLE);
    } else {
        mBackButton.setVisibility(View.GONE);
        mNextButton.setVisibility(View.GONE);
    }
}