Android Open Source - disconnected-content-explorer-android Background Tile Provider






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;
/*from   ww  w . jav  a 2 s .co  m*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.content.Context;

import com.google.android.gms.maps.model.Tile;
import com.google.android.gms.maps.model.TileProvider;


public class BackgroundTileProvider implements  TileProvider {

    private static final int TILE_WIDTH = 256;
    private static final int TILE_HEIGHT = 256;
    private static final int BUFFER_SIZE = 16 * 1024;
    
    private Context context;
    private Tile tile;
    
    public BackgroundTileProvider(Context context) {
        this.context = context;
    }
    
    
    @Override
    public Tile getTile(int x, int y, int zoom) {        
        return getTile();
    }
    
    
    private Tile getTile() {
        if (tile == null) {
            InputStream in = null;
            ByteArrayOutputStream baos = null;

            try {
                in = context.getAssets().open("background_tile.png");
                baos = new ByteArrayOutputStream();

                int nRead;
                byte[] data = new byte[BUFFER_SIZE];

                while ((nRead = in.read(data, 0, BUFFER_SIZE)) != -1) {
                    baos.write(data, 0, nRead);
                }
                baos.flush();

                tile = new Tile(TILE_WIDTH, TILE_HEIGHT, baos.toByteArray());

            } catch (IOException ignored) {
            }  finally {
                if (in != null) try { in.close(); } catch (Exception ignored) {}
                if (baos != null) try { baos.close(); } catch (Exception ignored) {}
            }
        }
        
        return tile;
    }
}




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