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.PopupUICustomization;
import java.util.Calendar;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import com.esri.android.map.popup.ArcGISEditAttributesAdapter;
import com.esri.android.map.popup.Popup;
/*
* Customized Attribute adapter to display graphic's attributes in edit mode
*
*/publicclass MyEditAttributesAdapter extends ArcGISEditAttributesAdapter {
private Drawable mAlertIcon;
public MyEditAttributesAdapter(Context context, Popup popup) {
super(context, popup);
// Change the layouts based on the type of the field.
// Code value domain field
setCodedValueLayoutResourceId(R.layout.popup_attribute_spinner,
R.id.label_textView, R.id.value_spinner);
// Range domain field
setRangeValueLayoutResourceId(R.layout.popup_attribute_spinner,
R.id.label_textView, R.id.value_spinner);
// Date field
setDateLayoutResourceId(R.layout.popup_attribute_date,
R.id.label_textView, R.id.value_button);
// Text field
setEditTextLayoutResourceId(R.layout.popup_attribute_edit_text,
R.id.label_textView, R.id.value_editText);
// Date picker used in a date field
setDatePickerLayoutResourceId(R.layout.popup_attribute_date_picker);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View layout = super.getView(position, convertView, parent);
if (layout != null) {
final AttributeInfo attributeInfo = getAttributeInfo(position);
FIELD_TYPE fieldType = determineFieldType(attributeInfo);
// set onclick listener to handle the click event for the "use current" button.
if (fieldType == FIELD_TYPE.DATE) {
Button nowButton = (Button) layout.findViewById(R.id.now_button);
nowButton.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) {
Calendar calendar = Calendar.getInstance();
Button dateButton = (Button) layout.findViewById(R.id.value_button);
// set the value of the date field to the current time.
try {
long now = calendar.getTimeInMillis();
mAttributes.put(attributeInfo.fieldInfo.getFieldName(), Long.valueOf(now));
dateButton.setText(mValueFormat.formatValue(mFeatureType, Long.valueOf(now),
mPopup.getPopupInfo().getFieldInfo(attributeInfo.field.getName())));
// call the popup modified listener to allow users to add their logic when a field is changed.
if (mPopup.getPopupListener() != null)
mPopup.getPopupListener().onPopupModified();
} catch (NumberFormatException e) {
// don't set the value, leave blank
}
}
});
}
}
return layout;
}
@Override
protectedvoid setRequiredState(View view, boolean required) {
View actualView = view;
if (view instanceof Spinner) {
Spinner spinner = (Spinner) view;
actualView = spinner.getSelectedView();
}
// Change the icon shown in the alert if a field is required.
if (actualView instanceof TextView) {
TextView editText = (TextView) actualView;
if (required && (Boolean.TRUE.equals(editText.getTag()))) {
if (mAlertIcon == null) {
mAlertIcon = mContext.getResources().getDrawable(R.drawable.required);
mAlertIcon.setColorFilter(Color.argb(255, 180, 180, 0), android.graphics.PorterDuff.Mode.SRC_IN);
int bound = (int) editText.getTextSize() + editText.getCompoundDrawablePadding();
mAlertIcon.setBounds(0, 0, bound, bound);
}
editText.setCompoundDrawables(null, null, mAlertIcon, null);
} else {
editText.setCompoundDrawables(null, null, null, null);
}
}
}
}