This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] resource transform callback example
- Loading branch information
1 parent
2bfbe90
commit 61e2695
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...App/src/main/java/com/mapbox/mapboxsdk/testapp/activity/storage/UrlTransformActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.mapbox.mapboxsdk.testapp.activity.storage; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; | ||
import com.mapbox.mapboxsdk.storage.FileSource; | ||
import com.mapbox.mapboxsdk.storage.Resource; | ||
import com.mapbox.mapboxsdk.testapp.R; | ||
|
||
import timber.log.Timber; | ||
|
||
/** | ||
* Test activity showcasing the url transform | ||
*/ | ||
public class UrlTransformActivity extends AppCompatActivity { | ||
|
||
private MapView mapView; | ||
|
||
/** | ||
* Be sure to use an isolated class so the activity is not leaked when | ||
* the activity goes out of scope (static class in this case). | ||
* <p> | ||
* Alternatively, unregister the callback in {@link Activity#onDestroy()} | ||
*/ | ||
private static final class Transform implements FileSource.ResourceTransformCallback { | ||
@Override | ||
public String onURL(@Resource.Kind int kind, String url) { | ||
Timber.i("[%s] Could be rewriting %s", Thread.currentThread().getName(), url); | ||
return url; | ||
} | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_data_driven_style); | ||
|
||
// Initialize map as normal | ||
mapView = (MapView) findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
|
||
// Get a handle to the file source and set the resource transform | ||
FileSource.getInstance(UrlTransformActivity.this).setResourceTransform(new Transform()); | ||
|
||
mapView.getMapAsync(new OnMapReadyCallback() { | ||
@Override | ||
public void onMapReady(MapboxMap map) { | ||
Timber.i("Map loaded"); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
|
||
// Example of how to reset the transform callback | ||
FileSource.getInstance(UrlTransformActivity.this).setResourceTransform(null); | ||
|
||
mapView.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters