osmdroid API解读(六)

osmdroid API解读(六)

osmdroid-android org.osmdroid.tileprovider.cachemanager 包

1. CacheManager

提供了一系列的管理瓦片在本地的缓存:

  • 下载瓦片到特定的区域
  • 清除特定区域的瓦片
  • 缓存容量信息及当前缓存的使用

注意:这些方法仅用于使用OnlineTileSourceBase瓦片源的MapView。

public class CacheManager {

    protected final ITileSource mTileSource;
    protected final IFilesystemCache mTileWriter;
    protected final int mMinZoomLevel;
    protected final int mMaxZoomLevel;
    protected Set mPendingTasks = new HashSet<>();
    protected boolean verifyCancel = true;
    ...
}

osmdroid-android org.osmdroid.tileprovider.utils包

1. ManifestUtil

用于读取Manifest的工具,目前仅有用于根据key查询meta数据的方法,用于在线地图的注册验证

public class ManifestUtil {

    public static String retrieveKey(final Context aContext, final String aKey) {

        // get the key from the manifest
        final PackageManager pm = aContext.getPackageManager();
        try {
            final ApplicationInfo info = pm.getApplicationInfo(aContext.getPackageName(),
                    PackageManager.GET_META_DATA);
            if (info.metaData == null) {
                Log.i(IMapView.LOGTAG,"Key %s not found in manifest"+aKey);
            } else {
                final String value = info.metaData.getString(aKey);
                if (value == null) {
                    Log.i(IMapView.LOGTAG,"Key %s not found in manifest"+aKey);
                } else {
                    return value.trim();
                }
            }
        } catch (final PackageManager.NameNotFoundException e) {
            Log.i(IMapView.LOGTAG,"Key %s not found in manifest" +aKey);
        }
        return "";
    }

}

2. Counters

自定义的一些用于追踪内部不同问题或错误的容器,用于解决osmdroid解决问题、发现内存泄漏等

public class Counters {
    static final String TAG="osmCounters";

    //out of memory errors
    public static int countOOM =0;

    public static int tileDownloadErrors=0;

    public static int fileCacheSaveErrors=0;

    public static int fileCacheMiss=0;

    public static int fileCacheOOM=0;
    public static int fileCacheHit=0;

    public static void printToLogcat() {
        Log.d(TAG, "countOOM " + countOOM);
        Log.d(TAG, "tileDownloadErrors " + tileDownloadErrors);
        Log.d(TAG, "fileCacheSaveErrors " + fileCacheSaveErrors);
        Log.d(TAG, "fileCacheMiss " + fileCacheMiss);
        Log.d(TAG, "fileCacheOOM " + fileCacheOOM);
        Log.d(TAG, "fileCacheHit " + fileCacheHit);
    }
    public static void reset(){
        countOOM =0;
        tileDownloadErrors=0;
        fileCacheSaveErrors=0;
        fileCacheMiss=0;
        fileCacheOOM=0;
        fileCacheHit=0;
    }
}

2. SimpleInvalidationHandler

一个简单的Handler类

public class SimpleInvalidationHandler extends Handler {
    private View mView;

    public SimpleInvalidationHandler(final View pView) {
        super();
        mView = pView;
    }

    @Override
    public void handleMessage(final Message msg) {
        switch (msg.what) {
        case MapTile.MAPTILE_SUCCESS_ID:
            if (mView!=null)
                mView.invalidate();
            break;
        }
    }

    /**
     * See https://github.com/osmdroid/osmdroid/issues/390
     *
     */
    public void destroy(){
        mView=null;
    }
}

3. SimpleRegisterReceiver

一个简单的注册接收者,用于接收广播

public class SimpleRegisterReceiver implements IRegisterReceiver {

    private Context mContext;

    public SimpleRegisterReceiver(final Context pContext) {
        super();
        mContext = pContext;
    }

    @Override
    public Intent registerReceiver(final BroadcastReceiver aReceiver, final IntentFilter aFilter) {
        return mContext.registerReceiver(aReceiver, aFilter);
    }

    @Override
    public void unregisterReceiver(final BroadcastReceiver aReceiver) {
        mContext.unregisterReceiver(aReceiver);
    }

    @Override
    public void destroy() {
        mContext=null;
    }
}

4. StorageUtils

用于管理本地内存访问、管理的类

public class StorageUtils {
    ...
}

5. StreamUtils

用于流访问、管理的工具

public class StreamUtils {
    ...
}

6. CloudmadeUtil

云端访问和管理的工具

public class CloudmadeUtil{
    ...
}

你可能感兴趣的:(osmdroid API解读(六))