Advertisement
Guest User

osmdroid user-agent

a guest
Jan 19th, 2014
2,762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.75 KB | None | 0 0
  1. Index: osmdroid-android/src/main/java/org/osmdroid/http/HttpClientFactory.java
  2. ===================================================================
  3. --- osmdroid-android/src/main/java/org/osmdroid/http/HttpClientFactory.java (revision 1400)
  4. +++ osmdroid-android/src/main/java/org/osmdroid/http/HttpClientFactory.java (working copy)
  5. @@ -2,6 +2,7 @@
  6.  
  7.  import org.apache.http.client.HttpClient;
  8.  import org.apache.http.impl.client.DefaultHttpClient;
  9. +import org.apache.http.params.CoreProtocolPNames;
  10.  
  11.  /**
  12.   * Factory class for creating an instance of {@link HttpClient}.
  13. @@ -35,5 +36,11 @@
  14.     public static HttpClient createHttpClient() {
  15.         return mFactoryInstance.createHttpClient();
  16.     }
  17. +  
  18. +   public static HttpClient createHttpClient(String pUserAgent) {
  19. +       HttpClient httpClient = mFactoryInstance.createHttpClient();
  20. +       httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, pUserAgent);
  21. +       return httpClient;
  22. +   }
  23.  
  24.  }
  25. Index: osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTileProviderBasic.java
  26. ===================================================================
  27. --- osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTileProviderBasic.java  (revision 1400)
  28. +++ osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTileProviderBasic.java  (working copy)
  29. @@ -36,7 +36,7 @@
  30.      */
  31.     public MapTileProviderBasic(final Context pContext, final ITileSource pTileSource) {
  32.         this(new SimpleRegisterReceiver(pContext), new NetworkAvailabliltyCheck(pContext),
  33. -               pTileSource);
  34. +               pTileSource, pContext);
  35.     }
  36.  
  37.     /**
  38. @@ -43,7 +43,8 @@
  39.      * Creates a {@link MapTileProviderBasic}.
  40.      */
  41.     public MapTileProviderBasic(final IRegisterReceiver pRegisterReceiver,
  42. -           final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource) {
  43. +           final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource,
  44. +           final Context pContext) {
  45.         super(pTileSource, pRegisterReceiver);
  46.  
  47.         final TileWriter tileWriter = new TileWriter();
  48. @@ -57,7 +58,7 @@
  49.         mTileProviderList.add(archiveProvider);
  50.  
  51.         final MapTileDownloader downloaderProvider = new MapTileDownloader(pTileSource, tileWriter,
  52. -               aNetworkAvailablityCheck);
  53. +               aNetworkAvailablityCheck, "osmdroid (" + pContext.getPackageName() + ")");
  54.         mTileProviderList.add(downloaderProvider);
  55.     }
  56.  }
  57. Index: osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/MapTileDownloader.java
  58. ===================================================================
  59. --- osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/MapTileDownloader.java (revision 1400)
  60. +++ osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/MapTileDownloader.java (working copy)
  61. @@ -56,6 +56,8 @@
  62.     private final AtomicReference<OnlineTileSourceBase> mTileSource = new AtomicReference<OnlineTileSourceBase>();
  63.  
  64.     private final INetworkAvailablityCheck mNetworkAvailablityCheck;
  65. +  
  66. +   private final String mUserAgent;
  67.  
  68.     // ===========================================================
  69.     // Constructors
  70. @@ -62,28 +64,31 @@
  71.     // ===========================================================
  72.  
  73.     public MapTileDownloader(final ITileSource pTileSource) {
  74. -       this(pTileSource, null, null);
  75. +       this(pTileSource, null, null, null);
  76.     }
  77.  
  78.     public MapTileDownloader(final ITileSource pTileSource, final IFilesystemCache pFilesystemCache) {
  79. -       this(pTileSource, pFilesystemCache, null);
  80. +       this(pTileSource, pFilesystemCache, null, null);
  81.     }
  82.  
  83.     public MapTileDownloader(final ITileSource pTileSource,
  84.             final IFilesystemCache pFilesystemCache,
  85. -           final INetworkAvailablityCheck pNetworkAvailablityCheck) {
  86. +           final INetworkAvailablityCheck pNetworkAvailablityCheck,
  87. +           final String pUserAgent) {
  88.         this(pTileSource, pFilesystemCache, pNetworkAvailablityCheck,
  89. -               NUMBER_OF_TILE_DOWNLOAD_THREADS, TILE_DOWNLOAD_MAXIMUM_QUEUE_SIZE);
  90. +               NUMBER_OF_TILE_DOWNLOAD_THREADS, TILE_DOWNLOAD_MAXIMUM_QUEUE_SIZE, pUserAgent);
  91.     }
  92.  
  93.     public MapTileDownloader(final ITileSource pTileSource,
  94.             final IFilesystemCache pFilesystemCache,
  95.             final INetworkAvailablityCheck pNetworkAvailablityCheck, int pThreadPoolSize,
  96. -           int pPendingQueueSize) {
  97. +           int pPendingQueueSize,
  98. +           final String pUserAgent) {
  99.         super(pThreadPoolSize, pPendingQueueSize);
  100.  
  101.         mFilesystemCache = pFilesystemCache;
  102.         mNetworkAvailablityCheck = pNetworkAvailablityCheck;
  103. +       mUserAgent = pUserAgent;
  104.         setTileSource(pTileSource);
  105.     }
  106.  
  107. @@ -180,7 +185,7 @@
  108.                     return null;
  109.                 }
  110.  
  111. -               final HttpClient client = HttpClientFactory.createHttpClient();
  112. +               final HttpClient client = HttpClientFactory.createHttpClient(mUserAgent);
  113.                 final HttpUriRequest head = new HttpGet(tileURLString);
  114.                 final HttpResponse response = client.execute(head);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement