@@ -0,0 +1,3720 @@
+package com.cocoahero.android.gmaps.addons.mapbox;%0A%0Aimport java.io.Closeable;%0Aimport java.io.File;%0A%0Aimport android.database.Cursor;%0Aimport android.database.sqlite.SQLiteDatabase;%0A%0Aimport com.google.android.gms.maps.model.Tile;%0Aimport com.google.android.gms.maps.model.TileProvider;%0A%0Apublic class MapBoxOfflineTileProvider implements TileProvider, Closeable %7B%0A%0A    // ------------------------------------------------------------------------%0A    // Instance Variables%0A    // ------------------------------------------------------------------------%0A%0A    private int mMinimumZoom = -1;%0A    private int mMaximumZoom = -1;%0A    private SQLiteDatabase mDatabase;%0A%0A    // ------------------------------------------------------------------------%0A    // Constructors%0A    // ------------------------------------------------------------------------%0A%0A    public MapBoxOfflineTileProvider(File file) %7B%0A        int flags = SQLiteDatabase.OPEN_READONLY %7C SQLiteDatabase.NO_LOCALIZED_COLLATORS;%0A        this.mDatabase = SQLiteDatabase.openDatabase(file.getAbsolutePath(), null, flags);%0A        this.calculateZoomConstraints();%0A    %7D%0A%0A    // ------------------------------------------------------------------------%0A    // TileProvider Interface%0A    // ------------------------------------------------------------------------%0A%0A    @Override%0A    public Tile getTile(int x, int y, int z) %7B%0A        Tile tile = NO_TILE;%0A        if (this.isZoomLevelAvailable(z) && this.isDatabaseAvailable()) %7B%0A            int row = (int) (Math.pow(2, z) - y);%0A            String%5B%5D projection = %7B %22tile_data%22 %7D;%0A            String predicate = %22tile_row = ? AND tile_column = ? AND zoom_level = ?%22;%0A            String%5B%5D values = %7B String.valueOf(row), String.valueOf(x), String.valueOf(z) %7D;%0A            Cursor c = this.mDatabase.query(%22tiles%22, projection, predicate, values, null, null, null);%0A            if (c != null) %7B%0A                c.moveToFirst();%0A                if (!c.isAfterLast()) %7B%0A                    tile = new Tile(256, 256, c.getBlob(0));%0A                %7D%0A                c.close();%0A            %7D%0A        %7D%0A        return tile;%0A    %7D%0A%0A    // ------------------------------------------------------------------------%0A    // Closeable Interface%0A    // ------------------------------------------------------------------------%0A%0A    @Override%0A    public void close() %7B%0A        if (this.mDatabase != null) %7B%0A            this.mDatabase.close();%0A            this.mDatabase = null;%0A        %7D%0A    %7D%0A%0A    // ------------------------------------------------------------------------%0A    // Public Methods%0A    // ------------------------------------------------------------------------%0A%0A    public int getMinimumZoom() %7B%0A        return this.mMinimumZoom;%0A    %7D%0A%0A    public int getMaximumZoom() %7B%0A        return this.mMaximumZoom;%0A    %7D%0A%0A    // ------------------------------------------------------------------------%0A    // Private Methods%0A    // ------------------------------------------------------------------------%0A%0A    private void calculateZoomConstraints() %7B%0A        if (this.isDatabaseAvailable()) %7B%0A            String%5B%5D projection = %7B %22min(zoom_level)%22, %22max(zoom_level)%22 %7D;%0A            Cursor c = this.mDatabase.query(%22tiles%22, projection, null, null, null, null, null);%0A            c.moveToFirst();%0A            if (!c.isAfterLast()) %7B%0A                this.mMinimumZoom = c.getInt(0);%0A                this.mMaximumZoom = c.getInt(1);%0A            %7D%0A            c.close();%0A        %7D%0A    %7D%0A%0A    private boolean isZoomLevelAvailable(int zoom) %7B%0A        return (this.mMinimumZoom %3C= zoom) && (this.mMaximumZoom %3E= zoom);%0A    %7D%0A%0A    private boolean isDatabaseAvailable() %7B%0A        return (this.mDatabase != null) && (this.mDatabase.isOpen());%0A    %7D%0A%0A%7D%0A

Add MapBoxOfflineTileProvider