Skip to content

Commit 2809a67

Browse files
committed
updated sample provisioning
1 parent 5321223 commit 2809a67

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

add-feature-layers/src/main/java/com/esri/arcgisruntime/sample/addfeaturelayers/DownloadActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ package com.esri.arcgisruntime.sample.addfeaturelayers
33
import android.content.Intent
44
import android.os.Bundle
55
import com.esri.arcgisruntime.sample.sampleslib.DownloaderActivity
6+
import java.io.File
67

78
class DownloadActivity : DownloaderActivity() {
89
override fun onCreate(savedInstanceState: Bundle?) {
910
super.onCreate(savedInstanceState)
11+
val downloadFolder = File(
12+
getExternalFilesDir(null)?.path.toString() + File.separator + getString(R.string.app_name)
13+
)
1014
downloadAndStartSample(
1115
Intent(this, MainActivity::class.java),
1216
// get the download path of the sample
13-
getExternalFilesDir(null)?.path.toString(),
17+
downloadFolder.path,
1418
listOf(
1519
// ArcGIS Portal item containing the .mmpk mobile map package
1620
"https://www.arcgis.com/home/item.html?id=2b0f9e17105847809dfeb04e3cad69e0",

add-feature-layers/src/main/java/com/esri/arcgisruntime/sample/addfeaturelayers/MainActivity.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class MainActivity : AppCompatActivity() {
5757
activityMainBinding.mapView
5858
}
5959

60+
private val provisionPath: String by lazy {
61+
getExternalFilesDir(null)?.path.toString() + File.separator + getString(R.string.app_name)
62+
}
63+
6064
// enum to keep track of the selected source to display the feature layer
6165
enum class FeatureLayerSource(val menuPosition: Int) {
6266
SERVICE_FEATURE_TABLE(0),
@@ -134,8 +138,7 @@ class MainActivity : AppCompatActivity() {
134138
*/
135139
private suspend fun loadGeodatabase() {
136140
// locate the .geodatabase file in the device
137-
val geodatabaseFile =
138-
File(getExternalFilesDir(null), getString(R.string.geodatabase_la_trails))
141+
val geodatabaseFile = File(provisionPath, getString(R.string.geodatabase_la_trails))
139142
// instantiate the geodatabase with the file path
140143
val geodatabase = Geodatabase(geodatabaseFile.path)
141144
// load the geodatabase
@@ -163,7 +166,7 @@ class MainActivity : AppCompatActivity() {
163166
*/
164167
private suspend fun loadGeopackage() {
165168
// locate the .gpkg file in the device
166-
val geopackageFile = File(getExternalFilesDir(null), "/AuroraCO.gpkg")
169+
val geopackageFile = File(provisionPath, "/AuroraCO.gpkg")
167170
// instantiate the geopackage with the file path
168171
val geoPackage = GeoPackage(geopackageFile.path)
169172
// load the geopackage
@@ -187,7 +190,7 @@ class MainActivity : AppCompatActivity() {
187190
private suspend fun loadShapefile() {
188191
// locate the shape file in device
189192
val file = File(
190-
getExternalFilesDir(null),
193+
provisionPath,
191194
"/ScottishWildlifeTrust_ReserveBoundaries_20201102.shp"
192195
)
193196
// create a shapefile feature table from a named bundle resource

add-feature-layers/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
2-
<string name="app_name">Display feature layers</string>
2+
<string name="app_name">Add feature layers</string>
33
<string name="hint">Select a feature layer source</string>
44
<string name="sample_service_url">https://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0</string>
55
<string name="geodatabase_la_trails">/LA_Trails.geodatabase</string>

display-map-from-mobile-map-package/src/main/java/com/esri/arcgisruntime/sample/displaymapfrommobilemappackage/DownloadActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ package com.esri.arcgisruntime.sample.displaymapfrommobilemappackage
1919
import android.content.Intent
2020
import android.os.Bundle
2121
import com.esri.arcgisruntime.sample.sampleslib.DownloaderActivity
22+
import java.io.File
2223

2324
class DownloadActivity : DownloaderActivity() {
2425
override fun onCreate(savedInstanceState: Bundle?) {
2526
super.onCreate(savedInstanceState)
27+
val downloadFolder = File(
28+
getExternalFilesDir(null)?.path.toString() + File.separator + getString(R.string.app_name)
29+
)
2630
downloadAndStartSample(
2731
Intent(this, MainActivity::class.java),
2832
// get the download path of the sample
29-
getExternalFilesDir(null)?.path.toString(),
33+
downloadFolder.path,
3034
listOf(
3135
// ArcGIS Portal item containing the .mmpk mobile map package
3236
"https://www.arcgis.com/home/item.html?id=e1f3a7254cb845b09450f54937c16061"

display-map-from-mobile-map-package/src/main/java/com/esri/arcgisruntime/sample/displaymapfrommobilemappackage/MainActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ import arcgisruntime.mapping.MobileMapPackage
2828
import com.esri.arcgisruntime.sample.displaymapfrommobilemappackage.databinding.ActivityMainBinding
2929
import com.google.android.material.snackbar.Snackbar
3030
import kotlinx.coroutines.launch
31+
import java.io.File
3132

3233
class MainActivity : AppCompatActivity() {
3334

3435
private val TAG = MainActivity::class.java.simpleName
3536

37+
private val provisionPath: String by lazy {
38+
getExternalFilesDir(null)?.path.toString() + File.separator + getString(R.string.app_name)
39+
}
40+
3641
override fun onCreate(savedInstanceState: Bundle?) {
3742
super.onCreate(savedInstanceState)
3843

@@ -48,7 +53,7 @@ class MainActivity : AppCompatActivity() {
4853
lifecycle.addObserver(mapView)
4954

5055
// get the file path of the (.mmpk) file
51-
val filePath = getExternalFilesDir(null)?.path + getString(R.string.yellowstone_mmpk)
56+
val filePath = provisionPath + getString(R.string.yellowstone_mmpk)
5257

5358
// create the mobile map package
5459
val mapPackage = MobileMapPackage(filePath)

samples-lib/src/main/java/com/esri/arcgisruntime/sample/sampleslib/DownloaderActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ abstract class DownloaderActivity : AppCompatActivity() {
9595

9696
// the provision folder at the destination
9797
val provisionFolder = File(destinationPath)
98+
if (!provisionFolder.exists()) {
99+
provisionFolder.mkdirs()
100+
}
98101

99102
// suspends the coroutine until the dialog is resolved.
100103
val downloadRequired: Boolean =
@@ -103,7 +106,7 @@ abstract class DownloaderActivity : AppCompatActivity() {
103106
val provisionQuestionDialog = AlertDialog.Builder(this@DownloaderActivity)
104107
.setTitle("Download data?")
105108

106-
if (provisionFolder.exists()) {
109+
if (provisionFolder.list()?.isNotEmpty() == true) {
107110
// folder exists, prompt user to download again
108111
provisionQuestionDialog.setMessage(getString(R.string.already_provisioned))
109112
// if user taps "Re-download" data

0 commit comments

Comments
 (0)