Example usage for android.location GpsStatus GPS_EVENT_FIRST_FIX

List of usage examples for android.location GpsStatus GPS_EVENT_FIRST_FIX

Introduction

In this page you can find the example usage for android.location GpsStatus GPS_EVENT_FIRST_FIX.

Prototype

int GPS_EVENT_FIRST_FIX

To view the source code for android.location GpsStatus GPS_EVENT_FIRST_FIX.

Click Source Link

Document

Event sent when the GPS system has received its first fix since starting.

Usage

From source file:com.nextgis.ngm_clink_monitoring.fragments.StatusBarFragment.java

@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:

        GISApplication app = (GISApplication) getActivity().getApplication();

        if (app.getCurrentLocation() != null) {
            mIsGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < 10000;
        }/*from www  . j  a  v  a2  s  .  co m*/

        if (!mIsGPSFix) { // The fix has been lost.
            setLocationDefaultText();
            mDistView.setTextColor(Color.BLACK);

            if (isVisible()) {
                setLocationViewsText();
            }
        }

        break;

    case GpsStatus.GPS_EVENT_FIRST_FIX:
        mIsGPSFix = true;
        break;
    }
}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

@Override
public void onGpsStatusChanged(int event) {
    if (GpsStatus.GPS_EVENT_STARTED == event) {
        Log.i(TAG, "GPS started");
    } else if (GpsStatus.GPS_EVENT_STOPPED == event) {
        Log.i(TAG, "GPS stopped");
    } else if (GpsStatus.GPS_EVENT_FIRST_FIX == event) {
        Log.i(TAG, "GPS first fix");
    } else if (GpsStatus.GPS_EVENT_SATELLITE_STATUS == event) {
        if (locationManager != null) {
            final GpsStatus s = locationManager.getGpsStatus(null);
            context.satellitesInUse = 0;
            context.satellitesInView = 0;
            for (final GpsSatellite sat : s.getSatellites()) {
                if (sat.usedInFix()) {
                    context.satellitesInUse += 1;
                }/*  ww w  .j  a va 2s. com*/
                context.satellitesInView += 1;
            }
            if (BuildConfig.DEBUG) {
                Log.v(TAG, "GPS satellite status: " + context.satellitesInUse + " satellite(s) used in fix");
            }
            fireNmeaRelayContextChanged();
        }
    }
}

From source file:org.destil.gpsaveraging.MainActivity.java

@SuppressWarnings("unused")
@Override/* w ww .  ja va 2  s.c  o  m*/
public void onGpsStatusChanged(int status) {
    if (status == GpsStatus.GPS_EVENT_FIRST_FIX) {
        DisplayCoordsNoAveraging();
    } else if (status == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
        GpsStatus gpsStatus = locationManager.getGpsStatus(null);
        int all = 0;
        Iterable<GpsSatellite> satellites = gpsStatus.getSatellites();
        for (GpsSatellite satellite : satellites) {
            all++;
        }
        uiSatellites.setText(getString(R.string.satellites_info, all));
    } else if (status == GpsStatus.GPS_EVENT_STOPPED) {
        showError(R.string.gps_not_available);
    }
}

From source file:com.android.gpstest.GpsStatusFragment.java

public void onGpsStatusChanged(int event, GpsStatus status) {
    switch (event) {
    case GpsStatus.GPS_EVENT_STARTED:
        setStarted(true);//from w  ww . jav  a2  s.  c o  m
        break;

    case GpsStatus.GPS_EVENT_STOPPED:
        setStarted(false);
        break;

    case GpsStatus.GPS_EVENT_FIRST_FIX:
        break;

    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        updateStatus(status);
        break;
    }
}

From source file:com.nextgis.maplibui.service.TrackerService.java

@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
    case GpsStatus.GPS_EVENT_STARTED:
    case GpsStatus.GPS_EVENT_STOPPED:
        mHasGPSFix = false;/* w ww . j a  v  a 2 s  .c  o m*/
        break;
    case GpsStatus.GPS_EVENT_FIRST_FIX:
        mHasGPSFix = true;
        break;

    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        mSatellitesCount = 0;

        for (GpsSatellite sat : mLocationManager.getGpsStatus(null).getSatellites()) {
            if (sat.usedInFix()) {
                mSatellitesCount++;
            }
        }
        break;
    }
}

From source file:com.shadowmaps.example.GpsTestActivity.java

public void onGpsStatusChanged(int event) {
    //Log.v("GpsTestActivity", "onGpsStatusChanged");

    mStatus = mService.getGpsStatus(mStatus);

    switch (event) {
    case GpsStatus.GPS_EVENT_STARTED:
        break;/*from   w  w  w. j  a  v  a2 s. c o  m*/
    case GpsStatus.GPS_EVENT_STOPPED:
        break;
    case GpsStatus.GPS_EVENT_FIRST_FIX:
        int ttff = mStatus.getTimeToFirstFix();
        if (ttff == 0) {
            mTtff = "";
        } else {
            ttff = (ttff + 500) / 1000;
            mTtff = Integer.toString(ttff) + " sec";
        }
        break;
    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        // Stop progress bar after the first status information is obtained
        setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
        break;
    }

    for (GpsTestListener listener : mGpsTestListeners) {
        listener.onGpsStatusChanged(event, mStatus);
    }
}

From source file:com.landenlabs.all_devtool.GpsFragment.java

@Override
public void onGpsStatusChanged(int event) {
    if (getActivity() != null) {
        final LocationManager locMgr = (LocationManager) getActivity()
                .getSystemService(Context.LOCATION_SERVICE);

        try {/* w ww. ja  v a  2  s  .  c  o  m*/
            gpsStatus = locMgr.getGpsStatus(gpsStatus);
            String msg = "";
            switch (event) {
            case GpsStatus.GPS_EVENT_STARTED:
                msg = "GPS event started";
                break;
            case GpsStatus.GPS_EVENT_STOPPED:
                msg = "GPS event stopped";
                break;
            case GpsStatus.GPS_EVENT_FIRST_FIX:
                msg = "GPS first fix";
                break;
            case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
                msg = "GPS sat status";
                break;
            }

            if (TextUtils.isEmpty(msg)) {
                addMsgToDetailRow(s_colorGps, msg);
                GpsItem gpsItem = m_lastUpdates.get(STATUS_CB);
                if (gpsItem != null) {
                    gpsItem.set(System.currentTimeMillis(), msg);
                    listChanged();
                }
            }
            showProviders();
        } catch (SecurityException ex) {
            Log.e(TAG, ex.getMessage());
        }
    }
}

From source file:biz.bokhorst.bpt.BPTService.java

@Override
public void onGpsStatusChanged(int event) {
    if (locating)
        if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
            if (locationManager != null) {
                GpsStatus status = locationManager.getGpsStatus(null);
                if (status != null) {
                    int fix = 0;
                    int count = 0;
                    Iterable<GpsSatellite> sats = status.getSatellites();
                    Iterator<GpsSatellite> satI = sats.iterator();
                    while (satI.hasNext()) {
                        GpsSatellite gpssatellite = satI.next();
                        count++;//w ww. jav a2  s  .co m
                        if (gpssatellite.usedInFix())
                            fix++;
                    }
                    sendSatellites(fix, count);
                }
            }

        } else {
            if (event == GpsStatus.GPS_EVENT_FIRST_FIX)
                sendStatus(getString(R.string.GpsFix));
            else if (event == GpsStatus.GPS_EVENT_STARTED)
                sendStatus(getString(R.string.GpsStarted));
            else if (event == GpsStatus.GPS_EVENT_STOPPED)
                sendStatus(getString(R.string.GpsStopped));
            else
                sendStatus(String.format("Event %d", event));
        }
}

From source file:com.android.gpstest.GpsTestActivity.java

public void onGpsStatusChanged(int event) {
    mStatus = mService.getGpsStatus(mStatus);

    switch (event) {
    case GpsStatus.GPS_EVENT_STARTED:
        break;/*  ww  w .  j a  v a2  s  .co  m*/
    case GpsStatus.GPS_EVENT_STOPPED:
        break;
    case GpsStatus.GPS_EVENT_FIRST_FIX:
        int ttff = mStatus.getTimeToFirstFix();
        if (ttff == 0) {
            mTtff = "";
        } else {
            ttff = (ttff + 500) / 1000;
            mTtff = Integer.toString(ttff) + " sec";
        }
        break;
    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        // Stop progress bar after the first status information is obtained
        setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
        break;
    }

    // If the user is viewing the tutorial, we don't want to clutter the status screen, so return
    if (sv != null && sv.isShown()) {
        return;
    }

    for (GpsTestListener listener : mGpsTestListeners) {
        listener.onGpsStatusChanged(event, mStatus);
    }
}

From source file:com.androzic.location.LocationService.java

@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
    case GpsStatus.GPS_EVENT_STARTED:
        updateProvider(LocationManager.GPS_PROVIDER, true);
        updateGpsStatus(GPS_SEARCHING, 0, 0);
        break;//ww w.  j  a v  a2 s. c  o  m
    case GpsStatus.GPS_EVENT_FIRST_FIX:
        isContinous = false;
        break;
    case GpsStatus.GPS_EVENT_STOPPED:
        tearTrack();
        updateGpsStatus(GPS_OFF, 0, 0);
        updateProvider(LocationManager.GPS_PROVIDER, false);
        break;
    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        if (locationManager == null)
            return;
        GpsStatus gpsStatus = locationManager.getGpsStatus(null);
        Iterator<GpsSatellite> it = gpsStatus.getSatellites().iterator();
        int tSats = 0;
        int fSats = 0;
        while (it.hasNext()) {
            tSats++;
            GpsSatellite sat = (GpsSatellite) it.next();
            if (sat.usedInFix())
                fSats++;
        }
        if (SystemClock.elapsedRealtime() - lastLocationMillis < 3000) {
            updateGpsStatus(GPS_OK, fSats, tSats);
        } else {
            tearTrack();
            updateGpsStatus(GPS_SEARCHING, fSats, tSats);
        }
        break;
    }
}