com.taobao.weex.bridge.SimpleJSCallback Java Examples

The following examples show how to use com.taobao.weex.bridge.SimpleJSCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultLocation.java    From incubator-weex-playground with Apache License 2.0 6 votes vote down vote up
@Override
public void getCurrentPosition(final String successCallback, final String errorCallback, final String params) {
  WXLogUtils.d(TAG, "into--[getCurrentPosition] successCallback:" + successCallback + " \nerrorCallback:" + errorCallback + " \nparams:" + params);
  if (!TextUtils.isEmpty(params)) {
    try {
      JSONObject jsObj = new JSONObject(params);
      boolean enableHighAccuracy = jsObj.optBoolean("enableHighAccuracy");
      boolean enableAddress = jsObj.optBoolean("address");
      WXLocationListener listener = findLocation(null, successCallback, errorCallback, enableHighAccuracy, enableAddress);
      if (listener != null) {
        mWXLocationListeners.add(listener);
      }
      return;
    } catch (JSONException e) {
      WXLogUtils.e(TAG, e);
    }
  }
  Map<String, Object> options = new HashMap<>();
  options.put(ERROR_CODE, ErrorCode.PARAMS_ERROR);
  options.put(ERROR_MSG, ErrorMsg.PARAMS_ERROR);
  if (mWXSDKInstance != null) {
    new SimpleJSCallback(mWXSDKInstance.getInstanceId(), errorCallback).invoke(options);
  }
}
 
Example #2
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Notifies WEEX that this event has occurred
 * @param eventName WEEX register event
 * @param module Events occur in this Module
 * @param params The parameters to be notified to WEEX are required
 */
public void fireModuleEvent(String eventName, WXModule module,Map<String, Object> params) {
  if (TextUtils.isEmpty(eventName) || module == null) {
    return;
  }

  Map<String, Object> event = new HashMap<>();
  event.put("type", eventName);
  event.put("module", module.getModuleName());
  event.put("data", params);

  List<String> callbacks = module.getEventCallbacks(eventName);
  if (callbacks != null) {
    for (String callback : callbacks) {
      SimpleJSCallback jsCallback = new SimpleJSCallback(mInstanceId, callback);
      if (module.isOnce(callback)) {
        jsCallback.invoke(event);
      } else {
        jsCallback.invokeAndKeepAlive(event);
      }
    }
  }
}
 
Example #3
Source File: WXSDKInstance.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Notifies WEEX that this event has occurred
 * @param eventName WEEX register event
 * @param module Events occur in this Module
 * @param params The parameters to be notified to WEEX are required
 */
public void fireModuleEvent(String eventName, WXModule module,Map<String, Object> params) {
  if (TextUtils.isEmpty(eventName) || module == null) {
    return;
  }
  List<String> callbacks = module.getEventCallbacks(eventName);
  if (callbacks != null) {
    for (String callback : callbacks) {
      SimpleJSCallback jsCallback = new SimpleJSCallback(mInstanceId, callback);
      if (module.isOnce(callback)) {
        jsCallback.invokeAndKeepAlive(params);
      } else {
        jsCallback.invoke(params);
      }
    }
  }
}
 
Example #4
Source File: DefaultLocation.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@Override
public void watchPosition(final String successCallback, final String errorCallback, final String params) {
  if (WXEnvironment.isApkDebugable()){
    WXLogUtils.d("into--[watchPosition] successCallback:" + successCallback + " errorCallback:" + errorCallback + "\nparams:" + params);
  }
  if (!TextUtils.isEmpty(params)) {
    try {
      JSONObject jsObj = new JSONObject(params);
      boolean enableHighAccuracy = jsObj.optBoolean("enableHighAccuracy");
      boolean enableAddress = jsObj.optBoolean("address");

      String id = UUID.randomUUID().toString();
      WXLocationListener listener = findLocation(id, successCallback, errorCallback, enableHighAccuracy, enableAddress);
      if (listener != null) {
        mRegisterSucCallbacks.put(id, listener);
      }
      return;
    } catch (JSONException e) {
      WXLogUtils.e(TAG, e);
    }
  }
  Map<String, Object> options = new HashMap<>();
  options.put(ERROR_CODE, ErrorCode.PARAMS_ERROR);
  options.put(ERROR_MSG, ErrorMsg.PARAMS_ERROR);
  if (mWXSDKInstance != null) {
    new SimpleJSCallback(mWXSDKInstance.getInstanceId(), errorCallback).invoke(options);
  }
}
 
Example #5
Source File: DefaultLocation.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
private WXLocationListener(LocationManager locationManager, WXSDKInstance instance, String watchId, String sucCallback, String errorCallback, boolean enableAddress) {
  this.mWatchId = watchId;
  if (instance != null) {
    this.mSucCallback = new SimpleJSCallback(instance.getInstanceId(), sucCallback);
    this.mErrorCallback = new SimpleJSCallback(instance.getInstanceId(), errorCallback);
    mContext = instance.getContext();
  }
  this.mEnableAddress = enableAddress;
  mHandler = new Handler(this);
  mLocationManager = locationManager;
  mHandler.sendEmptyMessageDelayed(TIME_OUT_WHAT, GPS_TIMEOUT);
}