Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android example using Java8
- Loading branch information
Showing
62 changed files
with
872 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
buildToolsVersion "27.0.3" | ||
|
||
defaultConfig { | ||
applicationId "dslplatform.com.androidexample" | ||
minSdkVersion 15 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled true | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:27.1.1' | ||
|
||
//java8 version can work via desugar | ||
compile 'com.dslplatform:dsl-json-java8:1.8.0' | ||
//using alternative to java8 time api | ||
compile 'com.dslplatform:dsl-json-threetenbp:1.8.0' | ||
//invoke the compile time databinding | ||
annotationProcessor 'com.dslplatform:dsl-json-java8:1.8.0' | ||
//just satisfy Jsonb provided dependency | ||
provided 'javax.json.bind:javax.json.bind-api:1.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in D:\Programi\Android\sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# DSL-JSON | ||
-keep class dsl_json.** { *; } | ||
-keep @com.dslplatform.json.CompiledJson class * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dslplatform.com.androidexample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
22 changes: 22 additions & 0 deletions
22
examples/AndroidJava/app/src/main/java/dslplatform/com/androidexample/DSL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dslplatform.com.androidexample; | ||
|
||
import com.dslplatform.json.DslJson; | ||
import com.dslplatform.json.runtime.Settings; | ||
|
||
public abstract class DSL { | ||
private static DslJson<Object> json; | ||
public static DslJson<Object> JSON() { | ||
if (json == null) { | ||
//Model converters will be loaded based on naming convention. | ||
//Previously it would be loaded through ServiceLoader.load, | ||
//which is still an option if dsljson.configuration name is specified. | ||
//DSL-JSON loads all services registered into META-INF/services | ||
//and falls back to naming based convention of package._NAME_DslJsonConfiguration if not found | ||
//basicSetup is Android friendly version of withRuntime (which avoids Java8 types) | ||
//It is enabled to support runtime analysis for stuff which is not registered by default | ||
//Annotation processor will run by default and generate descriptions for JSON encoding/decoding | ||
json = new DslJson<>(Settings.basicSetup().allowArrayFormat(true)); | ||
} | ||
return json; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/AndroidJava/app/src/main/java/dslplatform/com/androidexample/ImmutablePerson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dslplatform.com.androidexample; | ||
|
||
import com.dslplatform.json.CompiledJson; | ||
|
||
public class ImmutablePerson { | ||
|
||
public final String firstName; | ||
public final String lastName; | ||
public final int age; | ||
|
||
//when there are multiple constructors, @CompiledJson annotation can be used to specify appropriate constructor | ||
//objects can be encoded/decoded as key:value pairs or as object format (without keys) | ||
//array format must be allowed in DslJson before it will be used for encoding | ||
//when non-empty ctor is used, array index on properties are not mandatory | ||
@CompiledJson(formats = {CompiledJson.Format.ARRAY, CompiledJson.Format.OBJECT}) | ||
public ImmutablePerson(String firstName, String lastName, int age) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.age = age; | ||
} | ||
} |
Oops, something went wrong.