Android Open Source - arcgis-runtime-samples-android Class Breaks Renderer Activity






From Project

Back to project page arcgis-runtime-samples-android.

License

The source code is released under:

Apache License

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
 *// w  ww  .  j a  v a2 s.c o  m
 * 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.
 * 
 * 
 */

public class ClassBreaksRendererActivity extends Activity {

  MapView mMapView;
  GeodatabaseFeatureServiceTable table;
  FeatureLayer feature_layer;
  ClassBreaksRenderer wind_renderer;
  static int LAYER_ID = 0;
  View calloutView;

  /** Called when the activity is first created. */
  @Override
  public void 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
      public void 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
      public void 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() {

      private static final long serialVersionUID = 1L;

      @Override
      public void onSingleTap(final float x, final float 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
   */

  private void 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
  protected void onDestroy() {
    super.onDestroy();

  }

  /*
   * Called when the activity pauses
   */

  @Override
  protected void onPause() {

    super.onPause();
    mMapView.pause();

  }

  /*
   * Called when the activity resumes
   */

  @Override
  protected void onResume() {

    super.onResume();
    mMapView.unpause();

  }

}




Java Source Code List

com.arcgis.android.samples.ExportTileCacheTask.ExportTileCacheTaskSampleActivity.java
com.arcgis.android.samples.cloudportal.featureservicetablequery.MainActivity.java
com.arcgis.android.samples.cloudportal.querycloudfeatureservice.MainActivity.java
com.arcgis.android.samples.dynamiclayer.DynamicLayerRendererActivity.java
com.arcgis.android.samples.geometrysample.BufferFragment.java
com.arcgis.android.samples.geometrysample.GeometrySampleActivity.java
com.arcgis.android.samples.geometrysample.GeometryUtil.java
com.arcgis.android.samples.geometrysample.SampleListFragment.java
com.arcgis.android.samples.geometrysample.SpatialRelationshipsFragment.java
com.arcgis.android.samples.geometrysample.UnionDifferenceFragment.java
com.arcgis.android.samples.localdata.localrasterdata.EditTextUtils.java
com.arcgis.android.samples.localdata.localrasterdata.FileBrowserFragment.java
com.arcgis.android.samples.localdata.localrasterdata.HillshadeRendererParametersFragment.java
com.arcgis.android.samples.localdata.localrasterdata.MainActivity.java
com.arcgis.android.samples.localdata.localrasterdata.OnDialogDismissListener.java
com.arcgis.android.samples.localdata.localrasterdata.RendererType.java
com.arcgis.android.samples.localdata.localrasterdata.StretchParametersFragment.java
com.arcgis.android.samples.maps.basemaps.MainActivity.java
com.arcgis.android.samples.maps.fragmentmanagement.BasemapListFragment.java
com.arcgis.android.samples.maps.fragmentmanagement.MainActivity.java
com.arcgis.android.samples.maps.fragmentmanagement.MapFragment.java
com.arcgis.android.samples.maps.helloworld.MainActivity.java
com.arcgis.android.samples.maps.maplegend.LegendDialogFragment.java
com.arcgis.android.samples.maps.maplegend.MainActivity.java
com.arcgis.android.samples.maps.maprotation.Compass.java
com.arcgis.android.samples.maps.maprotation.MainActivity.java
com.arcgis.android.samples.maps.switchmaps.MainActivity.java
com.arcgis.android.samples.maps.switchmaps.MapFragment.java
com.arcgis.android.samples.milsym2525c.MainActivity.java
com.arcgis.android.samples.milsym2525c.Mil2525cMessageParser.java
com.arcgis.android.samples.oauth2sample.MapFragment.java
com.arcgis.android.samples.oauth2sample.OAuth2Sample.java
com.arcgis.android.samples.oauth2sample.UserContentActivity.java
com.arcgis.android.samples.oauth2sample.UserContentArrayAdapter.java
com.arcgis.android.samples.oauth2sample.UserContentFragment.java
com.arcgis.android.samples.oauth2sample.UserWebmaps.java
com.arcgis.android.samples.search.placesearch.MainActivity.java
com.esri.android.sample.closestfacilities.MainActivity.java
com.esri.android.samples.mbtiles.LocalMBTiles.java
com.esri.android.samples.mbtiles.MBTilesLayer.java
com.esri.android.samples.mgrsgrid.LocateMGRSActivity.java
com.esri.arcgis.android.sample.runtimegeodb.CreateRuntimeGeodatabaseActivity.java
com.esri.arcgis.android.sample.simplemap.SimpleMapActivity.java
com.esri.arcgis.android.sample.simplemap.SimpleMapFragment.java
com.esri.arcgis.android.sample.simplemap.SingleFragmentActivity.java
com.esri.arcgis.android.samples.GeoJSONEarthquakeMap.GeoJSONEarthquakeMapActivity.java
com.esri.arcgis.android.samples.PopupUICustomization.LayerQueryTask.java
com.esri.arcgis.android.samples.PopupUICustomization.MyAttachmentsView.java
com.esri.arcgis.android.samples.PopupUICustomization.MyEditAttributesAdapter.java
com.esri.arcgis.android.samples.PopupUICustomization.MyMediaAdapter.java
com.esri.arcgis.android.samples.PopupUICustomization.MyMediaView.java
com.esri.arcgis.android.samples.PopupUICustomization.MyReadOnlyAttributesAdapter.java
com.esri.arcgis.android.samples.PopupUICustomization.MyTitleView.java
com.esri.arcgis.android.samples.PopupUICustomization.PopupFragment.java
com.esri.arcgis.android.samples.PopupUICustomization.PopupUICustomizationActivity.java
com.esri.arcgis.android.samples.addcsv2graphic.AddCSVActivity.java
com.esri.arcgis.android.samples.attributeeditor.AttributeEditorActivity.java
com.esri.arcgis.android.samples.attributeeditor.AttributeItem.java
com.esri.arcgis.android.samples.attributeeditor.AttributeListAdapter.java
com.esri.arcgis.android.samples.attributeeditor.FeatureLayerUtils.java
com.esri.arcgis.android.samples.basiclicense.MainActivity.java
com.esri.arcgis.android.samples.basiclicense.MessageDialogFragment.java
com.esri.arcgis.android.samples.classbreaksrenderer.ClassBreaksRendererActivity.java
com.esri.arcgis.android.samples.featuredusergroup.FeaturedGroupsActivity.java
com.esri.arcgis.android.samples.featuredusergroup.GroupsFragment.java
com.esri.arcgis.android.samples.featuredusergroup.ItemsFragment.java
com.esri.arcgis.android.samples.featuredusergroup.MapActivity.java
com.esri.arcgis.android.samples.geometryeditor.ConfirmDiscardDialogFragment.java
com.esri.arcgis.android.samples.geometryeditor.EditFailedDialogFragment.java
com.esri.arcgis.android.samples.geometryeditor.FeatureTypeData.java
com.esri.arcgis.android.samples.geometryeditor.FeatureTypeDialogFragment.java
com.esri.arcgis.android.samples.geometryeditor.GeometryEditorActivity.java
com.esri.arcgis.android.samples.identifytask.Identify.java
com.esri.arcgis.android.samples.measure.MainActivity.java
com.esri.arcgis.android.samples.nearby.Nearby.java
com.esri.arcgis.android.samples.offlineeditor.GDBUtil.java
com.esri.arcgis.android.samples.offlineeditor.OfflineActions.java
com.esri.arcgis.android.samples.offlineeditor.OfflineEditorActivity.java
com.esri.arcgis.android.samples.offlineeditor.TemplatePicker.java
com.esri.arcgis.android.samples.offlineroutingandgeocoding.RoutingAndGeocoding.java
com.esri.arcgis.android.samples.popupinwebmapforediting.PopupInWebmapForEditing.java
com.esri.arcgis.android.samples.popupinwebmapforviewing.PopupInWebmapForViewing.java
com.esri.arcgis.android.samples.querytask.MainActivity.java
com.esri.arcgis.android.samples.routing.MyAdapter.java
com.esri.arcgis.android.samples.routing.RoutingDialogFragment.java
com.esri.arcgis.android.samples.routing.RoutingListFragment.java
com.esri.arcgis.android.samples.routing.RoutingSample.java
com.esri.arcgis.android.samples.servicearea.EditFragment.java
com.esri.arcgis.android.samples.servicearea.ServiceAreaSample.java
com.esri.arcgis.android.samples.standardlicense.MainActivity.java
com.esri.arcgis.android.samples.standardlicense.MessageDialogFragment.java
com.esri.arcgis.android.samples.standardlicenseoffline.MainActivity.java
com.esri.arcgis.android.samples.standardlicenseoffline.MessageDialogFragment.java
com.esri.arcgis.android.samples.uniquevaluerenderer.UniqueValueRendererSampleActivity.java
com.esri.arcgis.android.samples.viewshed.Viewshed.java
com.esri.arcgis.android.samples.wmslayer.MainActivity.java
com.esri.arcgis.samples.offlineanalysis.MainActivity.java