Android Open Source - footprint Main Activity






From Project

Back to project page footprint.

License

The source code is released under:

MIT License

If you think the Android project footprint listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sabaware.footprint;
//  ww  w .j  a  va2  s . c om
import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.app.Activity;

import android.graphics.drawable.Drawable;

import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.ItemizedIconOverlay.OnItemGestureListener;
import org.osmdroid.views.overlay.MyLocationOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;


public class MainActivity extends Activity {
  MyItemizedOverlay myItemizedOverlay = null;
  MyLocationOverlay myLocationOverlay = null;
  MapView mapView;
  MapController mapController;
  DatabaseHelper db;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mapView = (MapView) findViewById(R.id.mapview);
    
    /*Offline Map
    //copy zip in an activity before open this activity*/
    
    //db = new DatabaseHelper(this);
    //mapView.setUseDataConnection(false);
    mapView.setUseDataConnection(true);
    
    mapController = mapView.getController();
    
    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);
    
    myLocationOverlay.runOnFirstFix(new Runnable() {
      public void run() {
        mapController.animateTo(myLocationOverlay.getMyLocation());
      }
    });
    
    //mapView.setMaxZoomLevel(20);
    mapView.setMinZoomLevel(2);
    mapController.setZoom(12);
    //mapController.setCenter(new GeoPoint(35.700523, 51.388153));
         
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapView.setClickable(false);
    
    ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
    mapView.getOverlays().add(myScaleBarOverlay);
    
    ///////////////////////////////////////////////////////////////////
    Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
    int markerWidth = marker.getIntrinsicWidth();
    int markerHeight = marker.getIntrinsicHeight();
    marker.setBounds(0, markerHeight, markerWidth, 0);
    
    ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
    myItemizedOverlay = new MyItemizedOverlay(marker, resourceProxy);
    
    mapView.getOverlays().add(myItemizedOverlay);
    
    GeoPoint myPoint1 = new GeoPoint(0*1000000, 0*1000000);
    myItemizedOverlay.addItem(myPoint1, "myPoint1", "myPoint1");
    GeoPoint myPoint2 = new GeoPoint(50*1000000, 50*1000000);
    myItemizedOverlay.addItem(myPoint2, "myPoint2", "myPoint2");
    /////////////////////////////////////////////////////////////////////
    
    ArrayList<OverlayItem> anotherOverlayItemArray = new ArrayList<OverlayItem>();

              anotherOverlayItemArray.add(new OverlayItem(
                "US", "US", new GeoPoint(38.883333, -77.016667)));
              anotherOverlayItemArray.add(new OverlayItem(
                "China", "China", new GeoPoint(39.916667, 116.383333)));
        
        ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = 
            new ItemizedIconOverlay<OverlayItem>(this, anotherOverlayItemArray, myOnItemGestureListener);
        mapView.getOverlays().add(anotherItemizedIconOverlay);
    
        


  }
  
  OnItemGestureListener<OverlayItem> myOnItemGestureListener = new OnItemGestureListener<OverlayItem>(){

    @Override
    public boolean onItemLongPress(int arg0, OverlayItem arg1) {
      
       return false;
    }
  
    @Override
    public boolean onItemSingleTapUp(int index, OverlayItem item) {
      Toast.makeText(MainActivity.this, item.mDescription + "\n" + item.mTitle + "\n"
          + item.mGeoPoint.getLatitudeE6() + " : " + item.mGeoPoint.getLongitudeE6(), 
        Toast.LENGTH_LONG).show();
      return true;
    }
     
    };
  
  @Override
  protected void onResume() {
    super.onResume();
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.enableCompass();
    myLocationOverlay.enableFollowLocation();
  }
  @Override
  protected void onPause() {
    super.onPause();
    myLocationOverlay.disableMyLocation();
    myLocationOverlay.disableCompass();
    myLocationOverlay.disableFollowLocation();
  }
  
  public void onClick(View v)
  {
    mapView.getController().animateTo(myLocationOverlay.getMyLocation());
    mapController.zoomInFixing(myLocationOverlay.getMyLocation());
  }
  
}




Java Source Code List

com.sabaware.footprint.DatabaseHelper.java
com.sabaware.footprint.MainActivity.java
com.sabaware.footprint.MyItemizedOverlay.java