If you think the Android project arcgis-runtime-samples-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/* Copyright 2014 ESRI
*//www.java2s.com
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
*
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
*
* See the Sample code usage restrictions document for further information.
*
*/package com.esri.arcgis.android.samples.classbreaksrenderer;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.esri.android.map.Callout;
import com.esri.android.map.FeatureLayer;
import com.esri.android.map.MapView;
import com.esri.android.map.event.OnSingleTapListener;
import com.esri.core.geodatabase.GeodatabaseFeatureServiceTable;
import com.esri.core.geodatabase.GeodatabaseFeatureServiceTable.Status;
import com.esri.core.geometry.Point;
import com.esri.core.map.CallbackListener;
import com.esri.core.map.Feature;
import com.esri.core.renderer.ClassBreaksRenderer;
/**
* This app uses GeodatabaseFeatureServiceTable and Feature Layer. It
* demonstrates the use of Class breaks renderer. Wind stations are displayed
* using arrow markers whose size depends upon the wind speeds and rotation
* depends on the wind direction. On clicking an arrow marker, a callout is
* displayed which shows the station name, country, temperature and wind speed.
*
* Please be aware that the Feature Layer service is not guaranteed to be
* running.
*
*
*/publicclass ClassBreaksRendererActivity extends Activity {
MapView mMapView;
GeodatabaseFeatureServiceTable table;
FeatureLayer feature_layer;
ClassBreaksRenderer wind_renderer;
staticint LAYER_ID = 0;
View calloutView;
/** Called when the activity is first created. */
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMapView = (MapView) findViewById(R.id.map);
mMapView.setEsriLogoVisible(true);
mMapView.enableWrapAround(true);
// Inflate the view for the callouts
calloutView = View.inflate(this, R.xml.callout, null);
String url = this.getResources().getString(R.string.featurelayer_url);
// Create the GeodatabaseFeatureServiceTable from service url and layer
// id
table = new GeodatabaseFeatureServiceTable(url, LAYER_ID);
// Initializing the GeodatabaseFeatureServiceTable asynchronously
table.initialize(new CallbackListener<GeodatabaseFeatureServiceTable.Status>() {
@Override
publicvoid onCallback(Status objs) {
if (objs == Status.INITIALIZED) {
// Creating a feature table
feature_layer = new FeatureLayer(table);
// Adding feature layer to the map
mMapView.addLayer(feature_layer);
}
}
@Override
publicvoid onError(Throwable e) {
// Get the error using getInitializationError() method
Toast.makeText(getApplicationContext(), "Feature Layer not available", Toast.LENGTH_LONG).show();
}
});
// Identify on single tap of map
mMapView.setOnSingleTapListener(new OnSingleTapListener() {
privatestaticfinallong serialVersionUID = 1L;
@Override
publicvoid onSingleTap(finalfloat x, finalfloat y) {
// Check if there is a feature present
if (feature_layer.getFeatureIDs(x, y, 20).length != 0) {
feature_layer.clearSelection();
Point mapPoint = mMapView.toMapPoint(x, y);
long[] iDs = feature_layer.getFeatureIDs(x, y, 20);
// Get the particular feature values and highlight it
feature_layer.selectFeature(iDs[0]);
Feature f = feature_layer.getFeature(iDs[0]);
String station_name = (String) f
.getAttributeValue("STATION_NAME");
String country_name = (String) f
.getAttributeValue("COUNTRY");
String temp = (String) f.getAttributeValue("TEMP")
.toString();
String wind_speed = (String) f.getAttributeValue(
"WIND_SPEED").toString();
// Update the content of the callout
updateContent(station_name, country_name, temp, wind_speed);
// Create callout from mapview
Callout mapCallout = mMapView.getCallout();
// populate callout with updated content
mapCallout.setCoordinates(mapPoint);
mapCallout.setOffset(0, -3);
mapCallout.setContent(calloutView);
// show callout
mapCallout.show();
}
}
});
}
/*
* Updating the content of the callout with the feature values
*/privatevoid updateContent(String station, String country, String temp,
String wind_speed) {
if (calloutView == null)
return;
TextView tv_station = (TextView) calloutView.findViewById(R.id.tv_station);
tv_station.setText(station);
TextView tv_country = (TextView) calloutView.findViewById(R.id.tv_country);
tv_country.setText(country);
TextView tv_temp = (TextView) calloutView.findViewById(R.id.tv_temp);
tv_temp.setText(temp + "F");
TextView tv_speed = (TextView) calloutView.findViewById(R.id.tv_speed);
tv_speed.setText(wind_speed);
}
/*
* Called when the activity is destroyed
*/
@Override
protectedvoid onDestroy() {
super.onDestroy();
}
/*
* Called when the activity pauses
*/
@Override
protectedvoid onPause() {
super.onPause();
mMapView.pause();
}
/*
* Called when the activity resumes
*/
@Override
protectedvoid onResume() {
super.onResume();
mMapView.unpause();
}
}