diff --git a/CHANGELOG.md b/CHANGELOG.md index f280484..7fecc64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog: ### Versions: -* **1.1.0** - New @SaveInstance annotation to automatically save and restore variables on configuration changes. +* **1.1.1** - @OnBackground and @OnUIThread now can be used with static methods. Solved several method search problems, too. +* **1.1.0** - New @SaveInstance annotation to automatically save and restore variables on configuration changes. * **1.0.4** - Fixed bug in @InjectViews annotation which didn't recognize "List" as a valid container. * **1.0.3** - Fixed bug in ``@OnLongClick`` annotation. * **1.0.2** - Fixed bug that prevented anything but an Activity from injection. Disabled type checking for auto-generated methods, so users won't have to type ``@CompileStatic(TypeCheckingMethod.SKIP)``. diff --git a/README.md b/README.md index fc8d9bd..030bf3e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,13 @@ class MyActivity extends Activity { } ``` +## Colaborators + +I'd really want to thank: + +* [Dexafree](https://github.com/dexafree) for adding `@SaveInstance` annotation and helping with the testing. +* [Eugene Kamenev](https://github.com/eugene-kamenev) for adding DSL functionality to *android-dsl* branch. + ## Documentation For more info, please [read the wiki pages](https://github.com/Arasthel/SwissKnife/wiki). They contain explanations about how to use the library and the available annotations: @@ -77,7 +84,7 @@ Once your project App Module is configured to use Groovy you can add this librar ```groovy dependencies { ... - compile 'com.arasthel:swissknife:1.1.0' + compile 'com.arasthel:swissknife:1.1.1' ... } diff --git a/SwissKnife/SwissKnife.iml b/SwissKnife/SwissKnife.iml index e356336..0901614 100644 --- a/SwissKnife/SwissKnife.iml +++ b/SwissKnife/SwissKnife.iml @@ -1,5 +1,5 @@ - + @@ -10,9 +10,10 @@ diff --git a/SwissKnife/build.gradle b/SwissKnife/build.gradle index f79b537..4156b2a 100644 --- a/SwissKnife/build.gradle +++ b/SwissKnife/build.gradle @@ -1,27 +1,16 @@ -buildscript { - repositories { - mavenLocal() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:0.12.+' - classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.0' - } -} - apply plugin: 'com.android.library' apply plugin: 'me.champeau.gradle.groovy-android' android { - compileSdkVersion 19 + compileSdkVersion 21 buildToolsVersion "20.0.0" defaultConfig { applicationId "com.arasthel.swissknife" minSdkVersion 8 - targetSdkVersion 19 + targetSdkVersion 21 versionCode 1 - versionName "1.0.1" + versionName "1.1.1" } buildTypes { release { @@ -42,9 +31,8 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'org.codehaus.groovy:groovy:2.4.0-beta-3:grooid' - compile 'com.android.support:support-v4:20.0.0' + compile 'com.android.support:support-v4:21.0.0' } // Script to upload plugin to Maven apply from: '../maven_push.gradle' - diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/SwissKnife.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/SwissKnife.groovy similarity index 93% rename from SwissKnife/src/main/java/com/arasthel/swissknife/SwissKnife.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/SwissKnife.groovy index 10ad20a..05cdfdc 100644 --- a/SwissKnife/src/main/java/com/arasthel/swissknife/SwissKnife.groovy +++ b/SwissKnife/src/main/groovy/com/arasthel/swissknife/SwissKnife.groovy @@ -36,7 +36,6 @@ public class SwissKnife { public static void inject(Object target) { Method method = null; - Method[] methods = null; try { method = SwissKnife.searchMethod(target, "injectViews", [Object.class]); } catch (NoSuchMethodException e) { @@ -414,10 +413,40 @@ public class SwissKnife { Method method = null; - try { - method = currentObject.class.getMethod(name, parameters); - } catch (NoSuchMethodException e) { - return null; + // We use a set so methods can't appear twice in here + Set methods = new HashSet<>() + if(currentObject instanceof Class) { + methods.addAll(currentObject.getMethods()) + // Search for private methods, too + methods.addAll(currentObject.getDeclaredMethods()) + } else { + methods.addAll(currentObject.class.getMethods()) + // Search for private methods, too + methods.addAll(currentObject.class.getDeclaredMethods()) + } + + // As getMethod(...) doesn't search for a compatible but an exact match, we have to search manually + for(Method m : methods) { + if(m.getName() == name) { + if(m.getParameterTypes().length == parameters.length) { + boolean found = true + for(int i = 0; i < m.getParameterTypes().length; i++) { + Class parameter = m.getParameterTypes()[i] + if(!parameter.isAssignableFrom(parameters[i])) { + found = false + } + } + if(found == true) { + method = m + break + } + } + } + } + + // If method is private (shouldn't be), we make it accessible + if(!method.isAccessible()) { + method.setAccessible(true) } return method; diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectView.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectView.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectView.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectView.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectViewTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectViewTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectViewTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectViewTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectViews.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectViews.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectViews.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectViews.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectViewsTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectViewsTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/InjectViewsTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/InjectViewsTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnBackground.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnBackground.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnBackground.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnBackground.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnBackgroundTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnBackgroundTransformation.groovy similarity index 95% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnBackgroundTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnBackgroundTransformation.groovy index ec8cbfd..0ca0987 100644 --- a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnBackgroundTransformation.groovy +++ b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnBackgroundTransformation.groovy @@ -33,7 +33,7 @@ public class OnBackgroundTransformation implements ASTTransformation, Opcodes { } private MethodNode createNewMethod(MethodNode annotatedMethod, BlockStatement originalCode) { - return new MethodNode(annotatedMethod.name+"\$background", ACC_PUBLIC, ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode); + return new MethodNode(annotatedMethod.name+"\$background", annotatedMethod.getModifiers(), ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode); } private void createRunnable(MethodNode annotatedMethod) { diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnChecked.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnChecked.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnChecked.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnChecked.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnCheckedTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnCheckedTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnCheckedTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnCheckedTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnClick.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnClick.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnClick.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnClick.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnClickTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnClickTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnClickTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnClickTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnEditorAction.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnEditorAction.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnEditorAction.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnEditorAction.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnEditorActionTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnEditorActionTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnEditorActionTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnEditorActionTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnFocusChanged.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnFocusChanged.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnFocusChanged.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnFocusChanged.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnFocusChangedTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnFocusChangedTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnFocusChangedTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnFocusChangedTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemClick.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemClick.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemClick.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemClick.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemClickTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemClickTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemClickTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemClickTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemLongClick.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemLongClick.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemLongClick.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemLongClick.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemLongClickTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemLongClickTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemLongClickTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemLongClickTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemSelected.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemSelected.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemSelected.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemSelected.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemSelectedTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemSelectedTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnItemSelectedTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnItemSelectedTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnLongClick.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnLongClick.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnLongClick.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnLongClick.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnLongClickTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnLongClickTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnLongClickTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnLongClickTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnPageChanged.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnPageChanged.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnPageChanged.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnPageChanged.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnPageChangedTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnPageChangedTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnPageChangedTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnPageChangedTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTextChanged.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTextChanged.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTextChanged.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTextChanged.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTextChangedTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTextChangedTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTextChangedTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTextChangedTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTouch.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTouch.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTouch.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTouch.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTouchTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTouchTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnTouchTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnTouchTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnUIThread.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnUIThread.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnUIThread.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnUIThread.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnUIThreadTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnUIThreadTransformation.groovy similarity index 95% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnUIThreadTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnUIThreadTransformation.groovy index b0739e3..ddcac5a 100644 --- a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/OnUIThreadTransformation.groovy +++ b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/OnUIThreadTransformation.groovy @@ -34,7 +34,7 @@ public class OnUIThreadTransformation implements ASTTransformation, Opcodes { } private MethodNode createNewMethod(MethodNode annotatedMethod, BlockStatement originalCode) { - return new MethodNode(annotatedMethod.name+"\$uithread", ACC_PUBLIC, ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode); + return new MethodNode(annotatedMethod.name+"\$uithread", annotatedMethod.getModifiers(), ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode); } private void createRunnable(MethodNode annotatedMethod) { diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/SaveInstance.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/SaveInstance.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/SaveInstance.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/SaveInstance.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/annotations/SaveInstanceTransformation.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/SaveInstanceTransformation.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/annotations/SaveInstanceTransformation.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/annotations/SaveInstanceTransformation.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/utils/AnnotationUtils.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/utils/AnnotationUtils.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/utils/AnnotationUtils.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/utils/AnnotationUtils.groovy diff --git a/SwissKnife/src/main/java/com/arasthel/swissknife/utils/Finder.groovy b/SwissKnife/src/main/groovy/com/arasthel/swissknife/utils/Finder.groovy similarity index 100% rename from SwissKnife/src/main/java/com/arasthel/swissknife/utils/Finder.groovy rename to SwissKnife/src/main/groovy/com/arasthel/swissknife/utils/Finder.groovy diff --git a/SwissKnifeProject.iml b/SwissKnifeProject.iml index efecf5c..a9d756f 100644 --- a/SwissKnifeProject.iml +++ b/SwissKnifeProject.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index e9432b8..ae8d467 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,8 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:0.12.2' + classpath 'com.android.tools.build:gradle:0.13.+' + classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index d1e94aa..69ff097 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,8 +17,8 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=1.1.0 -VERSION_CODE=6 +VERSION_NAME=1.1.1 +VERSION_CODE=7 GROUP=com.arasthel POM_DESCRIPTION=Android library for View Injection and Async processing diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1e61d1f..41e5e08 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 10 15:27:10 PDT 2013 +#Tue Oct 28 12:47:37 CET 2014 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 2c00c40..2d02104 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,25 +1,14 @@ -buildscript { - repositories { - mavenLocal() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:0.12.+' - classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.0' - } -} - apply plugin: 'com.android.application' apply plugin: 'me.champeau.gradle.groovy-android' android { - compileSdkVersion 19 + compileSdkVersion 21 buildToolsVersion "20.0.0" defaultConfig { applicationId "com.dexafree.sample" minSdkVersion 14 - targetSdkVersion 19 + targetSdkVersion 21 versionCode 1 versionName "1.0" } @@ -29,16 +18,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - - packagingOptions { - // workaround for http://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk - exclude 'META-INF/LICENSE.txt' - exclude 'META-INF/groovy-release-info.properties' - } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':SwissKnife') - compile 'org.codehaus.groovy:groovy:2.4.0-beta-2:grooid' + compile 'org.codehaus.groovy:groovy:2.4.0-beta-3:grooid' } diff --git a/sample/sample.iml b/sample/sample.iml index 7155eb2..98b13aa 100644 --- a/sample/sample.iml +++ b/sample/sample.iml @@ -1,5 +1,5 @@ - + @@ -10,9 +10,10 @@ diff --git a/sample/src/main/groovy/com/dexafree/sample/BackgroundActivity.groovy b/sample/src/main/groovy/com/dexafree/sample/BackgroundActivity.groovy new file mode 100644 index 0000000..8be87e3 --- /dev/null +++ b/sample/src/main/groovy/com/dexafree/sample/BackgroundActivity.groovy @@ -0,0 +1,114 @@ +package com.dexafree.sample + +import android.app.Activity +import android.content.Context +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.os.Bundle +import android.util.Log +import android.widget.EditText +import android.widget.ImageView +import com.arasthel.swissknife.SwissKnife +import com.arasthel.swissknife.annotations.InjectView +import com.arasthel.swissknife.annotations.OnBackground +import com.arasthel.swissknife.annotations.OnClick +import com.arasthel.swissknife.annotations.OnUIThread +import com.arasthel.swissknife.annotations.SaveInstance +import groovy.transform.CompileStatic + +@CompileStatic +public class BackgroundActivity extends Activity { + + private Context mContext; + + @SaveInstance + public Person[] myPersons + + @SaveInstance + public Person aPerson + + @SaveInstance + public ArrayList aParcelableList + + @SaveInstance + public String myString + + @SaveInstance + public int myInt + + + @InjectView(R.id.edit_text) + @SaveInstance + public EditText textView; + + + @InjectView(R.id.image_view) ImageView image + + @OnClick(R.id.load_button) + public void onClick() { + startLoading() + } + + @OnBackground() + public void startLoading() { + String url = "https://camo.githubusercontent.com/216b3510229c2a6a77ccef60f258ac760a86fc79/687474703a2f2f692e696d6775722e636f6d2f4c53396f4859562e706e67"; + Bitmap imageBitmap; + + InputStream inputStream = new URL(url).openStream() + imageBitmap = BitmapFactory.decodeStream(inputStream) + + setImage(imageBitmap) + } + + @OnUIThread() + public void setImage(Bitmap bitmap){ + image.setImageBitmap(bitmap) + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState) + mContext = this; + setContentView(R.layout.activity_background) + + SwissKnife.inject(this) + SwissKnife.restoreState(this, savedInstanceState) + + if(savedInstanceState == null){ + Log.d("SIS", "WAS NULL") + + myPersons = new Person[1] + aParcelableList = new ArrayList() + aPerson = new Person("MyName", 55) + myInt = 150 + myString = "I am a String" + + myPersons[0] = aPerson + aParcelableList.add(aPerson) + + } + + + assert myPersons[0].name== "MyName" + assert myPersons[0].age == 55 + + assert aPerson.name == "MyName" + assert aPerson.age == 55 + + assert aParcelableList.get(0).name == "MyName" + assert aParcelableList.get(0).age == 55 + + assert myInt == 150 + assert myString == "I am a String" + } + + + @Override + public void onSaveInstanceState(Bundle outState){ + super.onSaveInstanceState(outState) + } + + + + +} \ No newline at end of file diff --git a/sample/src/main/groovy/com/dexafree/sample/BaseActivity.groovy b/sample/src/main/groovy/com/dexafree/sample/BaseActivity.groovy new file mode 100644 index 0000000..ccb9de5 --- /dev/null +++ b/sample/src/main/groovy/com/dexafree/sample/BaseActivity.groovy @@ -0,0 +1,17 @@ +package com.dexafree.sample + +import android.app.Activity +import android.widget.Button +import android.widget.TextView +import com.arasthel.swissknife.annotations.InjectView;/** + * Created by Arasthel on 27/10/14. + */ + +import groovy.transform.CompileStatic; + +@CompileStatic +public class BaseActivity extends Activity { + + @InjectView(R.id.written_text) + TextView writtenTextView +} diff --git a/sample/src/main/groovy/com/dexafree/sample/MainActivity.groovy b/sample/src/main/groovy/com/dexafree/sample/MainActivity.groovy new file mode 100644 index 0000000..d39d32e --- /dev/null +++ b/sample/src/main/groovy/com/dexafree/sample/MainActivity.groovy @@ -0,0 +1,109 @@ +package com.dexafree.sample + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.view.KeyEvent +import android.view.Menu +import android.view.MenuItem +import android.widget.* +import com.arasthel.swissknife.SwissKnife +import com.arasthel.swissknife.annotations.* +import groovy.transform.CompileStatic + +@CompileStatic +public class MainActivity extends BaseActivity { + + private Context mContext; + + @InjectView(R.id.first_textview) + TextView firstTextView + @InjectView(R.id.first_button) + Button firstButton + @InjectView(R.id.list_view) + ListView listView + + @OnTextChanged(value = R.id.edit_text, method = OnTextChanged.Method.ON_TEXT_CHANGED) + public void onTextChanged(CharSequence sequence) { + writtenTextView.setText(sequence) + } + + @OnEditorAction(R.id.edit_text) + public boolean onEditorAction(KeyEvent key) { + Toast.makeText(mContext, "Editor action received", Toast.LENGTH_SHORT).show() + true + } + + + @OnClick(R.id.first_button) + public void clicked() { + firstButton.setText("I've been clicked! Click me longer!") + } + + @OnLongClick(R.id.first_button) + public boolean longClicked() { + firstButton.setText("I've been clicked for a long time!") + return true + } + + @OnClick(R.id.second_button) + public void changeText() { + firstTextView.setText("You have pressed the second button!") + } + + @OnClick(R.id.new_activity) + public void newActivity() { + startActivity(new Intent(mContext, BackgroundActivity.class)) + } + + @OnItemClick(R.id.list_view) + public void onItemClick(int position) { + Toast.makeText(mContext, "Pressed item number $position", Toast.LENGTH_SHORT).show() + } + + @OnItemLongClick(R.id.list_view) + public boolean onItemLongClick(int position) { + Toast.makeText(mContext, "Long pressed item number $position", Toast.LENGTH_SHORT).show() + true + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState) + mContext = this; + setContentView(R.layout.activity_main) + + SwissKnife.inject(this) + firstTextView.setText("HELLO") + + def items = generateItems() + listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, items)) + } + + List generateItems() { + def strings = [] + 20.times { + strings << "Element $it" + } + + strings + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu) + true + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId() + if (id == R.id.action_settings) { + return true + } + return super.onOptionsItemSelected(item) + } +} \ No newline at end of file diff --git a/sample/src/main/groovy/com/dexafree/sample/Person.groovy b/sample/src/main/groovy/com/dexafree/sample/Person.groovy new file mode 100644 index 0000000..e5c23ee --- /dev/null +++ b/sample/src/main/groovy/com/dexafree/sample/Person.groovy @@ -0,0 +1,64 @@ +package com.dexafree.sample; + + +import android.os.Parcel; +import android.os.Parcelable +import groovy.transform.CompileStatic; + + +public class Person implements Parcelable { + + private String name; + private int age; + + String getName() { + return name; + } + + void setName(String name) { + this.name = name; + } + + int getAge() { + return age; + } + + void setAge(int age) { + this.age = age; + } + + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.name); + dest.writeInt(this.age); + } + + public Person() { + } + + public Person(String name, int age){ + this.name = name; + this.age = age; + } + + private Person(Parcel parcel) { + this.name = parcel.readString(); + this.age = parcel.readInt(); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public Person createFromParcel(Parcel source) { + return new Person(source); + } + + public Person[] newArray(int size) { + return new Person[size]; + } + }; +}