Skip to content

Repository files navigation

Floo

Build StatusLicensemaven-central

An URL router supporting AOP, stack control, cross-page message, and dynamic routing.

Get sample on Google Play

Getting started

In your build.gradle:

dependencies {
implementation 'me.drakeet.floo:floo:1.2.0'
}

Floo has been rebuilt based on AndroidX. If you are still using the android support library, please use:

dependencies {
implementation 'me.drakeet.floo:floo:1.1.0'
}

Usage & Examples

publicclassAppextendsApplication {
@OverridepublicvoidonCreate() {
super.onCreate();
Map<String, Target> mappings = newHashMap<>();
mappings.put("m.drakeet.me/home", newTarget("floo://drakeet.sdk/target"));
mappings.put("m.drakeet.me/link", newTarget("floo://drakeet.sdk/target"));
mappings.put("m.drakeet.me/web", newTarget("floo://drakeet.sdk/web"));
mappings.put("m.drakeet.me/container", newTarget("floo://m.drakeet.me/container"));
Floo.configuration()
.setDebugEnabled(BuildConfig.DEBUG)
.setIntentHandler(newFragmentIntentHandler()) // DefaultIntentHandler by default 
.addRequestInterceptor(newLogInterceptor("Request"))
.addTargetInterceptor(newLogInterceptor("Target"))
.addTargetNotFoundHandler(newWebHandler())
.addTargetNotFoundHandler(newOpenDirectlyHandler())
.addTargetNotFoundHandler(newTargetNotFoundToaster());
Floo.apply(mappings);
}
}
Floo.navigation(this, "sdk://m.drakeet.me/home")
.appendQueryParameter("date", "2017.9.11")
.appendQueryParameter("user_id", "drakeet")
.putExtra(TargetActivity.KEY_MAIL, mail)
.start();
// Allow incomplete URLsFloo.navigation(this, "PureWriter").start();
Floo.stack(this)
.target(Urls.indexUrl("https://chunchun.io/page2"))
.result("abc")
.start();
Floo.stack(this)
.popCount(2)
.result(anything)
.start();
Floo.stack(this).popCount(3).start();

Principle

For example, if we call the following code:

Floo.navigation(context, "https://play.google.com/store/apps/details")
.appendQueryParameter("id", "com.drakeet.purewriter")
.start();

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, and ask your registered RequestInterceptors: "Do you want to intercept and handle the URL?"

Every your registered RequestInterceptor will receive the full URL one by one. If someone deals with it and returns true, the link ends.

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.

url-parts.png

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 TargetNotFoundHandlers one by one. If someone deals with it and returns true, the link ends. If nobody deals with it, the link also ends.

So what if Floo finds a target and generates a new URL?

At this point, Floo will send the new URL one by one to your registered TargetInterceptors. If someone deals with it and returns true, the link ends.

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.

More Interfaces

publicinterfaceNavigation {
@NonNull@CheckResultNavigationsetFlags(intintentFlags);
@NonNull@CheckResultNavigationappendQueryParameter(@NonNullStringkey, @NonNullStringvalue);
@NonNull@CheckResultNavigationputExtras(@NonNullBundlebundle);
@NonNull@CheckResultNavigationputExtras(@NonNullIntentintent);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, intvalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, longvalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, floatvalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, doublevalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, booleanvalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, bytevalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, shortvalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, @NullableStringvalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, @NullableCharSequencevalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, @NullableParcelablevalue);
@NonNull@CheckResultNavigationputExtra(@NonNullStringkey, @NullableSerializablevalue);
@NonNull@CheckResultNavigationputIntegerArrayListExtra(@NonNullStringname, @NonNullArrayList<Integer> value);
@NonNull@CheckResultNavigationputStringArrayListExtra(@NonNullStringname, @NonNullArrayList<String> value);
@NonNull@CheckResultNavigationputCharSequenceArrayListExtra(@NonNullStringname, @NonNullArrayList<CharSequence> value);
@NonNull@CheckResultNavigationputParcelableArrayListExtra(@NonNullStringname, @NonNullArrayList<? extendsParcelable> value);
@Nullable@CheckResultIntentgetIntent();
booleanhasTarget();
voidifIntentNonNullSendTo(@NonNullIntentReceiverreceiver);
voidstart();
}
publicinterfaceStackStates {
interfaceTarget {
@NonNull@CheckResultFlowpopCount(@IntRange(from = 1) intcount);
@NonNull@CheckResultFlowtarget(@NonNullStringindexKey);
}
interfaceFlow {
@NonNull@CheckResultEndresult(@NonNullObjectresult);
voidstart();
}
interfaceEnd {
voidstart();
}
}

Progurad

-keep class com.drakeet.floo.Target { *; }

Some built-in extensions

  • LogInterceptor
  • OpenDirectlyHandler

License

Copyright 2017 drakeet. https://github.com/drakeet
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

:octocat: A dynamic URL router for Android

Resources

Stars

550 stars

Watchers

15 watching

Forks

Releases

Packages

Contributors

Languages