Skip to content

Commit

Permalink
Merge pull request Esri#98 from Esri/dop/optimize-samples
Browse files Browse the repository at this point in the history
Dop/optimize samples
  • Loading branch information
doneill committed Nov 3, 2015
2 parents d5f7e03 + b640559 commit 22a7c4e
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 128 deletions.
2 changes: 1 addition & 1 deletion AttributeEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.esri.arcgis.android.samples.attributeeditor"
minSdkVersion 15
targetSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion AttributeEditor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:label="@string/app_name" >
<activity
android:name=".AttributeEditorActivity"
android:configChanges="orientation"
android:configChanges="orientation|screenSize|uiMode"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,39 @@
*/
public class AttributeEditorActivity extends Activity {

MapView mapView;

ArcGISFeatureLayer featureLayer;
ArcGISDynamicMapServiceLayer dmsl;

Point pointClicked;

LayoutInflater inflator;

AttributeListAdapter listAdapter;

Envelope initextent;

ListView listView;

View listLayout;
// arcgis components
private MapView mapView;
private ArcGISFeatureLayer featureLayer;
private ArcGISDynamicMapServiceLayer operationalLayer;
private Point pointClicked;
private Envelope initextent;

// android components
private LayoutInflater inflator;
private AttributeListAdapter listAdapter;
private ListView listView;
private View listLayout;

public static final String TAG = "AttributeEditorSample";

static final int ATTRIBUTE_EDITOR_DIALOG_ID = 1;
private static final int ATTRIBUTE_EDITOR_DIALOG_ID = 1;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);



mapView = new MapView(this);
initextent = new Envelope(-10868502.895856911, 4470034.144641369,
-10837928.084542884, 4492965.25312689);
mapView.setExtent(initextent, 0);
ArcGISTiledMapServiceLayer tmsl = new ArcGISTiledMapServiceLayer(
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
mapView.addLayer(tmsl);
ArcGISTiledMapServiceLayer basemap = new ArcGISTiledMapServiceLayer(getResources().getString(R.string.basemap));
mapView.addLayer(basemap);

dmsl = new ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/MapServer");
mapView.addLayer(dmsl);
operationalLayer = new ArcGISDynamicMapServiceLayer(getResources().getString(R.string.operational_layer));
mapView.addLayer(operationalLayer);

featureLayer = new ArcGISFeatureLayer(
"http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/FeatureServer/0",
MODE.SELECTION);
getResources().getString(R.string.feature_layer),
MODE.SELECTION);
setContentView(mapView);

SimpleFillSymbol sfs = new SimpleFillSymbol(Color.TRANSPARENT);
Expand All @@ -111,18 +102,12 @@ public void onCreate(Bundle savedInstanceState) {

// Create a new AttributeListAdapter when the feature layer is initialized
if (featureLayer.isInitialized()) {

listAdapter = new AttributeListAdapter(this, featureLayer.getFields(), featureLayer.getTypes(),
featureLayer.getTypeIdField());

} else {

featureLayer.setOnStatusChangedListener(new OnStatusChangedListener() {

private static final long serialVersionUID = 1L;

public void onStatusChanged(Object source, STATUS status) {

if (status == STATUS.INITIALIZED) {
listAdapter = new AttributeListAdapter(AttributeEditorActivity.this, featureLayer.getFields(), featureLayer
.getTypes(), featureLayer.getTypeIdField());
Expand All @@ -133,11 +118,9 @@ public void onStatusChanged(Object source, STATUS status) {

// Set tap listener for MapView
mapView.setOnSingleTapListener(new OnSingleTapListener() {

private static final long serialVersionUID = 1L;

public void onSingleTap(float x, float y) {

// convert event into screen click
pointClicked = mapView.toMapPoint(x, y);

Expand All @@ -153,15 +136,11 @@ public void onSingleTap(float x, float y) {

// handle any errors
public void onError(Throwable e) {

Log.d(TAG, "Select Features Error" + e.getLocalizedMessage());

}

public void onCallback(FeatureSet queryResults) {

if (queryResults.getGraphics().length > 0) {

Log.d(
TAG,
"Feature found id="
Expand Down Expand Up @@ -226,7 +205,7 @@ protected Dialog onCreateDialog(int id) {
/**
* Helper method to return an OnClickListener for the Apply button
*/
public OnClickListener returnOnClickApplyChangesListener() {
private OnClickListener returnOnClickApplyChangesListener() {

return new OnClickListener() {

Expand All @@ -235,14 +214,14 @@ public void onClick(View v) {
boolean isTypeField = false;
boolean hasEdits = false;
boolean updateMapLayer = false;
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();

// loop through each attribute and set the new values if they have
// changed
for (int i = 0; i < listAdapter.getCount(); i++) {

AttributeItem item = (AttributeItem) listAdapter.getItem(i);
String value = "";
String value;

// check to see if the View has been set
if (item.getView() != null) {
Expand Down Expand Up @@ -326,7 +305,7 @@ public void onClick(View v) {
/**
* OnClick method for the Discard button
*/
public OnClickListener returnOnClickDiscardChangesListener() {
private OnClickListener returnOnClickDiscardChangesListener() {

return new OnClickListener() {

Expand All @@ -345,7 +324,7 @@ public void onClick(View v) {
*
* @return CallbackListener<FeatureEditResult[][]>
*/
CallbackListener<FeatureEditResult[][]> createEditCallbackListener(final boolean updateLayer) {
private CallbackListener<FeatureEditResult[][]> createEditCallbackListener(final boolean updateLayer) {

return new CallbackListener<FeatureEditResult[][]>() {

Expand All @@ -360,7 +339,7 @@ public void onCallback(FeatureEditResult[][] result) {
// updated features
if (updateLayer) {

dmsl.refresh();
operationalLayer.refresh();

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* POJO for storing the data associated with a row in the attributes list
*/
public class AttributeItem {
class AttributeItem {

private Field field;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,21 @@
* Adapter class which contains the logic of how to use and process the
* FeatureLayers Fields and Attributes into an List Layout
*/
public class AttributeListAdapter extends BaseAdapter {
class AttributeListAdapter extends BaseAdapter {

FeatureSet featureSet;

Field[] fields;

FeatureType[] types;

String typeIdFieldName;

Context context;

LayoutInflater lInflator;

int[] editableFieldIndexes;

String[] typeNames;

HashMap<String, FeatureType> typeMap;

AttributeItem[] items;

DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT,
private final Field[] fields;
private final FeatureType[] types;
private final String typeIdFieldName;
private final Context context;
private final LayoutInflater lInflator;
private final int[] editableFieldIndexes;
private final String[] typeNames;
private final HashMap<String, FeatureType> typeMap;
private AttributeItem[] items;

final DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.SHORT);

/**
Expand Down Expand Up @@ -129,7 +121,7 @@ public Object getItem(int position) {
// array created at startup
int fieldIndex = this.editableFieldIndexes[position];

AttributeItem row = null;
AttributeItem row;

// check to see if we have already created an attribute item if not
// create
Expand Down Expand Up @@ -263,8 +255,8 @@ public void setFeatureSet(FeatureSet featureSet) {
* value that is passed in from the list (the features value). Can be used
* for domains as well as types.
*/
Spinner createSpinnerViewFromArray(View container, Field field,
Object value, String[] values) {
private Spinner createSpinnerViewFromArray(View container, Field field,
Object value, String[] values) {

TextView fieldAlias = (TextView) container
.findViewById(R.id.field_alias_txt);
Expand All @@ -273,7 +265,7 @@ Spinner createSpinnerViewFromArray(View container, Field field,
fieldAlias.setText(field.getAlias());
spinner.setPrompt(field.getAlias());

ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(
this.context, android.R.layout.simple_spinner_item, values);
spinnerAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Expand All @@ -290,7 +282,7 @@ Spinner createSpinnerViewFromArray(View container, Field field,
* it uses the locale and presents a button with the date and time in short
* format.
*/
Button createDateButtonFromLongValue(View container, Field field, long date) {
private Button createDateButtonFromLongValue(View container, Field field, long date) {

TextView fieldAlias = (TextView) container
.findViewById(R.id.field_alias_txt);
Expand All @@ -314,7 +306,7 @@ Button createDateButtonFromLongValue(View container, Field field, long date) {
* is applied here, it is assumed that the container has this set already
* (in XML).
*/
View createAttributeRow(View container, Field field, Object value) {
private View createAttributeRow(View container, Field field, Object value) {

TextView fieldAlias = (TextView) container
.findViewById(R.id.field_alias_txt);
Expand Down Expand Up @@ -344,7 +336,7 @@ View createAttributeRow(View container, Field field, Object value) {
/**
* Helper method to create the date button and its associated events
*/
void addListenersToDatebutton(Button dateButton) {
private void addListenersToDatebutton(Button dateButton) {

// create new onDateSetLisetener with the button associated with it
final ListOnDateSetListener listener = new ListOnDateSetListener(
Expand Down Expand Up @@ -393,7 +385,7 @@ public void onClick(View v) {
*/
class ListOnDateSetListener implements OnDateSetListener {

Button button;
final Button button;

public ListOnDateSetListener(Button button) {

Expand Down
Loading

0 comments on commit 22a7c4e

Please sign in to comment.