Skip to content

Commit

Permalink
Initial commit. First working version.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilsjolander committed Jun 16, 2015
0 parents commit 2b95d26
Show file tree
Hide file tree
Showing 32 changed files with 925 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
###Android###

# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log


###IntelliJ###

*.iml
*.ipr
*.iws
.idea/


###OSX###

.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


###Linux###

*~

# KDE directory preferences
.directory
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#IntentBuilder
IntentBuilder is a type safe way of creating intents and populating them with extras. Intents were created to be very dynamic but often times the dynamic nature of intents is not needed and just gets in the way of writing safe code.

##Installation
```groovy
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'se.emilsjolander:intentbuilder-api:0.9.0'
apt 'se.emilsjolander:intentbuilder-compiler:0.9.0'
}
```

##Usage
Annotate your activities and services with an `@IntentBuilder` annotation so that they are picked up by the library. For every class with an `@IntentBuilder` annotation a class named `MyActivityIntentBuilder` will be generated (Replace 'MyActivity' in the class name whith whatever the name of your Activity or Service class is). If your activity or service takes in parameters via extras in the intent you can now mark field with the `@Extra` annotation and they can be injected with the static `inject` method on the generated intent builder class. Extras can be marked as optional with the `@Optional` annotation.

```java
@IntentBuilder
class DetailActivity extends Activity {

@Extra
String id;

@Extra @Optional
String title;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DetailActivityIntentBuilder.inject(getIntent(), this);
// TODO use id and title
}

}
43 changes: 43 additions & 0 deletions README.md.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#IntentBuilder
IntentBuilder is a type safe way of creating intents and populating them with extras. Intents were created to be very dynamic but often times the dynamic nature of intents is not needed and just gets in the way of writing safe code.

##Installation
```groovy
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
compile 'se.emilsjolander:intentbuilder-api:%%version%%'
apt 'se.emilsjolander:intentbuilder-compiler:%%version%%'
}
```

##Usage
Annotate your activities and services with an `@IntentBuilder` annotation so that they are picked up by the library. For every class with an `@IntentBuilder` annotation a class named `MyActivityIntentBuilder` will be generated (Replace 'MyActivity' in the class name whith whatever the name of your Activity or Service class is). If your activity or service takes in parameters via extras in the intent you can now mark field with the `@Extra` annotation and they can be injected with the static `inject` method on the generated intent builder class. Extras can be marked as optional with the `@Optional` annotation.

```java
@IntentBuilder
class DetailActivity extends Activity {

@Extra
String id;

@Extra @Optional
String title;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DetailActivityIntentBuilder.inject(getIntent(), this);
// TODO use id and title
}

}
30 changes: 30 additions & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.library'
apply plugin: 'bintray-release'

android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

publish {
userOrg = 'emilsjolander'
groupId = 'se.emilsjolander'
artifactId = 'intentbuilder-api'
version = VERSION
description = 'Generate type safe code for building intents.'
website = 'https://github.com/emilsjolander/intentbuilder'
licences = ['Apache-2.0']
}
7 changes: 7 additions & 0 deletions api/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="se.emilsjolander.api">

<application android:allowBackup="true">

</application>

</manifest>
4 changes: 4 additions & 0 deletions api/src/main/java/se/emilsjolander/intentbuilder/Extra.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package se.emilsjolander.intentbuilder;

public @interface Extra {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package se.emilsjolander.intentbuilder;

public @interface IntentBuilder {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package se.emilsjolander.intentbuilder;

/**
* Created by emilsjolander on 6/14/15.
*/
public @interface Optional {
}
59 changes: 59 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath 'com.novoda:bintray-release:0.2.10'
}
}

allprojects {
repositories {
jcenter()
}
}

ext {
VERSION = version()
}

task bumpMajor << {
ant.propertyfile(file: 'version.properties') {
entry(key: 'major', type: 'int', operation: '+', value: 1)
entry(key: 'minor', type: 'int', operation: '=', value: 0)
entry(key: 'patch', type: 'int', operation: '=', value: 0)
}
}

task bumpMinor << {
ant.propertyfile(file: 'version.properties') {
entry(key: 'minor', type: 'int', operation: '+', value: 1)
entry(key: 'patch', type: 'int', operation: '=', value: 0)
}
}

task bumpPatch << {
ant.propertyfile(file: 'version.properties') {
entry(key: 'patch', type: 'int', operation: '+', value: 1)
}
}

task genReadMe << {
def template = file('README.md.template').text
def result = template.replaceAll("%%version%%", version())
file("README.md").withWriter{ it << result }
}

task version << {
println version()
}

def String version() {
def versionPropsFile = file('version.properties')
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))

return versionProps['major'] + "." + versionProps['minor'] + "." + versionProps['patch']
}
29 changes: 29 additions & 0 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'java'
apply plugin: 'bintray-release'

sourceCompatibility = 1.7

sourceSets {
main {
java {
srcDirs = ['src/main/java', '../api/src/main/java']
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':api')
compile 'com.squareup:javapoet:1.0.0'
compile 'com.google.android:android:4.1.1.4'
}

publish {
userOrg = 'emilsjolander'
groupId = 'se.emilsjolander'
artifactId = 'intentbuilder-compiler'
version = VERSION
description = 'Generate type safe code for building intents.'
website = 'https://github.com/emilsjolander/intentbuilder'
licences = ['Apache-2.0']
}
Loading

0 comments on commit 2b95d26

Please sign in to comment.