├── sample
├── .gitignore
├── debug.jks
├── release.jks
├── src
│ └── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── menu
│ │ │ └── menu_main.xml
│ │ └── layout
│ │ │ ├── activity_not_registered.xml
│ │ │ ├── activity_target.xml
│ │ │ ├── activity_web.xml
│ │ │ ├── activity_container.xml
│ │ │ └── activity_main.xml
│ │ ├── java
│ │ └── me
│ │ │ └── drakeet
│ │ │ └── floo
│ │ │ └── sample
│ │ │ ├── NotRegisteredActivity.java
│ │ │ ├── URLs.java
│ │ │ ├── TargetNotFoundToaster.java
│ │ │ ├── WebHandler.java
│ │ │ ├── entity
│ │ │ └── Mail.java
│ │ │ ├── TargetActivity.java
│ │ │ ├── App.java
│ │ │ ├── WebActivity.java
│ │ │ ├── ContainerActivity.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ └── main
│ │ ├── java
│ │ └── me
│ │ │ └── drakeet
│ │ │ └── floo
│ │ │ ├── DefaultIntentHandler.java
│ │ │ ├── Preconditions.java
│ │ │ ├── IntentHandler.java
│ │ │ ├── Interceptor.java
│ │ │ ├── IntentReceiver.java
│ │ │ ├── StackCallback.java
│ │ │ ├── InvalidJsonException.java
│ │ │ ├── StackStates.java
│ │ │ ├── extensions
│ │ │ ├── LogInterceptor.java
│ │ │ └── OpenDirectlyHandler.java
│ │ │ ├── TargetMap.java
│ │ │ ├── Target.java
│ │ │ ├── Urls.java
│ │ │ ├── Chain.java
│ │ │ ├── TargetNotFoundHandler.java
│ │ │ ├── ActivityOnResumeCallback.java
│ │ │ ├── Stack.java
│ │ │ ├── Navigation.java
│ │ │ ├── TargetMapParser.java
│ │ │ ├── StackManager.java
│ │ │ ├── Configuration.java
│ │ │ └── Floo.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
├── build.gradle
├── gradle.properties
└── gradle-mvn-push.gradle
├── url-parts.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── findbugs.xml
├── settings.gradle
├── .travis.yml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
├── checkstyle.xml
├── README.md
└── LICENSE
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/url-parts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/url-parts.png
--------------------------------------------------------------------------------
/sample/debug.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/debug.jks
--------------------------------------------------------------------------------
/sample/release.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/release.jks
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drakeet/Floo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/findbugs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Apr 28 13:51:19 CST 2019
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-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/DefaultIntentHandler.java:
--------------------------------------------------------------------------------
1 | package me.drakeet.floo;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import androidx.annotation.NonNull;
6 |
7 | /**
8 | * @author drakeet
9 | */
10 | public class DefaultIntentHandler implements IntentHandler {
11 |
12 | @Override
13 | public void onIntentCreated(@NonNull Context context, @NonNull Intent intent) {
14 | context.startActivity(intent);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Preconditions.java:
--------------------------------------------------------------------------------
1 | package me.drakeet.floo;
2 |
3 | import androidx.annotation.NonNull;
4 |
5 | /**
6 | * @author drakeet
7 | */
8 | public final class Preconditions {
9 |
10 | @NonNull
11 | @SuppressWarnings("ConstantConditions")
12 | public static T checkNotNull(@NonNull final T object) {
13 | if (object == null) {
14 | throw new NullPointerException();
15 | }
16 | return object;
17 | }
18 |
19 | private Preconditions() {}
20 | }
21 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/IntentHandler.java:
--------------------------------------------------------------------------------
1 | package me.drakeet.floo;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import androidx.annotation.NonNull;
6 |
7 | /**
8 | * @author drakeet
9 | */
10 | public interface IntentHandler {
11 |
12 | /**
13 | * Called immediately after intent has created on {@link Floo#start()}.
14 | *
15 | * @param context The context.
16 | * @param intent The intent.
17 | */
18 | void onIntentCreated(@NonNull Context context, @NonNull Intent intent);
19 | }
20 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 | include ':library'
18 | include ':sample'
19 |
--------------------------------------------------------------------------------
/library/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 /Users/drakeet/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/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 /Users/drakeet/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #FFFFFF
20 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Interceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | /**
22 | * @author drakeet
23 | */
24 | public interface Interceptor {
25 |
26 | @NonNull Chain intercept(@NonNull Chain chain);
27 | }
28 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 | Floo
21 | Loading...
22 |
23 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #4688F1
20 | #366AD3
21 | #FF4081
22 |
23 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 |
4 | env:
5 | global:
6 | - ANDROID_TARGET=android-25
7 | - ANDROID_BUILD_TOOLS_VERSION=26.0.1
8 | - ANDROID_ABI=armeabi-v7a
9 |
10 | android:
11 | components:
12 | - tools
13 | - build-tools-$ANDROID_BUILD_TOOLS_VERSION
14 | - android-22
15 | - $ANDROID_TARGET
16 | - sys-img-armeabi-v7a-android-22
17 | - extra-android-m2repository
18 | - extra-android-support
19 | - extra
20 | licenses:
21 | - android-sdk-license-.+
22 |
23 | before_install:
24 | - echo yes | android update sdk --all --filter build-tools-$ANDROID_BUILD_TOOLS_VERSION --no-ui --force
25 |
26 | before_script:
27 | - chmod +x gradlew
28 | - echo no | android create avd --force -n test -t android-22 --abi $ANDROID_ABI
29 | - emulator -avd test -no-window &
30 | - android-wait-for-emulator
31 | - adb shell input keyevent 82 &
32 |
33 | script:
34 | - ./gradlew clean connectedAndroidTest
35 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/IntentReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.content.Intent;
20 | import androidx.annotation.NonNull;
21 |
22 | /**
23 | * @author drakeet
24 | */
25 | public interface IntentReceiver {
26 |
27 | void onReceived(@NonNull Intent intent);
28 | }
29 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/StackCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import androidx.annotation.Nullable;
20 |
21 | /**
22 | * @author drakeet
23 | */
24 | public interface StackCallback {
25 |
26 | @Nullable String indexKeyForStackTarget();
27 |
28 | void onReceivedResult(@Nullable Object result);
29 | }
30 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Android template
3 | # Built application files
4 | *.apk
5 | *.ap_
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio Navigation editor temp files
32 | .navigation/
33 |
34 | # Android Studio captures folder
35 | captures/
36 |
37 | # Intellij
38 | *.iml
39 | .idea/workspace.xml
40 | .idea/tasks.xml
41 | .idea/gradle.xml
42 | .idea/dictionaries
43 | .idea/libraries
44 |
45 | # External native build folder generated in Android Studio 2.2 and later
46 | .externalNativeBuild
47 |
48 | # Google Services (e.g. APIs or Firebase)
49 | google-services.json
50 |
51 | # Freeline
52 | freeline.py
53 | freeline/
54 | freeline_project_description.json
55 |
56 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/InvalidJsonException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | /**
22 | * @author drakeet
23 | */
24 | class InvalidJsonException extends RuntimeException {
25 |
26 | InvalidJsonException(@NonNull String json, @NonNull Throwable throwable) {
27 | super("Invalid JSON: " + json, throwable);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/NotRegisteredActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import androidx.appcompat.app.AppCompatActivity;
20 | import android.os.Bundle;
21 | import com.drakeet.floo.sample.R;
22 |
23 | public class NotRegisteredActivity extends AppCompatActivity {
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_not_registered);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/URLs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | /**
22 | * @author drakeet
23 | */
24 | public class URLs {
25 |
26 | private static final String MAIN_SCHEME = "floo";
27 |
28 | public static final String WEB = "https://m.drakeet.me/web";
29 | public static final String NOT_REGISTERED = "floo://m.drakeet.me/not_registered";
30 |
31 | @NonNull
32 | public static String scheme() {
33 | return MAIN_SCHEME;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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: 'com.android.library'
18 | apply from: 'gradle-mvn-push.gradle'
19 |
20 | android {
21 | compileSdkVersion 28
22 |
23 | defaultConfig {
24 | minSdkVersion 14
25 | targetSdkVersion 28
26 | versionCode 12
27 | versionName "1.2.0"
28 | }
29 |
30 | buildTypes {
31 | release {
32 | minifyEnabled false
33 | consumerProguardFile 'proguard-rules.pro'
34 | }
35 | }
36 | }
37 |
38 | dependencies {
39 | testImplementation 'junit:junit:4.12'
40 | implementation 'androidx.annotation:annotation:1.0.2'
41 | }
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_not_registered.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
26 |
27 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/StackStates.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import androidx.annotation.CheckResult;
20 | import androidx.annotation.IntRange;
21 | import androidx.annotation.NonNull;
22 |
23 | /**
24 | * @author drakeet
25 | */
26 | public interface StackStates {
27 |
28 | interface Target {
29 | @NonNull @CheckResult Flow popCount(@IntRange(from = 1) int count);
30 | @NonNull @CheckResult Flow target(@NonNull String indexKey);
31 | }
32 |
33 | interface Flow {
34 | @NonNull @CheckResult End result(@NonNull Object result);
35 | void start();
36 | }
37 |
38 | interface End {
39 | void start();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/extensions/LogInterceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.extensions;
18 |
19 | import androidx.annotation.NonNull;
20 | import android.util.Log;
21 | import me.drakeet.floo.Chain;
22 | import me.drakeet.floo.Interceptor;
23 |
24 | /**
25 | * @author drakeet
26 | */
27 | public class LogInterceptor implements Interceptor {
28 |
29 | private @NonNull final String tag;
30 |
31 | public LogInterceptor(@NonNull String tag) {
32 | this.tag = tag;
33 | }
34 |
35 | @NonNull @Override
36 | public Chain intercept(@NonNull Chain chain) {
37 | Log.d("Floo", "LogInterceptor: " + tag + ": " + chain.request());
38 | return chain;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/TargetMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 | import java.util.Map;
22 |
23 | /**
24 | * url - Target
25 | *
26 | * @author drakeet
27 | */
28 | final class TargetMap {
29 |
30 | private @NonNull Map map;
31 |
32 | TargetMap(@NonNull Map map) {
33 | this.map = map;
34 | }
35 |
36 | void set(@NonNull Map map) {
37 | this.map = map;
38 | }
39 |
40 | @NonNull
41 | Map get() {
42 | return map;
43 | }
44 |
45 | @Nullable
46 | Target getTarget(@NonNull String url) {
47 | // TODO: 2017/8/23 case?
48 | return map.get(url);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2017 drakeet. https://github.com/drakeet
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 | # Project-wide Gradle settings.
17 | # IDE (e.g. Android Studio) users:
18 | # Gradle settings configured through the IDE *will override*
19 | # any settings specified in this file.
20 | # For more details on how to configure your build environment visit
21 | # http://www.gradle.org/docs/current/userguide/build_environment.html
22 | # Specifies the JVM arguments used for the daemon process.
23 | # The setting is particularly useful for tweaking memory settings.
24 | android.enableJetifier=true
25 | android.useAndroidX=true
26 | org.gradle.jvmargs=-Xmx1536m
27 | # When configured, Gradle will run in incubating parallel mode.
28 | # This option should only be used with decoupled projects. More details, visit
29 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
30 | # org.gradle.parallel=true
31 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/TargetNotFoundToaster.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import android.content.Context;
20 | import android.net.Uri;
21 | import android.os.Bundle;
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 | import android.widget.Toast;
25 | import me.drakeet.floo.TargetNotFoundHandler;
26 |
27 | /**
28 | * @author drakeet
29 | */
30 | public class TargetNotFoundToaster implements TargetNotFoundHandler {
31 |
32 | @Override
33 | public boolean onTargetNotFound(
34 | @NonNull Context context,
35 | @NonNull Uri sourceUri,
36 | @NonNull Bundle extras,
37 | @Nullable Integer intentFlags) {
38 |
39 | Toast.makeText(context, "ERROR: " + sourceUri.toString(), Toast.LENGTH_SHORT).show();
40 | return true;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_target.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
33 |
34 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_web.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
32 |
33 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Target.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.net.Uri;
20 | import androidx.annotation.NonNull;
21 |
22 | /**
23 | * @author drakeet
24 | */
25 | public class Target {
26 |
27 | private @NonNull final String url;
28 |
29 | public Target(@NonNull String url) {
30 | this.url = url;
31 | }
32 |
33 | @NonNull
34 | public String toTargetUrl() {
35 | return Uri.parse(url).buildUpon().build().toString();
36 | }
37 |
38 | @NonNull
39 | public String getUrl() {
40 | return url;
41 | }
42 |
43 | @Override
44 | public boolean equals(Object o) {
45 | if (this == o) return true;
46 | if (o == null || getClass() != o.getClass()) return false;
47 |
48 | Target target = (Target) o;
49 | return url.equals(target.url);
50 | }
51 |
52 | @Override
53 | public int hashCode() {
54 | return url.hashCode();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Urls.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.net.Uri;
20 | import androidx.annotation.NonNull;
21 |
22 | /**
23 | * @author drakeet
24 | */
25 | public class Urls {
26 |
27 | // TODO: 2017/9/11 Match Case
28 |
29 | @NonNull
30 | public static String indexUrl(@NonNull final String uriString) {
31 | return indexUrl(Uri.parse(uriString));
32 | }
33 |
34 | @NonNull
35 | public static String indexUrl(@NonNull final Uri uri) {
36 | return uri.getScheme() != null && uri.getAuthority() != null ?
37 | uri.getAuthority() + uri.getPath() :
38 | uri.getPath();
39 | }
40 |
41 | public static boolean isWebScheme(@NonNull Uri sourceUri) {
42 | return sourceUri.getScheme() != null &&
43 | (sourceUri.getScheme().toLowerCase().equals("http") ||
44 | sourceUri.getScheme().toLowerCase().equals("https"));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Chain.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.net.Uri;
20 | import androidx.annotation.NonNull;
21 |
22 | /**
23 | * @author drakeet
24 | */
25 | public class Chain {
26 |
27 | private @NonNull final Uri requestUri;
28 | private boolean proceed = true;
29 |
30 | public Chain(@NonNull Uri requestUri) {
31 | this.requestUri = requestUri;
32 | }
33 |
34 | private Chain(@NonNull Uri requestUri, boolean proceed) {
35 | this.requestUri = requestUri;
36 | this.proceed = proceed;
37 | }
38 |
39 | @NonNull
40 | public Uri request() {
41 | return requestUri;
42 | }
43 |
44 | @NonNull
45 | public Chain proceed(@NonNull final Uri requestUri) {
46 | return new Chain(requestUri, true);
47 | }
48 |
49 | @NonNull
50 | public Chain abort() {
51 | return new Chain(requestUri, false);
52 | }
53 |
54 | public boolean isProceed() {
55 | return proceed;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/WebHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import android.content.Context;
20 | import android.content.Intent;
21 | import android.net.Uri;
22 | import android.os.Bundle;
23 | import androidx.annotation.NonNull;
24 | import androidx.annotation.Nullable;
25 | import me.drakeet.floo.TargetNotFoundHandler;
26 | import me.drakeet.floo.Urls;
27 |
28 | /**
29 | * @author drakeet
30 | */
31 | public class WebHandler implements TargetNotFoundHandler {
32 |
33 | @Override
34 | public boolean onTargetNotFound(
35 | @NonNull Context context,
36 | @NonNull Uri sourceUri,
37 | @NonNull Bundle extras,
38 | @Nullable Integer intentFlags) {
39 |
40 | if (Urls.isWebScheme(sourceUri)) {
41 | Intent intent = new Intent(context, WebActivity.class);
42 | intent.putExtra("url", sourceUri.toString());
43 | if (intentFlags != null) {
44 | intent.setFlags(intentFlags);
45 | }
46 | context.startActivity(intent);
47 | return true;
48 | }
49 | return false;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_container.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
25 |
26 |
32 |
33 |
36 |
37 |
42 |
43 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/TargetNotFoundHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.content.Context;
20 | import android.net.Uri;
21 | import android.os.Bundle;
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 |
25 | /**
26 | * Interface definition for a handler to be invoked when a target is not found.
27 | * The handler will be invoked one by one following the registered order.
28 | *
29 | * @author drakeet
30 | */
31 | public interface TargetNotFoundHandler {
32 |
33 | /**
34 | * Called when a target not found event occurred. This allows handlers to
35 | * get a chance to respond before error.
36 | *
37 | * @param context The context.
38 | * @param sourceUri The source URI.
39 | * @param extras The bundle extras.
40 | * @param intentFlags The desired flags.
41 | * @return True if the handler has consumed the event, false otherwise.
42 | */
43 | boolean onTargetNotFound(
44 | @NonNull Context context,
45 | @NonNull Uri sourceUri,
46 | @NonNull Bundle extras,
47 | @Nullable Integer intentFlags
48 | );
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/ActivityOnResumeCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.app.Activity;
20 | import android.app.Application;
21 | import android.os.Build;
22 | import android.os.Bundle;
23 | import androidx.annotation.RequiresApi;
24 |
25 | /**
26 | * @author drakeet
27 | */
28 | @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
29 | public abstract class ActivityOnResumeCallback implements Application.ActivityLifecycleCallbacks {
30 |
31 | @Override
32 | public abstract void onActivityResumed(Activity activity);
33 |
34 | @Override
35 | public final void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
36 |
37 | @Override
38 | public final void onActivityStarted(Activity activity) {}
39 |
40 | @Override
41 | public final void onActivityPaused(Activity activity) {}
42 |
43 | @Override
44 | public final void onActivityStopped(Activity activity) {}
45 |
46 | @Override
47 | public final void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
48 |
49 | @Override
50 | public final void onActivityDestroyed(Activity activity) {}
51 | }
52 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/extensions/OpenDirectlyHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.extensions;
18 |
19 | import android.content.ActivityNotFoundException;
20 | import android.content.Context;
21 | import android.content.Intent;
22 | import android.net.Uri;
23 | import android.os.Bundle;
24 | import androidx.annotation.NonNull;
25 | import androidx.annotation.Nullable;
26 | import me.drakeet.floo.TargetNotFoundHandler;
27 |
28 | /**
29 | * @author drakeet
30 | */
31 | public class OpenDirectlyHandler implements TargetNotFoundHandler {
32 |
33 | @Override
34 | public boolean onTargetNotFound(
35 | @NonNull Context context,
36 | @NonNull Uri uri,
37 | @NonNull Bundle bundle,
38 | @Nullable Integer intentFlags) {
39 |
40 | Intent intent = new Intent(Intent.ACTION_VIEW, uri);
41 | intent.putExtras(bundle);
42 | if (intentFlags != null) {
43 | intent.setFlags(intentFlags);
44 | }
45 | try {
46 | context.startActivity(intent);
47 | } catch (ActivityNotFoundException exception) {
48 | exception.printStackTrace();
49 | return false;
50 | }
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
26 |
27 |
34 |
35 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/entity/Mail.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample.entity;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 |
22 | /**
23 | * @author drakeet
24 | */
25 | public class Mail implements Parcelable {
26 |
27 | public String content;
28 | public String from;
29 | public String to;
30 |
31 | public Mail() {}
32 |
33 | private Mail(Parcel in) {
34 | this.content = in.readString();
35 | this.from = in.readString();
36 | this.to = in.readString();
37 | }
38 |
39 | @Override
40 | public void writeToParcel(Parcel dest, int flags) {
41 | dest.writeString(this.content);
42 | dest.writeString(this.from);
43 | dest.writeString(this.to);
44 | }
45 |
46 | @Override
47 | public int describeContents() { return 0; }
48 |
49 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
50 | @Override
51 | public Mail createFromParcel(Parcel source) {
52 | return new Mail(source);
53 | }
54 |
55 | @Override
56 | public Mail[] newArray(int size) {
57 | return new Mail[size];
58 | }
59 | };
60 |
61 | @Override
62 | public String toString() {
63 | return "Mail { " +
64 | "name='" + content + '\'' +
65 | ", from='" + from + '\'' +
66 | ", to='" + to + '\'' +
67 | " }";
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Stack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.app.Activity;
20 | import androidx.annotation.CheckResult;
21 | import androidx.annotation.IntRange;
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 |
25 | /**
26 | * @author drakeet
27 | */
28 | public class Stack implements StackStates.Target, StackStates.Flow, StackStates.End {
29 |
30 | private @NonNull final Activity activity;
31 |
32 | private @Nullable Object result;
33 | private @Nullable String indexKey;
34 |
35 | private int count = 1;
36 |
37 | public Stack(@NonNull Activity activity) { this.activity = activity; }
38 |
39 | @NonNull @CheckResult
40 | public StackStates.Flow popCount(@IntRange(from = 1) int count) {
41 | this.count = count;
42 | return this;
43 | }
44 |
45 | @NonNull @CheckResult
46 | public StackStates.Flow target(@NonNull String indexKey) {
47 | this.indexKey = indexKey;
48 | return this;
49 | }
50 |
51 | @NonNull @CheckResult
52 | public StackStates.End result(@NonNull Object result) {
53 | this.result = result;
54 | return this;
55 | }
56 |
57 | public void start() {
58 | if (indexKey != null) {
59 | StackManager.post(result, indexKey);
60 | } else {
61 | StackManager.postCount(result, count);
62 | }
63 | StackManager.start(activity);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/TargetActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import android.content.Intent;
20 | import android.net.Uri;
21 | import android.os.Bundle;
22 | import androidx.appcompat.app.AppCompatActivity;
23 | import android.view.View;
24 | import android.widget.TextView;
25 | import com.drakeet.floo.sample.R;
26 |
27 | public class TargetActivity extends AppCompatActivity {
28 |
29 | public static final String KEY_MAIL = "key_mail";
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_target);
35 | Intent intent = getIntent();
36 |
37 | TextView text = (TextView) findViewById(R.id.text);
38 | text.append("\n\n\nExtras: \n\n");
39 |
40 | Bundle bundle = intent.getExtras();
41 | assert bundle != null;
42 | for (String key : bundle.keySet()) {
43 | text.append(key + "\n" + bundle.get(key) + "\n\n");
44 | }
45 |
46 | String sourceUrl = intent.getStringExtra("__source__");
47 | if (sourceUrl != null) {
48 | setTitle(Uri.parse(sourceUrl).getPath());
49 | }
50 |
51 | // noinspection ConstantConditions
52 | String subUrl = intent.getData().getQueryParameter("url");
53 | if (subUrl != null) {
54 | text.append("\n\nSUB-URL: ");
55 | text.append(subUrl);
56 | }
57 | }
58 |
59 | public void onBack(View view) {
60 | onBackPressed();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2017 drakeet. https://github.com/drakeet
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 | # Project-wide Gradle settings.
17 | # IDE (e.g. Android Studio) users:
18 | # Settings specified in this file will override any Gradle settings
19 | # configured through the IDE.
20 | # For more details on how to configure your build environment visit
21 | # http://www.gradle.org/docs/current/userguide/build_environment.html
22 | # Specifies the JVM arguments used for the daemon process.
23 | # The setting is particularly useful for tweaking memory settings.
24 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
25 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
26 | # When configured, Gradle will run in incubating parallel mode.
27 | # This option should only be used with decoupled projects. More details, visit
28 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
29 | # org.gradle.parallel=true
30 | # https://github.com/drakeet
31 | POM_NAME=floo
32 | POM_ARTIFACT_ID=floo
33 | POM_PACKAGING=aar
34 | VERSION_NAME=1.2.0
35 | VERSION_CODE=12
36 | GROUP=me.drakeet.floo
37 | POM_DESCRIPTION=A router supporting AOP, stack control, cross-page message, and dynamic routing.
38 | POM_URL=http://github.com/drakeet/Floo
39 | POM_SCM_URL=http://github.com/drakeet/Floo
40 | POM_SCM_CONNECTION=scm:git@github.com:drakeet/Floo.git
41 | POM_SCM_DEV_CONNECTION=scm:git@github.com:drakeet/Floo.git
42 | POM_LICENCE_NAME=Apache License 2.0
43 | POM_LICENCE_URL=Apache License 2.0
44 | POM_LICENCE_DIST=repo
45 | POM_DEVELOPER_ID=drakeet
46 | POM_DEVELOPER_NAME=drakeet
47 | POM_DEVELOPER_URL=https://drakeet.com
48 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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: 'com.android.application'
18 |
19 | def releaseKey = file('release.jks')
20 | def debugKey = file('debug.jks')
21 |
22 | android {
23 | compileSdkVersion 28
24 |
25 | defaultConfig {
26 | applicationId "me.drakeet.floo.sample"
27 | minSdkVersion 14
28 | targetSdkVersion 28
29 | versionCode 12
30 | versionName "1.2.0"
31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32 | }
33 |
34 | signingConfigs {
35 | debug {
36 | storeFile debugKey
37 | storePassword '123456'
38 | keyAlias 'debug'
39 | keyPassword '123456'
40 | }
41 | release {
42 | storeFile releaseKey
43 | storePassword project.hasProperty('FLOO_STOREPASS') ? FLOO_STOREPASS : ''
44 | keyAlias project.hasProperty('FLOO_KEYALIAS') ? FLOO_KEYALIAS : ''
45 | keyPassword project.hasProperty('FLOO_KEYPASS') ? FLOO_KEYPASS : ''
46 | }
47 | }
48 |
49 | buildTypes {
50 | debug {
51 | versionNameSuffix " debug"
52 | applicationIdSuffix ".debug"
53 | resValue "string", "scheme", "floo-debug"
54 | }
55 | release {
56 | resValue "string", "scheme", "floo"
57 | minifyEnabled false
58 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
59 | }
60 | }
61 | }
62 |
63 | dependencies {
64 | implementation project(':library')
65 |
66 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
67 | exclude group: 'com.android.support', module: 'support-annotations'
68 | })
69 | androidTestImplementation('androidx.test.espresso:espresso-intents:3.1.0', {
70 | exclude group: 'com.android.support', module: 'support-annotations'
71 | })
72 |
73 | implementation 'androidx.appcompat:appcompat:1.0.2'
74 | testImplementation 'junit:junit:4.12'
75 | }
76 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Navigation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 | import android.os.Parcelable;
22 | import androidx.annotation.CheckResult;
23 | import androidx.annotation.NonNull;
24 | import androidx.annotation.Nullable;
25 | import java.io.Serializable;
26 | import java.util.ArrayList;
27 |
28 | /**
29 | * @author drakeet
30 | */
31 | public interface Navigation {
32 |
33 | @NonNull @CheckResult Navigation setFlags(int intentFlags);
34 | @NonNull @CheckResult Navigation appendQueryParameter(@NonNull String key, @NonNull String value);
35 |
36 | @NonNull @CheckResult Navigation putExtras(@NonNull Bundle bundle);
37 | @NonNull @CheckResult Navigation putExtras(@NonNull Intent intent);
38 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, int value);
39 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, long value);
40 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, float value);
41 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, double value);
42 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, boolean value);
43 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, byte value);
44 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, short value);
45 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable String value);
46 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable CharSequence value);
47 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable Parcelable value);
48 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable Serializable value);
49 | @NonNull @CheckResult Navigation putIntegerArrayListExtra(@NonNull String name, @NonNull ArrayList value);
50 | @NonNull @CheckResult Navigation putStringArrayListExtra(@NonNull String name, @NonNull ArrayList value);
51 | @NonNull @CheckResult Navigation putCharSequenceArrayListExtra(@NonNull String name, @NonNull ArrayList value);
52 | @NonNull @CheckResult Navigation putParcelableArrayListExtra(@NonNull String name, @NonNull ArrayList extends Parcelable> value);
53 |
54 | @Nullable @CheckResult Intent getIntent();
55 |
56 | boolean hasTarget();
57 | void ifIntentNonNullSendTo(@NonNull IntentReceiver receiver);
58 | void start();
59 | }
60 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/App.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import android.app.Application;
20 | import androidx.annotation.NonNull;
21 | import com.drakeet.floo.sample.R;
22 | import java.util.HashMap;
23 | import java.util.Map;
24 | import me.drakeet.floo.Chain;
25 | import me.drakeet.floo.Floo;
26 | import me.drakeet.floo.Interceptor;
27 | import me.drakeet.floo.Target;
28 | import me.drakeet.floo.extensions.LogInterceptor;
29 | import me.drakeet.floo.extensions.OpenDirectlyHandler;
30 |
31 | /**
32 | * @author drakeet
33 | */
34 | public class App extends Application {
35 |
36 | @Override
37 | public void onCreate() {
38 | super.onCreate();
39 |
40 | Map mappings = new HashMap<>();
41 | mappings.put("m.drakeet.me/home", new Target("floo://drakeet.sdk/target"));
42 | mappings.put("m.drakeet.me/link", new Target("floo://drakeet.sdk/target"));
43 | mappings.put("m.drakeet.me/web", new Target("floo://drakeet.sdk/web"));
44 | mappings.put("m.drakeet.me/container", new Target("floo://m.drakeet.me/container"));
45 | mappings.put("mosaic.chunchun.io:8080", new Target("https://play.google.com/store/apps/details?id=me.drakeet.puremosaic"));
46 | mappings.put("PureWriter", new Target("https://play.google.com/store/apps/details?id=com.drakeet.purewriter"));
47 |
48 | Floo.configuration()
49 | .setDebugEnabled(true)
50 | .addRequestInterceptor(new PureSchemeInterceptor(getString(R.string.scheme)))
51 | .addRequestInterceptor(new LogInterceptor("Request"))
52 | .addTargetInterceptor(new PureSchemeInterceptor(getString(R.string.scheme)))
53 | .addTargetInterceptor(new LogInterceptor("Target"))
54 | .addTargetNotFoundHandler(new WebHandler())
55 | .addTargetNotFoundHandler(new OpenDirectlyHandler())
56 | .addTargetNotFoundHandler(new TargetNotFoundToaster());
57 |
58 | Floo.apply(mappings);
59 | }
60 |
61 | private static class PureSchemeInterceptor implements Interceptor {
62 |
63 | private @NonNull final String scheme;
64 |
65 | private PureSchemeInterceptor(@NonNull String scheme) {
66 | this.scheme = scheme;
67 | }
68 |
69 | @NonNull
70 | @Override
71 | public Chain intercept(@NonNull Chain chain) {
72 | if (BuildConfig.DEBUG && URLs.scheme().equals(chain.request().getScheme())) {
73 | chain = new Chain(chain.request().buildUpon().scheme(scheme).build());
74 | }
75 | return chain;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/WebActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import android.annotation.SuppressLint;
20 | import android.os.Bundle;
21 | import androidx.appcompat.app.AppCompatActivity;
22 | import android.view.View;
23 | import android.view.animation.AlphaAnimation;
24 | import android.view.animation.Animation;
25 | import android.view.animation.ScaleAnimation;
26 | import android.webkit.WebView;
27 | import android.webkit.WebViewClient;
28 | import android.widget.TextView;
29 | import com.drakeet.floo.sample.R;
30 |
31 | public class WebActivity extends AppCompatActivity {
32 |
33 | private static final String URL = "url";
34 | private TextView loading;
35 |
36 | @Override
37 | @SuppressLint("SetJavaScriptEnabled")
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_web);
41 | WebView webView = (WebView) findViewById(R.id.web_view);
42 | String url = getIntent().getStringExtra(URL);
43 | if (url == null && getIntent().getData() != null) {
44 | url = getIntent().getData().getQueryParameter(URL);
45 | }
46 | if (url == null) {
47 | finish();
48 | }
49 | webView.setWebViewClient(new InnerWebViewClient());
50 | webView.getSettings().setJavaScriptEnabled(true);
51 | webView.loadUrl(url);
52 |
53 | loading = (TextView) findViewById(R.id.loading);
54 | Animation animation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f,
55 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
56 | animation.setRepeatMode(Animation.REVERSE);
57 | animation.setRepeatCount(Animation.INFINITE);
58 | animation.setDuration(500);
59 | loading.startAnimation(animation);
60 | setTitle(url);
61 | }
62 |
63 | public class InnerWebViewClient extends WebViewClient {
64 |
65 | @Override @SuppressWarnings("deprecation")
66 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
67 | view.loadUrl(url);
68 | return true;
69 | }
70 |
71 | @Override
72 | public void onPageCommitVisible(WebView view, String url) {
73 | super.onPageCommitVisible(view, url);
74 | loading.clearAnimation();
75 | loading.setVisibility(View.GONE);
76 | view.setVisibility(View.VISIBLE);
77 | Animation animation = new AlphaAnimation(0.1f, 1.0f);
78 | animation.setDuration(800);
79 | view.setAnimation(animation);
80 | setTitle(view.getTitle());
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
26 |
27 |
28 |
29 |
36 |
37 |
41 |
42 |
46 |
47 |
51 |
52 |
56 |
57 |
61 |
62 |
66 |
67 |
71 |
72 |
76 |
77 |
81 |
82 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/TargetMapParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 | import java.util.HashMap;
22 | import java.util.Iterator;
23 | import java.util.Map;
24 | import org.json.JSONException;
25 | import org.json.JSONObject;
26 |
27 | /**
28 | * @author drakeet
29 | */
30 | public class TargetMapParser {
31 |
32 | private static final String TARGET_URL = "url";
33 |
34 | @NonNull
35 | public Map fromJson(@Nullable String json) throws JSONException {
36 | return toTargetMap(toJsonObject(json));
37 | }
38 |
39 | /**
40 | * Convert a target map to JSON string.
41 | *
42 | * @param targetMap The target map.
43 | * @return A JSON string of the map.
44 | */
45 | @NonNull
46 | public String toJson(@NonNull Map targetMap) {
47 | final Map flatMap = new HashMap<>();
48 | for (Map.Entry entry : targetMap.entrySet()) {
49 | try {
50 | flatMap.put(entry.getKey(), toJsonObject(entry.getValue()));
51 | } catch (JSONException e) {
52 | e.printStackTrace();
53 | }
54 | }
55 | try {
56 | // 2 indent spaces for pretty printing
57 | return new JSONObject(flatMap).toString(2);
58 | } catch (JSONException e) {
59 | e.printStackTrace();
60 | return "{}";
61 | }
62 | }
63 |
64 | @NonNull
65 | private JSONObject toJsonObject(@NonNull Target target) throws JSONException {
66 | final JSONObject jsonObject = new JSONObject();
67 | jsonObject.putOpt(TARGET_URL, target.getUrl());
68 | return jsonObject;
69 | }
70 |
71 | @NonNull
72 | private Map toTargetMap(@NonNull final JSONObject json) throws JSONException {
73 | final Map result = new HashMap<>();
74 |
75 | final Iterator keys = json.keys();
76 | while (keys.hasNext()) {
77 | String key = keys.next();
78 | Target target = getTarget(json.getJSONObject(key));
79 | result.put(key, target);
80 | }
81 | return result;
82 | }
83 |
84 | @NonNull
85 | private Target getTarget(@NonNull JSONObject targetJson) {
86 | String targetUrl = targetJson.optString(TARGET_URL, null);
87 | if (targetUrl == null) {
88 | throw new InvalidJsonException(targetJson.toString(),
89 | new NullPointerException(TARGET_URL + " == null"));
90 | }
91 | return new Target(targetUrl);
92 | }
93 |
94 | @NonNull
95 | private JSONObject toJsonObject(@Nullable String json) throws InvalidJsonException {
96 | if (json == null) {
97 | return new JSONObject();
98 | }
99 | try {
100 | return new JSONObject(json);
101 | } catch (JSONException e) {
102 | throw new InvalidJsonException(json, e);
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/ContainerActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import android.net.Uri;
20 | import android.os.Build;
21 | import android.os.Bundle;
22 | import androidx.annotation.Nullable;
23 | import androidx.annotation.RequiresApi;
24 | import androidx.appcompat.app.AppCompatActivity;
25 | import android.view.View;
26 | import android.widget.Button;
27 | import android.widget.TextView;
28 | import me.drakeet.floo.Floo;
29 | import me.drakeet.floo.StackCallback;
30 | import me.drakeet.floo.Urls;
31 | import com.drakeet.floo.sample.R;
32 |
33 | /**
34 | * @author drakeet
35 | */
36 | public class ContainerActivity extends AppCompatActivity implements StackCallback {
37 |
38 | private TextView textView;
39 |
40 | @Nullable @Override
41 | public String indexKeyForStackTarget() {
42 | if (getIntent().getData() == null) {
43 | return null;
44 | }
45 | String pageURLOfThis = getIntent().getData().getQueryParameter("url");
46 | Uri pageUri = Uri.parse(pageURLOfThis);
47 |
48 | return Urls.indexUrl(pageUri);
49 | }
50 |
51 | @Override
52 | public void onReceivedResult(@Nullable Object result) {
53 | textView.append("\n\nReceived data: " + result);
54 | textView.append("\n(You have passed a data from a page to current page successfully)");
55 | }
56 |
57 | @Override
58 | protected void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 | setContentView(R.layout.activity_container);
61 | textView = (TextView) findViewById(R.id.url_text);
62 | if (getIntent().getData() != null) {
63 | textView.setText(getIntent().getData().toString());
64 | }
65 | }
66 |
67 | @Override
68 | protected void onStart() {
69 | super.onStart();
70 | if (getIntent().getData() == null) {
71 | return;
72 | }
73 | String subURLOfThis = getIntent().getData().getQueryParameter("url");
74 |
75 | Button setResultButton = (Button) findViewById(R.id.set_result_button);
76 | if (subURLOfThis.contains("page5")) {
77 | setResultButton.setVisibility(View.VISIBLE);
78 | } else {
79 | setResultButton.setVisibility(View.INVISIBLE);
80 | }
81 | }
82 |
83 | @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
84 | public void setResultAndBackToPage2(View view) {
85 | Floo.stack(this)
86 | .target(Urls.indexUrl("https://chunchun.io/page2"))
87 | .result("https://play.google.com/store/apps/details?id=com.drakeet.purewriter")
88 | .start();
89 | }
90 |
91 | @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
92 | private void popCount() {
93 | Floo.stack(this)
94 | .popCount(2)
95 | .result("https://play.google.com/store/apps/details?id=com.drakeet.purewriter")
96 | .start();
97 | }
98 |
99 | public void back(View view) {
100 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
101 | Floo.stack(this).popCount(1).start();
102 | } else {
103 | onBackPressed();
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/library/gradle-mvn-push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | * Copyright 2017 drakeet
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 | apply plugin: 'maven'
19 | apply plugin: 'signing'
20 |
21 | def isReleaseBuild() {
22 | return VERSION_NAME.contains("SNAPSHOT") == false
23 | }
24 |
25 | def getReleaseRepositoryUrl() {
26 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL : "https://oss.sonatype.org/content/repositories/snapshots/"
31 | }
32 |
33 | def getRepositoryUsername() {
34 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
35 | }
36 |
37 | def getRepositoryPassword() {
38 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
39 | }
40 |
41 | afterEvaluate { project ->
42 | uploadArchives {
43 | repositories {
44 | mavenDeployer {
45 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
46 |
47 | pom.groupId = GROUP
48 | pom.artifactId = POM_ARTIFACT_ID
49 | pom.version = VERSION_NAME
50 |
51 | repository(url: getReleaseRepositoryUrl()) {
52 | authentication(userName: getRepositoryUsername(),
53 | password: getRepositoryPassword())
54 | }
55 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
56 | authentication(userName: getRepositoryUsername(),
57 | password: getRepositoryPassword())
58 | }
59 |
60 | pom.project {
61 | name POM_NAME
62 | packaging POM_PACKAGING
63 | description POM_DESCRIPTION
64 | url POM_URL
65 |
66 | scm {
67 | url POM_SCM_URL
68 | connection POM_SCM_CONNECTION
69 | developerConnection POM_SCM_DEV_CONNECTION
70 | }
71 |
72 | licenses {
73 | license {
74 | name POM_LICENCE_NAME
75 | url POM_LICENCE_URL
76 | distribution POM_LICENCE_DIST
77 | }
78 | }
79 |
80 | developers {
81 | developer {
82 | id POM_DEVELOPER_ID
83 | name POM_DEVELOPER_NAME
84 | }
85 | }
86 | }
87 | }
88 | }
89 | }
90 |
91 | signing {
92 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
93 | sign configurations.archives
94 | }
95 |
96 | android.libraryVariants.all { variant ->
97 | task("${variant.name}Javadoc", type: Javadoc) {
98 | description "Generates Javadoc for $variant.name."
99 | source = variant.getJavaCompileProvider().get().source
100 | classpath = files(variant.getJavaCompileProvider().get().classpath.files,
101 | project.android.getBootClasspath())
102 | exclude '**/BuildConfig.java'
103 | exclude '**/R.java'
104 | }
105 | }
106 |
107 | task javadocJar(type: Jar, dependsOn: 'releaseJavadoc') {
108 | classifier = 'javadoc'
109 | from {
110 | releaseJavadoc.destinationDir
111 | }
112 | }
113 |
114 | task androidSourcesJar(type: Jar) {
115 | classifier = 'sources'
116 | from android.sourceSets.main.java.sourceFiles
117 | }
118 |
119 | artifacts {
120 | archives androidSourcesJar
121 | archives javadocJar
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/StackManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.app.Activity;
20 | import androidx.annotation.IntRange;
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 |
24 | /**
25 | * @author drakeet
26 | */
27 | final class StackManager {
28 |
29 | private @Nullable static String targetIndexKey;
30 | private @Nullable static Object result;
31 |
32 | private static boolean hasCount;
33 | private static int currentCount;
34 |
35 | private StackManager() { throw new AssertionError(); }
36 |
37 | static void start(@NonNull Activity activity) {
38 | consumeACount();
39 | activity.finish();
40 | }
41 |
42 | static void onActivityResumed(@NonNull final Activity activity) {
43 | if (hasCount() && currentCount > 0) {
44 | consumeACount();
45 | activity.finish();
46 | } else if (hasCount() && currentCount <= 0) {
47 | consumeHasCount();
48 | if (hasResult()) {
49 | if (activity instanceof StackCallback) {
50 | StackCallback callback = stackCallback(activity);
51 | callback.onReceivedResult(result);
52 | consumeResult();
53 | } else {
54 | consumeResult();
55 | }
56 | }
57 | } else if (hasTarget()) {
58 | if (activity instanceof StackCallback) {
59 | StackCallback callback = stackCallback(activity);
60 |
61 | if (match(callback.indexKeyForStackTarget())) {
62 | consumeTarget();
63 | if (hasResult()) {
64 | callback.onReceivedResult(result);
65 | consumeResult();
66 | }
67 | } else {
68 | activity.finish();
69 | }
70 | } else {
71 | reset();
72 | }
73 | }
74 | }
75 |
76 | private static void consumeHasCount() {
77 | StackManager.hasCount = false;
78 | }
79 |
80 | static void post(@Nullable Object result, @NonNull String toMatcherKey) {
81 | StackManager.result = result;
82 | targetIndexKey = toMatcherKey;
83 | }
84 |
85 | static void postCount(@Nullable Object result, @IntRange(from = 1) int count) {
86 | StackManager.result = result;
87 | StackManager.hasCount = true;
88 | StackManager.currentCount = count;
89 | }
90 |
91 | private static void reset() {
92 | targetIndexKey = null;
93 | result = null;
94 | result = null;
95 | hasCount = false;
96 | currentCount = 0;
97 | }
98 |
99 | private static boolean hasTarget() {
100 | return targetIndexKey != null;
101 | }
102 |
103 | private static boolean match(@Nullable String matcherKey) {
104 | return equals(matcherKey, StackManager.targetIndexKey);
105 | }
106 |
107 | private static void consumeTarget() { targetIndexKey = null; }
108 |
109 | private static boolean hasResult() { return result != null; }
110 |
111 | private static void consumeResult() { result = null; }
112 |
113 | private static boolean hasCount() { return hasCount; }
114 |
115 | private static void consumeACount() { currentCount--; }
116 |
117 | @NonNull
118 | private static StackCallback stackCallback(@NonNull Activity activity) {
119 | return (StackCallback) activity;
120 | }
121 |
122 | private static boolean equals(@Nullable Object a, @Nullable Object b) {
123 | return (a == b) || (a != null && a.equals(b));
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
23 |
24 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
54 |
55 |
56 |
57 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/drakeet/floo/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo.sample;
18 |
19 | import android.content.Intent;
20 | import android.net.Uri;
21 | import android.os.Bundle;
22 | import androidx.appcompat.app.AppCompatActivity;
23 | import android.view.Menu;
24 | import android.view.MenuItem;
25 | import android.view.View;
26 | import android.widget.TextView;
27 | import com.drakeet.floo.sample.R;
28 | import java.net.URLEncoder;
29 | import java.util.Map;
30 | import me.drakeet.floo.Floo;
31 | import me.drakeet.floo.Target;
32 | import me.drakeet.floo.sample.entity.Mail;
33 |
34 | public class MainActivity extends AppCompatActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_main);
40 | TextView text = (TextView) findViewById(R.id.text);
41 | Map targetMap = Floo.getTargetMap();
42 | for (Map.Entry entry : targetMap.entrySet()) {
43 | text.append(entry.getKey());
44 | text.append("\t\t <-> \t\t");
45 | text.append(entry.getValue().toTargetUrl());
46 | text.append("\n");
47 | }
48 | }
49 |
50 | public void onStartHomeWithExtraDataAndParams(View view) {
51 | Mail mail = new Mail();
52 | mail.content = "Hello World";
53 | mail.from = "drakeet";
54 | mail.to = "Xiaoai";
55 | Floo.navigation(this, "sdk://m.drakeet.me/home")
56 | .appendQueryParameter("date", "2017.9.11")
57 | .appendQueryParameter("user_id", "drakeet")
58 | .putExtra(TargetActivity.KEY_MAIL, mail)
59 | .start();
60 | }
61 |
62 | public void onStartHomeWithParams(View view) {
63 | Floo.navigation(this, "sdk://m.drakeet.me/home")
64 | .appendQueryParameter("tag", "just")
65 | .appendQueryParameter("tab", "top")
66 | .appendQueryParameter("user_id", "drakeet")
67 | .start();
68 | }
69 |
70 | public void onStartHomeWithoutScheme(View view) {
71 | Floo.navigation(this, "m.drakeet.me/home").start();
72 | }
73 |
74 | public void onStartWebViewWhenUrlNotFound(View view) {
75 | Floo.navigation(this, "http://drakeet.me").start();
76 | }
77 |
78 | public void onStartH5WithPageURL(View view) {
79 | Floo.navigation(this, URLs.WEB)
80 | .appendQueryParameter("url", "https://github.com/drakeet")
81 | .start();
82 | }
83 |
84 | public void onStartPagesForResult(View view) {
85 | for (int i = 1; i <= 5; i++) {
86 | String pageURL = URLEncoder.encode("https://chunchun.io/page" + i);
87 | Floo.navigation(this, "https://m.drakeet.me/container?url=" + pageURL).start();
88 | }
89 | }
90 |
91 | public void onStartNoRegisteredPage(View view) {
92 | Floo.navigation(this, URLs.NOT_REGISTERED).start();
93 | }
94 |
95 | public void onStartSimpleKey(View view) {
96 | Floo.navigation(this, "PureWriter").start();
97 | }
98 |
99 | public void onStartByHostAndPort(View view) {
100 | Floo.navigation(this, "http://mosaic.chunchun.io:8080").start();
101 | }
102 |
103 | public void onStartError(View view) {
104 | final String invalidUrl = "BS08PTQ9FS85K34E";
105 | Floo.navigation(this, invalidUrl)
106 | .appendQueryParameter("tab", "profile")
107 | .appendQueryParameter("user_id", "drakeet")
108 | .start();
109 | }
110 |
111 | @Override
112 | public boolean onCreateOptionsMenu(Menu menu) {
113 | super.onCreateOptionsMenu(menu);
114 | getMenuInflater().inflate(R.menu.menu_main, menu);
115 | return true;
116 | }
117 |
118 | @Override
119 | public boolean onOptionsItemSelected(MenuItem item) {
120 | if (item.getItemId() == R.id.github) {
121 | // This navigation will be handled by our registered WebHandler
122 | // Floo.navigation(this, "https://github.com/drakeet/Floo").start();
123 | // So we should open it by self:
124 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/drakeet/Floo")));
125 | }
126 | return true;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Configuration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.app.Activity;
20 | import android.os.Build;
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 | import androidx.annotation.RequiresApi;
24 | import java.util.ArrayList;
25 | import java.util.Collections;
26 | import java.util.HashMap;
27 | import java.util.List;
28 | import java.util.Map;
29 |
30 | import static me.drakeet.floo.Preconditions.checkNotNull;
31 |
32 | /**
33 | * A delegate for floo to hold the configuration fields
34 | *
35 | * @author drakeet
36 | */
37 | public class Configuration {
38 |
39 | private @NonNull final TargetMap targetMap;
40 | private @NonNull final List targetNotFoundHandlers;
41 | private @NonNull final List requestInterceptors;
42 | private @NonNull final List targetInterceptors;
43 | private @NonNull IntentHandler intentHandler = new DefaultIntentHandler();
44 | private boolean debug = false;
45 | private boolean stackObserverInitialized = false;
46 |
47 | Configuration() {
48 | targetMap = new TargetMap(Collections.emptyMap());
49 | targetNotFoundHandlers = new ArrayList<>();
50 | requestInterceptors = new ArrayList<>();
51 | targetInterceptors = new ArrayList<>();
52 | }
53 |
54 | void apply(@NonNull final Map map) {
55 | checkNotNull(map);
56 | targetMap.set(new HashMap<>(map));
57 | }
58 |
59 | @NonNull
60 | public Configuration addRequestInterceptor(@NonNull Interceptor requestInterceptor) {
61 | checkNotNull(requestInterceptor);
62 | requestInterceptors.add(requestInterceptor);
63 | return this;
64 | }
65 |
66 | @NonNull
67 | public Configuration addTargetInterceptor(@NonNull Interceptor responseInterceptor) {
68 | checkNotNull(responseInterceptor);
69 | targetInterceptors.add(responseInterceptor);
70 | return this;
71 | }
72 |
73 | @NonNull
74 | public Configuration addTargetNotFoundHandler(@NonNull TargetNotFoundHandler handler) {
75 | checkNotNull(handler);
76 | targetNotFoundHandlers.add(handler);
77 | return this;
78 | }
79 |
80 | /**
81 | * Set debug enabled for logging including interceptors, warnings, and errors.
82 | * By default the debug enabled is false.
83 | *
84 | * @param debug if true {@link Floo} will print some logs if need, otherwise false
85 | * @return {@link Configuration} for more configuring
86 | */
87 | @NonNull
88 | public Configuration setDebugEnabled(boolean debug) {
89 | this.debug = debug;
90 | return this;
91 | }
92 |
93 | public boolean isDebugEnabled() { return debug; }
94 |
95 | public void setIntentHandler(@NonNull IntentHandler intentHandler) {
96 | checkNotNull(intentHandler);
97 | this.intentHandler = intentHandler;
98 | }
99 |
100 | @NonNull
101 | public IntentHandler getIntentHandler() {
102 | return intentHandler;
103 | }
104 |
105 | @NonNull
106 | public List getTargetNotFoundHandlers() {
107 | return targetNotFoundHandlers;
108 | }
109 |
110 | @NonNull
111 | public List getRequestInterceptors() {
112 | return requestInterceptors;
113 | }
114 |
115 | @NonNull
116 | public List getTargetInterceptors() {
117 | return targetInterceptors;
118 | }
119 |
120 | @Nullable
121 | public Target getTarget(@NonNull String url) {
122 | checkNotNull(url);
123 | return targetMap.getTarget(url);
124 | }
125 |
126 | @NonNull
127 | public Map extends String, ? extends Target> getTargetMap() {
128 | return targetMap.get();
129 | }
130 |
131 | @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
132 | void initStackObserverIfNeed(@NonNull Activity activity) {
133 | if (!stackObserverInitialized) {
134 | activity.getApplication().registerActivityLifecycleCallbacks(
135 | new ActivityOnResumeCallback() {
136 |
137 | @Override
138 | public void onActivityResumed(@NonNull Activity activity) {
139 | StackManager.onActivityResumed(activity);
140 | }
141 | });
142 | stackObserverInitialized = true;
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
23 |
24 |
25 |
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 |
83 |
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 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Floo
2 |
3 | [](https://travis-ci.org/drakeet/Floo)
4 | [](https://github.com/drakeet/Floo/blob/master/LICENSE)
5 | 
6 |
7 | An URL router supporting AOP, stack control, cross-page message, and dynamic routing.
8 |
9 |
10 |
11 | ## Getting started
12 |
13 | In your `build.gradle`:
14 |
15 | ```groovy
16 | dependencies {
17 | implementation 'me.drakeet.floo:floo:1.2.0'
18 | }
19 | ```
20 |
21 | Floo has been rebuilt based on AndroidX. If you are still using the android support library, please use:
22 |
23 | ```groovy
24 | dependencies {
25 | implementation 'me.drakeet.floo:floo:1.1.0'
26 | }
27 | ```
28 |
29 | ## Usage & Examples
30 |
31 | ```java
32 | public class App extends Application {
33 |
34 | @Override
35 | public void onCreate() {
36 | super.onCreate();
37 |
38 | Map mappings = new HashMap<>();
39 | mappings.put("m.drakeet.me/home", new Target("floo://drakeet.sdk/target"));
40 | mappings.put("m.drakeet.me/link", new Target("floo://drakeet.sdk/target"));
41 | mappings.put("m.drakeet.me/web", new Target("floo://drakeet.sdk/web"));
42 | mappings.put("m.drakeet.me/container", new Target("floo://m.drakeet.me/container"));
43 |
44 | Floo.configuration()
45 | .setDebugEnabled(BuildConfig.DEBUG)
46 | .setIntentHandler(new FragmentIntentHandler()) // DefaultIntentHandler by default
47 | .addRequestInterceptor(new LogInterceptor("Request"))
48 | .addTargetInterceptor(new LogInterceptor("Target"))
49 | .addTargetNotFoundHandler(new WebHandler())
50 | .addTargetNotFoundHandler(new OpenDirectlyHandler())
51 | .addTargetNotFoundHandler(new TargetNotFoundToaster());
52 |
53 | Floo.apply(mappings);
54 | }
55 | }
56 | ```
57 |
58 | ```java
59 | Floo.navigation(this, "sdk://m.drakeet.me/home")
60 | .appendQueryParameter("date", "2017.9.11")
61 | .appendQueryParameter("user_id", "drakeet")
62 | .putExtra(TargetActivity.KEY_MAIL, mail)
63 | .start();
64 | ```
65 |
66 | ```java
67 | // Allow incomplete URLs
68 | Floo.navigation(this, "PureWriter").start();
69 | ```
70 |
71 | ```java
72 | Floo.stack(this)
73 | .target(Urls.indexUrl("https://chunchun.io/page2"))
74 | .result("abc")
75 | .start();
76 | ```
77 |
78 | ```java
79 | Floo.stack(this)
80 | .popCount(2)
81 | .result(anything)
82 | .start();
83 | ```
84 |
85 | ```java
86 | Floo.stack(this).popCount(3).start();
87 | ```
88 |
89 | ## Principle
90 |
91 | For example, if we call the following code:
92 |
93 | ```java
94 | Floo.navigation(context, "https://play.google.com/store/apps/details")
95 | .appendQueryParameter("id", "com.drakeet.purewriter")
96 | .start();
97 | ```
98 |
99 | At the beginning, Floo will build the URL and parameters to a full URL, like as: [https://play.google.com/store/apps/details?id=com.drakeet.purewriter](https://play.google.com/store/apps/details?id=com.drakeet.purewriter), and ask your registered `RequestInterceptor`s: _"Do you want to intercept and handle the URL?"_
100 |
101 | Every your registered `RequestInterceptor` will receive the full URL one by one. If someone deals with it and returns `true`, the link ends.
102 |
103 | Otherwise, Floo will use the `authority(host:port)` + `path` to get an **index key**. For this example, it is `play.google.com` + `/store/apps/details` -> `play.google.com/store/apps/details`.
104 |
105 | 
106 |
107 | Then, Floo uses the **index key** to find a registered target URL / URI. If Floo finds it, Floo will transfer or merge the parameters of the original URL to the new URL. Otherwise, Floo will create a TargetNotFound event, and dispatch it to all of your registered `TargetNotFoundHandler`s one by one. If someone deals with it and returns `true`, the link ends. If nobody deals with it, the link also ends.
108 |
109 | So what if Floo finds a target and generates a new URL?
110 |
111 | At this point, Floo will send the new URL one by one to your registered `TargetInterceptor`s. If someone deals with it and returns `true`, the link ends.
112 |
113 | Otherwise, Floo comes to the last step, it will use this new URL to create an Intent, and start the Intent. This new URL may be associated with an `Activity`, so the `Activity` will be opened.
114 |
115 |
116 | ## More Interfaces
117 |
118 | ```java
119 | public interface Navigation {
120 |
121 | @NonNull @CheckResult Navigation setFlags(int intentFlags);
122 | @NonNull @CheckResult Navigation appendQueryParameter(@NonNull String key, @NonNull String value);
123 |
124 | @NonNull @CheckResult Navigation putExtras(@NonNull Bundle bundle);
125 | @NonNull @CheckResult Navigation putExtras(@NonNull Intent intent);
126 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, int value);
127 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, long value);
128 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, float value);
129 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, double value);
130 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, boolean value);
131 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, byte value);
132 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, short value);
133 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable String value);
134 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable CharSequence value);
135 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable Parcelable value);
136 | @NonNull @CheckResult Navigation putExtra(@NonNull String key, @Nullable Serializable value);
137 | @NonNull @CheckResult Navigation putIntegerArrayListExtra(@NonNull String name, @NonNull ArrayList value);
138 | @NonNull @CheckResult Navigation putStringArrayListExtra(@NonNull String name, @NonNull ArrayList value);
139 | @NonNull @CheckResult Navigation putCharSequenceArrayListExtra(@NonNull String name, @NonNull ArrayList value);
140 | @NonNull @CheckResult Navigation putParcelableArrayListExtra(@NonNull String name, @NonNull ArrayList extends Parcelable> value);
141 |
142 | @Nullable @CheckResult Intent getIntent();
143 |
144 | boolean hasTarget();
145 | void ifIntentNonNullSendTo(@NonNull IntentReceiver receiver);
146 | void start();
147 | }
148 | ```
149 |
150 | ```java
151 | public interface StackStates {
152 |
153 | interface Target {
154 | @NonNull @CheckResult Flow popCount(@IntRange(from = 1) int count);
155 | @NonNull @CheckResult Flow target(@NonNull String indexKey);
156 | }
157 |
158 |
159 | interface Flow {
160 | @NonNull @CheckResult End result(@NonNull Object result);
161 | void start();
162 | }
163 |
164 |
165 | interface End {
166 | void start();
167 | }
168 | }
169 | ```
170 |
171 | ## Progurad
172 |
173 | ```
174 | -keep class com.drakeet.floo.Target { *; }
175 | ```
176 |
177 | ## Some built-in extensions
178 |
179 | - `LogInterceptor`
180 | - `OpenDirectlyHandler`
181 |
182 |
183 | License
184 | -------
185 |
186 | Copyright 2017 drakeet. https://github.com/drakeet
187 |
188 | Licensed under the Apache License, Version 2.0 (the "License");
189 | you may not use this file except in compliance with the License.
190 | You may obtain a copy of the License at
191 |
192 | http://www.apache.org/licenses/LICENSE-2.0
193 |
194 | Unless required by applicable law or agreed to in writing, software
195 | distributed under the License is distributed on an "AS IS" BASIS,
196 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
197 | See the License for the specific language governing permissions and
198 | limitations under the License.
199 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/library/src/main/java/me/drakeet/floo/Floo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 drakeet. https://github.com/drakeet
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 me.drakeet.floo;
18 |
19 | import android.app.Activity;
20 | import android.content.Context;
21 | import android.content.Intent;
22 | import android.net.Uri;
23 | import android.os.Build;
24 | import android.os.Bundle;
25 | import android.os.Parcelable;
26 | import androidx.annotation.CheckResult;
27 | import androidx.annotation.NonNull;
28 | import androidx.annotation.Nullable;
29 | import androidx.annotation.RequiresApi;
30 | import android.util.Log;
31 | import java.io.Serializable;
32 | import java.util.ArrayList;
33 | import java.util.Collections;
34 | import java.util.HashMap;
35 | import java.util.List;
36 | import java.util.Map;
37 | import org.json.JSONException;
38 |
39 | import static android.util.Log.DEBUG;
40 | import static android.util.Log.ERROR;
41 | import static android.util.Log.INFO;
42 | import static android.util.Log.WARN;
43 | import static java.lang.String.format;
44 |
45 | /**
46 | * @author drakeet
47 | */
48 | public final class Floo implements Navigation {
49 |
50 | private static final String TAG = "Floo";
51 |
52 | private static final Configuration CONFIGURATION = new Configuration();
53 |
54 | private @NonNull final Context context;
55 | private @NonNull final Bundle bundle;
56 | private @NonNull final Map queries;
57 | private @NonNull Uri sourceUri;
58 |
59 | private @Nullable Uri targetUri;
60 | private @Nullable Integer intentFlags;
61 |
62 | private Floo(@NonNull Context context, @NonNull String url) {
63 | this.context = context;
64 | this.bundle = new Bundle();
65 | this.sourceUri = Uri.parse(url);
66 | this.queries = new HashMap<>();
67 | }
68 |
69 | /**
70 | * Create a new {@link Navigation} to open a URL.
71 | *
72 | * @param context The context.
73 | * @param url The source URL.
74 | * @return A reference to the {@link Navigation}.
75 | */
76 | @NonNull @CheckResult
77 | public static Navigation navigation(@NonNull Context context, @NonNull String url) {
78 | return new Floo(context, url.trim());
79 | }
80 |
81 | /**
82 | * Create a new {@link Stack} to back.
83 | *
84 | * @param activity The current activity.
85 | * @return A reference to the {@link Stack}.
86 | */
87 | @NonNull @CheckResult
88 | @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
89 | public static Stack stack(@NonNull Activity activity) {
90 | configuration().initStackObserverIfNeed(activity);
91 | return new Stack(activity);
92 | }
93 |
94 | /**
95 | * Initialize the {@code FlooDelegate}, will load the last rules map.
96 | *
97 | * @return The {@link Configuration}.
98 | */
99 | @NonNull @CheckResult
100 | public static Configuration configuration() {
101 | return CONFIGURATION;
102 | }
103 |
104 | /**
105 | * Apply the rules map. It will replace the original map.
106 | *
107 | * @param map The rules map.
108 | */
109 | public static void apply(@NonNull final Map map) {
110 | configuration().apply(map);
111 | }
112 |
113 | /**
114 | * Apply the rules map from a JSON. It will replace the original map.
115 | *
116 | * @param targetMapJson The target map JSON of your rules.
117 | * @throws JSONException When the JSON's format is error or unexpected.
118 | */
119 | public static void apply(@NonNull final String targetMapJson) throws JSONException {
120 | configuration().apply(new TargetMapParser().fromJson(targetMapJson));
121 | }
122 |
123 | /**
124 | * Set special flags controlling how this intent is handled.
125 | *
126 | * @param intentFlags The desired intent flags.
127 | * @return A reference to the {@link Navigation}.
128 | * @see Intent#setFlags(int)
129 | */
130 | @NonNull @Override @CheckResult
131 | public Navigation setFlags(int intentFlags) {
132 | this.intentFlags = intentFlags;
133 | return this;
134 | }
135 |
136 | /**
137 | * Inserts all mappings from the given Bundle.
138 | *
139 | * @param bundle A Bundle.
140 | * @return A reference to the {@link Navigation}.
141 | * @see Navigation
142 | * @see #putExtra(String, byte)
143 | * @see #putExtra(String, short)
144 | * @see #putExtra(String, int)
145 | * @see #putExtra(String, long)
146 | * @see #putExtra(String, float)
147 | * @see #putExtra(String, double)
148 | * @see #putExtra(String, boolean)
149 | * @see #putExtra(String, String)
150 | * @see #putExtra(String, CharSequence)
151 | * @see #putExtra(String, Parcelable)
152 | * @see #putExtra(String, Serializable)
153 | */
154 | @NonNull @Override @CheckResult
155 | public Navigation putExtras(@NonNull Bundle bundle) {
156 | bundle.putAll(bundle);
157 | return this;
158 | }
159 |
160 | /**
161 | * Append a query parameter.
162 | *
163 | * @return A reference to the {@link Navigation}.
164 | */
165 | @NonNull @Override @CheckResult
166 | public Navigation appendQueryParameter(@NonNull String key, @NonNull String value) {
167 | queries.put(key, value);
168 | return this;
169 | }
170 |
171 | /**
172 | * Build and start the target URL.
173 | *
174 | * @see #getIntent()
175 | */
176 | @Override
177 | public void start() {
178 | final Intent intent = getIntent();
179 | if (intent != null) {
180 | configuration().getIntentHandler().onIntentCreated(context, intent);
181 | } else {
182 | log(WARN, "The target Intent is null, " +
183 | "it may has been intercepted or dispatched to your TargetNotFoundHandlers.");
184 | }
185 | }
186 |
187 | /**
188 | * A convenient method to get the non-null target intent. If the target intent is non-null,
189 | * it will be sent to the {@link IntentReceiver} so that you can do anything without checking
190 | * the intent. Otherwise, nothing happens.
191 | *
192 | * @param receiver The target intent receiver.
193 | */
194 | @Override
195 | public void ifIntentNonNullSendTo(@NonNull IntentReceiver receiver) {
196 | Intent intent = getIntent();
197 | if (intent != null) {
198 | receiver.onReceived(intent);
199 | } else {
200 | log(INFO, "ifIntentNonNullSendTo: intent == null");
201 | }
202 | }
203 |
204 | /**
205 | * Get the result intent. Return null if the intent has been intercepted.
206 | *
207 | * @return The Intent, null if the intent has been intercepted.
208 | * @see #ifIntentNonNullSendTo(IntentReceiver)
209 | */
210 | @Nullable @Override @CheckResult
211 | public Intent getIntent() {
212 | sourceUri = appendSourceUri(sourceUri, queries);
213 | Chain chain = interceptRequest(sourceUri);
214 | sourceUri = chain.request();
215 | if (chain.isProceed()) {
216 | Target target = configuration().getTarget(getIndexUrl());
217 | if (target != null) {
218 | targetUri = createTargetUri(sourceUri, target);
219 | } else {
220 | log(ERROR, getIndexUrl() + " target not found");
221 | onTargetNotFound(sourceUri, bundle);
222 | chain = chain.abort();
223 | }
224 | }
225 | if (chain.isProceed()) {
226 | assert targetUri != null;
227 | chain = interceptTarget(targetUri);
228 | targetUri = chain.request();
229 | if (chain.isProceed()) {
230 | return createIntent();
231 | }
232 | }
233 | return null;
234 | }
235 |
236 | @NonNull
237 | private Intent createIntent() {
238 | final Intent intent = new Intent(Intent.ACTION_VIEW, targetUri);
239 | if (configuration().isDebugEnabled()) {
240 | if (intent.getStringExtra("__source__") == null) {
241 | intent.putExtra("__source__", sourceUri.toString());
242 | }
243 | if (intent.getStringExtra("__target__") == null) {
244 | assert targetUri != null;
245 | intent.putExtra("__target__", targetUri.toString());
246 | }
247 | }
248 | intent.putExtras(bundle);
249 | if (intentFlags != null) {
250 | intent.setFlags(intentFlags);
251 | }
252 | return intent;
253 | }
254 |
255 | /**
256 | * Intercept the request URI and dispatch the {@link Chain} to all of registered {@link Interceptor}s
257 | * one by one.
258 | *
259 | * @param uri The request URI.
260 | * @return The result chain.
261 | * @see Configuration#addRequestInterceptor(Interceptor)
262 | */
263 | @NonNull
264 | private Chain interceptRequest(@NonNull final Uri uri) {
265 | Chain chain = new Chain(uri);
266 | for (Interceptor interceptor : configuration().getRequestInterceptors()) {
267 | chain = interceptor.intercept(chain);
268 | if (!chain.isProceed()) {
269 | log(INFO, "The source URI has been passed to your " +
270 | interceptor.getClass().getName() +
271 | ", and been aborted by the interceptor.");
272 | break;
273 | }
274 | }
275 | return chain;
276 | }
277 |
278 | /**
279 | * Intercept the target URI and dispatch the {@link Chain} to all of registered {@link Interceptor}s
280 | * one by one.
281 | *
282 | * @param target The target URI.
283 | * @return The result chain.
284 | * @see Configuration#addTargetInterceptor(Interceptor)
285 | */
286 | private Chain interceptTarget(@NonNull final Uri target) {
287 | Chain chain = new Chain(target);
288 | for (Interceptor interceptor : configuration().getTargetInterceptors()) {
289 | chain = interceptor.intercept(chain);
290 | if (!chain.isProceed()) {
291 | log(DEBUG, "The target URI has been passed to your " +
292 | interceptor.getClass().getName() +
293 | ", and been aborted by the interceptor.");
294 | break;
295 | }
296 | }
297 | return chain;
298 | }
299 |
300 | private void onTargetNotFound(@NonNull Uri sourceUri, @NonNull Bundle extras) {
301 | log(DEBUG, format("No target URI link to he source URI(%s)", sourceUri));
302 | dispatchTargetNotFoundEvent(sourceUri, extras);
303 | }
304 |
305 | private void dispatchTargetNotFoundEvent(@NonNull Uri sourceUri, @NonNull Bundle extras) {
306 | boolean handled;
307 | for (TargetNotFoundHandler observer : configuration().getTargetNotFoundHandlers()) {
308 | handled = observer.onTargetNotFound(context, sourceUri, extras, intentFlags);
309 | if (handled) {
310 | log(DEBUG, "The TargetNotFoundEvent has been handled by " + observer.getClass().getName());
311 | break;
312 | }
313 | }
314 | }
315 |
316 | @NonNull
317 | private Uri appendSourceUri(@NonNull final Uri base, @NonNull final Map queryParams) {
318 | final Uri.Builder sourceBuilder = base.buildUpon();
319 | for (Map.Entry query : queryParams.entrySet()) {
320 | sourceBuilder.appendQueryParameter(query.getKey(), query.getValue());
321 | }
322 | return sourceBuilder.build();
323 | }
324 |
325 | @NonNull
326 | private Uri createTargetUri(@NonNull final Uri sourceUri, @NonNull final Target target) {
327 | final String targetUrl = target.toTargetUrl();
328 | final Uri sessionUri = Uri.parse(targetUrl);
329 | final String mergedEncodedQuery = mergeEncodedQuery(sourceUri, sessionUri);
330 | return sourceUri.buildUpon()
331 | .scheme(sessionUri.getScheme())
332 | .authority(sessionUri.getAuthority())
333 | .path(sessionUri.getPath())
334 | .encodedQuery(mergedEncodedQuery)
335 | .fragment(sessionUri.getFragment())
336 | .build();
337 | }
338 |
339 | @NonNull
340 | private String mergeEncodedQuery(@NonNull Uri sourceUri, @NonNull Uri sessionUri) {
341 | final Map map = new HashMap<>();
342 | map.putAll(encodedQueryParameters(sourceUri));
343 | map.putAll(encodedQueryParameters(sessionUri));
344 | StringBuilder builder = new StringBuilder();
345 | for (Map.Entry query : map.entrySet()) {
346 | builder.append(query.getKey()).append("=").append(query.getValue()).append("&");
347 | }
348 | String result = builder.toString();
349 | if (result.endsWith("&")) {
350 | result = result.substring(0, result.length() - 1);
351 | }
352 | return result;
353 | }
354 |
355 | @NonNull
356 | public static Map getTargetMap() {
357 | return Collections.unmodifiableMap(configuration().getTargetMap());
358 | }
359 |
360 | /**
361 | * Get the unmodifiable target list.
362 | *
363 | * @return The target list.
364 | */
365 | @NonNull
366 | public static List getTargets() {
367 | return Collections.unmodifiableList(new ArrayList<>(configuration().getTargetMap().values()));
368 | }
369 |
370 | /**
371 | * Check if exist the target for the navigation.
372 | *
373 | * @return If exist, true, otherwise false.
374 | */
375 | @Override
376 | public boolean hasTarget() {
377 | return configuration().getTarget(getIndexUrl()) != null;
378 | }
379 |
380 | /**
381 | * Inserts an int value into the mapping of this Bundle, replacing
382 | * any existing value for the given key.
383 | *
384 | * @param key a String, or null
385 | * @param value an int
386 | */
387 | @NonNull @Override @CheckResult
388 | public Navigation putExtra(@NonNull String key, int value) {
389 | bundle.putInt(key, value);
390 | return this;
391 | }
392 |
393 | @NonNull @Override @CheckResult
394 | public Navigation putExtra(@NonNull String key, long value) {
395 | bundle.putLong(key, value);
396 | return this;
397 | }
398 |
399 | @NonNull @Override @CheckResult
400 | public Navigation putExtra(@NonNull String key, float value) {
401 | bundle.putFloat(key, value);
402 | return this;
403 | }
404 |
405 | @NonNull @Override @CheckResult
406 | public Navigation putExtra(@NonNull String key, double value) {
407 | bundle.putDouble(key, value);
408 | return this;
409 | }
410 |
411 | @NonNull @Override @CheckResult
412 | public Navigation putExtra(@NonNull String key, boolean value) {
413 | bundle.putBoolean(key, value);
414 | return this;
415 | }
416 |
417 | @NonNull @Override @CheckResult
418 | public Navigation putExtra(@NonNull String key, byte value) {
419 | bundle.putByte(key, value);
420 | return this;
421 | }
422 |
423 | @NonNull @Override @CheckResult
424 | public Navigation putExtra(@NonNull String key, short value) {
425 | bundle.putShort(key, value);
426 | return this;
427 | }
428 |
429 | @NonNull @Override @CheckResult
430 | public Navigation putExtra(@NonNull String key, @Nullable String value) {
431 | bundle.putString(key, value);
432 | return this;
433 | }
434 |
435 | @NonNull @Override @CheckResult
436 | public Navigation putExtra(@NonNull String key, @Nullable CharSequence value) {
437 | bundle.putCharSequence(key, value);
438 | return this;
439 | }
440 |
441 | /**
442 | * Put {@link Parcelable} with key and value.
443 | *
444 | * @return A reference to the {@link Navigation}.
445 | * @see #putExtra(String, Serializable)
446 | */
447 | @NonNull @Override @CheckResult
448 | public Navigation putExtra(@NonNull String key, @Nullable Parcelable value) {
449 | bundle.putParcelable(key, value);
450 | return this;
451 | }
452 |
453 | /**
454 | * Put {@link Serializable} with key and value.
455 | *
456 | * @return A reference to the {@link Navigation}.
457 | * @see #putExtra(String, Parcelable)
458 | */
459 | @NonNull @Override @CheckResult
460 | public Navigation putExtra(@NonNull String key, @Nullable Serializable value) {
461 | bundle.putSerializable(key, value);
462 | return this;
463 | }
464 |
465 | @NonNull @Override @CheckResult
466 | public Navigation putExtras(@NonNull Intent intent) {
467 | Bundle extras = intent.getExtras();
468 | if (extras != null) {
469 | return putExtras(extras);
470 | }
471 | return this;
472 | }
473 |
474 | @NonNull @Override @CheckResult
475 | public Navigation putIntegerArrayListExtra(@NonNull String name, @NonNull ArrayList value) {
476 | bundle.putIntegerArrayList(name, value);
477 | return this;
478 | }
479 |
480 | @NonNull @Override @CheckResult
481 | public Navigation putStringArrayListExtra(@NonNull String name, @NonNull ArrayList value) {
482 | bundle.putStringArrayList(name, value);
483 | return this;
484 | }
485 |
486 | @NonNull @Override @CheckResult
487 | public Navigation putCharSequenceArrayListExtra(@NonNull String name, @NonNull ArrayList value) {
488 | bundle.putCharSequenceArrayList(name, value);
489 | return this;
490 | }
491 |
492 | @NonNull @Override @CheckResult
493 | public Navigation putParcelableArrayListExtra(@NonNull String name, @NonNull ArrayList extends Parcelable> value) {
494 | bundle.putParcelableArrayList(name, value);
495 | return this;
496 | }
497 |
498 | private static void log(int priority, String message) {
499 | if (configuration().isDebugEnabled()) {
500 | Log.println(priority, TAG, message);
501 | }
502 | }
503 |
504 | /**
505 | * Returns a map of the unique names of all query parameters. Iterating
506 | * over the set will return the names in order of their first occurrence.
507 | *
508 | * @param uri The URI to transform.
509 | * @return A map of decoded names.
510 | */
511 | @NonNull
512 | private static Map encodedQueryParameters(@NonNull final Uri uri) {
513 | final HashMap map = new HashMap<>();
514 | final String query = uri.getEncodedQuery();
515 | if (query != null) {
516 |
517 | String[] ands = query.split("&");
518 | for (String and : ands) {
519 | int splitIndex = and.indexOf("=");
520 | if (splitIndex != -1) {
521 | map.put(and.substring(0, splitIndex), and.substring(splitIndex + 1));
522 | } else {
523 | Log.w("ParametersParseError", "query: " + query);
524 | }
525 | }
526 | }
527 | return map;
528 | }
529 |
530 | @NonNull
531 | private String getIndexUrl() {
532 | return Urls.indexUrl(sourceUri);
533 | }
534 | }
535 |
--------------------------------------------------------------------------------