Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Metawidget (licensed under LGPL)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package org.metawidget.android.widget.widgetbuilder;
import static org.metawidget.inspector.InspectionResultConstants.*;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.metawidget.android.widget.AndroidMetawidget;
import org.metawidget.android.widget.AndroidValueAccessor;
import org.metawidget.android.widget.Stub;
import org.metawidget.iface.MetawidgetException;
import org.metawidget.util.CollectionUtils;
import org.metawidget.util.WidgetBuilderUtils;
import org.metawidget.util.simple.StringUtils;
import org.metawidget.widgetbuilder.iface.WidgetBuilder;
import android.R;
import android.content.Context;
import android.text.InputFilter;
import android.text.SpannableStringBuilder;
import android.text.method.DateKeyListener;
import android.text.method.DigitsKeyListener;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
/**
* WidgetBuilder for Android environments.
*
* Creates native Android Views, such as EditText and Spinner, to suit the
* inspected fields.
*
* @author Richard Kennard
*/
public class AndroidWidgetBuilder
implements WidgetBuilder, AndroidValueAccessor {
//
// Public methods
//
@SuppressWarnings( "deprecation" )
public Object getValue( View view ) {
// CheckBox
if ( view instanceof CheckBox ) {
return Boolean.valueOf( ( (CheckBox) view ).isChecked() );
}
// TextView/EditText
if ( view instanceof TextView ) {
CharSequence text = ( (TextView) view ).getText();
// Convert SpannableStringBuilder to Strings
//
// This is a little controversial, but it's painful to handle SpannableStringBuilder
// everywhere in client code
if ( text instanceof SpannableStringBuilder ) {
text = text.toString();
}
return text;
}
// DatePicker
if ( view instanceof DatePicker ) {
DatePicker datePicker = (DatePicker) view;
return new Date( datePicker.getYear() - 1900, datePicker.getMonth(), datePicker.getDayOfMonth() );
}
// Spinner
if ( view instanceof Spinner ) {
return ( (Spinner) view ).getSelectedItem();
}
return null;
}
@SuppressWarnings( "deprecation" )
public boolean setValue( Object value, View view ) {
// CheckBox
if ( view instanceof CheckBox ) {
( (CheckBox) view ).setChecked( (Boolean) value );
return true;
}
// TextView/EditText
if ( view instanceof TextView ) {
( (TextView) view ).setText( StringUtils.quietValueOf( value ) );
return true;
}
// DatePicker
if ( view instanceof DatePicker ) {
Date date = (Date) value;
( (DatePicker) view ).updateDate( 1900 + date.getYear(), date.getMonth(), date.getDate() );
return true;
}
// Spinner
if ( view instanceof Spinner ) {
AdapterView> adapterView = (AdapterView>) view;
@SuppressWarnings( "unchecked" )
ArrayAdapter