Android Open Source - arcgis-runtime-samples-android Template Picker






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

package com.esri.arcgis.android.samples.offlineeditor;
/*from  www .  j  av  a2 s. c o m*/
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;

import com.esri.android.map.FeatureLayer;
import com.esri.android.map.Layer;
import com.esri.android.map.MapView;
import com.esri.core.geodatabase.GeodatabaseFeature;
import com.esri.core.geodatabase.GeodatabaseFeatureTable;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.Polyline;
import com.esri.core.map.FeatureTemplate;
import com.esri.core.map.FeatureType;
import com.esri.core.renderer.Renderer;
import com.esri.core.symbol.Symbol;
import com.esri.core.symbol.SymbolHelper;
import com.esri.core.table.TableException;

public class TemplatePicker extends PopupWindow {
  Context context;

  MapView map;

  private FeatureLayer selectedLayer;

  private FeatureTemplate selectedTemplate;

  private Symbol selectedSymbol;

  public TemplatePicker(Context ctx, MapView map) {
    this.context = ctx;
    this.map = map;
    setContentView(populateContentView());
    Display display = ((Activity) ctx).getWindowManager().getDefaultDisplay();
    // create an pont object to receive the size information
    android.graphics.Point size = new android.graphics.Point();
    // get the size in pixels
    display.getSize(size);
    // size.x = width
    setWidth(size.x);
    setHeight(300);
    setFocusable(true);
  }

  public View populateContentView() {

    ScrollView scrollTemplateGroup = new ScrollView(context);
    scrollTemplateGroup.setVerticalScrollBarEnabled(true);
    scrollTemplateGroup.setVisibility(View.VISIBLE);
    scrollTemplateGroup.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);

    LinearLayout templateGroup = new LinearLayout(context);
    templateGroup.setPadding(10, 10, 10, 10);
    templateGroup.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
        android.view.ViewGroup.LayoutParams.MATCH_PARENT));
    templateGroup.setBackgroundResource(R.drawable.popupbg);
    templateGroup.setOrientation(LinearLayout.VERTICAL);

    for (Layer layer : map.getLayers()) {
      if (layer instanceof FeatureLayer) {
        RelativeLayout templateLayout = new RelativeLayout(context);
        templateLayout.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.MATCH_PARENT));

        TextView layerName = new TextView(context);
        layerName.setPadding(10, 10, 10, 10);
        layerName.setText(layer.getName());
        layerName.setTextColor(Color.MAGENTA);
        layerName.setId(1);

        RelativeLayout.LayoutParams layerTemplateParams = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        layerTemplateParams.addRule(RelativeLayout.BELOW, layerName.getId());
        HorizontalScrollView scrollTemplateAndType = new HorizontalScrollView(context);
        scrollTemplateAndType.setPadding(5, 5, 5, 5);
        LinearLayout layerTemplate = new LinearLayout(context);
        layerTemplate.setBackgroundColor(Color.WHITE);
        layerTemplate.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
        layerTemplate.setId(2);
        String typeIdField = ((GeodatabaseFeatureTable) ((FeatureLayer) layer).getFeatureTable()).getTypeIdField();

        if (typeIdField.equals("")) {
          List<FeatureTemplate> featureTemp = ((GeodatabaseFeatureTable) ((FeatureLayer) layer).getFeatureTable())
              .getFeatureTemplates();

          for (FeatureTemplate featureTemplate : featureTemp) {
            GeodatabaseFeature g;
            try {
              g = ((GeodatabaseFeatureTable) ((FeatureLayer) layer).getFeatureTable()).createFeatureWithTemplate(
                  featureTemplate, null);
              Renderer renderer = ((FeatureLayer) layer).getRenderer();
              Symbol symbol = renderer.getSymbol(g);

              Bitmap bitmap = createBitmapfromSymbol(symbol, (FeatureLayer) layer);

              populateTemplateView(layerTemplate, bitmap, featureTemplate, (FeatureLayer) layer, symbol);
            } catch (TableException e) {

              e.printStackTrace();
            }

          }

        } else {
          List<FeatureType> featureTypes = ((GeodatabaseFeatureTable) ((FeatureLayer) layer).getFeatureTable())
              .getFeatureTypes();

          for (FeatureType featureType : featureTypes) {

            FeatureTemplate[] templates = featureType.getTemplates();
            for (FeatureTemplate featureTemplate : templates) {
              GeodatabaseFeature g;
              try {
                g = ((GeodatabaseFeatureTable) ((FeatureLayer) layer).getFeatureTable()).createFeatureWithTemplate(
                    featureTemplate, null);
                Renderer renderer = ((FeatureLayer) layer).getRenderer();
                Symbol symbol = renderer.getSymbol(g);
                Bitmap bitmap = createBitmapfromSymbol(symbol, (FeatureLayer) layer);

                populateTemplateView(layerTemplate, bitmap, featureTemplate, (FeatureLayer) layer, symbol);
              } catch (TableException e) {
                e.printStackTrace();
              }

            }

          }
        }

        templateLayout.addView(layerName);
        scrollTemplateAndType.addView(layerTemplate);
        templateLayout.addView(scrollTemplateAndType, layerTemplateParams);
        templateGroup.addView(templateLayout);
      }

    }
    scrollTemplateGroup.addView(templateGroup);

    return scrollTemplateGroup;
  }

  private Bitmap createBitmapfromSymbol(Symbol symbol, FeatureLayer layer) {
    Bitmap bitmap = null;
    if (layer.getGeometryType().equals(Geometry.Type.POINT)) {
      Point pt = new Point(20, 20);
      bitmap = SymbolHelper.getLegendImage(symbol, pt, 50, 50, Color.WHITE);
    } else if (layer.getGeometryType().equals(Geometry.Type.POLYLINE)) {
      Polyline polyline = new Polyline();
      polyline.startPath(0, 0);
      polyline.lineTo(40, 40);
      bitmap = SymbolHelper.getLegendImage(symbol, polyline, 50, 50, Color.WHITE);
    } else if (layer.getGeometryType().equals(Geometry.Type.POLYGON)) {
      Polygon polygon = new Polygon();
      polygon.startPath(0, 0);
      polygon.lineTo(40, 0);
      polygon.lineTo(40, 40);
      polygon.lineTo(0, 40);
      polygon.lineTo(0, 0);
      bitmap = SymbolHelper.getLegendImage(symbol, polygon, 50, 50, Color.WHITE);
    }
    return bitmap;
  }

  private void populateTemplateView(LinearLayout layerTemplate, Bitmap bitmap, final FeatureTemplate featureTemplate,
      final FeatureLayer flayer, final Symbol symbol) {
    LinearLayout templateAndType = new LinearLayout(context);
    templateAndType.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
        android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
    templateAndType.setOrientation(LinearLayout.VERTICAL);
    templateAndType.setPadding(10, 10, 10, 10);

    final ImageButton template = new ImageButton(context);
    template.setBackgroundColor(Color.WHITE);

    template.setImageBitmap(bitmap);
    template.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        selectedLayer = flayer;
        selectedTemplate = featureTemplate;
        selectedSymbol = symbol;
        dismiss();

      }
    });

    TextView templateType = new TextView(context);
    templateType.setText(featureTemplate.getName());
    templateType.setPadding(5, 5, 5, 5);
    templateAndType.addView(template);
    templateAndType.addView(templateType);

    LinearLayout.LayoutParams templateParams = new LinearLayout.LayoutParams(
        android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    templateParams.setMargins(20, 20, 20, 20);
    layerTemplate.addView(templateAndType, templateParams);
  }

  public FeatureLayer getSelectedLayer() {
    return selectedLayer;
  }

  public FeatureTemplate getselectedTemplate() {

    return selectedTemplate;
  }

  public void clearSelection() {
    this.selectedTemplate = null;
    this.selectedLayer = null;
  }

  public Symbol getSelectedSymbol() {
    return selectedSymbol;
  }

}




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