com.taobao.weex.bridge.JSCallback Java Examples

The following examples show how to use com.taobao.weex.bridge.JSCallback. 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: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void length(@Nullable final JSCallback callback) {
    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.length(new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #2
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarRightItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarRightItem(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example #3
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarLeftItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarLeftItem(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }

}
 
Example #4
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@JSMethod(uiThread = true)
public void close(JSONObject options, JSCallback success, JSCallback failure) {
    JSONObject result = new JSONObject();
    JSCallback callback = null;
    if (mWXSDKInstance.getContext() instanceof Activity) {
        callback = success;
        ((Activity) mWXSDKInstance.getContext()).finish();
    } else {
        result.put(CALLBACK_RESULT, MSG_FAILED);
        result.put(CALLBACK_MESSAGE, "close page failed");
        callback = failure;
    }
    if (callback != null) {
        callback.invoke(result);
    }
}
 
Example #5
Source File: WXRenderStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
public void getComponentSize(String ref, JSCallback callback) {
  WXComponent component = mRegistry.get(ref);
  Map<String, Object> options = new HashMap<>();
  if (component != null) {
    Map<String, String> size = new HashMap<>();
    Rect sizes = component.getComponentSize();
    size.put("width", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.width(),mWXSDKInstance.getViewPortWidth())));
    size.put("height", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.height(),mWXSDKInstance.getViewPortWidth())));
    size.put("bottom",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.bottom,mWXSDKInstance.getViewPortWidth())));
    size.put("left",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.left,mWXSDKInstance.getViewPortWidth())));
    size.put("right",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.right,mWXSDKInstance.getViewPortWidth())));
    size.put("top",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.top,mWXSDKInstance.getViewPortWidth())));
    options.put("size", size);
    options.put("result", true);
  } else {
    options.put("errMsg", "Component does not exist");
  }
  callback.invoke(options);
}
 
Example #6
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void pop(String param, JSCallback callback) {

    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().pop(param)) {
            if (callback != null) {
                callback.invoke(MSG_SUCCESS);
            }
            return;
        }
    }

    if (mWXSDKInstance.getContext() instanceof Activity) {
        if (callback != null) {
            callback.invoke(MSG_SUCCESS);
        }
        ((Activity) mWXSDKInstance.getContext()).finish();
    }
}
 
Example #7
Source File: WXStreamModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private void sendRequest(Options options,ResponseCallback callback,JSCallback progressCallback){
  WXRequest wxRequest = new WXRequest();
  wxRequest.method = options.getMethod();
  wxRequest.url = mWXSDKInstance.rewriteUri(Uri.parse(options.getUrl()), URIAdapter.REQUEST).toString();
  wxRequest.body = options.getBody();
  wxRequest.timeoutMs = options.getTimeout();

  if(options.getHeaders()!=null)
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = options.getHeaders();
  }else{
    wxRequest.paramMap.putAll(options.getHeaders());
  }


  IWXHttpAdapter adapter = ( mAdapter==null && mWXSDKInstance != null) ? mWXSDKInstance.getWXHttpAdapter() : mAdapter;
  if (adapter != null) {
    adapter.sendRequest(wxRequest, new StreamHttpListener(callback,progressCallback));
  }else{
    WXLogUtils.e("WXStreamModule","No HttpAdapter found,request failed.");
  }
}
 
Example #8
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarTitle(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarTitle(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }
    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example #9
Source File: WXStorageModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void setItemPersistent(String key, String value, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key) || value == null) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.setItemPersistent(key, value, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #10
Source File: WXStorageModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void getAllKeys(@Nullable final JSCallback callback) {
    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.getAllKeys(new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #11
Source File: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void setItemPersistent(String key, String value, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key) || value == null) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.setItemPersistent(key, value, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #12
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarLeftItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarLeftItem(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }

}
 
Example #13
Source File: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void getAllKeys(@Nullable final JSCallback callback) {
    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.getAllKeys(new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #14
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void pop(String param, JSCallback callback) {

    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().pop(param)) {
            if (callback != null) {
                callback.invoke(MSG_SUCCESS);
            }
            return;
        }
    }

    if (mWXSDKInstance.getContext() instanceof Activity) {
        if (callback != null) {
            callback.invoke(MSG_SUCCESS);
        }
        ((Activity) mWXSDKInstance.getContext()).finish();
    }
}
 
Example #15
Source File: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void removeItem(String key, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key)) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.removeItem(key, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #16
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void close(JSONObject options, JSCallback success, JSCallback failure) {
    JSONObject result = new JSONObject();
    JSCallback callback = null;
    if (mWXSDKInstance.getContext() instanceof Activity) {
        callback = success;
        ((Activity) mWXSDKInstance.getContext()).finish();
    } else {
        result.put(CALLBACK_RESULT, MSG_FAILED);
        result.put(CALLBACK_MESSAGE, "Close page failed.");
        callback = failure;
    }
    if (callback != null) {
        callback.invoke(result);
    }
}
 
Example #17
Source File: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void getItem(String key, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key)) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.getItem(key, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #18
Source File: WXStorageModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void removeItem(String key, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key)) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.removeItem(key, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #19
Source File: WXClipboardModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod
public void getString(@Nullable JSCallback callback) {
    Context context = mWXSDKInstance.getContext();
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    Map<String, Object> map = new HashMap<>(2);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        ClipData.Item item = clip.getItemAt(0);
        CharSequence text = coerceToText(context, item);

        map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED);
        map.put(DATA, text != null ? text : "");
    } else {
        map.put(RESULT, RESULT_FAILED);
        map.put(DATA, "");
    }

    if (null != callback) {
        callback.invoke(map);
    }
}
 
Example #20
Source File: WXStreamModule.java    From weex-uikit with MIT License 6 votes vote down vote up
private void sendRequest(Options options,ResponseCallback callback,JSCallback progressCallback){
  WXRequest wxRequest = new WXRequest();
  wxRequest.method = options.getMethod();
  wxRequest.url = mWXSDKInstance.rewriteUri(Uri.parse(options.getUrl()), URIAdapter.REQUEST).toString();
  wxRequest.body = options.getBody();
  wxRequest.timeoutMs = options.getTimeout();

  if(options.getHeaders()!=null)
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = options.getHeaders();
  }else{
    wxRequest.paramMap.putAll(options.getHeaders());
  }


  IWXHttpAdapter adapter = ( mAdapter==null && mWXSDKInstance != null) ? mWXSDKInstance.getWXHttpAdapter() : mAdapter;
  if (adapter != null) {
    adapter.sendRequest(wxRequest, new StreamHttpListener(callback,progressCallback));
  }else{
    WXLogUtils.e("WXStreamModule","No HttpAdapter found,request failed.");
  }
}
 
Example #21
Source File: WXDomStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
public void getComponentSize(final String ref, final JSCallback callback) {
  if (mDestroy) {
    Map<String, Object> options = new HashMap<>();
    options.put("result", false);
    options.put("errMsg", "Component does not exist");
    callback.invoke(options);
    return;
  }

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.getComponentSize(mInstanceId, ref, callback);
    }

    @Override
    public String toString() {
      return "getComponentSize";
    }
  });
  mDirty=true;

}
 
Example #22
Source File: WXStorageModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void setItem(String key, String value, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key) || value == null) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.setItem(key, value, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });


}
 
Example #23
Source File: WXStorageModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void length(@Nullable final JSCallback callback) {
    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.length(new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #24
Source File: WXClipboardModuleTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetString() throws Exception {

  JSCallback mock = Mockito.mock(JSCallback.class);
  module.getString(mock);
  Mockito.verify(mock,Mockito.times(1)).invoke(Mockito.anyObject());

  testSetString();

  mock = Mockito.mock(JSCallback.class);
  module.getString(mock);
  Mockito.verify(mock,Mockito.times(1)).invoke(Mockito.anyObject());
}
 
Example #25
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarRightItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarRightItem(param)) {
                callback.invoke(MSG_SUCCESS);
                return;
            }
        }
    }

    callback.invoke(MSG_FAILED);
}
 
Example #26
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarMoreItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarMoreItem(param)) {
                callback.invoke(MSG_SUCCESS);
                return;
            }
        }
    }

    callback.invoke(MSG_FAILED);
}
 
Example #27
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarLeftItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarLeftItem(param)) {
                callback.invoke(MSG_SUCCESS);
                return;
            }
        }
    }

    callback.invoke(MSG_FAILED);

}
 
Example #28
Source File: WXNavigatorModuleTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  mockStatic(WXSDKEngine.class);
  callback = Mockito.mock(JSCallback.class);


  module = new WXNavigatorModule();
  module.mWXSDKInstance = WXSDKInstanceTest.createInstance();
}
 
Example #29
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void push(String param, JSCallback callback) {

    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().push(param)) {
                callback.invoke(MSG_SUCCESS);
                return;
            }
        }

        try {
            JSONObject jsonObject = JSON.parseObject(param);
            String url = jsonObject.getString(URL);
            if (!TextUtils.isEmpty(url)) {
                Uri rawUri = Uri.parse(url);
                String scheme = rawUri.getScheme();
                Uri.Builder builder = rawUri.buildUpon();
                if (TextUtils.isEmpty(scheme)) {
                    builder.scheme(Constants.Scheme.HTTP);
                }
                Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
                intent.addCategory(WEEX);
                intent.putExtra(INSTANCE_ID, mWXSDKInstance.getInstanceId());
                mWXSDKInstance.getContext().startActivity(intent);
                callback.invoke(MSG_SUCCESS);
            }
        } catch (Exception e) {
            WXLogUtils.eTag(TAG, e);
            callback.invoke(MSG_FAILED);
        }
    }

    callback.invoke(MSG_FAILED);
}
 
Example #30
Source File: WXWsonTestModule.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = false)
public void  backAsync(JSONObject params, JSCallback callback) {
    JSONObject back = new JSONObject(params);
    back.put("longMax", Long.MAX_VALUE);
    back.put("longMin", Long.MIN_VALUE);
    back.put("javaJSON", back.toJSONString());
    callback.invoke(back);
}