use of com.taobao.weex.bridge.SimpleJSCallback in project incubator-weex by apache.
the class DefaultLocation method getCurrentPosition.
@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);
}
}
use of com.taobao.weex.bridge.SimpleJSCallback in project incubator-weex by apache.
the class DefaultLocation method findLocation.
private WXLocationListener findLocation(String watchId, String sucCallback, String errorCallback, boolean enableHighAccuracy, boolean enableAddress) {
WXLogUtils.d(TAG, "into--[findLocation] mWatchId:" + watchId + "\nsuccessCallback:" + sucCallback + "\nerrorCallback:" + errorCallback + "\nenableHighAccuracy:" + enableHighAccuracy + "\nmEnableAddress:" + enableAddress);
if (mLocationManager == null) {
mLocationManager = (LocationManager) mWXSDKInstance.getContext().getSystemService(Context.LOCATION_SERVICE);
}
Criteria criteria = new Criteria();
if (enableHighAccuracy) {
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
}
// String provider = locationManager.getBestProvider(criteria, false);
if (ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
WXLocationListener WXLocationListener = new WXLocationListener(mLocationManager, mWXSDKInstance, watchId, sucCallback, errorCallback, enableAddress);
if (mLocationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) {
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE, WXLocationListener);
}
if (mLocationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) {
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, WXLocationListener);
}
return WXLocationListener;
} else {
Map<String, Object> options = new HashMap<>();
options.put(ERROR_CODE, ErrorCode.NO_PERMISSION_ERROR);
options.put(ERROR_MSG, ErrorMsg.NO_PERMISSION_ERROR);
if (mWXSDKInstance != null) {
new SimpleJSCallback(mWXSDKInstance.getInstanceId(), errorCallback).invoke(options);
}
}
return null;
}
use of com.taobao.weex.bridge.SimpleJSCallback in project incubator-weex by apache.
the class WXSDKInstance method fireModuleEvent.
/**
* 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);
}
}
}
}
Aggregations