├── .codebeatignore ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── _config.yml ├── activitystarter-annotations ├── build.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── activitystarter │ ├── ActivityStarterConfig.java │ ├── ActivityStarterNameConstruction.java │ ├── Arg.java │ ├── MakeActivityStarter.java │ └── wrapping │ └── ArgConverter.java ├── activitystarter-compiler ├── build.gradle ├── gradle.properties └── src │ ├── main │ ├── java │ │ └── activitystarter │ │ │ └── compiler │ │ │ ├── ActivityStarterProcessor.kt │ │ │ ├── error │ │ │ ├── Errors.kt │ │ │ └── PrintErrorFun.kt │ │ │ ├── generation │ │ │ ├── ActivityGeneration.kt │ │ │ ├── BindingHelpers.kt │ │ │ ├── BroadcastReceiverGeneration.kt │ │ │ ├── ClassGeneration.kt │ │ │ ├── ConverterGeneration.kt │ │ │ ├── FragmentGeneration.kt │ │ │ ├── IntentBinding.kt │ │ │ ├── ParcelerGeneration.kt │ │ │ └── ServiceGeneration.kt │ │ │ ├── model │ │ │ ├── ConverterModel.kt │ │ │ ├── ProjectConfig.kt │ │ │ ├── classbinding │ │ │ │ ├── ClassModel.kt │ │ │ │ └── KnownClassType.kt │ │ │ └── param │ │ │ │ ├── ArgumentModel.kt │ │ │ │ ├── FieldAccessType.kt │ │ │ │ ├── FieldAccessor.kt │ │ │ │ └── ParamType.kt │ │ │ ├── processing │ │ │ ├── ArgumentFactory.kt │ │ │ ├── ClassBindingFactory.kt │ │ │ ├── ConverterFaktory.kt │ │ │ └── GetConvertersTypeMirrorsFunc.kt │ │ │ └── utils │ │ │ ├── CamelCaseToUppercaseUnderscoreFun.kt │ │ │ ├── CreateSublistsFun.kt │ │ │ ├── IsSubtypeOfTypeFun.kt │ │ │ └── Utills.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor │ └── test │ └── java │ └── activitystarter │ └── compiler │ ├── BindeingHelpersTest.kt │ ├── CreateSublistsFunKtTest.kt │ ├── ParamTypeFromTypeTest.kt │ ├── generation │ ├── ClassWithGetter.java │ ├── ConverterGenerationTest.kt │ └── GetterArgGenerationTest.kt │ ├── helpers │ ├── AssertionUtills.kt │ ├── ConfigElement.kt │ ├── TypeMirrorsExt.kt │ └── TypeMirrorsTest.kt │ ├── issubtype │ ├── ExampleTypes.kt │ ├── IsSubtypeHelperProcessor.kt │ ├── IsSubtypeOfTest.kt │ └── ParamProcessor.kt │ ├── model │ ├── ConverterModelTest.kt │ └── ProjectConfigConvertersTest.kt │ ├── processing │ └── ConverterFactoryTest.kt │ └── utils │ └── CamelCaseToUppercaseUnderscoreFunKtTest.kt ├── activitystarter-kotlin ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── marcinmoskala │ │ │ └── activitystarter │ │ │ └── ArgExtra.kt │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── marcinmoskala │ └── activitystarter │ └── ConditionsCheckUnitTest.kt ├── activitystarter ├── build.gradle ├── gradle.properties ├── proguard-rules.txt └── src │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── activitystarter │ │ ├── ActivityStarter.java │ │ └── Helpers.java │ └── test │ └── java │ └── activitystarter │ ├── Helpers.kt │ └── generation │ ├── ActivityForResultGenerationTest.kt │ ├── ActivityGenerationTest.kt │ ├── ActivityNonSavableGenerationTest.kt │ ├── ActivityWithConvertersTest.kt │ ├── ByAccessorsTest.kt │ ├── CustomIdGenerationTest.kt │ ├── FragmentGenerationTest.kt │ ├── GenerationErrorTest.kt │ ├── GenerationTest.kt │ ├── ServiceGenerationTest.kt │ └── TypeGenerationTest.kt ├── build.gradle ├── generationExamples ├── activity │ ├── ConflictedOptional │ ├── EmptyAnnotated │ ├── MultipleOptional │ ├── Optional │ ├── SetterGetter │ └── Simple ├── activityForResult │ ├── ConflictedOptional │ ├── EmptyAnnotated │ ├── MultipleOptional │ ├── Optional │ ├── SetterGetter │ └── Simple ├── activityNonSavable │ ├── ConflictedOptional │ ├── EmptyAnnotated │ ├── MultipleOptional │ ├── Optional │ ├── SetterGetter │ └── Simple ├── byAccessor │ ├── GetterSetter │ └── Single ├── customId │ ├── MultipleOptional │ ├── Optional │ └── Simple ├── fragment │ ├── ConflictedOptional │ ├── EmptyAnnotated │ ├── MultipleOptional │ ├── Optional │ ├── SetterGetter │ └── Simple ├── parceler │ └── Simple ├── service │ ├── Complex │ ├── EmptyAnnotated │ └── Simple ├── shouldThrowError │ ├── ActivityPrivateFIeld │ ├── ActivityWithObjectToParcelableWithoutInterfaceConverter │ ├── GetterOnly │ ├── List │ ├── PrivateClass │ ├── ServiceParcelableField │ └── SetterOnly └── withConverters │ └── ActivityWithIntToLongConverter ├── gradle.properties ├── gradle ├── gradle-mvn-push.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── app │ ├── build.gradle │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── activitystarter │ │ │ ├── AllTypesTest.java │ │ │ ├── ClickableExampleTest.java │ │ │ ├── NonSavingTest.java │ │ │ └── SavingTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── activitystarter │ │ │ ├── AllTypesActivity.java │ │ │ ├── BaseActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── SavingTestActivity.java │ │ │ ├── SomeService.java │ │ │ ├── StudentDataActivity.java │ │ │ ├── fragment │ │ │ ├── TabbedFragmentActivity.java │ │ │ └── TabbedPlaceholderFragment.java │ │ │ ├── parcelable │ │ │ ├── StudentParcelable.java │ │ │ └── StudentParcelableActivity.java │ │ │ ├── parceler │ │ │ ├── StudentParceler.java │ │ │ └── StudentParcelerActivity.java │ │ │ ├── savetest │ │ │ ├── NonSavingActivity.java │ │ │ └── SavingActivity.java │ │ │ └── serializable │ │ │ ├── StudentSerializable.java │ │ │ └── StudentSerializableActivity.java │ │ └── res │ │ ├── layout │ │ ├── activity_data.xml │ │ ├── activity_main.xml │ │ ├── activity_save_test.xml │ │ ├── activity_saving_test.xml │ │ ├── activity_tabbed_fragment.xml │ │ └── fragment_tabbed.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml └── kotlinapp │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── marcinmoskala │ │ └── kotlinapp │ │ ├── AllTypesActivityTest.kt │ │ ├── ClickableSampleTest.kt │ │ ├── DataActivityTest.kt │ │ ├── DataRotationTest.kt │ │ ├── FromIntentTest.kt │ │ ├── NonSavingTest.kt │ │ ├── NotificationTest.kt │ │ ├── ParcelableActivityTest.kt │ │ ├── SavingTest.kt │ │ └── SerializableActivityTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── marcinmoskala │ │ │ └── kotlinapp │ │ │ ├── AllTypesActivity.kt │ │ │ ├── BaseActivity.kt │ │ │ ├── ContextExtensions.kt │ │ │ ├── MainActivity.kt │ │ │ ├── StudentDataActivity.kt │ │ │ ├── StudentParcelable.kt │ │ │ ├── StudentParcelableActivity.kt │ │ │ ├── StudentSerializable.kt │ │ │ ├── StudentSerializableActivity.kt │ │ │ ├── fragment │ │ │ ├── TabbedFragmentActivity.kt │ │ │ └── TabbedPlaceholderFragment.kt │ │ │ ├── notification │ │ │ └── NotificationPublisher.kt │ │ │ └── savetest │ │ │ ├── NonSavingActivity.kt │ │ │ └── SavingActivity.kt │ └── res │ │ ├── layout │ │ ├── activity_data.xml │ │ ├── activity_main.xml │ │ ├── activity_save_test.xml │ │ ├── activity_tabbed_fragment.xml │ │ └── fragment_tabbed.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── marcinmoskala │ └── kotlinapp │ └── ExampleUnitTest.java ├── settings.gradle └── testall.sh /.codebeatignore: -------------------------------------------------------------------------------- 1 | sample/** -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | eclipsebin 5 | 6 | bin 7 | gen 8 | out 9 | lib 10 | 11 | .idea 12 | *.iml 13 | classes 14 | 15 | obj 16 | 17 | .DS_Store 18 | 19 | # Gradle 20 | .gradle 21 | jniLibs 22 | build 23 | local.properties 24 | reports 25 | 26 | **/build/** -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | android: 4 | components: 5 | - tools 6 | - platform-tools 7 | - build-tools-27.0.3 8 | - build-tools-25.0.1 9 | - build-tools-25.0.2 10 | - android-28 11 | - android-27 12 | - android-22 13 | - extra-android-m2repository 14 | - sys-img-armeabi-v7a-android-22 15 | 16 | licenses: 17 | - 'android-sdk-license-.+' 18 | - 'android-sdk-preview-.+' 19 | - '.*' 20 | 21 | jdk: 22 | - oraclejdk8 23 | 24 | sudo: true 25 | 26 | before_script: 27 | - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a 28 | - emulator -avd test -no-skin -no-audio -no-window & 29 | - android-wait-for-emulator 30 | - sleep 10 31 | - adb shell input keyevent 82 32 | 33 | env: 34 | matrix: 35 | - TEST=:sample:app:connectedDebugAndroidTest 36 | - TEST=:activitystarter:test 37 | - TEST=:activitystarter-compiler:test 38 | 39 | script: 40 | - ./gradlew $TEST -i 41 | 42 | notifications: 43 | email: true 44 | 45 | cache: 46 | directories: 47 | - $HOME/.m2 48 | - $HOME/.gradle -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 0.5 *(2017-04-05)* 5 | ---------------------------- 6 | 7 | Add startForResult functionality for Activity. 8 | 9 | Now on @MakeActivityStarter there is a field includeStartForResult used to make Activities generate startForResult and startWithFlagsForResult mothods. Example: 10 | 11 | ``` 12 | @MakeActivityStarter(includeStartForResult = true) 13 | public class MainActivity extends Activity {} 14 | ``` 15 | 16 | we can start using: 17 | 18 | ``` 19 | MainActivityStarter.startForResult(activity, code) 20 | ``` 21 | 22 | Version 0.4 *(2017-04-01)* 23 | ---------------------------- 24 | 25 | App is much more tested. There is no more static field in ActivityStarter. Add support to all types. All supported types: 26 | * Subtype of Parcelable 27 | * Subtype of Serializable 28 | * ArrayList intL 29 | * ArrayList strLi 30 | * ArrayList 31 | * String 32 | * int 33 | * long 34 | * float 35 | * boolean bo 36 | * double 37 | * char 38 | * byte 39 | * short 40 | * CharSequence 41 | * String[] 42 | * int[] 43 | * long[] 44 | * float[] 45 | * boolean[] 46 | * double[] 47 | * char[] 48 | * byte[] 49 | * short[] 50 | * CharSequence[] 51 | 52 | Version 0.3 *(2017-02-25)* 53 | ---------------------------- 54 | 55 | Now custom keys are allowed. Example: 56 | 57 | ``` kotlin 58 | public class MainActivity extends Activity { 59 | @Arg(key = "SOME_KEY") String name; 60 | } 61 | ``` 62 | 63 | Also default keys were changed to include file package. Tests were improved. 64 | 65 | Version 0.2 *(2017-02-15)* 66 | ---------------------------- 67 | 68 | Release provided Activity support for saving state, annotation to omit that and better support for fields accesses by setter and getter. 69 | 70 | Version 0.1 *(2017-02-08)* 71 | ---------------------------- 72 | 73 | Library is well-tested and stable. Checked also on real-life big project. Library contain support to: 74 | * Activities 75 | * Fragments (+v4) 76 | * Services 77 | * BroadcastReceivers 78 | * Also fully functional in Kotlin (used in big project). 79 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Feel free to contribute or suggest changes and/or improvements. 2 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-tactile -------------------------------------------------------------------------------- /activitystarter-annotations/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | google() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 9 | } 10 | } 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'com.github.dcendents.android-maven' 14 | 15 | group = 'com.marcinmoskala' 16 | 17 | def logger = new com.android.build.gradle.internal.LoggerWrapper(project.logger) 18 | def sdkHandler = new com.android.build.gradle.internal.SdkHandler(project, logger) 19 | for (File file : sdkHandler.sdkLoader.repositories) { 20 | repositories.maven { 21 | url = file.toURI() 22 | } 23 | } 24 | 25 | sourceCompatibility = rootProject.ext.sourceCompatibilityVersion 26 | targetCompatibility = rootProject.ext.targetCompatibilityVersion 27 | 28 | dependencies { 29 | compileOnly deps.android 30 | implementation deps.supportAnnotations 31 | } 32 | 33 | task sourcesJar(type: Jar, dependsOn: classes) { 34 | classifier = 'sources' 35 | from sourceSets.main.allSource 36 | } 37 | 38 | artifacts { 39 | archives sourcesJar 40 | } 41 | 42 | install { 43 | repositories.mavenInstaller { 44 | pom.project { 45 | licenses { 46 | license { 47 | name 'The Apache Software License, Version 2.0' 48 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 49 | distribution 'repo' 50 | } 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /activitystarter-annotations/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=SuperActivity Annotations 2 | POM_ARTIFACT_ID=superactivity-annotations 3 | POM_PACKAGING=jar 4 | -------------------------------------------------------------------------------- /activitystarter-annotations/src/main/java/activitystarter/ActivityStarterConfig.java: -------------------------------------------------------------------------------- 1 | package activitystarter; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import activitystarter.wrapping.ArgConverter; 7 | 8 | import static java.lang.annotation.ElementType.TYPE; 9 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 10 | 11 | @Retention(RUNTIME) @Target(TYPE) 12 | public @interface ActivityStarterConfig { 13 | 14 | Class>[] converters() default {}; 15 | } 16 | -------------------------------------------------------------------------------- /activitystarter-annotations/src/main/java/activitystarter/ActivityStarterNameConstruction.java: -------------------------------------------------------------------------------- 1 | package activitystarter; 2 | 3 | public class ActivityStarterNameConstruction { 4 | 5 | public static String getterFieldAccessorName(String fieldName) { 6 | String capitalizedName = capitalize(fieldName); 7 | return "getValueOf" + capitalizedName + "From"; 8 | } 9 | 10 | public static String getterFieldCheckerName(String fieldName) { 11 | String capitalizedName = capitalize(fieldName); 12 | return "isFilledValueOf" + capitalizedName + "From"; 13 | } 14 | 15 | private static String capitalize(String name) { 16 | if(name != null && name.length() != 0) { 17 | char[] chars = name.toCharArray(); 18 | chars[0] = Character.toUpperCase(chars[0]); 19 | return new String(chars); 20 | } else { 21 | return name; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /activitystarter-annotations/src/main/java/activitystarter/Arg.java: -------------------------------------------------------------------------------- 1 | package activitystarter; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.FIELD; 7 | import static java.lang.annotation.ElementType.METHOD; 8 | import static java.lang.annotation.RetentionPolicy.CLASS; 9 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 10 | 11 | @Retention(RUNTIME) 12 | @Target({FIELD, METHOD}) 13 | public @interface Arg { 14 | String key() default ""; 15 | 16 | boolean optional() default false; 17 | 18 | boolean parceler() default false; 19 | } -------------------------------------------------------------------------------- /activitystarter-annotations/src/main/java/activitystarter/MakeActivityStarter.java: -------------------------------------------------------------------------------- 1 | package activitystarter; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.TYPE; 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | @Retention(RUNTIME) @Target(TYPE) 10 | public @interface MakeActivityStarter { 11 | 12 | // This flag should be used only for Activities 13 | boolean includeStartForResult() default false; 14 | 15 | boolean savable() default true; 16 | } 17 | -------------------------------------------------------------------------------- /activitystarter-annotations/src/main/java/activitystarter/wrapping/ArgConverter.java: -------------------------------------------------------------------------------- 1 | package activitystarter.wrapping; 2 | 3 | public interface ArgConverter { 4 | 5 | public R wrap(T toWrap); 6 | 7 | public T unwrap(R wrapped); 8 | } 9 | -------------------------------------------------------------------------------- /activitystarter-compiler/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=SuperActivity Compiler 2 | POM_ARTIFACT_ID=superactivity-compiler 3 | POM_PACKAGING=jar 4 | -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/error/Errors.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.error 2 | 3 | import activitystarter.compiler.model.param.ParamType 4 | 5 | object Errors { 6 | val notAClass = "fields may only be contained in classes." 7 | val privateClass = "fields may not be contained in private classes." 8 | val notSupportedType: String = "Type {Type} of {Field} is not supported. Supported types are: ${ParamType.supportedTypes}." 9 | val inaccessibleField: String = "Inaccessable element." 10 | val notBasicTypeInReceiver: String = "On BroadcastReceiver only basic types are supported." 11 | val wrongClassType: String = "Is in wroing typeName. It needs to be Activity, Froagment, Service or BroadcastReceiver." 12 | val noGetter: String = "Trying to set Inaccessible field" 13 | val moreThenOneConfig: String = "There cannot be more then one ActivityStarter config (Annotation @ActivityStarterConfig)" 14 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/error/PrintErrorFun.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.error 2 | 3 | import javax.annotation.processing.Messager 4 | import javax.lang.model.element.Element 5 | import javax.lang.model.element.TypeElement 6 | import javax.tools.Diagnostic.Kind.ERROR 7 | 8 | var messanger: Messager? = null 9 | 10 | inline fun parsingError(text: String, element: Element, enclosingElement: TypeElement) { 11 | error(enclosingElement, "@%s %s $text (%s)", T::class.java.simpleName, enclosingElement.qualifiedName, element.simpleName) 12 | } 13 | 14 | fun error(element: Element, message: String, vararg args: Any) { 15 | messanger!!.printMessage(ERROR, if (args.isNotEmpty()) String.format(message, *args) else message, element) 16 | } 17 | 18 | fun error(message: String, vararg args: Any) { 19 | messanger!!.printMessage(ERROR, if (args.isNotEmpty()) String.format(message, *args) else message) 20 | } 21 | -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/generation/BroadcastReceiverGeneration.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.generation 2 | 3 | import activitystarter.compiler.model.classbinding.ClassModel 4 | import activitystarter.compiler.model.param.ArgumentModel 5 | import com.squareup.javapoet.MethodSpec 6 | 7 | internal class BroadcastReceiverGeneration(classModel: ClassModel) : IntentBinding(classModel) { 8 | 9 | override fun createFillFieldsMethod() = fillByIntentBinding("receiver") 10 | 11 | override fun createStarters(variant: List): List = listOf( 12 | createGetIntentMethod(variant) 13 | ) 14 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/generation/ConverterGeneration.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.generation 2 | 3 | import activitystarter.compiler.model.ConverterModel 4 | 5 | class ConverterGeneration(val converter: ConverterModel) { 6 | 7 | fun wrap( f: ()->String): String { 8 | return "new ${converter.className}().wrap(${f()})" 9 | } 10 | 11 | fun unwrap( f: ()->String): String { 12 | return "new ${converter.className}().unwrap(${f()})" 13 | } 14 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/generation/ParcelerGeneration.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.generation 2 | 3 | class ParcelerGeneration() { 4 | 5 | fun wrap(f: () -> String): String { 6 | return "org.parceler.Parcels.wrap(${f()})" 7 | } 8 | 9 | fun unwrap(f: () -> String): String { 10 | return "org.parceler.Parcels.unwrap(${f()})" 11 | } 12 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/generation/ServiceGeneration.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.generation 2 | 3 | import activitystarter.compiler.model.classbinding.ClassModel 4 | import activitystarter.compiler.model.param.ArgumentModel 5 | import com.squareup.javapoet.MethodSpec 6 | 7 | internal class ServiceGeneration(classModel: ClassModel) : IntentBinding(classModel) { 8 | 9 | override fun createFillFieldsMethod(): MethodSpec = fillByIntentBinding("service") 10 | 11 | override fun createStarters(variant: List): List = listOf( 12 | createGetIntentMethod(variant), 13 | createStartServiceMethod(variant) 14 | ) 15 | 16 | private fun createStartServiceMethod(variant: List) = 17 | createGetIntentStarter("startService", variant) 18 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/model/ConverterModel.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model 2 | 3 | import activitystarter.compiler.model.param.ParamType 4 | import activitystarter.compiler.utils.isSubtypeOfType 5 | import javax.lang.model.type.TypeMirror 6 | 7 | 8 | data class ConverterModel( 9 | val className: String, 10 | val typeFrom: TypeMirror, 11 | val typeTo: TypeMirror 12 | ) { 13 | val toParamType: ParamType? 14 | get() = ParamType.fromType(typeTo) 15 | 16 | val fromParamType: ParamType? 17 | get() = ParamType.fromType(typeFrom) 18 | 19 | fun canWrap(type: TypeMirror): Boolean { 20 | val paramType = ParamType.fromType(type) 21 | return paramType == fromParamType && 22 | if(paramType.typeUsedBySupertype()) type.isSubtypeOfType(typeFrom.toString()) else true 23 | } 24 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/model/ProjectConfig.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model 2 | 3 | import javax.lang.model.type.TypeMirror 4 | 5 | data class ProjectConfig(val converters: List = listOf()) { 6 | 7 | fun converterFor(type: TypeMirror): ConverterModel? { 8 | return converters.firstOrNull { it.canWrap(type) } 9 | } 10 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/model/classbinding/ClassModel.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model.classbinding 2 | 3 | import activitystarter.compiler.generation.* 4 | import activitystarter.compiler.model.classbinding.KnownClassType.* 5 | import activitystarter.compiler.model.param.ArgumentModel 6 | import activitystarter.compiler.utils.createSublists 7 | import com.squareup.javapoet.ClassName 8 | import com.squareup.javapoet.TypeName 9 | 10 | class ClassModel( 11 | private val knownClassType: KnownClassType, 12 | val targetTypeName: TypeName, 13 | val bindingClassName: ClassName, 14 | val packageName: String, 15 | val argumentModels: List, 16 | val savable: Boolean, 17 | val includeStartForResult: Boolean 18 | ) { 19 | 20 | val argumentModelVariants: List> 21 | get() = argumentModels 22 | .createSublists { it.isOptional } 23 | .distinctBy { it.map { it.typeName } } 24 | 25 | internal fun getClasGeneration(): ClassGeneration = when (knownClassType) { 26 | Activity -> ActivityGeneration(this) 27 | Fragment -> FragmentGeneration(this) 28 | Service -> ServiceGeneration(this) 29 | BroadcastReceiver -> BroadcastReceiverGeneration(this) 30 | } 31 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/model/classbinding/KnownClassType.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model.classbinding 2 | 3 | import activitystarter.compiler.utils.isSubtypeOfType 4 | import javax.lang.model.type.TypeMirror 5 | 6 | enum class KnownClassType(vararg val typeString: String) { 7 | Activity(ACTIVITY_TYPE), 8 | Fragment(FRAGMENT_TYPE, FRAGMENTv4_TYPE), 9 | Service(SERVICE_TYPE), 10 | BroadcastReceiver(BROADCAST_RECEIVER_TYPE); 11 | 12 | companion object { 13 | fun getByType(elementType: TypeMirror): KnownClassType? = values() 14 | .first { elementType.isSubtypeOfType(*it.typeString) } 15 | } 16 | } 17 | 18 | private const val ACTIVITY_TYPE = "android.app.Activity" 19 | private const val FRAGMENT_TYPE = "android.app.Fragment" 20 | private const val FRAGMENTv4_TYPE = "android.support.v4.app.Fragment" 21 | private const val SERVICE_TYPE = "android.app.Service" 22 | private const val BROADCAST_RECEIVER_TYPE = "android.content.BroadcastReceiver" 23 | private const val SERIALIZABLE_TYPE = "java.io.Serializable" 24 | private const val PARCELABLE_TYPE = "android.os.Parcelable" -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/model/param/ArgumentModel.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model.param 2 | 3 | import activitystarter.ActivityStarterNameConstruction 4 | import activitystarter.compiler.generation.ConverterGeneration 5 | import activitystarter.compiler.generation.ParcelerGeneration 6 | import activitystarter.compiler.model.ConverterModel 7 | import activitystarter.compiler.utils.camelCaseToUppercaseUnderscore 8 | import com.squareup.javapoet.TypeName 9 | 10 | class ArgumentModel( 11 | val name: String, 12 | val key: String, 13 | val paramType: ParamType, 14 | val typeName: TypeName, 15 | val saveParamType: ParamType, 16 | val isOptional: Boolean, 17 | val accessor: FieldAccessor, 18 | private val converter: ConverterModel?, 19 | val parceler: Boolean 20 | ) { 21 | val keyFieldName: String by lazy { camelCaseToUppercaseUnderscore(name) + "_KEY" } 22 | val accessorName = ActivityStarterNameConstruction.getterFieldAccessorName(name) 23 | val checkerName = ActivityStarterNameConstruction.getterFieldCheckerName(name) 24 | 25 | fun addUnwrapper(body: () -> String) = when { 26 | parceler -> ParcelerGeneration().unwrap(body) 27 | converter != null -> ConverterGeneration(converter).unwrap(body) 28 | else -> body() 29 | } 30 | 31 | fun addWrapper(body: () -> String) = when { 32 | parceler -> ParcelerGeneration().wrap(body) 33 | converter != null -> ConverterGeneration(converter).wrap(body) 34 | else -> body() 35 | } 36 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/model/param/FieldAccessType.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model.param 2 | 3 | enum class FieldAccessType { 4 | Accessible, 5 | ByMethod, 6 | ByNoIsMethod, 7 | Inaccessible 8 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/processing/ClassBindingFactory.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.processing 2 | 3 | import activitystarter.Arg 4 | import activitystarter.MakeActivityStarter 5 | import activitystarter.compiler.error.Errors 6 | import activitystarter.compiler.error.parsingError 7 | import activitystarter.compiler.model.ProjectConfig 8 | import activitystarter.compiler.model.classbinding.ClassModel 9 | import activitystarter.compiler.model.classbinding.KnownClassType 10 | import activitystarter.compiler.model.classbinding.KnownClassType.Companion.getByType 11 | import activitystarter.compiler.model.param.ArgumentModel 12 | import activitystarter.compiler.utils.getElementType 13 | import com.squareup.javapoet.ParameterizedTypeName 14 | import com.squareup.javapoet.TypeName 15 | import javax.lang.model.element.Element 16 | import javax.lang.model.element.TypeElement 17 | 18 | internal class ClassBindingFactory(val typeElement: TypeElement, val config: ProjectConfig) { 19 | 20 | fun create(): ClassModel? { 21 | val knownClassType: KnownClassType = getKnownClassType() ?: return null 22 | val targetTypeName = getTargetTypeName(typeElement) 23 | val bindingClassName = activitystarter.compiler.generation.getBindingClassName(typeElement) 24 | val packageName = bindingClassName.packageName() 25 | val argumentFactory = ArgumentFactory(typeElement, config) 26 | val enclosedElements = typeElement.enclosedElements 27 | val argumentBindings = getArgumentBindings(enclosedElements, argumentFactory, packageName, knownClassType) 28 | val makeActivityStarterAnnotation = typeElement.getAnnotation(MakeActivityStarter::class.java) 29 | val savable = makeActivityStarterAnnotation?.savable ?: true 30 | val addStartForResult = makeActivityStarterAnnotation?.includeStartForResult ?: false 31 | return ClassModel(knownClassType, targetTypeName, bindingClassName, packageName, argumentBindings, savable, addStartForResult) 32 | } 33 | 34 | private fun getKnownClassType(): KnownClassType? { 35 | val knownClassType: KnownClassType? = getByType(getElementType(typeElement)) 36 | val error = getClassError(knownClassType) 37 | if (error != null) { 38 | parsingError(error, typeElement, typeElement) 39 | return null 40 | } 41 | return knownClassType 42 | } 43 | 44 | private fun getArgumentBindings(enclosedElements: List, argumentFactory: ArgumentFactory, packageName: String, knownClassType: KnownClassType): List = 45 | enclosedElements 46 | .filter { it.getAnnotation(Arg::class.java) != null } 47 | .map { argumentFactory.create(it, packageName, knownClassType) } 48 | .filterNotNull() 49 | 50 | private fun getClassError(elementType: KnownClassType?) = when { 51 | elementType == null -> Errors.wrongClassType 52 | else -> null 53 | } 54 | 55 | private fun getTargetTypeName(enclosingElement: TypeElement) = TypeName 56 | .get(enclosingElement.asType()) 57 | .let { if (it is ParameterizedTypeName) it.rawType else it } 58 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/processing/ConverterFaktory.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.processing 2 | 3 | import activitystarter.compiler.model.ConverterModel 4 | import activitystarter.compiler.utils.toTypeElement 5 | import javax.lang.model.type.DeclaredType 6 | import javax.lang.model.type.TypeMirror 7 | 8 | 9 | class ConverterFaktory { 10 | 11 | fun create(converters: List): List = converters.mapNotNull { c -> 12 | val typeElement = c.toTypeElement() ?: return@mapNotNull null 13 | val declaredParentInterface = typeElement.interfaces?.get(0) as? DeclaredType 14 | val genericTypes = declaredParentInterface?.typeArguments ?: return@mapNotNull null 15 | val fromClass = genericTypes[0]!! 16 | val toClass = genericTypes[1]!! 17 | ConverterModel(c.toString(), fromClass, toClass) 18 | } 19 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/processing/GetConvertersTypeMirrorsFunc.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.processing 2 | 3 | import activitystarter.ActivityStarterConfig 4 | import javax.lang.model.element.AnnotationValue 5 | import javax.lang.model.element.Element 6 | import javax.lang.model.type.TypeMirror 7 | 8 | fun getConvertersTypeMirrors(element: Element): List { 9 | val convertersValue: AnnotationValue = element.annotationMirrors 10 | .filter { it.annotationType.toString() == ActivityStarterConfig::class.java.name } 11 | .flatMap { it.elementValues.toList() } 12 | .firstOrNull { (k, _) -> k.simpleName.toString() == "converters" }?.second ?: return emptyList() 13 | val valueList = convertersValue.value as List 14 | return valueList.map { it.value as TypeMirror } 15 | } 16 | -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/utils/CamelCaseToUppercaseUnderscoreFun.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.utils 2 | 3 | fun camelCaseToUppercaseUnderscore(str: String): String = str 4 | .replace("([A-Z])".toRegex(), "_\$1") 5 | .toUpperCase() 6 | .deleteIfFirst('_') 7 | 8 | private fun String.deleteIfFirst(c: Char): String = if(!isEmpty() && get(0) == c) drop(1) else this 9 | -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/utils/CreateSublistsFun.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.utils 2 | 3 | fun List.createSublists(isSplitter: (T) -> Boolean): List> = when { 4 | size == 0 -> listOf(listOf()) 5 | none { isSplitter(it) } -> listOf(this) 6 | size == 1 -> listOf(this, listOf()) 7 | isSplitter(last()) -> sublistFromRest(isSplitter) 8 | .flatMap { listOf(it + last(), it) } 9 | else -> sublistFromRest(isSplitter) 10 | .map { it + last() } 11 | } 12 | 13 | private fun List.sublistFromRest(isSplitter: (T) -> Boolean) = dropLast(1).createSublists(isSplitter) -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/utils/IsSubtypeOfTypeFun.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.utils 2 | 3 | import javax.lang.model.element.TypeElement 4 | import javax.lang.model.type.DeclaredType 5 | import javax.lang.model.type.TypeKind 6 | import javax.lang.model.type.TypeMirror 7 | 8 | fun TypeMirror.isSubtypeOfType(vararg otherType: String): Boolean { 9 | val typeString = this.toString() 10 | val kind = kind 11 | return when { 12 | otherType.any { it.substringBefore("<") == typeString } -> true 13 | kind != TypeKind.DECLARED -> false 14 | else -> { 15 | val element = this.toTypeElement() ?: return false 16 | element.superclass.isSubtypeOfType(*otherType) || element.interfaces.any { it.isSubtypeOfType(*otherType) } 17 | } 18 | } 19 | } 20 | 21 | fun TypeMirror.toTypeElement() = (this as? DeclaredType)?.asElement() as? TypeElement -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/java/activitystarter/compiler/utils/Utills.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.utils 2 | 3 | import com.squareup.javapoet.ClassName 4 | import com.squareup.javapoet.MethodSpec 5 | import com.squareup.javapoet.TypeSpec 6 | import javax.lang.model.element.Element 7 | import javax.lang.model.type.TypeKind 8 | import javax.lang.model.type.TypeMirror 9 | import javax.lang.model.type.TypeVariable 10 | 11 | val INTENT = ClassName.get("android.content", "Intent") 12 | val BUNDLE = ClassName.get("android.os", "Bundle") 13 | val CONTEXT = ClassName.get("android.content", "Context") 14 | val ACTIVITY = ClassName.get("android.app", "Activity") 15 | val STRING = ClassName.get("java.lang", "String") 16 | 17 | fun getElementType(element: Element): TypeMirror = element.asType() 18 | .let { if (it.kind == TypeKind.TYPEVAR) (it as TypeVariable).upperBound else it } 19 | 20 | inline fun MethodSpec.Builder.doIf(check: Boolean, f: MethodSpec.Builder.() -> Unit) = apply { 21 | if (check) f() 22 | } 23 | 24 | inline fun TypeSpec.Builder.doIf(check: Boolean, f: TypeSpec.Builder.() -> Unit) = apply { 25 | if (check) f() 26 | } 27 | 28 | fun List.addIf(condition: Boolean, vararg e: T): List { 29 | return if(condition) this + listOf(*e) else this 30 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | activitystarter.compiler.ActivityStarterProcessor -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/BindeingHelpersTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler 2 | 3 | import activitystarter.compiler.generation.getPutArgumentToIntentMethodName 4 | import activitystarter.compiler.model.param.ParamType 5 | import org.junit.Assert 6 | import org.junit.Assert.assertEquals 7 | import org.junit.Test 8 | 9 | class BindeingHelpersTest { 10 | 11 | @Test 12 | fun `For simple types Intent put is putExtra`() { 13 | val exampleSimpleTypes = listOf(ParamType.Boolean, ParamType.BooleanArray, ParamType.Byte, ParamType.ByteArray, ParamType.Double, ParamType.Short) 14 | for(simpleType in exampleSimpleTypes) { 15 | assertEquals("putExtra", getPutArgumentToIntentMethodName(simpleType)) 16 | } 17 | } 18 | 19 | @Test 20 | fun `For ArrayList type Intent put is specific`() { 21 | val arrayTypeToPutFunctionMap = mapOf( 22 | ParamType.IntegerArrayList to "putIntegerArrayListExtra", 23 | ParamType.CharSequenceArrayList to "putCharSequenceArrayListExtra", 24 | ParamType.ParcelableArrayListSubtype to "putParcelableArrayListExtra", 25 | ParamType.StringArrayList to "putStringArrayListExtra" 26 | ) 27 | for((type, functionName) in arrayTypeToPutFunctionMap) { 28 | assertEquals(functionName, getPutArgumentToIntentMethodName(type)) 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/CreateSublistsFunKtTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler 2 | 3 | import activitystarter.compiler.utils.createSublists 4 | import org.junit.Assert.assertEquals 5 | import org.junit.Test 6 | 7 | class CreateSublistsFunKtTest { 8 | 9 | @Test 10 | fun testEmptyCreateSublists() { 11 | assertEquals(listOf(listOf()), listOf().createSublists { it % 2 == 0 }) 12 | } 13 | 14 | @Test 15 | fun testOrderCreateSublists() { 16 | assertEquals(listOf(listOf(1,2),listOf(1),listOf(2), listOf()), listOf(1,2).createSublists { true }) 17 | } 18 | 19 | @Test 20 | fun testCreateSublists() { 21 | assertEquals(setOf(listOf(1, 2, 3), listOf(1, 3)), listOf(1, 2, 3).createSublists { it % 2 == 0 }.toSet()) 22 | assertEquals(setOf(listOf(1, 2, 3, 4), listOf(1, 2, 3), listOf(1, 3, 4), listOf(1, 3)), listOf(1, 2, 3, 4).createSublists { it % 2 == 0 }.toSet()) 23 | } 24 | 25 | @Test 26 | fun testCreateBigSublists() { 27 | // 10 splitters, so 2^10 = 1024 lists 28 | assert((1..20).toList().createSublists { it % 2 == 0 }.size == 1024) 29 | assert((1..40).toList().createSublists { it % 4 == 0 }.size == 1024) 30 | } 31 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/generation/ClassWithGetter.java: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.generation; 2 | 3 | public class ClassWithGetter { 4 | 5 | String getName() { 6 | return "Ala"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/generation/ConverterGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.generation 2 | 3 | import activitystarter.compiler.helpers.ConfigElement 4 | import activitystarter.compiler.processing.ConverterFaktory 5 | import org.junit.Test 6 | import kotlin.test.assertEquals 7 | 8 | class ConverterGenerationTest { 9 | 10 | val integerToLongConverter by lazy { ConverterFaktory().create(ConfigElement.integerToLongConverter)[0] } 11 | val integerToLongConverterGeneration by lazy { ConverterGeneration(integerToLongConverter) } 12 | 13 | val objectToParcelableConverter by lazy { ConverterFaktory().create(ConfigElement.objectToParcelableConverter)[0] } 14 | val objectToParcelableConverterGeneration by lazy { ConverterGeneration(objectToParcelableConverter) } 15 | 16 | @Test 17 | fun `Basic wrapping is just creating converter by empty constructor and invoking wrap method`() { 18 | assertEquals( 19 | "new com.example.activitystarter.MainActivity.ParcelableConverter().wrap(A)", 20 | objectToParcelableConverterGeneration.wrap { "A" } 21 | ) 22 | } 23 | 24 | @Test 25 | fun `Basic unwrapping is just creating converter by empty constructor and invoking unwrap method`() { 26 | assertEquals( 27 | "new com.example.activitystarter.MainActivity.ParcelableConverter().unwrap(A)", 28 | objectToParcelableConverterGeneration.unwrap { "A" } 29 | ) 30 | } 31 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/generation/GetterArgGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.generation 2 | 3 | import activitystarter.compiler.helpers.ConfigElement 4 | import activitystarter.compiler.helpers.getElement 5 | import activitystarter.compiler.processing.ConverterFaktory 6 | import com.google.testing.compile.CompilationRule 7 | import org.junit.Rule 8 | import org.junit.Test 9 | import kotlin.test.assertEquals 10 | 11 | class GetterArgGenerationTest { 12 | 13 | @Rule @JvmField val c = CompilationRule() 14 | 15 | @Test 16 | fun `Getting getter returned type`() { 17 | val elements = c.elements.getTypeElement(ClassWithGetter::class.java.canonicalName).enclosedElements.filter { it.simpleName.startsWith("get") } 18 | assertEquals(1, elements.size) 19 | } 20 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/helpers/AssertionUtills.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.helpers 2 | 3 | fun assertContains(what: String, where: String) { 4 | assert(what in where) { "$what not found in $where" } 5 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/issubtype/ExampleTypes.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.issubtype 2 | 3 | abstract class A() 4 | interface B 5 | abstract class C() 6 | 7 | open class D(): A(), B 8 | interface E: B 9 | 10 | class F: E, D() 11 | class G: C(), E -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/issubtype/IsSubtypeHelperProcessor.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.issubtype 2 | 3 | import activitystarter.compiler.error.error 4 | import activitystarter.compiler.utils.getElementType 5 | import activitystarter.compiler.utils.isSubtypeOfType 6 | import com.google.auto.service.AutoService 7 | import javax.annotation.processing.Processor 8 | import javax.lang.model.element.Element 9 | 10 | @AutoService(Processor::class) 11 | class IsSubtypeHelperProcessor(val ofWhat: String) : ParamProcessor() { 12 | 13 | override fun onParamFound(element: Element) { 14 | try { 15 | val isSubtype = getElementType(element).isSubtypeOfType(ofWhat) 16 | if(!isSubtype) error(element, notSubtypeError) 17 | } catch (e: Exception) { 18 | e.printStackTrace() 19 | error(element, otherError) 20 | } 21 | } 22 | 23 | companion object { 24 | val notSubtypeError = "Not a subtype" 25 | val otherError = "Error" 26 | } 27 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/issubtype/IsSubtypeOfTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.issubtype 2 | 3 | import org.junit.Test 4 | 5 | class IsSubtypeOfTest { 6 | 7 | @Test 8 | fun subtypesTest() { 9 | assertIsSubtypeOf() 10 | assertIsSubtypeOf() 11 | } 12 | 13 | @Test 14 | fun interfaceTest() { 15 | assertIsSubtypeOf() 16 | assertIsSubtypeOf() 17 | assertIsSubtypeOf() 18 | assertIsSubtypeOf() 19 | assertIsSubtypeOf() 20 | } 21 | 22 | @Test 23 | fun itselfTest() { 24 | assertIsSubtypeOf() 25 | assertIsSubtypeOf() 26 | assertIsSubtypeOf() 27 | assertIsSubtypeOf() 28 | assertIsSubtypeOf() 29 | assertIsSubtypeOf() 30 | assertIsSubtypeOf() 31 | } 32 | 33 | @Test 34 | fun notASubtypeReversedInheritenceTest() { 35 | assertIsNotSubtypeOf() 36 | assertIsNotSubtypeOf() 37 | assertIsNotSubtypeOf() 38 | assertIsNotSubtypeOf() 39 | assertIsNotSubtypeOf() 40 | } 41 | 42 | @Test 43 | fun notASubtypeNotConnectedTest() { 44 | assertIsNotSubtypeOf() 45 | assertIsNotSubtypeOf() 46 | assertIsNotSubtypeOf() 47 | assertIsNotSubtypeOf() 48 | } 49 | 50 | inline fun assertIsSubtypeOf() { 51 | ParamProcessor.compile( 52 | paramTypeName = A::class.java.simpleName, 53 | paramTypeImport = "activitystarter.compiler.issubtype.*", 54 | processor = IsSubtypeHelperProcessor(B::class.java.canonicalName)) 55 | } 56 | 57 | inline fun assertIsNotSubtypeOf() { 58 | ParamProcessor.compileAndExpectError( 59 | paramTypeName = A::class.java.simpleName, 60 | paramTypeImport = "activitystarter.compiler.issubtype.*", 61 | processor = IsSubtypeHelperProcessor(B::class.java.canonicalName), 62 | errorContaining = IsSubtypeHelperProcessor.notSubtypeError 63 | ) 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/model/ConverterModelTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model 2 | 3 | import activitystarter.compiler.helpers.* 4 | import activitystarter.compiler.model.param.ParamType 5 | import activitystarter.compiler.processing.ConverterFaktory 6 | import com.google.testing.compile.CompilationRule 7 | import org.junit.Rule 8 | import org.junit.Test 9 | import kotlin.test.assertEquals 10 | import kotlin.test.assertFalse 11 | import kotlin.test.assertTrue 12 | 13 | class ConverterModelTest() { 14 | 15 | @Rule @JvmField val c = CompilationRule() 16 | 17 | val factory by lazy { ConverterFaktory() } 18 | val integerToLongConverter by lazy { factory.create(ConfigElement.integerToLongConverter)[0] } 19 | val objectToParcelableConverter by lazy { factory.create(ConfigElement.objectToParcelableConverter)[0] } 20 | 21 | @Test 22 | fun `To ParamType is correct`() { 23 | assertEquals(ParamType.Long, integerToLongConverter.toParamType) 24 | assertEquals(ParamType.ParcelableSubtype, objectToParcelableConverter.toParamType) 25 | } 26 | 27 | @Test 28 | fun `ConverterGeneration can weap simple correct types`() { 29 | assertTrue(integerToLongConverter.canWrap(c.intTypeMirror)) 30 | assertFalse(integerToLongConverter.canWrap(c.longTypeMirror)) 31 | assertFalse(integerToLongConverter.canWrap(c.objectFTypeMirror)) 32 | assertFalse(integerToLongConverter.canWrap(c.subtypeOfParcelableTypeMirror)) 33 | assertFalse(objectToParcelableConverter.canWrap(c.intTypeMirror)) 34 | assertFalse(objectToParcelableConverter.canWrap(c.longTypeMirror)) 35 | assertTrue(objectToParcelableConverter.canWrap(c.objectFTypeMirror)) 36 | assertFalse(objectToParcelableConverter.canWrap(c.parcelableSubtypeArrayListTypeMirror)) 37 | } 38 | 39 | @Test 40 | fun `Then convertet include interface then only classes that are implementing it can be wrapped`() { 41 | assertTrue(ConverterModel("SomeName", c.interfaceETypeMirror, c.intTypeMirror).canWrap(c.objectFTypeMirror)) 42 | assertTrue(ConverterModel("SomeName", c.interfaceBTypeMirror, c.intTypeMirror).canWrap(c.objectFTypeMirror)) 43 | assertTrue(ConverterModel("SomeName", c.interfaceBTypeMirror, c.intTypeMirror).canWrap(c.interfaceETypeMirror)) 44 | assertTrue(ConverterModel("SomeName", c.objectFTypeMirror, c.intTypeMirror).canWrap(c.objectFTypeMirror)) 45 | assertFalse(ConverterModel("SomeName", c.interfaceETypeMirror, c.intTypeMirror).canWrap(c.interfaceBTypeMirror)) 46 | } 47 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/model/ProjectConfigConvertersTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.model 2 | 3 | import activitystarter.compiler.helpers.* 4 | import activitystarter.compiler.processing.ConverterFaktory 5 | import com.google.testing.compile.CompilationRule 6 | import org.junit.Rule 7 | import org.junit.Test 8 | import kotlin.test.assertEquals 9 | import kotlin.test.assertNull 10 | 11 | class ProjectConfigConvertersTest() { 12 | 13 | @Rule @JvmField val c = CompilationRule() 14 | 15 | val factory by lazy { ConverterFaktory() } 16 | 17 | @Test 18 | fun `There is correct converter applied for simple examples`() { 19 | val model = ProjectConfig( 20 | converters = factory.create(ConfigElement.multipleConverter) 21 | ) 22 | assertNull(model.converterFor(c.boolTypeMirror)) 23 | assertNull(model.converterFor(c.longTypeMirror)) 24 | assertNull(model.converterFor(c.floatTypeMirror)) 25 | assertEquals( 26 | "com.example.activitystarter.MainActivity.IntToLongConverter", 27 | model.converterFor(c.intTypeMirror)?.className 28 | ) 29 | assertEquals( 30 | "com.example.activitystarter.MainActivity.ParcelableConverter", 31 | model.converterFor(c.objectFTypeMirror)?.className 32 | ) 33 | } 34 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/processing/ConverterFactoryTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.processing 2 | 3 | import activitystarter.compiler.helpers.ConfigElement 4 | import org.junit.Test 5 | import kotlin.test.assertEquals 6 | 7 | class ConverterFactoryTest() { 8 | 9 | val factory by lazy { ConverterFaktory() } 10 | val emptyConverters by lazy { factory.create(ConfigElement.empty) } 11 | val singleConverters by lazy { factory.create(ConfigElement.integerToLongConverter) } 12 | 13 | @Test 14 | fun `Converter list size is correct`() { 15 | val empty = ConfigElement.empty 16 | val singleConverter = ConfigElement.integerToLongConverter 17 | assertEquals(0, emptyConverters.size) 18 | assertEquals(1, singleConverters.size) 19 | } 20 | 21 | @Test 22 | fun `Converter list class name is correct ofter processing`() { 23 | assertEquals("com.example.activitystarter.MainActivity.IntToLongConverter", singleConverters[0].className) 24 | } 25 | 26 | @Test 27 | fun `Converter list parameter type names are correct ofter processing`() { 28 | assertEquals("java.lang.Integer", singleConverters[0].typeFrom.toString()) 29 | assertEquals("java.lang.Long", singleConverters[0].typeTo.toString()) 30 | } 31 | } -------------------------------------------------------------------------------- /activitystarter-compiler/src/test/java/activitystarter/compiler/utils/CamelCaseToUppercaseUnderscoreFunKtTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.compiler.utils 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Test 5 | 6 | class CamelCaseToUppercaseUnderscoreFunKtTest { 7 | 8 | @Test fun `Empty is translated to empty`() { 9 | assertEquals("", camelCaseToUppercaseUnderscore("")) 10 | } 11 | 12 | @Test fun `Simple underscore camelcase translations to uppercase underscore`() { 13 | assertEquals("JA_MAN", camelCaseToUppercaseUnderscore("jaMan")) 14 | assertEquals("KO_KO_KO", camelCaseToUppercaseUnderscore("koKoKo")) 15 | } 16 | 17 | 18 | @Test fun `Simple upperscore camelcase translations to uppercase underscore`() { 19 | assertEquals("JA_MAN", camelCaseToUppercaseUnderscore("JaMan")) 20 | assertEquals("KO_KO_KO", camelCaseToUppercaseUnderscore("KoKoKo")) 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /activitystarter-kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /activitystarter-kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | dependencies { 3 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 4 | } 5 | } 6 | 7 | apply plugin: 'com.android.library' 8 | apply plugin: 'kotlin-android' 9 | apply plugin: 'com.github.dcendents.android-maven' 10 | 11 | group='com.marcinmoskala' 12 | 13 | def logger = new com.android.build.gradle.internal.LoggerWrapper(project.logger) 14 | def sdkHandler = new com.android.build.gradle.internal.SdkHandler(project, logger) 15 | for (File file : sdkHandler.sdkLoader.repositories) { 16 | repositories.maven { 17 | url = file.toURI() 18 | } 19 | } 20 | 21 | android { 22 | compileSdkVersion rootProject.ext.compileSdkVersion 23 | 24 | defaultConfig { 25 | minSdkVersion rootProject.ext.minSdkVersion 26 | testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' 27 | } 28 | buildToolsVersion '27.0.3' 29 | } 30 | 31 | sourceCompatibility = rootProject.ext.sourceCompatibilityVersion 32 | targetCompatibility = rootProject.ext.targetCompatibilityVersion 33 | 34 | dependencies { 35 | compile project(':activitystarter-annotations') 36 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" 37 | implementation deps.supportAppcompatv7 38 | implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" 39 | 40 | testImplementation deps.junit 41 | } 42 | 43 | task sourcesJar(type: Jar) { 44 | from android.sourceSets.main.java.srcDirs 45 | classifier = 'sources' 46 | } 47 | 48 | artifacts { 49 | archives sourcesJar 50 | } 51 | 52 | install { 53 | repositories.mavenInstaller { 54 | pom.project { 55 | licenses { 56 | license { 57 | name 'The Apache Software License, Version 2.0' 58 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 59 | distribution 'repo' 60 | } 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /activitystarter-kotlin/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\marci\AppData\Local\Android\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 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /activitystarter-kotlin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /activitystarter-kotlin/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | activitystarter-parceler-arg-wrapper 3 | 4 | -------------------------------------------------------------------------------- /activitystarter-kotlin/src/test/java/com/marcinmoskala/activitystarter/ConditionsCheckUnitTest.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("IllegalIdentifier") 2 | 3 | package com.marcinmoskala.activitystarter 4 | 5 | import activitystarter.Arg 6 | import org.junit.Assert.assertEquals 7 | import org.junit.Assert.assertTrue 8 | import org.junit.Test 9 | 10 | class ConditionsCheckUnitTest { 11 | 12 | // TODO Depend on part that is in hold bacause of problems in beta versions of Gradle, which are suggested in AndroidStudio 3.0 13 | // @Test 14 | // fun `when property define argument delegate and it does not contain annotation then error is thrown`() { 15 | // assertThrowsError(ErrorMessages.noAnnotation) { 16 | // object { 17 | // val a: A? by BoundToArgValueDelegateProvider() 18 | // } 19 | // } 20 | // } 21 | // 22 | // @Test 23 | // fun `when not nullable and not optional value and no default then throwing error`() { 24 | // assertThrowsError(ErrorMessages.optionalValueNeeded) { 25 | // object { 26 | // @get:Arg(optional = true) val a: A by BoundToArgValueDelegateProvider() 27 | // } 28 | // } 29 | // } 30 | // 31 | // @Test 32 | // fun `when nullable type, no default value is allowed`() { 33 | // object { 34 | // @get:Arg val a: A? by BoundToArgValueDelegateProvider() 35 | // } 36 | // } 37 | 38 | @Test 39 | fun `Other use-cases`() { 40 | object { 41 | @get:Arg val a: A? by BoundToArgValueDelegateProvider(null) 42 | @get:Arg val c: A? by BoundToArgValueDelegateProvider(A()) 43 | @get:Arg val d: A by BoundToArgValueDelegateProvider() 44 | @get:Arg val e: A by BoundToArgValueDelegateProvider(A()) 45 | @get:Arg(optional = true) val f: A? by BoundToArgValueDelegateProvider(A()) 46 | @get:Arg(optional = true) val g: A? by BoundToArgValueDelegateProvider(null) 47 | @get:Arg(optional = true) val h: A? by BoundToArgValueDelegateProvider() 48 | } 49 | } 50 | 51 | class A 52 | 53 | private fun assertThrowsError(message: String? = null, f: () -> Unit) { 54 | assertTrue(try { 55 | f() 56 | false 57 | } catch (t: Throwable) { 58 | if (message != null) assertEquals(message, t.message) 59 | true 60 | }) 61 | } 62 | } -------------------------------------------------------------------------------- /activitystarter/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=activitystarter 2 | POM_NAME=ActivityStarter 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /activitystarter/proguard-rules.txt: -------------------------------------------------------------------------------- 1 | # please KEEP ALL THE NAMES 2 | -keep class **Starter { *; } -------------------------------------------------------------------------------- /activitystarter/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /activitystarter/src/main/java/activitystarter/Helpers.java: -------------------------------------------------------------------------------- 1 | package activitystarter; 2 | 3 | public class Helpers { 4 | 5 | public static boolean isSubtype(Class subclass, Class superclass) { 6 | return subclass.isAssignableFrom(superclass); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/Helpers.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("IllegalIdentifier") 2 | 3 | package activitystarter 4 | 5 | import activitystarter.Helpers.isSubtype 6 | import android.accounts.Account 7 | import android.os.Parcelable 8 | import org.junit.Assert 9 | import org.junit.Assert.assertTrue 10 | import org.junit.Test 11 | 12 | internal fun assertTypeEquals(class1: Class<*>, class2: Class<*>) { 13 | Assert.assertEquals(class1.canonicalName, class2.canonicalName) 14 | } 15 | 16 | internal fun assertSubtype(subclass: Class<*>, superclass: Class<*>) { 17 | assertTrue("$subclass is not sublcass of $superclass.", isSubtype(subclass, superclass)) 18 | } 19 | 20 | internal fun assertThrowsError(f: () -> Unit) { 21 | try { 22 | f() 23 | throw Error("Function didn't throw error.") 24 | } catch (t: Throwable) { 25 | // noop 26 | } 27 | } 28 | 29 | class HelpersTests() { 30 | 31 | @Test fun `assertSubtype simple subtypes are passing`() { 32 | assertSubtype(Parcelable::class.java, Account::class.java) 33 | assertSubtype(String::class.java, String::class.java) 34 | } 35 | 36 | @Test fun `assertSubtype not subtypes are not passing`() { 37 | assertThrowsError { assertSubtype(String::class.java, Int::class.java) } 38 | assertThrowsError { assertSubtype(Long::class.java, Int::class.java) } 39 | } 40 | 41 | @Test fun `assertSubtype reversed subtypes are not passing`() { 42 | assertThrowsError { assertSubtype(Account::class.java, Parcelable::class.java) } 43 | } 44 | 45 | @Test fun `assertThrowsError is passing when failing assert is inside`() { 46 | val message = "Fake error that should be catched by assertThrowsError" 47 | assertThrowsError { throw Error(message) } 48 | assertThrowsError { assertTrue(message, false) } 49 | } 50 | 51 | @Test fun `assertThrowsError throwing error when there is no error inside`() { 52 | assertThrowsError { assertThrowsError { } } 53 | } 54 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/ActivityForResultGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import org.junit.Test 4 | 5 | class ActivityForResultGenerationTest: GenerationTest() { 6 | 7 | @Test 8 | fun emptyAnnotatedGenerationTest() { 9 | filePrecessingComparator("activityForResult/EmptyAnnotated") 10 | } 11 | 12 | @Test 13 | fun simpleGenerationTest() { 14 | filePrecessingComparator("activityForResult/Simple") 15 | } 16 | 17 | @Test 18 | fun setterGetterGenerationTest() { 19 | filePrecessingComparator("activityForResult/SetterGetter") 20 | } 21 | 22 | @Test 23 | fun optionalArgGenerationTest() { 24 | filePrecessingComparator("activityForResult/Optional") 25 | } 26 | 27 | @Test 28 | fun multipleOptionalArgGenerationTest() { 29 | filePrecessingComparator("activityForResult/MultipleOptional") 30 | } 31 | 32 | @Test 33 | fun conflictedOptionalArgGenerationTest() { 34 | filePrecessingComparator("activityForResult/ConflictedOptional") 35 | } 36 | 37 | @Test 38 | fun allGenerationTest() { 39 | dirPrecessingComparator("activityForResult") 40 | } 41 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/ActivityGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import org.junit.Test 4 | 5 | class ActivityGenerationTest: GenerationTest() { 6 | 7 | @Test 8 | fun emptyAnnotatedGenerationTest() { 9 | filePrecessingComparator("activity/EmptyAnnotated") 10 | } 11 | 12 | @Test 13 | fun simpleGenerationTest() { 14 | filePrecessingComparator("activity/Simple") 15 | } 16 | 17 | @Test 18 | fun setterGetterGenerationTest() { 19 | filePrecessingComparator("activity/SetterGetter") 20 | } 21 | 22 | @Test 23 | fun optionalArgGenerationTest() { 24 | filePrecessingComparator("activity/Optional") 25 | } 26 | 27 | @Test 28 | fun multipleOptionalArgGenerationTest() { 29 | filePrecessingComparator("activity/MultipleOptional") 30 | } 31 | 32 | @Test 33 | fun conflictedOptionalArgGenerationTest() { 34 | filePrecessingComparator("activity/ConflictedOptional") 35 | } 36 | 37 | @Test 38 | fun allGenerationTest() { 39 | dirPrecessingComparator("activity") 40 | } 41 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/ActivityNonSavableGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import org.junit.Test 4 | 5 | class ActivityNonSavableGenerationTest: GenerationTest() { 6 | 7 | @Test 8 | fun emptyAnnotatedGenerationTest() { 9 | filePrecessingComparator("activityNonSavable/EmptyAnnotated") 10 | } 11 | 12 | @Test 13 | fun singleArgGenerationTest() { 14 | filePrecessingComparator("activityNonSavable/Simple") 15 | } 16 | 17 | @Test 18 | fun setterGetterGenerationTest() { 19 | filePrecessingComparator("activityNonSavable/SetterGetter") 20 | } 21 | 22 | @Test 23 | fun optionalArgGenerationTest() { 24 | filePrecessingComparator("activityNonSavable/Optional") 25 | } 26 | 27 | @Test 28 | fun multipleOptionalArgGenerationTest() { 29 | filePrecessingComparator("activityNonSavable/MultipleOptional") 30 | } 31 | 32 | @Test 33 | fun conflictedOptionalArgGenerationTest() { 34 | filePrecessingComparator("activityNonSavable/ConflictedOptional") 35 | } 36 | 37 | @Test 38 | fun allGenerationTest() { 39 | dirPrecessingComparator("activityNonSavable") 40 | } 41 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/ActivityWithConvertersTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import activitystarter.compiler.error.Errors 4 | import org.junit.Test 5 | 6 | @Suppress("IllegalIdentifier") 7 | class ActivityWithConvertersTest: GenerationTest() { 8 | 9 | @Test 10 | fun intToLongConversionTest() { 11 | filePrecessingComparator("withConverters/ActivityWithIntToLongConverter") 12 | } 13 | 14 | @Test 15 | fun toParcelableConversionTest() { 16 | filePrecessingComparator("parceler/Simple") 17 | } 18 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/ByAccessorsTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import activitystarter.compiler.error.Errors 4 | import org.junit.Test 5 | 6 | @Suppress("IllegalIdentifier") 7 | class ByAccessorsTest : GenerationTest() { 8 | 9 | @Test 10 | fun singleGetterTest() { 11 | filePrecessingComparator("byAccessor/Single") 12 | } 13 | 14 | @Test 15 | fun getterSetterTest() { 16 | filePrecessingComparator("byAccessor/GetterSetter") 17 | } 18 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/CustomIdGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import org.junit.Test 4 | 5 | class CustomIdGenerationTest: GenerationTest() { 6 | 7 | @Test 8 | fun simpleGenerationTest() { 9 | filePrecessingComparator("customId/Simple") 10 | } 11 | 12 | @Test 13 | fun optionalGenerationTest() { 14 | filePrecessingComparator("customId/Optional") 15 | } 16 | 17 | @Test 18 | fun multipleOptionalGenerationTest() { 19 | filePrecessingComparator("customId/MultipleOptional") 20 | } 21 | 22 | @Test 23 | fun allGenerationTest() { 24 | dirPrecessingComparator("customId") 25 | } 26 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/FragmentGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import org.junit.Test 4 | 5 | 6 | class FragmentGenerationTest: GenerationTest() { 7 | 8 | @Test 9 | fun emptyAnnotatedGenerationTest() { 10 | filePrecessingComparator("fragment/EmptyAnnotated") 11 | } 12 | 13 | @Test 14 | fun simpleArgGenerationTest() { 15 | filePrecessingComparator("fragment/Simple") 16 | } 17 | 18 | @Test 19 | fun optionalArgGenerationTest() { 20 | filePrecessingComparator("fragment/Optional") 21 | } 22 | 23 | @Test 24 | fun multipleOptionalArgGenerationTest() { 25 | filePrecessingComparator("fragment/MultipleOptional") 26 | } 27 | 28 | @Test 29 | fun conflictedOptionalArgGenerationTest() { 30 | filePrecessingComparator("fragment/ConflictedOptional") 31 | } 32 | 33 | @Test 34 | fun setterGetterGenerationTest() { 35 | filePrecessingComparator("fragment/SetterGetter") 36 | } 37 | 38 | @Test 39 | fun allGenerationTest() { 40 | dirPrecessingComparator("fragment") 41 | } 42 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/GenerationErrorTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import activitystarter.compiler.error.Errors 4 | import org.junit.Test 5 | import kotlin.test.assertEquals 6 | 7 | class GenerationErrorTest : GenerationTest() { 8 | 9 | @Test 10 | fun simpleGenerationErrorTest() { 11 | filePrecessingCheckError("shouldThrowError/ActivityPrivateFIeld", Errors.inaccessibleField) 12 | } 13 | 14 | @Test 15 | fun serviceParcelableFieldErrorTest() { 16 | filePrecessingCheckError("shouldThrowError/ServiceParcelableField", Errors.notBasicTypeInReceiver) 17 | } 18 | 19 | @Test 20 | fun privateClassErrorTest() { 21 | filePrecessingCheckError("shouldThrowError/PrivateClass", Errors.privateClass) 22 | } 23 | 24 | @Test 25 | fun setterOnlyGenerationErrorTest() { 26 | filePrecessingCheckError("shouldThrowError/SetterOnly", Errors.inaccessibleField) 27 | } 28 | 29 | @Test 30 | fun getterOnlyGenerationErrorTest() { 31 | filePrecessingCheckError("shouldThrowError/GetterOnly", Errors.inaccessibleField) 32 | } 33 | } -------------------------------------------------------------------------------- /activitystarter/src/test/java/activitystarter/generation/ServiceGenerationTest.kt: -------------------------------------------------------------------------------- 1 | package activitystarter.generation 2 | 3 | import org.junit.Test 4 | 5 | class ServiceGenerationTest: GenerationTest() { 6 | 7 | @Test 8 | fun simpleGenerationTest() { 9 | filePrecessingComparator("service/EmptyAnnotated") 10 | } 11 | 12 | @Test 13 | fun singleArgGenerationTest() { 14 | filePrecessingComparator("service/Simple") 15 | } 16 | 17 | @Test 18 | fun complexArgGenerationTest() { 19 | filePrecessingComparator("service/Complex") 20 | } 21 | 22 | @Test 23 | fun allGenerationTest() { 24 | dirPrecessingComparator("service") 25 | } 26 | } -------------------------------------------------------------------------------- /generationExamples/activity/EmptyAnnotated: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Activity; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter 8 | public class MainActivity extends Activity {} 9 | ********com.example.activitystarter.MainActivityStarter******** 10 | package com.example.activitystarter; 11 | 12 | import android.content.Context; 13 | import android.content.Intent; 14 | import android.os.Bundle; 15 | 16 | public final class MainActivityStarter { 17 | 18 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 19 | } 20 | 21 | public static void save(MainActivity activity, Bundle bundle) { 22 | } 23 | 24 | public static Intent getIntent(Context context) { 25 | Intent intent = new Intent(context, MainActivity.class); 26 | return intent; 27 | } 28 | 29 | public static void start(Context context) { 30 | Intent intent = getIntent(context); 31 | context.startActivity(intent); 32 | } 33 | 34 | public static void startWithFlags(Context context, int flags) { 35 | Intent intent = getIntent(context); 36 | intent.addFlags(flags); 37 | context.startActivity(intent); 38 | } 39 | } -------------------------------------------------------------------------------- /generationExamples/activity/Optional: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg(optional = true) String name; 8 | } 9 | ********com.example.activitystarter.MainActivityStarter******** 10 | package com.example.activitystarter; 11 | 12 | import android.content.Context; 13 | import android.content.Intent; 14 | import android.os.Bundle; 15 | import java.lang.String; 16 | 17 | public final class MainActivityStarter { 18 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 19 | 20 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 21 | Intent intent = activity.getIntent(); 22 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 23 | activity.name = savedInstanceState.getString(NAME_KEY); 24 | } else { 25 | if(intent.hasExtra(NAME_KEY)) 26 | activity.name = intent.getStringExtra(NAME_KEY); 27 | } 28 | } 29 | 30 | public static void save(MainActivity activity, Bundle bundle) { 31 | bundle.putString(NAME_KEY, activity.name); 32 | } 33 | 34 | public static Intent getIntent(Context context, String name) { 35 | Intent intent = new Intent(context, MainActivity.class); 36 | intent.putExtra(NAME_KEY, name); 37 | return intent; 38 | } 39 | 40 | public static void start(Context context, String name) { 41 | Intent intent = getIntent(context, name); 42 | context.startActivity(intent); 43 | } 44 | 45 | public static void startWithFlags(Context context, String name, int flags) { 46 | Intent intent = getIntent(context, name); 47 | intent.addFlags(flags); 48 | context.startActivity(intent); 49 | } 50 | 51 | public static Intent getIntent(Context context) { 52 | Intent intent = new Intent(context, MainActivity.class); 53 | return intent; 54 | } 55 | 56 | public static void start(Context context) { 57 | Intent intent = getIntent(context); 58 | context.startActivity(intent); 59 | } 60 | 61 | public static void startWithFlags(Context context, int flags) { 62 | Intent intent = getIntent(context); 63 | intent.addFlags(flags); 64 | context.startActivity(intent); 65 | } 66 | } -------------------------------------------------------------------------------- /generationExamples/activity/SetterGetter: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg private String name; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | } 17 | ********com.example.activitystarter.MainActivityStarter******** 18 | package com.example.activitystarter; 19 | 20 | import android.content.Context; 21 | import android.content.Intent; 22 | import android.os.Bundle; 23 | import java.lang.String; 24 | 25 | public final class MainActivityStarter { 26 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 27 | 28 | /** 29 | * This is method used to fill fields. Use it by calling ActivityStarter.fill(this). */ 30 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 31 | Intent intent = activity.getIntent(); 32 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 33 | activity.setName(savedInstanceState.getString(NAME_KEY)); 34 | } else { 35 | if(intent.hasExtra(NAME_KEY)) 36 | activity.setName(intent.getStringExtra(NAME_KEY)); 37 | } 38 | } 39 | 40 | public static void save(MainActivity activity, Bundle bundle) { 41 | bundle.putString(NAME_KEY, activity.getName()); 42 | } 43 | 44 | public static Intent getIntent(Context context, String name) { 45 | Intent intent = new Intent(context, MainActivity.class); 46 | intent.putExtra(NAME_KEY, name); 47 | return intent; 48 | } 49 | 50 | public static void start(Context context, String name) { 51 | Intent intent = getIntent(context, name); 52 | context.startActivity(intent); 53 | } 54 | 55 | public static void startWithFlags(Context context, String name, int flags) { 56 | Intent intent = getIntent(context, name); 57 | intent.addFlags(flags); 58 | context.startActivity(intent); 59 | } 60 | } -------------------------------------------------------------------------------- /generationExamples/activity/Simple: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg String name; 8 | } 9 | ********com.example.activitystarter.MainActivityStarter******** 10 | package com.example.activitystarter; 11 | 12 | import android.content.Context; 13 | import android.content.Intent; 14 | import android.os.Bundle; 15 | import java.lang.String; 16 | 17 | public final class MainActivityStarter { 18 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 19 | 20 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 21 | Intent intent = activity.getIntent(); 22 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 23 | activity.name = savedInstanceState.getString(NAME_KEY); 24 | } else { 25 | if(intent.hasExtra(NAME_KEY)) 26 | activity.name = intent.getStringExtra(NAME_KEY); 27 | } 28 | } 29 | 30 | public static void save(MainActivity activity, Bundle bundle) { 31 | bundle.putString(NAME_KEY, activity.name); 32 | } 33 | 34 | public static Intent getIntent(Context context, String name) { 35 | Intent intent = new Intent(context, MainActivity.class); 36 | intent.putExtra(NAME_KEY, name); 37 | return intent; 38 | } 39 | 40 | public static void start(Context context, String name) { 41 | Intent intent = getIntent(context, name); 42 | context.startActivity(intent); 43 | } 44 | 45 | public static void startWithFlags(Context context, String name, int flags) { 46 | Intent intent = getIntent(context, name); 47 | intent.addFlags(flags); 48 | context.startActivity(intent); 49 | } 50 | } -------------------------------------------------------------------------------- /generationExamples/activityForResult/EmptyAnnotated: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Activity; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(includeStartForResult = true) 8 | public class MainActivity extends Activity {} 9 | ********com.example.activitystarter.MainActivityStarter******** 10 | package com.example.activitystarter; 11 | 12 | import android.app.Activity; 13 | import android.content.Context; 14 | import android.content.Intent; 15 | import android.os.Bundle; 16 | 17 | public final class MainActivityStarter { 18 | 19 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 20 | } 21 | 22 | public static void save(MainActivity activity, Bundle bundle) { 23 | } 24 | 25 | public static Intent getIntent(Context context) { 26 | Intent intent = new Intent(context, MainActivity.class); 27 | return intent; 28 | } 29 | 30 | public static void start(Context context) { 31 | Intent intent = getIntent(context); 32 | context.startActivity(intent); 33 | } 34 | 35 | public static void startWithFlags(Context context, int flags) { 36 | Intent intent = getIntent(context); 37 | intent.addFlags(flags); 38 | context.startActivity(intent); 39 | } 40 | 41 | public static void startForResult(Activity context, int result) { 42 | Intent intent = getIntent(context); 43 | context.startActivityForResult(intent, result); 44 | } 45 | 46 | public static void startWithFlagsForResult(Activity context, int result, int flags) { 47 | Intent intent = getIntent(context); 48 | intent.addFlags(flags); 49 | context.startActivityForResult(intent, result); 50 | } 51 | } -------------------------------------------------------------------------------- /generationExamples/activityForResult/SetterGetter: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(includeStartForResult = true) 8 | public class MainActivity extends Activity { 9 | @Arg private String name; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | } 19 | ********com.example.activitystarter.MainActivityStarter******** 20 | package com.example.activitystarter; 21 | 22 | import android.app.Activity; 23 | import android.content.Context; 24 | import android.content.Intent; 25 | import android.os.Bundle; 26 | import java.lang.String; 27 | 28 | public final class MainActivityStarter { 29 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 30 | 31 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 32 | Intent intent = activity.getIntent(); 33 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 34 | activity.setName(savedInstanceState.getString(NAME_KEY)); 35 | } else { 36 | if(intent.hasExtra(NAME_KEY)) 37 | activity.setName(intent.getStringExtra(NAME_KEY)); 38 | } 39 | } 40 | 41 | public static void save(MainActivity activity, Bundle bundle) { 42 | bundle.putString(NAME_KEY, activity.getName()); 43 | } 44 | 45 | public static Intent getIntent(Context context, String name) { 46 | Intent intent = new Intent(context, MainActivity.class); 47 | intent.putExtra(NAME_KEY, name); 48 | return intent; 49 | } 50 | 51 | public static void start(Context context, String name) { 52 | Intent intent = getIntent(context, name); 53 | context.startActivity(intent); 54 | } 55 | 56 | public static void startWithFlags(Context context, String name, int flags) { 57 | Intent intent = getIntent(context, name); 58 | intent.addFlags(flags); 59 | context.startActivity(intent); 60 | } 61 | 62 | public static void startForResult(Activity context, String name, int result) { 63 | Intent intent = getIntent(context, name); 64 | context.startActivityForResult(intent, result); 65 | } 66 | 67 | public static void startWithFlagsForResult(Activity context, String name, int result, int flags) { 68 | Intent intent = getIntent(context, name); 69 | intent.addFlags(flags); 70 | context.startActivityForResult(intent, result); 71 | } 72 | } -------------------------------------------------------------------------------- /generationExamples/activityForResult/Simple: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(includeStartForResult = true) 8 | public class MainActivity extends Activity { 9 | @Arg String name; 10 | } 11 | ********com.example.activitystarter.MainActivityStarter******** 12 | package com.example.activitystarter; 13 | 14 | import android.app.Activity; 15 | import android.content.Context; 16 | import android.content.Intent; 17 | import android.os.Bundle; 18 | import java.lang.String; 19 | 20 | public final class MainActivityStarter { 21 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 22 | 23 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 24 | Intent intent = activity.getIntent(); 25 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 26 | activity.name = savedInstanceState.getString(NAME_KEY); 27 | } else { 28 | if(intent.hasExtra(NAME_KEY)) 29 | activity.name = intent.getStringExtra(NAME_KEY); 30 | } 31 | } 32 | 33 | public static void save(MainActivity activity, Bundle bundle) { 34 | bundle.putString(NAME_KEY, activity.name); 35 | } 36 | 37 | public static Intent getIntent(Context context, String name) { 38 | Intent intent = new Intent(context, MainActivity.class); 39 | intent.putExtra(NAME_KEY, name); 40 | return intent; 41 | } 42 | 43 | public static void start(Context context, String name) { 44 | Intent intent = getIntent(context, name); 45 | context.startActivity(intent); 46 | } 47 | 48 | public static void startWithFlags(Context context, String name, int flags) { 49 | Intent intent = getIntent(context, name); 50 | intent.addFlags(flags); 51 | context.startActivity(intent); 52 | } 53 | 54 | public static void startForResult(Activity context, String name, int result) { 55 | Intent intent = getIntent(context, name); 56 | context.startActivityForResult(intent, result); 57 | } 58 | 59 | public static void startWithFlagsForResult(Activity context, String name, int result, int flags) { 60 | Intent intent = getIntent(context, name); 61 | intent.addFlags(flags); 62 | context.startActivityForResult(intent, result); 63 | } 64 | } -------------------------------------------------------------------------------- /generationExamples/activityNonSavable/ConflictedOptional: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(savable = false) 8 | public class MainActivity extends Activity { 9 | @Arg(optional = true) String name; 10 | @Arg(optional = true) String surname; 11 | } 12 | ********com.example.activitystarter.MainActivityStarter******** 13 | package com.example.activitystarter; 14 | 15 | import android.content.Context; 16 | import android.content.Intent; 17 | import android.os.Bundle; 18 | import java.lang.String; 19 | 20 | public final class MainActivityStarter { 21 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 22 | 23 | private static final String SURNAME_KEY = "com.example.activitystarter.surnameStarterKey"; 24 | 25 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 26 | Intent intent = activity.getIntent(); 27 | if(intent.hasExtra(NAME_KEY)) 28 | activity.name = intent.getStringExtra(NAME_KEY); 29 | if(intent.hasExtra(SURNAME_KEY)) 30 | activity.surname = intent.getStringExtra(SURNAME_KEY); 31 | } 32 | 33 | public static void save(MainActivity activity, Bundle bundle) { 34 | } 35 | 36 | public static Intent getIntent(Context context, String name, String surname) { 37 | Intent intent = new Intent(context, MainActivity.class); 38 | intent.putExtra(NAME_KEY, name); 39 | intent.putExtra(SURNAME_KEY, surname); 40 | return intent; 41 | } 42 | 43 | public static void start(Context context, String name, String surname) { 44 | Intent intent = getIntent(context, name, surname); 45 | context.startActivity(intent); 46 | } 47 | 48 | public static void startWithFlags(Context context, String name, String surname, int flags) { 49 | Intent intent = getIntent(context, name, surname); 50 | intent.addFlags(flags); 51 | context.startActivity(intent); 52 | } 53 | 54 | public static Intent getIntent(Context context, String name) { 55 | Intent intent = new Intent(context, MainActivity.class); 56 | intent.putExtra(NAME_KEY, name); 57 | return intent; 58 | } 59 | 60 | public static void start(Context context, String name) { 61 | Intent intent = getIntent(context, name); 62 | context.startActivity(intent); 63 | } 64 | 65 | public static void startWithFlags(Context context, String name, int flags) { 66 | Intent intent = getIntent(context, name); 67 | intent.addFlags(flags); 68 | context.startActivity(intent); 69 | } 70 | 71 | public static Intent getIntent(Context context) { 72 | Intent intent = new Intent(context, MainActivity.class); 73 | return intent; 74 | } 75 | 76 | public static void start(Context context) { 77 | Intent intent = getIntent(context); 78 | context.startActivity(intent); 79 | } 80 | 81 | public static void startWithFlags(Context context, int flags) { 82 | Intent intent = getIntent(context); 83 | intent.addFlags(flags); 84 | context.startActivity(intent); 85 | } 86 | } -------------------------------------------------------------------------------- /generationExamples/activityNonSavable/EmptyAnnotated: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Activity; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(savable = false) 8 | public class MainActivity extends Activity {} 9 | ********com.example.activitystarter.MainActivityStarter******** 10 | package com.example.activitystarter; 11 | 12 | import android.content.Context; 13 | import android.content.Intent; 14 | import android.os.Bundle; 15 | 16 | public final class MainActivityStarter { 17 | 18 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 19 | } 20 | 21 | public static void save(MainActivity activity, Bundle bundle) { 22 | } 23 | 24 | public static Intent getIntent(Context context) { 25 | Intent intent = new Intent(context, MainActivity.class); 26 | return intent; 27 | } 28 | 29 | public static void start(Context context) { 30 | Intent intent = getIntent(context); 31 | context.startActivity(intent); 32 | } 33 | 34 | public static void startWithFlags(Context context, int flags) { 35 | Intent intent = getIntent(context); 36 | intent.addFlags(flags); 37 | context.startActivity(intent); 38 | } 39 | } -------------------------------------------------------------------------------- /generationExamples/activityNonSavable/Optional: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(savable = false) 8 | public class MainActivity extends Activity { 9 | @Arg(optional = true) String name; 10 | } 11 | ********com.example.activitystarter.MainActivityStarter******** 12 | package com.example.activitystarter; 13 | 14 | import android.content.Context; 15 | import android.content.Intent; 16 | import android.os.Bundle; 17 | import java.lang.String; 18 | 19 | public final class MainActivityStarter { 20 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 21 | 22 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 23 | Intent intent = activity.getIntent(); 24 | if(intent.hasExtra(NAME_KEY)) 25 | activity.name = intent.getStringExtra(NAME_KEY); 26 | } 27 | 28 | public static void save(MainActivity activity, Bundle bundle) { 29 | } 30 | 31 | public static Intent getIntent(Context context, String name) { 32 | Intent intent = new Intent(context, MainActivity.class); 33 | intent.putExtra(NAME_KEY, name); 34 | return intent; 35 | } 36 | 37 | public static void start(Context context, String name) { 38 | Intent intent = getIntent(context, name); 39 | context.startActivity(intent); 40 | } 41 | 42 | public static void startWithFlags(Context context, String name, int flags) { 43 | Intent intent = getIntent(context, name); 44 | intent.addFlags(flags); 45 | context.startActivity(intent); 46 | } 47 | 48 | public static Intent getIntent(Context context) { 49 | Intent intent = new Intent(context, MainActivity.class); 50 | return intent; 51 | } 52 | 53 | public static void start(Context context) { 54 | Intent intent = getIntent(context); 55 | context.startActivity(intent); 56 | } 57 | 58 | public static void startWithFlags(Context context, int flags) { 59 | Intent intent = getIntent(context); 60 | intent.addFlags(flags); 61 | context.startActivity(intent); 62 | } 63 | } -------------------------------------------------------------------------------- /generationExamples/activityNonSavable/SetterGetter: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(savable = false) 8 | public class MainActivity extends Activity { 9 | @Arg private String name; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | } 19 | ********com.example.activitystarter.MainActivityStarter******** 20 | package com.example.activitystarter; 21 | 22 | import android.content.Context; 23 | import android.content.Intent; 24 | import android.os.Bundle; 25 | import java.lang.String; 26 | 27 | public final class MainActivityStarter { 28 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 29 | 30 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 31 | Intent intent = activity.getIntent(); 32 | if(intent.hasExtra(NAME_KEY)) 33 | activity.setName(intent.getStringExtra(NAME_KEY)); 34 | } 35 | 36 | public static void save(MainActivity activity, Bundle bundle) { 37 | } 38 | 39 | public static Intent getIntent(Context context, String name) { 40 | Intent intent = new Intent(context, MainActivity.class); 41 | intent.putExtra(NAME_KEY, name); 42 | return intent; 43 | } 44 | 45 | public static void start(Context context, String name) { 46 | Intent intent = getIntent(context, name); 47 | context.startActivity(intent); 48 | } 49 | 50 | public static void startWithFlags(Context context, String name, int flags) { 51 | Intent intent = getIntent(context, name); 52 | intent.addFlags(flags); 53 | context.startActivity(intent); 54 | } 55 | } -------------------------------------------------------------------------------- /generationExamples/activityNonSavable/Simple: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | import activitystarter.MakeActivityStarter; 6 | 7 | @MakeActivityStarter(savable = false) 8 | public class MainActivity extends Activity { 9 | @Arg String name; 10 | } 11 | ********com.example.activitystarter.MainActivityStarter******** 12 | package com.example.activitystarter; 13 | 14 | import android.content.Context; 15 | import android.content.Intent; 16 | import android.os.Bundle; 17 | import java.lang.String; 18 | 19 | public final class MainActivityStarter { 20 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 21 | 22 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 23 | Intent intent = activity.getIntent(); 24 | if(intent.hasExtra(NAME_KEY)) 25 | activity.name = intent.getStringExtra(NAME_KEY); 26 | } 27 | 28 | public static void save(MainActivity activity, Bundle bundle) { 29 | } 30 | 31 | public static Intent getIntent(Context context, String name) { 32 | Intent intent = new Intent(context, MainActivity.class); 33 | intent.putExtra(NAME_KEY, name); 34 | return intent; 35 | } 36 | 37 | public static void start(Context context, String name) { 38 | Intent intent = getIntent(context, name); 39 | context.startActivity(intent); 40 | } 41 | 42 | public static void startWithFlags(Context context, String name, int flags) { 43 | Intent intent = getIntent(context, name); 44 | intent.addFlags(flags); 45 | context.startActivity(intent); 46 | } 47 | } -------------------------------------------------------------------------------- /generationExamples/byAccessor/GetterSetter: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Activity; 5 | import android.os.Bundle; 6 | 7 | import activitystarter.ActivityStarter; 8 | import activitystarter.Arg; 9 | 10 | public final class MainActivity extends Activity { 11 | private boolean b; 12 | 13 | @Arg(optional = true) 14 | public final boolean getB() { 15 | return b; 16 | } 17 | public final void setB(boolean b) { 18 | this.b = b; 19 | } 20 | 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | ActivityStarter.fill(this, savedInstanceState); 24 | } 25 | 26 | protected void onSaveInstanceState(Bundle outState) { 27 | super.onSaveInstanceState(outState); 28 | ActivityStarter.save(this, outState); 29 | } 30 | } 31 | 32 | ********com.example.activitystarter.MainActivityStarter******** 33 | package com.example.activitystarter; 34 | 35 | import android.content.Context; 36 | import android.content.Intent; 37 | import android.os.Bundle; 38 | import java.lang.String; 39 | 40 | public final class MainActivityStarter { 41 | private static final String B_KEY = "com.example.activitystarter.bStarterKey"; 42 | 43 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 44 | if(savedInstanceState != null && savedInstanceState.containsKey(B_KEY)) { 45 | activity.setB(savedInstanceState.getBoolean(B_KEY)); 46 | } 47 | } 48 | 49 | public static void save(MainActivity activity, Bundle bundle) { 50 | bundle.putBoolean(B_KEY, activity.getB()); 51 | } 52 | 53 | public static boolean isFilledValueOfBFrom(MainActivity activity) { 54 | Intent intent = activity.getIntent(); 55 | return intent != null && intent.hasExtra(B_KEY); 56 | } 57 | 58 | public static boolean getValueOfBFrom(MainActivity activity) { 59 | Intent intent = activity.getIntent(); 60 | return intent.getBooleanExtra(B_KEY, false); 61 | } 62 | 63 | public static Intent getIntent(Context context, boolean b) { 64 | Intent intent = new Intent(context, MainActivity.class); 65 | intent.putExtra(B_KEY, b); 66 | return intent; 67 | } 68 | 69 | public static void start(Context context, boolean b) { 70 | Intent intent = getIntent(context, b); 71 | context.startActivity(intent); 72 | } 73 | 74 | public static void startWithFlags(Context context, boolean b, int flags) { 75 | Intent intent = getIntent(context, b); 76 | intent.addFlags(flags); 77 | context.startActivity(intent); 78 | } 79 | 80 | public static Intent getIntent(Context context) { 81 | Intent intent = new Intent(context, MainActivity.class); 82 | return intent; 83 | } 84 | 85 | public static void start(Context context) { 86 | Intent intent = getIntent(context); 87 | context.startActivity(intent); 88 | } 89 | 90 | public static void startWithFlags(Context context, int flags) { 91 | Intent intent = getIntent(context); 92 | intent.addFlags(flags); 93 | context.startActivity(intent); 94 | } 95 | } -------------------------------------------------------------------------------- /generationExamples/byAccessor/Single: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | 8 | @Arg public String getName() { 9 | return "Marcin"; 10 | } 11 | } 12 | ********com.example.activitystarter.MainActivityStarter******** 13 | package com.example.activitystarter; 14 | 15 | import android.content.Context; 16 | import android.content.Intent; 17 | import android.os.Bundle; 18 | import java.lang.String; 19 | 20 | public final class MainActivityStarter { 21 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 22 | 23 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 24 | } 25 | 26 | public static void save(MainActivity activity, Bundle bundle) { 27 | bundle.putString(NAME_KEY, activity.getName()); 28 | } 29 | 30 | public static boolean isFilledValueOfNameFrom(MainActivity activity) { 31 | Intent intent = activity.getIntent(); 32 | return intent != null && intent.hasExtra(NAME_KEY); 33 | } 34 | 35 | public static String getValueOfNameFrom(MainActivity activity) { 36 | Intent intent = activity.getIntent(); 37 | return intent.getStringExtra(NAME_KEY); 38 | } 39 | 40 | public static Intent getIntent(Context context, String name) { 41 | Intent intent = new Intent(context, MainActivity.class); 42 | intent.putExtra(NAME_KEY, name); 43 | return intent; 44 | } 45 | 46 | public static void start(Context context, String name) { 47 | Intent intent = getIntent(context, name); 48 | context.startActivity(intent); 49 | } 50 | 51 | public static void startWithFlags(Context context, String name, int flags) { 52 | Intent intent = getIntent(context, name); 53 | intent.addFlags(flags); 54 | context.startActivity(intent); 55 | } 56 | } -------------------------------------------------------------------------------- /generationExamples/customId/Optional: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg(key = "SOME_OPTIONAL", optional = true) String name; 8 | } 9 | ********com.example.activitystarter.MainActivityStarter******** 10 | package com.example.activitystarter; 11 | 12 | import android.content.Context; 13 | import android.content.Intent; 14 | import android.os.Bundle; 15 | import java.lang.String; 16 | 17 | public final class MainActivityStarter { 18 | private static final String NAME_KEY = "SOME_OPTIONAL"; 19 | 20 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 21 | Intent intent = activity.getIntent(); 22 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 23 | activity.name = savedInstanceState.getString(NAME_KEY); 24 | } else {if(intent.hasExtra(NAME_KEY)) 25 | activity.name = intent.getStringExtra(NAME_KEY); 26 | }} 27 | 28 | public static void save(MainActivity activity, Bundle bundle) { 29 | bundle.putString(NAME_KEY, activity.name); 30 | } 31 | 32 | public static Intent getIntent(Context context, String name) { 33 | Intent intent = new Intent(context, MainActivity.class); 34 | intent.putExtra(NAME_KEY, name); 35 | return intent; 36 | } 37 | 38 | public static void start(Context context, String name) { 39 | Intent intent = getIntent(context, name); 40 | context.startActivity(intent); 41 | } 42 | 43 | public static void startWithFlags(Context context, String name, int flags) { 44 | Intent intent = getIntent(context, name); 45 | intent.addFlags(flags); 46 | context.startActivity(intent); 47 | } 48 | 49 | public static Intent getIntent(Context context) { 50 | Intent intent = new Intent(context, MainActivity.class); 51 | return intent; 52 | } 53 | 54 | public static void start(Context context) { 55 | Intent intent = getIntent(context); 56 | context.startActivity(intent); 57 | } 58 | 59 | public static void startWithFlags(Context context, int flags) { 60 | Intent intent = getIntent(context); 61 | intent.addFlags(flags); 62 | context.startActivity(intent); 63 | } 64 | } -------------------------------------------------------------------------------- /generationExamples/customId/Simple: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg(key = "SOME_NAME") String name; 8 | } 9 | ********com.example.activitystarter.MainActivityStarter******** 10 | package com.example.activitystarter; 11 | 12 | import android.content.Context; 13 | import android.content.Intent; 14 | import android.os.Bundle; 15 | import java.lang.String; 16 | 17 | public final class MainActivityStarter { 18 | private static final String NAME_KEY = "SOME_NAME"; 19 | 20 | /** 21 | * This is method used to fill fields. Use it by calling ActivityStarter.fill(this). */ 22 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 23 | Intent intent = activity.getIntent(); 24 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 25 | activity.name = savedInstanceState.getString(NAME_KEY); 26 | } else {if(intent.hasExtra(NAME_KEY)) 27 | activity.name = intent.getStringExtra(NAME_KEY); 28 | }} 29 | 30 | public static void save(MainActivity activity, Bundle bundle) { 31 | bundle.putString(NAME_KEY, activity.name); 32 | } 33 | 34 | public static Intent getIntent(Context context, String name) { 35 | Intent intent = new Intent(context, MainActivity.class); 36 | intent.putExtra(NAME_KEY, name); 37 | return intent; 38 | } 39 | 40 | public static void start(Context context, String name) { 41 | Intent intent = getIntent(context, name); 42 | context.startActivity(intent); 43 | } 44 | 45 | public static void startWithFlags(Context context, String name, int flags) { 46 | Intent intent = getIntent(context, name); 47 | intent.addFlags(flags); 48 | context.startActivity(intent); 49 | } 50 | } -------------------------------------------------------------------------------- /generationExamples/fragment/ConflictedOptional: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainFragment******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Fragment; 5 | 6 | import activitystarter.Arg; 7 | 8 | public class MainFragment extends Fragment { 9 | @Arg(optional = true) String name; 10 | @Arg(optional = true) String surname; 11 | } 12 | ********com.example.activitystarter.MainFragmentStarter******** 13 | package com.example.activitystarter; 14 | 15 | import android.os.Bundle; 16 | import java.lang.String; 17 | 18 | public final class MainFragmentStarter { 19 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 20 | 21 | private static final String SURNAME_KEY = "com.example.activitystarter.surnameStarterKey"; 22 | 23 | public static void fill(MainFragment fragment, Bundle savedInstanceState) { 24 | Bundle arguments = fragment.getArguments(); 25 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 26 | fragment.name = savedInstanceState.getString(NAME_KEY); 27 | } else {if(arguments != null && arguments.containsKey(NAME_KEY)) fragment.name = arguments.getString(NAME_KEY); 28 | }if(savedInstanceState != null && savedInstanceState.containsKey(SURNAME_KEY)) { 29 | fragment.surname = savedInstanceState.getString(SURNAME_KEY); 30 | } else {if(arguments != null && arguments.containsKey(SURNAME_KEY)) fragment.surname = arguments.getString(SURNAME_KEY); 31 | }} 32 | 33 | public static void save(MainFragment fragment, Bundle bundle) { 34 | bundle.putString(NAME_KEY, fragment.name); 35 | bundle.putString(SURNAME_KEY, fragment.surname); 36 | } 37 | 38 | public static MainFragment newInstance(String name, String surname) { 39 | MainFragment fragment = new MainFragment(); 40 | Bundle args = new Bundle(); 41 | args.putString(NAME_KEY, name); 42 | args.putString(SURNAME_KEY, surname); 43 | fragment.setArguments(args); 44 | return fragment; 45 | } 46 | 47 | public static MainFragment newInstance(String name) { 48 | MainFragment fragment = new MainFragment(); 49 | Bundle args = new Bundle(); 50 | args.putString(NAME_KEY, name); 51 | fragment.setArguments(args); 52 | return fragment; 53 | } 54 | 55 | public static MainFragment newInstance() { 56 | MainFragment fragment = new MainFragment(); 57 | return fragment; 58 | } 59 | } -------------------------------------------------------------------------------- /generationExamples/fragment/EmptyAnnotated: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainFragment******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Fragment; 5 | 6 | import activitystarter.MakeActivityStarter; 7 | 8 | @MakeActivityStarter 9 | public class MainFragment extends Fragment {} 10 | ********com.example.activitystarter.MainFragmentStarter******** 11 | package com.example.activitystarter; 12 | 13 | import android.os.Bundle; 14 | 15 | public final class MainFragmentStarter { 16 | 17 | public static void fill(MainFragment fragment, Bundle savedInstanceState) { 18 | } 19 | 20 | public static void save(MainFragment fragment, Bundle bundle) { 21 | } 22 | 23 | public static MainFragment newInstance() { 24 | MainFragment fragment = new MainFragment(); 25 | return fragment; 26 | } 27 | } -------------------------------------------------------------------------------- /generationExamples/fragment/MultipleOptional: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainFragment******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Fragment; 5 | 6 | import activitystarter.Arg; 7 | 8 | public class MainFragment extends Fragment { 9 | @Arg(optional = true) String name; 10 | @Arg(optional = true) int id; 11 | } 12 | ********com.example.activitystarter.MainFragmentStarter******** 13 | package com.example.activitystarter; 14 | 15 | import android.os.Bundle; 16 | import java.lang.String; 17 | 18 | public final class MainFragmentStarter { 19 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 20 | private static final String ID_KEY = "com.example.activitystarter.idStarterKey"; 21 | 22 | public static void fill(MainFragment fragment, Bundle savedInstanceState) { 23 | Bundle arguments = fragment.getArguments(); 24 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 25 | fragment.name = savedInstanceState.getString(NAME_KEY); 26 | } else {if(arguments != null && arguments.containsKey(NAME_KEY)) fragment.name = arguments.getString(NAME_KEY); 27 | }if(savedInstanceState != null && savedInstanceState.containsKey(ID_KEY)) { 28 | fragment.id = savedInstanceState.getInt(ID_KEY); 29 | } else {if(arguments != null && arguments.containsKey(ID_KEY)) fragment.id = arguments.getInt(ID_KEY); 30 | }} 31 | 32 | public static void save(MainFragment fragment, Bundle bundle) { 33 | bundle.putString(NAME_KEY, fragment.name); 34 | bundle.putInt(ID_KEY, fragment.id); 35 | } 36 | 37 | public static MainFragment newInstance(String name, int id) { 38 | MainFragment fragment = new MainFragment(); 39 | Bundle args = new Bundle(); 40 | args.putString(NAME_KEY, name); 41 | args.putInt(ID_KEY, id); 42 | fragment.setArguments(args); 43 | return fragment; 44 | } 45 | 46 | public static MainFragment newInstance(String name) { 47 | MainFragment fragment = new MainFragment(); 48 | Bundle args = new Bundle(); 49 | args.putString(NAME_KEY, name); 50 | fragment.setArguments(args); 51 | return fragment; 52 | } 53 | 54 | public static MainFragment newInstance(int id) { 55 | MainFragment fragment = new MainFragment(); 56 | Bundle args = new Bundle(); 57 | args.putInt(ID_KEY, id); 58 | fragment.setArguments(args); 59 | return fragment; 60 | } 61 | 62 | public static MainFragment newInstance() { 63 | MainFragment fragment = new MainFragment(); 64 | return fragment; 65 | } 66 | } -------------------------------------------------------------------------------- /generationExamples/fragment/Optional: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainFragment******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Fragment; 5 | 6 | import activitystarter.Arg; 7 | 8 | public class MainFragment extends Fragment { 9 | @Arg(optional = true) String name; 10 | } 11 | ********com.example.activitystarter.MainFragmentStarter******** 12 | package com.example.activitystarter; 13 | 14 | import android.os.Bundle; 15 | import java.lang.String; 16 | 17 | public final class MainFragmentStarter { 18 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 19 | 20 | public static void fill(MainFragment fragment, Bundle savedInstanceState) { 21 | Bundle arguments = fragment.getArguments(); 22 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 23 | fragment.name = savedInstanceState.getString(NAME_KEY); 24 | } else {if(arguments != null && arguments.containsKey(NAME_KEY)) fragment.name = arguments.getString(NAME_KEY); 25 | }} 26 | 27 | public static void save(MainFragment fragment, Bundle bundle) { 28 | bundle.putString(NAME_KEY, fragment.name); 29 | } 30 | 31 | public static MainFragment newInstance(String name) { 32 | MainFragment fragment = new MainFragment(); 33 | Bundle args = new Bundle(); 34 | args.putString(NAME_KEY, name); 35 | fragment.setArguments(args); 36 | return fragment; 37 | } 38 | 39 | public static MainFragment newInstance() { 40 | MainFragment fragment = new MainFragment(); 41 | return fragment; 42 | } 43 | } -------------------------------------------------------------------------------- /generationExamples/fragment/SetterGetter: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainFragment******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Fragment; 5 | 6 | import activitystarter.Arg; 7 | 8 | public class MainFragment extends Fragment { 9 | 10 | @Arg private String name; 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | } 20 | ********com.example.activitystarter.MainFragmentStarter******** 21 | package com.example.activitystarter; 22 | 23 | import android.os.Bundle; 24 | import java.lang.String; 25 | 26 | public final class MainFragmentStarter { 27 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 28 | 29 | public static void fill(MainFragment fragment, Bundle savedInstanceState) { 30 | Bundle arguments = fragment.getArguments(); 31 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 32 | fragment.setName(savedInstanceState.getString(NAME_KEY)); 33 | } else {if(arguments != null && arguments.containsKey(NAME_KEY)) fragment.setName(arguments.getString(NAME_KEY)); 34 | }} 35 | 36 | public static void save(MainFragment fragment, Bundle bundle) { 37 | bundle.putString(NAME_KEY, fragment.getName()); 38 | } 39 | 40 | public static MainFragment newInstance(String name) { 41 | MainFragment fragment = new MainFragment(); 42 | Bundle args = new Bundle(); 43 | args.putString(NAME_KEY, name); 44 | fragment.setArguments(args); 45 | return fragment; 46 | } 47 | } -------------------------------------------------------------------------------- /generationExamples/fragment/Simple: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainFragment******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Fragment; 5 | 6 | import activitystarter.Arg; 7 | 8 | public class MainFragment extends Fragment { 9 | @Arg String name; 10 | } 11 | ********com.example.activitystarter.MainFragmentStarter******** 12 | package com.example.activitystarter; 13 | 14 | import android.os.Bundle; 15 | import java.lang.String; 16 | 17 | public final class MainFragmentStarter { 18 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 19 | 20 | public static void fill(MainFragment fragment, Bundle savedInstanceState) { 21 | Bundle arguments = fragment.getArguments(); 22 | if(savedInstanceState != null && savedInstanceState.containsKey(NAME_KEY)) { 23 | fragment.name = savedInstanceState.getString(NAME_KEY); 24 | } else {if(arguments != null && arguments.containsKey(NAME_KEY)) fragment.name = arguments.getString(NAME_KEY); 25 | }} 26 | 27 | public static void save(MainFragment fragment, Bundle bundle) { 28 | bundle.putString(NAME_KEY, fragment.name); 29 | } 30 | 31 | public static MainFragment newInstance(String name) { 32 | MainFragment fragment = new MainFragment(); 33 | Bundle args = new Bundle(); 34 | args.putString(NAME_KEY, name); 35 | fragment.setArguments(args); 36 | return fragment; 37 | } 38 | } -------------------------------------------------------------------------------- /generationExamples/parceler/Simple: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | import org.parceler.Parcel; 6 | 7 | public class MainActivity extends Activity { 8 | 9 | @Arg(parceler = true) StudentParcel studentParceler; 10 | 11 | @Parcel 12 | public static class StudentParcel { 13 | 14 | private int id; 15 | private String name; 16 | private char grade; 17 | 18 | public StudentParcel() { 19 | } 20 | 21 | public StudentParcel(int id, String name, char grade) { 22 | this.id = id; 23 | this.name = name; 24 | this.grade = grade; 25 | } 26 | 27 | public int getId() { 28 | return id; 29 | } 30 | 31 | public void setId(int id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public char getGrade() { 44 | return grade; 45 | } 46 | 47 | public void setGrade(char grade) { 48 | this.grade = grade; 49 | } 50 | } 51 | } 52 | ********com.example.activitystarter.MainActivityStarter******** 53 | package com.example.activitystarter; 54 | 55 | import android.content.Context; 56 | import android.content.Intent; 57 | import android.os.Bundle; 58 | import java.lang.String; 59 | 60 | public final class MainActivityStarter { 61 | private static final String STUDENT_PARCELER_KEY = "com.example.activitystarter.studentParcelerStarterKey"; 62 | 63 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 64 | Intent intent = activity.getIntent(); 65 | if(savedInstanceState != null && savedInstanceState.containsKey(STUDENT_PARCELER_KEY)) { 66 | activity.studentParceler = (MainActivity.StudentParcel) org.parceler.Parcels.unwrap(savedInstanceState.getParcelable(STUDENT_PARCELER_KEY)); 67 | } else {if(intent.hasExtra(STUDENT_PARCELER_KEY)) 68 | activity.studentParceler = (MainActivity.StudentParcel) org.parceler.Parcels.unwrap(intent.getParcelableExtra(STUDENT_PARCELER_KEY)); 69 | }} 70 | 71 | public static void save(MainActivity activity, Bundle bundle) { 72 | bundle.putParcelable(STUDENT_PARCELER_KEY, org.parceler.Parcels.wrap(activity.studentParceler)); 73 | } 74 | 75 | public static Intent getIntent(Context context, MainActivity.StudentParcel studentParceler) { 76 | Intent intent = new Intent(context, MainActivity.class); 77 | intent.putExtra(STUDENT_PARCELER_KEY, org.parceler.Parcels.wrap(studentParceler)); 78 | return intent; 79 | } 80 | 81 | public static void start(Context context, MainActivity.StudentParcel studentParceler) { 82 | Intent intent = getIntent(context, studentParceler); 83 | context.startActivity(intent); 84 | } 85 | 86 | public static void startWithFlags(Context context, MainActivity.StudentParcel studentParceler, int flags) { 87 | Intent intent = getIntent(context, studentParceler); 88 | intent.addFlags(flags); 89 | context.startActivity(intent); 90 | } 91 | } -------------------------------------------------------------------------------- /generationExamples/service/Complex: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.SomeService******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Service; 5 | import android.content.Intent; 6 | import android.os.IBinder; 7 | import android.util.Log; 8 | 9 | import activitystarter.ActivityStarter; 10 | import activitystarter.Arg; 11 | 12 | public class SomeService extends Service { 13 | 14 | @Arg(optional = true) String name = ""; 15 | @Arg(optional = true) String surname = ""; 16 | @Arg int id; 17 | 18 | public SomeService() {} 19 | 20 | @Override 21 | public IBinder onBind(Intent intent) { 22 | return null; 23 | } 24 | } 25 | ********com.example.activitystarter.SomeService******** 26 | package com.example.activitystarter; 27 | 28 | import android.content.Context; 29 | import android.content.Intent; 30 | import java.lang.String; 31 | 32 | public final class SomeServiceStarter { 33 | 34 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 35 | private static final String SURNAME_KEY = "com.example.activitystarter.surnameStarterKey"; 36 | private static final String ID_KEY = "com.example.activitystarter.idStarterKey"; 37 | 38 | public static void fill(SomeService service, Intent intent) { 39 | if(intent == null) return; 40 | if(intent.hasExtra(NAME_KEY)) 41 | service.name = intent.getStringExtra(NAME_KEY); 42 | if(intent.hasExtra(SURNAME_KEY)) 43 | service.surname = intent.getStringExtra(SURNAME_KEY); 44 | if(intent.hasExtra(ID_KEY)) 45 | service.id = intent.getIntExtra(ID_KEY, -1); 46 | } 47 | 48 | public static Intent getIntent(Context context, String name, String surname, int id) { 49 | Intent intent = new Intent(context, SomeService.class); 50 | intent.putExtra(NAME_KEY, name); 51 | intent.putExtra(SURNAME_KEY, surname); 52 | intent.putExtra(ID_KEY, id); 53 | return intent; 54 | } 55 | 56 | public static void start(Context context, String name, String surname, int id) { 57 | Intent intent = getIntent(context, name, surname, id); 58 | context.startService(intent); 59 | } 60 | 61 | public static Intent getIntent(Context context, String name, int id) { 62 | Intent intent = new Intent(context, SomeService.class); 63 | intent.putExtra(NAME_KEY, name); 64 | intent.putExtra(ID_KEY, id); 65 | return intent; 66 | } 67 | 68 | public static void start(Context context, String name, int id) { 69 | Intent intent = getIntent(context, name, id); 70 | context.startService(intent); 71 | } 72 | 73 | public static Intent getIntent(Context context, int id) { 74 | Intent intent = new Intent(context, SomeService.class); 75 | intent.putExtra(ID_KEY, id); 76 | return intent; 77 | } 78 | 79 | public static void start(Context context, int id) { 80 | Intent intent = getIntent(context, id); 81 | context.startService(intent); 82 | } 83 | } -------------------------------------------------------------------------------- /generationExamples/service/EmptyAnnotated: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.SomeService******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Service; 5 | import android.content.Intent; 6 | import android.os.IBinder; 7 | import android.support.annotation.Nullable; 8 | 9 | import activitystarter.Arg; 10 | import activitystarter.MakeActivityStarter; 11 | 12 | @MakeActivityStarter 13 | public class SomeService extends Service { 14 | 15 | @Nullable 16 | @Override 17 | public IBinder onBind(Intent intent) { 18 | return null; 19 | } 20 | } 21 | ********com.example.activitystarter.SomeService******** 22 | // Generated code from ActivityStarter. Do not modify! 23 | package com.example.activitystarter; 24 | 25 | import android.content.Context; 26 | import android.content.Intent; 27 | 28 | public final class SomeServiceStarter { 29 | public static void fill(SomeService service, Intent intent) { 30 | if(intent == null) return; 31 | } 32 | 33 | public static Intent getIntent(Context context) { 34 | Intent intent = new Intent(context, SomeService.class); 35 | return intent; 36 | } 37 | 38 | public static void start(Context context) { 39 | Intent intent = getIntent(context); 40 | context.startService(intent); 41 | } 42 | } -------------------------------------------------------------------------------- /generationExamples/service/Simple: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.SomeService******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Service; 5 | import android.content.Intent; 6 | import android.os.IBinder; 7 | import android.support.annotation.Nullable; 8 | 9 | import activitystarter.Arg; 10 | import activitystarter.MakeActivityStarter; 11 | 12 | @MakeActivityStarter 13 | public class SomeService extends Service { 14 | 15 | @Arg String name = ""; 16 | 17 | @Nullable 18 | @Override 19 | public IBinder onBind(Intent intent) { 20 | return null; 21 | } 22 | } 23 | ********com.example.activitystarter.SomeService******** 24 | package com.example.activitystarter; 25 | 26 | import android.content.Context; 27 | import android.content.Intent; 28 | import java.lang.String; 29 | 30 | public final class SomeServiceStarter { 31 | 32 | private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey"; 33 | 34 | public static void fill(SomeService service, Intent intent) { 35 | if(intent == null) return; 36 | if(intent.hasExtra(NAME_KEY)) 37 | service.name = intent.getStringExtra(NAME_KEY); 38 | } 39 | 40 | public static Intent getIntent(Context context, String name) { 41 | Intent intent = new Intent(context, SomeService.class); 42 | intent.putExtra(NAME_KEY, name); 43 | return intent; 44 | } 45 | 46 | public static void start(Context context, String name) { 47 | Intent intent = getIntent(context, name); 48 | context.startService(intent); 49 | } 50 | } -------------------------------------------------------------------------------- /generationExamples/shouldThrowError/ActivityPrivateFIeld: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg private String name; 8 | } -------------------------------------------------------------------------------- /generationExamples/shouldThrowError/ActivityWithObjectToParcelableWithoutInterfaceConverter: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.ActivityWithConverters******** 2 | package com.example.activitystarter; 3 | 4 | import android.app.Activity; 5 | 6 | import com.marcinmoskala.activitystarterparcelerargconverter.IsParcel; 7 | import com.marcinmoskala.activitystarterparcelerargconverter.ParcelerArgConverter; 8 | 9 | import org.parceler.Parcel; 10 | 11 | import activitystarter.ActivityStarterConfig; 12 | import activitystarter.Arg; 13 | 14 | @ActivityStarterConfig(converters = {ParcelerArgConverter.class}) 15 | public class ActivityWithConverters extends Activity { 16 | 17 | @Arg StudentParcel studentParceler; 18 | 19 | @Parcel 20 | public static class StudentParcel { 21 | 22 | private int id; 23 | private String name; 24 | private char grade; 25 | 26 | public StudentParcel() { 27 | } 28 | 29 | public StudentParcel(int id, String name, char grade) { 30 | this.id = id; 31 | this.name = name; 32 | this.grade = grade; 33 | } 34 | 35 | public int getId() { 36 | return id; 37 | } 38 | 39 | public void setId(int id) { 40 | this.id = id; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public char getGrade() { 52 | return grade; 53 | } 54 | 55 | public void setGrade(char grade) { 56 | this.grade = grade; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /generationExamples/shouldThrowError/GetterOnly: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg private String name; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | } -------------------------------------------------------------------------------- /generationExamples/shouldThrowError/List: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | 5 | import java.util.List; 6 | 7 | import activitystarter.Arg; 8 | 9 | public class MainActivity extends Activity { 10 | @Arg List name; 11 | } -------------------------------------------------------------------------------- /generationExamples/shouldThrowError/PrivateClass: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | 5 | import java.util.List; 6 | 7 | import activitystarter.Arg; 8 | 9 | class SuperClass { 10 | private class MainActivity extends Activity { 11 | @Arg 12 | List name; 13 | } 14 | } -------------------------------------------------------------------------------- /generationExamples/shouldThrowError/ServiceParcelableField: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter.MainActivity; 3 | 4 | import activitystarter.Arg; 5 | import android.content.BroadcastReceiver; 6 | import android.os.Parcelable; 7 | 8 | import android.content.Context; 9 | import android.content.Intent; 10 | 11 | public class MainActivity extends BroadcastReceiver { 12 | 13 | @Arg Parcelable time; 14 | 15 | @Override public void onReceive(Context context, Intent intent) { 16 | } 17 | } -------------------------------------------------------------------------------- /generationExamples/shouldThrowError/SetterOnly: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | import android.app.Activity; 4 | import activitystarter.Arg; 5 | 6 | public class MainActivity extends Activity { 7 | @Arg private String name; 8 | 9 | public void setName(String name) { 10 | this.name = name; 11 | } 12 | } -------------------------------------------------------------------------------- /generationExamples/withConverters/ActivityWithIntToLongConverter: -------------------------------------------------------------------------------- 1 | ********com.example.activitystarter.MainActivity******** 2 | package com.example.activitystarter; 3 | 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import java.lang.annotation.Annotation; 8 | 9 | import activitystarter.ActivityStarterConfig; 10 | import activitystarter.Arg; 11 | import activitystarter.wrapping.ArgConverter; 12 | 13 | @ActivityStarterConfig(converters = { MainActivity.IntToLongConverter.class }) 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | @Arg int l; 17 | 18 | static class IntToLongConverter implements ArgConverter { 19 | 20 | @Override 21 | public Long wrap(Integer toWrap) { 22 | return toWrap.longValue(); 23 | } 24 | 25 | @Override 26 | public Integer unwrap(Long wrapped) { 27 | return wrapped.intValue(); 28 | } 29 | } 30 | } 31 | ********com.example.activitystarter.MainActivityStarter******** 32 | package com.example.activitystarter; 33 | 34 | import android.content.Context; 35 | import android.content.Intent; 36 | import android.os.Bundle; 37 | import java.lang.String; 38 | 39 | public final class MainActivityStarter { 40 | private static final String L_KEY = "com.example.activitystarter.lStarterKey"; 41 | 42 | public static void fill(MainActivity activity, Bundle savedInstanceState) { 43 | Intent intent = activity.getIntent(); 44 | if(savedInstanceState != null && savedInstanceState.containsKey(L_KEY)) { 45 | activity.l = new com.example.activitystarter.MainActivity.IntToLongConverter().unwrap(savedInstanceState.getLong(L_KEY)); 46 | } else {if(intent.hasExtra(L_KEY)) 47 | activity.l = new com.example.activitystarter.MainActivity.IntToLongConverter().unwrap(intent.getLongExtra(L_KEY, -1L)); 48 | }} 49 | 50 | public static void save(MainActivity activity, Bundle bundle) { 51 | bundle.putLong(L_KEY, new com.example.activitystarter.MainActivity.IntToLongConverter().wrap(activity.l)); 52 | } 53 | 54 | public static Intent getIntent(Context context, int l) { 55 | Intent intent = new Intent(context, MainActivity.class); 56 | intent.putExtra(L_KEY, new com.example.activitystarter.MainActivity.IntToLongConverter().wrap(l)); 57 | return intent; 58 | } 59 | 60 | public static void start(Context context, int l) { 61 | Intent intent = getIntent(context, l); 62 | context.startActivity(intent); 63 | } 64 | 65 | public static void startWithFlags(Context context, int l, int flags) { 66 | Intent intent = getIntent(context, l); 67 | intent.addFlags(flags); 68 | context.startActivity(intent); 69 | } 70 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | GROUP=com.marcinmoskala 2 | VERSION_NAME=8.4.1-SNAPSHOT 3 | 4 | POM_DESCRIPTION=Field and method binding for Android views. 5 | 6 | POM_URL=https://github.com/MarcinMoskala/activitystarter/ 7 | POM_SCM_URL=https://github.com/MarcinMoskala/activitystarter/ 8 | POM_SCM_CONNECTION=scm:git:git://github.com/MarcinMoskala/activitystarter.git 9 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/MarcinMoskala/activitystarter.git 10 | 11 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 12 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 13 | POM_LICENCE_DIST=repo 14 | 15 | POM_DEVELOPER_ID=marcinmoskala 16 | POM_DEVELOPER_NAME=Marcin Moskala 17 | 18 | org.gradle.configureondemand=false -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarcinMoskala/ActivityStarter/ebeb6d6f575c33f414c7e3725a1c2543ebb07bda/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Apr 01 21:39:09 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows argumentModelVariants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /sample/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '27.0.3' 6 | 7 | defaultConfig { 8 | applicationId "com.example.activitystarter" 9 | minSdkVersion 18 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation project(':activitystarter') 27 | annotationProcessor project(':activitystarter-compiler') 28 | 29 | // In real project use this: 30 | // compile 'com.github.marcinmoskala.activitystarter:activitystarter:0.50' 31 | // annotationProcessor 'com.github.marcinmoskala.activitystarter:activitystarter-compiler:0.50' 32 | 33 | implementation 'com.jakewharton:butterknife:8.5.1' 34 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 35 | 36 | implementation 'com.android.support:appcompat-v7:25.1.0' 37 | implementation 'com.android.support:design:25.1.0' 38 | 39 | implementation 'org.parceler:parceler-api:1.1.8' 40 | annotationProcessor 'org.parceler:parceler:1.1.8' 41 | 42 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 43 | exclude group: 'com.android.support', module: 'support-annotations' 44 | }) 45 | testImplementation deps.junit 46 | androidTestImplementation deps.uiAutomator 47 | } 48 | repositories { 49 | mavenCentral() 50 | // Remember about this: 51 | // maven { url 'https://jitpack.io' } 52 | } -------------------------------------------------------------------------------- /sample/app/src/androidTest/java/com/example/activitystarter/ClickableExampleTest.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | 4 | import android.support.test.rule.ActivityTestRule; 5 | import android.support.test.runner.AndroidJUnit4; 6 | import android.test.suitebuilder.annotation.LargeTest; 7 | 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | 12 | import static android.support.test.espresso.Espresso.onView; 13 | import static android.support.test.espresso.action.ViewActions.click; 14 | import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; 15 | import static android.support.test.espresso.action.ViewActions.replaceText; 16 | import static android.support.test.espresso.action.ViewActions.scrollTo; 17 | import static android.support.test.espresso.assertion.ViewAssertions.matches; 18 | import static android.support.test.espresso.matcher.ViewMatchers.isChecked; 19 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 20 | import static android.support.test.espresso.matcher.ViewMatchers.withText; 21 | import static org.hamcrest.Matchers.not; 22 | 23 | @LargeTest 24 | @RunWith(AndroidJUnit4.class) 25 | public class ClickableExampleTest { 26 | 27 | @Rule 28 | public ActivityTestRule activityTestRule = new ActivityTestRule<>(MainActivity.class); 29 | 30 | @Test 31 | public void defaultDataActivityTest() throws InterruptedException { 32 | onView(withId(R.id.student_grade)).perform(scrollTo(), replaceText("A"), closeSoftKeyboard()); 33 | 34 | onView(withId(R.id.show_data_button)).perform(scrollTo(), click()); 35 | 36 | onView(withId(R.id.student_name)).check(matches(withText("No name provided"))); 37 | onView(withId(R.id.student_id)).check(matches(withText("-1"))); 38 | onView(withId(R.id.student_grade)).check(matches(withText("A"))); 39 | onView(withId(R.id.student_is_passing)).check(matches(not(isChecked()))); 40 | } 41 | 42 | @Test 43 | public void dataActivityTest() throws InterruptedException { 44 | onView(withId(R.id.student_name)).perform(scrollTo(), replaceText("Marcin"), closeSoftKeyboard()); 45 | onView(withId(R.id.student_id)).perform(scrollTo(), replaceText("123"), closeSoftKeyboard()); 46 | onView(withId(R.id.student_grade)).perform(scrollTo(), replaceText("A"), closeSoftKeyboard()); 47 | onView(withId(R.id.student_is_passing)).perform(scrollTo(), click()); 48 | 49 | onView(withId(R.id.show_data_button)).perform(scrollTo(), click()); 50 | 51 | onView(withId(R.id.student_name)).check(matches(withText("Marcin"))); 52 | onView(withId(R.id.student_id)).check(matches(withText("123"))); 53 | onView(withId(R.id.student_grade)).check(matches(withText("A"))); 54 | onView(withId(R.id.student_is_passing)).check(matches(isChecked())); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sample/app/src/androidTest/java/com/example/activitystarter/NonSavingTest.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.pm.ActivityInfo; 7 | import android.content.res.Configuration; 8 | import android.support.test.InstrumentationRegistry; 9 | import android.support.test.rule.ActivityTestRule; 10 | import android.support.test.runner.AndroidJUnit4; 11 | 12 | import com.example.activitystarter.savetest.NonSavingActivity; 13 | import com.example.activitystarter.savetest.SavingActivity; 14 | 15 | import org.junit.Rule; 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | 19 | import static android.support.test.espresso.Espresso.onView; 20 | import static android.support.test.espresso.assertion.ViewAssertions.matches; 21 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 22 | import static android.support.test.espresso.matcher.ViewMatchers.withText; 23 | import static org.junit.Assert.assertEquals; 24 | 25 | @RunWith(AndroidJUnit4.class) 26 | public class NonSavingTest { 27 | 28 | @Rule 29 | public ActivityTestRule activityTestRule = new ActivityTestRule<>(NonSavingActivity.class); 30 | 31 | @Test 32 | public void startTest() throws InterruptedException { 33 | onView(withId(R.id.i)).check(matches(withText("" + SavingActivity.DEFAULT_I))); 34 | onView(withId(R.id.str)).check(matches(withText("" + SavingActivity.DEFAULT_STR))); 35 | onView(withId(R.id.b)).check(matches(withText("" + SavingActivity.DEFAULT_B))); 36 | 37 | final NonSavingActivity activity = activityTestRule.getActivity(); 38 | activity.i = SavingActivity.NEW_I; 39 | activity.str = SavingActivity.NEW_STR; 40 | activity.b = SavingActivity.NEW_B; 41 | 42 | rotateScreen(); 43 | rotateScreen(); 44 | 45 | Thread.sleep(500); 46 | 47 | onView(withId(R.id.i)).check(matches(withText("" + SavingActivity.DEFAULT_I))); 48 | onView(withId(R.id.str)).check(matches(withText("" + SavingActivity.DEFAULT_STR))); 49 | onView(withId(R.id.b)).check(matches(withText("" + SavingActivity.DEFAULT_B))); 50 | } 51 | 52 | private void rotateScreen() { 53 | Context context = InstrumentationRegistry.getTargetContext(); 54 | int orientation = context.getResources().getConfiguration().orientation; 55 | activityTestRule.getActivity() 56 | .setRequestedOrientation( 57 | (orientation == Configuration.ORIENTATION_PORTRAIT) ? 58 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : 59 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT 60 | ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sample/app/src/androidTest/java/com/example/activitystarter/SavingTest.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.pm.ActivityInfo; 7 | import android.content.res.Configuration; 8 | import android.support.test.InstrumentationRegistry; 9 | import android.support.test.rule.ActivityTestRule; 10 | import android.support.test.runner.AndroidJUnit4; 11 | 12 | import com.example.activitystarter.savetest.SavingActivity; 13 | 14 | import org.junit.Rule; 15 | import org.junit.Test; 16 | import org.junit.runner.RunWith; 17 | 18 | import static android.support.test.espresso.Espresso.onView; 19 | import static android.support.test.espresso.assertion.ViewAssertions.matches; 20 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 21 | import static android.support.test.espresso.matcher.ViewMatchers.withText; 22 | 23 | @RunWith(AndroidJUnit4.class) 24 | public class SavingTest { 25 | 26 | @Rule 27 | public ActivityTestRule activityTestRule = new ActivityTestRule<>(SavingActivity.class); 28 | 29 | @Test 30 | public void savingTest() throws InterruptedException { 31 | onView(withId(R.id.i)).check(matches(withText("" + SavingActivity.DEFAULT_I))); 32 | onView(withId(R.id.str)).check(matches(withText("" + SavingActivity.DEFAULT_STR))); 33 | onView(withId(R.id.b)).check(matches(withText("" + SavingActivity.DEFAULT_B))); 34 | 35 | final SavingActivity activity = activityTestRule.getActivity(); 36 | activity.i = SavingActivity.NEW_I; 37 | activity.str = SavingActivity.NEW_STR; 38 | activity.b = SavingActivity.NEW_B; 39 | 40 | Thread.sleep(500); 41 | 42 | rotateScreen(); 43 | 44 | Thread.sleep(500); 45 | 46 | rotateScreen(); 47 | 48 | Thread.sleep(500); 49 | 50 | onView(withId(R.id.i)).check(matches(withText("" + SavingActivity.NEW_I))); 51 | onView(withId(R.id.str)).check(matches(withText("" + SavingActivity.NEW_STR))); 52 | onView(withId(R.id.b)).check(matches(withText("" + SavingActivity.NEW_B))); 53 | } 54 | 55 | private void rotateScreen() { 56 | Context context = InstrumentationRegistry.getTargetContext(); 57 | int orientation = context.getResources().getConfiguration().orientation; 58 | activityTestRule.getActivity() 59 | .setRequestedOrientation( 60 | (orientation == Configuration.ORIENTATION_PORTRAIT) ? 61 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : 62 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 29 | 32 | 35 | 38 | 42 | 43 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/AllTypesActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | import com.example.activitystarter.parcelable.StudentParcelable; 4 | import com.example.activitystarter.serializable.StudentSerializable; 5 | 6 | import java.util.ArrayList; 7 | 8 | import activitystarter.Arg; 9 | 10 | public class AllTypesActivity extends BaseActivity { 11 | 12 | @Arg String str; 13 | @Arg int i; 14 | @Arg long l; 15 | @Arg float f; 16 | @Arg boolean bool; 17 | @Arg double d; 18 | @Arg char c; 19 | @Arg byte b; 20 | @Arg short s; 21 | @Arg CharSequence cs; 22 | 23 | @Arg String[] stra; 24 | @Arg int[] ia; 25 | @Arg long[] la; 26 | @Arg float[] fa; 27 | @Arg boolean[] boola; 28 | @Arg double[] da; 29 | @Arg char[] ca; 30 | @Arg byte[] ba; 31 | @Arg short[] sa; 32 | @Arg CharSequence[] csa; 33 | 34 | @Arg ArrayList intList; 35 | @Arg ArrayList strList; 36 | @Arg ArrayList csList; 37 | 38 | @Arg StudentParcelable sp; 39 | @Arg StudentSerializable ss; 40 | 41 | @Arg ArrayList spList; 42 | } -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import activitystarter.ActivityStarter; 7 | 8 | 9 | public class BaseActivity extends AppCompatActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | ActivityStarter.fill(this, savedInstanceState); 15 | } 16 | 17 | @Override 18 | protected void onSaveInstanceState(Bundle outState) { 19 | ActivityStarter.save(this, outState); 20 | super.onSaveInstanceState(outState); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/SavingTestActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.TextView; 8 | 9 | import activitystarter.ActivityStarter; 10 | import activitystarter.Arg; 11 | 12 | public class SavingTestActivity extends AppCompatActivity { 13 | 14 | @Arg(optional = true) 15 | int value = 0; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_saving_test); 21 | ActivityStarter.fill(this, savedInstanceState); 22 | 23 | final Button incrementButton = (Button) findViewById(R.id.increment); 24 | final TextView valueDisplay = (TextView) findViewById(R.id.value); 25 | 26 | valueDisplay.setText("" + value); 27 | incrementButton.setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View view) { 30 | value++; 31 | valueDisplay.setText("" + value); 32 | } 33 | }); 34 | } 35 | 36 | @Override 37 | protected void onSaveInstanceState(Bundle outState) { 38 | super.onSaveInstanceState(outState); 39 | ActivityStarter.save(this, outState); 40 | } 41 | } -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/SomeService.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.IBinder; 6 | import android.util.Log; 7 | 8 | import activitystarter.ActivityStarter; 9 | import activitystarter.Arg; 10 | 11 | public class SomeService extends Service { 12 | 13 | public static final String NAME_KEY = "NAME_KEY"; 14 | 15 | @Arg(key = NAME_KEY, optional = true) String name = ""; 16 | @Arg(optional = true) String surname = ""; 17 | @Arg int id; 18 | 19 | public SomeService() {} 20 | 21 | @Override 22 | public IBinder onBind(Intent intent) { 23 | return null; 24 | } 25 | 26 | @Override 27 | public int onStartCommand(Intent intent, int flags, int startId) { 28 | ActivityStarter.fill(this, intent); 29 | Log.i("SomeService:", "Name: " + name + ", id: " + id); 30 | return super.onStartCommand(intent, flags, startId); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/StudentDataActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.Button; 6 | import android.widget.EditText; 7 | import android.widget.Switch; 8 | 9 | import activitystarter.Arg; 10 | import activitystarter.MakeActivityStarter; 11 | import butterknife.BindView; 12 | import butterknife.ButterKnife; 13 | 14 | @MakeActivityStarter 15 | public class StudentDataActivity extends BaseActivity { 16 | 17 | private static int NO_ID = -1; 18 | public static int DEFAULT_ID = NO_ID; 19 | public static String DEFAULT_NAME = "No name provided"; 20 | 21 | @Arg(optional = true) String name = DEFAULT_NAME; 22 | @Arg(optional = true) int id = DEFAULT_ID; 23 | @Arg char grade; 24 | @Arg boolean passing; 25 | 26 | @BindView(R.id.student_name) EditText studentNameView; 27 | @BindView(R.id.student_id) EditText studentIdView; 28 | @BindView(R.id.student_grade) EditText studentGradeView; 29 | @BindView(R.id.student_is_passing) Switch studentIsPassingView; 30 | @BindView(R.id.save_button) Button saveButton; 31 | @BindView(R.id.restore_button) Button restoreButton; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_data); 37 | ButterKnife.bind(this); 38 | 39 | fill(); 40 | 41 | saveButton.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View v) { 44 | name = studentNameView.getText().toString(); 45 | id = Integer.parseInt(studentIdView.getText().toString()); 46 | grade = studentGradeView.getText().toString().charAt(0); 47 | passing = studentIsPassingView.isChecked(); 48 | } 49 | }); 50 | restoreButton.setOnClickListener(new View.OnClickListener() { 51 | @Override 52 | public void onClick(View v) { 53 | fill(); 54 | } 55 | }); 56 | } 57 | 58 | private void fill() { 59 | studentNameView.setText(name); 60 | studentIdView.setText(""+id); 61 | studentGradeView.setText(""+grade); 62 | studentIsPassingView.setChecked(passing); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/fragment/TabbedFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | import android.support.v4.view.ViewPager; 8 | import android.support.v7.app.AppCompatActivity; 9 | 10 | import com.example.activitystarter.R; 11 | 12 | import activitystarter.ActivityStarter; 13 | import activitystarter.MakeActivityStarter; 14 | 15 | @MakeActivityStarter 16 | public class TabbedFragmentActivity extends AppCompatActivity { 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_tabbed_fragment); 22 | SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); 23 | ViewPager mViewPager = (ViewPager) findViewById(R.id.container); 24 | mViewPager.setAdapter(mSectionsPagerAdapter); 25 | } 26 | 27 | public class SectionsPagerAdapter extends FragmentPagerAdapter { 28 | 29 | SectionsPagerAdapter(FragmentManager fm) { 30 | super(fm); 31 | } 32 | 33 | @Override 34 | public Fragment getItem(int position) { 35 | return TabbedPlaceholderFragmentStarter.newInstance(position + 1); 36 | } 37 | 38 | @Override 39 | public int getCount() { 40 | return 3; 41 | } 42 | 43 | @Override 44 | public CharSequence getPageTitle(int position) { 45 | switch (position) { 46 | case 0:return "SECTION 1"; 47 | case 1:return "SECTION 2"; 48 | case 2:return "SECTION 3"; 49 | } 50 | return null; 51 | } 52 | } 53 | 54 | @Override 55 | protected void onSaveInstanceState(Bundle outState) { 56 | super.onSaveInstanceState(outState); 57 | ActivityStarter.save(this, outState); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/fragment/TabbedPlaceholderFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import com.example.activitystarter.R; 11 | 12 | import activitystarter.ActivityStarter; 13 | import activitystarter.Arg; 14 | 15 | public class TabbedPlaceholderFragment extends Fragment { 16 | 17 | @Arg int sectionNumber; 18 | 19 | public TabbedPlaceholderFragment() {} 20 | 21 | @Override 22 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 23 | View rootView = inflater.inflate(R.layout.fragment_tabbed, container, false); 24 | ActivityStarter.fill(this, savedInstanceState); 25 | final TextView textView = (TextView) rootView.findViewById(R.id.section_label); 26 | textView.setOnClickListener(new View.OnClickListener() { 27 | @Override 28 | public void onClick(View v) { 29 | ++sectionNumber; 30 | textView.setText(getString(R.string.section_format, sectionNumber)); 31 | } 32 | }); 33 | textView.setText(getString(R.string.section_format, sectionNumber)); 34 | return rootView; 35 | } 36 | 37 | @Override 38 | public void onSaveInstanceState(Bundle outState) { 39 | super.onSaveInstanceState(outState); 40 | ActivityStarter.save(this, outState); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/parcelable/StudentParcelable.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.parcelable; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | public class StudentParcelable implements Parcelable { 7 | 8 | private int id; 9 | private String name; 10 | private char grade; 11 | 12 | // Constructor 13 | public StudentParcelable(int id, String name, char grade) { 14 | this.id = id; 15 | this.name = name; 16 | this.grade = grade; 17 | } 18 | 19 | // Getter and setter methods 20 | public int getId() { 21 | return id; 22 | } 23 | 24 | public void setId(int id) { 25 | this.id = id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public char getGrade() { 37 | return grade; 38 | } 39 | 40 | public void setGrade(char grade) { 41 | this.grade = grade; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "{id:" + id + ", name: " + name + ", grade: " + grade + "}"; 47 | } 48 | 49 | // Parcelling part 50 | public StudentParcelable(Parcel in) { 51 | String[] data = new String[3]; 52 | 53 | in.readStringArray(data); 54 | this.id = Integer.parseInt(data[0]); 55 | this.name = data[1]; 56 | this.grade = data[2].charAt(0); 57 | } 58 | 59 | @Override 60 | public int describeContents() { 61 | return 0; 62 | } 63 | 64 | @Override 65 | public void writeToParcel(Parcel dest, int flags) { 66 | dest.writeStringArray(new String[]{ 67 | "" + this.id, 68 | this.name, 69 | "" + this.grade}); 70 | } 71 | 72 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 73 | public StudentParcelable createFromParcel(Parcel in) { 74 | return new StudentParcelable(in); 75 | } 76 | 77 | public StudentParcelable[] newArray(int size) { 78 | return new StudentParcelable[size]; 79 | } 80 | }; 81 | 82 | @Override 83 | public boolean equals(Object o) { 84 | if (this == o) return true; 85 | if (o == null || getClass() != o.getClass()) return false; 86 | 87 | StudentParcelable that = (StudentParcelable) o; 88 | 89 | if (id != that.id) return false; 90 | if (grade != that.grade) return false; 91 | return name != null ? name.equals(that.name) : that.name == null; 92 | 93 | } 94 | 95 | @Override 96 | public int hashCode() { 97 | int result = id; 98 | result = 31 * result + (name != null ? name.hashCode() : 0); 99 | result = 31 * result + (int) grade; 100 | return result; 101 | } 102 | } -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/parcelable/StudentParcelableActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.parcelable; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.Button; 6 | import android.widget.EditText; 7 | import android.widget.Switch; 8 | 9 | import com.example.activitystarter.BaseActivity; 10 | import com.example.activitystarter.R; 11 | 12 | import activitystarter.Arg; 13 | import activitystarter.MakeActivityStarter; 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | 17 | @MakeActivityStarter 18 | public class StudentParcelableActivity extends BaseActivity { 19 | 20 | public @Arg StudentParcelable student; 21 | 22 | @BindView(R.id.student_name) EditText studentNameView; 23 | @BindView(R.id.student_id) EditText studentIdView; 24 | @BindView(R.id.student_grade) EditText studentGradeView; 25 | @BindView(R.id.student_is_passing) Switch studentIsPassingView; 26 | @BindView(R.id.save_button) Button saveButton; 27 | @BindView(R.id.restore_button) Button restoreButton; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_data); 33 | ButterKnife.bind(this); 34 | 35 | fill(); 36 | 37 | saveButton.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | String name = studentNameView.getText().toString(); 41 | int id = Integer.parseInt(studentIdView.getText().toString()); 42 | char grade = studentGradeView.getText().charAt(0); 43 | student = new StudentParcelable(id, name, grade); 44 | } 45 | }); 46 | restoreButton.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | fill(); 50 | } 51 | }); 52 | } 53 | 54 | private void fill() { 55 | studentNameView.setText(student.getName()); 56 | studentIdView.setText(""+student.getId()); 57 | studentGradeView.setText(""+student.getGrade()); 58 | studentIsPassingView.setVisibility(View.GONE); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/parceler/StudentParceler.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.parceler; 2 | 3 | import org.parceler.Parcel; 4 | import org.parceler.ParcelConstructor; 5 | 6 | @Parcel(Parcel.Serialization.BEAN) 7 | public class StudentParceler { 8 | 9 | private int id; 10 | private String name; 11 | private char grade; 12 | 13 | @ParcelConstructor 14 | public StudentParceler(int id, String name, char grade) { 15 | this.id = id; 16 | this.name = name; 17 | this.grade = grade; 18 | } 19 | 20 | public int getId() { 21 | return id; 22 | } 23 | 24 | public void setId(int id) { 25 | this.id = id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public char getGrade() { 37 | return grade; 38 | } 39 | 40 | public void setGrade(char grade) { 41 | this.grade = grade; 42 | } 43 | } -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/parceler/StudentParcelerActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.parceler; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.Button; 6 | import android.widget.EditText; 7 | import android.widget.Switch; 8 | 9 | import com.example.activitystarter.BaseActivity; 10 | import com.example.activitystarter.R; 11 | 12 | import activitystarter.Arg; 13 | import activitystarter.MakeActivityStarter; 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | 17 | @MakeActivityStarter 18 | public class StudentParcelerActivity extends BaseActivity { 19 | 20 | @Arg(parceler = true) StudentParceler student; 21 | 22 | @BindView(R.id.student_name) EditText studentNameView; 23 | @BindView(R.id.student_id) EditText studentIdView; 24 | @BindView(R.id.student_grade) EditText studentGradeView; 25 | @BindView(R.id.student_is_passing) Switch studentIsPassingView; 26 | @BindView(R.id.save_button) Button saveButton; 27 | @BindView(R.id.restore_button) Button restoreButton; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_data); 33 | ButterKnife.bind(this); 34 | 35 | fill(); 36 | 37 | saveButton.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | String name = studentNameView.getText().toString(); 41 | int id = Integer.parseInt(studentIdView.getText().toString()); 42 | char grade = studentGradeView.getText().charAt(0); 43 | student = new StudentParceler(id, name, grade); 44 | } 45 | }); 46 | restoreButton.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | fill(); 50 | } 51 | }); 52 | } 53 | 54 | private void fill() { 55 | studentNameView.setText(student.getName()); 56 | studentIdView.setText(""+student.getId()); 57 | studentGradeView.setText(""+student.getGrade()); 58 | studentIsPassingView.setVisibility(View.GONE); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/savetest/NonSavingActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.savetest; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.TextView; 7 | 8 | import com.example.activitystarter.R; 9 | 10 | import activitystarter.ActivityStarter; 11 | import activitystarter.Arg; 12 | 13 | public class NonSavingActivity extends Activity { 14 | 15 | public static final int DEFAULT_I = -1; 16 | public static final String DEFAULT_STR = "AAA"; 17 | public static final boolean DEFAULT_B = false; 18 | 19 | public static final int NEW_I = 100; 20 | public static final String NEW_STR = "BBB"; 21 | public static final boolean NEW_B = true; 22 | 23 | @Arg(optional = true) public int i = DEFAULT_I; 24 | @Arg(optional = true) public String str = DEFAULT_STR; 25 | @Arg(optional = true) public boolean b = DEFAULT_B; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | ActivityStarter.fill(this, savedInstanceState); 31 | setContentView(R.layout.activity_save_test); 32 | ((TextView) findViewById(R.id.i)).setText(""+i); 33 | ((TextView) findViewById(R.id.str)).setText(""+str); 34 | ((TextView) findViewById(R.id.b)).setText(""+b); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/savetest/SavingActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.savetest; 2 | 3 | import android.app.Activity; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.widget.TextView; 7 | 8 | import com.example.activitystarter.R; 9 | 10 | import activitystarter.ActivityStarter; 11 | import activitystarter.Arg; 12 | 13 | public class SavingActivity extends Activity { 14 | 15 | public static final int DEFAULT_I = -1; 16 | public static final String DEFAULT_STR = "AAA"; 17 | public static final boolean DEFAULT_B = false; 18 | 19 | public static final int NEW_I = 100; 20 | public static final String NEW_STR = "BBB"; 21 | public static final boolean NEW_B = true; 22 | 23 | @Arg(optional = true) public int i = DEFAULT_I; 24 | @Arg(optional = true) public String str = DEFAULT_STR; 25 | @Arg(optional = true) public boolean b = DEFAULT_B; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | ActivityStarter.fill(this, savedInstanceState); 31 | setContentView(R.layout.activity_save_test); 32 | ((TextView) findViewById(R.id.i)).setText(""+i); 33 | ((TextView) findViewById(R.id.str)).setText(""+str); 34 | ((TextView) findViewById(R.id.b)).setText(""+b); 35 | } 36 | 37 | @Override 38 | protected void onSaveInstanceState(Bundle outState) { 39 | super.onSaveInstanceState(outState); 40 | ActivityStarter.save(this, outState); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/serializable/StudentSerializable.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.serializable; 2 | 3 | import java.io.Serializable; 4 | 5 | public class StudentSerializable implements Serializable { 6 | 7 | public int id; 8 | public String name; 9 | public char grade; 10 | public boolean passing; 11 | 12 | public StudentSerializable(int id, String name, char grade, boolean passing) { 13 | this.id = id; 14 | this.name = name; 15 | this.grade = grade; 16 | this.passing = passing; 17 | } 18 | 19 | @Override 20 | public boolean equals(Object o) { 21 | if (this == o) return true; 22 | if (o == null || getClass() != o.getClass()) return false; 23 | 24 | StudentSerializable that = (StudentSerializable) o; 25 | 26 | if (id != that.id) return false; 27 | if (grade != that.grade) return false; 28 | if (passing != that.passing) return false; 29 | return name != null ? name.equals(that.name) : that.name == null; 30 | 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | int result = id; 36 | result = 31 * result + (name != null ? name.hashCode() : 0); 37 | result = 31 * result + (int) grade; 38 | result = 31 * result + (passing ? 1 : 0); 39 | return result; 40 | } 41 | } -------------------------------------------------------------------------------- /sample/app/src/main/java/com/example/activitystarter/serializable/StudentSerializableActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.activitystarter.serializable; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.Button; 6 | import android.widget.EditText; 7 | import android.widget.Switch; 8 | 9 | import com.example.activitystarter.BaseActivity; 10 | import com.example.activitystarter.R; 11 | 12 | import activitystarter.Arg; 13 | import activitystarter.MakeActivityStarter; 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | 17 | @MakeActivityStarter 18 | public class StudentSerializableActivity extends BaseActivity { 19 | 20 | public @Arg StudentSerializable student; 21 | 22 | @BindView(R.id.student_name) EditText studentNameView; 23 | @BindView(R.id.student_id) EditText studentIdView; 24 | @BindView(R.id.student_grade) EditText studentGradeView; 25 | @BindView(R.id.student_is_passing) Switch studentIsPassingView; 26 | @BindView(R.id.save_button) Button saveButton; 27 | @BindView(R.id.restore_button) Button restoreButton; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_data); 33 | ButterKnife.bind(this); 34 | 35 | fill(); 36 | 37 | saveButton.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | student.name = studentNameView.getText().toString(); 41 | student.id = studentIdView.getId(); 42 | student.grade = studentGradeView.getText().charAt(0); 43 | } 44 | }); 45 | restoreButton.setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View v) { 48 | fill(); 49 | } 50 | }); 51 | } 52 | 53 | private void fill() { 54 | studentNameView.setText(student.name); 55 | studentIdView.setText(""+student.id); 56 | studentGradeView.setText(""+student.grade); 57 | studentIsPassingView.setChecked(student.passing); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sample/app/src/main/res/layout/activity_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 15 | 16 | 20 | 21 | 22 | 23 | 28 | 29 | 34 | 35 | 36 | 37 | 42 | 43 | 48 | 49 | 50 | 51 | 56 | 57 |