diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java index 4d5e2552fd..139d5ae0b5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java @@ -37,18 +37,18 @@ import java.util.ArrayList; public class OfflineActivity extends AppCompatActivity implements OfflineDownloadRegionDialog.DownloadRegionDialogListener { - private final static String LOG_TAG = "OfflineActivity"; + private static final String LOG_TAG = "OfflineActivity"; // JSON encoding/decoding - public final static String JSON_CHARSET = "UTF-8"; - public final static String JSON_FIELD_REGION_NAME = "FIELD_REGION_NAME"; + public static final String JSON_CHARSET = "UTF-8"; + public static final String JSON_FIELD_REGION_NAME = "FIELD_REGION_NAME"; /* * UI elements */ - private MapView mMapView; + private MapView mapView; private MapboxMap mapboxMap; - private ProgressBar mProgressBar; + private ProgressBar progressBar; private Button downloadRegion; private Button listRegions; @@ -57,8 +57,8 @@ public class OfflineActivity extends AppCompatActivity /* * Offline objects */ - private OfflineManager mOfflineManager; - private OfflineRegion mOfflineRegion; + private OfflineManager offlineManager; + private OfflineRegion offlineRegion; @Override protected void onCreate(Bundle savedInstanceState) { @@ -75,10 +75,10 @@ public class OfflineActivity extends AppCompatActivity } // Set up map - mMapView = (MapView) findViewById(R.id.mapView); - mMapView.setStyleUrl(Style.MAPBOX_STREETS); - mMapView.onCreate(savedInstanceState); - mMapView.getMapAsync(new OnMapReadyCallback() { + mapView = (MapView) findViewById(R.id.mapView); + mapView.setStyleUrl(Style.MAPBOX_STREETS); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { Log.d(LOG_TAG, "Map is ready"); @@ -96,13 +96,13 @@ public class OfflineActivity extends AppCompatActivity }); // The progress bar - mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); + progressBar = (ProgressBar) findViewById(R.id.progress_bar); // Set up button listeners downloadRegion = (Button) findViewById(R.id.button_download_region); downloadRegion.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(View view) { handleDownloadRegion(); } }); @@ -110,43 +110,43 @@ public class OfflineActivity extends AppCompatActivity listRegions = (Button) findViewById(R.id.button_list_regions); listRegions.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(View view) { handleListRegions(); } }); // Set up the OfflineManager - mOfflineManager = OfflineManager.getInstance(this); + offlineManager = OfflineManager.getInstance(this); } @Override public void onResume() { super.onResume(); - mMapView.onResume(); + mapView.onResume(); } @Override public void onPause() { super.onPause(); - mMapView.onPause(); + mapView.onPause(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mMapView.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); } @Override protected void onDestroy() { super.onDestroy(); - mMapView.onDestroy(); + mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); - mMapView.onLowMemory(); + mapView.onLowMemory(); } @Override @@ -176,7 +176,7 @@ public class OfflineActivity extends AppCompatActivity Log.d(LOG_TAG, "handleListRegions"); // Query the DB asynchronously - mOfflineManager.listOfflineRegions(new OfflineManager.ListOfflineRegionsCallback() { + offlineManager.listOfflineRegions(new OfflineManager.ListOfflineRegionsCallback() { @Override public void onList(OfflineRegion[] offlineRegions) { // Check result @@ -214,8 +214,8 @@ public class OfflineActivity extends AppCompatActivity String json = new String(metadata, JSON_CHARSET); JSONObject jsonObject = new JSONObject(json); regionName = jsonObject.getString(JSON_FIELD_REGION_NAME); - } catch (Exception e) { - Log.e(LOG_TAG, "Failed to decode metadata: " + e.getMessage()); + } catch (Exception exception) { + Log.e(LOG_TAG, "Failed to decode metadata: " + exception.getMessage()); regionName = "Region " + offlineRegion.getID(); } @@ -240,13 +240,13 @@ public class OfflineActivity extends AppCompatActivity startProgress(); // Definition - String styleURL = mapboxMap.getStyleUrl(); + String styleUrl = mapboxMap.getStyleUrl(); LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds; double minZoom = mapboxMap.getCameraPosition().zoom; double maxZoom = mapboxMap.getMaxZoom(); float pixelRatio = this.getResources().getDisplayMetrics().density; OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition( - styleURL, bounds, minZoom, maxZoom, pixelRatio); + styleUrl, bounds, minZoom, maxZoom, pixelRatio); // Sample way of encoding metadata from a JSONObject byte[] metadata; @@ -255,17 +255,17 @@ public class OfflineActivity extends AppCompatActivity jsonObject.put(JSON_FIELD_REGION_NAME, regionName); String json = jsonObject.toString(); metadata = json.getBytes(JSON_CHARSET); - } catch (Exception e) { - Log.e(LOG_TAG, "Failed to encode metadata: " + e.getMessage()); + } catch (Exception exception) { + Log.e(LOG_TAG, "Failed to encode metadata: " + exception.getMessage()); metadata = null; } // Create region - mOfflineManager.createOfflineRegion(definition, metadata, new OfflineManager.CreateOfflineRegionCallback() { + offlineManager.createOfflineRegion(definition, metadata, new OfflineManager.CreateOfflineRegionCallback() { @Override public void onCreate(OfflineRegion offlineRegion) { Log.d(LOG_TAG, "Offline region created: " + regionName); - mOfflineRegion = offlineRegion; + OfflineActivity.this.offlineRegion = offlineRegion; launchDownload(); } @@ -278,12 +278,12 @@ public class OfflineActivity extends AppCompatActivity private void launchDownload() { // Set an observer - mOfflineRegion.setObserver(new OfflineRegion.OfflineRegionObserver() { + offlineRegion.setObserver(new OfflineRegion.OfflineRegionObserver() { @Override public void onStatusChanged(OfflineRegionStatus status) { // Compute a percentage - double percentage = status.getRequiredResourceCount() >= 0 ? - (100.0 * status.getCompletedResourceCount() / status.getRequiredResourceCount()) : + double percentage = status.getRequiredResourceCount() >= 0 + ? (100.0 * status.getCompletedResourceCount() / status.getRequiredResourceCount()) : 0.0; if (status.isComplete()) { @@ -315,7 +315,7 @@ public class OfflineActivity extends AppCompatActivity }); // Change the region state - mOfflineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE); + offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE); } /* @@ -329,18 +329,20 @@ public class OfflineActivity extends AppCompatActivity // Start and show the progress bar isEndNotified = false; - mProgressBar.setIndeterminate(true); - mProgressBar.setVisibility(View.VISIBLE); + progressBar.setIndeterminate(true); + progressBar.setVisibility(View.VISIBLE); } private void setPercentage(final int percentage) { - mProgressBar.setIndeterminate(false); - mProgressBar.setProgress(percentage); + progressBar.setIndeterminate(false); + progressBar.setProgress(percentage); } private void endProgress(final String message) { // Don't notify more than once - if (isEndNotified) return; + if (isEndNotified) { + return; + } // Enable buttons downloadRegion.setEnabled(true); @@ -348,8 +350,8 @@ public class OfflineActivity extends AppCompatActivity // Stop and hide the progress bar isEndNotified = true; - mProgressBar.setIndeterminate(false); - mProgressBar.setVisibility(View.GONE); + progressBar.setIndeterminate(false); + progressBar.setVisibility(View.GONE); // Show a toast Toast.makeText(OfflineActivity.this, message, Toast.LENGTH_LONG).show(); |