Android Open Source - arcgis-runtime-samples-android Stretch Parameters Fragment






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
 */*from   w ww . j  a  v a 2s. 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.arcgis.android.samples.localdata.localrasterdata;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;

import com.esri.core.renderer.RGBRenderer;
import com.esri.core.renderer.StretchParameters;
import com.esri.core.renderer.StretchParameters.ClipStretchParameters;
import com.esri.core.renderer.StretchParameters.HistogramStretchParamaeters;
import com.esri.core.renderer.StretchParameters.MinMaxStretchParameters;
import com.esri.core.renderer.StretchParameters.StdDevStretchParameters;
import com.esri.core.renderer.StretchRenderer;

/*
 * Dialog to allow users to select StretchType used in RGBRenderer and StretchRenderer.
 */
public class StretchParametersFragment extends DialogFragment implements OnClickListener {

  private SeekBar barStddev, barClipMin, barClipMax;
  private OnDialogDismissListener mDialogListener;
  private RendererType mType;
  private final static String KEY_INT = "code";
  private final static String KEY_STRETCH_TYPE ="type";
  private final static String KEY_MIN_CLIP = "minClip";
  private final static String KEY_MAX_CLIP = "maxClip";
  private final static String KEY_STANDARD_DEVIATION = "stdDev";
  private final static String KEY_GAMMA = "gamma";

  public static StretchParametersFragment newInstance(int code, int stretchType, 
      double stdDev, double minClip, double maxClip, double gamma) {
    StretchParametersFragment fragment = new StretchParametersFragment();

    Bundle args = new Bundle();
    args.putInt(KEY_INT, code);
    args.putInt(KEY_STRETCH_TYPE, stretchType);
    args.putDouble(KEY_STANDARD_DEVIATION, stdDev);
    args.putDouble(KEY_MIN_CLIP, minClip);
    args.putDouble(KEY_MAX_CLIP, maxClip);
    args.putDouble(KEY_GAMMA, gamma);
    fragment.setArguments(args);

    return fragment;
  }

  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    mDialogListener = (OnDialogDismissListener) getActivity();
    mType = RendererType.fromCode(getArguments().getInt(KEY_INT));

    // Create layout of the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = createView();

    builder.setView(view);
    builder.setTitle(mType.getName())
        .setPositiveButton(R.string.rgbrenderer_parameters_ok, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int whichButton) {
            doPositiveClick();
          }
        }).setNegativeButton(R.string.rgbrenderer_parameters_cancel, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int whichButton) {
            doNegativeClick();
          }
        });
    return builder.create();
  }

  @Override
  public void onClick(View view) {
    boolean checked = ((RadioButton) view).isChecked();
    // Check which radio button was clicked
    switch (view.getId()) {
    case R.id.radio_stretchtype_stddev:
      if (checked) {
        barStddev.setVisibility(View.VISIBLE);
        barClipMin.setVisibility(View.INVISIBLE);
        barClipMax.setVisibility(View.INVISIBLE);
      } else {
        barStddev.setVisibility(View.INVISIBLE);
      }
      break;
    case R.id.radio_stretchtype_pecentclip:
      if (checked) {
        barStddev.setVisibility(View.INVISIBLE);
        barClipMin.setVisibility(View.VISIBLE);
        barClipMax.setVisibility(View.VISIBLE);
      } else {
        barClipMin.setVisibility(View.INVISIBLE);
        barClipMax.setVisibility(View.INVISIBLE);
      }
      break;
    default:
      barStddev.setVisibility(View.INVISIBLE);
      barClipMin.setVisibility(View.INVISIBLE);
      barClipMax.setVisibility(View.INVISIBLE);
      break;
    }
  }

  private void checkStretchType(View view) {
    int index = getArguments().getInt(KEY_STRETCH_TYPE);
    barStddev = (SeekBar) view.findViewById(R.id.parameter_stddev);
    barStddev.setVisibility(View.INVISIBLE);
    barClipMin = (SeekBar) view.findViewById(R.id.parameter_minclip);
    barClipMin.setVisibility(View.INVISIBLE);
    barClipMax = (SeekBar) view.findViewById(R.id.parameter_maxclip);
    barClipMax.setVisibility(View.INVISIBLE);
    if ((index < 0) || (index > StretchParameters.StretchType.values().length))
      return;
    
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.rgbrenderer_parameters_group);
    switch (index) {
      case 0:
        radioGroup.check(R.id.radio_stretchtype_none);
        break;
      case 1:
        radioGroup.check(R.id.radio_stretchtype_minmax);
        break;
      case 2:
        radioGroup.check(R.id.radio_stretchtype_stddev);
        barStddev.setVisibility(View.VISIBLE);
        if (getArguments().getDouble(KEY_STANDARD_DEVIATION) != EditTextUtils.DEFAULT_DOUBLE_VALUE)
        {
          barStddev.setProgress((int) getArguments().getDouble(KEY_STANDARD_DEVIATION));
        }
        break;
      case 3:
        radioGroup.check(R.id.radio_stretchtype_histogram);
        break;
      case 4:
        radioGroup.check(R.id.radio_stretchtype_pecentclip);
        barClipMin.setVisibility(View.VISIBLE);
        if (getArguments().getDouble(KEY_MIN_CLIP) != EditTextUtils.DEFAULT_DOUBLE_VALUE) {
          barClipMin.setProgress((int) getArguments().getDouble(KEY_MIN_CLIP));
        }
        barClipMax.setVisibility(View.VISIBLE);
        if (getArguments().getDouble(KEY_MAX_CLIP) != EditTextUtils.DEFAULT_DOUBLE_VALUE) {
          barClipMax.setProgress((int) getArguments().getDouble(KEY_MAX_CLIP));
        }
        break;
      default:
        radioGroup.check(R.id.radio_stretchtype_none);
        break; 
    }
  }
  
  private View createView() {
    View view = getActivity().getLayoutInflater().inflate(R.layout.stretch_parameters, null);
    view.findViewById(R.id.radio_stretchtype_none).setOnClickListener(this);
    view.findViewById(R.id.radio_stretchtype_minmax).setOnClickListener(this);
    view.findViewById(R.id.radio_stretchtype_stddev).setOnClickListener(this);
    view.findViewById(R.id.radio_stretchtype_histogram).setOnClickListener(this);
    view.findViewById(R.id.radio_stretchtype_pecentclip).setOnClickListener(this);

    checkStretchType(view);
    EditTextUtils.setEditTextValue(view, R.id.parameter_stretch_gamma, getArguments().getDouble(KEY_GAMMA));
    return view;
  }
  
  private void doPositiveClick() {
    StretchParameters stretchParams = null;
    
    RadioGroup radioGroup = (RadioGroup) getDialog().findViewById(R.id.rgbrenderer_parameters_group);
    switch (radioGroup.getCheckedRadioButtonId()) {
    case R.id.radio_stretchtype_none:
      stretchParams = null;
      break;
    case R.id.radio_stretchtype_minmax:
      stretchParams = new MinMaxStretchParameters();
      break;
    case R.id.radio_stretchtype_stddev:
      StdDevStretchParameters stdDveStretch = new StdDevStretchParameters();
      if (barStddev.getVisibility() == View.VISIBLE) {
        stdDveStretch.setStdDev(barStddev.getProgress());
      }
      stretchParams = stdDveStretch;
      break;
    case R.id.radio_stretchtype_histogram:
      stretchParams = new HistogramStretchParamaeters();
      break;
    case R.id.radio_stretchtype_pecentclip:
      ClipStretchParameters clipStretch = new ClipStretchParameters();
      if (barClipMin.getVisibility() == View.VISIBLE) {
        clipStretch.setMinClip(barClipMin.getProgress());
      }
      if (barClipMax.getVisibility() == View.VISIBLE) {
        clipStretch.setMaxClip(barClipMax.getProgress());
      }
      stretchParams = clipStretch;
      break;
    }
    
    if (stretchParams != null) {
      EditText gammaText = (EditText) getDialog().findViewById(R.id.parameter_stretch_gamma);
      double gamma = EditTextUtils.getEditTextValue(gammaText);
      // default = -1
      stretchParams.setGamma(gamma);
    }

    if (mType == RendererType.RGB) {
      RGBRenderer rgbRenderer = new RGBRenderer();
      rgbRenderer.setStretchParameters(stretchParams);
      mDialogListener.onPositiveClicked(rgbRenderer);
    } else if (mType == RendererType.STRETCHED) {
      StretchRenderer renderer = new StretchRenderer();
      renderer.setStretchParameters(stretchParams);
      mDialogListener.onPositiveClicked(renderer);
    }
  }

  // Do nothing but dismiss the dialog.
  private void doNegativeClick() {

  }

}




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