Esempio n. 1
0
 private Drawable getLoadingTile() {
   if (userSelectedLoadingDrawable != null) return userSelectedLoadingDrawable;
   if (mLoadingTile == null && mLoadingBackgroundColor != Color.TRANSPARENT) {
     try {
       final int tileSize =
           mTileProvider.getTileSource() != null
               ? mTileProvider.getTileSource().getTileSizePixels()
               : 256;
       final Bitmap bitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.ARGB_8888);
       final Canvas canvas = new Canvas(bitmap);
       final Paint paint = new Paint();
       canvas.drawColor(mLoadingBackgroundColor);
       paint.setColor(mLoadingLineColor);
       paint.setStrokeWidth(0);
       final int lineSize = tileSize / 16;
       for (int a = 0; a < tileSize; a += lineSize) {
         canvas.drawLine(0, a, tileSize, a, paint);
         canvas.drawLine(a, 0, a, tileSize, paint);
       }
       mLoadingTile = new BitmapDrawable(bitmap);
     } catch (final OutOfMemoryError e) {
       Log.e(IMapView.LOGTAG, "OutOfMemoryError getting loading tile");
       System.gc();
     } catch (final NullPointerException e) {
       Log.e(IMapView.LOGTAG, "NullPointerException getting loading tile");
       System.gc();
     }
   }
   return mLoadingTile;
 }
Esempio n. 2
0
 @Override
 public void initialiseLoop(final int pZoomLevel, final int pTileSizePx) {
   // make sure the cache is big enough for all the tiles
   final int numNeeded =
       (mLowerRight.y - mUpperLeft.y + 1) * (mLowerRight.x - mUpperLeft.x + 1);
   mTileProvider.ensureCapacity(numNeeded + mOvershootTileCache);
 }
Esempio n. 3
0
        @Override
        public void handleTile(
            final Canvas pCanvas,
            final int pTileSizePx,
            final MapTile pTile,
            final int pX,
            final int pY) {
          // no overflow detected here Log.d(IMapView.LOGTAG, "handleTile " + pTile.toString() +
          // ","+pX + "," + pY);
          Drawable currentMapTile = mTileProvider.getMapTile(pTile);
          boolean isReusable = currentMapTile instanceof ReusableBitmapDrawable;
          final ReusableBitmapDrawable reusableBitmapDrawable =
              isReusable ? (ReusableBitmapDrawable) currentMapTile : null;
          if (currentMapTile == null) {
            currentMapTile = getLoadingTile();
          }

          if (currentMapTile != null) {
            mTilePoint.set(pX * pTileSizePx, pY * pTileSizePx);
            mTileRect.set(
                mTilePoint.x, mTilePoint.y, mTilePoint.x + pTileSizePx, mTilePoint.y + pTileSizePx);
            if (isReusable) {
              reusableBitmapDrawable.beginUsingDrawable();
            }
            try {
              if (isReusable && !((ReusableBitmapDrawable) currentMapTile).isBitmapValid()) {
                currentMapTile = getLoadingTile();
                isReusable = false;
              }
              onTileReadyToDraw(pCanvas, currentMapTile, mTileRect);
            } finally {
              if (isReusable) reusableBitmapDrawable.finishUsingDrawable();
            }
          }

          if (DEBUGMODE) {
            mTileRect.set(
                pX * pTileSizePx,
                pY * pTileSizePx,
                pX * pTileSizePx + pTileSizePx,
                pY * pTileSizePx + pTileSizePx);
            pCanvas.drawText(
                pTile.toString(),
                mTileRect.left + 1,
                mTileRect.top + mDebugPaint.getTextSize(),
                mDebugPaint);
            pCanvas.drawLine(
                mTileRect.left, mTileRect.top, mTileRect.right, mTileRect.top, mDebugPaint);
            pCanvas.drawLine(
                mTileRect.left, mTileRect.top, mTileRect.left, mTileRect.bottom, mDebugPaint);
          }
        }
Esempio n. 4
0
 /**
  * Set whether to use the network connection if it's available.
  *
  * @param aMode if true use the network connection if it's available. if false don't use the
  *     network connection even if it's available.
  */
 public void setUseDataConnection(final boolean aMode) {
   mTileProvider.setUseDataConnection(aMode);
 }
Esempio n. 5
0
 /** Whether to use the network connection if it's available. */
 public boolean useDataConnection() {
   return mTileProvider.useDataConnection();
 }
Esempio n. 6
0
 public int getMaximumZoomLevel() {
   return mTileProvider.getMaximumZoomLevel();
 }