diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b6b1eec
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+*/bin/*
+*/gen/*
+.idea/
+.gradle/
+*/.DS_Store
+gradle/
+gradlew
+gradlew.bat
+*/build/
+build/
+*.iml
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..f2533c7
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,9 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:1.1.0'
+ }
+}
diff --git a/formbuilder-android/.classpath b/formbuilder-android/.classpath
index 7bc01d9..d0eff61 100644
--- a/formbuilder-android/.classpath
+++ b/formbuilder-android/.classpath
@@ -3,6 +3,8 @@
+
+
diff --git a/formbuilder-android/.gitignore b/formbuilder-android/.gitignore
index b6b5597..73a5bf6 100644
--- a/formbuilder-android/.gitignore
+++ b/formbuilder-android/.gitignore
@@ -2,7 +2,7 @@
.metadata/
.project
.settings/
- bin/
- gen/
+ ./bin/
+ ./gen/
diff --git a/formbuilder-android/.project b/formbuilder-android/.project
new file mode 100644
index 0000000..d97a6e3
--- /dev/null
+++ b/formbuilder-android/.project
@@ -0,0 +1,33 @@
+
+
+ formbuilder-android
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/formbuilder-android/.settings/org.eclipse.jdt.core.prefs b/formbuilder-android/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..b080d2d
--- /dev/null
+++ b/formbuilder-android/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/formbuilder-android/AndroidManifest.xml b/formbuilder-android/AndroidManifest.xml
index e8a3465..54a451b 100644
--- a/formbuilder-android/AndroidManifest.xml
+++ b/formbuilder-android/AndroidManifest.xml
@@ -4,13 +4,14 @@
android:versionName="1.0" >
+ android:minSdkVersion="9"
+ android:targetSdkVersion="19" />
+ android:label="@string/app_name"
+ android:theme="@style/AppBaseTheme">
-
+
\ No newline at end of file
diff --git a/formbuilder-android/How to change the UI b/formbuilder-android/How to change the UI
new file mode 100644
index 0000000..cce36ee
--- /dev/null
+++ b/formbuilder-android/How to change the UI
@@ -0,0 +1,28 @@
+
+How to change the image for radio button/checkbox:
+
+1. Download the drawable/image from "http://android-holo-colors.com/".
+ This site can be used to download the drawables for the color of your choice.
+
+2. Transfer the contents to "workspace\FormBuilder-Android\formbuilder-android\res".
+ Ensure that the files are present in the various drawable folders.
+
+3. Go to "radio_custom.xml" for radio button, or "check_custom.xml" for checkbox present in the drawable folder.
+
+4. Identify the name of the image file in the required item tag-->android:drawable and change the file to the required
+ drawable.
+
+
+How to change colors in UI:
+
+1. Go to "color.xml" present in res/values.
+
+2. To change the TextView color, change the present color code to the required color code for the color name
+ "TextViewNormal".
+
+3. To change the color of EditText borders, change the present color code to the required color code for the color name
+ 1) "EditTextBeforeBorder" - When the focus is not on the EditText
+ 2) "EditTextAfterBorder" - When the focus is on the EditText
+
+4. To change the color of the ErrorMessage, change the present color code to the required color code for the color name
+ "ErrorMessage".
\ No newline at end of file
diff --git a/formbuilder-android/build.gradle b/formbuilder-android/build.gradle
new file mode 100644
index 0000000..a71a9e2
--- /dev/null
+++ b/formbuilder-android/build.gradle
@@ -0,0 +1,39 @@
+apply plugin: 'android-library'
+
+dependencies {
+ compile fileTree(dir: 'libs', include: '*.jar')
+}
+
+android {
+ compileSdkVersion 19
+ buildToolsVersion "22.0.1"
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_7
+ targetCompatibility JavaVersion.VERSION_1_7
+ }
+
+ sourceSets {
+ main {
+ manifest.srcFile 'AndroidManifest.xml'
+ java.srcDirs = ['src']
+ resources.srcDirs = ['src']
+ aidl.srcDirs = ['src']
+ renderscript.srcDirs = ['src']
+ res.srcDirs = ['res']
+ assets.srcDirs = ['assets']
+ }
+
+ // Move the tests to tests/java, tests/res, etc...
+ instrumentTest.setRoot('tests')
+
+ // Move the build types to build-types/
+ // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
+ // This moves them out of them default location under src//... which would
+ // conflict with src/ being used by the main source set.
+ // Adding new build types or product flavors should be accompanied
+ // by a similar customization.
+ debug.setRoot('build-types/debug')
+ release.setRoot('build-types/release')
+ }
+}
diff --git a/formbuilder-android/lint.xml b/formbuilder-android/lint.xml
index ee0eead..7732133 100644
--- a/formbuilder-android/lint.xml
+++ b/formbuilder-android/lint.xml
@@ -1,3 +1,4 @@
+
\ No newline at end of file
diff --git a/formbuilder-android/project.properties b/formbuilder-android/project.properties
new file mode 100644
index 0000000..91d2b02
--- /dev/null
+++ b/formbuilder-android/project.properties
@@ -0,0 +1,15 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
+android.library=true
diff --git a/formbuilder-android/res/drawable-hdpi/apptheme_btn_check_off_focused_holo_light.png b/formbuilder-android/res/drawable-hdpi/apptheme_btn_check_off_focused_holo_light.png
new file mode 100644
index 0000000..86796c8
Binary files /dev/null and b/formbuilder-android/res/drawable-hdpi/apptheme_btn_check_off_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-hdpi/apptheme_btn_check_on_focused_holo_light.png b/formbuilder-android/res/drawable-hdpi/apptheme_btn_check_on_focused_holo_light.png
new file mode 100644
index 0000000..c7f6676
Binary files /dev/null and b/formbuilder-android/res/drawable-hdpi/apptheme_btn_check_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-hdpi/apptheme_btn_radio_off_disabled_holo_light.png b/formbuilder-android/res/drawable-hdpi/apptheme_btn_radio_off_disabled_holo_light.png
new file mode 100644
index 0000000..25e8e1b
Binary files /dev/null and b/formbuilder-android/res/drawable-hdpi/apptheme_btn_radio_off_disabled_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-hdpi/apptheme_btn_radio_on_focused_holo_light.png b/formbuilder-android/res/drawable-hdpi/apptheme_btn_radio_on_focused_holo_light.png
new file mode 100644
index 0000000..5e7a8a1
Binary files /dev/null and b/formbuilder-android/res/drawable-hdpi/apptheme_btn_radio_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-mdpi/apptheme_btn_check_off_focused_holo_light.png b/formbuilder-android/res/drawable-mdpi/apptheme_btn_check_off_focused_holo_light.png
new file mode 100644
index 0000000..ed1a777
Binary files /dev/null and b/formbuilder-android/res/drawable-mdpi/apptheme_btn_check_off_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-mdpi/apptheme_btn_check_on_focused_holo_light.png b/formbuilder-android/res/drawable-mdpi/apptheme_btn_check_on_focused_holo_light.png
new file mode 100644
index 0000000..30e4424
Binary files /dev/null and b/formbuilder-android/res/drawable-mdpi/apptheme_btn_check_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-mdpi/apptheme_btn_radio_off_focused_holo_light.png b/formbuilder-android/res/drawable-mdpi/apptheme_btn_radio_off_focused_holo_light.png
new file mode 100644
index 0000000..88c4e5e
Binary files /dev/null and b/formbuilder-android/res/drawable-mdpi/apptheme_btn_radio_off_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-mdpi/apptheme_btn_radio_on_focused_holo_light.png b/formbuilder-android/res/drawable-mdpi/apptheme_btn_radio_on_focused_holo_light.png
new file mode 100644
index 0000000..ee76e43
Binary files /dev/null and b/formbuilder-android/res/drawable-mdpi/apptheme_btn_radio_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xhdpi/apptheme_btn_check_off_focused_holo_light.png b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_check_off_focused_holo_light.png
new file mode 100644
index 0000000..cca5fd6
Binary files /dev/null and b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_check_off_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xhdpi/apptheme_btn_check_on_focused_holo_light.png b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_check_on_focused_holo_light.png
new file mode 100644
index 0000000..d584134
Binary files /dev/null and b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_check_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xhdpi/apptheme_btn_radio_off_focused_holo_light.png b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_radio_off_focused_holo_light.png
new file mode 100644
index 0000000..04a8890
Binary files /dev/null and b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_radio_off_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xhdpi/apptheme_btn_radio_on_focused_holo_light.png b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_radio_on_focused_holo_light.png
new file mode 100644
index 0000000..72b0250
Binary files /dev/null and b/formbuilder-android/res/drawable-xhdpi/apptheme_btn_radio_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_check_off_focused_holo_light.png b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_check_off_focused_holo_light.png
new file mode 100644
index 0000000..04cbf7b
Binary files /dev/null and b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_check_off_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_check_on_focused_holo_light.png b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_check_on_focused_holo_light.png
new file mode 100644
index 0000000..8d9a36c
Binary files /dev/null and b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_check_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_radio_off_focused_holo_light.png b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_radio_off_focused_holo_light.png
new file mode 100644
index 0000000..dc00f77
Binary files /dev/null and b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_radio_off_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_radio_on_focused_holo_light.png b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_radio_on_focused_holo_light.png
new file mode 100644
index 0000000..8e9032b
Binary files /dev/null and b/formbuilder-android/res/drawable-xxhdpi/apptheme_btn_radio_on_focused_holo_light.png differ
diff --git a/formbuilder-android/res/drawable/after_select.xml b/formbuilder-android/res/drawable/after_select.xml
new file mode 100644
index 0000000..fa2adbf
--- /dev/null
+++ b/formbuilder-android/res/drawable/after_select.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/drawable/before_select.xml b/formbuilder-android/res/drawable/before_select.xml
new file mode 100644
index 0000000..68827f9
--- /dev/null
+++ b/formbuilder-android/res/drawable/before_select.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/formbuilder-android/res/drawable/button_pressed.xml b/formbuilder-android/res/drawable/button_pressed.xml
new file mode 100644
index 0000000..58609b8
--- /dev/null
+++ b/formbuilder-android/res/drawable/button_pressed.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/drawable/button_select.xml b/formbuilder-android/res/drawable/button_select.xml
new file mode 100644
index 0000000..079ddae
--- /dev/null
+++ b/formbuilder-android/res/drawable/button_select.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/drawable/button_unpressed.xml b/formbuilder-android/res/drawable/button_unpressed.xml
new file mode 100644
index 0000000..4978a4f
--- /dev/null
+++ b/formbuilder-android/res/drawable/button_unpressed.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/drawable/check_custom.xml b/formbuilder-android/res/drawable/check_custom.xml
new file mode 100644
index 0000000..5089632
--- /dev/null
+++ b/formbuilder-android/res/drawable/check_custom.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/formbuilder-android/res/drawable/cross_2.png b/formbuilder-android/res/drawable/cross_2.png
new file mode 100644
index 0000000..e3d1495
Binary files /dev/null and b/formbuilder-android/res/drawable/cross_2.png differ
diff --git a/formbuilder-android/res/drawable/cross_grey.png b/formbuilder-android/res/drawable/cross_grey.png
new file mode 100644
index 0000000..cdfda79
Binary files /dev/null and b/formbuilder-android/res/drawable/cross_grey.png differ
diff --git a/formbuilder-android/res/drawable/edit_text_selector.xml b/formbuilder-android/res/drawable/edit_text_selector.xml
new file mode 100644
index 0000000..1e7789b
--- /dev/null
+++ b/formbuilder-android/res/drawable/edit_text_selector.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/drawable/prev_next_buttons.xml b/formbuilder-android/res/drawable/prev_next_buttons.xml
new file mode 100644
index 0000000..8db3998
--- /dev/null
+++ b/formbuilder-android/res/drawable/prev_next_buttons.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/formbuilder-android/res/drawable/radio_custom.xml b/formbuilder-android/res/drawable/radio_custom.xml
new file mode 100644
index 0000000..56cc355
--- /dev/null
+++ b/formbuilder-android/res/drawable/radio_custom.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/drawable/spinner_pressed_false.xml b/formbuilder-android/res/drawable/spinner_pressed_false.xml
new file mode 100644
index 0000000..7ee5e9e
--- /dev/null
+++ b/formbuilder-android/res/drawable/spinner_pressed_false.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/drawable/spinner_pressed_true.xml b/formbuilder-android/res/drawable/spinner_pressed_true.xml
new file mode 100644
index 0000000..4ab5b95
--- /dev/null
+++ b/formbuilder-android/res/drawable/spinner_pressed_true.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
diff --git a/formbuilder-android/res/drawable/spinner_selector.xml b/formbuilder-android/res/drawable/spinner_selector.xml
new file mode 100644
index 0000000..dc9b047
--- /dev/null
+++ b/formbuilder-android/res/drawable/spinner_selector.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/address.xml b/formbuilder-android/res/layout/address.xml
new file mode 100644
index 0000000..861c386
--- /dev/null
+++ b/formbuilder-android/res/layout/address.xml
@@ -0,0 +1,160 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/capture.xml b/formbuilder-android/res/layout/capture.xml
new file mode 100644
index 0000000..945d8c3
--- /dev/null
+++ b/formbuilder-android/res/layout/capture.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/formbuilder-android/res/layout/captureadapter.xml b/formbuilder-android/res/layout/captureadapter.xml
new file mode 100644
index 0000000..34efa3c
--- /dev/null
+++ b/formbuilder-android/res/layout/captureadapter.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
diff --git a/formbuilder-android/res/layout/checkbox.xml b/formbuilder-android/res/layout/checkbox.xml
new file mode 100644
index 0000000..55cd59b
--- /dev/null
+++ b/formbuilder-android/res/layout/checkbox.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
diff --git a/formbuilder-android/res/layout/contact.xml b/formbuilder-android/res/layout/contact.xml
new file mode 100644
index 0000000..be2468c
--- /dev/null
+++ b/formbuilder-android/res/layout/contact.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/date_time_dialog.xml b/formbuilder-android/res/layout/date_time_dialog.xml
new file mode 100644
index 0000000..224dcec
--- /dev/null
+++ b/formbuilder-android/res/layout/date_time_dialog.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/datepicker.xml b/formbuilder-android/res/layout/datepicker.xml
new file mode 100644
index 0000000..a12f322
--- /dev/null
+++ b/formbuilder-android/res/layout/datepicker.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/datetimepicker.xml b/formbuilder-android/res/layout/datetimepicker.xml
new file mode 100644
index 0000000..0c02cec
--- /dev/null
+++ b/formbuilder-android/res/layout/datetimepicker.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/display_date_time.xml b/formbuilder-android/res/layout/display_date_time.xml
new file mode 100644
index 0000000..394141c
--- /dev/null
+++ b/formbuilder-android/res/layout/display_date_time.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/drop_down_xml.xml b/formbuilder-android/res/layout/drop_down_xml.xml
new file mode 100644
index 0000000..1990426
--- /dev/null
+++ b/formbuilder-android/res/layout/drop_down_xml.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/email.xml b/formbuilder-android/res/layout/email.xml
new file mode 100644
index 0000000..1d1f13d
--- /dev/null
+++ b/formbuilder-android/res/layout/email.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/fullname.xml b/formbuilder-android/res/layout/fullname.xml
index 3718c5a..d215c93 100644
--- a/formbuilder-android/res/layout/fullname.xml
+++ b/formbuilder-android/res/layout/fullname.xml
@@ -2,43 +2,58 @@
+ android:orientation="vertical"
+ android:paddingTop="5dp"
+ android:paddingBottom="5dp"
+ android:layout_margin="10dp" >
+ android:layout_height="wrap_content">
+
+
+
+
-
-
-
diff --git a/formbuilder-android/res/layout/multiline_edit_text.xml b/formbuilder-android/res/layout/multiline_edit_text.xml
new file mode 100644
index 0000000..5777a1a
--- /dev/null
+++ b/formbuilder-android/res/layout/multiline_edit_text.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/number_edit_text.xml b/formbuilder-android/res/layout/number_edit_text.xml
new file mode 100644
index 0000000..bdae185
--- /dev/null
+++ b/formbuilder-android/res/layout/number_edit_text.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/price.xml b/formbuilder-android/res/layout/price.xml
new file mode 100644
index 0000000..3630123
--- /dev/null
+++ b/formbuilder-android/res/layout/price.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/radio.xml b/formbuilder-android/res/layout/radio.xml
new file mode 100644
index 0000000..2ef4033
--- /dev/null
+++ b/formbuilder-android/res/layout/radio.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/simple_edit_text.xml b/formbuilder-android/res/layout/simple_edit_text.xml
new file mode 100644
index 0000000..05298ef
--- /dev/null
+++ b/formbuilder-android/res/layout/simple_edit_text.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/spinner_textview.xml b/formbuilder-android/res/layout/spinner_textview.xml
new file mode 100644
index 0000000..6122ee2
--- /dev/null
+++ b/formbuilder-android/res/layout/spinner_textview.xml
@@ -0,0 +1,7 @@
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/layout/time_picker.xml b/formbuilder-android/res/layout/time_picker.xml
new file mode 100644
index 0000000..2c932ef
--- /dev/null
+++ b/formbuilder-android/res/layout/time_picker.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/raw/roboto.ttf b/formbuilder-android/res/raw/roboto.ttf
new file mode 100644
index 0000000..3e6e2e7
Binary files /dev/null and b/formbuilder-android/res/raw/roboto.ttf differ
diff --git a/formbuilder-android/res/values-v11/styles.xml b/formbuilder-android/res/values-v11/styles.xml
index 3c02242..3d4da9f 100644
--- a/formbuilder-android/res/values-v11/styles.xml
+++ b/formbuilder-android/res/values-v11/styles.xml
@@ -4,8 +4,13 @@
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
-
+
-
+
\ No newline at end of file
diff --git a/formbuilder-android/res/values-v14/styles.xml b/formbuilder-android/res/values-v14/styles.xml
index a91fd03..4427d54 100644
--- a/formbuilder-android/res/values-v14/styles.xml
+++ b/formbuilder-android/res/values-v14/styles.xml
@@ -5,8 +5,11 @@
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
-
+
-
+
\ No newline at end of file
diff --git a/formbuilder-android/res/values/arrays.xml b/formbuilder-android/res/values/arrays.xml
index 4181111..c41f145 100644
--- a/formbuilder-android/res/values/arrays.xml
+++ b/formbuilder-android/res/values/arrays.xml
@@ -6,4 +6,5 @@
- Miss
- Dr
+
diff --git a/formbuilder-android/res/values/color.xml b/formbuilder-android/res/values/color.xml
new file mode 100644
index 0000000..8dcf014
--- /dev/null
+++ b/formbuilder-android/res/values/color.xml
@@ -0,0 +1,15 @@
+
+
+
+ #000000
+ #000000
+ #ff0000
+ #ff0000
+ #000000
+ #eeeeee
+ #888888
+ #eeeeee
+ #939393
+ #ffffff
+
+
\ No newline at end of file
diff --git a/formbuilder-android/res/values/colors_apptheme.xml b/formbuilder-android/res/values/colors_apptheme.xml
new file mode 100644
index 0000000..e9bb5e3
--- /dev/null
+++ b/formbuilder-android/res/values/colors_apptheme.xml
@@ -0,0 +1,4 @@
+
+
+ #3aa610
+
diff --git a/formbuilder-android/res/values/dd_contents.xml b/formbuilder-android/res/values/dd_contents.xml
new file mode 100644
index 0000000..fd9e3eb
--- /dev/null
+++ b/formbuilder-android/res/values/dd_contents.xml
@@ -0,0 +1,10 @@
+
+
+
+ - a
+ - b
+ - c
+ - d
+
+
+
diff --git a/formbuilder-android/res/values/strings.xml b/formbuilder-android/res/values/strings.xml
index d1a6f3d..735a654 100644
--- a/formbuilder-android/res/values/strings.xml
+++ b/formbuilder-android/res/values/strings.xml
@@ -2,5 +2,5 @@
formbuilder
Name
-
+ Email
\ No newline at end of file
diff --git a/formbuilder-android/res/values/styles.xml b/formbuilder-android/res/values/styles.xml
new file mode 100644
index 0000000..64993e2
--- /dev/null
+++ b/formbuilder-android/res/values/styles.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Address.java b/formbuilder-android/src/com/vertis/formbuilder/Address.java
new file mode 100644
index 0000000..cdb6059
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Address.java
@@ -0,0 +1,314 @@
+package com.vertis.formbuilder;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Locale;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Typeface;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnFocusChangeListener;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+public class Address implements IField {
+
+ private FieldConfig config;
+
+ //Views
+ LinearLayout ad;
+ EditText streetEditText;
+ TextView streetTextView;
+ EditText cityEditText;
+ TextView cityTextView;
+ EditText stateEditText;
+ TextView stateTextView;
+ EditText zipEditText;
+ TextView zipTextView;
+ Spinner countriesSpinner;
+ TextView countryTextView;
+ TextView title;
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String country="";
+ int countryPosition=0;
+ @Expose
+ String street="";
+ @Expose
+ String city="";
+ @Expose
+ String state="";
+ @Expose
+ String zip="";
+
+ String fullAddress="";
+ private Typeface mFont;
+
+ //constructor to populate config
+ public Address(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @Override
+ public void createForm(Activity context) {
+ mFont = new FormBuilderUtil().getFontFromRes(context);
+ getViesByID(context);
+ setTextSizeAndTypeFace();
+ defineViewSettings(context);
+ setViewValues();
+ mapView();
+ setValues();
+ }
+
+ public void getViesByID(Activity context) {
+ LayoutInflater inflater = context.getLayoutInflater();
+ ad=(LinearLayout) inflater.inflate(R.layout.address,null);
+ streetTextView = ( TextView) ad.findViewById(R.id.textViewStreet);
+ cityTextView = (TextView) ad.findViewById(R.id.textViewCity);
+ stateTextView = (TextView) ad.findViewById(R.id.textViewState);
+ zipEditText = (EditText) ad.findViewById(R.id.editTextZip);
+ countryTextView= (TextView) ad.findViewById(R.id.textViewCountry);
+ title= (TextView) ad.findViewById(R.id.textViewAddress);
+ streetEditText = (EditText) ad.findViewById(R.id.editTextStreet);
+ cityEditText = (EditText) ad.findViewById(R.id.editTextCity);
+ stateEditText = (EditText) ad.findViewById(R.id.editTextState);
+ zipTextView = (TextView) ad.findViewById(R.id.textViewZip);
+ countriesSpinner =(Spinner) ad.findViewById(R.id.Country);
+ }
+
+ private void setTextSizeAndTypeFace() {
+ setTextSize(title, 14f);
+ setTextSize(streetTextView, 14f);
+ setTextSize(cityTextView, 14f);
+ setTextSize(stateTextView, 14f);
+ setTextSize(zipTextView, 14f);
+ setTextSize(countryTextView, 14f);
+ setTextSize(streetEditText, 12.5f);
+ setTextSize(cityEditText, 12.5f);
+ setTextSize(stateEditText, 12.5f);
+ setTextSize(zipEditText, 12.5f);
+ }
+
+ private void addTextChangeListeners() {
+ streetEditText.addTextChangedListener(new CustomTextChangeListener(config));
+ cityEditText.addTextChangedListener(new CustomTextChangeListener(config));
+ stateEditText.addTextChangedListener(new CustomTextChangeListener(config));
+ zipEditText.addTextChangedListener(new CustomTextChangeListener(config));
+ }
+
+ public void setTextSize(TextView view, float size){
+ view.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
+ view.setTypeface(mFont);
+ }
+
+ private void defineViewSettings(Activity context) {
+ streetEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus)
+ noErrorMessage(streetTextView);
+ else
+ setValues();
+ }
+ });
+ cityEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus)
+ noErrorMessage(cityTextView);
+ else
+ setValues();
+ }
+ });
+ stateEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus)
+ noErrorMessage(stateTextView);
+ else
+ setValues();
+ }
+ });
+ zipEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus)
+ noErrorMessage(zipTextView);
+ else
+ setValues();
+ }
+ });
+ ArrayAdapter adapter = getAdapter(context);
+ countriesSpinner.setAdapter(adapter);
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid() + "_1", ad);
+ ViewLookup.mapField(this.config.getCid() + "_1_1", streetEditText);
+ ViewLookup.mapField(this.config.getCid() + "_1_2", cityEditText);
+ ViewLookup.mapField(this.config.getCid() + "_1_3", stateEditText);
+ ViewLookup.mapField(this.config.getCid() + "_1_4", zipEditText);
+ ViewLookup.mapField(this.config.getCid() + "_1_5", countriesSpinner);
+ }
+ private void setViewValues() {
+ title.setText(this.config.getLabel() + (this.config.getRequired() ? "*" : ""));
+ streetEditText.setText(street);
+ cityEditText.setText(city);
+ stateEditText.setText(state);
+ zipEditText.setText(zip);
+ countriesSpinner.setSelection(countryPosition);
+ }
+
+ private ArrayList getCountryList() {
+ Locale[] locale = Locale.getAvailableLocales();
+ ArrayList countries = new ArrayList();
+ String country;
+ int i = 0;
+ for (Locale loc : locale) {
+ country = loc.getDisplayCountry();
+ if (country.length() > 0 && !countries.contains(country)) {
+ if (!countries.contains(new SelectElement(i, loc.getCountry(),
+ loc.getDisplayCountry(), 1))) {
+ countries.add(new SelectElement(i, loc.getCountry(), loc
+ .getDisplayCountry(), 1));
+ }
+ }
+ i = i++;
+ }
+ Collections.sort(countries);
+ return countries;
+ }
+
+ private ArrayAdapter getAdapter(Context context) {
+ return new CountriesArrayAdapter(context, getCountryList());
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return ad;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid = false;
+ try {
+ valid = checkEmpty(streetTextView, street, " Street Required");
+ valid = checkEmpty(cityTextView, city, " City Required");
+ valid = checkEmpty(stateTextView, state, " State Required");
+ valid = checkEmpty(zipTextView, zip, " Zip Required");
+ valid = checkEmpty(countryTextView, country, " Country Required");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return valid;
+ }
+
+ private boolean checkEmpty(TextView view, String street, String errorMessage) {
+ if(config.getRequired() && street.equals("")){
+ errorMessage(view, errorMessage);
+ return false;
+ } else{
+ noErrorMessage(view);
+ return true;
+ }
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(TextView view ,String message) {
+ if(view==null)return;
+ view.setText((this.config.getRequired()?"*":"") );
+ view.setText(view.getText() + message);
+ view.setTextColor(R.color.ErrorMessage);
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage(TextView view ) {
+ if(view==null)return;
+ view.setText(this.config.getRequired()?"Street*":"" );
+ view.setTextColor(R.color.TextViewNormal);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(ad!=null){
+ street=streetEditText.getText().toString();
+ city=cityEditText.getText().toString();
+ state=stateEditText.getText().toString();
+ zip=zipEditText.getText().toString();
+ countryPosition=countriesSpinner.getSelectedItemPosition();
+ country=countriesSpinner.getSelectedItem().toString();
+ fullAddress=street+" "+city+" "+state+" "+zip+" "+country;
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ ad=null;
+ streetEditText=null;
+ streetTextView=null;
+ cityEditText=null;
+ cityTextView=null;
+ stateEditText=null;
+ stateTextView=null;
+ zipEditText=null;
+ zipTextView=null;
+ countriesSpinner=null;
+ countryTextView=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ @Override
+ public void hideField() {
+ if(ad!=null){
+ ad.setVisibility(View.GONE);
+ ad.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(ad!=null){
+ ad.setVisibility(View.VISIBLE);
+ ad.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(fullAddress.toLowerCase().contains(value.toLowerCase()) || fullAddress.trim().equals("")){
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(ad!=null) {
+ return !ad.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Capture.java b/formbuilder-android/src/com/vertis/formbuilder/Capture.java
new file mode 100644
index 0000000..3d8c207
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Capture.java
@@ -0,0 +1,238 @@
+package com.vertis.formbuilder;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Locale;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Environment;
+import android.provider.MediaStore;
+import android.util.Log;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.LinearLayout.LayoutParams;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+public class Capture implements IField{
+
+ private static final int ACTION_LOAD_IMAGE = 100;
+ private FieldConfig config;
+ //Views
+ LinearLayout llCapture;
+ TextView tvCapture;
+ Button buttonCaptureImage, buttonCaptureVideo, buttonCaptureAudio;
+ ArrayAdapter contentAdapter;
+ ArrayList captureList= new ArrayList();
+ ListView lvCapture;
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String capturedFile="";
+ private Activity context;
+ private Uri uri;
+
+ public Capture(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @Override
+ public void createForm(final Activity context) {
+ this.context = context;
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ llCapture=(LinearLayout) inflater.inflate(R.layout.capture,null);
+ tvCapture = (TextView) llCapture.findViewById(R.id.textViewCapture);
+ buttonCaptureImage=(Button) llCapture.findViewById(R.id.buttonImage);
+ buttonCaptureVideo=(Button) llCapture.findViewById(R.id.buttonVideo);
+ buttonCaptureAudio=(Button) llCapture.findViewById(R.id.buttonAudio);
+ lvCapture=(ListView) llCapture.findViewById(R.id.listCapturedObjects);
+ tvCapture.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f);
+ tvCapture.setTypeface(new FormBuilderUtil().getFontFromRes(context));
+ buttonCaptureImage.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
+ if (uri == null) {
+ uri = getOutputVideoUri("PIC", ".jpg");
+ }
+ cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
+ context.startActivityForResult(cameraIntent, ACTION_LOAD_IMAGE);
+
+ Toast.makeText(context, "Image Captured.", Toast.LENGTH_SHORT).show();
+ captureList.add("Image");
+ contentAdapter.notifyDataSetChanged();
+ modifyListViewHeight();
+ }
+ });
+ buttonCaptureVideo.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(context, "Video Captured.", Toast.LENGTH_SHORT).show();
+ captureList.add("Video");
+ contentAdapter.notifyDataSetChanged();
+ modifyListViewHeight();
+ }
+ });
+ buttonCaptureAudio.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(context, "Audio Captured.", Toast.LENGTH_SHORT).show();
+ captureList.add("Audio");
+ contentAdapter.notifyDataSetChanged();
+ modifyListViewHeight();
+ }
+ });
+ setViewValues();
+ mapView();
+ setValues();
+ noErrorMessage();
+ }
+
+ private static Uri getOutputVideoUri(String prefix, String safix) {
+ if (Environment.getExternalStorageState() == null) {
+ return null;
+ }
+ File mediaStorage = new File(Environment.getExternalStorageDirectory()
+ .getAbsolutePath() + "/SheqScan/uploadFiles");
+ if (!mediaStorage.exists()) {
+ if (!mediaStorage.mkdirs()) {
+ Log.e("TAG", "failed to create directory: " + mediaStorage);
+ }
+ return null;
+ }
+ String timeStamp = new SimpleDateFormat("dd-MM-yyyy_hh-mm-ss",
+ Locale.US).format(new Date());
+ File mediaFile = new File(mediaStorage, prefix + "_" + timeStamp
+ + safix);
+ return Uri.fromFile(mediaFile);
+ }
+
+ public void decreaseHeight(){
+ int lvHeight = captureList.size()*62;
+ lvCapture.setLayoutParams(new LayoutParams(lvCapture.getWidth(), lvHeight));
+ }
+ private void modifyListViewHeight(){
+ int lvHeight = captureList.size()*62;
+ lvCapture.setLayoutParams(new LayoutParams(lvCapture.getWidth(), lvHeight));
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(tvCapture==null)return;
+ tvCapture.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvCapture.setTextColor(R.color.TextViewNormal);
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid()+"_1", llCapture);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", buttonCaptureImage);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", buttonCaptureVideo);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", buttonCaptureAudio);
+ }
+
+ private void setViewValues() {
+ tvCapture.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvCapture.setTextColor(-1);
+ contentAdapter= new CaptureContentAdapter(context, R.layout.capture, captureList, Capture.this);
+ lvCapture.setAdapter(contentAdapter);
+ //modifyListViewHeight();
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llCapture;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ if(config.getRequired() && captureList.isEmpty()){
+ valid=false;
+ errorMessage(" Required");
+ }else{
+ valid=true;
+ }
+ return valid;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(String message) {
+ if(tvCapture==null)return;
+ tvCapture.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvCapture.setText(tvCapture.getText() + message);
+ tvCapture.setTextColor(R.color.ErrorMessage);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ llCapture=null;
+ tvCapture=null;
+ buttonCaptureImage=null;
+ buttonCaptureVideo=null;
+ buttonCaptureAudio=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llCapture!=null){
+ llCapture.setVisibility(View.GONE);
+ llCapture.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llCapture!=null){
+ llCapture.setVisibility(View.VISIBLE);
+ llCapture.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")) {
+ for (String capture : captureList) {
+ if (capture.equals(value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(llCapture!=null) {
+ return !llCapture.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/CaptureContentAdapter.java b/formbuilder-android/src/com/vertis/formbuilder/CaptureContentAdapter.java
new file mode 100644
index 0000000..cd35510
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/CaptureContentAdapter.java
@@ -0,0 +1,55 @@
+package com.vertis.formbuilder;
+
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+public class CaptureContentAdapter extends ArrayAdapter {
+
+ @Override
+ public int getCount() {
+ return capturedObject.size();
+ }
+
+ private ArrayList capturedObject;
+ private Context context;
+ private Button cross;
+ private Capture c;
+
+ public CaptureContentAdapter(Context context, int resource, ArrayList objects, Capture c) {
+ super(context, resource, objects);
+ this.context = context;
+ this.capturedObject = objects;
+ this.c=c;
+ }
+
+ public View getView(final int position, View convertView, ViewGroup parent) {
+ View return_view= convertView;
+ if (return_view == null) {
+ LayoutInflater layoutInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ return_view = layoutInf.inflate(R.layout.captureadapter, null);
+ }
+ TextView tv = (TextView)return_view.findViewById(R.id.tvCapturedFile);
+ tv.setText(this.capturedObject.get(position));
+ cross= (Button)return_view.findViewById(R.id.crossImage);
+ cross.setTag(position);
+ cross.setOnClickListener(new OnClickListener (){
+ @Override
+ public void onClick(View v) {
+ int pos = (Integer) v.getTag();
+ capturedObject.remove(capturedObject.get(pos));
+ c.decreaseHeight();
+ CaptureContentAdapter.this.notifyDataSetChanged();
+ }
+ });
+ return return_view;
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Checkbox.java b/formbuilder-android/src/com/vertis/formbuilder/Checkbox.java
new file mode 100644
index 0000000..ca089c4
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Checkbox.java
@@ -0,0 +1,194 @@
+package com.vertis.formbuilder;
+
+import java.util.ArrayList;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.Listeners.CheckboxChangeListener;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.graphics.Color;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class Checkbox implements IField {
+
+ private FieldConfig config;
+ // Views
+ LinearLayout llCheckBox;
+ TextView tvCheckBox;
+ EditText otherTextBox;
+ ArrayList checkedValues= new ArrayList();
+ ArrayList cbValues = new ArrayList();
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String optionSelected;
+ int checked = 0;
+ @Expose
+ String other;
+
+ public Checkbox(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @Override
+ public void createForm(Activity context) {
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ llCheckBox=(LinearLayout) inflater.inflate(R.layout.checkbox,null);
+ tvCheckBox = (TextView) llCheckBox.findViewById(R.id.tvCheckbox);
+ tvCheckBox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f);
+ tvCheckBox.setTypeface(new FormBuilderUtil().getFontFromRes(context));
+ int i = 0;
+ if(cbValues != null)
+ cbValues.clear();
+ for (i = 0; i < this.config.getField_options().getOptions().size(); i++) {
+ addBox(i, context);
+ }
+ llCheckBox.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ llCheckBox.setFocusableInTouchMode(true);
+ llCheckBox.setFocusable(true);
+ llCheckBox.requestFocus();
+ }
+ });
+ mapview();
+ setViewValues();
+ }
+
+ private void mapview() {
+ int j=1;
+ ViewLookup.mapField(this.config.getCid()+"_1",llCheckBox);
+ for (CheckBox i : cbValues) {
+ ViewLookup.mapField(this.config.getCid()+"_1_"+j,i);
+ j++;
+ }
+ }
+
+ private void setViewValues() {
+ tvCheckBox.setText(this.config.getLabel() + (this.config.getRequired()?"*":""));
+ tvCheckBox.setTextColor(Color.BLACK);
+ }
+
+ public void addBox(int i, Activity context) {
+ CheckBox box = new CheckBox(context);
+ ViewLookup.mapField(this.config.getCid()+"_1_1_"+Integer.toString(i), llCheckBox);
+ if(i < this.config.getField_options().getOptions().size()){
+ box.setText(this.config.getField_options().getOptions().get(i).getLabel());
+ box.setChecked(this.config.getField_options().getOptions().get(i).getChecked());
+ }
+ if(checkedValues.contains(this.config.getField_options().getOptions().get(i).getLabel())){
+ box.setChecked(true);
+ }
+ llCheckBox.addView(box);
+ box.setButtonDrawable(R.drawable.check_custom);
+ cbValues.add(box);
+ box.setOnCheckedChangeListener(new CheckboxChangeListener(config));
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llCheckBox;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ if(checkedValues.isEmpty()){
+ valid=false;
+ errorMessage(" Pick one!");
+ } else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(tvCheckBox==null)return;
+ tvCheckBox.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvCheckBox.setTextColor(R.color.TextViewNormal);
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(String message) {
+ if(tvCheckBox==null)return;
+ tvCheckBox.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+// tvCheckBox.setText(tvCheckBox.getText() + " " + message);
+ tvCheckBox.setTextColor(R.color.ErrorMessage);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(llCheckBox!=null){
+ checkedValues.clear();
+ for (CheckBox tempCheck : cbValues) {
+ if(tempCheck.isChecked()){
+ checkedValues.add(tempCheck.getText().toString());
+ }
+ }
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ llCheckBox=null;
+ tvCheckBox=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llCheckBox!=null){
+ llCheckBox.setVisibility(View.GONE);
+ llCheckBox.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llCheckBox!=null){
+ llCheckBox.setVisibility(View.VISIBLE);
+ llCheckBox.invalidate();
+ }
+ }
+
+ @Override
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ for (String checkedValue : checkedValues) {
+ if(checkedValue.toLowerCase().equals(value.toLowerCase())){
+ return true;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(llCheckBox!=null) {
+ return !llCheckBox.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Contact.java b/formbuilder-android/src/com/vertis/formbuilder/Contact.java
new file mode 100644
index 0000000..0c2bf4e
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Contact.java
@@ -0,0 +1,188 @@
+package com.vertis.formbuilder;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.vertis.formbuilder.Listeners.TextChangeListener;
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnFocusChangeListener;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+public class Contact implements IField{
+
+ private FieldConfig config;
+ private static final String contactPattern = "^[0-9]+$";
+ //Views
+ LinearLayout llContact;
+ TextView tvContact;
+ EditText etContact;
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String contactNo="10";
+ private Typeface font;
+
+ public Contact(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ @Override
+ public void createForm(Activity context) {
+ font = new FormBuilderUtil().getFontFromRes(context);
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ llContact=(LinearLayout) inflater.inflate(R.layout.contact,null);
+ tvContact = (TextView) llContact.findViewById(R.id.textViewContact);
+ etContact = (EditText) llContact.findViewById(R.id.editTextContact);
+ setTextTypefaseAndTextSize(etContact, 12.5f);
+ setTextTypefaseAndTextSize(tvContact, 14);
+ tvContact.setTextColor(R.color.TextViewNormal);
+
+ etContact.addTextChangedListener(new TextChangeListener(config));
+
+ defineViewSettings(context);
+ setViewValues();
+ mapView();
+ setValues();
+ noErrorMessage();
+ }
+
+ public void setTextTypefaseAndTextSize(TextView view, float size) {
+ view.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
+ view.setTypeface(font);
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(tvContact==null)return;
+ tvContact.setText(this.config.getLabel() + (this.config.getRequired() ? "*" : ""));
+ tvContact.setTextColor(R.color.TextViewNormal);
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(String message) {
+ if(tvContact==null)return;
+ tvContact.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvContact.setText(tvContact.getText() + message);
+ tvContact.setTextColor(R.color.ErrorMessage);
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid() + "_1", llContact);
+ ViewLookup.mapField(this.config.getCid() + "_1_1", etContact);
+ }
+
+ private void setViewValues() {
+ tvContact.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ etContact.setText(contactNo);
+ tvContact.setTextColor(-1);
+ }
+
+ private void defineViewSettings(Activity context) {
+ etContact.setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus)
+ noErrorMessage();
+ else
+ setValues();
+ }
+ });
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llContact;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ String contactString = contactNo;
+ if(config.getRequired() && contactString.equals("")){
+ valid=false;
+ errorMessage(" Required");
+ } else if(contactValidation(contactString)){
+ valid=false;
+ errorMessage(" Invalid entry");
+ } else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
+ }
+
+ private boolean contactValidation(String contactCheck) {
+ Pattern pattern = Pattern.compile(contactPattern);
+ Matcher matcher = pattern.matcher(contactCheck);
+ return !matcher.matches();
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(llContact!=null){
+ contactNo=etContact.getText().toString();
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ llContact=null;
+ tvContact=null;
+ etContact=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llContact!=null){
+ llContact.setVisibility(View.GONE);
+ llContact.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llContact!=null){
+ llContact.setVisibility(View.VISIBLE);
+ llContact.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(contactNo.equals(value) || contactNo.equals("")){
+ return true;
+ }
+ return false;
+ }
+ return false;
+ }
+
+ public boolean isHidden(){
+ if(llContact!=null) {
+ return !llContact.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/CountriesArrayAdapter.java b/formbuilder-android/src/com/vertis/formbuilder/CountriesArrayAdapter.java
new file mode 100644
index 0000000..4df33ea
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/CountriesArrayAdapter.java
@@ -0,0 +1,32 @@
+package com.vertis.formbuilder;
+
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+public class CountriesArrayAdapter extends ArrayAdapter {
+ ArrayList CountryList;
+
+ public CountriesArrayAdapter(Context context,ArrayList CountryList) {
+ super(context, android.R.layout.simple_list_item_1, CountryList);
+ this.CountryList = CountryList;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View v= convertView;
+ if (v == null) {
+ LayoutInflater layoutInf = (LayoutInflater) getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ v = layoutInf.inflate(R.layout.spinner_textview, null);
+ }
+ TextView tv = (TextView)v.findViewById(android.R.id.text1);
+ tv.setText(this.CountryList.get(position).value);
+ return v;
+ }
+}
diff --git a/formbuilder-android/src/com/vertis/formbuilder/CustomTextChangeListener.java b/formbuilder-android/src/com/vertis/formbuilder/CustomTextChangeListener.java
new file mode 100644
index 0000000..11239ef
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/CustomTextChangeListener.java
@@ -0,0 +1,71 @@
+package com.vertis.formbuilder;
+
+import java.util.ArrayList;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.vertis.formbuilder.parser.FieldConfig;
+
+import android.text.Editable;
+import android.text.TextWatcher;
+
+public class CustomTextChangeListener implements TextWatcher {
+ private FieldConfig config;
+
+ CustomTextChangeListener(FieldConfig config){
+ this.config = config;
+ }
+ /* Other methods protected by singleton-ness */
+ protected void demoMethod( ) {
+ System.out.println("demoMethod for singleton");
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ int size= config.getConditions().size();
+ for (int i = 0; i < size; i++) {
+ checkCondition(config.getConditions().get(i).getSource(), config.getConditions().get(i).getCondition(),
+ config.getConditions().get(i).getValue(), config.getConditions().get(i).getAction(),
+ config.getConditions().get(i).getTarget(), config.getConditions().get(i).getIsSource());
+ }
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) { }
+
+ private void checkCondition(String source, String condition, String value, String action, String target, Boolean isSource) {
+ String actualValue="";
+ IField sourceField = getFieldFromCID(source);
+ IField targetField = getFieldFromCID(target);
+ sourceField.setValues();
+ if(action.equals("hide")){
+ if(sourceField.validateDisplay(value,condition)){
+ targetField.hideField();
+ }else {
+ targetField.showField();
+ }
+ }else if(action.equals("show")){
+ if(sourceField.validateDisplay(value,condition)){
+ targetField.showField();
+ }else{
+ targetField.hideField();
+ }
+ }
+ }
+
+ private IField getFieldFromCID(String source) {
+ IField returnField=null;
+ for (ArrayList fieldList: FormBuilder.fields.values()) {
+ for(IField field:fieldList){
+ if (field.getCIDValue().equals(source)) {
+ returnField=field;
+ break;
+ }
+ }
+ }
+ return returnField;
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/DateTimePicker.java b/formbuilder-android/src/com/vertis/formbuilder/DateTimePicker.java
new file mode 100644
index 0000000..4b01e6a
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/DateTimePicker.java
@@ -0,0 +1,194 @@
+package com.vertis.formbuilder;
+
+import java.lang.reflect.Field;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.DatePicker;
+import android.widget.DatePicker.OnDateChangedListener;
+import android.widget.LinearLayout;
+import android.widget.NumberPicker;
+import android.widget.RelativeLayout;
+import android.widget.TimePicker;
+import android.widget.TimePicker.OnTimeChangedListener;
+import android.widget.ViewSwitcher;
+
+@SuppressLint("InflateParams")
+public class DateTimePicker extends RelativeLayout implements
+View.OnClickListener, OnDateChangedListener, OnTimeChangedListener{
+
+ private static int TIME_PICKER_STEPS = 1;
+ private DatePicker datePicker;
+ private TimePicker timePicker;
+ private ViewSwitcher viewSwitcher;
+ private Calendar calendar;
+ private LinearLayout datePickerControl;
+ private LinearLayout timePickerControl;
+ private LinearLayout buttonsLinearLayout;
+
+ public DateTimePicker(Context context) {
+ this(context, null);
+ }
+
+ public DateTimePicker(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public DateTimePicker(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ LayoutInflater inflater = (LayoutInflater) context
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ inflater.inflate(R.layout.datetimepicker, this, true);
+ calendar = Calendar.getInstance();
+ getIds(inflater);
+ setEvents();
+ }
+
+ @SuppressLint("InflateParams")
+ private void getIds(LayoutInflater inflater) {
+ datePickerControl = (LinearLayout) inflater.inflate(
+ R.layout.datepicker, null);
+ timePickerControl = (LinearLayout) inflater.inflate(
+ R.layout.time_picker, null);
+ viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
+ datePicker = (DatePicker) datePickerControl
+ .findViewById(R.id.DatePicker);
+ buttonsLinearLayout = (LinearLayout) findViewById(R.id.buttonlayout);
+ }
+
+ private void setEvents() {
+ timePicker = (TimePicker) timePickerControl
+ .findViewById(R.id.TimePicker);
+ datePicker.init(calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH), this);
+ timePicker.setOnTimeChangedListener(this);
+ getTimeField();
+ findViewById(R.id.settime).setOnClickListener(this);
+ findViewById(R.id.setdate).setOnClickListener(this);
+ }
+
+ private void getTimeField() {
+ try {
+ Class> classForid = Class.forName("com.android.internal.R$id");
+ Field field = classForid.getField("minute");
+ NumberPicker mMinuteSpinner = (NumberPicker) timePicker
+ .findViewById(field.getInt(null));
+ mMinuteSpinner.setMinValue(0);
+ mMinuteSpinner.setMaxValue((60 / TIME_PICKER_STEPS) - 1);
+ List displayedValues = new ArrayList();
+ for (int i = 0; i < 60; i += TIME_PICKER_STEPS) {
+ displayedValues.add(String.format("%02d", i));
+ }
+ mMinuteSpinner.setDisplayedValues(displayedValues
+ .toArray(new String[0]));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ if(v.getId() == R.id.setdate) {
+ v.setEnabled(false);
+ findViewById(R.id.settime).setEnabled(true);
+ viewSwitcher.showPrevious();
+ }else if(v.getId() == R.id.settime) {
+ // :
+ v.setEnabled(false);
+ findViewById(R.id.setdate).setEnabled(true);
+ viewSwitcher.showNext();
+ }
+ }
+
+ @Override
+ public void onDateChanged(DatePicker view, int year, int monthOfYear,
+ int dayOfMonth) {
+ calendar.set(year, monthOfYear, dayOfMonth,
+ calendar.get(Calendar.HOUR_OF_DAY),
+ calendar.get(Calendar.MINUTE));
+ }
+
+ @Override
+ public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
+ calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH), hourOfDay, minute*TIME_PICKER_STEPS);
+ }
+
+ public int get(final int field) {
+ return calendar.get(field);
+ }
+
+ public void setMaxDate(long maxDate) {
+ datePicker.setMaxDate(maxDate);
+ }
+
+ public void reset() {
+ final Calendar c = Calendar.getInstance();
+ updateDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH),
+ c.get(Calendar.DAY_OF_MONTH));
+ updateTime(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
+ }
+
+ public long getDateTimeMillis() {
+ return calendar.getTimeInMillis();
+ }
+
+ public void setIs24HourView(boolean is24HourView) {
+ timePicker.setIs24HourView(is24HourView);
+ }
+
+ public boolean is24HourView() {
+ return timePicker.is24HourView();
+ }
+
+ public void updateDate(int year, int monthOfYear, int dayOfMonth) {
+ datePicker.updateDate(year, monthOfYear, dayOfMonth);
+ }
+
+ public void updateTime(int currentHour, int currentMinute) {
+ timePicker.setCurrentHour(currentHour);
+ timePicker.setCurrentMinute(((int)currentMinute/TIME_PICKER_STEPS));
+ }
+
+ public void setButtonsVisibility(int visibility) {
+ buttonsLinearLayout.setVisibility(visibility);
+ }
+
+ @SuppressLint("SimpleDateFormat")
+ public String returnDateTime(String format) {
+ return new SimpleDateFormat(format).format(calendar.getTime());
+ }
+
+ public void controlShow(String type) {
+ if (type.equals("birth_date")|| type.equals("date")) {
+ viewSwitcher.removeAllViews();
+ viewSwitcher.addView(datePickerControl, 0);
+ setButtonsVisibility(GONE);
+ } else if (type.equals("time")) {
+ viewSwitcher.removeAllViews();
+ viewSwitcher.addView(timePickerControl, 0);
+ setButtonsVisibility(GONE);
+ } else if (type.equals("endDateTimeDifference")
+ || type.equals("startDateTimeDifference")
+ || type.equals("date_time")) {
+ viewSwitcher.removeAllViews();
+ viewSwitcher.addView(datePickerControl, 0);
+ viewSwitcher.addView(timePickerControl, 1);
+ setButtonsVisibility(VISIBLE);
+ }
+ }
+
+ public static void setSteps(int steps){
+ TIME_PICKER_STEPS = steps;
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/DisplayDateTime.java b/formbuilder-android/src/com/vertis/formbuilder/DisplayDateTime.java
new file mode 100644
index 0000000..7745358
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/DisplayDateTime.java
@@ -0,0 +1,308 @@
+package com.vertis.formbuilder;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.res.Resources.NotFoundException;
+import android.graphics.Typeface;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnFocusChangeListener;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.Listeners.TextChangeListener;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+@SuppressLint("SimpleDateFormat")
+public class DisplayDateTime implements IField {
+
+ //Views
+ private FieldConfig config;
+ LinearLayout llDisplayDateTime;
+ TextView showTextDateTime;
+ TextView tvDateTime;
+ Boolean isDialogOpen=false;
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String datetime="";
+ String maxtime="";
+ @Expose
+ String dateTimeToRetainValue="";
+ private Activity context;
+ private Typeface font;
+
+ public DisplayDateTime(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ @Override
+ public void createForm(Activity context) {
+ this.context = context;
+ font = new FormBuilderUtil().getFontFromRes(context);
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ llDisplayDateTime=(LinearLayout) inflater.inflate(R.layout.display_date_time, null);
+ showTextDateTime = (TextView) llDisplayDateTime.findViewById(R.id.showTextDateTime);
+ tvDateTime=(TextView) llDisplayDateTime.findViewById(R.id.tvErrorMessage);
+ datetime = config.getField_options().getExistingFieldValue();
+ tvDateTime.setTextColor(R.color.TextViewNormal);
+ showTextDateTime.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) 12.5);
+ tvDateTime.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
+ tvDateTime.setTypeface(font);
+ showTextDateTime.setTypeface(font);
+ showTextDateTime.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(isDialogOpen==false) {
+ showTextDateTime.setFocusableInTouchMode(true);
+ showTextDateTime.setFocusable(true);
+ showTextDateTime.requestFocus();
+ if(config.getField_type().equals("birth_date")){
+ maxtime = new SimpleDateFormat(config.getField_options().getDate_format()).format(Calendar.getInstance().getTime());
+ }else {
+ maxtime = config.getField_options().getMaxDate();
+ }
+ openDialog(config.getField_options().getSteps(),
+ config.getField_options().getDate_format(),
+ config.getField_type(),
+ maxtime,
+ datetime);
+ isDialogOpen=true;
+ }
+ }
+ });
+
+ showTextDateTime.addTextChangedListener(new TextChangeListener(config));
+ defineViewSettings(context);
+ setViewValues();
+ mapView();
+ setValues();
+ noErrorMessage();
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid()+"_1", llDisplayDateTime);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", showTextDateTime);
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(tvDateTime==null)return;
+ tvDateTime.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvDateTime.setTextColor(R.color.TextViewNormal);
+ }
+
+ private void setViewValues() {
+ tvDateTime.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ showTextDateTime.setText(dateTimeToRetainValue);
+ tvDateTime.setTextColor(-1);
+ }
+
+ private void defineViewSettings(Activity context) {
+ showTextDateTime.setOnFocusChangeListener( new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if(hasFocus)
+ noErrorMessage();
+ else
+ setValues();
+ }
+ });
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llDisplayDateTime;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ if(config.getRequired() && showTextDateTime.getText().toString().equals("")){
+ valid=false;
+ errorMessage(" Required");
+ }else{
+ valid=true;
+ }
+ return valid;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(String message) {
+ if(tvDateTime==null)return;
+ tvDateTime.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvDateTime.setText(tvDateTime.getText() + message);
+ tvDateTime.setTextColor(R.color.ErrorMessage);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(llDisplayDateTime!=null){
+ datetime=showTextDateTime.getText().toString();
+ dateTimeToRetainValue=showTextDateTime.getText().toString();
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ llDisplayDateTime=null;
+ showTextDateTime=null;
+ tvDateTime=null;
+ }
+
+ private void openDialog(int steps, final String date_format, final String field_type, final String maxDate, final String existingFieldValue) {
+ try {
+ DateTimePicker.setSteps(steps);
+ final Dialog mDateTimeDialog = new Dialog(context);
+ mDateTimeDialog.setCancelable(false);
+ final RelativeLayout mDateTimeDialogView = (RelativeLayout) context
+ .getLayoutInflater().inflate(R.layout.date_time_dialog, null);
+ final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
+ .findViewById(R.id.DateTimePicker);
+ mDateTimeDialogView.findViewById(R.id.SetDateTime).setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mDateTimePicker.clearFocus();
+ String returnDateTime = mDateTimePicker.returnDateTime(date_format);
+ mDateTimeDialog.dismiss();
+ isDialogOpen=false;
+ displayDateTime(returnDateTime);
+ }
+
+ private void displayDateTime(String returnDateTime) {
+ showTextDateTime.setText(returnDateTime);
+ datetime = returnDateTime;
+ }
+ });
+
+ mDateTimeDialogView.findViewById(R.id.CancelDialog).setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mDateTimeDialog.cancel();
+ isDialogOpen=false;
+ }
+ });
+ mDateTimeDialogView.findViewById(R.id.setcurrentDate)
+ .setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mDateTimePicker.reset();
+ }
+ });
+ mDateTimePicker.setIs24HourView(false);
+ if (!field_type.equals("datetime") && !field_type.equals("startDateTimeDifference") && !field_type.equals("endDateTimeDifference")) {
+ mDateTimePicker.setButtonsVisibility(View.GONE);
+ }
+ if (!maxDate.equals("")) {
+ mDateTimeDialogView.findViewById(R.id.setcurrentDate).setVisibility(View.GONE);
+ mDateTimePicker.setMaxDate(getDate(maxDate));
+ }
+
+ Calendar calendar = getExistingFieldValueCalender(existingFieldValue, date_format);
+ mDateTimePicker.updateDate(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH));
+ mDateTimePicker.updateTime(calendar.get(Calendar.HOUR_OF_DAY),calendar.get(Calendar.MINUTE));
+ mDateTimePicker.controlShow(field_type);
+ mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ mDateTimeDialog.setContentView(mDateTimeDialogView);
+ mDateTimeDialog.show();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @SuppressLint("SimpleDateFormat")
+ private long getDate(String string) throws ParseException {
+ final SimpleDateFormat sdf = new SimpleDateFormat(config.getField_options().getDate_format()); //$NON-NLS-1$
+ sdf.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
+ Date d = sdf.parse(string);
+ return d.getTime();
+ }
+
+ private Calendar getExistingFieldValueCalender(String existingTime,
+ String dateFormat) throws ParseException {
+ Calendar calendar = Calendar.getInstance();
+ if (!existingTime.equals("")) {
+ calendar.setTime(getExistingDate(existingTime, dateFormat));
+ }
+ return calendar;
+ }
+
+ private Date getExistingDate(String existingTime, String dateFormat) throws ParseException {
+ return new SimpleDateFormat(dateFormat).parse(existingTime);
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llDisplayDateTime!=null){
+ llDisplayDateTime.setVisibility(View.GONE);
+ llDisplayDateTime.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llDisplayDateTime!=null){
+ llDisplayDateTime.setVisibility(View.VISIBLE);
+ llDisplayDateTime.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(datetime.equals(value) || datetime.equals("")){
+ return true;
+ }
+ } else if(condition.equals("is greater than")){
+ if(Integer.parseInt(datetime)>Integer.parseInt(value) || datetime.equals("")){
+ return true;
+ }
+ } else if(condition.equals("is less than")){
+ if(Integer.parseInt(datetime) adapter = getAdapter(context);
+ sDropdown.setAdapter(adapter);
+ }
+
+ private ArrayAdapter getAdapter(Activity context) {
+ return new CountriesArrayAdapter(context, getContentList(context));
+ }
+
+ private ArrayList getContentList(Activity context) {
+ int i=0;
+ ArrayList contents=new ArrayList();
+ ArrayList new_contents=new ArrayList();
+ for (int j = 0; j < this.config.getField_options().getOptions().size(); j++) {
+ new_contents.add(this.config.getField_options().getOptions().get(j).getLabel());
+ }
+ for (String string : new_contents) {
+ contents.add(new SelectElement(i, string, string));
+ }
+ return contents;
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llDropdown;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid=false;
+ if(config.getRequired()&&drop.equals("")) {
+ valid=false;
+ errorMessage(" Pick one!");
+ } else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
+ }
+
+ private void errorMessage(String message) {
+ if(tvDropdown==null)return;
+ tvDropdown.setText((this.config.getRequired()?"*":""));
+ tvDropdown.setText(tvDropdown.getText() + message);
+ tvDropdown.setTextColor(-65536);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(llDropdown!=null){
+ ddPosition=sDropdown.getSelectedItemPosition();
+ drop=sDropdown.getSelectedItem().toString();
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ llDropdown=null;
+ tvDropdown=null;
+ sDropdown=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llDropdown!=null){
+ llDropdown.setVisibility(View.GONE);
+ llDropdown.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llDropdown!=null){
+ llDropdown.setVisibility(View.VISIBLE);
+ llDropdown.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(drop.toLowerCase().equals(value.toLowerCase()) || drop.equals("")){
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(llDropdown!=null) {
+ return !llDropdown.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Email.java b/formbuilder-android/src/com/vertis/formbuilder/Email.java
new file mode 100644
index 0000000..68a9ffb
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Email.java
@@ -0,0 +1,187 @@
+package com.vertis.formbuilder;
+
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.vertis.formbuilder.Listeners.TextChangeListener;
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnFocusChangeListener;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+public class Email implements IField{
+
+ private FieldConfig config;
+ private static final String EMAIL_PATTERN = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$";
+ //Views
+ LinearLayout em;
+ TextView emailTextBox;
+ EditText emailEditBox;
+ ArrayList Conditions;
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String emailid="";
+ private Typeface font;
+
+ public Email(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ @Override
+ public void createForm(Activity context) {
+ font = new FormBuilderUtil().getFontFromRes(context);
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ em=(LinearLayout) inflater.inflate(R.layout.email,null);
+ emailTextBox = (TextView) em.findViewById(R.id.textViewEmail);
+ emailEditBox = (EditText) em.findViewById(R.id.editTextEmail);
+ emailEditBox.setTypeface(font);
+ emailTextBox.setTypeface(font);
+ emailEditBox.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float) 12.5);
+ emailTextBox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
+ emailTextBox.setTextColor(R.color.TextViewNormal);
+
+ emailEditBox.addTextChangedListener(new TextChangeListener(config));
+
+ defineViewSettings(context);
+ setViewValues();
+ mapView();
+ setValues();
+ noErrorMessage();
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(emailTextBox==null)return;
+ emailTextBox.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ emailTextBox.setTextColor(R.color.TextViewNormal);
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid()+"_1", em);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", emailEditBox);
+ }
+
+ private void setViewValues() {
+ emailTextBox.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ emailEditBox.setText(emailid);
+ emailTextBox.setTextColor(-1);
+ }
+
+ private void defineViewSettings(Activity context) {
+ emailEditBox.setOnFocusChangeListener( new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if(hasFocus)
+ noErrorMessage();
+ else
+ setValues();
+ }
+ });
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return em;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ String emailString = emailid;
+ if(config.getRequired() && emailString.equals("")){
+ valid=false;
+ errorMessage(" Required");
+ } else if(emailValidation(emailString)){
+ valid=false;
+ errorMessage(" Invalid entry");
+ } else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
+ }
+
+ private boolean emailValidation(String emailCheck) {
+ Pattern pattern = Pattern.compile(EMAIL_PATTERN);
+ Matcher matcher = pattern.matcher(emailCheck);
+ return !matcher.matches();
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(String message) {
+ if(emailTextBox==null)return;
+ emailTextBox.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ emailTextBox.setText(emailTextBox.getText() + message);
+ emailTextBox.setTextColor(R.color.ErrorMessage);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(em!=null){
+ emailid=emailEditBox.getText().toString();
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ em=null;
+ emailTextBox=null;
+ emailEditBox=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(em!=null){
+ em.setVisibility(View.GONE);
+ em.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(em!=null){
+ em.setVisibility(View.VISIBLE);
+ em.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(emailid.equals(value) || emailid.equals("")){
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(em!=null) {
+ return !em.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/FieldRegistry.java b/formbuilder-android/src/com/vertis/formbuilder/FieldRegistry.java
index 8be4fe6..6ab9685 100644
--- a/formbuilder-android/src/com/vertis/formbuilder/FieldRegistry.java
+++ b/formbuilder-android/src/com/vertis/formbuilder/FieldRegistry.java
@@ -2,18 +2,35 @@
import java.util.HashMap;
+import android.util.Config;
+
public class FieldRegistry {
@SuppressWarnings("rawtypes")
static HashMap fields=new HashMap();
static{
- fields.put("fullname", FullName.class);
fields.put("fullnamexml", FullNameXml.class);
fields.put("radio", Radio.class);
fields.put("section_break", Section.class);
+ fields.put("email",Email.class);
+ fields.put("address",Address.class);
+ fields.put("checkbox",Checkbox.class);
+ fields.put("dropdown", Dropdown.class);
+ fields.put("contact", Contact.class);
+ fields.put("text", SimpleEditText.class);
+ fields.put("mtext", MultiLineEditText.class);
+ fields.put("price",Price.class);
+ fields.put("date_time", DisplayDateTime.class);
+ fields.put("birth_date", DisplayDateTime.class);
+ fields.put("date", DisplayDateTime.class);
+ fields.put("time", DisplayDateTime.class);
+ fields.put("endDateTimeDifference", DisplayDateTime.class);
+ fields.put("startDateTimeDifference", DisplayDateTime.class);
+ fields.put("take_pic_video_audio", Capture.class);
+ fields.put("number", NumberField.class);
}
-
+
@SuppressWarnings("rawtypes")
public static Class getField(String typeName){
return fields.get(typeName);
diff --git a/formbuilder-android/src/com/vertis/formbuilder/FormBuilder.java b/formbuilder-android/src/com/vertis/formbuilder/FormBuilder.java
index f513513..c7632dc 100644
--- a/formbuilder-android/src/com/vertis/formbuilder/FormBuilder.java
+++ b/formbuilder-android/src/com/vertis/formbuilder/FormBuilder.java
@@ -8,195 +8,241 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.parser.FieldOptions;
import com.vertis.formbuilder.parser.FormJson;
+import com.vertis.formbuilder.Listeners.CheckConditions;
+
import android.app.Activity;
+import android.view.Gravity;
import android.view.View;
+import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
public class FormBuilder {
- TreeMap> fields = new TreeMap>();
- int currentSection;
- /**
- * Private Variables:
- * Tree map containing all the views
- * (section id mapped to all views in that section )
- * currentSection stores section id of the section currently displayed
- */
-
- LinearLayout form;
- Activity context;
- /**
- * Form is the linearLayout containing the fields(we will get it from the constructor)
- * context will be taken from the constructor
- */
-
- LinearLayout previousNextContainer;
- Button previousButton;
- Button nextButton;
- /**
- *
- * previous and next button will be used if there are section breaks
- */
-
-
- //render generates the required views(from json) and adds the required views to linearlayout passed to the functions
- public void setup(String json , LinearLayout form,Activity context) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
-
- Gson gson=new Gson();
- //fj contains all the field models
- FormJson fj = gson.fromJson(json, FormJson.class);
-
- //iterate through FieldConfigs and generate instances of IFields to populate fields array
- ArrayListfieldConfigs = fj.getFields();
- for(FieldConfig fcg : fieldConfigs){
- Class> ViewImpl = FieldRegistry.getField(fcg.getField_type());
- Constructor> ctor =ViewImpl.getConstructor(FieldConfig.class);
- IField ifield = (IField) ctor.newInstance(fcg);
-
- //putting each field in appropriate ArrayList(mapped to section id)
- if(fields.get(fcg.getSection_id()) == null ){
- fields.put(fcg.getSection_id(), new ArrayList());
- }
- fields.get(fcg.getSection_id()).add(ifield);
- }
- this.context=context;
- if(fields.size()!=1){
- /**
- * Section break exists:
- * Split main linear layout(form) in two parts:
- * 1) contains linear layout which hosts the fields(this.form)
- * 2) initialize previous and next buttons and put them in a container
- */
- this.form=new LinearLayout(context);
- this.form.setOrientation(LinearLayout.VERTICAL);
- this.previousNextContainer= new LinearLayout(context);
- this.previousNextContainer.setOrientation(LinearLayout.HORIZONTAL);
- nextButton=new Button(context);
- nextButton.setText("Next");
- nextButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- next();
- }
- });
- previousButton=new Button(context);
- previousButton.setText("Previous");
- previousButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- previous();
- }
- });
- previousNextContainer.addView(previousButton);
- previousNextContainer.addView(nextButton);
- previousButton.setEnabled(false);
-
- form.addView(this.form);
- form.addView(this.previousNextContainer);
- }
- else{
- //No section break=>no previous/next buttons
- this.form=form;
- }
-
- //render the first section
- this.render(fields.firstKey());
- }
-
- /**
- * createForm initializes the Views
- * getView returns the view to be displayed
- * form is the linearLayout which hosts the field
- */
- public void render(int sectionId){
-
- currentSection = sectionId;
-
- for(IField field : fields.get(sectionId))
- {
- field.createForm(context);
- if(field.getView()!=null)
- form.addView(field.getView());
- }
- }
-
- //delete all views currently displayed after saving their data( done by clearViews)
- public void clear(int sectionId){
- for(IField field : fields.get(sectionId))
- {
- field.clearViews();
- }
- form.removeAllViews();
- }
-
- //Submit works only if you are in the last section and all fields are valid
- //returns output json which is {values:[array of json objects from field.toJson ]}
- public String submit(){
-
- if(fields.higherEntry(currentSection)!=null)
- return "Not ready to submit!!!";
-
- for(IField field: fields.get(currentSection)){
- field.setValues();
- if(!field.validate())
- return "Not ready to submit!!!";
- }
-
- ResultJson rj = new ResultJson();
-
- for (ArrayList fieldList: this.fields.values()) {
- for(IField field:fieldList){
- field.setValues();
- rj.addValue(field);
- }
- }
- Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
- return gson.toJson(rj);
- }
-
- /**
- * called when next is pressed
- * activates previous button
- * deactivates next if this is the last section
- * goes to next page only if all fields are valid (after setting values)
- * calls clear on current sectionId
- * calls render on next sectionId
- */
- public void next(){
- for(IField field : fields.get(currentSection)){
- field.setValues();
- if(!field.validate())
- return;
- }
- previousButton.setEnabled(true);
- clear(currentSection);
- currentSection=fields.higherKey(currentSection);
- render(currentSection);
-
- if(fields.higherKey(currentSection)==null){
- nextButton.setEnabled(false);
- }
- }
-
- /**
- * called when previous is pressed
- * activates next button
- * deactivates previous if this is the first section
- * calls clear on current sectionId
- * calls render on previous sectionId
- */
- public void previous(){
- nextButton.setEnabled(true);
- clear(currentSection);
- currentSection=fields.lowerKey(currentSection);
- render(currentSection);
-
- if(fields.lowerKey(currentSection)==null){
- previousButton.setEnabled(false);
- }
- }
+ Activity context;
+ public static int currentSection;
+ /**
+ * Private Variables:
+ * Tree map containing all the views
+ * (section id mapped to all views in that section )
+ * currentSection stores section id of the section currently displayed
+ */
+ public static TreeMap> fields = new TreeMap>();
+ /**
+ * Form is the linearLayout containing various section breaks.
+ * These section breaks will contain various fields.
+ * the fields context will be taken from the constructor
+ */
+ public static TreeMap sectionsTreeMap= new TreeMap();
+ LinearLayout previousNextContainer;
+ Button previousButton;
+ Button nextButton;
+ public FormBuilder() {
+ fields = new TreeMap>();
+ }
+
+ public void setup(String json , LinearLayout form, Activity context) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
+ this.context=context;
+ Gson gson = new Gson();
+ //fj contains all the field models
+ FormJson fj = gson.fromJson(json, FormJson.class);
+ //iterate through FieldConfigs and generate instances of IFields to populate fields array
+ ArrayListfieldConfigs = fj.getFields();
+ addSection();
+ loopOverFieldConfig(fieldConfigs);
+ checkMoreThanOneSections(form);
+ //render the first section
+ currentSection = 0;
+ sectionsTreeMap.get(currentSection).getView().setVisibility(View.VISIBLE);
+ loopOverFieldConfigToCheckConditions(fieldConfigs);
+ }
+
+ private void addSection() {
+ Section section = new Section(new FieldConfig("c00", 0, "section_break",new FieldOptions()));
+ section.createForm(context);
+ sectionsTreeMap.put(0,section);
+ }
+
+ private void loopOverFieldConfigToCheckConditions(ArrayList fieldConfigs) {
+ for(FieldConfig fcg : fieldConfigs){
+ CheckConditions checkConditionsObject=new CheckConditions(fcg);
+ checkConditionsObject.loopOverCheckCondition();
+ }
+ }
+
+ private void checkMoreThanOneSections(LinearLayout form) {
+ if(fields.size()!=1){
+ /**
+ * Section break exists:
+ * Split main linear layout(form) in two parts:
+ * 1) contains linear layout which hosts the fields(this.form)
+ * 2) initialize previous and next buttons and put them in a container
+ */
+ buttonSpecifications();
+ loopOverSectionTreeMap(form);
+ form.addView(this.previousNextContainer);
+ } else{
+ //No section break=>no previous/next buttons
+ View v = this.sectionsTreeMap.get(0).getView();
+ //render generates the required views(from json) and adds the required views to linearlayout passed to the functions
+ this.render(0);
+ form.addView(v);
+ }
+ }
+
+ private void loopOverSectionTreeMap(LinearLayout form) {
+ for (int i = 0; i < sectionsTreeMap.size() ; i++) {
+ View v = this.sectionsTreeMap.get(i).getView();
+ v.setVisibility(View.GONE);
+ this.render(i);
+ form.addView(v);
+ }
+ }
+
+ private void loopOverFieldConfig(ArrayList fieldConfigs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
+ int j=1;
+ for(FieldConfig fcg : fieldConfigs){
+ Class> ViewImpl = FieldRegistry.getField(fcg.getField_type());
+ Constructor> ctor =ViewImpl.getConstructor(FieldConfig.class);
+ IField ifield = (IField) ctor.newInstance(fcg);
+ //putting each field in appropriate ArrayList(mapped to section id)
+ if(fields.get(fcg.getSection_id()) == null ){
+ fields.put(fcg.getSection_id(), new ArrayList());
+ }
+ if (fcg.getField_type().equals("section_break")){
+ ifield.createForm(context);
+ sectionsTreeMap.put(j,(Section)ifield);
+ j++;
+ }else {
+ fields.get(fcg.getSection_id()).add(ifield);
+ }
+ }
+ }
+
+ private void buttonSpecifications() {
+ // previous and next button will be used if there are section breaks
+ this.previousNextContainer= new LinearLayout(context);
+ this.previousNextContainer.setOrientation(LinearLayout.HORIZONTAL);
+ LinearLayout.LayoutParams abc = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+ abc.setMargins(0, 10, 0, 10);
+ this.previousNextContainer.setGravity(Gravity.RIGHT);
+ this.previousNextContainer.setLayoutParams(abc);
+ this.nextButton=new Button(context);
+ this.nextButton.setText("Next");
+ this.nextButton.setBackgroundResource(R.drawable.prev_next_buttons);
+ nextButton.setOnClickListener(new View.OnClickListener(){
+ @Override
+ public void onClick(View v) {
+ next();
+ }
+ });
+ this.previousButton=new Button(context);
+ this.previousButton.setText("Previous");
+ this.previousButton.setBackgroundResource(R.drawable.prev_next_buttons);
+ this.previousButton.setOnClickListener(new View.OnClickListener(){
+ @Override
+ public void onClick(View v) {
+ previous();
+ }
+ });
+ this.previousNextContainer.addView(previousButton);
+ this.previousNextContainer.addView(nextButton);
+ this.previousButton.setEnabled(false);
+ }
+
+ /**
+ * createForm initializes the Views
+ * getView returns the view to be displayed
+ * form is the linearLayout which hosts the field
+ */
+ public void render(int sectionId){
+ for(IField field : fields.get(sectionId)){
+ field.createForm(context);
+ if(field.getView()!=null)
+ sectionsTreeMap.get(sectionId).getView().addView(field.getView());
+ }
+ }
+
+ //delete all views currently displayed after saving their data(done by clearViews)
+ public void clear(int sectionId){
+ for(IField field : fields.get(sectionId)){
+ field.clearViews();
+ }
+ //form_section.removeAllViews();
+ }
+
+ //Submit works only if you are in the last section and all fields are valid
+ //returns output json which is {values:[array of json objects from field.toJson ]}
+ public String submit(){
+ if(fields.higherEntry(currentSection)!=null)
+ return "Not ready to submit!!!";
+
+ for(IField field: fields.get(currentSection)){
+ field.setValues();
+ if(!field.validate())
+ return "Not ready to submit!!!";
+ }
+ ResultJson rj = new ResultJson();
+ for (ArrayList fieldList: this.fields.values()) {
+ for(IField field:fieldList){
+ field.setValues();
+ rj.addValue(field);
+ }
+ }
+ Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
+ return gson.toJson(rj);
+ }
+
+ /**
+ * called when next is pressed
+ * activates previous button
+ * deactivates next if this is the last section
+ * goes to next page only if all fields are valid (after setting values)
+ * calls clear on current sectionId
+ * calls render on next sectionId
+ */
+ public void next(){
+ for(IField field : fields.get(currentSection)){
+ field.setValues();
+ if(!field.validate())
+ return;
+ }
+ previousButton.setEnabled(true);
+ sectionsTreeMap.get(currentSection).getView().setVisibility(View.GONE);
+ currentSection=fields.higherKey(currentSection);
+ if(sectionsTreeMap.get(currentSection).isHidden()){
+ sectionsTreeMap.get(currentSection).getView().setVisibility(View.GONE);
+ if(fields.higherKey(currentSection)!= null) {
+ next();
+ }
+ }else{
+ sectionsTreeMap.get(currentSection).getView().setVisibility(View.VISIBLE);
+ }
+ if(fields.higherKey(currentSection)==null){
+ nextButton.setEnabled(false);
+ }
+ }
+
+ /**
+ * called when previous is pressed
+ * activates next button
+ * deactivates previous if this is the first section
+ * calls clear on current sectionId
+ * calls render on previous sectionId
+ */
+ public void previous(){
+ nextButton.setEnabled(true);
+ sectionsTreeMap.get(currentSection).getView().setVisibility(View.GONE);
+ currentSection=fields.lowerKey(currentSection);
+ if(sectionsTreeMap.get(currentSection).isHidden()){
+ sectionsTreeMap.get(currentSection).getView().setVisibility(View.GONE);
+ }else{
+ sectionsTreeMap.get(currentSection).getView().setVisibility(View.VISIBLE);
+ }
+ if(fields.lowerKey(currentSection)==null){
+ previousButton.setEnabled(false);
+ }
+ }
}
diff --git a/formbuilder-android/src/com/vertis/formbuilder/FullName.java b/formbuilder-android/src/com/vertis/formbuilder/FullName.java
deleted file mode 100644
index df3eabd..0000000
--- a/formbuilder-android/src/com/vertis/formbuilder/FullName.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package com.vertis.formbuilder;
-
-import com.google.gson.annotations.Expose;
-import com.vertis.formbuilder.parser.FieldConfig;
-
-import android.app.Activity;
-import android.view.View;
-import android.view.View.OnFocusChangeListener;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.Spinner;
-import android.widget.TextView;
-
-public class FullName implements IField {
-
- //config contains all data from json ie id,sid,label,field_options
- private FieldConfig config;
-
- // Default Values
- String firstNameHint = "first name";
- String lastNameHint = "last name";
- @SuppressWarnings("unused")
- private boolean includeOtherOption;
-
-
- // Views
- LinearLayout subForm;
- TextView headingText;
- LinearLayout nameField;
- Spinner prefixBox;
- EditText firstNameTextBox;
- EditText lastNameTextBox;
-
- //Values
- @Expose
- String cid;
- @Expose
- String prefix="";
- int prefixPosition=0;
- @Expose
- String firstName="";
- @Expose
- String lastName="";
-
- //constructor to populate config
- public FullName(FieldConfig fcg){
- this.config=fcg;
- }
-
- //generates the views using context and assigns ids using viewLookup
- //Also calls setValues to initialize values(and calls noErrorMessage)
- //for EditText:
- //if focus lost, setValues is called
- //if focus gained, noErrorMessage is called
- public void createForm(Activity context) {
- subForm = new LinearLayout(context);
- subForm.setOrientation(LinearLayout.VERTICAL);
- headingText = new TextView(context);
- subForm.addView(headingText);
- nameField = new LinearLayout(context);
- prefixBox = new Spinner(context);
- nameField.addView(prefixBox);
- firstNameTextBox = new EditText(context);
- nameField.addView(firstNameTextBox);
- lastNameTextBox = new EditText(context);
- nameField.addView(lastNameTextBox);
- subForm.addView(nameField);
-
- defineViewSettings(context);
- setViewValues();
- mapView();
-
- setValues();
- noErrorMessage();
- }
-
- void defineViewSettings(Activity context){
- ArrayAdapter adapter = ArrayAdapter.createFromResource(context, R.array.prefixArray, android.R.layout.simple_spinner_item);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- prefixBox.setAdapter(adapter);
- firstNameTextBox.setHint(firstNameHint);
- firstNameTextBox.setOnFocusChangeListener( new OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if(hasFocus)
- noErrorMessage();
- else
- setValues();
- }
- });
- lastNameTextBox.setOnFocusChangeListener( new OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if(hasFocus)
- noErrorMessage();
- else
- setValues();
- }
- });
- lastNameTextBox.setHint(lastNameHint);
- }
-
- void setViewValues(){
- headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
- prefixBox.setSelection(prefixPosition);
- firstNameTextBox.setText(firstName);
- lastNameTextBox.setText(lastName);
-
- }
-
- void mapView(){
- ViewLookup.mapField(this.config.getCid()+"_1", subForm);
- ViewLookup.mapField(this.config.getCid()+"_1_1",prefixBox);
- ViewLookup.mapField(this.config.getCid()+"_1_2", firstNameTextBox);
- ViewLookup.mapField(this.config.getCid()+"_1_3", lastNameTextBox);
-
- }
-
- //return views
- public ViewGroup getView() {
- return subForm;
- }
-
- @Override
- public void clearViews() {
- setValues();
-
- subForm=null;
- headingText=null;
- nameField=null;
- prefixBox=null;
- firstNameTextBox=null;
- lastNameTextBox=null;
-
- }
-
- public void setValues() {
- this.cid=config.getCid();
-
- if(subForm!=null){
- firstName=firstNameTextBox.getText().toString();
- lastName=lastNameTextBox.getText().toString();
- prefixPosition=prefixBox.getSelectedItemPosition();
- prefix=prefixBox.getSelectedItem().toString();
- }
- validate();
- }
-
- public boolean validate() {
- boolean valid;
-
- if(config.getRequired()&&firstName.equals("")){
- valid=false;
- errorMessage("Required");
- }
- else{
- valid=true;
- noErrorMessage();
- }
- return valid;
- }
-
- public void errorMessage(String message){
- if(headingText==null)return;
-
- headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
- headingText.setText(headingText.getText() + " " + message);
- headingText.setTextColor(-65536);
- }
-
- public void noErrorMessage(){
- if(headingText==null)return;
-
- headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
- headingText.setTextColor(-1);
- }
-};
diff --git a/formbuilder-android/src/com/vertis/formbuilder/FullNameXml.java b/formbuilder-android/src/com/vertis/formbuilder/FullNameXml.java
index 15b5796..50bd579 100644
--- a/formbuilder-android/src/com/vertis/formbuilder/FullNameXml.java
+++ b/formbuilder-android/src/com/vertis/formbuilder/FullNameXml.java
@@ -1,10 +1,16 @@
package com.vertis.formbuilder;
+import java.util.ArrayList;
+
import com.google.gson.annotations.Expose;
import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
+import android.graphics.Typeface;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
@@ -23,9 +29,6 @@ public class FullNameXml implements IField {
// Default Values
String firstNameHint = "first name";
String lastNameHint = "last name";
- @SuppressWarnings("unused")
- private boolean includeOtherOption;
-
// Views
LinearLayout subForm;
@@ -45,6 +48,9 @@ public class FullNameXml implements IField {
String firstName="";
@Expose
String lastName="";
+ @Expose
+ String fullName="";
+ private Typeface font;
//constructor to populate config
public FullNameXml(FieldConfig fcg){
@@ -57,25 +63,45 @@ public FullNameXml(FieldConfig fcg){
//if focus lost, setValues is called
//if focus gained, noErrorMessage is called
public void createForm(Activity context) {
+ font = new FormBuilderUtil().getFontFromRes(context);
LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
subForm=(LinearLayout) inflater.inflate(R.layout.fullname,null);
headingText = (TextView) subForm.findViewById(R.id.textView1);
prefixBox = (Spinner) subForm.findViewById(R.id.spinner1);
firstNameTextBox = (EditText) subForm.findViewById(R.id.editText1);
lastNameTextBox = (EditText) subForm.findViewById(R.id.editText2);
-
+ headingText.setTypeface(font);
+ firstNameTextBox.setTypeface(font);
+ lastNameTextBox.setTypeface(font);
+ firstNameTextBox.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float) 14);
+ lastNameTextBox.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float) 14);
defineViewSettings(context);
setViewValues();
mapView();
-
setValues();
noErrorMessage();
}
+ private void addTextChangedListeners() {
+ firstNameTextBox.addTextChangedListener(new CustomTextChangeListener(config));
+ lastNameTextBox.addTextChangedListener(new CustomTextChangeListener(config));
+ }
+
+ private ArrayAdapter getAdapter(Context context) {
+ return new CountriesArrayAdapter(context, getPrefixList(context));
+ }
+
+ private ArrayList getPrefixList(Context context) {
+ int i=0;
+ String[] prefixes = context.getResources().getStringArray(R.array.prefixArray);
+ ArrayList prefixArr=new ArrayList();
+ for (String string : prefixes)
+ prefixArr.add(new SelectElement(i, string, string));
+ return prefixArr;
+ }
+
void defineViewSettings(Activity context){
- ArrayAdapter adapter = ArrayAdapter.createFromResource(context, R.array.prefixArray, android.R.layout.simple_spinner_item);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- prefixBox.setAdapter(adapter);
+ prefixBox.setAdapter(getAdapter(context));
firstNameTextBox.setHint(firstNameHint);
firstNameTextBox.setOnFocusChangeListener( new OnFocusChangeListener() {
@Override
@@ -103,7 +129,6 @@ void setViewValues(){
prefixBox.setSelection(prefixPosition);
firstNameTextBox.setText(firstName);
lastNameTextBox.setText(lastName);
-
}
void mapView(){
@@ -111,7 +136,6 @@ void mapView(){
ViewLookup.mapField(this.config.getCid()+"_1_1",prefixBox);
ViewLookup.mapField(this.config.getCid()+"_1_2", firstNameTextBox);
ViewLookup.mapField(this.config.getCid()+"_1_3", lastNameTextBox);
-
}
//return views
@@ -122,31 +146,28 @@ public ViewGroup getView() {
@Override
public void clearViews() {
setValues();
-
subForm=null;
headingText=null;
nameField=null;
prefixBox=null;
firstNameTextBox=null;
lastNameTextBox=null;
-
}
public void setValues() {
this.cid=config.getCid();
-
if(subForm!=null){
firstName=firstNameTextBox.getText().toString();
lastName=lastNameTextBox.getText().toString();
prefixPosition=prefixBox.getSelectedItemPosition();
prefix=prefixBox.getSelectedItem().toString();
+ fullName=firstName+" "+lastName;
}
validate();
}
public boolean validate() {
boolean valid;
-
if(config.getRequired()&&firstName.equals("")){
valid=false;
errorMessage("Required");
@@ -160,16 +181,52 @@ public boolean validate() {
public void errorMessage(String message){
if(headingText==null)return;
-
headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
headingText.setText(headingText.getText() + " " + message);
headingText.setTextColor(-65536);
}
+ @SuppressLint("ResourceAsColor")
public void noErrorMessage(){
if(headingText==null)return;
-
headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
- headingText.setTextColor(-1);
+ headingText.setTextColor(R.color.TextViewNormal);
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
}
-};
+
+ public void hideField() {
+ if(subForm!=null){
+ subForm.setVisibility(View.GONE);
+ subForm.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(subForm!=null){
+ subForm.setVisibility(View.VISIBLE);
+ subForm.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(fullName.toLowerCase().contains(value.toLowerCase()) || fullName.trim().equals("")){
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(subForm!=null) {
+ return !subForm.isShown();
+ } else {
+ return false;
+ }
+ }
+};
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/IField.java b/formbuilder-android/src/com/vertis/formbuilder/IField.java
index 8cd322b..80ea2f2 100644
--- a/formbuilder-android/src/com/vertis/formbuilder/IField.java
+++ b/formbuilder-android/src/com/vertis/formbuilder/IField.java
@@ -56,4 +56,14 @@ public interface IField {
public abstract void clearViews();
+ public abstract String getCIDValue();
+
+ public abstract void hideField();
+
+ public abstract void showField();
+
+ public abstract boolean validateDisplay(String value,String condition);
+
+ public boolean isHidden();
+
}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Listeners/CheckConditions.java b/formbuilder-android/src/com/vertis/formbuilder/Listeners/CheckConditions.java
new file mode 100644
index 0000000..c663d64
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Listeners/CheckConditions.java
@@ -0,0 +1,106 @@
+package com.vertis.formbuilder.Listeners;
+
+import java.util.ArrayList;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.vertis.formbuilder.FormBuilder;
+import com.vertis.formbuilder.IField;
+import com.vertis.formbuilder.parser.FieldConfig;
+
+public class CheckConditions {
+
+ private FieldConfig config;
+
+ public CheckConditions(FieldConfig config){
+ this.config = config;
+ }
+
+ public void loopOverCheckCondition(){
+ int size= config.getConditions().size();
+ for (int i = 0; i < size; i++) {
+ checkCondition(config.getConditions().get(i).getSource(),config.getConditions().get(i).getCondition(),config.getConditions().get(i).getValue(),
+ config.getConditions().get(i).getAction(),config.getConditions().get(i).getTarget(),config.getConditions().get(i).getIsSource());
+ }
+ }
+
+ public void checkCondition(String source, String condition, String value, String action, String target, Boolean isSource) {
+ String actualValue="";
+ IField sourceField = getFieldFromCID(source);
+ IField targetField = getFieldFromCID(target);
+
+ sourceField.setValues();
+ Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
+ actualValue = gson.toJson(sourceField);
+ switch(condition){
+ case "equals":
+ if(action.equals("hide")){
+ if(sourceField.validateDisplay(value,"equals")){
+ targetField.hideField();
+ }else{
+ targetField.showField();
+ }
+ }else if(action.equals("show")){
+ if(sourceField.validateDisplay(value,"equals")){
+ targetField.showField();
+ }else{
+ targetField.hideField();
+ }
+ }
+ break;
+
+ case "is greater than":
+ if(action.equals("hide")){
+ if(sourceField.validateDisplay(value,"moreThan")){
+ targetField.hideField();
+ }else{
+ targetField.showField();
+ }
+ }else if(action.equals("show")){
+ if(sourceField.validateDisplay(value,"moreThan")){
+ targetField.showField();
+ }else{
+ targetField.hideField();
+ }
+ }
+ break;
+
+ case "is less than":
+ if(action.equals("hide")){
+ if(sourceField.validateDisplay(value,"lessThan")){
+ targetField.hideField();
+ }else{
+ targetField.showField();
+ }
+ }else if(action.equals("show")){
+ if(sourceField.validateDisplay(value,"lessThan")){
+ targetField.showField();
+ }else{
+ targetField.hideField();
+ }
+ }
+ break;
+ }
+ }
+
+ private IField getFieldFromCID(String cid) {
+ IField returnField=null;
+ for (ArrayList fieldList: FormBuilder.fields.values()) {
+ for(IField field:fieldList){
+ if (field.getCIDValue().equals(cid)) {
+ returnField=field;
+ break;
+ }
+ }
+ }
+ if(returnField==null){
+ for (IField field : FormBuilder.sectionsTreeMap.values()) {
+ if (field.getCIDValue().equals(cid)) {
+ returnField=field;
+ break;
+ }
+ }
+ }
+ return returnField;
+ }
+}
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Listeners/CheckboxChangeListener.java b/formbuilder-android/src/com/vertis/formbuilder/Listeners/CheckboxChangeListener.java
new file mode 100644
index 0000000..815e6e1
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Listeners/CheckboxChangeListener.java
@@ -0,0 +1,21 @@
+package com.vertis.formbuilder.Listeners;
+
+import com.vertis.formbuilder.parser.FieldConfig;
+
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+
+public class CheckboxChangeListener implements OnCheckedChangeListener {
+
+ private FieldConfig config;
+
+ public CheckboxChangeListener(FieldConfig config){
+ this.config = config;
+ }
+
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ CheckConditions checkConditionsObject=new CheckConditions(config);
+ checkConditionsObject.loopOverCheckCondition();
+ }
+}
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Listeners/ListChangeListener.java b/formbuilder-android/src/com/vertis/formbuilder/Listeners/ListChangeListener.java
new file mode 100644
index 0000000..e14f983
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Listeners/ListChangeListener.java
@@ -0,0 +1,23 @@
+package com.vertis.formbuilder.Listeners;
+import com.vertis.formbuilder.parser.FieldConfig;
+
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+
+public class ListChangeListener implements OnItemClickListener {
+
+ private FieldConfig config;
+
+ public ListChangeListener(FieldConfig config){
+ this.config = config;
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position,
+ long id) {
+ CheckConditions checkConditionsObject=new CheckConditions(config);
+ checkConditionsObject.loopOverCheckCondition();
+ }
+
+}
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Listeners/RadioChangeListener.java b/formbuilder-android/src/com/vertis/formbuilder/Listeners/RadioChangeListener.java
new file mode 100644
index 0000000..bc00024
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Listeners/RadioChangeListener.java
@@ -0,0 +1,21 @@
+package com.vertis.formbuilder.Listeners;
+
+import com.vertis.formbuilder.parser.FieldConfig;
+
+import android.widget.RadioGroup;
+import android.widget.RadioGroup.OnCheckedChangeListener;
+
+public class RadioChangeListener implements OnCheckedChangeListener{
+
+ private FieldConfig config;
+
+ public RadioChangeListener(FieldConfig config){
+ this.config = config;
+ }
+
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ CheckConditions checkConditionsObject=new CheckConditions(config);
+ checkConditionsObject.loopOverCheckCondition();
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Listeners/TextChangeListener.java b/formbuilder-android/src/com/vertis/formbuilder/Listeners/TextChangeListener.java
new file mode 100644
index 0000000..f04a6e1
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Listeners/TextChangeListener.java
@@ -0,0 +1,28 @@
+package com.vertis.formbuilder.Listeners;
+
+import com.vertis.formbuilder.parser.FieldConfig;
+
+import android.text.Editable;
+import android.text.TextWatcher;
+
+public class TextChangeListener implements TextWatcher {
+
+ private FieldConfig config;
+
+ public TextChangeListener(FieldConfig config){
+ this.config = config;
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count,
+ int after) { }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ CheckConditions checkConditionsObject=new CheckConditions(config);
+ checkConditionsObject.loopOverCheckCondition();
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) { }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/MultiLineEditText.java b/formbuilder-android/src/com/vertis/formbuilder/MultiLineEditText.java
new file mode 100644
index 0000000..93e5734
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/MultiLineEditText.java
@@ -0,0 +1,172 @@
+package com.vertis.formbuilder;
+
+import com.vertis.formbuilder.Listeners.TextChangeListener;
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnFocusChangeListener;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+public class MultiLineEditText implements IField{
+
+ private FieldConfig config;
+ //Views
+ LinearLayout llEditText;
+ TextView tvEditText;
+ EditText etEditText;
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String mtext="";
+ private Typeface font;
+
+ public MultiLineEditText(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ @Override
+ public void createForm(Activity context) {
+ font = new FormBuilderUtil().getFontFromRes(context);
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ llEditText=(LinearLayout) inflater.inflate(R.layout.multiline_edit_text,null);
+ tvEditText = (TextView) llEditText.findViewById(R.id.multilineTextView);
+ etEditText = (EditText) llEditText.findViewById(R.id.multilineEditText);
+ etEditText.setTypeface(font);
+ tvEditText.setTypeface(font);
+ etEditText.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float) 12.5);
+ tvEditText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
+ tvEditText.setTextColor(R.color.TextViewNormal);
+
+ etEditText.addTextChangedListener(new TextChangeListener(config));
+
+ defineViewSettings(context);
+ setViewValues();
+ mapView();
+ setValues();
+ noErrorMessage();
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(tvEditText==null)return;
+ tvEditText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvEditText.setTextColor(R.color.TextViewNormal);
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid()+"_1", llEditText);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", etEditText);
+ }
+
+ private void setViewValues() {
+ tvEditText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ etEditText.setText(mtext);
+ tvEditText.setTextColor(-1);
+ }
+
+ private void defineViewSettings(Activity context) {
+ etEditText.setOnFocusChangeListener( new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if(hasFocus)
+ noErrorMessage();
+ else
+ setValues();
+ }
+ });
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llEditText;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ if(config.getRequired() && mtext.equals("")){
+ valid=false;
+ errorMessage(" Required");
+ }
+ else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(String message) {
+ if(tvEditText==null)return;
+ tvEditText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvEditText.setText(tvEditText.getText() + message);
+ tvEditText.setTextColor(R.color.ErrorMessage);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(llEditText!=null){
+ mtext=etEditText.getText().toString();
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ llEditText=null;
+ tvEditText=null;
+ etEditText=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llEditText!=null){
+ llEditText.setVisibility(View.GONE);
+ llEditText.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llEditText!=null){
+ llEditText.setVisibility(View.VISIBLE);
+ llEditText.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(mtext.toLowerCase().equals(value.toLowerCase()) || mtext.equals("")){
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(llEditText!=null) {
+ return !llEditText.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/NumberField.java b/formbuilder-android/src/com/vertis/formbuilder/NumberField.java
new file mode 100644
index 0000000..cce161b
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/NumberField.java
@@ -0,0 +1,180 @@
+package com.vertis.formbuilder;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnFocusChangeListener;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+public class NumberField implements IField{
+
+ private FieldConfig config;
+ //Views
+ LinearLayout llNumber;
+ TextView tvNumber;
+ EditText etNumber;
+
+ //Values
+ @Expose
+ String cid;
+ @Expose
+ String number="";
+ private Typeface font;
+
+ public NumberField(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ @Override
+ public void createForm(Activity context) {
+ font = new FormBuilderUtil().getFontFromRes(context);
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ llNumber=(LinearLayout) inflater.inflate(R.layout.number_edit_text,null);
+ tvNumber = (TextView) llNumber.findViewById(R.id.numberTextView);
+ etNumber = (EditText) llNumber.findViewById(R.id.numberEditText);
+ etNumber.setTypeface(font);
+ tvNumber.setTypeface(font);
+ etNumber.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float) 12.5);
+ tvNumber.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
+ tvNumber.setTextColor(R.color.TextViewNormal);
+ etNumber.addTextChangedListener(new CustomTextChangeListener(config));
+
+ defineViewSettings(context);
+ setViewValues();
+ mapView();
+ setValues();
+ noErrorMessage();
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(tvNumber==null)return;
+ tvNumber.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvNumber.setTextColor(R.color.TextViewNormal);
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid()+"_1", llNumber);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", etNumber);
+ }
+
+ private void setViewValues() {
+ tvNumber.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ etNumber.setText(number);
+ tvNumber.setTextColor(-1);
+ }
+
+ private void defineViewSettings(Activity context) {
+ etNumber.setOnFocusChangeListener( new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if(hasFocus)
+ noErrorMessage();
+ else
+ setValues();
+ }
+ });
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llNumber;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ if(config.getRequired() && number.equals("")){
+ valid=false;
+ errorMessage(" Required");
+ }
+ else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void errorMessage(String message) {
+ if(tvNumber==null)return;
+ tvNumber.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvNumber.setText(tvNumber.getText() + message);
+ tvNumber.setTextColor(R.color.ErrorMessage);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(llNumber!=null){
+ number=etNumber.getText().toString();
+ }
+ validate();
+
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ llNumber=null;
+ tvNumber=null;
+ etNumber=null;
+ }
+
+ @Override
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llNumber!=null){
+ llNumber.setVisibility(View.GONE);
+ llNumber.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llNumber!=null){
+ llNumber.setVisibility(View.VISIBLE);
+ llNumber.invalidate();
+ }
+ }
+
+ @Override
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(number.equals(value) || number.equals("")){
+ return true;
+ }
+ } else if(condition.equals("is greater than")){
+ if(Integer.parseInt(number) > Integer.parseInt(value) || number.equals("")){
+ return true;
+ }
+ } else if(condition.equals("is less than")){
+ if(Integer.parseInt(number) < Integer.parseInt(value) || number.equals("")){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isHidden(){
+ if(llNumber!=null) {
+ return !llNumber.isShown();
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/Price.java b/formbuilder-android/src/com/vertis/formbuilder/Price.java
new file mode 100644
index 0000000..f8f17b9
--- /dev/null
+++ b/formbuilder-android/src/com/vertis/formbuilder/Price.java
@@ -0,0 +1,215 @@
+package com.vertis.formbuilder;
+
+import com.google.gson.annotations.Expose;
+import com.vertis.formbuilder.parser.FieldConfig;
+import com.vertis.formbuilder.util.FormBuilderUtil;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnFocusChangeListener;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class Price implements IField {
+
+ //config contains all data from json ie id,sid,label,field_options
+ private FieldConfig config;
+ private Typeface font;
+
+ public Price(FieldConfig fcg){
+ this.config=fcg;
+ }
+
+ //Views
+ LinearLayout llPrice;
+ TextView tvPrice;
+ EditText etDollars;
+ EditText etCents;
+
+ //Default values
+ String dollarsHint="Dollars";
+ String centsHint="Cents";
+
+ @Expose
+ String cid;
+ @Expose
+ String dollars="";
+ @Expose
+ String cents="";
+ @Expose
+ String totalPrice;
+
+
+
+ @Override
+ public void createForm(Activity context) {
+ font = new FormBuilderUtil().getFontFromRes(context);
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ llPrice=(LinearLayout) inflater.inflate(R.layout.price,null);
+ tvPrice = (TextView) llPrice.findViewById(R.id.textViewPrice);
+ etDollars = (EditText) llPrice.findViewById(R.id.dollars);
+ etCents = (EditText) llPrice.findViewById(R.id.cents);
+ tvPrice.setTypeface(font);
+ etDollars.setTypeface(font);
+ etCents.setTypeface(font);
+ tvPrice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
+ etDollars.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float) 12.5);
+ etCents.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float) 12.5);
+
+ addTextChangeListeners();
+
+ defineViewSettings(context);
+ setViewValues();
+ mapView();
+ setValues();
+ noErrorMessage();
+ }
+
+ private void addTextChangeListeners() {
+ etDollars.addTextChangedListener(new CustomTextChangeListener(config));
+ etCents.addTextChangedListener(new CustomTextChangeListener(config));
+ }
+
+ @SuppressLint("ResourceAsColor")
+ private void noErrorMessage() {
+ if(tvPrice==null)return;
+ tvPrice.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvPrice.setTextColor(R.color.TextViewNormal);
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid()+"_1", llPrice);
+ ViewLookup.mapField(this.config.getCid()+"_1_1", tvPrice);
+ ViewLookup.mapField(this.config.getCid()+"_1_2", etDollars);
+ ViewLookup.mapField(this.config.getCid()+"_1_3", etCents);
+ }
+
+ private void setViewValues() {
+ tvPrice.setText(this.config.getLabel());
+ etDollars.setText(dollars);
+ etCents.setText(cents);
+ }
+
+ private void defineViewSettings(Activity context) {
+ etDollars.setHint(dollarsHint);
+ etDollars.setOnFocusChangeListener( new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if(hasFocus)
+ noErrorMessage();
+ else
+ setValues();
+ }
+ });
+ etCents.setHint(centsHint);
+ etCents.setOnFocusChangeListener( new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if(hasFocus)
+ noErrorMessage();
+ else
+ setValues();
+ }
+ });
+ }
+
+ @Override
+ public ViewGroup getView() {
+ return llPrice;
+ }
+
+ @Override
+ public boolean validate() {
+ boolean valid;
+ if(config.getRequired()&&dollars.equals("")){
+ valid=false;
+ errorMessage("Required");
+ }
+ //else if(Integer.parseInt(cents)>99){
+ //errorMessage("Value of Cents cannot be more than 99");
+ //valid=false;
+ //}
+ else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
+ }
+
+ private void errorMessage(String message) {
+ if(tvPrice==null)return;
+ tvPrice.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
+ tvPrice.setText(tvPrice.getText() + " " + message);
+ tvPrice.setTextColor(-65536);
+ }
+
+ @Override
+ public void setValues() {
+ this.cid=config.getCid();
+ if(llPrice!=null){
+ dollars=etDollars.getText().toString();
+ cents=etCents.getText().toString();
+ totalPrice=dollars+"."+cents;
+ }
+ validate();
+ }
+
+ @Override
+ public void clearViews() {
+ setValues();
+ llPrice=null;
+ tvPrice=null;
+ etDollars=null;
+ etCents=null;
+ }
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(llPrice!=null){
+ llPrice.setVisibility(View.GONE);
+ llPrice.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(llPrice!=null){
+ llPrice.setVisibility(View.VISIBLE);
+ llPrice.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(totalPrice.equals(value) || totalPrice.equals("")){
+ return true;
+ }
+ } else if(condition.equals("is greater than")){
+ if(Integer.parseInt(totalPrice)>Integer.parseInt(value) || totalPrice.equals("")){
+ return true;
+ }
+ } else if(condition.equals("is less than")){
+ if(Integer.parseInt(totalPrice) options = new ArrayList();
-
// Views
LinearLayout subForm;
TextView headingText;
RadioGroup radioGroup;
- EditText otherTextBox;
+ //Values
@Expose
String cid;
@Expose
- String optionSelected;
- int positionSelected = 0;
+ String optionSelected = "";
@Expose
String other;
@@ -43,56 +40,67 @@ public Radio(FieldConfig fcg){
}
public void createForm(Activity context) {
- options.add("male");
- options.add("female");
- otherHeading="other";
-
- subForm = new LinearLayout(context);
- ViewLookup.mapField(this.config.getCid()+"_1", subForm);
- subForm.setOrientation(LinearLayout.VERTICAL);
- headingText = new TextView(context);
- headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
- subForm.addView(headingText);
+ LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
+ subForm=(LinearLayout) inflater.inflate(R.layout.radio,null);
+ headingText = (TextView) subForm.findViewById(R.id.tvRadio);
+ otherHeading="other";
radioGroup = new RadioGroup(context);
ViewLookup.mapField(this.config.getCid()+"_1_1", radioGroup);
subForm.addView(radioGroup);
+ radioGroup.clearCheck();
+ subForm.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ subForm.setFocusableInTouchMode(true);
+ subForm.setFocusable(true);
+ subForm.requestFocus();
+ }
+ });
int i = 0;
- for (i = 0; i < options.size(); i++) {
+ for (i = 0; i < this.config.getField_options().getOptions().size(); i++) {
addButton(i, context);
}
- if (otherRequired) {
- addButton(i, context);
- otherTextBox = new EditText(context);
- otherTextBox.setText(other);
- subForm.addView(otherTextBox);
+ radioGroup.setOnCheckedChangeListener(new RadioChangeListener(config));
+ mapView();
+ setViewValues();
+ }
+
+ private void mapView() {
+ ViewLookup.mapField(this.config.getCid()+"_1",subForm);
+ for (int i = 0; i < radioGroup.getChildCount(); i++) {
+ ViewLookup.mapField(this.config.getCid()+"_1_"+i+1, radioGroup.getChildAt(i));
}
}
+ private void setViewValues(){
+ headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":""));
+ headingText.setTextColor(Color.BLACK);
+ }
+
void addButton(int i , Activity context){
RadioButton button = new RadioButton(context);
+ button.setId(i);
ViewLookup.mapField(this.config.getCid()+"_1_1_"+Integer.toString(i), radioGroup);
- button.setText(options.get(i));
+ if(i < this.config.getField_options().getOptions().size()){
+ button.setText(this.config.getField_options().getOptions().get(i).getLabel());
+ }
+ button.setButtonDrawable(R.drawable.radio_custom);
radioGroup.addView(button);
- if (i == positionSelected)
+ if(optionSelected!= null && !TextUtils.isEmpty(optionSelected)&& this.config.getField_options().getOptions().get(i).getLabel().equals(optionSelected))
radioGroup.check(button.getId());
- if(i==options.size()){
- button.setOnCheckedChangeListener(new OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView,
- boolean isChecked) {
- if (isChecked) {
- otherTextBox.setVisibility(View.VISIBLE);
- }
- else {
- otherTextBox.setVisibility(View.GONE);
- }
- }
- });
- }
}
+
public boolean validate() {
- return true;
+ boolean valid;
+ if(TextUtils.isEmpty(optionSelected)){
+ valid=false;
+ errorMessage(" Pick one!");
+ } else{
+ valid=true;
+ noErrorMessage();
+ }
+ return valid;
}
public ViewGroup getView() {
@@ -102,42 +110,71 @@ public ViewGroup getView() {
@Override
public void setValues() {
this.cid=config.getCid();
- RadioButton selectedButton=(RadioButton)radioGroup.findViewById(radioGroup.getCheckedRadioButtonId());
- optionSelected=selectedButton.getText().toString();
- if(otherRequired)
- other=otherTextBox.getText().toString();
- else
- other="";
-
- for(int i=0 ; i < options.size() ; i++ ){
- if(options.get(i).equals(optionSelected)){
- positionSelected=i;break;
- }
+ if(subForm!=null){
+ RadioButton selectedButton=(RadioButton)radioGroup.findViewById(radioGroup.getCheckedRadioButtonId());
+ if(selectedButton != null){
+ optionSelected=selectedButton.getText().toString();
+ }
}
+ validate();
}
-
+ @SuppressLint("ResourceAsColor")
public void errorMessage(String message){
if(headingText==null)return;
-
headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
headingText.setText(headingText.getText() + " " + message);
- headingText.setTextColor(-65536);
+ headingText.setTextColor(R.color.ErrorMessage);
}
+ @SuppressLint("ResourceAsColor")
public void noErrorMessage(){
if(headingText==null)return;
-
headingText.setText(this.config.getLabel() + (this.config.getRequired()?"*":"") );
- headingText.setTextColor(-1);
+ headingText.setTextColor(R.color.TextViewNormal);
}
@Override
public void clearViews() {
setValues();
-
subForm=null;
headingText=null;
radioGroup=null;
- otherTextBox=null;
}
-};
\ No newline at end of file
+
+ public String getCIDValue() {
+ return this.config.getCid();
+ }
+
+ public void hideField() {
+ if(subForm!=null){
+ subForm.setVisibility(View.GONE);
+ subForm.invalidate();
+ }
+ }
+
+ @Override
+ public void showField() {
+ if(subForm!=null){
+ subForm.setVisibility(View.VISIBLE);
+ subForm.invalidate();
+ }
+ }
+
+ public boolean validateDisplay(String value,String condition) {
+ if(condition.equals("equals")){
+ if(optionSelected.toLowerCase().equals(value.toLowerCase()) || optionSelected.equals("")){
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isHidden(){
+ if(subForm!=null) {
+ return !subForm.isShown();
+ } else {
+ return false;
+ }
+ }
+};
\ No newline at end of file
diff --git a/formbuilder-android/src/com/vertis/formbuilder/ResultJson.java b/formbuilder-android/src/com/vertis/formbuilder/ResultJson.java
index 1145755..ebfd45f 100644
--- a/formbuilder-android/src/com/vertis/formbuilder/ResultJson.java
+++ b/formbuilder-android/src/com/vertis/formbuilder/ResultJson.java
@@ -5,11 +5,9 @@
import com.google.gson.annotations.Expose;
public class ResultJson {
-
@Expose
ArrayList