GeoNotes.java :  » Geo » geonote » org » geonote » Android Open Source

Android Open Source » Geo » geonote 
geonote » org » geonote » GeoNotes.java
/**
 * 
 */

package org.geonote;

import org.geonote.errors.LocationException;
import org.geonote.location.BestLocationListener;

import android.app.Application;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;

import java.util.Observer;

/**
 * 
 */
public class GeoNotes extends Application {
    
    private static final String TAG = "Foursquared";
    private static final boolean DEBUG = Settings.DEBUG;
    
    
    
    private BestLocationListener mBestLocationListener = new BestLocationListener();
    
    public BestLocationListener requestLocationUpdates(boolean gps) {
        mBestLocationListener.register(
                (LocationManager) getSystemService(Context.LOCATION_SERVICE), gps);
        return mBestLocationListener;
    }

    public BestLocationListener requestLocationUpdates(Observer observer) {
        mBestLocationListener.addObserver(observer);
        mBestLocationListener.register(
                (LocationManager) getSystemService(Context.LOCATION_SERVICE), true);
        return mBestLocationListener;
    }

    public void removeLocationUpdates() {
        mBestLocationListener
                .unregister((LocationManager) getSystemService(Context.LOCATION_SERVICE));
    }

    public void removeLocationUpdates(Observer observer) {
        mBestLocationListener.deleteObserver(observer);
        this.removeLocationUpdates();
    }

    public Location getLastKnownLocation() {
        return mBestLocationListener.getLastKnownLocation();
    }

    public Location getLastKnownLocationOrThrow() throws LocationException {
        Location location = mBestLocationListener.getLastKnownLocation();
        if (location == null) {
            throw new LocationException();
        }
        return location;
    }
    
    public void clearLastKnownLocation() {
        mBestLocationListener.clearLastKnownLocation();
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.