Library that allows you to easily and quickly create forms in Android with little code

Overview

NexusDialog

Simple Form Generator for Android

NexusDialog is a library that allows you to dynamically generate forms in Android with little code. It's great for apps with many form-based UIs, since it reduces the boilerplate code to setup the view layout and tie things together in the Activity. Currently, it supports Android API 10+.

This library follows semantic versioning. Note that since this library is still active in development, new releases might introduce interface-breaking changes, which will be indicated in the changelog. NexusDialog 1.0.0 will be the first stable release.

A Simple Example

To give you an idea of the simplicity of NexusDialog, here's a screenshot of a simple example:

screenshot

Here's the code for that example (less than 7 lines of real code!):

import java.util.Arrays;
import com.github.dkharrat.nexusdialog.FormActivity;
import com.github.dkharrat.nexusdialog.controllers.*;

public class SimpleExample extends FormActivity {

    @Override protected void initForm() {
        setTitle("Simple Example");

        FormSectionController section = new FormSectionController(this, "Personal Info");
        section.addElement(new EditTextController(this, "firstName", "First name"));
        section.addElement(new EditTextController(this, "lastName", "Last name"));
        section.addElement(new SelectionController(this, "gender", "Gender", true, "Select", Arrays.asList("Male", "Female"), true));

        getFormController().addSection(section);
    }
}

For more examples, browse the sample directory.

Features

NexusDialog supports many built-in fields for your form, like text boxes, date pickers, spinners, etc. The framework is also designed to be extensible so that you can easily add custom form elements if needed. Contributions are also welcome! If you've implemented a custom control that is useful, pull requests are welcome and appreciated! Currently, the following form elements are supported:

  • ValueController: Shows a TextView containing a value
  • EditTextController: EditText view that allows for free-form text input.
  • CheckBoxController: CheckBox view that allows for two-states: either checked or unchecked.
  • DatePickerController: Displays a date picker to allow choosing a specific date
  • TimePickerController: Displays a time picker to allow choosing a specific time
  • SelectionController: Displays a spinner with a list of item to select from
  • SearchableSelectionController: Displays a (typically large) list of items to select from, with the ability to search the list and also allow free-form text.

Apps Using NexusDialog

Do you have an app that's utilizing NexusDialog? Let me know and I'll add a link to it here!

How to Add NexusDialog to Your Project

There are multiple ways to include your project, depending on your build environment:

Gradle

Add the following dependency to your build.gradle file for your project:

dependencies {
  compile 'com.github.dkharrat.nexusdialog:nexusdialog:0.4.2'
}

Make sure your application is using the Android SDK v23 or later in your build.gradle file:

android {
    compileSdkVersion 23
    buildToolsVersion "23"
    ...
}

Maven

Add the following dependency to your pom.xml file for your project (requires android-maven-plugin 3.8.0+):

<dependency>
    <groupId>com.github.dkharrat.nexusdialog</groupId>
    <artifactId>nexusdialog</artifactId>
    <version>0.4.2</version>
    <type>aar</type>
</dependency>

Android Studio or IntelliJ 13+

Add the appropriate dependency in your build.gradle file and refresh your project.

How to Use NexusDialog

Once NexusDialog is setup as a dependency in your project (by following the instructions above), you can start creating forms right away! The main classes you will be working with the most are:

  • FormActivity or FormActivityWithActionBar: If you wish to use the default Activity implementation for NexusDialog, this is the base class for each activity you wish to display a form in. Your activity must inherit from it. Form setup is done in the initForm() method.

  • FormController: This is the main class that manages the form elements of NexusDialog. It provides simple APIs to quickly create and manage form fields. FormActivity creates this class for you, or you can be create one manually for custom Activities.

  • FormElementController: Although you will not be using this class directly, you will be using its subclasses. All form elements (text boxes, labels, sections, etc.) inherit from this base class, which provides them common functionality and properties they need. Also, you could use FormSectionController to group a set of form fields together.

  • FormModel: This class abstracts the data model your form will use. It's the interface that NexusDialog uses to access and update the underlying data model the form is based on. A FormActivity uses it to initialize the field values to the desired values when its first displayed, as well as update the underlying model when values change in the UI. FromActivity uses a default generic FormModel based on a key-value store that is usually sufficient for most use cases. However, if you need more control over how the form data is retrieved and stored, you can provide your custom implementation (via FormActivity#setModel).

Add some fields grouped by section

public class RegistrationForm extends FormActivity {
    @Override protected void initForm() {
        setTitle("Register Account");

        FormSectionController section1 = new FormSectionController(this, "Personal Info");
        section1.addElement(new EditTextController(this, "firstName", "First name"));
        section1.addElement(new EditTextController(this, "lastName", "Last name"));
        getFormController().addSection(section1);

        FormSectionController section2 = new FormSectionController(this, "Account");
        section2.addElement(new EditTextController(this, "username", "Username"));
        section2.addElement(new EditTextController(this, "password", "Password") {{
            setSecureEntry(true);
        }});
        getFormController().addSection(section2);
    }
}

Initialize fields to certain values when the form is first displayed

@Override protected void initForm() {
    // form setup
    // ...

    getModel().setValue("firstName", "John");
    getModel().setValue("lastName", "Smith");
}

To retrieve the current field value at any time:

getModel().getValue("firstName");

Listen to changes in fields:

getModel().addPropertyChangeListener("firstName", new PropertyChangeListener() {
    @Override public void propertyChange(PropertyChangeEvent event) {
        LOG.i("tag", "Value was: " + event.getOldValue() + ", now: " + event.getNewValue());
    }
});

Please browse through the samples included with the project for examples on how NexusDialog can be used.

Documentation

See the current Javadoc.

Styling

TODO

Adding Custom Elements

If the built-in form controls provided by NexusDialog don't meet your needs, you can easily extend NexusDialog to provide custom form elements. The common parent class for all form elements is FormElementController. Among other things, FormElementController tells NexusDialog how to construct the view to display in the form.

Typically your custom element falls under one of these cases:

  1. Your custom element needs to show a label before a custom field: in this case, consider inheriting from LabeledFieldController which can provide the label functionality for you.

  2. Your custom element needs full customization for how it's displayed: in this case, inherit from FormElementController and implement the createView method to tell NexusDialog how to create the custom view.

Browse through the catalog sample for an example of implementing a custom element, or go over the code for the built-in form elements to get an idea how they work.

Planned Features

The framework is constantly being improved and new features are being implemented. The following improvements are planned:

  • Support buttons
  • Support sliders

Contributing

Contributions via pull requests are welcome! For suggestions, feedback, or feature requests, please submit an issue.

Author

Dia Kharrat - [email protected]
Twitter: http://twitter.com/dkharrat

License

Copyright 2013 Dia Kharrat

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • right to left

    right to left

    Hello, could you please tell me how to change direction of controls? For example i would like to set direction of EditTextController to right to left . is it possible?

    opened by ghazalarabi 12
  • Crash on screen rotation with SelectionController.

    Crash on screen rotation with SelectionController.

    The application crash on a screen rotation When a SelectionController is in the currently shown Form with an EditTextController or a SearchableSelectionController, with the Error:

    com.github.dkharrat.nexusdialog.sample E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.github.dkharrat.nexusdialog.sample, PID: 7355
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.github.dkharrat.nexusdialog.sample/com.github.dkharrat.nexusdialog.sample.SimpleExample}: java.lang.ClassCastException: android.widget.TextView$SavedState cannot be cast to android.widget.Spinner$SavedState
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            [...]
        Caused by: java.lang.ClassCastException: android.widget.TextView$SavedState cannot be cast to android.widget.Spinner$SavedState
            at android.widget.Spinner.onRestoreInstanceState(Spinner.java:762)
            [...]
    

    The value of SPINNER_ID and EDIT_TEXT_ID seems to be mixed-up on the redraw (I don't really see why though), so changing the value of SPINNER_ID will solve the problem.

    opened by aveuiller 11
  • Any plans to implement functionality on the Fragment level?

    Any plans to implement functionality on the Fragment level?

    For example, if using a ViewPager to switch between sections of the form it would be necessary to be able to add form sections and elements in each Fragment, rather than the Activity.

    opened by theblang 11
  • FormFragment not function in pageadapter and tablayout

    FormFragment not function in pageadapter and tablayout

    I have problems in implementing the new feature formFragment because by putting them in a PageAdapter and tablayout only displays the first page but the other tabs are blank, they could help me make the right implementation, thanks

    opened by powellbird 4
  • Custom field validators

    Custom field validators

    This feature add the possibility to create and assign custom validations to field.

    These custom validations may enable the user to hold a better control on the inputs (I added an example in the ComplexForm sample).

    Does that feature/implementation suits you?

    opened by aveuiller 4
  • Field ID generation

    Field ID generation

    The fix wasn't as easy as expected, but I have something. :)

    I had to create every field View programmatically, because xml layouts will end with the same bug as #12, i.e. every field of the same type will share the same id, so Android will recognize them as the same and copy values between them on rotation. So the Idea is that every field has a new ID when created.

    At this point, the rotation creates new fields (thus with different IDs), so their values weren't kept. I had to make the FormModel Serializable in order to save it upon Activity destruction and re-set it on activity creation (which are called on a phone rotation without special treatment).

    This will Close #11

    opened by aveuiller 4
  • let setting element models from different places

    let setting element models from different places

    Before creating form, Users may need attach data to form elements. So Users can set model of elements before FormController.addFormElementsToView call.

    opened by Kml55 4
  • Failed to implement formFragment in Tablayout and Tabs, Please help

    Failed to implement formFragment in Tablayout and Tabs, Please help

    Good afternoon.

    This library is great.

    But when implementing the new formFragment feature in a Tablayout, viewpargeradapter and tabs, I get an error when I try to capture in the form's controls, a null error, either in the text or in the select.

    There is some special way for this feature to work correctly in the viewpageradapter and tablayout tab.

    Thank you.

    opened by blackbirdsr71br 3
  • Changing text/underline color

    Changing text/underline color

    I've look through entire code, couldn't find a simple way to change color to white (from black). Is kind of stupid to create custom element just to change color, or is it really the only way?

    opened by zmajeric 3
  • fragmentForm feature error

    fragmentForm feature error

    Good Afternoon.

    Could you help me with the following error please.

    FragmentForm property causes an error when using it with a FragmentPagerAdapter and a TabLayou and change Tab.

    The error is a null as I show in the following text.

    Com.github.dkharrat.nexusdialog.sample E / AndroidRuntime: FATAL EXCEPTION: main Process: com.github.dkharrat.nexusdialog.sample, PID: 2385 ## Java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.dkharrat.nexusdialog.FormElementController.refresh ()' on a null object reference At com.github.dkharrat.nexusdialog.FormController $ 1.propertyChange (FormController.java:248) At java.beans.PropertyChangeSupport.firePropertyChange (PropertyChangeSupport.java:396) At java.beans.PropertyChangeSupport.firePropertyChange (PropertyChangeSupport.java:88) At com.github.dkharrat.nexusdialog.FormModel.setValue (FormModel.java:62) At com.github.dkharrat.nexusdialog.controllers.EditTextController $ 1.afterTextChanged (EditTextController.java:202) At android.widget.TextView.sendAfterTextChanged (TextView.java:8017) At android.widget.TextView $ ChangeWatcher.afterTextChanged (TextView.java:10178) At android.text.SpannableStringBuilder.sendAfterTextChanged (SpannableStringBuilder.java:1043) At android.text.SpannableStringBuilder.replace (SpannableStringBuilder.java:560) At android.text.SpannableStringBuilder.replace (SpannableStringBuilder.java:492) At android.text.SpannableStringBuilder.replace (SpannableStringBuilder.java:491) At android.view.inputmethod.BaseInputConnection.replaceText (BaseInputConnection.java:685) At android.view.inputmethod.BaseInputConnection.setComposingText (BaseInputConnection.java:445) At com.android.internal.view.IInputConnectionWrapper.executeMessage (IInputConnectionWrapper.java:340) at

    opened by powellbird 2
  • Fragment Feature not function in tabbed application

    Fragment Feature not function in tabbed application

    The feature FormFragment only works if you set it on the same page of the activity, when I use tabLayout and FragmentPagerAdapter tabbed this does not work because when changing TAB, and want to use the controls, causes a null value and the application stops function.

    Example I have three fragments with different controls when changing tab and want to capture information in a text or change value in a picker marks the next error.

    FATAL EXCEPTION: main Process: com.github.dkharrat.nexusdialog.sample, PID: 28643 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.dkharrat.nexusdialog.FormElementController.refresh()' on a null object reference at com.github.dkharrat.nexusdialog.FormController$1.propertyChange(FormController.java:247) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:396) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:88) at com.github.dkharrat.nexusdialog.FormModel.setValue(FormModel.java:62) at com.github.dkharrat.nexusdialog.controllers.EditTextController$1.afterTextChanged(EditTextController.java:195) at android.widget.TextView.sendAfterTextChanged(TextView.java:8017) at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:10178) at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1043) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:560) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:492) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:491) at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:685) at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:445) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:340) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

    opened by powellbird 2
  • Layout Element

    Layout Element

    Como posso altera a visulizaรงรฃo dos elementos.

    image

    I would like the chosen option to be below the description, so the description of the field could extend to the side thus having more space for description

    image

    opened by gustavobrunoro 0
  • How can i support subsections?

    How can i support subsections?

    can someone suggest any ideas for supporting subsections in this library? @dkharrat I have requirements for this, It would be really nice of you to share any kind of ideas for supporting subsections.

    opened by srinivas3120 0
  • theme problem

    theme problem

    I am using nexusdialog and creating a form in my application, I need to support multiple theme in my application. For this reason I need to check the sharedPreferences for current theme in form before setting the layout in form, how could be possible when the layout is previously set.

    
     @Override
        public void onCreate(Bundle savedInstanceState) throws SQLException {
            super.onCreate(savedInstanceState);
    //chooseTheme is a method that check sharedpreferences for current theme and set the theme
    //this method should be before setContentView
            chooseTheme(this);
            this.setContentView(layout.form_activity);
    }
    
    opened by elnazem 0
  • change font color

    change font color

    I would like to know how to change the font color or back ground color of Edit Text. I tried to override the value_field but it didn't work. please help

    opened by ghazalarabi 0
  • cannot create tabbed dynamic views | with Fragments

    cannot create tabbed dynamic views | with Fragments

    cannot create two dyanamic views in two tabs with fragments where library only refers to one instance of fragmentview which already created. and when creating the second tab it is generated in 1st tab cause of that issue

    Please help to solve this

    opened by ThilinaF 0
Owner
Dia Kharrat
Dia Kharrat
A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

Carlos Mota 3 Oct 27, 2021
With MaterialTimelineView you can easily create a material looking timeline.

MaterialTimelineView With MaterialTimelineView you can easily create a material looking timeline. Setup The library is pushed to jCenter() as an AAR,

Przemek 454 Dec 19, 2022
Framework for quickly creating connected applications in Kotlin with minimal effort

Ktor is an asynchronous framework for creating microservices, web applications and more. Written in Kotlin from the ground up. import io.ktor.server.n

ktor.io 10.7k Jan 9, 2023
๐Ÿ‘‹ A common toolkit (utils) โš’๏ธ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! ๐Ÿญ

Toolkit [ ?? Work in progress โ› ?? ??๏ธ ?? ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

ๅ‡› 35 Jul 23, 2022
A react-like kotlin library to create an inventory ui easily in paper plugins

A react-like kotlin library to create an inventory ui easily in paper plugins

R2turnTrue 6 Aug 23, 2022
The KPy gradle plugin allows you to write Kotlin/Native code and use it from python.

The KPy gradle plugin allows you to write Kotlin/Native code and use it from python.

Martmists 14 Dec 26, 2022
Arrow Endpoint offers a composable Endpoint datatype, that allows us easily define an Endpoint from which we can derive clients, servers & documentation.

Arrow Endpoint Arrow Endpoint offers a composable Endpoint datatype, that allows us easily define an Endpoint from which we can derive clients, server

ฮ›RROW 23 Dec 15, 2022
Arrow Endpoint offers a composable Endpoint datatype, that allows us easily define an Endpoint from which we can derive clients, servers & documentation.

Arrow Endpoint Arrow Endpoint offers a composable Endpoint datatype, that allows us easily define an Endpoint from which we can derive clients, server

ฮ›RROW 8 Oct 11, 2021
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Practical Kotlin Multiplatform on the Web ๋ณธ ์ €์žฅ์†Œ๋Š” ์ฝ”ํ‹€๋ฆฐ ๋ฉ€ํ‹ฐํ”Œ๋žซํผ ๊ธฐ๋ฐ˜ ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์›Œํฌ์ˆ(๊ฐ•์ขŒ)์„ ์œ„ํ•ด ์ž‘์„ฑ๋œ ํ…œํ”Œ๋ฆฟ ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ๋Š” ๊ณณ์ž…๋‹ˆ๋‹ค. ์›Œํฌ์ˆ ๊ณผ์ •์—์„œ ์ฝ”ํ‹€๋ฆฐ ๋ฉ€ํ‹ฐํ”Œ๋žซํผ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ”„๋ก ํŠธ์—”๋“œ(front-end)๋Š” Ko

SpringRunner 14 Nov 5, 2022
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Building a Full Stack Web App with Kotlin Multiplatform ๋ณธ ์ €์žฅ์†Œ๋Š” INFCON 2022์—์„œ ์ฝ”ํ‹€๋ฆฐ ๋ฉ€ํ‹ฐํ”Œ๋žซํผ ๊ธฐ๋ฐ˜ ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ•ธ์ฆˆ์˜จ๋žฉ์„ ์œ„ํ•ด ์ž‘์„ฑ๋œ ํ…œํ”Œ๋ฆฟ ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ๋Š” ๊ณณ์ž…๋‹ˆ๋‹ค. ํ•ธ์ฆˆ์˜จ ๊ณผ์ •์—์„œ ์ฝ”ํ‹€๋ฆฐ ๋ฉ€ํ‹ฐํ”Œ๋žซํผ์„

Arawn Park 19 Sep 8, 2022
[Android Library] A SharedPreferences helper library to save and fetch the values easily.

Preference Helper A SharedPreferences helper library to save and fetch the values easily. Featured in Use in your project Add this to your module's bu

Naveen T P 13 Apr 4, 2020
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview Create carousel effect in recyclerview with the CarouselRecyclerview in a simple way. Including in your project Gradle Add below

Jack and phantom 514 Jan 8, 2023
A Gradle plugin to easily publish library components to Maven.

Component Publisher A Gradle plugin to easily publish components based on maven-publish. You can find the latest released plugin on Gradle Plugin Port

Hulk Su 7 Oct 24, 2022
Kotlin and Ktor app, which can easily be deployed to Heroku

[ ?? Work in progress ??โ€โ™€๏ธ โ› ?? ??๏ธ ?? ?? ?? ] Shoppe Kotlin Multiplatform App Kotlin and Ktor app, which can easily be deployed to Heroku. This appl

Adrian Witaszak 13 Oct 2, 2022
Movie app that receives popular movies and allows the user to search for the specific movie through the Rest API with help of retrofit library &MVVM architecture.

MovieClue Millions of movies, TV shows and people to discover. Explore now Movie app that recieves popular movies and allow the user to search for spe

Shubham Tomar 6 Mar 31, 2022
A simple and easy adapter for RecyclerView. You don't have to make adapters and view holders anymore. Slush will help you.

ํ•œ๊ตญ์–ด No more boilerplate adapters and view holders. Slush will make using RecyclerView easy and fast. The goal of this project is to make RecyclerView,

SeungHyun 26 Sep 13, 2022
Quick route to developer options page easily

QuickRoute Using Quick Settings Tile to navigate to Developer options page without click a lot of buttons. Preview Install Can install from Google Pla

Jintin 18 Oct 1, 2021
An android application for creating a journal for subjects you studied and also you can set timer for break.

Study Journal An android application for creating a journal for subjects you studied and also you can set timer for break between two consecutive subj

Prasoon 3 Aug 10, 2022