Skip to content

Commit

Permalink
Merge pull request Esri#541 from Esri/trev8939/prepDevelopFor100.4Rel…
Browse files Browse the repository at this point in the history
…ease

Trev8939/prep develop for100.4 release
  • Loading branch information
tschie authored Oct 16, 2018
2 parents 6188120 + 4f0f7cb commit 0dde5c2
Show file tree
Hide file tree
Showing 87 changed files with 2,544 additions and 979 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Overview
ArcGIS Runtime SDK for Android v100.3.0 samples. The `master` branch of this repository contains sample app modules for the latest available version of the [ArcGIS Runtime SDK for Android](https://developers.arcgis.com/android/). Samples released under older versions can be found through the [git tags](https://github.com/Esri/arcgis-runtime-samples-android/tags). Please read our [wiki](https://github.com/Esri/arcgis-runtime-samples-android/wiki) for help with working with this repository.
ArcGIS Runtime SDK for Android v100.4.0 samples. The `master` branch of this repository contains sample app modules for the latest available version of the [ArcGIS Runtime SDK for Android](https://developers.arcgis.com/android/). Samples released under older versions can be found through the [git tags](https://github.com/Esri/arcgis-runtime-samples-android/tags). Please read our [wiki](https://github.com/Esri/arcgis-runtime-samples-android/wiki) for help with working with this repository.

# Prerequisites
* The samples are building with `compileSdkVersion 27`
* The samples are building with `compileSdkVersion 28`
* [Android Studio](http://developer.android.com/sdk/index.html)

## SDK Maven repo
The SDK is available through the Bintray Maven repo, you can take a look at the repository with the link below:

[ ![Download](https://api.bintray.com/packages/esri/arcgis/arcgis-android/images/download.svg?version=100.3.0) ](https://bintray.com/esri/arcgis/arcgis-android/100.3.0/link)
[ ![Download](https://api.bintray.com/packages/esri/arcgis/arcgis-android/images/download.svg?version=100.4.0) ](https://bintray.com/esri/arcgis/arcgis-android/100.4.0/link)

## Developer Instructions
Please read our [developer instructions wiki page](https://github.com/Esri/arcgis-runtime-samples-android/wiki/dev-instructions) to set up your developer environment with Android Studio. Instructions include forking and cloning the repository for those new to Git.
Expand Down
10 changes: 5 additions & 5 deletions java/blend-renderer/src/main/res/layout/dialog_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
app:layout_constraintVertical_bias="1.0"/>

<TextView
android:id="@+id/textView"
android:id="@+id/color_ramp_text_view"
android:text="@string/color_ramp_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -137,12 +137,12 @@
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView"
app:layout_constraintTop_toTopOf="@+id/color_ramp_text_view"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="@+id/textView"
app:layout_constraintBottom_toBottomOf="@+id/color_ramp_text_view"
android:layout_marginBottom="0dp"
app:layout_constraintLeft_toRightOf="@+id/textView"
app:layout_constraintLeft_toRightOf="@+id/color_ramp_text_view"
android:layout_marginLeft="8dp"
app:layout_constraintVertical_bias="0.571"/>

</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
1 change: 1 addition & 0 deletions java/display-kml/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
36 changes: 36 additions & 0 deletions java/display-kml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Display KML
Display a KML layer from a URL, portal item, or local KML file.

![Display KML App](display-kml.png)

## How to use the sample
Select the KML layer you'd like to display from the dropdown menu in the upper right.

Before attempting to load a KML file from local storage, the file will have to be sideloaded onto the device. See [Offline Data](#offline-data).

## How it works
1. To create a KML layer from a URL, create a `KMLDataset` using the URL to the KML file. Then pass the data set to the `KmlLayer` constructor.
2. To create a KML layer from a portal item, construct a `PortalItem` with a portal and the KML portal item. Pass the portal item to the `KmlLayer` constructor.
1. To create a KML layer from a local file, create a `KMLDataset` using a path to the local KML file in external storage. Then pass the data set to the `KmlLayer` constructor.
1. Add the layer as an operational layer to the map with `map.getOperationalLayers().add(kmlLayer)`.

## Relevant API
* KmlDataset
* KmlLayer
* Portal
* PortalItem

## Offline Data
1. Download the data from [ArcGIS Online](https://arcgisruntime.maps.arcgis.com/home/item.html?id=324e4742820e46cfbe5029ff2c32cb1f).
1. Extract the contents of the downloaded zip file to disk.
1. Open your command prompt and navigate to the folder where you extracted the contents of the data from step 1.
1. Execute the following command:
`adb push US_State_Capitals.kml /sdcard/ArcGIS/Samples/KML/US_State_Capitals.kml`


Link | Local Location
---------|-------|
|[US State Capitals KML](https://arcgisruntime.maps.arcgis.com/home/item.html?id=324e4742820e46cfbe5029ff2c32cb1f)| `<sdcard>`/ArcGIS/Samples/KML/US_State_Capitals.kml|

#### Tags
Layers
31 changes: 31 additions & 0 deletions java/display-kml/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.esri.arcgisruntime.sample.displaykml"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
targetCompatibility rootProject.ext.targetJavaVersion
sourceCompatibility rootProject.ext.sourceJavaVersion
}
}

dependencies {
// arcgis-android & appcompat lib dependencies from rootProject build.gradle
implementation "com.android.support.constraint:constraint-layout:$constraintLayoutVersion"
}
Binary file added java/display-kml/display-kml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions java/display-kml/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
28 changes: 28 additions & 0 deletions java/display-kml/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.esri.arcgisruntime.displaykml">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/* Copyright 2018 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.esri.arcgisruntime.displaykml;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.esri.arcgisruntime.layers.KmlLayer;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.ogc.kml.KmlDataset;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;

public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();

private MapView mMapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// get the reference to the map view
mMapView = findViewById(R.id.mapView);

// create a map with the dark gray canvas basemap
ArcGISMap map = new ArcGISMap(Basemap.Type.DARK_GRAY_CANVAS_VECTOR, 39, -98, 4);

// set the map to the map view
mMapView.setMap(map);

requestReadPermission();
}

/**
* Clear all operational layers and add the kml layer to the map as an operational layer.
*
* @param kmlLayer to add to the map
*/
private void display(KmlLayer kmlLayer) {
// clear the existing layers from the map
mMapView.getMap().getOperationalLayers().clear();

// add the KML layer to the map
mMapView.getMap().getOperationalLayers().add(kmlLayer);
}

/**
* Display a kml layer from a URL.
*/
private void changeSourceToURL() {
// create a kml data set from a URL
KmlDataset kmlDataset = new KmlDataset(getString(R.string.kml_url));

// a KML layer created from a remote KML file
KmlLayer kmlLayer = new KmlLayer(kmlDataset);
display(kmlLayer);

// report errors if failed to load
kmlDataset.addDoneLoadingListener(() -> {
if (kmlDataset.getLoadStatus() != LoadStatus.LOADED) {
String error = "Failed to load kml layer from URL: " + kmlDataset.getLoadError().getMessage();
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
Log.e(TAG, error);
}
});
}

/**
* Display a kml layer from a portal item.
*/
private void changeSourceToPortalItem() {
// create a portal to ArcGIS Online
Portal portal = new Portal(getString(R.string.arcgis_online_url));

// create a portal item from a kml item id
PortalItem portalItem = new PortalItem(portal, getString(R.string.kml_item_id));

// a KML layer created from an ArcGIS Online portal item
KmlLayer kmlLayer = new KmlLayer(portalItem);
display(kmlLayer);

// report errors if failed to load
kmlLayer.addDoneLoadingListener(() -> {
if (kmlLayer.getLoadStatus() != LoadStatus.LOADED) {
String error = "Failed to load kml layer from portal item: " + kmlLayer.getLoadError().getCause().getMessage();
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
Log.e(TAG, error);
}
});
}

/**
* Display a kml layer from external storage.
*/
private void changeSourceToFileExternalStorage() {
// a data set made from data in external storage
KmlDataset kmlDataset = new KmlDataset(Environment.getExternalStorageDirectory() + getString(R.string.kml_path));

// a KML layer created from a local KML file
KmlLayer kmlLayer = new KmlLayer(kmlDataset);
display(kmlLayer);

// report errors if failed to load
kmlDataset.addDoneLoadingListener(() -> {
if (kmlDataset.getLoadStatus() != LoadStatus.LOADED) {
String error =
"Failed to load kml data set from external storage: " + kmlDataset.getLoadError().getCause().getMessage();
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
Log.e(TAG, error);
}
});
}

@Override public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.kml_sources, menu);
return super.onCreateOptionsMenu(menu);
}

@Override public boolean onOptionsItemSelected(MenuItem item) {
int i = item.getItemId();
if (i == R.id.kmlFromUrl) {
changeSourceToURL();
} else if (i == R.id.kmlFromPortal) {
changeSourceToPortalItem();
} else if (i == R.id.kmlFromExternalStorage) {
changeSourceToFileExternalStorage();
} else {
Log.e(TAG, "Menu option not implemented");
}
return super.onOptionsItemSelected(item);
}

/**
* Request read external storage for API level 23+.
*/
private void requestReadPermission() {
// define permission to request
String[] reqPermission = { Manifest.permission.READ_EXTERNAL_STORAGE };
int requestCode = 2;
if (ContextCompat.checkSelfPermission(this, reqPermission[0]) == PackageManager.PERMISSION_GRANTED) {
// set initial KML to URL
changeSourceToURL();
} else {
// request permission
ActivityCompat.requestPermissions(this, reqPermission, requestCode);
}
}

/**
* Handle the permissions request response.
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// set initial KML to URL
changeSourceToURL();
} else {
// report to user that permission was denied
Toast.makeText(this, getString(R.string.kml_read_permission_denied), Toast.LENGTH_SHORT).show();
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
protected void onPause() {
mMapView.pause();
super.onPause();
}

@Override
protected void onResume() {
super.onResume();
mMapView.resume();
}

@Override
protected void onDestroy() {
mMapView.dispose();
super.onDestroy();
}
}

Loading

0 comments on commit 0dde5c2

Please sign in to comment.