com.taobao.weex.bridge.WXBridgeManager Java Examples

The following examples show how to use com.taobao.weex.bridge.WXBridgeManager. 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: UWXFrameBaseActivity.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
    if (intent == null) {
        return;
    }
    if (intent.getStringExtra("params") != null) {
        String params = intent.getStringExtra("params");
        String backTag = intent.getStringExtra("backTag");
        if (!TextUtils.isEmpty(params)) {
            WXComponent comp = mInstance.getRootComponent();
            if (comp != null) {
                WXEvent events = comp.getDomObject().getEvents();
                boolean hasActive = events.contains(UConstants.Event.ACTIVED);
                if (hasActive) {
                    Map<String, Object> data = new HashMap<>();
                    data.put("param", params);
                    data.put("tagCode", backTag);
                    WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ACTIVED, data, null);
                }
            }
        }
    }
}
 
Example #2
Source File: UWXFrameBaseActivity.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
    public void onViewCreated(WXSDKInstance wxsdkInstance, View view) {
        super.onViewCreated(wxsdkInstance, view);
        WXComponent comp = mInstance.getRootComponent();
        if (comp != null) {
            WXEvent events = comp.getDomObject().getEvents();
            boolean hasReady = events.contains(UConstants.Event.READY);
            if (hasReady) {
                Map<String, Object> data = new HashMap<>();
                data.put("param", wxInfo.getParam());
                WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.READY, data, null);
            }
        }
//        if (!isHasNavBar) {
//            setTranslateAnimation(getContainer());
//        }
    }
 
Example #3
Source File: UWXFrameBaseActivity.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    WXComponent comp = mInstance.getRootComponent();
    if (comp != null) {
        WXEvent events = comp.getDomObject().getEvents();
        boolean hasDeactived = events.contains(UConstants.Event.DEACTIVED);
        if (hasDeactived) {
            WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.DEACTIVED, null, null);
        }
    }
    if (mIsShakeDetectorStarted && mShakeDetector != null) {
        mShakeDetector.stop();
        mIsShakeDetectorStarted = false;
    }
}
 
Example #4
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 6 votes vote down vote up
@WXModuleAnno
public void setNavBarLeftItem(String param, final String callbackId) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarLeftItem(param)) {
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                        WXConst.MSG_SUCCESS);
                return;
            }
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);

}
 
Example #5
Source File: AbstractEditComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod
public void getSelectionRange(String callbackId) {
  EditText hostView;
  Map<String, Object> result = new HashMap<>(2);
  if ((hostView = getHostView()) != null) {
    int start = hostView.getSelectionStart();
    int end = hostView.getSelectionEnd();

    if (!hostView.hasFocus()) {
      //The default behavior, same as iOS and web
      start = 0;
      end = 0;
    }

    result.put(Constants.Name.SELECTION_START, start);
    result.put(Constants.Name.SELECTION_END, end);
  }
  WXBridgeManager.getInstance().callback(getInstanceId(), callbackId, result, false);
}
 
Example #6
Source File: WXWsonTestModule.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = false)
public void switchTrans(JSCallback callback) {
    if(WXWsonJSONSwitch.USE_WSON){
        WXBridgeManager.updateGlobalConfig("wson_off");
        callback.invoke("wson off, use json");
    }else{
        WXBridgeManager.updateGlobalConfig("wson_on");
        callback.invoke("wson on, use wson");
    }
}
 
Example #7
Source File: WXComponentRegistry.java    From weex-uikit with MIT License 5 votes vote down vote up
public static boolean registerComponent(final String type, final IFComponentHolder holder, final Map<String, Object> componentInfo) throws WXException {
  if (holder == null || TextUtils.isEmpty(type)) {
    return false;
  }

  //execute task in js thread to make sure register order is same as the order invoke register method.
  WXBridgeManager.getInstance()
      .post(new Runnable() {
    @Override
    public void run() {
      try {
        Map<String, Object> registerInfo = componentInfo;
        if (registerInfo == null){
          registerInfo = new HashMap<>();
        }

        registerInfo.put("type",type);
        registerInfo.put("methods",holder.getMethods());
        registerNativeComponent(type, holder);
        registerJSComponent(registerInfo);
        sComponentInfos.add(registerInfo);
      } catch (WXException e) {
        WXLogUtils.e("register component error:", e);
      }

    }
  });
  return true;
}
 
Example #8
Source File: WXComponentRegistry.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void reload(){
  WXBridgeManager.getInstance().post(new Runnable() {
    @Override
    public void run() {
      try {
        for(Map<String,Object> com:sComponentInfos){
          registerJSComponent(com);
        }
      } catch (WXException e) {
        WXLogUtils.e("", e);
      }
    }
  });
}
 
Example #9
Source File: WXSDKInstance.java    From weex-uikit with MIT License 5 votes vote down vote up
public boolean onBackPressed() {
  WXComponent comp = getRootComponent();
  if(comp != null) {
    WXEvent events= comp.getDomObject().getEvents();
    boolean hasBackPressed = events.contains(Constants.Event.CLICKBACKITEM);
    if (hasBackPressed) {
      WXBridgeManager.getInstance().fireEvent(this.mInstanceId, comp.getRef(), Constants.Event.CLICKBACKITEM,null, null);
    }
    return hasBackPressed;
  }
  return false;
}
 
Example #10
Source File: WXSDKInstance.java    From weex-uikit with MIT License 5 votes vote down vote up
/********************************
 *  end hook Activity life cycle callback
 ********************************************************/

public void onViewDisappear(){
  WXComponent comp = getRootComponent();
  if(comp != null) {
    WXBridgeManager.getInstance().fireEvent(this.mInstanceId, comp.getRef(), Constants.Event.VIEWDISAPPEAR, null, null);
    //call disappear of nested instances
    for(OnInstanceVisibleListener instance:mVisibleListeners){
      instance.onDisappear();
    }
  }
}
 
Example #11
Source File: WXSDKInstance.java    From weex-uikit with MIT License 5 votes vote down vote up
public void onViewAppear(){
  WXComponent comp = getRootComponent();
  if(comp != null) {
    WXBridgeManager.getInstance().fireEvent(this.mInstanceId, comp.getRef(), Constants.Event.VIEWAPPEAR,null, null);
    for(OnInstanceVisibleListener instance:mVisibleListeners){
      instance.onAppear();
    }
  }
}
 
Example #12
Source File: WXSDKEngine.java    From weex-uikit with MIT License 5 votes vote down vote up
private static void doInitInternal(final Application application,final InitConfig config){
  WXEnvironment.sApplication = application;
  WXEnvironment.JsFrameworkInit = false;

  WXBridgeManager.getInstance().post(new Runnable() {
    @Override
    public void run() {
      long start = System.currentTimeMillis();
      WXSDKManager sm = WXSDKManager.getInstance();
      if(config != null ) {
        sm.setInitConfig(config);
        if(config.getDebugAdapter()!=null){
          config.getDebugAdapter().initDebug(application);
        }
      }
      WXSoInstallMgrSdk.init(application);
      boolean isSoInitSuccess = WXSoInstallMgrSdk.initSo(V8_SO_NAME, 1, config!=null?config.getUtAdapter():null);
      if (!isSoInitSuccess) {
        return;
      }
      sm.initScriptsFramework(config!=null?config.getFramework():null);

      WXEnvironment.sSDKInitExecuteTime = System.currentTimeMillis() - start;
      WXLogUtils.renderPerformanceLog("SDKInitExecuteTime", WXEnvironment.sSDKInitExecuteTime);
    }
  });
  register();
}
 
Example #13
Source File: WXSDKEngine.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void reload(final Context context,String framework, boolean remoteDebug) {
  WXEnvironment.sRemoteDebugMode = remoteDebug;
  WXBridgeManager.getInstance().restart();
  WXBridgeManager.getInstance().initScriptsFramework(framework);
  WXModuleManager.reload();
  WXComponentRegistry.reload();
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(JS_FRAMEWORK_RELOAD));
    }
  });
}
 
Example #14
Source File: WXTimerModuleTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception{
  module = new WXTimerModule();
  module.mWXSDKInstance = WXSDKInstanceTest.createInstance();

  bridge = Mockito.mock(WXBridgeManager.class);
  WXBridgeManagerTest.setBridgeManager(bridge);

}
 
Example #15
Source File: DebugTool.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
public static boolean stopRemoteDebug() {
    try {
        WXBridgeManager manager = WXBridgeManager.getInstance();
        Method method = manager.getClass().getDeclaredMethod("stopRemoteDebug");
        method.setAccessible(true);
        method.invoke(manager);
        return true;
    }catch (Exception e) {
        WXLogUtils.e(TAG,e.getMessage());
        return false;
    }
}
 
Example #16
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void push(String param, final String callbackId) {

    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().push(param)) {
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                        WXConst.MSG_SUCCESS);
                return;
            }
        }

        try {
            JSONObject jsonObject = new JSONObject(param);
            String url = jsonObject.optString(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("http");
                }
                Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
                intent.addCategory(WEEX);
                intent.putExtra(INSTANCE_ID, mWXSDKInstance.getInstanceId());
                mWXSDKInstance.getContext().startActivity(intent);
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                        WXConst.MSG_SUCCESS);
            }
        } catch (Exception e) {
            WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
            WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                    WXConst.MSG_FAILED);
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);
}
 
Example #17
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void pop(String param, final String callbackId) {

    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().pop(param)) {
            WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                    WXConst.MSG_SUCCESS);
            return;
        }
    }

    if (mWXSDKInstance.getContext() instanceof Activity) {
        ((Activity) mWXSDKInstance.getContext()).finish();
    }
}
 
Example #18
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void setNavBarRightItem(String param, final String callbackId) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarRightItem(param)) {
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                        WXConst.MSG_SUCCESS);
                return;
            }
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);
}
 
Example #19
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void clearNavBarRightItem(String param, final String callbackId) {
    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().clearNavBarRightItem(param)) {
            WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                    WXConst.MSG_SUCCESS);
            return;
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);
}
 
Example #20
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void clearNavBarLeftItem(String param, final String callbackId) {
    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().clearNavBarLeftItem(param)) {
            WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                    WXConst.MSG_SUCCESS);
            return;
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);
}
 
Example #21
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void setNavBarMoreItem(String param, final String callbackId) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarMoreItem(param)) {
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                        WXConst.MSG_SUCCESS);
                return;
            }
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);
}
 
Example #22
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void clearNavBarMoreItem(String param, final String callbackId) {
    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().clearNavBarMoreItem(param)) {
            WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                    WXConst.MSG_SUCCESS);
            return;
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);
}
 
Example #23
Source File: WXNavigatorModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void setNavBarTitle(String param, final String callbackId) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarTitle(param)) {
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
                        WXConst.MSG_SUCCESS);
                return;
            }
        }
    }

    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId,
            WXConst.MSG_FAILED);
}
 
Example #24
Source File: WXModalUIModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno
public void alert(String param, final String callbackId) {

  if (mWXSDKInstance.getContext() instanceof Activity) {

    String message = "";
    String okTitle = WXConst.OK;
    if (!TextUtils.isEmpty(param)) {
      try {
        param = URLDecoder.decode(param, "utf-8");
        JSONObject jsObj = new JSONObject(param);
        message = jsObj.optString(WXConst.MESSAGE);
        okTitle = jsObj.optString(WXConst.OK_TITLE);
      } catch (Exception e) {
        WXLogUtils.e("[WXModalUIModule] alert param parse error " + WXLogUtils.getStackTrace(e));
      }
    }
    if (TextUtils.isEmpty(message)) {
      message="";
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(mWXSDKInstance.getContext());
    builder.setMessage(message);

    final String okTitle_f = TextUtils.isEmpty(okTitle) ? WXConst.OK : okTitle;
    builder.setPositiveButton(okTitle_f, new OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callbackId, okTitle_f);

      }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.setCanceledOnTouchOutside(false);
    alertDialog.show();
  } else {
    WXLogUtils.e("[WXModalUIModule] when call alert mWXSDKInstance.getContext() must instanceof Activity");
  }
}
 
Example #25
Source File: WXComponentRegistry.java    From weex with Apache License 2.0 5 votes vote down vote up
private static void registerInternal(final String type,final Class<? extends WXComponent> clazz, final Map<String, String> componentInfo){
  WXBridgeManager.getInstance().getJSHandler().post(new Runnable() {
    @Override
    public void run() {
      try {
        registerNativeComponent(type, clazz);
        registerJSComponent(componentInfo);
      } catch (WXException e) {
        e.printStackTrace();
      }

    }
  });
}
 
Example #26
Source File: WXSDKEngine.java    From weex with Apache License 2.0 5 votes vote down vote up
private static void doInitInternal(final Application application,final InitConfig config){
  WXEnvironment.sApplication = application;
  WXEnvironment.JsFrameworkInit = false;

  WXBridgeManager.getInstance().getJSHandler().post(new Runnable() {
    @Override
    public void run() {
      long start = System.currentTimeMillis();
      WXSDKManager sm = WXSDKManager.getInstance();
      if(config != null ) {
        sm.setIWXHttpAdapter(config.getHttpAdapter());
        sm.setIWXImgLoaderAdapter(config.getImgAdapter());
        sm.setIWXUserTrackAdapter(config.getUtAdapter());
        sm.setIWXDebugAdapter(config.getDebugAdapter());
        if(config.getDebugAdapter()!=null){
          config.getDebugAdapter().initDebug(application);
        }
      }
      WXSoInstallMgrSdk.init(application);
      boolean isSoInitSuccess = WXSoInstallMgrSdk.initSo(V8_SO_NAME, 1, config!=null?config.getUtAdapter():null);
      if (!isSoInitSuccess) {
        return;
      }
      sm.initScriptsFramework(null);

      WXEnvironment.sSDKInitExecuteTime = System.currentTimeMillis() - start;
      WXLogUtils.renderPerformanceLog("SDKInitInvokeTime", WXEnvironment.sSDKInitInvokeTime);
      WXLogUtils.renderPerformanceLog("SDKInitExecuteTime", WXEnvironment.sSDKInitExecuteTime);
    }
  });
  register();
}
 
Example #27
Source File: WXTimerModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = false)
public void clearInterval(int funcId) {
  if(funcId <= 0){
    return;
  }
  WXBridgeManager.getInstance().removeMessage(WXJSBridgeMsgType.MODULE_INTERVAL, funcId);
}
 
Example #28
Source File: UWXFrameBaseActivity.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void onBackPressed() {
    WXComponent comp = mInstance.getRootComponent();
    if (comp != null) {
        WXEvent events = comp.getDomObject().getEvents();
        boolean hasBack = events.contains(UConstants.Event.ONANDROIDBACK);
        if (hasBack) {
            WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ONANDROIDBACK, null, null);
            return;
        } else {
            super.onBackPressed();
        }
    }
    super.onBackPressed();
}
 
Example #29
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void setNavBarHidden(String param, final String callback) {
    String message = MSG_FAILED;
    try {
        JSONObject jsObj = JSON.parseObject(param);
        int visibility = jsObj.getInteger(Constants.Name.NAV_BAR_VISIBILITY);
        boolean success = changeVisibilityOfActionBar(mWXSDKInstance.getContext(), visibility);
        if (success) {
            message = MSG_SUCCESS;
        }
    } catch (JSONException e) {
        WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
    }
    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, message);
}
 
Example #30
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void setNavBarHidden(String param, final String callback) {
    String message = MSG_FAILED;
    try {
        JSONObject jsObj = JSON.parseObject(param);
        int visibility = jsObj.getInteger(Constants.Name.NAV_BAR_VISIBILITY);
        boolean success = changeVisibilityOfActionBar(mWXSDKInstance.getContext(), visibility);
        if (success) {
            message = MSG_SUCCESS;
        }
    } catch (JSONException e) {
        WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
    }
    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, message);
}