├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── dictionaries
│ └── tyler.xml
├── encodings.xml
├── gradle.xml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
├── scopes
│ └── scope_settings.xml
└── vcs.xml
├── AngularAndroid.iml
├── LICENSE.txt
├── README-OLD.md
├── README.md
├── app
├── .gitignore
├── app-debug.apk
├── app.iml
├── build.gradle
├── manifest-merger-debug-report.txt
├── manifest-merger-release-report.txt
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── ngandroid
│ │ └── demo
│ │ ├── ApplicationTest.java
│ │ ├── ModelTests.java
│ │ └── ViewBindTests.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── ngandroid
│ │ └── demo
│ │ ├── model
│ │ ├── DemoItem.java
│ │ ├── NgMod.java
│ │ ├── User.java
│ │ └── test
│ │ │ ├── Input.java
│ │ │ ├── ModelTestScope.java
│ │ │ ├── Note.java
│ │ │ ├── TestBugScope.java
│ │ │ ├── TestClass.java
│ │ │ ├── TestJsonModel.java
│ │ │ ├── TestModel.java
│ │ │ ├── TestScope.java
│ │ │ ├── TestSetterRequired.java
│ │ │ ├── TestSubModel.java
│ │ │ └── ViewScope.java
│ │ ├── scope
│ │ ├── DemoScope.java
│ │ └── LoginScope.java
│ │ └── ui
│ │ └── pages
│ │ ├── main
│ │ ├── DemoActivity.java
│ │ └── DemoAdapter.java
│ │ ├── ngclick
│ │ └── NgClickFragment.java
│ │ └── ngmodel
│ │ └── NgModelFragment.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── layout
│ ├── activity_demo.xml
│ ├── activity_ng_model.xml
│ ├── fragment_ng_click.xml
│ ├── login.xml
│ ├── test_view.xml
│ └── view_demo_item.xml
│ ├── values-v16
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── lib
├── .gitignore
├── build.gradle
├── lib.iml
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── ngandroid
│ │ │ └── lib
│ │ │ ├── NgOptions.java
│ │ │ ├── annotations
│ │ │ ├── NgModel.java
│ │ │ └── NgScope.java
│ │ │ ├── exceptions
│ │ │ └── NgException.java
│ │ │ ├── ng
│ │ │ ├── Controller.java
│ │ │ └── ModelObserver.java
│ │ │ └── utils
│ │ │ ├── Blur.java
│ │ │ ├── DefaultBlur.java
│ │ │ ├── DefaultValueFormatter.java
│ │ │ └── ValueFormatter.java
│ └── res
│ │ ├── attrs
│ │ └── attrs.xml~
│ │ └── values
│ │ └── attr.xml
│ └── test
│ └── java
│ └── com
│ └── ngandroid
│ └── lib
│ └── NgAndroidTest.java
├── ng-processor
├── .gitignore
├── build.gradle
├── ng-processor.iml
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── davityle
│ │ │ └── ngprocessor
│ │ │ ├── NgProcessor.java
│ │ │ ├── attrcompiler
│ │ │ ├── AttributeCompiler.java
│ │ │ ├── GetExpressionVisitor.java
│ │ │ ├── ObserveExpressionVisitor.java
│ │ │ ├── SetExpressionVisitor.java
│ │ │ ├── TypeCheckVisitor.java
│ │ │ ├── Visitors.java
│ │ │ ├── node
│ │ │ │ ├── AVisitor.java
│ │ │ │ ├── BinaryOperator.java
│ │ │ │ ├── Expression.java
│ │ │ │ ├── FunctionCall.java
│ │ │ │ ├── FunctionName.java
│ │ │ │ ├── IVisitor.java
│ │ │ │ ├── Identifier.java
│ │ │ │ ├── Node.java
│ │ │ │ ├── NumberConstant.java
│ │ │ │ ├── ObjectField.java
│ │ │ │ ├── SpecialIdentifier.java
│ │ │ │ ├── StringLiteral.java
│ │ │ │ ├── TernaryOperator.java
│ │ │ │ ├── UnaryOperator.java
│ │ │ │ ├── ViewIdentifier.java
│ │ │ │ └── XmlValue.java
│ │ │ ├── parse
│ │ │ │ ├── ParseException.java
│ │ │ │ ├── Parser.java
│ │ │ │ ├── State.java
│ │ │ │ ├── StepResult.java
│ │ │ │ ├── Token.java
│ │ │ │ ├── TokenType.java
│ │ │ │ └── Tokenizer.java
│ │ │ └── sources
│ │ │ │ └── Source.java
│ │ │ ├── attributes
│ │ │ ├── AttrDependency.java
│ │ │ ├── AttrPackageResolver.java
│ │ │ ├── Attribute.java
│ │ │ ├── AttributeMap.java
│ │ │ ├── Attributes.java
│ │ │ └── ScopeAttrNameResolver.java
│ │ │ ├── deps
│ │ │ ├── AttrModule.java
│ │ │ ├── DependencyComponent.java
│ │ │ ├── LayoutModule.java
│ │ │ └── UtilsModule.java
│ │ │ ├── finders
│ │ │ ├── AndroidManifestFinder.java
│ │ │ ├── DefaultLayoutDirProvider.java
│ │ │ ├── FileHelper.java
│ │ │ ├── LayoutsFinder.java
│ │ │ ├── ManifestFinder.java
│ │ │ ├── NamespaceFinder.java
│ │ │ └── OptionsHelper.java
│ │ │ ├── map
│ │ │ ├── LayoutScopeMapper.java
│ │ │ └── ModelScopeMapper.java
│ │ │ ├── model
│ │ │ ├── Layout.java
│ │ │ ├── Model.java
│ │ │ └── Scope.java
│ │ │ ├── source
│ │ │ ├── SourceCreator.java
│ │ │ ├── SourceField.java
│ │ │ ├── linkers
│ │ │ │ ├── ModelSourceLinker.java
│ │ │ │ └── ScopeSourceLinker.java
│ │ │ └── links
│ │ │ │ ├── LayoutSourceLink.java
│ │ │ │ ├── NgModelSourceLink.java
│ │ │ │ ├── ScopeSourceLink.java
│ │ │ │ └── SourceLink.java
│ │ │ ├── util
│ │ │ ├── CollectionUtils.java
│ │ │ ├── ElementUtils.java
│ │ │ ├── ManifestPackageUtils.java
│ │ │ ├── MessageUtils.java
│ │ │ ├── Option.java
│ │ │ ├── PrimitiveUtils.java
│ │ │ ├── ScopeUtils.java
│ │ │ ├── Tuple.java
│ │ │ ├── TypeUtils.java
│ │ │ └── XmlNodeUtils.java
│ │ │ └── xml
│ │ │ ├── NamedNodeMapCollection.java
│ │ │ ├── NodeCollection.java
│ │ │ ├── NodeListCollection.java
│ │ │ ├── XmlAttribute.java
│ │ │ ├── XmlScope.java
│ │ │ ├── XmlUtils.java
│ │ │ └── XmlView.java
│ └── resources
│ │ ├── META-INF
│ │ └── services
│ │ │ ├── javax.annotation.processing.Processor
│ │ │ └── javax.annotation.processing.Processor~
│ │ ├── attributes
│ │ ├── CompoundButtonInteractor.java
│ │ ├── Executor.java
│ │ ├── FireCheckObserver.java
│ │ ├── NgBlur.java
│ │ ├── NgChange.java
│ │ ├── NgClick.java
│ │ ├── NgDisabled.java
│ │ ├── NgFocus.java
│ │ ├── NgGone.java
│ │ ├── NgIf.java
│ │ ├── NgInvisible.java
│ │ ├── NgLongClick.java
│ │ ├── NgModel.java
│ │ ├── NgText.java
│ │ ├── SetTextModelObserver.java
│ │ └── TextInteracter.java
│ │ ├── attrs
│ │ ├── attach
│ │ │ ├── NgBlurAttach.java
│ │ │ ├── NgChangeAttach.java
│ │ │ ├── NgClickAttach.java
│ │ │ ├── NgDisabledAttach.java
│ │ │ ├── NgFocusAttach.java
│ │ │ ├── NgGoneAttach.java
│ │ │ ├── NgInvisibleAttach.java
│ │ │ ├── NgLongClickAttach.java
│ │ │ ├── NgModelAttach.java
│ │ │ ├── NgScopeAttach.java
│ │ │ └── NgTextAttach.java
│ │ └── class
│ │ │ ├── NgBlurClass.java
│ │ │ ├── NgChangeClass.java
│ │ │ ├── NgClickClass.java
│ │ │ ├── NgDisabledClass.java
│ │ │ ├── NgFocusClass.java
│ │ │ ├── NgGoneClass.java
│ │ │ ├── NgInvisibleClass.java
│ │ │ ├── NgLongClickClass.java
│ │ │ ├── NgModelClass.java
│ │ │ ├── NgScopeClass.java
│ │ │ └── NgTextClass.java
│ │ ├── templates
│ │ ├── layout.vm
│ │ ├── ngmodel.vm
│ │ └── scope.vm
│ │ └── velocity.properties
│ └── test
│ ├── java
│ └── com
│ │ └── github
│ │ └── davityle
│ │ └── ngprocessor
│ │ ├── CaseTest.java
│ │ ├── DuplicateModelNameTest.java
│ │ ├── DuplicateNameTest.java
│ │ ├── InvalidModelTest.java
│ │ ├── LoginTest.java
│ │ ├── NestedClassesTest.java
│ │ ├── NgProcessorTest.java
│ │ ├── NonAccessableTest.java
│ │ ├── R.java
│ │ ├── attrcompiler
│ │ ├── AttributeCompilerTest.java
│ │ ├── parse
│ │ │ ├── SyntaxParserTest.java
│ │ │ └── TokenizerTest.java
│ │ └── sources
│ │ │ ├── BinaryOperatorSourceTest.java
│ │ │ └── SourceTest.java
│ │ └── util
│ │ └── TypeUtilsTest.java
│ └── resources
│ ├── case_layouts
│ └── case_test.xml
│ ├── layouts
│ └── ng_proc_test_layout.xml
│ ├── test_login
│ └── login.xml
│ └── test_private_method
│ └── test.xml
├── ngAndroid.iml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 |
8 | *.apk
9 | *.ap_
10 | *.dex
11 | *.class
12 | bin/
13 | gen/
14 |
15 | ng-processor/src/test/java/com/ngandroid/
16 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | ngAndroid
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/dictionaries/tyler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/AngularAndroid.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tyler-gh/ngAndroid/1497a9752cd3d4918035531cd072fd01576328e9/app/app-debug.apk
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.neenbedankt.android-apt'
3 |
4 | android {
5 | compileSdkVersion 22
6 | buildToolsVersion "20.0.0"
7 |
8 | defaultConfig {
9 | applicationId "com.ngandroid.angularandroid"
10 | minSdkVersion 15
11 | targetSdkVersion 22
12 | versionCode 1
13 | versionName "1.0"
14 | renderscriptTargetApi 19
15 | renderscriptSupportModeEnabled true
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | packagingOptions {
24 | exclude 'META-INF/LICENSE.txt'
25 | exclude 'META-INF/NOTICE.txt'
26 | exclude 'META-INF/services/javax.annotation.processing.Processor'
27 | }
28 | }
29 |
30 | dependencies {
31 | compile 'com.android.support:appcompat-v7:22.1.+'
32 | compile 'io.reactivex:rxandroid:1.0.1'
33 | compile project(':lib')
34 | compile project(':ng-processor')
35 | }
36 |
--------------------------------------------------------------------------------
/app/manifest-merger-debug-report.txt:
--------------------------------------------------------------------------------
1 | -- Merging decision tree log ---
2 | manifest
3 | ADDED from AndroidManifest.xml:2:1
4 | package
5 | ADDED from AndroidManifest.xml:3:5
6 | INJECTED from AndroidManifest.xml:0:0
7 | INJECTED from AndroidManifest.xml:0:0
8 | android:versionName
9 | INJECTED from AndroidManifest.xml:0:0
10 | INJECTED from AndroidManifest.xml:0:0
11 | xmlns:android
12 | ADDED from AndroidManifest.xml:2:11
13 | android:versionCode
14 | INJECTED from AndroidManifest.xml:0:0
15 | INJECTED from AndroidManifest.xml:0:0
16 | application
17 | ADDED from AndroidManifest.xml:5:5
18 | MERGED from com.android.support:appcompat-v7:21.0.3:16:5
19 | MERGED from com.android.support:support-v4:21.0.3:16:5
20 | MERGED from com.android.support:appcompat-v7:21.0.3:16:5
21 | MERGED from com.android.support:support-v4:21.0.3:16:5
22 | android:label
23 | ADDED from AndroidManifest.xml:8:9
24 | android:allowBackup
25 | ADDED from AndroidManifest.xml:6:9
26 | android:icon
27 | ADDED from AndroidManifest.xml:7:9
28 | android:theme
29 | ADDED from AndroidManifest.xml:9:9
30 | activity#com.ngandroid.demo.DemoActivity
31 | ADDED from AndroidManifest.xml:10:9
32 | android:label
33 | ADDED from AndroidManifest.xml:12:13
34 | android:name
35 | ADDED from AndroidManifest.xml:11:13
36 | intent-filter#android.intent.action.MAIN+android.intent.category.LAUNCHER
37 | ADDED from AndroidManifest.xml:13:13
38 | action#android.intent.action.MAIN
39 | ADDED from AndroidManifest.xml:14:17
40 | android:name
41 | ADDED from AndroidManifest.xml:14:25
42 | category#android.intent.category.LAUNCHER
43 | ADDED from AndroidManifest.xml:16:17
44 | android:name
45 | ADDED from AndroidManifest.xml:16:27
46 | uses-sdk
47 | INJECTED from AndroidManifest.xml:0:0 reason: use-sdk injection requested
48 | MERGED from com.android.support:appcompat-v7:21.0.3:15:5
49 | MERGED from com.android.support:support-v4:21.0.3:15:5
50 | MERGED from AngularAndroid:lib:unspecified:8:5
51 | MERGED from com.android.support:appcompat-v7:21.0.3:15:5
52 | MERGED from com.android.support:support-v4:21.0.3:15:5
53 | android:targetSdkVersion
54 | INJECTED from AndroidManifest.xml:0:0
55 | INJECTED from AndroidManifest.xml:0:0
56 | android:minSdkVersion
57 | INJECTED from AndroidManifest.xml:0:0
58 | INJECTED from AndroidManifest.xml:0:0
59 |
--------------------------------------------------------------------------------
/app/manifest-merger-release-report.txt:
--------------------------------------------------------------------------------
1 | -- Merging decision tree log ---
2 | manifest
3 | ADDED from AndroidManifest.xml:2:1
4 | package
5 | ADDED from AndroidManifest.xml:3:5
6 | INJECTED from AndroidManifest.xml:0:0
7 | INJECTED from AndroidManifest.xml:0:0
8 | android:versionName
9 | INJECTED from AndroidManifest.xml:0:0
10 | INJECTED from AndroidManifest.xml:0:0
11 | xmlns:android
12 | ADDED from AndroidManifest.xml:2:11
13 | android:versionCode
14 | INJECTED from AndroidManifest.xml:0:0
15 | INJECTED from AndroidManifest.xml:0:0
16 | application
17 | ADDED from AndroidManifest.xml:5:5
18 | android:label
19 | ADDED from AndroidManifest.xml:8:9
20 | android:allowBackup
21 | ADDED from AndroidManifest.xml:6:9
22 | android:icon
23 | ADDED from AndroidManifest.xml:7:9
24 | android:theme
25 | ADDED from AndroidManifest.xml:9:9
26 | activity#com.ngandroid.demo.DemoActivity
27 | ADDED from AndroidManifest.xml:10:9
28 | android:label
29 | ADDED from AndroidManifest.xml:12:13
30 | android:name
31 | ADDED from AndroidManifest.xml:11:13
32 | intent-filter#android.intent.action.MAIN+android.intent.category.LAUNCHER
33 | ADDED from AndroidManifest.xml:13:13
34 | action#android.intent.action.MAIN
35 | ADDED from AndroidManifest.xml:14:17
36 | android:name
37 | ADDED from AndroidManifest.xml:14:25
38 | category#android.intent.category.LAUNCHER
39 | ADDED from AndroidManifest.xml:16:17
40 | android:name
41 | ADDED from AndroidManifest.xml:16:27
42 | uses-sdk
43 | INJECTED from AndroidManifest.xml:0:0 reason: use-sdk injection requested
44 | MERGED from AngularAndroid:lib:unspecified:8:5
45 | android:targetSdkVersion
46 | INJECTED from AndroidManifest.xml:0:0
47 | INJECTED from AndroidManifest.xml:0:0
48 | android:minSdkVersion
49 | INJECTED from AndroidManifest.xml:0:0
50 | INJECTED from AndroidManifest.xml:0:0
51 |
--------------------------------------------------------------------------------
/app/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 /home/davityle/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/ngandroid/demo/ViewBindTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo;
18 |
19 | import android.test.ActivityInstrumentationTestCase2;
20 |
21 | import com.ngandroid.demo.ui.pages.main.DemoActivity;
22 |
23 | /**
24 | * Created by tyler on 3/9/15.
25 | */
26 | public class ViewBindTests extends ActivityInstrumentationTestCase2 {
27 | public ViewBindTests() {
28 | super(DemoActivity.class);
29 | }
30 |
31 | @Override
32 | protected void setUp() throws Exception {
33 | super.setUp();
34 |
35 | }
36 |
37 | // @UiThreadTest
38 | // public void testSettingValuesAfterInflation(){
39 | // ViewScope scope = new ViewScope();
40 | // NgAndroid.getInstance().inflate(scope, LayoutInflater.from(getActivity()), R.layout.test_view, null);
41 | // scope.note.setId(100);
42 | // assertEquals(100, scope.note.getId());
43 | // }
44 | //
45 | // public void testInflaterFactoryNotReCreated() throws NoSuchFieldException, IllegalAccessException {
46 | // LayoutInflater inflater = LayoutInflater.from(getActivity());
47 | //
48 | // AttributeBinder attributeBinder = new AttributeBinder(inflater, new TestScope(), null);
49 | // Field f = AttributeBinder.class.getDeclaredField("mInflater");
50 | // f.setAccessible(true);
51 | // LayoutInflater i1 = (LayoutInflater) f.get(attributeBinder);
52 | // assertEquals(inflater, i1);
53 | // BindingInflaterFactory factory1 = (BindingInflaterFactory) i1.getFactory();
54 | // attributeBinder = new AttributeBinder(inflater, new TestScope(), null);
55 | // LayoutInflater i2 = (LayoutInflater) f.get(attributeBinder);
56 | // assertEquals(inflater, i2);
57 | // assertEquals(factory1, i2.getFactory());
58 | // }
59 |
60 |
61 |
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/DemoItem.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.model;
2 |
3 | import android.app.Fragment;
4 |
5 | public class DemoItem {
6 | private String text;
7 | private Class extends Fragment> fragment;
8 |
9 | public DemoItem(){}
10 | public DemoItem(String text, Class extends Fragment> fragment){
11 | this.text = text;
12 | this.fragment = fragment;
13 | }
14 |
15 | public String getText() {
16 | return text;
17 | }
18 |
19 | public void setText(String text) {
20 | this.text = text;
21 | }
22 |
23 | public Class extends Fragment> getFragment() {
24 | return fragment;
25 | }
26 |
27 | public void setFragment(Class extends Fragment> fragment) {
28 | this.fragment = fragment;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/NgMod.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.model;
2 |
3 | /**
4 | * Created by tyler on 4/28/15.
5 | */
6 | public class NgMod {
7 | private String str;
8 | private int integer;
9 | private double dub;
10 | private float flt;
11 | private boolean bool;
12 | private long lon;
13 |
14 | public String getStr() {
15 | return str;
16 | }
17 |
18 | public void setStr(String str) {
19 | this.str = str;
20 | }
21 |
22 | public int getInteger() {
23 | return integer;
24 | }
25 |
26 | public void setInteger(int integer) {
27 | this.integer = integer;
28 | }
29 |
30 | public double getDub() {
31 | return dub;
32 | }
33 |
34 | public void setDub(double dub) {
35 | this.dub = dub;
36 | }
37 |
38 | public float getFlt() {
39 | return flt;
40 | }
41 |
42 | public void setFlt(float flt) {
43 | this.flt = flt;
44 | }
45 |
46 | public boolean getBool() {
47 | return bool;
48 | }
49 |
50 | public void setBool(boolean bool) {
51 | this.bool = bool;
52 | }
53 |
54 | public long getLon() {
55 | return lon;
56 | }
57 |
58 | public void setLon(long lon) {
59 | this.lon = lon;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/User.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.model;
2 |
3 | public class User {
4 |
5 | private String username = "", password = "";
6 |
7 | public String getUsername() {
8 | return username;
9 | }
10 |
11 | public void setUsername(String username) {
12 | this.username = username;
13 | }
14 |
15 | public String getPassword() {
16 | return password;
17 | }
18 |
19 | public void setPassword(String password) {
20 | this.password = password;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/Input.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.model.test;
2 |
3 | public class Input {
4 | private String input;
5 | private int integer;
6 | private boolean disabled;
7 | private boolean gone;
8 | private boolean invisible;
9 | private boolean blur;
10 | private boolean focus;
11 |
12 | public String getInput() {
13 | return input;
14 | }
15 |
16 | public void setInput(String input) {
17 | this.input = input;
18 | }
19 |
20 | public int getInteger() {
21 | return integer;
22 | }
23 |
24 | public void setInteger(int integer) {
25 | this.integer = integer;
26 | }
27 |
28 | public boolean getDisabled() {
29 | return disabled;
30 | }
31 |
32 | public void setDisabled(boolean disabled) {
33 | this.disabled = disabled;
34 | }
35 |
36 | public boolean getGone() {
37 | return gone;
38 | }
39 |
40 | public void setGone(boolean gone) {
41 | this.gone = gone;
42 | }
43 |
44 | public boolean getInvisible() {
45 | return invisible;
46 | }
47 |
48 | public void setInvisible(boolean invisible) {
49 | this.invisible = invisible;
50 | }
51 |
52 | public boolean getBlur() {
53 | return blur;
54 | }
55 |
56 | public void setBlur(boolean blur) {
57 | this.blur = blur;
58 | }
59 |
60 | public boolean getFocus() {
61 | return focus;
62 | }
63 |
64 | public void setFocus(boolean focus) {
65 | this.focus = focus;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/ModelTestScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | import com.ngandroid.lib.annotations.NgModel;
20 | import com.ngandroid.lib.annotations.NgScope;
21 |
22 | /**
23 | * Created by tyler on 3/23/15.
24 | */
25 | @NgScope(name="ModelTestScope")
26 | public class ModelTestScope {
27 | // TODO throw an error in this situation @NgModel
28 | public TestSetterRequired testSetterRequired;
29 | @NgModel
30 | public TestJsonModel testJsonModel;
31 | @NgModel
32 | public TestSubModel testSubModel;
33 | @NgModel
34 | public TestClass TestClass;
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/Note.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | public class Note {
20 |
21 | private long time;
22 | private int id;
23 | private String timeString;
24 | private String title;
25 | private String text;
26 |
27 | public long getTime() {
28 | return time;
29 | }
30 |
31 | public void setTime(long time) {
32 | this.time = time;
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 getTimeString() {
44 | return timeString;
45 | }
46 |
47 | public void setTimeString(String timeString) {
48 | this.timeString = timeString;
49 | }
50 |
51 | public String getTitle() {
52 | return title;
53 | }
54 |
55 | public void setTitle(String title) {
56 | this.title = title;
57 | }
58 |
59 | public String getText() {
60 | return text;
61 | }
62 |
63 | public void setText(String text) {
64 | this.text = text;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/TestBugScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | import com.ngandroid.lib.annotations.NgModel;
20 | import com.ngandroid.lib.annotations.NgScope;
21 |
22 | /**
23 | * Created by tyler on 3/23/15.
24 | */
25 | @NgScope(name="BugScope")
26 | public class TestBugScope {
27 | @NgModel
28 | public Input input;
29 | public void multiply(int x, int y){
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/TestClass.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | /**
20 | * Created by tyler on 4/1/15.
21 | */
22 | public class TestClass {
23 | private int x;
24 |
25 | public void setX(int x) {
26 | this.x = x;
27 | }
28 |
29 | public int getX(){
30 | return x;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/TestJsonModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | /**
20 | * Created by tyler on 3/23/15.
21 | */
22 | public class TestJsonModel {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/TestModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | public class TestModel {
20 |
21 | private String joe;
22 | private boolean isInvisible;
23 | private int num;
24 |
25 | public String getJoe() {
26 | return joe;
27 | }
28 |
29 | public void setJoe(String joe) {
30 | this.joe = joe;
31 | }
32 |
33 | public boolean getIsInvisible() {
34 | return isInvisible;
35 | }
36 |
37 | public void setIsInvisible(boolean isInvisible) {
38 | this.isInvisible = isInvisible;
39 | }
40 |
41 | public int getNum() {
42 | return num;
43 | }
44 |
45 | public void setNum(int num) {
46 | this.num = num;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/TestScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | import com.ngandroid.lib.annotations.NgModel;
20 | import com.ngandroid.lib.annotations.NgScope;
21 |
22 | /**
23 | * Created by tyler on 3/23/15.
24 | */
25 | @NgScope(name="TestScope")
26 | public class TestScope {
27 | @NgModel
28 | public TestModel modelName;
29 | private void method(){
30 | }
31 | private void method(String value){
32 | System.out.println(value);
33 | }
34 | private void method(int value){
35 | System.out.println(value);
36 | }
37 | private String getStringValue(){
38 | return "This is a string value ";
39 | }
40 | private int getIntValue(){
41 | return 42;
42 | }
43 | private boolean isTrue(){
44 | return true;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/TestSetterRequired.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | /**
20 | * Created by tyler on 3/23/15.
21 | */
22 | public interface TestSetterRequired {
23 |
24 | public int getX();
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/TestSubModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | public class TestSubModel {
20 | public TestJsonModel jsonModel;
21 |
22 | public TestJsonModel getJsonModel() {
23 | return jsonModel;
24 | }
25 |
26 | public void setJsonModel(TestJsonModel jsonModel) {
27 | this.jsonModel = jsonModel;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/model/test/ViewScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.demo.model.test;
18 |
19 | import com.ngandroid.lib.annotations.NgModel;
20 | import com.ngandroid.lib.annotations.NgScope;
21 |
22 | /**
23 | * Created by tyler on 3/23/15.
24 | */
25 | @NgScope(name="ViewScope")
26 | public class ViewScope {
27 | @NgModel
28 | public Note note;
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/scope/DemoScope.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.scope;
2 |
3 | import android.app.Fragment;
4 |
5 | import com.ngandroid.demo.model.DemoItem;
6 | import com.ngandroid.lib.annotations.NgModel;
7 | import com.ngandroid.lib.annotations.NgScope;
8 |
9 | @NgScope(name="DemoScope")
10 | public class DemoScope {
11 | @NgModel
12 | DemoItem item;
13 |
14 | private final FragmentSelectedListener fragmentSelectedListener;
15 |
16 | public DemoScope(FragmentSelectedListener fragmentSelectedListener){
17 | this.fragmentSelectedListener = fragmentSelectedListener;
18 | }
19 |
20 | public void setItem(DemoItem item) {
21 | this.item.setText(item.getText());
22 | this.item.setFragment(item.getFragment());
23 | }
24 |
25 | public void showFragment(Class extends Fragment> fragment){
26 | fragmentSelectedListener.onFragmentSelected(fragment);
27 | }
28 |
29 | public interface FragmentSelectedListener {
30 | void onFragmentSelected(Class extends Fragment> fragment);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/scope/LoginScope.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.scope;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | import com.ngandroid.demo.model.User;
8 | import com.ngandroid.demo.ui.pages.main.DemoActivity;
9 | import com.ngandroid.lib.annotations.NgModel;
10 | import com.ngandroid.lib.annotations.NgScope;
11 |
12 | import java.util.concurrent.TimeUnit;
13 |
14 | import rx.Observable;
15 | import rx.Subscriber;
16 | import rx.android.schedulers.AndroidSchedulers;
17 | import rx.schedulers.Schedulers;
18 |
19 | @NgScope(name="Login")
20 | public class LoginScope {
21 |
22 | @NgModel
23 | User user;
24 |
25 | void onSubmit(final Context context) {
26 | final ProgressDialog dialog = new ProgressDialog(context);
27 | dialog.setCancelable(false);
28 | dialog.setMessage("Logging in");
29 | dialog.show();
30 | Observable.timer(4, TimeUnit.SECONDS)
31 | .subscribeOn(Schedulers.io())
32 | .observeOn(AndroidSchedulers.mainThread())
33 | .subscribe(new Subscriber() {
34 | @Override
35 | public void onCompleted() {
36 | dialog.dismiss();
37 | context.startActivity(new Intent(context, DemoActivity.class));
38 | }
39 |
40 | @Override
41 | public void onError(Throwable e) {
42 | }
43 |
44 | @Override
45 | public void onNext(Long aLong) {
46 | }
47 | });
48 | }
49 |
50 | void intArg(int i) {
51 |
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/ui/pages/main/DemoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.ui.pages.main;
2 |
3 | import android.app.Activity;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 |
9 | import com.ngandroid.demo.model.DemoItem;
10 | import com.ngandroid.demo.scope.DemoScope;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by tyler on 4/23/15.
16 | */
17 | class DemoAdapter extends BaseAdapter {
18 |
19 | // private final NgAndroid ngAndroid = NgAndroid.getInstance();
20 | private final LayoutInflater inflater;
21 | private final DemoScope.FragmentSelectedListener fragmentSelectedListener;
22 | private final List items;
23 |
24 | DemoAdapter(Activity activity, DemoScope.FragmentSelectedListener fragmentSelectedListener, List items) {
25 | this.inflater = activity.getLayoutInflater();
26 | this.fragmentSelectedListener = fragmentSelectedListener;
27 | this.items = items;
28 | }
29 |
30 | @Override
31 | public int getCount() {
32 | return items.size();
33 | }
34 |
35 | @Override
36 | public Object getItem(int position) {
37 | return items.get(position);
38 | }
39 |
40 | @Override
41 | public long getItemId(int position) {
42 | return position;
43 | }
44 |
45 | @Override
46 | public View getView(int position, View convertView, ViewGroup parent) {
47 | if(convertView == null) {
48 | // DemoScope demoScope = new DemoScope(fragmentSelectedListener);
49 | convertView = new View(parent.getContext());
50 | // convertView = ngAndroid.inflate(demoScope, inflater, R.layout.view_demo_item, parent, false);
51 | // convertView.setTag(demoScope);
52 | }
53 | // ((DemoScope)convertView.getTag()).setItem(items.get(position));
54 | return convertView;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/ui/pages/ngclick/NgClickFragment.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.ui.pages.ngclick;
2 |
3 |
4 | import android.app.Fragment;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Toast;
10 |
11 | import com.ngandroid.demo.R;
12 | import com.ngandroid.demo.scope.LoginScope;
13 | import com.ngandroid.lib.NgOptions;
14 | import com.ngandroid.lib.annotations.NgModel;
15 | import com.ngandroid.lib.annotations.NgScope;
16 |
17 | import ng.layout.LoginController;
18 |
19 | /**
20 | * A simple {@link Fragment} subclass.
21 | */
22 | @NgScope(name="ClickFragment")
23 | public class NgClickFragment extends Fragment {
24 |
25 | public NgClickFragment() {
26 | }
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
30 | // View v = inflater.inflate(R.layout.fragment_ng_click, container, false);
31 | // new FragmentNgClickController(new NgOptions.Builder().build(), this).attach(v);
32 |
33 | View v = inflater.inflate(R.layout.login, container, false);
34 | new LoginController(new NgOptions.Builder().build(), new LoginScope()).attach(v);
35 |
36 | return v;
37 | }
38 |
39 | @NgModel
40 | Inv inv;
41 |
42 | public static class Inv {
43 | private boolean invisible, gone, disabled, focus, focus1;
44 |
45 | public boolean getInvisible() {
46 | return invisible;
47 | }
48 |
49 | public void setInvisible(boolean invisible) {
50 | this.invisible = invisible;
51 | }
52 |
53 | public boolean getGone() {
54 | return gone;
55 | }
56 |
57 | public void setGone(boolean gone) {
58 | this.gone = gone;
59 | }
60 |
61 | public boolean getDisabled() {
62 | return disabled;
63 | }
64 |
65 | public void setDisabled(boolean disabled) {
66 | this.disabled = disabled;
67 | }
68 |
69 | public boolean getFocus() {
70 | return focus;
71 | }
72 |
73 | public void setFocus(boolean focus) {
74 | this.focus = focus;
75 | }
76 |
77 | public boolean getFocus1() {
78 | return focus1;
79 | }
80 |
81 | public void setFocus1(boolean focus1) {
82 | this.focus1 = focus1;
83 | }
84 | }
85 |
86 | void makeToast(String value){
87 | Toast.makeText(getActivity(), value, Toast.LENGTH_SHORT).show();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ngandroid/demo/ui/pages/ngmodel/NgModelFragment.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.demo.ui.pages.ngmodel;
2 |
3 | import android.app.Fragment;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.ngandroid.demo.R;
11 | import com.ngandroid.demo.model.NgMod;
12 | import com.ngandroid.lib.NgOptions;
13 | import com.ngandroid.lib.annotations.NgModel;
14 | import com.ngandroid.lib.annotations.NgScope;
15 |
16 | import ng.layout.ActivityNgModelController;
17 |
18 | @NgScope(name="ModelFragment")
19 | public class NgModelFragment extends Fragment {
20 | @NgModel
21 | NgMod mod;
22 |
23 | @Nullable
24 | @Override
25 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
26 | View v = inflater.inflate(R.layout.activity_ng_model, container, false);
27 | new ActivityNgModelController(new NgOptions.Builder().build(), this).attach(v);
28 | return v;
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tyler-gh/ngAndroid/1497a9752cd3d4918035531cd072fd01576328e9/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tyler-gh/ngAndroid/1497a9752cd3d4918035531cd072fd01576328e9/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tyler-gh/ngAndroid/1497a9752cd3d4918035531cd072fd01576328e9/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tyler-gh/ngAndroid/1497a9752cd3d4918035531cd072fd01576328e9/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_demo.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
15 |
16 |
20 |
21 |
22 |
27 |
28 |
29 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_ng_click.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
21 |
22 |
27 |
28 |
33 |
34 |
39 |
40 |
45 |
46 |
51 |
52 |
57 |
58 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/login.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
26 |
27 |
35 |
36 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/test_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
23 |
24 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_demo_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v16/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #AFAFAF
4 | #155799
5 | #043577
6 | #159957
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Angular Android
5 | Hello world!
6 | Settings
7 | NgModelActivity
8 | String
9 | Integer
10 | Double
11 | Float
12 | Long
13 | Open
14 | Closed
15 | Boolean
16 | Hello blank fragment
17 | Make Toast
18 | Submit
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
14 |
15 |
20 |
21 |
27 |
28 |
33 |
34 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.1.0'
9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | VERSION_NAME=1.0.10-SNAPSHOT
21 | VERSION_CODE=12
22 | GROUP=com.github.davityle
23 | POM_DESCRIPTION=NgAndroid bringing Angular directives to Android
24 | POM_URL=https://github.com/davityle/ngandroid
25 | POM_SCM_URL=https://github.com/ngandroid.git
26 | POM_SCM_CONNECTION=scm:git@github.com:davityle/ngandroid.git
27 | POM_SCM_DEV_CONNECTION=scm:git@github.com:davityle/ngandroid.git
28 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
29 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
30 | POM_LICENCE_DIST=repo
31 | POM_DEVELOPER_ID=davityle
32 | POM_DEVELOPER_NAME=Tyler Davis
33 | POM_DEVELOPER_EMAIL=tyler@goodintheglobe.com
34 | POM_NAME=NgAndroid
35 | POM_ARTIFACT_ID=ngandroid
36 | POM_PACKAGING=aar
37 |
38 | org.gradle.daemon=true
39 | org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
40 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tyler-gh/ngAndroid/1497a9752cd3d4918035531cd072fd01576328e9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
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-2.2.1-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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 | apply plugin: 'signing'
4 |
5 |
6 | buildscript {
7 | repositories {
8 | mavenCentral()
9 | }
10 | }
11 |
12 | android {
13 | compileSdkVersion 21
14 | buildToolsVersion "20.0.0"
15 |
16 | defaultConfig {
17 | minSdkVersion 15
18 | targetSdkVersion 21
19 | versionCode 3
20 | versionName "0.0.1"
21 |
22 | renderscriptTargetApi 19
23 | renderscriptSupportModeEnabled true
24 | }
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 | }
32 |
33 | repositories {
34 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
35 | }
36 |
37 | dependencies {
38 | testCompile "org.robolectric:robolectric:3.0"
39 | }
40 |
41 | android {
42 | lintOptions {
43 | abortOnError false
44 | }
45 | }
46 |
47 |
48 | // Apply chrisbanes' excellent gradle-mvn-push recipe,
49 | // which lets us publish the build artifacts to maven
50 | // without *writing a single line of XML.*
51 | //
52 | // N.B.: We're using a specific commit from a fork to
53 | // work around a bug in the recipe caused by the new
54 | // version of gradle which hasn't been upstreamed yet.
55 | //apply from: 'https://raw.github.com/shamanland/gradle-mvn-push/cc18d56549cdea03f744b6fff27911569394073e/gradle-mvn-push.gradle'
56 | //
57 | // Revert to this version once chrisbanes/gradle-mvn-push#29
58 | // is merged.
59 | // apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
--------------------------------------------------------------------------------
/lib/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 /home/davityle/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 |
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/ngandroid/lib/annotations/NgModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.lib.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * This marks a field in a {@link NgScope} as a Model. The ng-processor will generate a class
26 | * that extends the class of the field annotated with this annotation. This extension will allow
27 | * dynamic access to the fields of the model without using reflection.
28 | *
29 | * Any class that is marked as a {@link NgModel} must have a getter and a setter for every field
30 | * that will made dynamically accessible by the compiler. It must also have a default constructor.
31 | */
32 | @Target(ElementType.FIELD)
33 | @Retention(RetentionPolicy.SOURCE)
34 | public @interface NgModel {
35 | }
36 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/ngandroid/lib/annotations/NgScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.lib.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * This annotation marks a class as a Scope. A scope can also be thought of as a controller. A scope
26 | * can be used to interact with and control a view. It's models can be bound to views and it's
27 | * methods can be triggered upon view events.
28 | */
29 | @Target(ElementType.TYPE)
30 | @Retention(RetentionPolicy.SOURCE)
31 | public @interface NgScope {
32 | String name();
33 | }
34 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/ngandroid/lib/exceptions/NgException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.lib.exceptions;
18 |
19 | /**
20 | * Will be thrown in various places throughout the NgAndroid library for misuse of the library
21 | */
22 | public class NgException extends RuntimeException {
23 | public NgException(){}
24 | public NgException(String message){
25 | super(message);
26 | }
27 | public NgException(String message, Throwable t){
28 | super(message, t);
29 | }
30 | public NgException(Throwable t){
31 | super(t);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/ngandroid/lib/ng/Controller.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.lib.ng;
2 |
3 | import android.view.View;
4 |
5 | public interface Controller {
6 | int getId();
7 | void attach(View __view__);
8 | }
9 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/ngandroid/lib/ng/ModelObserver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.lib.ng;
18 |
19 | /**
20 | * This class is used when observing a field in a model. It will be fired whenever the field is
21 | * changed. the name and value of the field will be passed in through the
22 | * {@link #invoke(T)} method
23 | */
24 | public interface ModelObserver {
25 | void invoke(T arg);
26 | }
27 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/ngandroid/lib/utils/Blur.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.lib.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 |
6 | public interface Blur {
7 | Bitmap blurBitmap(Bitmap bitmap, Context context);
8 | }
9 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/ngandroid/lib/utils/DefaultBlur.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ngandroid.lib.utils;
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.support.v8.renderscript.Allocation;
22 | import android.support.v8.renderscript.Element;
23 | import android.support.v8.renderscript.RenderScript;
24 | import android.support.v8.renderscript.ScriptIntrinsicBlur;
25 |
26 | /**
27 | * This class can be used to blur a bitmap using {@link RenderScript} and resizing of the bitmap.
28 | * It needs to be much more customizable.
29 | */
30 | public class DefaultBlur implements Blur {
31 | private final float scaleRatio;
32 | private final float blurRadius;
33 |
34 | public DefaultBlur(float scaleRatio, float blurRadius) {
35 | this.scaleRatio = scaleRatio;
36 | this.blurRadius = blurRadius;
37 | }
38 |
39 | public Bitmap blurBitmap(Bitmap bitmap, Context context){
40 | int width = bitmap.getWidth(), height = bitmap.getHeight();
41 | Bitmap b = Bitmap.createScaledBitmap(Bitmap.createScaledBitmap(bitmap,(int)(width/scaleRatio), (int)(height/scaleRatio), false), width, height, false);
42 | return blurBitmap(b, blurRadius, context);
43 | }
44 |
45 |
46 | private static Bitmap blurBitmap(Bitmap src, float blurRadius, Context context){
47 | RenderScript rs = RenderScript.create(context);
48 | Bitmap.Config conf = Bitmap.Config.ARGB_8888;
49 | Bitmap blurredBitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), conf);
50 |
51 | final Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
52 | final Allocation output = Allocation.createTyped(rs, input.getType());
53 |
54 | final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
55 | script.setRadius(blurRadius);
56 | script.setInput(input);
57 | script.forEach(output);
58 | output.copyTo(blurredBitmap);
59 | return blurredBitmap;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/lib/src/main/res/attrs/attrs.xml~:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tyler-gh/ngAndroid/1497a9752cd3d4918035531cd072fd01576328e9/lib/src/main/res/attrs/attrs.xml~
--------------------------------------------------------------------------------
/lib/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/lib/src/test/java/com/ngandroid/lib/NgAndroidTest.java:
--------------------------------------------------------------------------------
1 | package com.ngandroid.lib;
2 |
3 |
4 | import org.junit.runner.RunWith;
5 | import org.robolectric.RobolectricTestRunner;
6 | import org.robolectric.annotation.Config;
7 |
8 | @RunWith(RobolectricTestRunner.class)
9 | @Config(constants = BuildConfig.class, sdk=21, manifest=Config.NONE)
10 |
11 | public class NgAndroidTest {
12 |
13 |
14 |
15 | }
--------------------------------------------------------------------------------
/ng-processor/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/ng-processor/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/AttributeCompiler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.davityle.ngprocessor.attrcompiler;
18 |
19 |
20 | import com.github.davityle.ngprocessor.attrcompiler.node.Node;
21 | import com.github.davityle.ngprocessor.attrcompiler.parse.Parser;
22 | import com.github.davityle.ngprocessor.util.Option;
23 |
24 | import javax.inject.Inject;
25 |
26 | public class AttributeCompiler {
27 |
28 |
29 | @Inject
30 | public AttributeCompiler(){}
31 |
32 | public static Option translateToJavaGetter(String source) {
33 | Option expression = Parser.tryParse(source);
34 |
35 | if (expression.isAbsent()) {
36 | return Option.absent();
37 | } else {
38 | return Option.of(GetExpressionVisitor.generateGetExpression(expression.get(), "", ""));
39 | }
40 | }
41 |
42 | public static Option translateToJavaSetter(String source, String value) {
43 | Option expression = Parser.tryParse(source);
44 |
45 | if (expression.isAbsent()) {
46 | return Option.absent();
47 | } else {
48 | return Option.of(SetExpressionVisitor.generateSetExpression(expression.get(), value));
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/SetExpressionVisitor.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attrcompiler;
2 |
3 | import com.github.davityle.ngprocessor.attrcompiler.node.AVisitor;
4 | import com.github.davityle.ngprocessor.attrcompiler.node.Identifier;
5 | import com.github.davityle.ngprocessor.attrcompiler.node.Node;
6 | import com.github.davityle.ngprocessor.attrcompiler.node.ObjectField;
7 | import com.github.davityle.ngprocessor.source.SourceField;
8 |
9 | public class SetExpressionVisitor extends AVisitor {
10 |
11 | private final String value;
12 | private final StringBuilder result = new StringBuilder();
13 |
14 | SetExpressionVisitor(String value) {
15 | this.value = value;
16 | }
17 |
18 | public static String generateSetExpression(Node target, String value) {
19 | SetExpressionVisitor visitor = new SetExpressionVisitor(value);
20 | target.accept(visitor);
21 | return visitor.result.toString();
22 | }
23 |
24 | @Override
25 | public void visit(ObjectField node) {
26 | result.append(GetExpressionVisitor.generateGetExpression(node.getLHS(), "", ""));
27 | result.append('.');
28 | result.append("set");
29 | result.append(SourceField.capitalize(node.getToken().getScript()));
30 | result.append('(');
31 | result.append(value);
32 | result.append(')');
33 | }
34 |
35 | @Override
36 | public void visit(Identifier node) {
37 | // result.append(GetExpressionVisitor.generateGetExpression(node));
38 | result.append("set");
39 | result.append(node.getToken().getScript());
40 | result.append("(");
41 | result.append(value);
42 | result.append(")");
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/Visitors.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attrcompiler;
2 |
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.node.Node;
5 | import com.github.davityle.ngprocessor.model.Scope;
6 | import com.github.davityle.ngprocessor.util.ElementUtils;
7 | import com.github.davityle.ngprocessor.util.PrimitiveUtils;
8 | import com.github.davityle.ngprocessor.util.TypeUtils;
9 |
10 | import javax.inject.Inject;
11 |
12 | public class Visitors {
13 |
14 | private final TypeUtils typeUtils;
15 | private final ElementUtils elementUtils;
16 | private final PrimitiveUtils primitiveUtils;
17 |
18 | @Inject
19 | public Visitors(TypeUtils typeUtils, ElementUtils elementUtils, PrimitiveUtils primitiveUtils){
20 | this.typeUtils = typeUtils;
21 | this.elementUtils = elementUtils;
22 | this.primitiveUtils = primitiveUtils;
23 | }
24 |
25 | public String getGetterSource(Node node, String value, String xmlValuePrependage) {
26 | return GetExpressionVisitor.generateGetExpression(node, value, xmlValuePrependage);
27 | }
28 |
29 | public String getSetterSource(Node node, String value) {
30 | return SetExpressionVisitor.generateSetExpression(node, value);
31 | }
32 |
33 | public String getObserverSource(Node node, String value, String prependage) {
34 | return ObserveExpressionVisitor.generateObserveExpression(node, value, prependage);
35 | }
36 |
37 | public String getType(Node node, Scope scope) {
38 | return TypeCheckVisitor.getType(node, scope.getJavaElement(), typeUtils, elementUtils, primitiveUtils);
39 | }
40 |
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/AVisitor.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | public abstract class AVisitor implements IVisitor {
5 | public void visit(Node node) {
6 | throw new UnsupportedOperationException("Visitor does not support node " + node.toString());
7 | }
8 |
9 | public void visit(Expression node) {
10 | visit((Node)node);
11 | }
12 |
13 | public void visit(BinaryOperator node) {
14 | visit((Expression)node);
15 | }
16 |
17 | public void visit(FunctionCall node) {
18 | visit((Expression)node);
19 | }
20 | public void visit(Identifier node) {
21 | visit((Expression)node);
22 | }
23 | public void visit(NumberConstant node) {
24 | visit((Expression)node);
25 | }
26 | public void visit(StringLiteral node) { visit((Expression)node); }
27 | public void visit(ObjectField node) {
28 | visit((Expression)node);
29 | }
30 | public void visit(TernaryOperator node) {
31 | visit((Expression)node);
32 | }
33 | public void visit(UnaryOperator node) {
34 | visit((Expression)node);
35 | }
36 | public void visit(FunctionName node) {
37 | visit((Expression) node);
38 | }
39 | public void visit(SpecialIdentifier node) {
40 | visit((Expression) node);
41 | }
42 | public void visit(ViewIdentifier node) {
43 | visit((SpecialIdentifier) node);
44 | }
45 | public void visit(XmlValue node) {
46 | visit((Expression) node);
47 | }
48 | public void visit(XmlValue.BoolXmlValue node){
49 | visit((XmlValue) node);
50 | }
51 | public void visit(XmlValue.ColorXmlValue node){
52 | visit((XmlValue) node);
53 | }
54 | public void visit(XmlValue.DimenXmlValue node){
55 | visit((XmlValue) node);
56 | }
57 | public void visit(XmlValue.IdXmlValue node){
58 | visit((XmlValue) node);
59 | }
60 | public void visit(XmlValue.IntegerXmlValue node){
61 | visit((XmlValue) node);
62 | }
63 | public void visit(XmlValue.StringXmlValue node){
64 | visit((XmlValue) node);
65 | }
66 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/BinaryOperator.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public class BinaryOperator extends Expression {
7 |
8 | private final Expression lhs;
9 | private final Expression rhs;
10 |
11 | public BinaryOperator(Token operator, Expression lhs, Expression rhs) {
12 | super(operator);
13 | this.lhs = lhs;
14 | this.rhs = rhs;
15 | }
16 |
17 | @Override
18 | public void accept(IVisitor visitor) {
19 | visitor.visit(this);
20 | }
21 |
22 | public Expression getLHS() {
23 | return lhs;
24 | }
25 |
26 | public Expression getRHS() {
27 | return rhs;
28 | }
29 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/Expression.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public abstract class Expression extends Node {
7 |
8 | protected Expression(Token token) {
9 | super(token);
10 | }
11 |
12 | @Override
13 | public abstract void accept(IVisitor visitor);
14 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/FunctionCall.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | import java.util.List;
7 |
8 | public class FunctionCall extends Expression {
9 |
10 | private final Expression lhs;
11 | private List extends Expression> parameters;
12 |
13 | public FunctionCall(Token token, Expression lhs, List extends Expression> parameters) {
14 | super(token);
15 | this.lhs = lhs;
16 | this.parameters = parameters;
17 | }
18 |
19 | @Override
20 | public void accept(IVisitor visitor) {
21 | visitor.visit(this);
22 | }
23 |
24 | public Expression getLHS() {
25 | return lhs;
26 | }
27 |
28 | public List extends Expression> getParameters() {
29 | return parameters;
30 | }
31 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/FunctionName.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attrcompiler.node;
2 |
3 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
4 |
5 | public class FunctionName extends Expression {
6 |
7 | private final Expression lhs;
8 |
9 | public FunctionName(Expression lhs, Token rhs) {
10 | super(rhs);
11 | this.lhs = lhs;
12 | }
13 |
14 | @Override
15 | public void accept(IVisitor visitor) {
16 | visitor.visit(this);
17 | }
18 |
19 | public Expression getLHS() {
20 | return lhs;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/IVisitor.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | public interface IVisitor {
5 | void visit(Node node);
6 | void visit(Expression node);
7 | void visit(BinaryOperator node);
8 | void visit(FunctionCall node);
9 | void visit(Identifier node);
10 | void visit(NumberConstant node);
11 | void visit(StringLiteral node);
12 | void visit(ObjectField node);
13 | void visit(TernaryOperator node);
14 | void visit(UnaryOperator node);
15 | void visit(FunctionName node);
16 |
17 | /** xml values **/
18 | void visit(XmlValue node);
19 | void visit(XmlValue.BoolXmlValue node);
20 | void visit(XmlValue.ColorXmlValue node);
21 | void visit(XmlValue.DimenXmlValue node);
22 | void visit(XmlValue.IdXmlValue node);
23 | void visit(XmlValue.IntegerXmlValue node);
24 | void visit(XmlValue.StringXmlValue node);
25 |
26 | /** special identifiers **/
27 | void visit(SpecialIdentifier node);
28 | void visit(ViewIdentifier node);
29 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/Identifier.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public class Identifier extends Expression {
7 | public Identifier(Token identifier) {
8 | super(identifier);
9 | }
10 |
11 | @Override
12 | public void accept(IVisitor visitor) {
13 | visitor.visit(this);
14 | }
15 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/Node.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public abstract class Node {
7 |
8 | private final Token token;
9 |
10 | protected Node(Token token) {
11 | this.token = token;
12 | }
13 |
14 | public abstract void accept(IVisitor visitor);
15 |
16 | public Token getToken() {
17 | return token;
18 | }
19 |
20 | @Override
21 | public String toString() {
22 | return token.toString();
23 | }
24 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/NumberConstant.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public class NumberConstant extends Expression {
7 | public NumberConstant(Token source) {
8 | super(source);
9 | }
10 |
11 | @Override
12 | public void accept(IVisitor visitor) {
13 | visitor.visit(this);
14 | }
15 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/ObjectField.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public class ObjectField extends Expression {
7 |
8 | private final Expression lhs;
9 |
10 | public ObjectField(Expression lhs, Token rhs) {
11 | super(rhs);
12 | this.lhs = lhs;
13 | }
14 |
15 | @Override
16 | public void accept(IVisitor visitor) {
17 | visitor.visit(this);
18 | }
19 |
20 | public Expression getLHS() {
21 | return lhs;
22 | }
23 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/SpecialIdentifier.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attrcompiler.node;
2 |
3 | import com.github.davityle.ngprocessor.attrcompiler.parse.ParseException;
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public abstract class SpecialIdentifier extends Expression {
10 | private static Map> identifierMap = new HashMap>(){{
11 | put("$view", new Resolver() {
12 | @Override
13 | public ViewIdentifier create(Token token) {
14 | return new ViewIdentifier(token);
15 | }
16 | });
17 | }};
18 |
19 | public static SpecialIdentifier getSpecialIdentifier(Token token) throws ParseException {
20 | if(identifierMap.containsKey(token.getScript())) {
21 | return identifierMap.get(token.getScript()).create(token);
22 | }
23 | throw new ParseException(token, String.format("Invalid special identifier '%s'",token.getScript()));
24 | }
25 |
26 | protected SpecialIdentifier(Token token) {
27 | super(token);
28 | }
29 |
30 | public abstract String getCompiledSource();
31 |
32 | public interface Resolver {
33 | T create(Token token);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/StringLiteral.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attrcompiler.node;
2 |
3 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
4 |
5 | public class StringLiteral extends Expression {
6 | public StringLiteral(Token source) {
7 | super(source);
8 | }
9 |
10 | @Override
11 | public void accept(IVisitor visitor) {
12 | visitor.visit(this);
13 | }
14 |
15 | public String toJavaString() {
16 | StringBuilder result = new StringBuilder();
17 | boolean insideEscape = false;
18 |
19 | String source = getToken().getScript();
20 | source = source.substring(1, source.length() - 1);
21 |
22 | result.append('"');
23 |
24 | for (char character : source.toCharArray()) {
25 | if (!insideEscape) {
26 | if (character == '\\') {
27 | insideEscape = true;
28 | } else if (character == '"') {
29 | result.append("\\\"");
30 | } else {
31 | result.append(character);
32 | }
33 | } else {
34 | insideEscape = false;
35 | result.append('\\');
36 | result.append(character);
37 | }
38 | }
39 |
40 | result.append('"');
41 |
42 | return result.toString();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/TernaryOperator.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public class TernaryOperator extends Expression {
7 |
8 | private final Expression condition;
9 | private final Expression ifTrue;
10 | private final Expression ifFalse;
11 |
12 | public TernaryOperator(Token questionMark, Expression condition, Expression ifTrue, Expression ifFalse) {
13 | super(questionMark);
14 | this.condition = condition;
15 | this.ifTrue = ifTrue;
16 | this.ifFalse = ifFalse;
17 | }
18 |
19 | @Override
20 | public void accept(IVisitor visitor) {
21 | visitor.visit(this);
22 | }
23 |
24 | public Expression getCondition() {
25 | return condition;
26 | }
27 |
28 | public Expression getIfTrue() {
29 | return ifTrue;
30 | }
31 |
32 | public Expression getIfFalse() {
33 | return ifFalse;
34 | }
35 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/UnaryOperator.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.node;
3 |
4 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
5 |
6 | public class UnaryOperator extends Expression {
7 |
8 | private Expression rhs;
9 |
10 | public UnaryOperator(Token token, Expression rhs) {
11 | super(token);
12 | this.rhs = rhs;
13 | }
14 |
15 | @Override
16 | public void accept(IVisitor visitor) {
17 | visitor.visit(this);
18 | }
19 |
20 | public Expression getRHS() {
21 | return rhs;
22 | }
23 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/node/ViewIdentifier.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attrcompiler.node;
2 |
3 | import com.github.davityle.ngprocessor.attrcompiler.parse.Token;
4 |
5 | public final class ViewIdentifier extends SpecialIdentifier {
6 | public ViewIdentifier(Token token) {
7 | super(token);
8 | }
9 |
10 | @Override
11 | public void accept(IVisitor visitor) {
12 | visitor.visit(this);
13 | }
14 |
15 | @Override
16 | public String getCompiledSource() {
17 | return "view";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/parse/ParseException.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.parse;
3 |
4 | public class ParseException extends Exception {
5 | public ParseException(Token token) {
6 | super(token.toString());
7 | }
8 |
9 | public ParseException(Token token, String message) {
10 | super(token.toString() + "\n" + message);
11 | }
12 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/parse/StepResult.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attrcompiler.parse;
2 |
3 | public class StepResult
4 | {
5 | private State state;
6 | private TokenType tokenType;
7 |
8 | public StepResult(State state, TokenType tokenType)
9 | {
10 | this.state = state;
11 | this.tokenType = tokenType;
12 | }
13 |
14 | public StepResult(State state)
15 | {
16 | this.state = state;
17 | this.tokenType = TokenType.NONE;
18 | }
19 |
20 | public TokenType getTokenType()
21 | {
22 | return tokenType;
23 | }
24 |
25 | public State getState()
26 | {
27 | return state;
28 | }
29 | }
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/parse/Token.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright 2015 Tyler Davis
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.github.davityle.ngprocessor.attrcompiler.parse;
19 |
20 | /**
21 | * Created by davityle on 1/15/15.
22 | */
23 | public final class Token {
24 | private final TokenType tokenType;
25 | private final String script;
26 | private final int tokenLocation;
27 |
28 | Token(TokenType tokenType, String script, int tokenLocation) {
29 | this.tokenType = tokenType;
30 | this.script = script;
31 | this.tokenLocation = tokenLocation;
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return tokenType.toString() + "::" + script;
37 | }
38 |
39 | public TokenType getTokenType() {
40 | return tokenType;
41 | }
42 |
43 | public String getScript() {
44 | return script;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/parse/Tokenizer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.davityle.ngprocessor.attrcompiler.parse;
3 |
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | public class Tokenizer {
8 | private String source;
9 | private int currentTokenStart;
10 | private int currentPosition;
11 | private State state;
12 |
13 | public Tokenizer(String source) {
14 | this.source = source;
15 | this.currentTokenStart = 0;
16 | this.currentPosition = 0;
17 | this.state = State.StartState;
18 | }
19 |
20 | public List tokenize() throws ParseException {
21 | List result = new ArrayList();
22 |
23 | if (source != null && source.length() != 0) {
24 | State currentState = State.StartState;
25 |
26 | while (currentState != State.Done && currentPosition <= source.length()) {
27 | char currentChar;
28 |
29 | if (currentPosition == source.length()) {
30 | currentChar = '\0';
31 | } else {
32 | currentChar = source.charAt(currentPosition);
33 | }
34 |
35 | StepResult stepResult = currentState.step(currentChar);
36 | TokenType tokenType = stepResult.getTokenType();
37 | currentState = stepResult.getState();
38 |
39 | if (tokenType != TokenType.NONE) {
40 | if (tokenType == TokenType.RUBBISH) {
41 | String tokenValue = source.substring(currentTokenStart, currentPosition);
42 | throw new ParseException(new Token(tokenType, tokenValue, currentTokenStart), "Unexpected character '" + currentChar + "' at col " + currentTokenStart);
43 | } else if (tokenType != TokenType.WHITESPACE) {
44 | String tokenValue = source.substring(currentTokenStart, currentPosition);
45 | result.add(new Token(tokenType, tokenValue, currentTokenStart));
46 | }
47 |
48 | currentTokenStart = currentPosition;
49 | }
50 |
51 | ++currentPosition;
52 | }
53 | }
54 |
55 | result.add(new Token(TokenType.EOF, "", source.length()));
56 | return result;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attrcompiler/sources/Source.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.davityle.ngprocessor.attrcompiler.sources;
18 |
19 | import com.github.davityle.ngprocessor.attrcompiler.Visitors;
20 | import com.github.davityle.ngprocessor.attrcompiler.node.Node;
21 | import com.github.davityle.ngprocessor.attrcompiler.parse.ParseException;
22 | import com.github.davityle.ngprocessor.attrcompiler.parse.Parser;
23 | import com.github.davityle.ngprocessor.model.Scope;
24 |
25 | public class Source {
26 | private final Node node;
27 | private final Visitors visitors;
28 |
29 | public Source(String source, Visitors visitors) throws ParseException {
30 | this.visitors = visitors;
31 | this.node = Parser.parse(source);
32 | }
33 |
34 | public String getGetterSource(String value, String xmlValuePrependage) {
35 | return visitors.getGetterSource(node, value, xmlValuePrependage);
36 | }
37 |
38 | public String getSetterSource(String value) {
39 | return visitors.getSetterSource(node, value);
40 | }
41 |
42 | public String getObserverSource(String value, String prependage) {
43 | return visitors.getObserverSource(node, value, prependage);
44 | }
45 |
46 | public String getType(Scope scope) {
47 | return visitors.getType(node, scope);
48 | }
49 |
50 | public boolean isVoid() {
51 | return false;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attributes/AttrDependency.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attributes;
2 |
3 | import java.util.Scanner;
4 |
5 | public class AttrDependency {
6 |
7 | private final String className;
8 | private String[] dependencies;
9 |
10 | public AttrDependency(String className) {
11 | this.className = className;
12 | }
13 |
14 | public String getClassName() {
15 | return className;
16 | }
17 |
18 | protected static String getResource(String resourcePath){
19 | try {
20 | return new Scanner(AttrDependency.class.getClassLoader().getResourceAsStream(resourcePath), "UTF-8").useDelimiter("\\A").next();
21 | } catch (NullPointerException e) {
22 | return new Scanner(AttrDependency.class.getResourceAsStream(resourcePath), "UTF-8").useDelimiter("\\A").next();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attributes/AttrPackageResolver.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attributes;
2 |
3 | public interface AttrPackageResolver {
4 | String getPackage();
5 | String getAttrClassName();
6 | }
7 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attributes/Attribute.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attributes;
2 |
3 | public class Attribute extends AttrDependency {
4 |
5 | private final String attrName, classSource, attachSource;
6 | private String[] attrParameters;
7 |
8 | public Attribute(String className){
9 | this(className, toAttrName(className));
10 | }
11 |
12 | public Attribute(String className, String attrName) {
13 | super(className);
14 | this.attrName = attrName;
15 | }
16 |
17 | {
18 | this.classSource = getResource("attrs/class/" + getClassName() + "Class.java");
19 | this.attachSource = getResource("attrs/attach/" + getClassName() + "Attach.java");
20 | }
21 |
22 | public String getClassSource() {
23 | return classSource;
24 | }
25 |
26 | public String getAttachSource() {
27 | return attachSource;
28 | }
29 |
30 | public Attribute setAttrParameters(String ... attrParameters){
31 | this.attrParameters = attrParameters;
32 | return this;
33 | }
34 |
35 | public String[] getAttrParameters() {
36 | return attrParameters != null ? attrParameters : new String[0];
37 | }
38 |
39 | public String getAttrName() {
40 | return attrName;
41 | }
42 |
43 | private static String toAttrName(String className){
44 | return Character.toLowerCase(className.charAt(0)) + className.substring(1);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attributes/AttributeMap.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attributes;
2 |
3 | import java.util.HashMap;
4 |
5 | class AttributeMap extends HashMap {
6 | public Attribute put(Attribute value) {
7 | super.put(value.getAttrName(), value);
8 | return super.put(value.getClassName(), value);
9 | }
10 |
11 | protected void put(AttrDependency attrDependency) {
12 | put((Attribute)attrDependency);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attributes/Attributes.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attributes;
2 |
3 | import javax.inject.Inject;
4 |
5 | public class Attributes extends AttributeMap {
6 | @Inject
7 | public Attributes(ScopeAttrNameResolver scopeAttrNameResolver) {
8 | put(new Attribute(scopeAttrNameResolver.getScopeAttrNameUppercase()));
9 | put(new Attribute("NgBlur").setAttrParameters("blur"));
10 | put(new Attribute("NgChange"));
11 | put(new Attribute("NgClick"));
12 | put(new Attribute("NgDisabled"));
13 | put(new Attribute("NgFocus"));
14 | put(new Attribute("NgGone"));
15 | put(new Attribute("NgInvisible"));
16 | put(new Attribute("NgLongClick"));
17 | put(new Attribute("NgModel").setAttrParameters("formatter"));
18 | put(new Attribute("NgText").setAttrParameters("formatter"));
19 | }
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/attributes/ScopeAttrNameResolver.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.attributes;
2 |
3 | public interface ScopeAttrNameResolver {
4 | String getScopeAttrName();
5 | String getScopeAttrNameUppercase();
6 | }
7 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/deps/AttrModule.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.deps;
2 |
3 | import com.github.davityle.ngprocessor.attributes.AttrPackageResolver;
4 | import com.github.davityle.ngprocessor.attributes.ScopeAttrNameResolver;
5 |
6 | import dagger.Module;
7 | import dagger.Provides;
8 |
9 | @Module
10 | public class AttrModule {
11 | @Provides
12 | public AttrPackageResolver attrPackageResolver(){
13 | return new AttrPackageResolver() {
14 | @Override
15 | public String getPackage() {
16 | return "com.ngandroid.lib.ngattributes";
17 | }
18 |
19 | @Override
20 | public String getAttrClassName() {
21 | return "AttrsImpl";
22 | }
23 | };
24 | }
25 |
26 | @Provides
27 | public ScopeAttrNameResolver scopeAttrNameResolver() {
28 | return new ScopeAttrNameResolver() {
29 | @Override
30 | public String getScopeAttrName() {
31 | return "ngScope";
32 | }
33 |
34 | @Override
35 | public String getScopeAttrNameUppercase() {
36 | return "NgScope";
37 | }
38 | };
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/deps/DependencyComponent.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.deps;
2 |
3 | import com.github.davityle.ngprocessor.NgProcessor;
4 | import com.github.davityle.ngprocessor.map.LayoutScopeMapper;
5 | import com.github.davityle.ngprocessor.map.ModelScopeMapper;
6 | import com.github.davityle.ngprocessor.source.SourceCreator;
7 | import com.github.davityle.ngprocessor.source.linkers.ModelSourceLinker;
8 | import com.github.davityle.ngprocessor.source.linkers.ScopeSourceLinker;
9 | import com.github.davityle.ngprocessor.util.CollectionUtils;
10 | import com.github.davityle.ngprocessor.util.ElementUtils;
11 | import com.github.davityle.ngprocessor.util.ManifestPackageUtils;
12 | import com.github.davityle.ngprocessor.util.MessageUtils;
13 | import com.github.davityle.ngprocessor.util.ScopeUtils;
14 | import com.github.davityle.ngprocessor.xml.XmlUtils;
15 |
16 | import javax.inject.Singleton;
17 |
18 | import dagger.Component;
19 |
20 | @Singleton
21 | @Component(modules = {
22 | NgProcessor.EnvironmentModule.class,
23 | LayoutModule.class,
24 | AttrModule.class,
25 | UtilsModule.class
26 | })
27 | public interface DependencyComponent {
28 | ManifestPackageUtils createManifestPackageUtils();
29 | ScopeUtils createScopeUtils();
30 | MessageUtils createMessageUtils();
31 | XmlUtils createXmlUtils();
32 | CollectionUtils createCollectionUtils();
33 | ElementUtils elementUtils();
34 |
35 | void inject(ModelScopeMapper modelScopeMapper);
36 | void inject(LayoutScopeMapper layoutScopeMapper);
37 | void inject(ScopeSourceLinker scopeSourceLinker);
38 | void inject(ModelSourceLinker sourceLinker);
39 | void inject(SourceCreator sourceCreator);
40 | }
41 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/deps/LayoutModule.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.deps;
2 |
3 | import com.github.davityle.ngprocessor.finders.DefaultLayoutDirProvider;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | @Module
9 | public class LayoutModule {
10 |
11 | private final DefaultLayoutDirProvider defaultLayoutDirProvider;
12 |
13 | public LayoutModule(DefaultLayoutDirProvider defaultLayoutDirProvider) {
14 | this.defaultLayoutDirProvider = defaultLayoutDirProvider;
15 | }
16 |
17 |
18 | @Provides
19 | public DefaultLayoutDirProvider getDefaultDirProvider(){
20 | return defaultLayoutDirProvider;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/deps/UtilsModule.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.deps;
2 |
3 | import com.github.davityle.ngprocessor.util.MessageUtils;
4 |
5 | import javax.annotation.processing.ProcessingEnvironment;
6 | import javax.inject.Singleton;
7 |
8 | import dagger.Module;
9 | import dagger.Provides;
10 |
11 | @Module
12 | public class UtilsModule {
13 |
14 | private MessageUtils messageUtils;
15 | private ProcessingEnvironment processingEnvironment;
16 |
17 | @Provides
18 | @Singleton
19 | public MessageUtils messageUtils(ProcessingEnvironment processingEnvironment){
20 | if(this.messageUtils == null || this.processingEnvironment != processingEnvironment) {
21 | this.messageUtils = new MessageUtils(processingEnvironment);
22 | this.processingEnvironment = processingEnvironment;
23 | }
24 | return messageUtils;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/finders/DefaultLayoutDirProvider.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.finders;
2 |
3 | import com.github.davityle.ngprocessor.util.Option;
4 |
5 | /**
6 | * Created by tyler on 6/29/15.
7 | */
8 | public interface DefaultLayoutDirProvider {
9 | Option getDefaultLayoutDir();
10 | }
11 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/finders/ManifestFinder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.davityle.ngprocessor.finders;
18 |
19 | import com.github.davityle.ngprocessor.util.Option;
20 |
21 | import java.io.File;
22 |
23 | import javax.inject.Inject;
24 |
25 | public class ManifestFinder {
26 |
27 | @Inject
28 | public ManifestFinder(){
29 |
30 | }
31 |
32 | public Option findManifest(){
33 | return findManifest(new File("."));
34 | }
35 |
36 | private Option findManifest(File dir){
37 | File[] kids = dir.listFiles();
38 | if(kids != null) {
39 | for (File file : kids) {
40 | String name = file.getName();
41 | if (file.isDirectory()) {
42 | Option f = findManifest(file);
43 | if(f.isPresent())
44 | return f;
45 | }else{
46 | if(name.equals("AndroidManifest.xml")){
47 | return Option.of(file);
48 | }
49 | }
50 | }
51 | }
52 | return Option.absent();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/finders/NamespaceFinder.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.finders;
2 |
3 | import com.github.davityle.ngprocessor.util.Option;
4 |
5 | import org.w3c.dom.Document;
6 | import org.w3c.dom.NamedNodeMap;
7 | import org.w3c.dom.NodeList;
8 |
9 | import java.util.regex.Matcher;
10 | import java.util.regex.Pattern;
11 |
12 | import javax.inject.Inject;
13 |
14 | public class NamespaceFinder {
15 |
16 | private static final Pattern NAME_SPACE_PATTERN = Pattern.compile("xmlns:(.+)=\"http://schemas.android.com/apk/res-auto\"");
17 |
18 | @Inject
19 | public NamespaceFinder(){}
20 |
21 | public Option getNameSpace(Document doc){
22 | return getNameSpace(doc.getChildNodes());
23 | }
24 |
25 | public Option getNameSpace(NodeList nodes){
26 | for(int index = 0; index < nodes.getLength(); index++) {
27 | NamedNodeMap nodeMap = nodes.item(index).getAttributes();
28 | if(nodeMap != null){
29 | for(int j = 0; j < nodeMap.getLength(); j++){
30 | Matcher matcher = NAME_SPACE_PATTERN.matcher(nodeMap.item(j).toString());
31 | if(matcher.matches()){
32 | return Option.of(matcher.group(1));
33 | }
34 | }
35 | }
36 | }
37 | for(int index = 0; index < nodes.getLength(); index++) {
38 | NodeList nodeList = nodes.item(index).getChildNodes();
39 | if(nodeList != null){
40 | Option namespace = getNameSpace(nodeList);
41 | if(namespace.isPresent())
42 | return namespace;
43 | }
44 | }
45 | return Option.absent();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/finders/OptionsHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed To in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.github.davityle.ngprocessor.finders;
17 |
18 | import java.util.Map;
19 |
20 | import javax.annotation.processing.ProcessingEnvironment;
21 | import javax.inject.Inject;
22 |
23 | public class OptionsHelper {
24 |
25 | enum Option {
26 | ANDROID_MANIFEST_FILE("androidManifestFile", null);
27 |
28 | private String key;
29 | private String defaultValue;
30 |
31 | Option(String key, String defaultValue) {
32 | this.key = key;
33 | this.defaultValue = defaultValue;
34 | }
35 |
36 | public String getKey() {
37 | return key;
38 | }
39 |
40 | public String getDefaultValue() {
41 | return defaultValue;
42 | }
43 | }
44 |
45 | private final Map options;
46 |
47 | @Inject
48 | public OptionsHelper(ProcessingEnvironment processingEnvironment) {
49 | options = processingEnvironment.getOptions();
50 | }
51 |
52 | public String getAndroidManifestFile() {
53 | return getString(Option.ANDROID_MANIFEST_FILE);
54 | }
55 |
56 |
57 | private String getString(Option option) {
58 | String key = option.getKey();
59 | if (options.containsKey(key)) {
60 | return options.get(key);
61 | } else {
62 | return option.getDefaultValue();
63 | }
64 | }
65 |
66 | private boolean getBoolean(Option option) {
67 | return Boolean.valueOf(getString(option));
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/model/Layout.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.model;
2 |
3 | import java.io.File;
4 |
5 | public class Layout {
6 |
7 | private final String path, javaName, fileName;
8 |
9 | public Layout(String path) {
10 | this.path = path;
11 | this.fileName = fileName(path);
12 | this.javaName = name(path);
13 | }
14 |
15 | public String getPath() {
16 | return path;
17 | }
18 |
19 | public String getFileName() {
20 | return fileName;
21 | }
22 |
23 | public String getJavaName() {
24 | return javaName;
25 | }
26 |
27 | @Override
28 | public int hashCode() {
29 | return path.hashCode();
30 | }
31 |
32 | @Override
33 | public boolean equals(Object obj) {
34 | return obj instanceof Layout && ((Layout)obj).path.equals(path);
35 | }
36 |
37 | private static String fileName(String path) {
38 | return path.substring(path.lastIndexOf(File.separatorChar) + 1).replace(".xml", "");
39 | }
40 |
41 | private static String name(String path) {
42 | String[] sections = fileName(path).split("_");
43 | StringBuilder name = new StringBuilder();
44 | for(String s : sections) {
45 | if(s.length() > 0) {
46 | name.append(Character.toUpperCase(s.charAt(0)));
47 | }
48 | if(s.length() > 1){
49 | name.append(s.substring(1));
50 | }
51 | }
52 | return name.toString();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/model/Model.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.model;
2 |
3 | public class Model {
4 |
5 | private final String name, typeName;
6 |
7 | public Model(String name, String typeName) {
8 | this.name = name;
9 | this.typeName = typeName;
10 | }
11 |
12 | public String getName(){
13 | return name;
14 | }
15 |
16 | public String getTypeName(){
17 | return typeName;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/model/Scope.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.model;
2 |
3 | import com.github.davityle.ngprocessor.xml.XmlScope;
4 | import com.github.davityle.ngprocessor.xml.XmlView;
5 |
6 | import java.util.Collection;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | import javax.lang.model.element.Element;
11 |
12 | public class Scope {
13 |
14 | private final Element javaElement;
15 | private final Collection ngModels;
16 | private final String scopeName, scopeType, javaName;
17 | private final Map xmlScopes;
18 |
19 | public Scope(Element javaElement, Collection ngModels, String scopeName, String scopeType, String javaName) {
20 | this.javaElement = javaElement;
21 | this.ngModels = ngModels;
22 | this.scopeName = scopeName;
23 | this.scopeType = scopeType;
24 | this.javaName = javaName;
25 | this.xmlScopes = new HashMap<>();
26 | }
27 |
28 | public void addXmlScope(Layout layout, XmlScope xmlScope) {
29 | xmlScopes.put(layout, xmlScope);
30 | }
31 |
32 | public Map getXmlScopes() {
33 | return xmlScopes;
34 | }
35 |
36 | public boolean inLayout(String layout) {
37 | return xmlScopes.containsKey(new Layout(layout));
38 | }
39 |
40 | public Collection getLayouts() {
41 | return xmlScopes.keySet();
42 | }
43 |
44 | public Collection getViews(String layout) {
45 | return xmlScopes.get(new Layout(layout)).getViews();
46 | }
47 |
48 | public Element getJavaElement() {
49 | return javaElement;
50 | }
51 |
52 | public Collection getNgModels() {
53 | return ngModels;
54 | }
55 |
56 | public String getName() {
57 | return scopeName;
58 | }
59 |
60 | public String getJavaName() {
61 | return javaName;
62 | }
63 |
64 | public String getTypeName() {
65 | return scopeType;
66 | }
67 |
68 | @Override
69 | public String toString() {
70 | return javaElement.toString();
71 | }
72 |
73 | @Override
74 | public int hashCode() {
75 | return javaElement.hashCode();
76 | }
77 |
78 | @Override
79 | public boolean equals(Object obj) {
80 | return javaElement.equals(obj);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/source/SourceField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.davityle.ngprocessor.source;
18 |
19 | import com.github.davityle.ngprocessor.util.PrimitiveUtils;
20 |
21 | /**
22 | * Created by tyler on 3/25/15.
23 | */
24 | public final class SourceField {
25 |
26 | private final String name, typeName;
27 | private final PrimitiveUtils primitiveUtils;
28 | private String getter, setter;
29 |
30 | public SourceField(String name, String typeName, PrimitiveUtils primitiveUtils) {
31 | this.name = name;
32 | this.primitiveUtils = primitiveUtils;
33 | this.typeName = typeName.replaceAll("<.*>", "");
34 | }
35 |
36 | public String getName(){
37 | return name;
38 | }
39 |
40 | public String getTypeName(){
41 | return typeName;
42 | }
43 |
44 | public String getObjectType(){
45 | return primitiveUtils.getObjectType(typeName);
46 | }
47 |
48 | public String getGetter() { return getter; }
49 |
50 | public String getSetter() { return setter; }
51 |
52 | public boolean isPrimitive() {
53 | return primitiveUtils.isPrimitive(typeName);
54 | }
55 |
56 | public void setSetter(String setter) {
57 | this.setter = setter;
58 | }
59 |
60 | public void setGetter(String getter) {
61 | this.getter = getter;
62 | }
63 |
64 | public static String capitalize(final String line) {
65 | return Character.toUpperCase(line.charAt(0)) + line.substring(1);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/source/links/LayoutSourceLink.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.source.links;
2 |
3 |
4 | import com.github.davityle.ngprocessor.model.Layout;
5 | import com.github.davityle.ngprocessor.model.Scope;
6 |
7 | import org.apache.velocity.VelocityContext;
8 |
9 | import java.util.Collection;
10 | import java.util.Iterator;
11 |
12 | import javax.lang.model.element.Element;
13 |
14 | public class LayoutSourceLink implements SourceLink {
15 |
16 | private final static String PACKAGE = "ng.layout";
17 |
18 | private final Collection scopes;
19 | private final String layoutPath, layoutName, className, packageName, javaName;
20 |
21 | public LayoutSourceLink(Collection scopes, Layout layout, String packageName) {
22 | this.scopes = scopes;
23 | this.layoutPath = layout.getPath();
24 | this.layoutName = layout.getFileName();
25 | this.javaName = layout.getJavaName();
26 | this.className = layout.getJavaName() + "Controller";
27 | this.packageName = packageName;
28 | }
29 |
30 | @Override
31 | public VelocityContext getVelocityContext() {
32 | VelocityContext vc = new VelocityContext();
33 |
34 | vc.put("layoutName", layoutName);
35 | vc.put("className", className);
36 | vc.put("javaName", javaName);
37 | vc.put("scopes", scopes);
38 | vc.put("layoutPath", layoutPath);
39 | vc.put("package", PACKAGE);
40 | vc.put("packageName", packageName);
41 | return vc;
42 | }
43 |
44 | @Override
45 | public Element[] getElements() {
46 | Element[] elements = new Element[scopes.size()];
47 | Iterator it = scopes.iterator();
48 | int i = 0;
49 | while(it.hasNext()) {
50 | elements[i] = it.next().getJavaElement();
51 | i++;
52 | }
53 | return elements;
54 | }
55 |
56 | @Override
57 | public String getSourceFileName() {
58 | return PACKAGE + "." + className;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return layoutPath;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/source/links/ScopeSourceLink.java:
--------------------------------------------------------------------------------
1 | package com.github.davityle.ngprocessor.source.links;
2 |
3 | import com.github.davityle.ngprocessor.model.Scope;
4 |
5 | import org.apache.velocity.VelocityContext;
6 |
7 | import javax.lang.model.element.Element;
8 |
9 | public class ScopeSourceLink implements SourceLink{
10 |
11 | private final Scope scope;
12 | private final String pack, className;
13 | private final String packageName;
14 |
15 | public ScopeSourceLink(Scope scope, String fullName, String packageName) {
16 | this.scope = scope;
17 | this.pack = fullName.substring(0, fullName.lastIndexOf('.'));
18 | this.className = fullName.substring(fullName.lastIndexOf('.') + 1) + "$$NgScope";
19 | this.packageName = packageName;
20 | }
21 |
22 | @Override
23 | public VelocityContext getVelocityContext() {
24 | VelocityContext vc = new VelocityContext();
25 |
26 | vc.put("scope", scope);
27 | vc.put("className", className);
28 | vc.put("package", pack);
29 | vc.put("packageName", packageName);
30 | return vc;
31 | }
32 |
33 | @Override
34 | public Element[] getElements() {
35 | return new Element[]{scope.getJavaElement()};
36 | }
37 |
38 | @Override
39 | public String getSourceFileName() {
40 | return pack + "." + className;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return getSourceFileName() + ":" + scope.toString();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/source/links/SourceLink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.davityle.ngprocessor.source.links;
18 |
19 | import org.apache.velocity.VelocityContext;
20 |
21 | import javax.lang.model.element.Element;
22 |
23 | /**
24 | * Created by tyler on 3/30/15.
25 | */
26 | public interface SourceLink {
27 | public VelocityContext getVelocityContext();
28 | public Element[] getElements();
29 | public String getSourceFileName();
30 | }
31 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/util/MessageUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Tyler Davis
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.davityle.ngprocessor.util;
18 |
19 | import javax.annotation.processing.ProcessingEnvironment;
20 | import javax.inject.Inject;
21 | import javax.lang.model.element.Element;
22 |
23 | import javax.tools.Diagnostic.Kind;
24 |
25 | /**
26 | * Created by tyler on 3/30/15.
27 | */
28 | public class MessageUtils {
29 |
30 | private final ProcessingEnvironment processingEnv;
31 | private boolean hasErrors = false;
32 |
33 | @Inject
34 | public MessageUtils(ProcessingEnvironment processingEnv){
35 | this.processingEnv = processingEnv;
36 | }
37 |
38 | public void error(Option extends Element> element, String message, Object... args) {
39 | printMessage(Kind.ERROR, element, message, args);
40 | hasErrors = true;
41 | }
42 |
43 | public void note(Option extends Element> element, String message, Object... args){
44 | printMessage(Kind.NOTE, element, message, args);
45 | }
46 |
47 | public void warning(Option extends Element> element, String message, Object... args) {
48 | printMessage(Kind.WARNING, element, message, args);
49 | }
50 |
51 | private void printMessage(Kind kind, Option extends Element> element, String message, Object... args){
52 | if (args.length > 0) {
53 | message = String.format(message, args);
54 | }
55 | processingEnv.getMessager().printMessage(kind, message, element.getOrElse(null));
56 | }
57 |
58 | public boolean hasErrors() {
59 | return hasErrors;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/ng-processor/src/main/java/com/github/davityle/ngprocessor/util/Option.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed To in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.github.davityle.ngprocessor.util;
17 |
18 | /**
19 | * I'd love to use Guava's Optional, but we're trying to keep the dependency
20 | * level to a minimum.
21 | */
22 | public class Option {
23 |
24 | private static final Option> ABSENT = new Option