Routable, an in-app native URL router, for Android

Overview

Routable

Routable is an in-app native URL router, for Android. Also available for iOS.

Usage

Set up your app's router and URLs:

import com.usepropeller.routable.Router;

public class PropellerApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        
        // Set the global context
        Router.sharedRouter().setContext(getApplicationContext());
        // Symbol-esque params are passed as intent extras to the activities
        Router.sharedRouter().map("users/:id", UserActivity.class);
        Router.sharedRouter().map("users/new/:name/:zip", NewUserActivity.class);
    }
}

In your Activity classes, add support for the URL params:

import com.usepropeller.routable.Router;

public class UserActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle intentExtras = getIntent().getExtras();
        // Note this extra, and how it corresponds to the ":id" above
        String userId = intentExtras.get("id");
    }
}

public class NewUserActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle intentExtras = getIntent().getExtras();
        // Corresponds to the ":name" above
        String name = intentExtras.get("name");
        // Corresponds to the ":zip" above
        String zip = intentExtras.get("zip");
    }
}

Anywhere else in your app, open some URLs:

// starts a new UserActivity
Router.sharedRouter().open("users/16");
// starts a new NewUserActivity
Router.sharedRouter().open("users/new/Clay/94303");

Installation

Routable is currently an Android library project (so no Maven).

If you're in a hurry, you can just copy-paste the Router.java file.

Or if you're being a little more proactive, you should import the Routable project (this entire git repo) into Eclipse and reference it in your own project.

Features

Routable Functions

You can call arbitrary blocks of code with Routable:

Router.sharedRouter().map("logout", new Router.RouterCallback() {
    public void run(Router.RouteContext context) {
        User.logout();
    }
});

// Somewhere else
Router.sharedRouter().open("logout");

Open External URLs

Sometimes you want to open a URL outside of your app, like a YouTube URL or open a web URL in the browser. You can use Routable to do that:

Router.sharedRouter().openExternal("http://www.youtube.com/watch?v=oHg5SJYRHA0")

Multiple Routers

If you need to use multiple routers, simply create new instances of Router:

Router adminRouter = new Router();

Router userRouter = new Router();

Contact

Clay Allsopp (http://clayallsopp.com)

License

Routable for Android is available under the MIT license. See the LICENSE file for more info.

Comments
  • Maven-izing routable-android

    Maven-izing routable-android

    Hi Clay,

    I saw your post on hackernews right as I was preparing to write a library like this myself, so I thought I'd try to help out.

    Turns out the maven-android-plugin guys came up with a good way to package up android libraries, they call it the apklib. Facebook uses it for their android developer SDK, last I checked.

    Maven is pretty cool for android testing too - you can run a maven build that will automatically test against all possible SDK versions / hardware emulations (which, if you want to get widespread adoption of this library, would be a good thing).

    Sorry if the changes look a little jarring - I had to restructure the code into maven-modules format. I use IntelliJ for Java coding, but apparently Eclipse has pretty good integration with maven-android-plugin setups.

    Anyways, I was going to dive in and tackle some routing code, particularly handling fragments/backstack stuff, as one naysayer commented on your hackernews post .. I'd like to see if those obstacles can be surmounted.

    I'm going to try to integrate routable into an open-source hacker news app, since I'm playing around with mobile deep-linking a lot. If you're looking for more contributions, I'd be happy to hack on this on an ongoing basis.

    Thanks!

    • Andrew
    opened by andrewlook 9
  • Consolidated callback arguments into RouteContext

    Consolidated callback arguments into RouteContext

    Refactored callback arguments to a single RouteContext class, which now includes the parameters, the extras, and the Android context. Resolves #9

    I've also refactored open() so that it no longer parses the URL multiple times (once for callbacks, once for the intent). Resolves #12

    opened by richardszalay 5
  • Send extras bundle to RouterCallback

    Send extras bundle to RouterCallback

    Extras aren't currently passed to RouterCallback so they get lost in the process.

    Happy to do a PR for this, but it would break backwards compatibility unless it introduced a RouterExtrasCallback, which smells bad. Thoughts?

    opened by richardszalay 5
  • Add

    Add "query params" support

    Hello, clayallsopp. I just add "query params" support to Router. Url like /users/4?name=router will add a "name" param with value "router" in Intent's extras or callback's params.

    I am realy sorry there is many changes of your code, but I swear to god, I just change some codes between line 364 to line 407, "private RouterParams paramsForUrl(String url)", and add two method Map<String, String> parseQueryParams(String queryPart) and Map<String, String> mergeMaps(Map<String, String> map1, Map<String, String> map2).

    It's because of the IDE "Android Studio", it automatically reformat the code, please be aware.

    opened by frank-fan 2
  • Include querystring parameters in extras

    Include querystring parameters in extras

    It would be nice if querystring parameters were added as additional extras. This would allow additional, optional, parameters to be included.

    Happy to do a PR

    opened by richardszalay 2
  • Error in Router.java (line 374)

    Error in Router.java (line 374)

    (374) error: method cleanUrl in class Router cannot be applied to given types; required: String found: RouterOptions reason: actual argument RouterOptions cannot be converted to String by method invocation conversion

    opened by jgin 1
  • Update committed project settings

    Update committed project settings

    The current committed project settings have a few issues with them:

    • they rely on build tools version 18, which no longer available
    • they rely on gradle 0.6+, which is no longer supported by Android
    • they don't include the Android tests in the gradle project, so they don't run in Android Studio

    I'd recommend:

    • upgrading to gradle 1.2.3
    • updating to either build tools 19.1 (minimum available) or 22 (maximum available)
    • configuring the tests as Android Tests in gradle so they can be run in AS
    opened by richardszalay 0
  • open() parses URLs multiple times

    open() parses URLs multiple times

    Router.open() parses the URL parameters once to check for the callback and then again in intentFor(). This could easily be optimised to make use of the RouterParams (which should probably be renamed MatchedRoute to avoid confusion).

    Granted, it's a small optimisation given that open() is not expected to be called at high frequency. Still, it doesn't look too difficult to fix.

    opened by richardszalay 0
  • URLEncodedUtils and NameValuePair shouldn't be here

    URLEncodedUtils and NameValuePair shouldn't be here

    There are only a few lines of code which use http-client's related APIs: URLEncodedUtils & NameValuePair.

    List<NameValuePair> query = URLEncodedUtils.parse(parsedUri, "utf-8");
    
    for (NameValuePair pair : query) {
        routerParams.openParams.put(pair.getName(), pair.getValue());
    }
    

    They shouldn't be here because:

    • It can be easily replaced
    • MultiDex 65k method count limits: http-client has 7521 methods in total. It doesn't seem to be a problem. But think of the limit is 65535, the cost is too much for a small router component.

    They can be replaced by Uri. It handles urls such as xxx?key1=val+1&key2=val%202 pretty well.

    Uri uri = Uri.parse(url);
    Set<String> queryKeys = uri.getQueryParameterNames();
    for (String key : queryKeys) {
        routerParams.openParams.put(key, uri.getQueryParameter(key));
    }
    

    Sure Uri.getQueryParameterNames() is only available since API 11 and if you want to support API 9, then you can also achive the goal by using Uri.getEncodedQuery(), it's available since API 1. Of course you need to parse the parameters set by your own, but that wouldn't be a problem.

    This project uses http-client's API but there seems no jar file nor gradle dependence declared.

    It's a nice project but I don't think anyone can run the testcases in this project without too much pain. I was going to make a pull request but I found this project doesn't practice gradle very well. I might need to refactor the whole structure if I want to start to work on this project, I guess.

    A nice open source project should be friendly to other programmers, isn't it?

    opened by ryanhoo 1
  • Extend typed parameter in Uri.

    Extend typed parameter in Uri.

    It's a pity that we treat all parameter as String type. So I introduce type into key declaration, such as

    map("users/:defaultIsStringValue/i:intValue/l:longValue/f:floatValue/d:doubleValue/s:stringValue", UserActivity.class)
    

    In this situation, we can get typed parameter from intent. For example, use

    .getExtras().getInt("intValue")
    

    to get an Integer value.

    I keep the full compatibility to your original interface, and pass all original testing cases. Besides, I supply my testing cases to verify the typed parameter, and the mixed typed and none typed parameter.

    opened by walfud 1
Owner
Clay Allsopp
Clay Allsopp
Native solution for common React Native problem of focused views being covered by soft input view.

react-native-avoid-softinput Native solution for common React Native problem of focused views being covered by soft input view. It is solved by listen

Mateusz Mędrek 312 Jan 2, 2023
Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Shahid Iqbal 4 Nov 29, 2022
A robust native library loader for Android.

ReLinker A robust native library loader for Android. More information can be found in our blog post Min SDK: 9 JavaDoc Overview The Android PackageMan

Keepsafe 2.9k Dec 27, 2022
SoLoader is a native code loader for Android.

SoLoader is a native code loader for Android. It takes care of unpacking your native libraries and recursively loads dependencies on platforms that don't support that out of the box.

Meta 1.2k Jan 3, 2023
React Native wrapper to bridge our iOS and Android SDK

React Native wrapper to bridge our iOS and Android SDK

Intercom 94 Jan 1, 2023
Fuzzy string matching for Kotlin (JVM, native, JS, Web Assembly) - port of Fuzzy Wuzzy Python lib

FuzzyWuzzy-Kotlin Fuzzy string matching for Kotlin (JVM, iOS) - fork of the Java fork of of Fuzzy Wuzzy Python lib. For use in on JVM, Android, or Kot

WillowTree, LLC 54 Nov 8, 2022
Multiplaform kotlin library for calculating text differences. Based on java-diff-utils, supports JVM, JS and native targets.

kotlin-multiplatform-diff This is a port of java-diff-utils to kotlin with multiplatform support. All credit for the implementation goes to original a

Peter Trifanov 51 Jan 3, 2023
Gitversion - A native console application to calculate a version based on git commits and tags

GitCommit A native console application to calculate a version based on git commi

Solugo 5 Sep 13, 2022
Native Kotlin library for time-based TOTP and HMAC-based HOTP one-time passwords

A kotlin implementation of HOTP (RFC-4226) and TOTP (RFC-6238). Supports validation and generation of 2-factor authentication codes, recovery codes and randomly secure secrets.

Robin Ohs 6 Dec 19, 2022
A Kotlin native Postgres driver for SqlDelight.

Module postgres-native-sqldelight A native Postgres driver for SqlDelight. Source code Install This package is uploaded to MavenCentral and supports m

Philip Wedemann 19 Dec 30, 2022
POC Simulate Backend Biometric Authentication with AIDL (client app/server app)

poc-simulate-bio-auth-aidl POC Simulate Backend Biometric Authentication with AIDL (client app/server app) #How to use Install server app and run Inst

gundamD 0 Dec 30, 2021
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.

Secure-preferences - Deprecated Please use EncryptedSharedPreferences from androidx.security in preferenced to secure-preference. (There are no active

Scott Alexander-Bown 1.5k Dec 24, 2022
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Rohit Surwase 19 Nov 9, 2021
A util for setting status bar style on Android App.

StatusBarUtil A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4). 中文版点我 Sample Download StatusBarUtil-Demo Chang

Jaeger 8.8k Jan 6, 2023
Android library for viewing, editing and sharing in app databases.

DbInspector DbInspector provides a simple way to view the contents of the in-app database for debugging purposes. There is no need to pull the databas

Infinum 924 Jan 4, 2023
Android Market In-app Billing Library

Update In-app Billing v2 API is deprecated and will be shut down in January 2015. This library was developed for v2 a long time ago. If your app is st

Robot Media 533 Nov 25, 2022
Android app that displays the logcat buffer in a system overlay window

Ghost Log Ghost Log is an Android application that displays the device logcat buffer in a system overlay window. NOTE: Device root (superuser) access

Jeff Gilfelt 378 Nov 15, 2022
Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app

DroidMVP About DroidMVP is a small Android library to help you incorporate the MVP pattern along with Passive View and Presentation Model (yes, those

Andrzej Chmielewski 225 Nov 29, 2022
Utility for detecting and notifying when your Android app goes background / becomes foreground

Foredroid Utility for detecting and notifying when your Android app goes background / becomes foreground. API-level 14+. Usage: Initialise Foreground

Steve Liles 151 Nov 29, 2022