├── lifecycle.png
├── coordinators
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ ├── ids.xml
│ │ │ └── public.xml
│ │ └── java
│ │ └── com
│ │ └── squareup
│ │ └── coordinators
│ │ ├── Binder.java
│ │ ├── CoordinatorProvider.java
│ │ ├── Coordinator.java
│ │ ├── Binding.java
│ │ └── Coordinators.java
├── gradle.properties
└── build.gradle
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── gradle-mvn-push.gradle
├── settings.gradle
├── coordinators-sample-basic
├── lint.xml
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── ids.xml
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ └── layout
│ │ │ └── tic_tac_toe_view.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── squareup
│ │ └── coordinators
│ │ └── sample
│ │ └── basic
│ │ ├── BasicSampleActivity.java
│ │ ├── TicTacToeBoard.java
│ │ └── TicTacToeCoordinator.java
└── build.gradle
├── coordinators-sample-container
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── ids.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── layout
│ │ │ ├── counter_view.xml
│ │ │ ├── double_detach_view.xml
│ │ │ ├── root_layout.xml
│ │ │ └── tic_tac_toe_view.xml
│ │ └── layout-land
│ │ │ └── root_layout.xml
│ │ ├── java
│ │ └── com
│ │ │ └── squareup
│ │ │ └── coordinators
│ │ │ └── sample
│ │ │ └── container
│ │ │ ├── counter
│ │ │ ├── Counter.java
│ │ │ └── CounterCoordinator.java
│ │ │ ├── doubledetach
│ │ │ └── DoubleDetachCoordinator.java
│ │ │ ├── ObjectGraph.java
│ │ │ ├── tictactoe
│ │ │ ├── TicTacToeBoard.java
│ │ │ └── TicTacToeCoordinator.java
│ │ │ └── ContainerSampleActivity.java
│ │ └── AndroidManifest.xml
├── lint.xml
└── build.gradle
├── .gitignore
├── .travis.yml
├── gradle.properties
├── CONTRIBUTING.md
├── CHANGELOG.md
├── RELEASING.md
├── README.md
├── checkstyle.xml
├── gradlew
└── LICENSE.txt
/lifecycle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/lifecycle.png
--------------------------------------------------------------------------------
/coordinators/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/coordinators/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=coordinators
2 | POM_NAME=Coordinators
3 | POM_PACKAGING=aar
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':coordinators'
2 | include ':coordinators-sample-basic'
3 | include ':coordinators-sample-container'
4 |
--------------------------------------------------------------------------------
/coordinators/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-basic/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-basic/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-basic/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-basic/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-basic/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-container/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-container/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-container/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-container/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/coordinators/master/coordinators-sample-container/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # IntelliJ IDEA
2 | .idea
3 | *.iml
4 | gen
5 |
6 | # Maven
7 | target/
8 | pom.xml.versionsBackup
9 |
10 | # Gradle
11 | .gradle
12 | gradlew.bat
13 | build
14 | local.properties
15 |
--------------------------------------------------------------------------------
/coordinators/src/main/res/values/public.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu May 21 15:45:57 EDT 2020
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-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/coordinators-sample-container/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - tools
6 | - platform-tools
7 | - build-tools-29.0.3
8 | - android-29
9 | - extra-android-m2repository
10 |
11 | jdk: oraclejdk8
12 |
13 | branches:
14 | except:
15 | - gh-pages
16 |
17 | notifications:
18 | email: false
19 |
20 | sudo: false
21 |
22 | cache:
23 | directories:
24 | - $HOME/.m2
25 |
--------------------------------------------------------------------------------
/coordinators/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 |
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.compileSdkVersion
10 | }
11 | buildTypes {
12 | release {
13 | minifyEnabled false
14 | }
15 | }
16 | }
17 |
18 | dependencies {
19 | compileOnly 'androidx.annotation:annotation:1.1.0'
20 | }
21 |
22 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
23 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/java/com/squareup/coordinators/sample/container/counter/Counter.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.container.counter;
2 |
3 | import com.jakewharton.rxrelay2.BehaviorRelay;
4 | import io.reactivex.Observable;
5 |
6 | public class Counter {
7 | private BehaviorRelay count = BehaviorRelay.createDefault(0);
8 |
9 | public Observable count() {
10 | return count;
11 | }
12 |
13 | public void up() {
14 | count.accept(count.getValue() + 1);
15 | }
16 |
17 | public void down() {
18 | count.accept(count.getValue() - 1);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.squareup.coordinators
2 | VERSION_NAME=0.5-SNAPSHOT
3 |
4 | POM_DESCRIPTION=MVWhatever for Android
5 |
6 | POM_URL=https://github.com/square/coordinators/
7 | POM_SCM_URL=https://github.com/square/coordinators/
8 | POM_SCM_CONNECTION=scm:git:git://github.com/square/coordinators.git
9 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/square/coordinators.git
10 |
11 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
12 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
13 | POM_LICENCE_DIST=repo
14 |
15 | POM_DEVELOPER_ID=square
16 | POM_DEVELOPER_NAME=Square, Inc.
17 |
18 | android.useAndroidX=true
19 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ============
3 |
4 | If you would like to contribute code to this project you can do so through
5 | GitHub by forking the repository and sending a pull request.
6 |
7 | When submitting code, please make every effort to follow existing conventions
8 | and style in order to keep the code as readable as possible. Please also make
9 | sure your code compiles by running `./gradlew clean build check`.
10 |
11 | Before your code can be accepted into the project you must also sign the
12 | [Individual Contributor License Agreement (CLA)][1].
13 |
14 |
15 | [1]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1
16 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 0.4 *(2018-03-26)*
5 | --------------------------
6 | * Protects against reentrant calls to `onViewDetachedFromWindow`.
7 | * Changes contract of `isAttached()`, which is now false when `detach()` is called.
8 |
9 | Version 0.3 *(2017-04-28)*
10 | --------------------------
11 | * `installBinder` now binds existing children of the target ViewGroup. (@saantiaguilera)
12 | * Fixes call to `attach` before View is attached to Window.
13 | * Various sample app improvements, unrelated to their use of Coordinators.
14 |
15 | Version 0.2 *(2016-11-30)*
16 | --------------------------
17 | Bump for external release. No difference from 0.1.
18 |
19 | Version 0.1 *(2016-08-12)*
20 | --------------------------
21 | Initial, internal release.
22 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Coordinators Sample
19 |
20 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Coordinators Sample
19 |
20 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/RELEASING.md:
--------------------------------------------------------------------------------
1 | Releasing
2 | ========
3 |
4 | In order to deploy artifacts to a Maven repository, you'll need to set two properties in your private
5 | Gradle properties file (`~/.gradle/gradle.properties`):
6 |
7 | ```
8 | SONATYPE_NEXUS_USERNAME=
9 | SONATYPE_NEXUS_PASSWORD=
10 | ```
11 |
12 | 1. Change the version in `gradle.properties` to a non-SNAPSHOT version.
13 | 2. Update the `CHANGELOG.md` for the impending release.
14 | 3. Update the gradle coordinates in the README.
15 | 4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
16 | 5. `./gradlew clean uploadArchives`.
17 | 6. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact.
18 | 7. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version)
19 | 8. Update the `gradle.properties` to the next SNAPSHOT version.
20 | 8. `git commit -am "Prepare next development version."`
21 | 10. `git push && git push --tags`
22 |
23 | If step 5 or 6 fails, drop the Sonatype repo, fix the problem, commit, and start again at step 4.
24 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #3F51B5
20 | #303F9F
21 | #FF4081
22 | #CCCCCC
23 | #EEEEEE
24 | #6a1b9a
25 |
26 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #3F51B5
20 | #303F9F
21 | #FF4081
22 | #CCCCCC
23 | #EEEEEE
24 | #6a1b9a
25 |
26 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/coordinators-sample-container/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 |
7 | defaultConfig {
8 | applicationId "com.squareup.coordinators.sample.root_layout"
9 |
10 | minSdkVersion 21 // needed for in the layout files in this sample.
11 | versionName VERSION_NAME
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | }
19 | }
20 |
21 | packagingOptions {
22 | exclude 'LICENSE.txt'
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation project(':coordinators')
28 | implementation 'androidx.appcompat:appcompat:1.1.0'
29 | implementation 'com.google.android.material:material:1.1.0'
30 | androidTestImplementation 'androidx.test:runner:1.2.0'
31 | androidTestImplementation 'androidx.test:rules:1.2.0'
32 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
33 | implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.1'
34 | implementation 'io.reactivex.rxjava2:rxjava:2.2.19'
35 | }
36 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 |
7 | defaultConfig {
8 | applicationId "com.squareup.coordinators.sample.basic"
9 |
10 | minSdkVersion rootProject.ext.minSdkVersion
11 | versionName VERSION_NAME
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | }
19 | }
20 |
21 | packagingOptions {
22 | exclude 'LICENSE.txt'
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation project(':coordinators')
28 | implementation 'androidx.appcompat:appcompat:1.1.0'
29 | implementation 'com.google.android.material:material:1.1.0'
30 | implementation 'androidx.gridlayout:gridlayout:1.0.0'
31 | androidTestImplementation 'androidx.test:runner:1.2.0'
32 | androidTestImplementation 'androidx.test:rules:1.2.0'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34 | implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.1'
35 | implementation 'io.reactivex.rxjava2:rxjava:2.2.19'
36 | }
37 |
--------------------------------------------------------------------------------
/coordinators/src/main/java/com/squareup/coordinators/Binder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Square, Inc.
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 | package com.squareup.coordinators;
17 |
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import androidx.annotation.NonNull;
21 |
22 | final class Binder implements ViewGroup.OnHierarchyChangeListener {
23 | private final CoordinatorProvider provider;
24 |
25 | Binder(@NonNull CoordinatorProvider provider) {
26 | this.provider = provider;
27 | }
28 |
29 | @Override public void onChildViewAdded(View parent, View child) {
30 | Coordinators.bind(child, provider);
31 | }
32 |
33 | @Override public void onChildViewRemoved(View parent, View child) {
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/coordinators/src/main/java/com/squareup/coordinators/CoordinatorProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Square, Inc.
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 | package com.squareup.coordinators;
17 |
18 | import android.view.View;
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | public interface CoordinatorProvider {
23 |
24 | /**
25 | * Called to obtain a {@link Coordinator} for a View.
26 | *
27 | * Called from {@link Coordinators#bind}. Whether or not Coordinator instances are reused is up
28 | * to the implementer, but a Coordinator instance may only be bound to one View instance at a
29 | * time.
30 | *
31 | * @return null if the view has no associated coordinator
32 | */
33 | @Nullable Coordinator provideCoordinator(@NonNull View view);
34 | }
35 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/java/com/squareup/coordinators/sample/container/doubledetach/DoubleDetachCoordinator.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.container.doubledetach;
2 |
3 | import android.app.Activity;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import androidx.annotation.NonNull;
7 | import com.squareup.coordinators.Coordinator;
8 | import com.squareup.coordinators.sample.container.R;
9 |
10 | public class DoubleDetachCoordinator extends Coordinator {
11 | private int attachCount = 0;
12 |
13 | @Override public void attach(@NonNull View view) {
14 | attachCount++;
15 | super.attach(view);
16 |
17 | View button = view.findViewById(R.id.double_detach_button);
18 | button.setOnClickListener(new View.OnClickListener() {
19 | @Override public void onClick(View v) {
20 | Activity activity = (Activity) v.getContext();
21 | activity.finish();
22 | }
23 | });
24 | }
25 |
26 | @Override public void detach(@NonNull View view) {
27 | attachCount--;
28 | if (attachCount != 0) {
29 | // This would throw before https://github.com/square/coordinators/issues/28 was fixed.
30 | throw new AssertionError("Attach/detach imbalance! " + attachCount);
31 | }
32 |
33 |
34 | ViewGroup parent = (ViewGroup) view.getParent();
35 | parent.removeAllViews();
36 |
37 | super.detach(view);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Coordinators
2 | ============
3 |
4 | Simple lifecycle for your MVWhatever on Android. No kidding.
5 |
6 | 
7 |
8 | ```java
9 | class ExampleCoordinator extends Coordinator {
10 |
11 | @Override public void attach(View view) {
12 | // Attach listeners, load state, whatever.
13 | }
14 |
15 | @Override public void detach(View view) {
16 | // Unbind listeners, save state, go nuts.
17 | }
18 | }
19 | ```
20 |
21 | ```java
22 | // Create a factory for your Coordinators.
23 | CoordinatorProvider coordinatorProvider; // @Nullable (View) -> Coordinator
24 |
25 | // Bind a Coordinator to a View.
26 | Coordinators.bind(view, coordinatorProvider);
27 |
28 | // Bind a Coordinator to any child View added to a group.
29 | Coordinators.installBinder(viewGroup, coordinatorProvider);
30 | ```
31 |
32 | Download
33 | --------
34 |
35 | ```groovy
36 | dependencies {
37 | api 'com.squareup.coordinators:coordinators:0.4'
38 | }
39 | ```
40 |
41 | License
42 | -------
43 |
44 | Copyright 2016 Square
45 |
46 | Licensed under the Apache License, Version 2.0 (the "License");
47 | you may not use this file except in compliance with the License.
48 | You may obtain a copy of the License at
49 |
50 | http://www.apache.org/licenses/LICENSE-2.0
51 |
52 | Unless required by applicable law or agreed to in writing, software
53 | distributed under the License is distributed on an "AS IS" BASIS,
54 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55 | See the License for the specific language governing permissions and
56 | limitations under the License.
57 |
58 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/java/com/squareup/coordinators/sample/container/counter/CounterCoordinator.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.container.counter;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 | import com.squareup.coordinators.Coordinator;
6 | import com.squareup.coordinators.sample.container.R;
7 | import io.reactivex.disposables.Disposable;
8 | import io.reactivex.functions.Consumer;
9 |
10 | public class CounterCoordinator extends Coordinator {
11 | private final Counter counter;
12 |
13 | private Disposable subscription = null;
14 |
15 | public CounterCoordinator(Counter counter) {
16 | this.counter = counter;
17 | }
18 |
19 | @Override public void attach(final View view) {
20 | super.attach(view);
21 |
22 | final TextView textView = (TextView) view.findViewById(R.id.counter_value);
23 | final View up = view.findViewById(R.id.count_up);
24 | final View down = view.findViewById(R.id.count_down);
25 |
26 | subscription = counter.count().subscribe(new Consumer() {
27 | @Override public void accept(Integer count) throws Exception {
28 | textView.setText(String.format("%s", count));
29 | }
30 | });
31 |
32 | up.setOnClickListener(new View.OnClickListener() {
33 | @Override public void onClick(View v) {
34 | counter.up();
35 | }
36 | });
37 |
38 | down.setOnClickListener(new View.OnClickListener() {
39 | @Override public void onClick(View v) {
40 | counter.down();
41 | }
42 | });
43 | }
44 |
45 | @Override public void detach(View view) {
46 | subscription.dispose();
47 | super.detach(view);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/layout/counter_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
24 |
25 |
35 |
36 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/java/com/squareup/coordinators/sample/container/ObjectGraph.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.container;
2 |
3 | import com.squareup.coordinators.sample.container.counter.Counter;
4 | import com.squareup.coordinators.sample.container.counter.CounterCoordinator;
5 | import com.squareup.coordinators.sample.container.doubledetach.DoubleDetachCoordinator;
6 | import com.squareup.coordinators.sample.container.tictactoe.TicTacToeBoard;
7 | import com.squareup.coordinators.sample.container.tictactoe.TicTacToeCoordinator;
8 |
9 | /**
10 | * All the objects. In real life might be generated, e.g. by Dagger.
11 | */
12 | class ObjectGraph {
13 | private final Counter counter = new Counter();
14 | private final TicTacToeBoard ticTacToe = new TicTacToeBoard();
15 |
16 | private CounterCoordinator counterCoordinator() {
17 | return new CounterCoordinator(counter);
18 | }
19 |
20 | private DoubleDetachCoordinator doubleDetachCoordinator() {
21 | return new DoubleDetachCoordinator();
22 | }
23 |
24 | private TicTacToeCoordinator ticTacToeCoordinator() {
25 | return new TicTacToeCoordinator(ticTacToe);
26 | }
27 |
28 | @SuppressWarnings("unchecked") //
29 | T get(String className) {
30 | if (TicTacToeCoordinator.class.getName().equals(className)) {
31 | return (T) ticTacToeCoordinator();
32 | }
33 |
34 | if (DoubleDetachCoordinator.class.getName().equals(className)) {
35 | return (T) doubleDetachCoordinator();
36 | }
37 |
38 | if (CounterCoordinator.class.getName().equals(className)) {
39 | return (T) counterCoordinator();
40 | }
41 |
42 | throw new IllegalArgumentException("Unknown class: " + className);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/layout/double_detach_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
19 |
20 |
31 |
32 |
41 |
42 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/coordinators/src/main/java/com/squareup/coordinators/Coordinator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Square, Inc.
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 | package com.squareup.coordinators;
17 |
18 | import android.view.View;
19 | import androidx.annotation.NonNull;
20 |
21 | /**
22 | * A Coordinator is attached to one view at a time.
23 | *
24 | * What you do from there is up to you.
25 | *
26 | * @see CoordinatorProvider
27 | */
28 | public class Coordinator {
29 |
30 | private boolean attached;
31 |
32 | final void setAttached(boolean attached) {
33 | this.attached = attached;
34 | }
35 |
36 | /**
37 | * Called when the view is attached to a Window.
38 | *
39 | * Default implementation does nothing.
40 | *
41 | * @see View#onAttachedToWindow()
42 | */
43 | public void attach(@NonNull View view) {
44 | }
45 |
46 | /**
47 | * Called when the view is detached from a Window.
48 | *
49 | * Default implementation does nothing.
50 | *
51 | * @see View#onDetachedFromWindow()
52 | */
53 | public void detach(@NonNull View view) {
54 | }
55 |
56 | /**
57 | * True from just before {@link #attach} until just before {@link #detach}.
58 | */
59 | public final boolean isAttached() {
60 | return attached;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/java/com/squareup/coordinators/sample/basic/BasicSampleActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Square Inc.
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.squareup.coordinators.sample.basic;
18 |
19 | import android.app.Activity;
20 | import android.os.Bundle;
21 | import android.view.View;
22 | import androidx.annotation.Nullable;
23 | import com.squareup.coordinators.Coordinator;
24 | import com.squareup.coordinators.CoordinatorProvider;
25 | import com.squareup.coordinators.Coordinators;
26 |
27 | public class BasicSampleActivity extends Activity {
28 |
29 | private static final TicTacToeBoard MODEL = new TicTacToeBoard();
30 |
31 | @Override protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.tic_tac_toe_view);
34 |
35 | Coordinators.bind(findViewById(R.id.board_view), new CoordinatorProvider() {
36 | @Nullable @Override public Coordinator provideCoordinator(View view) {
37 |
38 | // A more interesting app could inspect the given view and choose an
39 | // appropriate coordinator for it -- perhaps based on the type of the view,
40 | // on on meta information in a tag on the view, so many possibilities...
41 |
42 | return new TicTacToeCoordinator(MODEL);
43 | }
44 | });
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/coordinators/src/main/java/com/squareup/coordinators/Binding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Square, Inc.
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 | package com.squareup.coordinators;
17 |
18 | import android.view.View;
19 | import androidx.annotation.NonNull;
20 |
21 | final class Binding implements View.OnAttachStateChangeListener {
22 | private final Coordinator coordinator;
23 | private final View view;
24 |
25 | Binding(@NonNull Coordinator coordinator, @NonNull View view) {
26 | this.coordinator = coordinator;
27 | this.view = view;
28 | }
29 |
30 | @Override public void onViewAttachedToWindow(@NonNull View v) {
31 | if (v != view) {
32 | throw new AssertionError("Binding for view " + view
33 | + " notified of attachment of different view " + v);
34 | }
35 | if (coordinator.isAttached()) {
36 | throw new IllegalStateException(
37 | "Coordinator " + coordinator + " is already attached");
38 | }
39 | coordinator.setAttached(true);
40 | coordinator.attach(view);
41 | view.setTag(R.id.coordinator, coordinator);
42 | }
43 |
44 | @Override public void onViewDetachedFromWindow(@NonNull View v) {
45 | if (v != view) {
46 | throw new AssertionError("Binding for view " + view
47 | + " notified of detachment of different view " + v);
48 | }
49 | if (!coordinator.isAttached()) {
50 | // Android tries not to make reentrant calls, but doesn't always succeed.
51 | // See https://github.com/square/coordinators/issues/28
52 | return;
53 | }
54 | coordinator.setAttached(false);
55 | coordinator.detach(view);
56 | view.setTag(R.id.coordinator, null);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/layout/root_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
32 |
33 |
46 |
47 |
60 |
61 |
62 |
63 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/layout-land/root_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
33 |
34 |
47 |
48 |
61 |
62 |
63 |
64 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/java/com/squareup/coordinators/sample/basic/TicTacToeBoard.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.basic;
2 |
3 | import android.os.Looper;
4 | import com.jakewharton.rxrelay2.BehaviorRelay;
5 | import io.reactivex.Observable;
6 | import io.reactivex.functions.BiPredicate;
7 | import java.util.Arrays;
8 |
9 | import static com.squareup.coordinators.sample.basic.TicTacToeBoard.Value.EMPTY;
10 | import static java.lang.String.format;
11 |
12 | final class TicTacToeBoard {
13 | enum Value {
14 | EMPTY(""), X, O;
15 |
16 | final String text;
17 |
18 | Value() {
19 | this.text = name();
20 | }
21 |
22 | Value(String text) {
23 | this.text = text;
24 | }
25 | }
26 |
27 | private BehaviorRelay grid = BehaviorRelay.createDefault(new Value[][] {
28 | { EMPTY, EMPTY, EMPTY }, //
29 | { EMPTY, EMPTY, EMPTY }, //
30 | { EMPTY, EMPTY, EMPTY }
31 | });
32 |
33 | /**
34 | * Returns an observable of the tic tac toe board. First value is provided immediately,
35 | * succeeding values are guaranteed to be distinct from previous values. Values are
36 | * always provided on the main thread.
37 | */
38 | public Observable grid() {
39 | return grid.distinctUntilChanged(new BiPredicate() {
40 | @Override public boolean test(Value[][] a, Value[][] b) throws Exception {
41 | return Arrays.equals(a, b);
42 | }
43 | });
44 | }
45 |
46 | /**
47 | * Change the value of a cell. Must be called from the main thread.
48 | */
49 | public void set(int row, int col, Value value) {
50 | assertOnMain();
51 | assertIndex("row", row);
52 | assertIndex("col", col);
53 |
54 | Value[][] newGrid = new Value[3][];
55 | for (int i = 0; i < 3; i++) {
56 | newGrid[i] = grid.getValue()[i].clone();
57 | }
58 |
59 | newGrid[row][col] = value;
60 | grid.accept(newGrid);
61 | }
62 |
63 | private void assertIndex(String label, int index) {
64 | if (index < 0 || index > 2) {
65 | throw new IllegalArgumentException(format("%s must be 0, 1 or 2", label));
66 | }
67 | }
68 |
69 | private void assertOnMain() {
70 | // https://speakerdeck.com/rjrjr/where-the-reactive-rubber-meets-the-road
71 |
72 | if (!(Looper.getMainLooper().getThread() == Thread.currentThread())) {
73 | throw new AssertionError("Model updates must come from main thread.");
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/java/com/squareup/coordinators/sample/container/tictactoe/TicTacToeBoard.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.container.tictactoe;
2 |
3 | import android.os.Looper;
4 | import com.jakewharton.rxrelay2.BehaviorRelay;
5 | import io.reactivex.Observable;
6 | import io.reactivex.functions.BiPredicate;
7 | import java.util.Arrays;
8 |
9 | import static com.squareup.coordinators.sample.container.tictactoe.TicTacToeBoard.Value.EMPTY;
10 | import static java.lang.String.format;
11 |
12 | public final class TicTacToeBoard {
13 | enum Value {
14 | EMPTY(""), X, O;
15 |
16 | final String text;
17 |
18 | Value() {
19 | this.text = name();
20 | }
21 |
22 | Value(String text) {
23 | this.text = text;
24 | }
25 | }
26 |
27 | private BehaviorRelay grid = BehaviorRelay.createDefault(new Value[][] {
28 | { EMPTY, EMPTY, EMPTY }, //
29 | { EMPTY, EMPTY, EMPTY }, //
30 | { EMPTY, EMPTY, EMPTY }
31 | });
32 |
33 | /**
34 | * Returns an observable of the tic tac toe board. First value is provided immediately,
35 | * succeeding values are guaranteed to be distinct from previous values. Values are
36 | * always provided on the main thread.
37 | */
38 | Observable grid() {
39 | return grid.distinctUntilChanged(new BiPredicate() {
40 | @Override public boolean test(Value[][] a, Value[][] b) throws Exception {
41 | return Arrays.equals(a, b);
42 | }
43 | });
44 | }
45 |
46 | /**
47 | * Change the value of a cell. Must be called from the main thread.
48 | */
49 | void set(int row, int col, Value value) {
50 | assertOnMain();
51 | assertIndex("row", row);
52 | assertIndex("col", col);
53 |
54 | Value[][] newGrid = new Value[3][];
55 | for (int i = 0; i < 3; i++) {
56 | newGrid[i] = grid.getValue()[i].clone();
57 | }
58 |
59 | newGrid[row][col] = value;
60 | grid.accept(newGrid);
61 | }
62 |
63 | private void assertIndex(String label, int index) {
64 | if (index < 0 || index > 2) {
65 | throw new IllegalArgumentException(format("%s must be 0, 1 or 2", label));
66 | }
67 | }
68 |
69 | private void assertOnMain() {
70 | // https://speakerdeck.com/rjrjr/where-the-reactive-rubber-meets-the-road
71 |
72 | if (!(Looper.getMainLooper().getThread() == Thread.currentThread())) {
73 | throw new AssertionError("Model updates must come from main thread.");
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/java/com/squareup/coordinators/sample/basic/TicTacToeCoordinator.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.basic;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 | import android.widget.TextView;
6 | import com.squareup.coordinators.Coordinator;
7 | import com.squareup.coordinators.sample.basic.TicTacToeBoard.Value;
8 | import io.reactivex.disposables.Disposable;
9 | import io.reactivex.functions.Consumer;
10 |
11 | /**
12 | * Binds a {@link ViewGroup} with nine TextView children to a
13 | * {@link TicTacToeBoard}.
14 | */
15 | public class TicTacToeCoordinator extends Coordinator {
16 | private final TicTacToeBoard board;
17 |
18 | private Disposable subscription;
19 |
20 | public TicTacToeCoordinator(TicTacToeBoard board) {
21 | this.board = board;
22 | }
23 |
24 | @Override public void attach(View view) {
25 | super.attach(view);
26 |
27 | final ViewGroup viewGroup = (ViewGroup) view;
28 | subscription = board.grid().subscribe(new Consumer() {
29 | @Override public void accept(Value[][] values) throws Exception {
30 | refresh(viewGroup, values);
31 | }
32 | });
33 | setCellClickListeners(viewGroup);
34 | }
35 |
36 | @Override public void detach(View view) {
37 | subscription.dispose();
38 | super.detach(view);
39 | }
40 |
41 | private void setCellClickListeners(ViewGroup viewGroup) {
42 | for (int i = 0; i < 9; i++) {
43 | final int index = i;
44 | final View cell = viewGroup.getChildAt(i);
45 |
46 | cell.setOnClickListener(new View.OnClickListener() {
47 | @Override public void onClick(View v) {
48 | toggle(cell, index);
49 | }
50 | });
51 | }
52 | }
53 |
54 | private void refresh(ViewGroup viewGroup, Value[][] values) {
55 | for (int i = 0; i < 9; i++) {
56 | int row = i / 3;
57 | int col = i % 3;
58 |
59 | TextView cell = (TextView) (viewGroup).getChildAt(i);
60 | Value value = values[row][col];
61 | cell.setText(value.text);
62 | cell.setTag(R.id.tic_tac_toe_cell_value_tag, value);
63 | }
64 | }
65 |
66 | private void toggle(View cell, int index) {
67 | Value oldValue = (Value) cell.getTag(R.id.tic_tac_toe_cell_value_tag);
68 | Value[] values = Value.values();
69 | Value newValue = values[(oldValue.ordinal() + 1) % values.length];
70 |
71 | int row = index / 3;
72 | int col = index % 3;
73 |
74 | board.set(row, col, newValue);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/java/com/squareup/coordinators/sample/container/tictactoe/TicTacToeCoordinator.java:
--------------------------------------------------------------------------------
1 | package com.squareup.coordinators.sample.container.tictactoe;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 | import android.widget.TextView;
6 | import com.squareup.coordinators.Coordinator;
7 | import com.squareup.coordinators.sample.container.R;
8 | import com.squareup.coordinators.sample.container.tictactoe.TicTacToeBoard.Value;
9 | import io.reactivex.disposables.Disposable;
10 | import io.reactivex.functions.Consumer;
11 |
12 | /**
13 | * Binds a {@link ViewGroup} with nine TextView children to a
14 | * {@link TicTacToeBoard}.
15 | */
16 | public class TicTacToeCoordinator extends Coordinator {
17 | private final TicTacToeBoard board;
18 |
19 | private Disposable subscription;
20 |
21 | public TicTacToeCoordinator(TicTacToeBoard board) {
22 | this.board = board;
23 | }
24 |
25 | @Override public void attach(View view) {
26 | super.attach(view);
27 |
28 | final ViewGroup viewGroup = (ViewGroup) view;
29 | subscription = board.grid().subscribe(new Consumer() {
30 | @Override public void accept(Value[][] values) throws Exception {
31 | refresh(viewGroup, values);
32 | }
33 | });
34 | setCellClickListeners(viewGroup);
35 | }
36 |
37 | @Override public void detach(View view) {
38 | subscription.dispose();
39 | subscription = null;
40 | super.detach(view);
41 | }
42 |
43 | private void setCellClickListeners(ViewGroup viewGroup) {
44 | for (int i = 0; i < 9; i++) {
45 | final int index = i;
46 | final View cell = viewGroup.getChildAt(i);
47 |
48 | cell.setOnClickListener(new View.OnClickListener() {
49 | @Override public void onClick(View v) {
50 | toggle(cell, index);
51 | }
52 | });
53 | }
54 | }
55 |
56 | private void refresh(ViewGroup viewGroup, Value[][] values) {
57 | for (int i = 0; i < 9; i++) {
58 | int row = i / 3;
59 | int col = i % 3;
60 |
61 | TextView cell = (TextView) (viewGroup).getChildAt(i);
62 | Value value = values[row][col];
63 | cell.setText(value.text);
64 | cell.setTag(R.id.tic_tac_toe_cell_value_tag, value);
65 | }
66 | }
67 |
68 | private void toggle(View cell, int index) {
69 | Value oldValue = (Value) cell.getTag(R.id.tic_tac_toe_cell_value_tag);
70 | Value[] values = Value.values();
71 | Value newValue = values[(oldValue.ordinal() + 1) % values.length];
72 |
73 | int row = index / 3;
74 | int col = index % 3;
75 |
76 | board.set(row, col, newValue);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/coordinators/src/main/java/com/squareup/coordinators/Coordinators.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Square, Inc.
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 | package com.squareup.coordinators;
17 |
18 | import android.os.Build;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 |
24 | public final class Coordinators {
25 | private Coordinators() {
26 | }
27 |
28 | /**
29 | * Attempts to bind a view to a {@link Coordinator}.
30 | *
31 | * Immediately calls provider to obtain a Coordinator for the view. If a non-null Coordinator is
32 | * returned, that Coordinator is permanently bound to the View.
33 | */
34 | public static void bind(@NonNull View view, @NonNull CoordinatorProvider provider) {
35 | final Coordinator coordinator = provider.provideCoordinator(view);
36 | if (coordinator == null) {
37 | return;
38 | }
39 |
40 | View.OnAttachStateChangeListener binding = new Binding(coordinator, view);
41 | view.addOnAttachStateChangeListener(binding);
42 | // Sometimes we missed the first attach because the child's already been added.
43 | // Sometimes we didn't. The binding keeps track to avoid double attachment of the Coordinator,
44 | // and to guard against attachment to two different views simultaneously.
45 | if (isAttachedToWindow(view)) {
46 | binding.onViewAttachedToWindow(view);
47 | }
48 | }
49 |
50 | /**
51 | * Installs a binder that calls {@link #bind(View, CoordinatorProvider)} for any child view added
52 | * to the group.
53 | */
54 | public static void installBinder(@NonNull ViewGroup viewGroup,
55 | @NonNull final CoordinatorProvider provider) {
56 | int childCount = viewGroup.getChildCount();
57 | for (int i = 0; i < childCount; i++) {
58 | bind(viewGroup.getChildAt(i), provider);
59 | }
60 | viewGroup.setOnHierarchyChangeListener(new Binder(provider));
61 | }
62 |
63 | @Nullable public static Coordinator getCoordinator(@NonNull View view) {
64 | return (Coordinator) view.getTag(R.id.coordinator);
65 | }
66 |
67 | private static boolean isAttachedToWindow(View view) {
68 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
69 | return view.getWindowToken() != null;
70 | } else {
71 | return view.isAttachedToWindow();
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/java/com/squareup/coordinators/sample/container/ContainerSampleActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Square Inc.
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.squareup.coordinators.sample.container;
18 |
19 | import android.app.Activity;
20 | import android.os.Bundle;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import androidx.annotation.LayoutRes;
25 | import androidx.annotation.NonNull;
26 | import androidx.annotation.Nullable;
27 | import com.squareup.coordinators.Coordinator;
28 | import com.squareup.coordinators.CoordinatorProvider;
29 | import com.squareup.coordinators.Coordinators;
30 |
31 | public class ContainerSampleActivity extends Activity {
32 | private static final ObjectGraph OBJECT_GRAPH = new ObjectGraph();
33 |
34 | private static @LayoutRes int currentScreen;
35 |
36 | private ViewGroup container;
37 |
38 | @Override protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 |
41 | setContentView(R.layout.root_layout);
42 | container = findViewById(R.id.container);
43 |
44 | // Make each button show the layout identified in its tag. See root_layout.xml
45 |
46 | ViewGroup buttons = findViewById(R.id.buttons);
47 | for (int i = 0; i < buttons.getChildCount(); i++) {
48 | View button = buttons.getChildAt(i);
49 |
50 | String layoutName = (String) button.getTag(R.id.layout_to_show_tag);
51 | layoutName = layoutName.substring("res/layout/".length());
52 | layoutName = layoutName.substring(0, layoutName.length() - ".xml".length());
53 |
54 | final int layout = getResources().getIdentifier(layoutName, "layout", getPackageName());
55 |
56 | button.setOnClickListener(new View.OnClickListener() {
57 | @Override public void onClick(View v) {
58 | showScreen(layout);
59 | }
60 | });
61 | }
62 |
63 | // Install a binder that will be called as each child view is added to the container
64 | // layout. Our binder expects each view to have a tag with the classname of the coordinator
65 | // that knows how to drive it. Again, we're setting those tags in the layout files themselves,
66 | // BECAUSE WE CAN!
67 |
68 | Coordinators.installBinder(container, new CoordinatorProvider() {
69 | @Nullable @Override public Coordinator provideCoordinator(@NonNull View view) {
70 | String coordinatorName = (String) view.getTag(R.id.coordinator_class_tag);
71 | return OBJECT_GRAPH.get(coordinatorName);
72 | }
73 | });
74 |
75 | refresh();
76 | }
77 |
78 | private void showScreen(@LayoutRes int id) {
79 | currentScreen = id;
80 | refresh();
81 | }
82 |
83 | private void refresh() {
84 | container.removeAllViews();
85 | if (currentScreen != 0) {
86 | LayoutInflater.from(container.getContext()).inflate(currentScreen, container);
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/gradle/gradle-mvn-push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
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 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return VERSION_NAME.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getReleaseRepositoryUrl() {
25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
31 | : "https://oss.sonatype.org/content/repositories/snapshots/"
32 | }
33 |
34 | def getRepositoryUsername() {
35 | return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : ""
36 | }
37 |
38 | def getRepositoryPassword() {
39 | return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : ""
40 | }
41 |
42 | afterEvaluate { project ->
43 | uploadArchives {
44 | repositories {
45 | mavenDeployer {
46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
47 |
48 | pom.groupId = GROUP
49 | pom.artifactId = POM_ARTIFACT_ID
50 | pom.version = VERSION_NAME
51 |
52 | repository(url: getReleaseRepositoryUrl()) {
53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
54 | }
55 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
57 | }
58 |
59 | pom.project {
60 | name POM_NAME
61 | packaging POM_PACKAGING
62 | description POM_DESCRIPTION
63 | url POM_URL
64 |
65 | scm {
66 | url POM_SCM_URL
67 | connection POM_SCM_CONNECTION
68 | developerConnection POM_SCM_DEV_CONNECTION
69 | }
70 |
71 | licenses {
72 | license {
73 | name POM_LICENCE_NAME
74 | url POM_LICENCE_URL
75 | distribution POM_LICENCE_DIST
76 | }
77 | }
78 |
79 | developers {
80 | developer {
81 | id POM_DEVELOPER_ID
82 | name POM_DEVELOPER_NAME
83 | }
84 | }
85 | }
86 | }
87 | }
88 | }
89 |
90 | signing {
91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
92 | sign configurations.archives
93 | }
94 |
95 | task androidJavadocs(type: Javadoc) {
96 | source = android.sourceSets.main.java.srcDirs
97 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
98 | classpath += project.configurations.releaseCompileClasspath
99 | }
100 |
101 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
102 | classifier = 'javadoc'
103 | from androidJavadocs.destinationDir
104 | }
105 |
106 | task androidSourcesJar(type: Jar) {
107 | classifier = 'sources'
108 | from android.sourceSets.main.java.sourceFiles
109 | }
110 |
111 | artifacts {
112 | archives androidSourcesJar
113 | archives androidJavadocsJar
114 | }
115 | }
--------------------------------------------------------------------------------
/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
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 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
--------------------------------------------------------------------------------
/coordinators-sample-basic/src/main/res/layout/tic_tac_toe_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
29 |
30 |
44 |
45 |
59 |
60 |
74 |
75 |
76 |
90 |
91 |
105 |
106 |
120 |
121 |
135 |
136 |
150 |
151 |
165 |
166 |
--------------------------------------------------------------------------------
/coordinators-sample-container/src/main/res/layout/tic_tac_toe_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
27 |
28 |
32 |
33 |
47 |
48 |
62 |
63 |
77 |
78 |
79 |
93 |
94 |
108 |
109 |
123 |
124 |
138 |
139 |
153 |
154 |
168 |
169 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin or MSYS, switch paths to Windows format before running java
129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=`expr $i + 1`
158 | done
159 | case $i in
160 | 0) set -- ;;
161 | 1) set -- "$args0" ;;
162 | 2) set -- "$args0" "$args1" ;;
163 | 3) set -- "$args0" "$args1" "$args2" ;;
164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=`save "$@"`
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185 | cd "$(dirname "$0")"
186 | fi
187 |
188 | exec "$JAVACMD" "$@"
189 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------