Android Open Source - anti-piracy-android-app Offline Map






From Project

Back to project page anti-piracy-android-app.

License

The source code is released under:

Apache License

If you think the Android project anti-piracy-android-app 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 mil.nga.giat.asam.map;
//  w w w .  j  a v  a2 s.c  o m
import java.util.ArrayList;
import java.util.Collection;

import mil.nga.giat.asam.R;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.android.gms.maps.model.TileOverlay;
import com.google.android.gms.maps.model.TileOverlayOptions;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.MultiPolygon;

public class OfflineMap {
    private static int FILL_COLOR = 0xFFDDDDDD;
    
    private Context mContext;
    private GoogleMap mMapUI;
    private Collection<Geometry> mOfflineFeatures;
    private TileOverlay backgroundTileOverlay;
    private Collection<Polygon> offlinePolygons = null;
    private ProgressDialog progressDialog;

    public OfflineMap(Context context, GoogleMap map, Collection<Geometry> offlineFeatures) {
        this.mContext = context;
        this.mMapUI = map;
        this.mOfflineFeatures = offlineFeatures;
        
        loadOfflineMaps();
    }
    
    public void clear() {
        backgroundTileOverlay.clearTileCache();
        backgroundTileOverlay.remove();
        
        for (Polygon polygon : offlinePolygons) {
            polygon.remove();
        }
        offlinePolygons.clear();
    }
    
    private void loadOfflineMaps() {
        OfflineMapsTask task = new OfflineMapsTask();
        task.execute(mOfflineFeatures.toArray(new Geometry[mOfflineFeatures.size()]));
    }
       
    private class OfflineMapsTask extends AsyncTask<Geometry, Void, Collection<PolygonOptions>> {
        @Override
        protected void onPreExecute() {
          progressDialog = ProgressDialog.show(mContext, mContext.getString(R.string.offline_map_progress_dialog_title_text), mContext.getString(R.string.offline_map_progress_dialog_content_text), true);

            mMapUI.setMapType(GoogleMap.MAP_TYPE_NONE);
            
            BackgroundTileProvider tileProvider = new BackgroundTileProvider(mContext);           
            backgroundTileOverlay = mMapUI.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider).zIndex(1).visible(false));
            backgroundTileOverlay.setVisible(true);
        }
      
        @Override
        protected Collection<PolygonOptions> doInBackground(Geometry... features) {    
            Collection<PolygonOptions> polygons = new ArrayList<PolygonOptions>(features.length);
            for (Geometry feature : features) { 
                if (feature instanceof com.vividsolutions.jts.geom.Polygon) {      
                  polygons.add(generatePolygon((com.vividsolutions.jts.geom.Polygon)feature));                    
                }
                else if(feature instanceof com.vividsolutions.jts.geom.MultiPolygon) {                  
                  MultiPolygon multiPolygon = (MultiPolygon)feature;
                  for(int i = 0; i < multiPolygon.getNumGeometries(); i++) {
                    Geometry geometry = multiPolygon.getGeometryN(i);
                    if(geometry instanceof com.vividsolutions.jts.geom.Polygon) {
                      polygons.add(generatePolygon((com.vividsolutions.jts.geom.Polygon)geometry));
                    }
                                        
                    //nested MultiPolygons are ignored for now.  Recursive solution has performance implications.                    
                  }                  
                }
            }    
            
            return polygons;
        }

    @Override
        protected void onPostExecute(Collection<PolygonOptions> polygons) {
        offlinePolygons = new ArrayList<Polygon>(polygons.size());
          for (PolygonOptions polygon : polygons) {
                offlinePolygons.add(mMapUI.addPolygon(polygon));  
          }
          
          progressDialog.dismiss();
        }
         
        /**
         * Utility method for generating PolygonOptions from a Polygon.
         * @param pPolygon A Polygon to generate.
         * @return A fully constructed PolygonOptions object complete with style and 
         *         z-index positioning.
         */
        private PolygonOptions generatePolygon(com.vividsolutions.jts.geom.Polygon pPolygon) {
          
          PolygonOptions options = new PolygonOptions()
            .visible(true)
                .zIndex(2)
                .fillColor(FILL_COLOR)
                .strokeWidth(0);
          
          //Exterior Polygon
          for (Coordinate coordinate : pPolygon.getExteriorRing().getCoordinates()) {
                options.add(new LatLng(coordinate.y, coordinate.x));
            }
          
          //Interior Polygons
          for (int i = 0; i < pPolygon.getNumInteriorRing(); i++) {
                Coordinate[] coordinates = pPolygon.getInteriorRingN(0).getCoordinates();
                Collection<LatLng> hole = new ArrayList<LatLng>(coordinates.length);
                for (Coordinate coordinate : coordinates) {
                    hole.add(new LatLng(coordinate.y, coordinate.x));
                }                                     
                options.addHole(hole);
            }          
          
          return options;
        }    
    } 
}




Java Source Code List

mil.nga.giat.asam.AsamListActivity.java
mil.nga.giat.asam.AsamListFragment.java
mil.nga.giat.asam.AsamListReportTabletActivity.java
mil.nga.giat.asam.AsamReportActivity.java
mil.nga.giat.asam.AsamReportFragment.java
mil.nga.giat.asam.Asam.java
mil.nga.giat.asam.DisclaimerActivity.java
mil.nga.giat.asam.DisclaimerDialogFragment.java
mil.nga.giat.asam.InfoActivity.java
mil.nga.giat.asam.InfoDialogFragment.java
mil.nga.giat.asam.InfoFragment.java
mil.nga.giat.asam.LaunchScreenActivity.java
mil.nga.giat.asam.LegalActivity.java
mil.nga.giat.asam.LegalDetailsActivity.java
mil.nga.giat.asam.LegalDetailsFragment.java
mil.nga.giat.asam.LegalFragment.java
mil.nga.giat.asam.LegalTabletActivity.java
mil.nga.giat.asam.MainActivity.java
mil.nga.giat.asam.PreferencesActivity.java
mil.nga.giat.asam.PreferencesDialogFragment.java
mil.nga.giat.asam.SortAsamListDialogFragment.java
mil.nga.giat.asam.TextQueryActivity.java
mil.nga.giat.asam.TextQueryDialogFragment.java
mil.nga.giat.asam.connectivity.NetworkChangeReceiver.java
mil.nga.giat.asam.connectivity.OfflineBannerFragment.java
mil.nga.giat.asam.db.AsamDbHelper.java
mil.nga.giat.asam.jackson.deserializer.Deserializer.java
mil.nga.giat.asam.jackson.deserializer.FeatureDeserializer.java
mil.nga.giat.asam.jackson.deserializer.GeometryDeserializer.java
mil.nga.giat.asam.map.AllAsamsMapActivity.java
mil.nga.giat.asam.map.AllAsamsMapTabletActivity.java
mil.nga.giat.asam.map.BackgroundTileProvider.java
mil.nga.giat.asam.map.OfflineMap.java
mil.nga.giat.asam.map.SingleAsamMapActivity.java
mil.nga.giat.asam.map.SubregionMapActivity.java
mil.nga.giat.asam.model.AsamBean.java
mil.nga.giat.asam.model.AsamJsonParser.java
mil.nga.giat.asam.model.AsamMapClusterBean.java
mil.nga.giat.asam.model.LegalBean.java
mil.nga.giat.asam.model.SubregionBean.java
mil.nga.giat.asam.model.SubregionTextParser.java
mil.nga.giat.asam.model.TextQueryParametersBean.java
mil.nga.giat.asam.net.AsamWebService.java
mil.nga.giat.asam.util.AsamConstants.java
mil.nga.giat.asam.util.AsamListContainer.java
mil.nga.giat.asam.util.AsamLog.java
mil.nga.giat.asam.util.AsamUtils.java
mil.nga.giat.asam.util.CurrentSubregionHelper.java
mil.nga.giat.asam.util.ManifestMetaData.java
mil.nga.giat.asam.util.SyncTime.java
mil.nga.giat.asam.widget.AsamArrayAdapter.java