Android Open Source - wizapp Router






From Project

Back to project page wizapp.

License

The source code is released under:

MIT License

If you think the Android project wizapp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wb.wizapp.router;
//  w  w  w. j  a  v a 2  s .  com
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

public class Router {

  private static Router underlying;

  private final Context context;
  private Map<String, RouteeCallback> eventMap;

  private Router(Context context) {
    this.context = context;
    this.eventMap = new HashMap<String, RouteeCallback>();
  }

  public static Router getRouter() {
    if (underlying == null) {
      throw new RuntimeException("router should be used after init");
    }
    return underlying;
  }

  public void map(String uriString) {

    Uri uri = Uri.parse(uriString);
    String scheme = uri.getScheme();

    Routee r = Routee.valueOf(scheme.toUpperCase(Locale.US));
    if (r != null) {
      r.run(context, uri);
    }
  }

  public void registerEvent(String uriString, RouteeCallback callback) {
    Uri uri = Uri.parse(uriString);
    String event = uri.getHost();
    if (!eventMap.containsKey(event)) {
      eventMap.put(event, callback);
    }
  }

  protected void triggerEvent(Uri uri) {
    String event = uri.getHost();
    if (eventMap.containsKey(event)) {
      eventMap.get(event).run(context, uri);
    }
  }

  public static Bundle getBundle(Uri uri) {
    Bundle bundle = new Bundle();
    if (!uri.getQuery().equals("")) {
      for (Iterator<String> it = uri.getQueryParameterNames().iterator(); it.hasNext();) {
        String key = it.next();
        String val = uri.getQueryParameter(key);
        if (val != null) {
          bundle.putString(key, val);
        }
      }
    }
    return bundle;
  }

}




Java Source Code List

com.wb.wizapp.IConstants.java
com.wb.wizapp.concurret.UIAsyncTask.java
com.wb.wizapp.concurret.UISyncTask.java
com.wb.wizapp.ex.WizError.java
com.wb.wizapp.rest.IJsonParsable.java
com.wb.wizapp.rest.IRestAPIServiceBuilder.java
com.wb.wizapp.rest.JsonBean.java
com.wb.wizapp.rest.JsonObject.java
com.wb.wizapp.rest.RestAPIHostFactory.java
com.wb.wizapp.rest.RestAPIHost.java
com.wb.wizapp.rest.RestAPISercieBuilderAdapter.java
com.wb.wizapp.rest.RestAPIService.java
com.wb.wizapp.router.RouteeCallback.java
com.wb.wizapp.router.Routee.java
com.wb.wizapp.router.Router.java
com.wb.wizapp.ui.BaseActivity.java
com.wb.wizapp.ui.BaseProgressFragment.java
com.wb.wizapp.ui.DetailActivity.java
com.wb.wizapp.ui.MainActivity.java
com.wb.wizapp.ui.MainDrawerFragment.java
com.wb.wizapp.ui.RouterWebViewActivity.java
com.wb.wizapp.ui.RouterWebView.java
com.wb.wizapp.ui.zxing.ScanActivity.java