Java Code Examples for android.location.GpsStatus#GPS_EVENT_FIRST_FIX

The following examples show how to use android.location.GpsStatus#GPS_EVENT_FIRST_FIX . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GpsStatusMonitor.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_STARTED:
            if (DEBUG) log("onGpsStatusChanged: GPS_EVENT_STARTED");
            break;
        case GpsStatus.GPS_EVENT_STOPPED:
            if (DEBUG) log("onGpsStatusChanged: GPS_EVENT_STOPPED");
            if (mGpsFixed) {
                mGpsFixed = false;
                notifyGpsFixChanged();
            }
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            if (DEBUG) log("onGpsStatusChanged: GPS_EVENT_FIRST_FIX");
            mGpsFixed = true;
            notifyGpsFixChanged();
            break;
    }
}
 
Example 2
Source File: GPSListenersMaker.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
        // first time fix
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            break;
        // satellite status changed
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            GpsStatus gpsStatus = mLocationManager.getGpsStatus(null);
            int maxSatellites = gpsStatus.getMaxSatellites();
            Iterator iters = gpsStatus.getSatellites().iterator();
            int count = 0;
            while (iters.hasNext() && count <= maxSatellites) {
                iters.next();
                count++;
            }
            mSatellitesNum = count;
            break;
        case GpsStatus.GPS_EVENT_STARTED:
            break;
        case GpsStatus.GPS_EVENT_STOPPED:
            break;
        default:
            break;
    }
}
 
Example 3
Source File: AndroidLocationManager.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void onGpsStatusChanged(int event) {
    boolean isGPSFix = false;
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            if (lastLocation != null) {
                isGPSFix = (SystemClock.elapsedRealtime() - lastLocationMillis) < 10000;
            }
            if (isGPSFix) { // A fix has been acquired.
                setLocationManagerStatus(AVAILABLE);
            } else { // The fix has been lost.
                setLocationManagerStatus(TEMPORARILY_UNAVAILABLE);
            }
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            setLocationManagerStatus(AVAILABLE);
            break;
    }
}
 
Example 4
Source File: TrackerService.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_STARTED:
        case GpsStatus.GPS_EVENT_STOPPED:
            mHasGPSFix = false;
            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;
    }
}
 
Example 5
Source File: GpsEventSource.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event)
{
    switch(event)
    {
        case GpsStatus.GPS_EVENT_STARTED:
        case GpsStatus.GPS_EVENT_STOPPED:
            mHasGPSFix = false;
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            mHasGPSFix = true;
            break;
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            break;
    }

    for (GpsEventListener listener : mListeners) {
        listener.onGpsStatusChanged(event);
    }
}
 
Example 6
Source File: DiagnosticsActivity.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            try {
                gpsStatus = lm.getGpsStatus(gpsStatus);
            } catch (SecurityException e) {
                e.printStackTrace();
            }

            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            // Do something.
            break;
    }
}
 
Example 7
Source File: GpsConnection.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
public void onGpsStatusChanged(int event) {
    // Logger.i(TAG, "onGpsStatusChanged(" + event + ")");
    try {
        if (locationManager == null)
            return;

        if (event == GpsStatus.GPS_EVENT_FIRST_FIX) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), first fix");
        } else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), satellite status");
            if (gpsStatus == null)
                gpsStatus = locationManager.getGpsStatus(null);
            else
                gpsStatus = locationManager.getGpsStatus(gpsStatus);

            LocationState.onGpsStatusChanged(event, gpsStatus);
        } else if (event == GpsStatus.GPS_EVENT_STARTED) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), started");
            LocationState.onGpsStatusChanged(event, null);
        } else if (event == GpsStatus.GPS_EVENT_STOPPED) {
            // Logger.w(TAG, "onGpsStatusChanged(" + event + "), stopped");
            LocationState.onGpsStatusChanged(event, null);
            // XXX this happen for unknown reason!
        }
    } catch (Exception e) {
        Logger.e(TAG, "onGpsStatusChanged(" + event + ")", e);
    }
}
 
Example 8
Source File: GPSLocationProvider.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
public void onGpsStatusChanged(int event) {
	
	if (passiveMode) {
		return;
	}
	
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            if (mLastLocation != null)
                isGpsFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < 3000;

            if (isGpsFix) { // A fix has been acquired.
            	filterNonGPSFix = true;
                // Do something.
            } else { // The fix has been lost.
            	filterNonGPSFix = false;
                // Do something.
            }

            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            // Do something.
        	isGpsFix = true;
        	filterNonGPSFix = true;

            break;
    }
}
 
Example 9
Source File: GpsActivity.java    From nearbydemo with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
	// ��ȡ��ǰ״̬
	gpsstatus = locationManager.getGpsStatus(null);
	switch (event) {
	// ��һ�ζ�λʱ���¼�
	case GpsStatus.GPS_EVENT_FIRST_FIX:
		break;
	// ��ʼ��λ���¼�
	case GpsStatus.GPS_EVENT_STARTED:
		break;
	// ����GPS����״̬�¼�
	case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
		Toast.makeText(GpsActivity.this, "GPS_EVENT_SATELLITE_STATUS", Toast.LENGTH_SHORT).show();
		Iterable<GpsSatellite> allSatellites = gpsstatus.getSatellites();
		Iterator<GpsSatellite> it = allSatellites.iterator();
		int count = 0;
		while (it.hasNext()) {
			count++;
		}
		Toast.makeText(GpsActivity.this, "Satellite Count:" + count, Toast.LENGTH_SHORT).show();
		break;
	// ֹͣ��λ�¼�
	case GpsStatus.GPS_EVENT_STOPPED:
		Log.d(TAG, "GPS_EVENT_STOPPED");
		break;
	}
}
 
Example 10
Source File: MainActivity.java    From SpeedMeter with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onGpsStatusChanged (int event) {
    switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            GpsStatus gpsStatus = mLocationManager.getGpsStatus(null);
            int satsInView = 0;
            int satsUsed = 0;
            Iterable<GpsSatellite> sats = gpsStatus.getSatellites();
            for (GpsSatellite sat : sats) {
                satsInView++;
                if (sat.usedInFix()) {
                    satsUsed++;
                }
            }
            satellite.setText(String.valueOf(satsUsed) + "/" + String.valueOf(satsInView));
            if (satsUsed == 0) {
                fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play));
                data.setRunning(false);
                status.setText("");
                stopService(new Intent(getBaseContext(), GpsServices.class));
                fab.setVisibility(View.INVISIBLE);
                refresh.setVisibility(View.INVISIBLE);
                accuracy.setText("");
                status.setText(getResources().getString(R.string.waiting_for_fix));
                firstfix = true;
            }
            break;

        case GpsStatus.GPS_EVENT_STOPPED:
            if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                showGpsDisabledDialog();
            }
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            break;
    }
}
 
Example 11
Source File: GPSController.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 4 votes vote down vote up
private static InitStatus setGPSStatusListener(){

        // IMPORTANT: The GpsStatus.Listener Interface is deprecated at API 24.
        // Reference: https://developer.android.com/reference/android/location/package-summary.html
        _gpsStatusListener = new GpsStatus.Listener() {

            @Override
            public void onGpsStatusChanged(int event) {
                Log.d(TAG, "GPS status changed.");

                // Ignore if GPS_EVENT_STARTED or GPS_EVENT_STOPPED
                if(!Thread.currentThread().isInterrupted() &&
                        (event == GpsStatus.GPS_EVENT_FIRST_FIX ||
                                event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) &&
                                        _locationManager != null){
                    sendCallback(PluginResult.Status.OK,
                            JSONHelper.satelliteDataJSON(_locationManager.getGpsStatus(null)));
                }
            }
        };

        final InitStatus status = new InitStatus();

        final Boolean gpsProviderEnabled = _locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        if(gpsProviderEnabled){
            try{
                _locationManager.addGpsStatusListener(_gpsStatusListener);
            }
            // if the ACCESS_FINE_LOCATION permission is not present
            catch(SecurityException exc){
                status.success = false;
                status.exception = exc.getMessage();
            }
        }
        else {
            //GPS not enabled
            status.success = false;
            status.error = ErrorMessages.GPS_UNAVAILABLE();
        }

        return status;
    }
 
Example 12
Source File: LocationService.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGpsStatusChanged(int event) {
    if (enableMockLocations && BuildConfig.DEBUG)
        return;

    switch (event) {
        case GpsStatus.GPS_EVENT_STARTED:
            mGpsStatus = GPS_SEARCHING;
            mTSats = 0;
            mFSats = 0;
            updateGpsStatus();
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:
            mContinuous = false;
            break;
        case GpsStatus.GPS_EVENT_STOPPED:
            tearTrack();
            mGpsStatus = GPS_OFF;
            mTSats = 0;
            mFSats = 0;
            updateGpsStatus();
            break;
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            if (mLocationManager == null)
                return;
            try {
                GpsStatus status = mLocationManager.getGpsStatus(null);
                Iterator<GpsSatellite> it = status.getSatellites().iterator();
                mTSats = 0;
                mFSats = 0;
                while (it.hasNext()) {
                    mTSats++;
                    GpsSatellite sat = it.next();
                    if (sat.usedInFix())
                        mFSats++;
                }
                if (mLastLocationMillis >= 0) {
                    if (SystemClock.elapsedRealtime() - mLastLocationMillis < 3000) {
                        mGpsStatus = GPS_OK;
                    } else {
                        if (mContinuous)
                            tearTrack();
                        mGpsStatus = GPS_SEARCHING;
                    }
                }
                updateGpsStatus();
            } catch (SecurityException e) {
                logger.error("Failed to update gps status", e);
            }
            break;
    }
}
 
Example 13
Source File: LocationService.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGpsStatusChanged(int event)
{
	if (enableMockLocations)
		return;

	switch (event)
	{
		case GpsStatus.GPS_EVENT_STARTED:
			updateProvider(LocationManager.GPS_PROVIDER, true);
			updateGpsStatus(GPS_SEARCHING, 0, 0);
			break;
		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;
	}
}