Android Open Source - ExpertAndroid Form Activity






From Project

Back to project page ExpertAndroid.

License

The source code is released under:

MIT License

If you think the Android project ExpertAndroid 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.androidbook.parse;
//ww w .  ja v  a2  s.  com
import java.util.ArrayList;

import android.view.View;
import android.view.ViewGroup.LayoutParams;

/*
 * Uses the field validator framework to do form validation
 * for derived activities.
 * Most useful for activities that are mainly forms.
 * 
 * What it does
 * ************
 * 1. overrides the setContentView() to call
 * initializeFormFields()
 * 2. In that function gather your fields and
 * register them as validators
 * 3. Knows how to validate the validator set
 * 
 * How to use it
 * ****************
 * 1. Extend FormActivity
 * 2. Override initializeFormFields()
 * 3. Gather your fields in step2
 * 4. Register fields through addValidator()
 * 5. Call validate() of form activity
 * 6. The field validators will set errors based on Android framework
 * 
 * initializeFormFields()
 * ************************************** 
 * int min=5;
 * int max=10;
 * String error = "Should be between 5 and 10";
 * MinMaxValidator mmv = new MinMaxValidator(5,10,error);
 * 
 * TextView control; boolean required=true;
 * Field f = new Field(control, true);
 * f.addValidator(mmv);
 * f.addValidatort(..others..);
 * 
 * See SignupSuccessActivity to see how this is used
 * 
 */
public abstract class FormActivity 
extends BaseActivity
{
  public FormActivity(String inTag) {
    super(inTag);
  }

  protected abstract void initializeFormFields();
  
  private ArrayList<IValidator> ruleSet = new ArrayList<IValidator>();
  
  public void addValidator(IValidator v)
  {
    ruleSet.add(v);
  }
  public boolean validateForm()
  {
    boolean finalResult = true;
    for(IValidator v: ruleSet)
    {
      boolean result = v.validate();
      if (result == false)
      {
        finalResult = false;
      }
      //if true go around
      //if all true it should stay true
    }
    return finalResult;
  }

  @Override
  public void setContentView(int viewid) {
    super.setContentView(viewid);
    initializeFormFields();
  }
}//eof-class





Java Source Code List

com.androidbook.notebad.NoteEditor.java
com.androidbook.notebad.NotePadProvider.java
com.androidbook.notebad.NotePad.java
com.androidbook.notebad.NotesList.java
com.androidbook.notebad.TitleEditor.java
com.androidbook.parse.BaseActivity.java
com.androidbook.parse.BaseListActivity.java
com.androidbook.parse.CreateAMeaningActivity.java
com.androidbook.parse.CreateAWordActivity.java
com.androidbook.parse.Field.java
com.androidbook.parse.FormActivity.java
com.androidbook.parse.IReportBack.java
com.androidbook.parse.IValidator.java
com.androidbook.parse.IValueValidator.java
com.androidbook.parse.LoginActivity.java
com.androidbook.parse.ParseApplication.java
com.androidbook.parse.ParseObjectWrapperOld1.java
com.androidbook.parse.ParseObjectWrapper.java
com.androidbook.parse.ParseStarterProjectActivity.java
com.androidbook.parse.PasswordFieldRule.java
com.androidbook.parse.PasswordResetActivity.java
com.androidbook.parse.PasswordResetSuccessActivity.java
com.androidbook.parse.SignupActivity.java
com.androidbook.parse.SignupSuccessActivity.java
com.androidbook.parse.StringUtils.java
com.androidbook.parse.UserListActivity.java
com.androidbook.parse.WelcomeActivity.java
com.androidbook.parse.WordListActivity.java
com.androidbook.parse.WordListAdapter.java
com.androidbook.parse.WordMeaningListAdapter.java
com.androidbook.parse.WordMeaning.java
com.androidbook.parse.WordMeaningsListActivity.java
com.androidbook.parse.Word.java
com.iuriio.demos.expertandroid.ch10search.MainActivity.java
com.iuriio.demos.expertandroid.ch10search.SearchActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.MainActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.SearchActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.SimpleSuggestionProvider.java
com.iuriio.demos.expertandroid.ch11searchprovider.SuggestUrlProvider.java
com.iuriio.demos.expertandroid.ch13parsesimple.BaseActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.LoginActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.MainActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseApp.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseObjectWrapper.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseStarterProjectActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.PasswordResetSuccessActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.ResetPasswordActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.SignupActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.StringUtils.java
com.iuriio.demos.expertandroid.ch13parsesimple.WordListActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.Word.java
com.iuriio.demos.expertandroid.ch1circleview.AbstractBaseView.java
com.iuriio.demos.expertandroid.ch1circleview.CircleView.java
com.iuriio.demos.expertandroid.ch1circleview.MainActivity.java
com.iuriio.demos.expertandroid.ch2durationcontrol.DatePickerFragment.java
com.iuriio.demos.expertandroid.ch2durationcontrol.DurationControl.java
com.iuriio.demos.expertandroid.ch2durationcontrol.MainActivity.java
com.iuriio.demos.expertandroid.ch3flowlayout.FlowLayout.java
com.iuriio.demos.expertandroid.ch3flowlayout.MainActivity.java
com.iuriio.demos.expertandroid.ch4gsonserialization.ChildObject.java
com.iuriio.demos.expertandroid.ch4gsonserialization.MainActivity.java
com.iuriio.demos.expertandroid.ch4gsonserialization.MainObject.java
com.iuriio.demos.expertandroid.ch6forms.BaseActivity.java
com.iuriio.demos.expertandroid.ch6forms.Field.java
com.iuriio.demos.expertandroid.ch6forms.FormActivity.java
com.iuriio.demos.expertandroid.ch6forms.IValidator.java
com.iuriio.demos.expertandroid.ch6forms.IValueValidator.java
com.iuriio.demos.expertandroid.ch6forms.MainActivity.java
com.iuriio.demos.expertandroid.ch6forms.PasswordFieldRule.java
com.iuriio.demos.expertandroid.ch6forms.StringUtils.java
com.iuriio.demos.expertandroid.ch6forms.WelcomeActivity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.AbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.AnimatedSimpleTriangleRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20AbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20ControlledAnimatedTexturedCubeRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20SimpleTriangleRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20SingleTextureAbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.FrustumDimensions.java
com.iuriio.demos.expertandroid.ch9openglexperiments.MainActivity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.MyApplication.java
com.iuriio.demos.expertandroid.ch9openglexperiments.OpenGLES10Activity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.OpenGLES20Activity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.PolygonRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.RegularPolygon.java
com.iuriio.demos.expertandroid.ch9openglexperiments.Shape.java
com.iuriio.demos.expertandroid.ch9openglexperiments.SimpleTriangleRenderer.java
converters.FieldTransporter.java
converters.IFieldTransport.java
converters.IntegerFieldTransport.java
converters.ParseObjectEssentials.java
converters.StringFieldTransport.java
converters.User.java
converters.ValueField.java