FormMaster


Source link: https://github.com/adib2149/FormMaster

Form-Master

Easily build big and bigger forms with minimal effort

This library aids in building bigger forms on-the-fly. Forms with large number of elements can easily be added programmatically within a few minutes.

Features

  • Easily build big and bigger forms with minimal effort
  • Fast color change as needed

Installation

Add this in your app's build.gradle file:

compile 'me.riddhimanadib.form-master:form-master:1.1.0' 

How to use

  1. Add a Recyclerview anywhere in the layout where you want your list to be shown (If confused, look at the examples in this repo).
<?xml version="1.0" encoding="utf-8"?> <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

<android.support.v7.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:id="@+id/recyclerView"

android:descendantFocusability="beforeDescendants" />  </LinearLayout> 
  1. Add the Form Elements programmatically in your activity
// initialize variables mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
 mFormBuilder = new FormBuildHelper(this, mRecyclerView);
  // declare form elements FormHeader header = FormHeader.createInstance("Personal Info");
 FormElementTextEmail element = FormElementTextEmail.createInstance().setTitle("Email").setHint("Enter Email");

 // add them in a list List<FormObject> formItems = new ArrayList<>();
 formItems.add(header);
 formItems.add(element);
  // build and display the form mFormBuilder.addFormElements(formItems);
 mFormBuilder.refreshView();
 
  1. Now build and run!!

Changelog

####v1.1.0

  1. New FormElement type: Switch.
  2. New way to define the form elements.
  3. Can set Titles in alert dialogs for Date and Time type form element.
  4. Can set Positive and negative texts for Date, Time and Switch type form elements.
  5. Can set Date and Time formats (if unset, default format will be used).

Reference

Item Definition

Header:

FormHeader header = FormHeader.createInstance("Personal Info");
 

Regular Elements:

General object format

<Class> element = <Class>.createInstance()
  .setTag(101123151) // optional tag to uniquely identify the elemnt for later use
  .setType(FormElement.TYPE_PICKER_MULTI_CHECKBOX) // setting input type
  .setTitle("Pick your favourite fruit") // setting title
  .setValue("Banana") // setting value of the field, if any
  .setOptions(fruits) // setting pickable options, if any
  .setHint("e.g. banana, guava etc") // setting hints, if any
  .setRequired(false);
 // marking if the form element is required to be filled to make the form valid, include if needed 

Samples:

// email input FormElementTextEmail element = FormElementTextEmail.createInstance().setTitle("Email").setHint("Enter Email");
  // phone number input FormElementTextPhone element = FormElementTextPhone.createInstance().setTitle("Phone").setValue("+8801712345678");
  // single line text input FormElementTextSingleLine element = FormElementTextSingleLine.createInstance().setTitle("Location").setValue("Dhaka");
  // multi line text input (default 4) FormElementTextMultiLine element = FormElementTextMultiLine.createInstance().setTitle("Address");
  // number element input FormElementTextNumber element = FormElementTextNumber.createInstance().setTitle("Zip Code").setValue("1000");
  // date picker input FormElementPickerDate element = FormElementPickerDate.createInstance().setTitle("Date").setDateFormat("MMM dd, yyyy");
  // time picker input FormElementPickerTime element = FormElementPickerTime.createInstance().setTitle("Time").setTimeFormat("KK hh");
  // password input FormElementTextPassword element = FormElementTextPassword.createInstance().setTitle("Password").setValue("abcd1234");
  // switch input FormElementSwitch element = FormElementSwitch.createInstance().setTitle("Frozen?").setSwitchTexts("Yes", "No");
  // single item picker input List<String> fruits = new ArrayList<>();
 fruits.add("Banana");
 fruits.add("Orange");
 fruits.add("Mango");
 fruits.add("Guava");
 FormElementPickerSingle element = FormElementPickerSingle.createInstance().setTitle("Single Item").setOptions(fruits).setPickerTitle("Pick any item");
  // multiple items picker input List<String> fruits = new ArrayList<>();
 fruits.add("Banana");
 fruits.add("Orange");
 fruits.add("Mango");
 fruits.add("Guava");
 FormElementPickerMulti element = FormElementPickerMulti.createInstance().setTitle("Multi Items").setOptions(fruits).setPickerTitle("Pick one or more").setNegativeText("reset");
 

Set form element value change listener to get changed value instantly

While creating new instance of FormBuildHelper, add a listener in the constructor

Have a look at the example code for details

FormBuildHelper mFormBuilder = new FormBuildHelper(this, mRecyclerView, new OnFormElementValueChangedListener() {

  @Override
  public void onValueChanged(FormElement formElement) {

// do anything here with formElement.getValue()
  
}
 
}
 );
 

Set unique tags for form elements (for later value retrieval)

Just add a unique tag for the element

FormElement element = FormElement.createInstance()
  .setTag(2149) // unique tag number to identify this element
  .setType(FormElement.TYPE_PICKER_MULTI_CHECKBOX)
  .setTitle("Pick your favourite fruit");
 

Get value for unique form elements

Use the unique tag assigned earlier to retrieve value (See examples in this repo)

FormElement targetElement = mFormBuilder.getFormElement(2149);
 String targetValue = targetElement.getValue();
 

Check if form is valid

Use this method if you need to check whether the required elements of the form is completed

mFormBuilder.isValidForm();
 // returns boolean whether the form is valid or not 

Form accent color change

If you want to change the colors, just override the colors in your colors.xml file:

<color name="colorFormMasterHeaderBackground">#DDDDDD</color> <color name="colorFormMasterHeaderText">#000000</color> <color name="colorFormMasterElementBackground">#FFFFFF</color> <color name="colorFormMasterElementTextTitle">#222222</color> <color name="colorFormMasterElementTextValue">#000000</color> <color name="colorFormMasterDivider">#DDDDDD</color> 

Form UI change

If you want to change how the forms look, just override the layout xml named form_element.xml and/or form_element_header.xml in your project.

Just make sure to keep the ID name same as it is in the library for the components.

android:id="@+id/formElementTitle" android:id="@+id/formElementValue" 

Contributing

Send Pull Requests and you're in!! Alternatively, you can start adding issues here in this repo!

License

This Library is released under the Apache License, Version 2.0.

Resources

A CoordinatorLayout behavior which mimics the functionality of DrawerLayout.

This is a library to help creating expanding views with animation in Android.

A Gradle Plugin that notifies about ending of the build task.

Protobuf Plugin for Gradle.

Modification to the standard Maven plugin to be compatible with android-library projects (aar).

Vertical marquee view.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes