Search in sources :

Example 6 with SimpleJSCallback

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);
    }
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Example 7 with SimpleJSCallback

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;
}
Also used : HashMap(java.util.HashMap) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) JSONObject(org.json.JSONObject) Criteria(android.location.Criteria)

Example 8 with SimpleJSCallback

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);
            }
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SimpleJSCallback(com.taobao.weex.bridge.SimpleJSCallback) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

SimpleJSCallback (com.taobao.weex.bridge.SimpleJSCallback)8 HashMap (java.util.HashMap)7 JSONObject (com.alibaba.fastjson.JSONObject)3 JSONObject (org.json.JSONObject)3 WXDomObject (com.taobao.weex.dom.WXDomObject)2 WXComponent (com.taobao.weex.ui.component.WXComponent)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JSONException (org.json.JSONException)2 Rect (android.graphics.Rect)1 Criteria (android.location.Criteria)1 Message (android.os.Message)1 WXSDKInstance (com.taobao.weex.WXSDKInstance)1 JSCallback (com.taobao.weex.bridge.JSCallback)1 WXRecyclerTemplateList (com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList)1 ArrayList (java.util.ArrayList)1