package com.algobase.activity; import java.io.File; import android.os.Bundle; import android.os.Handler; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.location.Location; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.ProgressBar; import android.widget.Toast; import com.google.android.maps.MapActivity; /* import com.google.android.maps.MapView; import com.google.android.maps.MapController; */ import com.algobase.gpx.GpxReader; import com.algobase.stracks.R; import com.algobase.share.maps.*; import com.algobase.map.MapOverlay; public class TrackMapActivity extends MapActivity { GMapView map_view; //MyMapView map_view; ProgressBar progress_bar; //MapController map_controller; ImageButton but_left; ImageButton but_sat; ImageButton but_back; ImageButton but_right; MapOverlay map_overlay; Handler handler; private void show_toast(String txt) { Toast.makeText(this,txt, Toast.LENGTH_SHORT).show(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); boolean debug_build = false; try { PackageManager pm = getPackageManager(); PackageInfo pi = pm.getPackageInfo(getPackageName(), 0); debug_build = ((pi.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); } catch (Exception e) { } setContentView(R.layout.track_map); ViewGroup root_view = (ViewGroup)findViewById(R.id.track_map); handler = new Handler(); String api_release_key = getResources().getString(R.string.api_release_key); String api_debug_key = getResources().getString(R.string.api_debug_key); //map_view = (MapView)findViewById(R.id.mapview); if (debug_build) map_view = new GMapView(this,api_debug_key); else map_view = new GMapView(this,api_release_key); /* map_view = new MyMapView(this); */ //map_view.setClickable(false); map_view.setClickable(true); map_view.setSatellite(false); root_view.addView(map_view,0); progress_bar = (ProgressBar)findViewById(R.id.progress_bar); //map_view.setBuiltInZoomControls(true); //map_view.getZoomButtonsController().setAutoDismissed(false); /* map_controller = map_view.getController(); map_controller.setZoom(12); */ map_view.setZoom(12); map_overlay = new MapOverlay(null,map_view); map_overlay.set_animation(false); map_overlay.set_track_width(8); map_overlay.set_node_width(10); //map_view.getOverlays().add(map_overlay); map_view.setOverlay(map_overlay); // buttons but_sat = (ImageButton)findViewById(R.id.button_sat); but_sat.getBackground().setAlpha(150); but_sat.setOnClickListener(new OnClickListener() { public void onClick(View v) { boolean sat = map_view.isSatellite(); map_view.setSatellite(!sat); } }); but_back = (ImageButton)findViewById(R.id.button_back); but_back.getBackground().setAlpha(150); but_back.setOnClickListener(new OnClickListener() { public void onClick(View v) { map_overlay.zoomToPath(); } }); but_left = (ImageButton)findViewById(R.id.button_left); but_left.getBackground().setAlpha(150); but_left.setOnClickListener(new OnClickListener() { public void onClick(View v) { //map_controller.zoomOut(); map_view.zoomOut(); } }); but_right = (ImageButton)findViewById(R.id.button_right); but_right.getBackground().setAlpha(150); but_right.setOnClickListener(new OnClickListener() { public void onClick(View v) { //map_controller.zoomIn(); map_view.zoomIn(); } }); Bundle bundle = this.getIntent().getExtras(); String file_name = bundle.getString("track_file"); String track_name = bundle.getString("track_name"); final File gpx_file = new File(file_name); setTitle(track_name); /* progress_bar.setVisibility(View.INVISIBLE); */ new Thread() { final GpxReader gpx = new GpxReader(gpx_file) { public boolean point_handler(final Location loc) { map_overlay.addCoursePoint(loc); /* handler.post(new Runnable() { public void run() { //map_overlay.addTrackPoint(loc); map_overlay.addCoursePoint(loc); //map_overlay.zoomToPath(); //map_view.invalidate(); } }); */ return true; } public void track_handler() { handler.post(new Runnable() { public void run() { map_overlay.zoomToPath(); } }); } }; public void run() { gpx.read(); //setTitle(map_overlay.bounding_box()); try { sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.post(new Runnable() { public void run() { progress_bar.setVisibility(View.INVISIBLE); //map_view.getOverlays().add(map_overlay); map_overlay.zoomToPath(); } }); } }.start(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); show_toast("onConfigurationChanged"); map_overlay.zoomToPath(); } @Override protected boolean isRouteDisplayed() { return false; } }