package atila.android.friendtracker;
import java.util.List;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import atila.android.friendtracker.app.Control;
import atila.android.friendtracker.app.G;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
/*
* FriendTracker
* Copyright (c) 2009 Juan Gomez Mosquera
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. Or you can get a
* copy here: <http://www.gnu.org/licenses/>.
*/
public class FTMapActivity extends MapActivity
{
//private LocationMgr m_LocationMgr;
private MapView m_MapView;
private MapController m_MapController;
private LocationListener m_LocationListener;
//public Position m_Position; //<JGM> La posicin del mapa
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
setContentView( R.layout.map );
//Cache
Control control = G.g_Control;
control.m_Map = this;
//<JGM> Iniciamos el LocationMgr de Control
control.m_LocationMgr.Init();
//<JGM> Inicimos al usuario, ahora que podemos representarlo grficamente
control.m_User.Init();
//<JGM> activamos los listeners.
m_LocationListener = new FTMapLocationListener(this);
m_MapView = (MapView) findViewById( R.id.map );
MapController mapController = m_MapView.getController();
mapController.animateTo(control.m_User.m_Position.GetMapPoint() );
mapController.setZoom(10);
m_MapController = mapController;
m_MapView.setBuiltInZoomControls(true);
m_MapView.displayZoomControls(true);
List<Overlay> overlays = m_MapView.getOverlays();
overlays.add(control.m_User.m_Overlay);
UpdateMap();
}
@Override
public void onStart()
{
super.onStart();
String provider = G.g_Control.m_LocationMgr.m_Provider.getName();
Location loc = G.g_Control.m_LocationMgr.m_LocMgr.getLastKnownLocation(provider);
if( loc != null )
G.g_Control.m_User.m_Position.SetPosition( loc );
UpdateMap();
//<JGM> Parametrizar
G.g_Control.m_LocationMgr.m_LocMgr.requestLocationUpdates(provider,
60000, // 1min
1000, // 1km
m_LocationListener);
}
@Override
public void onStop()
{
G.g_Control.m_LocationMgr.m_LocMgr.removeUpdates(m_LocationListener);
super.onStop();
}
@Override
protected boolean isRouteDisplayed()
{
// TODO Auto-generated method stub
return false;
}
public boolean UpdateMap()
{
//<JGM> Actualizamos nuestra posicion
m_MapView.invalidate();
m_MapController.animateTo( G.g_Control.m_User.m_Position.GetMapPoint() );
return true;
}
}
|