Android Open Source - disconnected-content-explorer-android Offline Map Loader






From Project

Back to project page disconnected-content-explorer-android.

License

The source code is released under:

MIT License

If you think the Android project disconnected-content-explorer-android 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.dice.map;
//  ww w .jav a2 s. c  o  m
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;

import mil.nga.dice.jackson.deserializer.FeatureDeserializer;
import android.content.Context;
import android.os.AsyncTask;

import com.vividsolutions.jts.geom.Geometry;

public class OfflineMapLoader {

  private Collection<Geometry> offlineFeatures = null;
  private Collection<OnOfflineFeaturesListener> offlineFeaturesListeners = new ArrayList<OnOfflineFeaturesListener>();
  private Context mContext;
  
  public interface OnOfflineFeaturesListener {
    public void onOfflineFeaturesLoaded(Collection<Geometry> offlineFeatures);
  }
  
  
  public OfflineMapLoader(Context context) {
    this.mContext = context;
    loadOfflineMap();
  }
  
  
  public void registerOfflineMapListener(OnOfflineFeaturesListener listener) {
      offlineFeaturesListeners.add(listener);
    if (offlineFeatures != null)
      listener.onOfflineFeaturesLoaded(offlineFeatures);
  }

  
  public void unregisterOfflineMapListener(OnOfflineFeaturesListener listener) {
      offlineFeaturesListeners.remove(listener);
  }
  
  
  public void loadOfflineMap() {
    OfflineMapTask task = new OfflineMapTask();
    task.execute();
  }

  
  private void setOfflineMap(Collection<Geometry> offlineFeatures) {
    this.offlineFeatures = offlineFeatures;

    for (OnOfflineFeaturesListener listener : offlineFeaturesListeners) {
      listener.onOfflineFeaturesLoaded(offlineFeatures);
    }
  }

  
  private class OfflineMapTask extends AsyncTask<Void, Void, Collection<Geometry>> {
      private static final String OFFLINE_MAP_FILENAME = "ne_110m_land.geojson";
      
    @Override
    protected Collection<Geometry> doInBackground(Void... params) {
        Collection<Geometry> geometries = new ArrayList<Geometry>();
            InputStream is = null;
            try {
                is = mContext.getAssets().open(OFFLINE_MAP_FILENAME);
                geometries = new FeatureDeserializer().parseFeatures(is);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                    }
                }
            }
            
            return geometries;
    }

    @Override
    protected void onPostExecute(Collection<Geometry> features) {
        setOfflineMap(features);
    }
  }
}




Java Source Code List

mil.nga.dice.DICE.java
mil.nga.dice.gridview.CustomGrid.java
mil.nga.dice.gridview.ReportGridActivity.java
mil.nga.dice.gridview.ReportGridFragment.java
mil.nga.dice.jackson.deserializer.Deserializer.java
mil.nga.dice.jackson.deserializer.FeatureDeserializer.java
mil.nga.dice.jackson.deserializer.GeometryDeserializer.java
mil.nga.dice.listview.CustomList.java
mil.nga.dice.listview.ReportListActivity.java
mil.nga.dice.listview.ReportListFragment.java
mil.nga.dice.listview.ReportListItem.java
mil.nga.dice.map.BackgroundTileProvider.java
mil.nga.dice.map.OfflineMapLoader.java
mil.nga.dice.map.OfflineMap.java
mil.nga.dice.map.ReportMapActivity.java
mil.nga.dice.map.ReportMapFragment.java
mil.nga.dice.report.NoteActivity.java
mil.nga.dice.report.NoteFragment.java
mil.nga.dice.report.ReportDetailActivity.java
mil.nga.dice.report.ReportDetailFragment.java
mil.nga.dice.report.ReportDropbox.java
mil.nga.dice.report.ReportManager.java
mil.nga.dice.report.ReportUnzipRunnable.java
mil.nga.dice.report.Report.java