com.taobao.weex.dom.WXEvent Java Examples

The following examples show how to use com.taobao.weex.dom.WXEvent. 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: WeexActivity.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
/**
 * 处理weex返回键
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    BasicComponentData basicComponentData = mWXSDKInstance.getRootComponent().getBasicComponentData();
    final WXAttr attrs = basicComponentData.getAttrs();
    boolean isHasInterceptBack = attrs.containsKey(WeexConstant.ATTR_INTERCEPT_BACK);
    if ((keyCode == KeyEvent.KEYCODE_BACK) && isHasInterceptBack) {
        Object interceptBackObj = attrs.get(WeexConstant.ATTR_INTERCEPT_BACK);
        try {
            boolean interceptBack = false;
            if (interceptBackObj != null) {
                interceptBack = Boolean.parseBoolean(interceptBackObj.toString());
            }
            if (interceptBack) {
                WXEvent events = basicComponentData.getEvents();
                boolean hasBack = events.contains(WeexConstant.EVENT_BACK);
                if (hasBack) {
                    mWXSDKInstance.fireEvent(basicComponentData.mRef, WeexConstant.EVENT_BACK);
                }
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #5
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 #6
Source File: WXSlider.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageSelected(int pos) {
  if (mAdapter.getRealPosition(pos) == lastPos) {
    return;
  }
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.d("onPageSelected >>>>" + mAdapter.getRealPosition(pos) + " lastPos: " + lastPos);
  }
  if (mAdapter == null || mAdapter.getRealCount() == 0) {
    return;
  }

  int realPosition = mAdapter.getRealPosition(pos);
  if (mChildren == null || realPosition >= mChildren.size()) {
    return;
  }

  if (getDomObject().getEvents().size() == 0) {
    return;
  }
  WXEvent event = getDomObject().getEvents();
  String ref = getDomObject().getRef();
  if (event.contains(Constants.Event.CHANGE) && WXViewUtils.onScreenArea(getHostView())) {
    params.put(INDEX, realPosition);

    Map<String, Object> domChanges = new HashMap<>();
    Map<String, Object> attrsChanges = new HashMap<>();
    attrsChanges.put(INDEX, realPosition);
    domChanges.put("attrs", attrsChanges);
    WXSDKManager.getInstance().fireEvent(getInstanceId(), ref,
        Constants.Event.CHANGE, params, domChanges);
  }

  mViewPager.requestLayout();
  getHostView().invalidate();
  lastPos = mAdapter.getRealPosition(pos);
}
 
Example #7
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 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) {
      fireEvent(comp.getRef(), Constants.Event.CLICKBACKITEM,null, null);
    }
    return hasBackPressed;
  }
  return false;
}
 
Example #8
Source File: WXDivTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom,"1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}
 
Example #9
Source File: WXSlider.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public void onPageSelected(int pos) {
  if (mAdapter.getRealPosition(pos) == lastPos) {
    return;
  }
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.d("onPageSelected >>>>" + mAdapter.getRealPosition(pos) + " lastPos: " + lastPos);
  }
  if (mAdapter == null || mAdapter.getRealCount() == 0) {
    return;
  }

  int realPosition = mAdapter.getRealPosition(pos);
  if (mChildren == null || realPosition >= mChildren.size()) {
    return;
  }

  if (getDomObject().getEvents().size() == 0) {
    return;
  }
  WXEvent event = getDomObject().getEvents();
  String ref = getDomObject().getRef();
  if (event.contains(Constants.Event.CHANGE) && WXViewUtils.onScreenArea(getHostView())) {
    params.put(INDEX, realPosition);

    Map<String, Object> domChanges = new HashMap<>();
    Map<String, Object> attrsChanges = new HashMap<>();
    attrsChanges.put(INDEX, realPosition);
    domChanges.put("attrs", attrsChanges);
    WXSDKManager.getInstance().fireEvent(getInstanceId(), ref,
        Constants.Event.CHANGE, params, domChanges);
  }

  mViewPager.requestLayout();
  getHostView().invalidate();
  lastPos = mAdapter.getRealPosition(pos);
}
 
Example #10
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 #11
Source File: WXDivTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom,"1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}