diff --git a/MapboxAndroidSDK/build.gradle b/MapboxAndroidSDK/build.gradle index 0c46a84..5a6e920 100644 --- a/MapboxAndroidSDK/build.gradle +++ b/MapboxAndroidSDK/build.gradle @@ -21,14 +21,14 @@ repositories { } dependencies { - compile 'com.vividsolutions:jts:1.13' - compile 'com.android.support:support-v4:23.1.1' - compile 'com.squareup.okhttp:okhttp:2.4.0' - compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0' - compile 'com.nineoldandroids:library:2.4.0' - compile 'com.jakewharton:disklrucache:2.0.2' - compile 'commons-codec:commons-codec:1.10' - compile 'commons-io:commons-io:2.4' + implementation 'com.vividsolutions:jts:1.13' + implementation "com.android.support:appcompat-v7:28.0.0" + implementation 'com.squareup.okhttp:okhttp:2.4.0' + implementation 'com.squareup.okhttp:okhttp-urlconnection:2.4.0' + implementation 'com.nineoldandroids:library:2.4.0' + implementation 'com.jakewharton:disklrucache:2.0.2' + implementation 'commons-codec:commons-codec:1.10' + implementation 'commons-io:commons-io:2.4' } android { @@ -85,7 +85,7 @@ android.libraryVariants.all { variant -> destinationDir = new File(destinationDir, variant.baseName) source = files(variant.javaCompile.source) ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" - classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) + doFirst { classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) } options.links("http://docs.oracle.com/javase/7/docs/api/") options.links("http://d.android.com/reference/") exclude '**/R.html', '**/R.*.html' diff --git a/MapboxAndroidSDK/gradle.properties b/MapboxAndroidSDK/gradle.properties index 78b0f98..e6325dd 100644 --- a/MapboxAndroidSDK/gradle.properties +++ b/MapboxAndroidSDK/gradle.properties @@ -13,9 +13,9 @@ POM_DEVELOPER_ID=mapbox POM_DEVELOPER_NAME=Mapbox ANDROID_MIN_SDK=9 -ANDROID_BUILD_TARGET_SDK_VERSION=22 -ANDROID_BUILD_TOOLS_VERSION=22.0.1 -ANDROID_BUILD_SDK_VERSION=22 +ANDROID_BUILD_TARGET_SDK_VERSION=29 +ANDROID_BUILD_TOOLS_VERSION=28.0.3 +ANDROID_BUILD_SDK_VERSION=29 POM_NAME=Mapbox SDK POM_ARTIFACT_ID=mapbox-android-sdk diff --git a/MapboxAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java b/MapboxAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java index 96b8002..ba750b5 100644 --- a/MapboxAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java +++ b/MapboxAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java @@ -92,7 +92,7 @@ public float getCurrentSpan() { if (mCurrLen == -1) { final float cvx = mCurrFingerDiffX; final float cvy = mCurrFingerDiffY; - mCurrLen = FloatMath.sqrt(cvx * cvx + cvy * cvy); + mCurrLen = (float) Math.sqrt(cvx * cvx + cvy * cvy); } return mCurrLen; } @@ -107,7 +107,7 @@ public float getPreviousSpan() { if (mPrevLen == -1) { final float pvx = mPrevFingerDiffX; final float pvy = mPrevFingerDiffY; - mPrevLen = FloatMath.sqrt(pvx * pvx + pvy * pvy); + mPrevLen = (float) Math.sqrt(pvx * pvx + pvy * pvy); } return mPrevLen; } diff --git a/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/tileprovider/modules/NetworkAvailabilityCheck.java b/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/tileprovider/modules/NetworkAvailabilityCheck.java index 09d27f5..edd84fe 100644 --- a/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/tileprovider/modules/NetworkAvailabilityCheck.java +++ b/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/tileprovider/modules/NetworkAvailabilityCheck.java @@ -25,21 +25,21 @@ public boolean getNetworkAvailable() { final NetworkInfo networkInfo = mConnectionManager.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isAvailable(); } - - public boolean getWiFiNetworkAvailable() { - final NetworkInfo wifi = mConnectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - return wifi != null && wifi.isAvailable(); - } - - public boolean getCellularDataNetworkAvailable() { - final NetworkInfo mobile = - mConnectionManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); - return mobile != null && mobile.isAvailable(); - } - - public boolean getRouteToPathExists(final int hostAddress) { - return (mConnectionManager.requestRouteToHost(ConnectivityManager.TYPE_WIFI, hostAddress) - || mConnectionManager.requestRouteToHost(ConnectivityManager.TYPE_MOBILE, - hostAddress)); - } +// +// public boolean getWiFiNetworkAvailable() { +// final NetworkInfo wifi = mConnectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); +// return wifi != null && wifi.isAvailable(); +// } +// +// public boolean getCellularDataNetworkAvailable() { +// final NetworkInfo mobile = +// mConnectionManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); +// return mobile != null && mobile.isAvailable(); +// } +// +// public boolean getRouteToPathExists(final int hostAddress) { +// return (mConnectionManager.requestRouteToHost(ConnectivityManager.TYPE_WIFI, hostAddress) +// || mConnectionManager.requestRouteToHost(ConnectivityManager.TYPE_MOBILE, +// hostAddress)); +// } } diff --git a/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/safecanvas/SafeTranslatedCanvas.java b/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/safecanvas/SafeTranslatedCanvas.java index ea4ab51..8cfb47f 100644 --- a/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/safecanvas/SafeTranslatedCanvas.java +++ b/MapboxAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/safecanvas/SafeTranslatedCanvas.java @@ -119,13 +119,13 @@ public boolean clipRect(final Rect rect) { @Override public boolean clipRegion(final Region region, final Op op) { region.translate(xOffset, yOffset); - return getWrappedCanvas().clipRegion(region, op); + return true; } @Override public boolean clipRegion(final Region region) { region.translate(xOffset, yOffset); - return getWrappedCanvas().clipRegion(region); + return true; } @Override @@ -478,7 +478,7 @@ public int save() { @Override public int save(int saveFlags) { - return getWrappedCanvas().save(saveFlags); + return getWrappedCanvas().save(); } @Override diff --git a/app/build.gradle b/app/build.gradle index 666118f..46c97d1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,17 +1,17 @@ apply plugin: 'com.android.application' ext { - supportLibVersion = '23.1.1' + supportLibVersion = '28.0.0' } android { - compileSdkVersion 26 + compileSdkVersion 29 buildToolsVersion '28.0.3' defaultConfig { applicationId "org.redcross.openmapkit" minSdkVersion 16 - targetSdkVersion 26 + targetSdkVersion 29 versionCode 23 versionName "1.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -22,7 +22,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } packagingOptions { exclude 'LICENSE.txt' exclude 'META-INF/LICENSE.txt' @@ -35,19 +38,16 @@ repositories { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile group: 'com.google.guava', name: 'guava', version: '18.0' - compile 'org.apache.commons:commons-lang3:3.0' - compile 'commons-io:commons-io:2.4' - compile 'com.nanohttpd:nanohttpd-webserver:2.1.1' - compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar' - compile 'com.google.zxing:core:3.2.1' - compile project(':MapboxAndroidSDK') - compile "com.android.support:support-annotations:${supportLibVersion}" - compile "com.android.support:support-v4:${supportLibVersion}" - compile "com.android.support:appcompat-v7:${supportLibVersion}" - compile "com.android.support:design:${supportLibVersion}" - compile "com.android.support:cardview-v7:${supportLibVersion}" - compile "com.android.support:recyclerview-v7:${supportLibVersion}" - androidTestCompile 'com.android.support.test:runner:0.5' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation group: 'com.google.guava', name: 'guava', version: '18.0' + implementation 'org.apache.commons:commons-lang3:3.0' + implementation 'commons-io:commons-io:2.6' + implementation 'com.nanohttpd:nanohttpd-webserver:2.1.1' + implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar' + implementation 'com.google.zxing:core:3.3.0' + implementation project(':MapboxAndroidSDK') + implementation "com.android.support:support-annotations:${supportLibVersion}" + implementation "com.android.support:design:${supportLibVersion}" + //noinspection GradleCompatible + implementation "com.android.support:appcompat-v7:28.0.0" } diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json new file mode 100644 index 0000000..720c588 --- /dev/null +++ b/app/release/output-metadata.json @@ -0,0 +1,18 @@ +{ + "version": 2, + "artifactType": { + "type": "APK", + "kind": "Directory" + }, + "applicationId": "org.redcross.openmapkit", + "variantName": "processReleaseResources", + "elements": [ + { + "type": "SINGLE", + "filters": [], + "versionCode": 23, + "versionName": "1.2", + "outputFile": "app-release.apk" + } + ] +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fd45f70..963140a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,6 +15,7 @@ android:icon="@mipmap/ic_omk_nobg_green" android:label="@string/app_name" android:largeHeap="true" + android:requestLegacyExternalStorage="true" android:theme="@style/AppTheme"> * The key of the outer map is to the tag in question */ private Map> hideMap = new HashMap<>(); @@ -41,7 +40,7 @@ public class Constraints { /** * Contains a map of constraint keys with the key value pairs of the * OSM Element conditions in which a tag view should be shown. - * + *

* The key of the outer map is to the tag in question. */ private Map> showMap = new HashMap<>(); @@ -99,7 +98,7 @@ public Set requiredTagsNotMet(OSMElement osmElement) { if (ODKCollectHandler.isODKCollectMode()) { Map tags = osmElement.getTags(); - Collection odkTags = ODKCollectHandler.getODKCollectData().getRequiredTags(); + Collection odkTags = ODKCollectHandler.getODKCollectData().getRequiredTags(); for (ODKTag odkTag : odkTags) { String odkTagKey = odkTag.getKey(); if (cascadeBooleanTagConstraint(odkTagKey, "required", false)) { @@ -174,7 +173,7 @@ public boolean tagShouldBeShown(String tagKey, OSMElement osmElement) { /** * If the tag has an implicit value, it returns it. * Otherwise, it returns null. - * + *

* This is how to test if the tag should be considered implicit. * * @param tagKey diff --git a/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java b/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java index 4557fea..773fb88 100644 --- a/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java +++ b/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java @@ -8,7 +8,6 @@ import com.google.common.io.Files; import org.apache.commons.io.FilenameUtils; -import org.json.JSONObject; import java.io.BufferedReader; import java.io.File; @@ -35,7 +34,7 @@ public class ExternalStorage { /** * Directories used by the app. - * * * + * * * */ public static final String APP_DIR = "openmapkit"; public static final String MBTILES_DIR = "mbtiles"; @@ -48,6 +47,7 @@ public class ExternalStorage { * The name of the form specific constraints file if it were to be delivered as an ODK media file */ public static final String CONSTRAINTS_FILE_NAME_ON_ODK = "omk-constraints.json"; + public static final String TAG = "apple"; /** * Creating the application directory structure. @@ -59,11 +59,11 @@ public static void checkOrCreateAppDirs() { File storageDir = Environment.getExternalStorageDirectory(); File appDir = new File(storageDir, APP_DIR); - if(!appDir.exists()) { + if (!appDir.exists()) { appDir.mkdirs(); // mkdirs is mkdir -p } File mbtilesDir = new File(appDir, MBTILES_DIR); - if(!mbtilesDir.exists()) { + if (!mbtilesDir.exists()) { mbtilesDir.mkdirs(); } File osmDir = new File(appDir, OSM_DIR); @@ -95,11 +95,11 @@ public static String getOSMDir() { + APP_DIR + "/" + OSM_DIR + "/"; } - + public static String getOSMDirRelativeToExternalDir() { return "/" + APP_DIR + "/" + OSM_DIR + "/"; } - + public static File[] fetchOSMXmlFiles() { List osms = allDeploymentOSMXmlFiles(); String dirPath = getOSMDir(); @@ -108,26 +108,27 @@ public static File[] fetchOSMXmlFiles() { Collections.addAll(osms, otherOsms); return osms.toArray(new File[osms.size()]); } - + public static String[] fetchOSMXmlFileNames() { File[] files = fetchOSMXmlFiles(); int len = files.length; - String [] names = new String[len]; - for (int i=0; i < len; ++i) { + String[] names = new String[len]; + for (int i = 0; i < len; ++i) { names[i] = files[i].getName(); } return names; } - + public static File[] fetchMBTilesFiles() { List mbtiles = allDeploymentMBTilesFiles(); String dirPath = getMBTilesDir(); File dir = new File(dirPath); - File[] otherMBTiles = dir.listFiles(); - Collections.addAll(mbtiles, otherMBTiles); + File[] otherMBTiles = dir.listFiles(); + if (otherMBTiles != null) + Collections.addAll(mbtiles, otherMBTiles); return mbtiles.toArray(new File[mbtiles.size()]); } - + /** * Checking if external storage is available for read and write */ @@ -140,7 +141,7 @@ public static boolean isWritable() { } /** - * Checking if external storage is available to read. + * Checking if external storage is available to read. */ public static boolean isReadable() { String state = Environment.getExternalStorageState(); @@ -210,15 +211,16 @@ public static List allDeploymentMBTilesFiles() { File storageDir = Environment.getExternalStorageDirectory(); File deploymentsDir = new File(storageDir, APP_DIR + "/" + DEPLOYMENTS_DIR); File[] deployments = deploymentsDir.listFiles(); - for (File deploymentDir : deployments) { - File[] files = deploymentDir.listFiles(); - for (File f : files) { - String ext = FilenameUtils.getExtension(f.getPath()); - if (ext.equals("mbtiles")) { - deploymentMBTilesFiles.add(f); + if (deployments != null) + for (File deploymentDir : deployments) { + File[] files = deploymentDir.listFiles(); + for (File f : files) { + String ext = FilenameUtils.getExtension(f.getPath()); + if (ext.equals("mbtiles")) { + deploymentMBTilesFiles.add(f); + } } } - } return deploymentMBTilesFiles; } @@ -271,7 +273,7 @@ public static Map deploymentDownloadedFiles(String deploymentName) if (files == null || files.length == 0) return deploymentFiles; for (File f : files) { String ext = FilenameUtils.getExtension(f.getPath()); - if ( ext.equals("mbtiles") || ext.equals("osm") || ext.equals("geojson") ) { + if (ext.equals("mbtiles") || ext.equals("osm") || ext.equals("geojson")) { deploymentFiles.put(f.getName(), f); } } @@ -374,23 +376,45 @@ public static File fetchConstraintsFile(String formName) { return new File(constraintsDir, formName + ".json"); } + public static File fetchConstraintsFileFromODKNew(String formName) { + File storageDir = Environment.getExternalStorageDirectory(); + File appDir = new File(storageDir, "Android"); + File appDir1 = new File(appDir, "data"); + File constraintsDir = new File(appDir1, "org.odk.collect.android"); + File appDir2 = new File(constraintsDir, constraintsDir.list()[0]); + File appDir3 = new File(appDir2, appDir2.list()[0]); + File appDir4 = new File(appDir3, appDir3.list()[0]); + File appDir5 = new File(appDir4, "forms"); + File appDir6 = new File(appDir5, formName + "-media"); + return new File(appDir6, appDir6.list()[0]); + } + /** * This method attempts to fetch the form's constraints file from ODK's media directory for the * form. If the constraints file is found on ODK's media directory for the form, its contents * will overwrite whatever is in OMK's constraints file for the form * - * @param formFileName The name of the ODK form + * @param formFileName The name of the ODK form * @return TRUE if there was a successful copy */ public static boolean copyFormConstraintsFromOdk(String formFileName) { String sdCardPath = Environment.getExternalStorageDirectory().getAbsolutePath(); - if(formFileName != null) { + if (formFileName != null) { + //new method to support moving constraints from odk inside Android/Data/org.odk.collect.android for Android 10 and below devices + //this doesn't apply to android 11 due to folder not made by odk app itself + try { + File formConstraintsFileTesting = ExternalStorage.fetchConstraintsFileFromODKNew(formFileName); + File omkConstraintsFile = fetchConstraintsFile(formFileName); + Files.copy(formConstraintsFileTesting, omkConstraintsFile); + return true; + } catch (Exception e) { + } String mediaDirPath = sdCardPath + "/odk/forms/" + formFileName + "-media"; File mediaDirectory = new File(mediaDirPath); - if(mediaDirectory.exists() && mediaDirectory.isDirectory()) { + if (mediaDirectory.exists() && mediaDirectory.isDirectory()) { String constraintsFilePath = mediaDirPath + "/" + CONSTRAINTS_FILE_NAME_ON_ODK; File odkConstraintsFile = new File(constraintsFilePath); - if(odkConstraintsFile.exists() && !odkConstraintsFile.isDirectory()) { + if (odkConstraintsFile.exists() && !odkConstraintsFile.isDirectory()) { File omkConstraintsFile = fetchConstraintsFile(formFileName); try { Files.copy(odkConstraintsFile, omkConstraintsFile); @@ -401,7 +425,6 @@ public static boolean copyFormConstraintsFromOdk(String formFileName) { } } } - return false; } @@ -419,7 +442,7 @@ public static String[] getStorageDirectories() { List typeWL = Arrays.asList("vfat", "exfat", "sdcardfs", "fuse"); List typeBL = Arrays.asList("tmpfs"); - String[] mountWL = { "/mnt", "/Removable" }; + String[] mountWL = {"/mnt", "/Removable"}; String[] mountBL = { "/mnt/secure", "/mnt/shell", @@ -427,16 +450,16 @@ public static String[] getStorageDirectories() { "/mnt/obb", "/mnt/media_rw/extSdCard", "/mnt/media_rw/sdcard", - "/storage/emulated" }; + "/storage/emulated"}; String[] deviceWL = { "/dev/block/vold", "/dev/fuse", - "/mnt/media_rw/extSdCard" }; + "/mnt/media_rw/extSdCard"}; try { bufReader = new BufferedReader(new FileReader("/proc/mounts")); String line; - while((line = bufReader.readLine()) != null) { + while ((line = bufReader.readLine()) != null) { StringTokenizer tokens = new StringTokenizer(line, " "); String device = tokens.nextToken(); @@ -456,15 +479,14 @@ public static String[] getStorageDirectories() { for (int i = 0; i < list.size(); i++) { dirs[i] = list.get(i); } - } - catch (FileNotFoundException e) {} - catch (IOException e) {} - finally { + } catch (FileNotFoundException e) { + } catch (IOException e) { + } finally { if (bufReader != null) { try { bufReader.close(); + } catch (IOException e) { } - catch (IOException e) {} } } return dirs; @@ -478,7 +500,7 @@ public static String[] getStorageDirectories() { */ public static File getSDCardDirWithExternalFallback() { String[] dirs = getStorageDirectories(); - return new File(dirs[dirs.length-1]); + return new File(dirs[dirs.length - 1]); } } diff --git a/app/src/main/java/org/redcross/openmapkit/MapActivity.java b/app/src/main/java/org/redcross/openmapkit/MapActivity.java index 209233f..400365e 100644 --- a/app/src/main/java/org/redcross/openmapkit/MapActivity.java +++ b/app/src/main/java/org/redcross/openmapkit/MapActivity.java @@ -12,6 +12,7 @@ import android.graphics.Rect; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; @@ -63,7 +64,7 @@ public class MapActivity extends AppCompatActivity implements OSMSelectionListen protected static final String PREVIOUS_LAT = "org.redcross.openmapkit.PREVIOUS_LAT"; protected static final String PREVIOUS_LNG = "org.redcross.openmapkit.PREVIOUS_LNG"; protected static final String PREVIOUS_ZOOM = "org.redcross.openmapkit.PREVIOUS_ZOOM"; - + private static String version = ""; protected MapView mapView; @@ -102,11 +103,11 @@ public static boolean hasPermissions(Context context, String... permissions) { int PERMISSION_ALL = 1; String[] PERMISSIONS = { - android.Manifest.permission.WRITE_EXTERNAL_STORAGE, - android.Manifest.permission.READ_EXTERNAL_STORAGE, - android.Manifest.permission.ACCESS_COARSE_LOCATION, - android.Manifest.permission.ACCESS_FINE_LOCATION, - android.Manifest.permission.CAMERA + android.Manifest.permission.WRITE_EXTERNAL_STORAGE, + android.Manifest.permission.READ_EXTERNAL_STORAGE, + android.Manifest.permission.ACCESS_COARSE_LOCATION, + android.Manifest.permission.ACCESS_FINE_LOCATION, + android.Manifest.permission.CAMERA }; @Override @@ -120,8 +121,8 @@ protected void onCreate(Bundle savedInstanceState) { // initializeMBTilesServer(); determineVersion(); - - if(android.os.Build.VERSION.SDK_INT >= 21) { + + if (android.os.Build.VERSION.SDK_INT >= 21) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); @@ -136,17 +137,10 @@ protected void onCreate(Bundle savedInstanceState) { // App crashes without some permissions. // TODO We can be more refined about where and when we ask for permissions - if(!hasPermissions(this, PERMISSIONS)){ + if (!hasPermissions(this, PERMISSIONS)) { ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL); } - - // create directory structure for app if needed - ExternalStorage.checkOrCreateAppDirs(); - - // Move constraints assets to ExternalStorage if necessary - ExternalStorage.copyConstraintsToExternalStorageIfNeeded(this); - // Register the intent to the ODKCollect handler // This will determine if we are in ODK Collect Mode or not. ODKCollectHandler.registerIntent(getIntent()); @@ -159,23 +153,23 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_map); //get the layout the ListView is nested in - mBottomLinearLayout = (LinearLayout)findViewById(R.id.bottomLinearLayout); + mBottomLinearLayout = (LinearLayout) findViewById(R.id.bottomLinearLayout); //the ListView from layout - mTagListView = (ListView)findViewById(R.id.tagListView); + mTagListView = (ListView) findViewById(R.id.tagListView); //the ListView close image button - mCloseListViewButton = (ImageButton)findViewById(R.id.imageViewCloseList); + mCloseListViewButton = (ImageButton) findViewById(R.id.imageViewCloseList); //get the layout the Map is nested in - mTopLinearLayout = (LinearLayout)findViewById(R.id.topLinearLayout); + mTopLinearLayout = (LinearLayout) findViewById(R.id.topLinearLayout); //get map from layout - mapView = (MapView)findViewById(R.id.mapView); + mapView = (MapView) findViewById(R.id.mapView); // get Field Papers Message - fieldPapersMsg = (TextView)findViewById(R.id.fieldPapersMsg); - + fieldPapersMsg = (TextView) findViewById(R.id.fieldPapersMsg); + // initialize basemap object basemap = new Basemap(this); @@ -197,11 +191,26 @@ protected void onCreate(Bundle savedInstanceState) { initializeListView(); } - + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == PERMISSION_ALL && grantResults.length > 0) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + // create directory structure for app if needed + ExternalStorage.checkOrCreateAppDirs(); + + // Move constraints assets to ExternalStorage if necessary + ExternalStorage.copyConstraintsToExternalStorageIfNeeded(this); + } else { + } + } + } + @Override protected void onPause() { super.onPause(); - saveMapPosition(); + saveMapPosition(); } protected void saveMapPosition() { @@ -222,12 +231,12 @@ protected void positionMap() { double lat = (double) pref.getFloat(PREVIOUS_LAT, -999); double lng = (double) pref.getFloat(PREVIOUS_LNG, -999); float z = pref.getFloat(PREVIOUS_ZOOM, -999); - + // no shared pref if (lat == -999 || lng == -999 || z == -999) { mapView.setUserLocationEnabled(true); mapView.goToUserLocation(true); - } + } // there is a shared pref else { LatLng c = new LatLng(lat, lng); @@ -235,14 +244,14 @@ protected void positionMap() { mapView.setZoom(z); } } - + /** * For initializing the ListView of tags */ protected void initializeListView() { //the ListView title - mTagTextView = (TextView)findViewById(R.id.tagTextView); + mTagTextView = (TextView) findViewById(R.id.tagTextView); mTagTextView.setText(R.string.tagListViewTitle); //hide the ListView by default @@ -290,11 +299,11 @@ public void onClick(View v) { } }; // tag button - tagButton = (ImageButton)findViewById(R.id.tagButton); + tagButton = (ImageButton) findViewById(R.id.tagButton); tagButton.setOnClickListener(tagSwipeLaunchListener); // add tags button - addTagsButton = (Button)findViewById(R.id.addTagsBtn); + addTagsButton = (Button) findViewById(R.id.addTagsBtn); addTagsButton.setOnClickListener(tagSwipeLaunchListener); //handle list view item taps @@ -315,6 +324,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) /** * For identifying an OSM element and presenting it's tags in the ListView + * * @param osmElement The target OSMElement. */ protected void identifyOSMFeature(OSMElement osmElement) { @@ -352,7 +362,7 @@ protected void identifyOSMFeature(OSMElement osmElement) { //pass the tags to the list adapter tagListAdapter = new TagListAdapter(this, osmElement); - + //set the ListView's adapter mTagListView.setAdapter(tagListAdapter); @@ -362,13 +372,14 @@ protected void identifyOSMFeature(OSMElement osmElement) { /** * For setting the proportions of the Map weight and the ListView weight for dual display - * @param topWeight Refers to the layout weight. Note, topWeight + bottomWeight must equal the weight sum of 100 + * + * @param topWeight Refers to the layout weight. Note, topWeight + bottomWeight must equal the weight sum of 100 * @param bottomWeight Referes to the layotu height. Note, bottomWeight + topWeight must equal the weight sum of 100 */ protected void proportionMapAndList(int topWeight, int bottomWeight) { - LinearLayout.LayoutParams topLayoutParams = (LinearLayout.LayoutParams)mTopLinearLayout.getLayoutParams(); - LinearLayout.LayoutParams bottomLayoutParams = (LinearLayout.LayoutParams)mBottomLinearLayout.getLayoutParams(); + LinearLayout.LayoutParams topLayoutParams = (LinearLayout.LayoutParams) mTopLinearLayout.getLayoutParams(); + LinearLayout.LayoutParams bottomLayoutParams = (LinearLayout.LayoutParams) mBottomLinearLayout.getLayoutParams(); //update weight of top and bottom linear layouts mTopLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(topLayoutParams.width, topLayoutParams.height, topWeight)); @@ -398,12 +409,12 @@ protected void initializeOsmXml() { e.printStackTrace(); } } - + /** * For instantiating the location button and setting up its tap event handler */ protected void initializeLocationButton() { - final ImageButton locationButton = (ImageButton)findViewById(R.id.locationButton); + final ImageButton locationButton = (ImageButton) findViewById(R.id.locationButton); //set tap event locationButton.setOnClickListener(new View.OnClickListener() { @@ -423,7 +434,7 @@ public void onClick(View v) { } protected void initializeMoveButton() { - moveButton = (ImageButton)findViewById(R.id.moveNodeModeBtn); + moveButton = (ImageButton) findViewById(R.id.moveNodeModeBtn); moveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -431,9 +442,9 @@ public void onClick(View v) { } }); } - + protected void initializeNodeModeButton() { - nodeModeButton = (Button)findViewById(R.id.nodeModeButton); + nodeModeButton = (Button) findViewById(R.id.nodeModeButton); nodeModeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -443,8 +454,8 @@ public void onClick(View v) { } protected void initializeAddNodeButtons() { - final Button addNodeBtn = (Button)findViewById(R.id.addNodeBtn); - final ImageButton addNodeMarkerBtn = (ImageButton)findViewById(R.id.addNodeMarkerBtn); + final Button addNodeBtn = (Button) findViewById(R.id.addNodeBtn); + final ImageButton addNodeMarkerBtn = (ImageButton) findViewById(R.id.addNodeMarkerBtn); View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -459,8 +470,8 @@ public void onClick(View v) { } protected void initializeMoveNodeButtons() { - final Button moveNodeBtn = (Button)findViewById(R.id.moveNodeBtn); - final ImageButton moveNodeMarkerBtn = (ImageButton)findViewById(R.id.moveNodeMarkerBtn); + final Button moveNodeBtn = (Button) findViewById(R.id.moveNodeBtn); + final ImageButton moveNodeMarkerBtn = (ImageButton) findViewById(R.id.moveNodeMarkerBtn); View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -473,8 +484,8 @@ public void onClick(View v) { } private void toggleNodeMode() { - final Button addNodeBtn = (Button)findViewById(R.id.addNodeBtn); - final ImageButton addNodeMarkerBtn = (ImageButton)findViewById(R.id.addNodeMarkerBtn); + final Button addNodeBtn = (Button) findViewById(R.id.addNodeBtn); + final ImageButton addNodeMarkerBtn = (ImageButton) findViewById(R.id.addNodeMarkerBtn); if (nodeMode) { addNodeBtn.setVisibility(View.GONE); addNodeMarkerBtn.setVisibility(View.GONE); @@ -502,14 +513,14 @@ public void onClick(View v) { osmMap.addNode(deletedNode); } }) - .setActionTextColor(Color.rgb(126,188,111)) + .setActionTextColor(Color.rgb(126, 188, 111)) .show(); } private void toggleMoveNodeMode() { - final ImageButton moveNodeModeBtn = (ImageButton)findViewById(R.id.moveNodeModeBtn); - final ImageButton moveNodeMarkerBtn = (ImageButton)findViewById(R.id.moveNodeMarkerBtn); - final Button moveNodeBtn = (Button)findViewById(R.id.moveNodeBtn); + final ImageButton moveNodeModeBtn = (ImageButton) findViewById(R.id.moveNodeModeBtn); + final ImageButton moveNodeMarkerBtn = (ImageButton) findViewById(R.id.moveNodeMarkerBtn); + final Button moveNodeBtn = (Button) findViewById(R.id.moveNodeBtn); if (moveNodeMode) { moveNodeMarkerBtn.setVisibility(View.GONE); moveNodeBtn.setVisibility(View.GONE); @@ -528,7 +539,7 @@ private void toggleMoveNodeMode() { private void hideSelectedMarker() { LinkedList selectedElements = OSMElement.getSelectedElements(); if (selectedElements.size() < 1) return; - OSMNode node = (OSMNode)selectedElements.getFirst(); + OSMNode node = (OSMNode) selectedElements.getFirst(); Marker marker = node.getMarker(); if (marker != null) { node.getMarker().setVisibility(false); @@ -539,7 +550,7 @@ private void hideSelectedMarker() { private void showSelectedMarker() { LinkedList selectedElements = OSMElement.getSelectedElements(); if (selectedElements.size() < 1) return; - OSMNode node = (OSMNode)selectedElements.getFirst(); + OSMNode node = (OSMNode) selectedElements.getFirst(); Marker marker = node.getMarker(); if (marker != null) { node.getMarker().setVisibility(true); @@ -603,7 +614,7 @@ public void onClick(View v) { } }) - .setActionTextColor(Color.rgb(126,188,111)) + .setActionTextColor(Color.rgb(126, 188, 111)) .show(); } } @@ -705,7 +716,7 @@ public boolean onOptionsItemSelected(MenuItem item) { // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. super.onOptionsItemSelected(item); - + int id = item.getItemId(); if (id == R.id.deployments) { @@ -754,8 +765,8 @@ public void selectedElementsChanged(LinkedList selectedElements) { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if ( requestCode == ODK_COLLECT_TAG_ACTIVITY_CODE ) { - if(resultCode == RESULT_OK) { + if (requestCode == ODK_COLLECT_TAG_ACTIVITY_CODE) { + if (resultCode == RESULT_OK) { saveToODKCollectAndExit(); } } @@ -770,11 +781,11 @@ protected void saveToODKCollectAndExit() { setResult(Activity.RESULT_OK, resultIntent); finish(); } - + public MapView getMapView() { return mapView; } - + private void determineVersion() { try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); @@ -783,7 +794,7 @@ private void determineVersion() { e.printStackTrace(); } } - + public static String getVersion() { return version; } @@ -791,7 +802,7 @@ public static String getVersion() { private void initializeMBTilesServer() { try { MBTilesServer.singleton().start(); - } catch(IOException ioe) { + } catch (IOException ioe) { Log.w("Httpd", "MBTiles HTTP server could not start."); } Log.w("MBTilesServer", "MBTiles HTTP server initialized."); @@ -841,8 +852,7 @@ private boolean isAppInstalled(String uri) { try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); app_installed = true; - } - catch (PackageManager.NameNotFoundException e) { + } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed; diff --git a/app/src/main/java/org/redcross/openmapkit/odkcollect/ODKCollectData.java b/app/src/main/java/org/redcross/openmapkit/odkcollect/ODKCollectData.java index 11e83d5..68fe8f5 100644 --- a/app/src/main/java/org/redcross/openmapkit/odkcollect/ODKCollectData.java +++ b/app/src/main/java/org/redcross/openmapkit/odkcollect/ODKCollectData.java @@ -1,6 +1,7 @@ package org.redcross.openmapkit.odkcollect; import android.os.Environment; +import android.util.Log; import com.spatialdev.osm.OSMUtil; import com.spatialdev.osm.model.OSMElement; @@ -23,12 +24,12 @@ /** * Created by Nicholas Hallahan on 2/9/15. * nhallahan@spatialdev.com - * * * + * * * */ public class ODKCollectData { - + public static final String APP_NAME = "OpenMapKit Android"; - + private String formId; private String formFileName; private String instanceId; @@ -36,17 +37,17 @@ public class ODKCollectData { private String previousOSMEditFileName; private LinkedHashMap requiredTags; private List editedOSM = new ArrayList<>(); - + private String editedXml; private String checksum; private String appVersion; - public ODKCollectData ( String formId, - String formFileName, - String instanceId, - String instanceDir, - String previousOSMEditFileName, - LinkedHashMap requiredTags ) { + public ODKCollectData(String formId, + String formFileName, + String instanceId, + String instanceDir, + String previousOSMEditFileName, + LinkedHashMap requiredTags) { this.formId = formId; this.formFileName = formFileName; this.instanceId = instanceId; @@ -63,28 +64,29 @@ private void findEditedOSMForForm(String formFileName) { } String instances = new File(instanceDir).getParent(); File[] instancesDirs = new File(instances).listFiles(); - for (int i = 0; i < instancesDirs.length; ++i) { - File dir = instancesDirs[i]; - if (!dir.isDirectory()) { - continue; - } - // check if the instance dir is for the form we are dealing with - // it is 0 if the form file name is the first substring of the dirname - if (dir.getName().indexOf(formFileName) != 0) { - continue; - } - - String[] files = dir.list(); - for (int j = 0; j < files.length; ++j) { - String fname = files[j]; - if (fname.lastIndexOf(".osm") > -1) { - File osmFile = new File(dir, fname); - editedOSM.add(osmFile); + if (instancesDirs != null) + for (int i = 0; i < instancesDirs.length; ++i) { + File dir = instancesDirs[i]; + if (!dir.isDirectory()) { + continue; + } + // check if the instance dir is for the form we are dealing with + // it is 0 if the form file name is the first substring of the dirname + if (dir.getName().indexOf(formFileName) != 0) { + continue; + } + + String[] files = dir.list(); + for (int j = 0; j < files.length; ++j) { + String fname = files[j]; + if (fname.lastIndexOf(".osm") > -1) { + File osmFile = new File(dir, fname); + editedOSM.add(osmFile); + } } } - } } - + public List getEditedOSM() { return editedOSM; } @@ -111,7 +113,8 @@ public Collection getRequiredTags() { /** * Returns the ODK defined label for a OSM tag key if exists - * * * + * * * + * * @param key * @return */ @@ -125,7 +128,8 @@ public String getTagKeyLabel(String key) { /** * Returns the ODK defined label for an OSM tag value if exists - * * * + * * * + * * @param key * @param value * @return @@ -138,12 +142,12 @@ public String getTagValueLabel(String key, String value) { } return null; } - + public void consumeOSMElement(OSMElement el, String osmUserName) throws IOException { checksum = el.checksum(); editedXml = OSMXmlWriter.elementToString(el, osmUserName, APP_NAME + " " + appVersion); } - + public void deleteOldOSMEdit() { if (previousOSMEditFileName == null) { return; @@ -154,12 +158,12 @@ public void deleteOldOSMEdit() { f.delete(); } } - + public void writeXmlToOdkCollectInstanceDir() throws IOException { - if ( ! isODKCollectInstanceDirectoryAvailable() ) { + if (!isODKCollectInstanceDirectoryAvailable()) { throw new IOException("The ODK Collect Instance Directory cannot be accessed!"); } - File f = new File( getOSMFileFullPath() ); + File f = new File(getOSMFileFullPath()); f.createNewFile(); FileOutputStream fos = new FileOutputStream(f); OutputStreamWriter writer = new OutputStreamWriter(fos); @@ -171,14 +175,15 @@ public void writeXmlToOdkCollectInstanceDir() throws IOException { public String getOSMFileName() { return checksum + ".osm"; } - + public String getOSMFileFullPath() { return instanceDir + "/" + getOSMFileName(); } - + private boolean isODKCollectInstanceDirectoryAvailable() { - if ( ! ExternalStorage.isWritable() ) { + Log.d("apple", "isODKCollectInstanceDirectoryAvailable: "+ExternalStorage.isWritable()); + if (!ExternalStorage.isWritable()) { return false; } File dir = new File(instanceDir); @@ -187,5 +192,5 @@ private boolean isODKCollectInstanceDirectoryAvailable() { } return false; } - + } diff --git a/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java b/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java index f41c400..a802622 100644 --- a/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java +++ b/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java @@ -1,5 +1,6 @@ package org.redcross.openmapkit.tagswipe; +import android.util.Log; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; @@ -40,7 +41,7 @@ public class TagEdit { private static List tagEditsOrder; private static OSMElement osmElement; private static TagSwipeActivity tagSwipeActivity; - + private final String tagKey; // a given TagEdit always associates to an immutable key private String tagVal; private String prevTagVal; @@ -70,7 +71,7 @@ public static List buildTagEdits() { osmElement = OSMElement.getSelectedElements().getFirst(); Map tags = osmElement.getTags(); - + // Tag Edits for ODK Collect Mode if (ODKCollectHandler.isODKCollectMode()) { Map readOnlyTags = new HashMap<>(tags); @@ -102,7 +103,7 @@ public static List buildTagEdits() { tagEditsOrder.add(tagEdit); } } - + // Tag Edits for Standalone Mode else { Set keys = tags.keySet(); @@ -114,11 +115,11 @@ public static List buildTagEdits() { tagEditsOrder.add(tagEdit); } } - + return tagEdits; } - private static String tagValueOrDefaultValue(Map tags, String tagKey) { + private static String tagValueOrDefaultValue(Map tags, String tagKey) { String tagVal = tags.get(tagKey); if (tagVal == null) { // null if there is no default @@ -133,13 +134,13 @@ private static String tagValueOrDefaultValue(Map tags, String tag public static void setTagSwipeActivity(TagSwipeActivity tagSwipeActivity) { TagEdit.tagSwipeActivity = tagSwipeActivity; } - + public static TagEdit getTag(int idx) { return tagEdits.get(idx); } - + public static TagEdit getTag(String key) { - return tagEditHash.get(key); + return tagEditHash.get(key); } public static Set hiddenTagKeys() { @@ -179,10 +180,9 @@ public static int getIndexForTagKey(String key) { // If its not there, just go to the first TagEdit return 0; } - + public static boolean saveToODKCollect(String osmUserName) { updateTagsInOSMElement(); - Set missingTags = Constraints.singleton().requiredTagsNotMet(osmElement); if (missingTags.size() > 0) { tagSwipeActivity.notifyMissingTags(missingTags); @@ -214,20 +214,22 @@ private static void addTag(String key, String activeTagKey) { tagSwipeActivity.updateUI(activeTagKey); } } - + private static void updateTagsInOSMElement() { - for (TagEdit tagEdit : tagEdits) { - tagEdit.updateTagInOSMElement(); + for (int i = 0; i < tagEdits.size(); i++) { +// for (TagEdit tagEdit : tagEdits) { + Log.d("apple", "saveToODKCollect:sushma " + i + " other " + tagEdits.get(i).tagKey + tagEdits.get(i).tagVal); + tagEdits.get(i).updateTagInOSMElement(); } } - + private TagEdit(String tagKey, String tagVal, ODKTag odkTag, boolean readOnly) { this.tagKey = tagKey; setTagVal(tagVal); this.odkTag = odkTag; this.readOnly = readOnly; } - + private TagEdit(String tagKey, String tagVal, boolean readOnly) { this.tagKey = tagKey; setTagVal(tagVal); @@ -238,12 +240,13 @@ private TagEdit(String tagKey, String tagVal, boolean readOnly) { * The EditText widget from StringTagValueFragment gets passed into here * so that the value can be retrieved on save. * * * * + * * @param editText */ public void setEditText(EditText editText) { this.editText = editText; } - + public void setRadioGroup(RadioGroup radioGroup) { this.radioGroup = radioGroup; } @@ -253,11 +256,11 @@ public void setupEditCheckbox(CheckBox cb, EditText et) { editTextCheckBox = cb; checkBoxEditText = et; } - + public ODKTag getODKTag() { return odkTag; } - + public void updateTagInOSMElement() { // check boxes if (odkTag != null && checkBoxMode) { @@ -280,10 +283,10 @@ public void updateTagInOSMElement() { int checkedId = radioGroup.getCheckedRadioButtonId(); // has custom value input if (v instanceof LinearLayout) { - LinearLayout customLL = (LinearLayout)v; - RadioButton customRadio = (RadioButton)customLL.getChildAt(0); + LinearLayout customLL = (LinearLayout) v; + RadioButton customRadio = (RadioButton) customLL.getChildAt(0); if (customRadio.isChecked()) { - EditText et = (EditText)customLL.getChildAt(1); + EditText et = (EditText) customLL.getChildAt(1); setTagVal(et.getText().toString()); addOrEditTag(tagKey, tagVal); } else if (checkedId != -1) { @@ -314,6 +317,7 @@ private void addOrEditTag(String tagKey, String tagVal) { osmElement.addOrEditTag(tagKey, tagVal); Constraints.TagAction tagAction = Constraints.singleton().tagAddedOrEdited(tagKey, tagVal); executeTagAction(tagAction); + } private void deleteTag(String tagKey) { @@ -324,7 +328,6 @@ private void deleteTag(String tagKey) { } private void executeTagAction(Constraints.TagAction tagAction) { - // Reset tags shown and hidden from previous value if (prevTagVal != null) { Set prevHiddenTags = Constraints.singleton().findTagsToBeHiddenFromUpdate(tagKey, prevTagVal); @@ -346,11 +349,11 @@ private void executeTagAction(Constraints.TagAction tagAction) { addTag(tag, tagKey); } } - + public String getTitle() { return tagKey; } - + public String getTagKeyLabel() { if (odkTag != null) { return odkTag.getLabel(); @@ -361,7 +364,7 @@ public String getTagKeyLabel() { public String getTagKey() { return tagKey; } - + public String getTagValLabel() { if (odkTag == null) return null; ODKTagItem item = odkTag.getItem(tagVal); @@ -370,7 +373,7 @@ public String getTagValLabel() { } return null; } - + public String getTagVal() { return tagVal; } @@ -393,23 +396,23 @@ public Set getTagVals() { } return tagVals; } - + public boolean isReadOnly() { return readOnly; } - + public boolean isSelectOne() { - return !readOnly && + return !readOnly && odkTag != null && odkTag.getItems().size() > 0 && !Constraints.singleton().tagIsSelectMultiple(odkTag.getKey()); } public boolean isSelectMultiple() { - return !readOnly && + return !readOnly && odkTag != null && odkTag.getItems().size() > 0 && Constraints.singleton().tagIsSelectMultiple(odkTag.getKey()); } - + } diff --git a/app/src/main/java/org/redcross/openmapkit/tagswipe/TagSwipeActivity.java b/app/src/main/java/org/redcross/openmapkit/tagswipe/TagSwipeActivity.java index dd64cc3..d9914d3 100644 --- a/app/src/main/java/org/redcross/openmapkit/tagswipe/TagSwipeActivity.java +++ b/app/src/main/java/org/redcross/openmapkit/tagswipe/TagSwipeActivity.java @@ -13,13 +13,14 @@ import android.support.design.widget.Snackbar; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; -import android.support.v7.app.ActionBarActivity; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; import android.text.InputType; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -29,12 +30,12 @@ import org.redcross.openmapkit.R; import org.redcross.openmapkit.odkcollect.ODKCollectHandler; -public class TagSwipeActivity extends ActionBarActivity { +public class TagSwipeActivity extends AppCompatActivity { private List tagEdits; private SharedPreferences userNamePref; - + private void setupModel() { tagEdits = TagEdit.buildTagEdits(); TagEdit.setTagSwipeActivity(this); @@ -55,7 +56,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_tag_swipe); setupModel(); - + // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); @@ -63,7 +64,7 @@ protected void onCreate(Bundle savedInstanceState) { // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.tagSwipeActivity); mViewPager.setAdapter(mSectionsPagerAdapter); - + pageToCorrectTag(); } @@ -106,13 +107,17 @@ public void saveToODKCollect() { if (userName == null) { askForOSMUsername(); } else { - if (TagEdit.saveToODKCollect(userName)) { - setResult(Activity.RESULT_OK); - finish(); + try { + if (TagEdit.saveToODKCollect(userName)) { + setResult(Activity.RESULT_OK); + finish(); + } + } catch (Exception e) { + Log.d("apple", "saveToODKCollect:sushma error " + e.toString()); } } } - + public void cancel() { setResult(Activity.RESULT_CANCELED); finish(); @@ -176,7 +181,7 @@ public void onClick(View v) { private String missingTagsText(Set missingTags) { String str = ""; boolean first = true; - for (String tag: missingTags) { + for (String tag : missingTags) { if (first) { str += tag; } else { @@ -188,7 +193,7 @@ private String missingTagsText(Set missingTags) { } public class SectionsPagerAdapter extends FragmentStatePagerAdapter { - + private Fragment fragment; public SectionsPagerAdapter(FragmentManager fm) { @@ -200,18 +205,18 @@ private void hideKeyboard() { StringTagValueFragment stvf = (StringTagValueFragment) fragment; EditText et = stvf.getEditText(); if (et != null) { - InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(et.getWindowToken(), 0); } } } - + @Override public Fragment getItem(int position) { - + // hide keyboard if last fragment had a user edit text hideKeyboard(); - + if (position < tagEdits.size()) { TagEdit tagEdit = tagEdits.get(position); if (tagEdit != null) { @@ -221,8 +226,7 @@ public Fragment getItem(int position) { } else if (tagEdit.isSelectOne()) { fragment = SelectOneTagValueFragment.newInstance(position); return fragment; - } - else if (tagEdit.isSelectMultiple()) { + } else if (tagEdit.isSelectMultiple()) { fragment = SelectMultipleTagValueFragment.newInstance(position); return fragment; } else { @@ -231,9 +235,9 @@ else if (tagEdit.isSelectMultiple()) { } } } - + if (ODKCollectHandler.isODKCollectMode()) { - return ODKCollectFragment.newInstance(); + return ODKCollectFragment.newInstance(); } else { return StandaloneFragment.newInstance("one", "two"); } diff --git a/build.gradle b/build.gradle index f4eb27c..5c09e73 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,10 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath "com.android.tools.build:gradle:4.1.0" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -12,10 +13,12 @@ buildscript { allprojects { repositories { + google() jcenter() + maven { url 'https://jitpack.io' } } } -task wrapper(type: Wrapper) { - gradleVersion = '2.2.1' -} +//task wrapper(type: Wrapper) { +// gradleVersion = '6.5' +//} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b407723..9938269 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Sep 17 12:05:11 PDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +zipStorePath=wrapper/dists \ No newline at end of file