Skip to content

Commit de0b44b

Browse files
committed
Added AndroidFormEnhancer sample.
1 parent 76a7f4a commit de0b44b

File tree

20 files changed

+199
-1
lines changed

20 files changed

+199
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Snippet codes for Android apps.
3838

3939
Example app using 'ProductFlavors'.
4040

41+
### AndroidFormEnhancer
42+
43+
Android application showing how to use
44+
[AndroidFormEnhancer](https://github.com/ksoichiro/AndroidFormEnhancer).
45+
4146
### SimpleAlertDialog for Android
4247

4348
Android application showing how to use
@@ -76,6 +81,14 @@ $ ./gradlew :app-flavor:installProductionDebug
7681
$ ./gradlew :app-flavor:installDevelopmentDebug
7782
```
7883

84+
### AndroidFormEnhancer
85+
86+
Install app with Gradle Wrapper.
87+
88+
```sh
89+
$ ./gradlew :app-androidformenhancer:installDebug
90+
```
91+
7992
### SimpleAlertDialog for Android
8093

8194
Install app with Gradle Wrapper.

app-androidformenhancer/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app-androidformenhancer/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# app-androidformenhancer
2+
3+
This is an Android application showing how to use [AndroidFormEnhancer](https://github.com/ksoichiro/AndroidFormEnhancer).
4+

app-androidformenhancer/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'android'
2+
3+
android {
4+
compileSdkVersion 19
5+
buildToolsVersion "19.1.0"
6+
7+
defaultConfig {
8+
applicationId "com.snippet.androidformenhancer"
9+
minSdkVersion 9
10+
targetSdkVersion 19
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
runProguard false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile 'com.android.support:appcompat-v7:19.+'
25+
compile 'com.github.ksoichiro:androidformenhancer:1.1.+@aar'
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Applications/adt-bundle-mac-x86_64-20131030/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.snippet.androidformenhancer" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@drawable/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme" >
10+
<activity
11+
android:name=".MainActivity"
12+
android:label="@string/app_name" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.snippet.androidformenhancer;
2+
3+
public class DefaultEntity {
4+
public String name;
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.snippet.androidformenhancer;
2+
3+
import com.androidformenhancer.annotation.MaxLength;
4+
import com.androidformenhancer.annotation.Multibyte;
5+
import com.androidformenhancer.annotation.Required;
6+
import com.androidformenhancer.annotation.Widget;
7+
8+
/**
9+
* Created by ksoichiro on 2014/06/03.
10+
*/
11+
public class DefaultForm {
12+
13+
@Required
14+
@Multibyte
15+
@MaxLength(20)
16+
@Widget(id = R.id.textfield_name, nameResId = R.string.form_default_name)
17+
public String name;
18+
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.snippet.androidformenhancer;
2+
3+
import android.support.v7.app.ActionBarActivity;
4+
import android.os.Bundle;
5+
import android.view.Menu;
6+
import android.view.MenuItem;
7+
import android.view.View;
8+
import android.widget.Toast;
9+
10+
import com.androidformenhancer.ValidationResult;
11+
import com.androidformenhancer.helper.ActivityFormHelper;
12+
13+
14+
public class MainActivity extends ActionBarActivity {
15+
16+
@Override
17+
protected void onCreate(Bundle savedInstanceState) {
18+
super.onCreate(savedInstanceState);
19+
setContentView(R.layout.activity_main);
20+
}
21+
22+
public void onSubmit(View v) {
23+
ActivityFormHelper helper = new ActivityFormHelper(DefaultForm.class, this);
24+
ValidationResult result = helper.validate();
25+
if (result.hasError()) {
26+
Toast.makeText(this, result.getAllSerializedErrors(), Toast.LENGTH_SHORT).show();
27+
} else {
28+
// Create entity and do what you want
29+
// e.g. insert into database, send to server by HTTP
30+
DefaultEntity entity = helper.create(DefaultEntity.class);
31+
Toast.makeText(this, "OK!", Toast.LENGTH_SHORT).show();
32+
}
33+
}
34+
}
Loading
Loading
Loading
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:paddingBottom="@dimen/activity_vertical_margin"
7+
android:paddingLeft="@dimen/activity_horizontal_margin"
8+
android:paddingRight="@dimen/activity_horizontal_margin"
9+
android:paddingTop="@dimen/activity_vertical_margin"
10+
tools:context=".MainActivity">
11+
12+
<TextView
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:text="@string/form_default_name" />
16+
17+
<EditText
18+
android:id="@+id/textfield_name"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:inputType="text" />
22+
23+
<Button
24+
android:id="@+id/btn_submit"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:layout_alignParentBottom="true"
28+
android:onClick="onSubmit"
29+
android:text="@string/btn_submit" />
30+
31+
</LinearLayout>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
3+
(such as screen margins) for screens with more than 820dp of available width. This
4+
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
5+
<dimen name="activity_horizontal_margin">64dp</dimen>
6+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<!-- Default screen margins, per the Android Design guidelines. -->
3+
<dimen name="activity_horizontal_margin">16dp</dimen>
4+
<dimen name="activity_vertical_margin">16dp</dimen>
5+
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">app-androidformenhancer</string>
5+
<string name="form_default_name">Name</string>
6+
<string name="btn_submit">Submit</string>
7+
8+
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5+
<!-- Customize your theme here. -->
6+
</style>
7+
8+
</resources>

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app', ':app-flavor', ':app-richbuttons', 'app-simplealertdialog'
1+
include ':app', ':app-flavor', ':app-richbuttons', ':app-androidformenhancer', ':app-simplealertdialog'

0 commit comments

Comments
 (0)