com.taobao.weex.common.WXThread Java Examples

The following examples show how to use com.taobao.weex.common.WXThread. 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: StickyHeaderHelper.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void notifyStickyRemove(WXCell compToRemove) {
  if (compToRemove == null)
    return;
  final WXCell component = mHeaderComps.remove(compToRemove.getRef());
  final View headerView = mHeaderViews.remove(compToRemove.getRef());


  if(component == null || headerView == null){
    WXLogUtils.e(" sticky header to remove not found."+compToRemove.getRef());
    return;
  }
  if(mCurrentStickyRef != null && mCurrentStickyRef.equals(compToRemove.getRef())){
    mCurrentStickyRef = null;
  }
  mParent.post(WXThread.secure(new Runnable() {
    @Override
    public void run() {
      mParent.removeView(headerView);
      component.recoverySticky();
    }
  }));
  if (component.getDomObject().getEvents().contains("unsticky")) {
    component.fireEvent("unsticky");
  }
}
 
Example #2
Source File: SimpleRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * remove top stickyView
 * @param component
 */
private void removeSticky(WXComponent component) {
  final WXCell headComponent = headComponentStack.pop();
  if (!component.getRef().equals(headComponent.getRef())) {
    headComponentStack.push(headComponent);
    return;
  }
  final View headerView = headerViewStack.pop();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        parent.removeView(headerView);
        headComponent.recoverySticky();
      }
    }));
  }

}
 
Example #3
Source File: SimpleRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Pop stickyView to stack
 */
private void showSticky() {
  WXCell headComponent = headComponentStack.pop();
  headComponentStack.push(headComponent);
  final View headerView = headComponent.getRealView();
  if (headerView == null)
    return;
  headerViewStack.push(headerView);
  headComponent.removeSticky();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        ViewGroup existedParent;
        if((existedParent = (ViewGroup)headerView.getParent())!= null){
          existedParent.removeView(headerView);
        }
        parent.addView(headerView);
      }
    }));
  }
}
 
Example #4
Source File: BounceRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * remove top stickyView
 * @param component
 */
private void removeSticky(WXComponent component) {
  final WXCell headComponent = headComponentStack.pop();
  if (!component.getRef().equals(headComponent.getRef())) {
    headComponentStack.push(headComponent);
    return;
  }
  final View headerView = headerViewStack.pop();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        parent.removeView(headerView);
        headComponent.recoverySticky();
      }
    }));
  }

}
 
Example #5
Source File: BounceRecyclerView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Pop stickyView to stack
 */
private void showSticky() {
  WXCell headComponent = headComponentStack.pop();
  headComponentStack.push(headComponent);
  final View headerView = headComponent.getRealView();
  if (headerView == null)
    return;
  headerViewStack.push(headerView);
  headComponent.removeSticky();
  final ViewGroup parent = (ViewGroup) getParent();
  if(parent != null){
    parent.post(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        ViewGroup existedParent;
        if((existedParent = (ViewGroup)headerView.getParent())!= null){
          existedParent.removeView(headerView);
        }
        parent.addView(headerView);
      }
    }));
  }
}
 
Example #6
Source File: WXRenderManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public void runOnThread(final String instanceId, final IWXRenderTask task) {
  mWXRenderHandler.post(WXThread.secure(new Runnable() {

    @Override
    public void run() {
      if (mRegistries.get(instanceId) == null) {
        return;
      }
      task.execute();
    }
  }));
}
 
Example #7
Source File: WXSliderNeighbor.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void updateAdapterScaleAndAlpha(final float alpha, final float scale) {
    final List<View> pageViews = mAdapter.getViews();
    final int curPos = mViewPager.getCurrentItem();

    if(pageViews.size() > 0) {
        final View currentPage = pageViews.get(curPos);
        updateScaleAndAlpha(((ViewGroup)currentPage).getChildAt(0), 1.0F, mCurrentItemScale);

        if(pageViews.size() < 2) {
            return;
        }
        //make sure View's width & height are measured.
        currentPage.postDelayed(WXThread.secure(new Runnable() {
            @Override
            public void run() {
                //change left and right page's translation
                updateNeighbor(currentPage, alpha, scale);

            }
        }), 17);

        // make sure only display view current, left, right.
        int left = (curPos == 0) ? pageViews.size()-1 : curPos-1;
        int right = (curPos == pageViews.size()-1) ? 0 : curPos+1;
        for(int i =0; i<mAdapter.getRealCount(); i++) {
            if(i != left && i != curPos && i != right) {
                ((ViewGroup)pageViews.get(i)).getChildAt(0).setAlpha(0F);
            }
        }
    }
}
 
Example #8
Source File: WXTimerModuleTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  WXSDKEngine.initialize(RuntimeEnvironment.application, new InitConfig.Builder().build());
  WXBridgeManager bridge = Mockito.mock(WXBridgeManager.class);
  when(bridge.getJSLooper()).thenReturn(new WXThread("js").getLooper());
  WXBridgeManagerTest.setBridgeManager(bridge);

  module = Mockito.spy(new WXTimerModule());
  module.mWXSDKInstance = WXSDKInstanceTest.createInstance();
  Handler handler = new Handler(WXBridgeManager.getInstance().getJSLooper(), module);
  mLooper = Shadows.shadowOf(handler.getLooper());
  module.setHandler(handler);
}
 
Example #9
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public void post(Runnable r){
  if(mInterceptor != null && mInterceptor.take(r)){
    //task is token by the interceptor
    return;
  }
  if (mJSHandler == null){
    return;
  }

  mJSHandler.post(WXThread.secure(r));
}
 
Example #10
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public void post(Runnable r, Object token) {
  if (mJSHandler == null) {
    return;
  }

  Message m = Message.obtain(mJSHandler, WXThread.secure(r));
  m.obj = token;
  m.sendToTarget();
}
 
Example #11
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Refresh instance
 */
public void refreshInstance(final String instanceId, final WXRefreshData jsonData) {
  if (TextUtils.isEmpty(instanceId) || jsonData == null) {
    return;
  }
  mJSHandler.postDelayed(WXThread.secure(new Runnable() {
    @Override
    public void run() {
      invokeRefreshInstance(instanceId, jsonData);
    }
  }), 0);
}
 
Example #12
Source File: DefaultWXStorage.java    From weex-uikit with MIT License 5 votes vote down vote up
private void execute(@Nullable final Runnable runnable) {
    if (mExecutorService == null) {
        mExecutorService = Executors.newSingleThreadExecutor();
    }

    if(runnable != null) {
        mExecutorService.execute(WXThread.secure(runnable));
    }
}
 
Example #13
Source File: WXDomManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public void post(Runnable task) {
  if (mDomHandler == null || task == null || mDomThread == null || !mDomThread.isWXThreadAlive()
      || mDomThread.getLooper() == null) {
    return;
  }
  mDomHandler.post(WXThread.secure(task));
}
 
Example #14
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void post(Runnable r){
  if(mInterceptor != null && mInterceptor.take(r)){
    //task is token by the interceptor
    return;
  }
  if (mJSHandler == null){
    return;
  }

  mJSHandler.post(WXThread.secure(r));
}
 
Example #15
Source File: WXSliderNeighbor.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
protected void addSubView(View view, int index) {
    if (view == null || mAdapter == null) {
        return;
    }

    if (view instanceof WXCircleIndicator) {
        return;
    }

    FrameLayout wrapper = new FrameLayout(getContext());
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    view.setLayoutParams(params);
    wrapper.addView(view);
    super.addSubView(wrapper,index);
    updateAdapterScaleAndAlpha(mNeighborAlpha, mNeighborScale); // we need to set neighbor view status when added.

    view.postDelayed(WXThread.secure(new Runnable() {
        @Override
        public void run() {
            int childCountByDomTree = getNeighborChildrenCount();
            if(mAdapter.getRealCount() == childCountByDomTree || childCountByDomTree == -1) { // -1 mean failed at get child count by travel the dom tree.
                mViewPager.setPageTransformer(false, createTransformer());
            }
        }
    }), 100); // we need to set the PageTransformer when all children has been rendered.

}
 
Example #16
Source File: WXSliderNeighbor.java    From weex-uikit with MIT License 5 votes vote down vote up
private void updateAdapterScaleAndAlpha(final float alpha, final float scale) {
    final List<View> pageViews = mAdapter.getViews();
    final int curPos = mViewPager.getCurrentItem();

    if(pageViews.size() > 0) {
        final View currentPage = pageViews.get(curPos);
        updateScaleAndAlpha(((ViewGroup)currentPage).getChildAt(0),1.0F,WX_DEFAULT_MAIN_NEIGHBOR_SCALE);

        if(pageViews.size() < 2) {
            return;
        }
        //make sure View's width & height are measured.
        currentPage.post(WXThread.secure(new Runnable() {
            @Override
            public void run() {
                //change left and right page's translation
                updateNeighbor(currentPage, alpha, scale);

            }
        }));

        // make sure only display view current, left, right.
        int left = (curPos == 0) ? pageViews.size()-1 : curPos-1;
        int right = (curPos == pageViews.size()-1) ? 0 : curPos+1;
        for(int i =0; i<mAdapter.getRealCount(); i++) {
            if(i != left && i != curPos && i != right) {
                ((ViewGroup)pageViews.get(i)).getChildAt(0).setAlpha(0F);
            }
        }
    }
}
 
Example #17
Source File: WXBridgeManager.java    From weex with Apache License 2.0 5 votes vote down vote up
private WXBridgeManager() {
  launchInspector(WXEnvironment.sRemoteDebugMode);
  if (mWXBridge == null) {
    mWXBridge = new WXBridge();
  }
  mJSThread = new WXThread("WeexJSBridgeThread", this);
  mJSHandler = mJSThread.getHandler();
}
 
Example #18
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void post(Runnable r, Object token) {
  if (mJSHandler == null) {
    return;
  }

  Message m = Message.obtain(mJSHandler, WXThread.secure(r));
  m.obj = token;
  m.sendToTarget();
}
 
Example #19
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Refresh instance
 */
public void refreshInstance(final String instanceId, final WXRefreshData jsonData) {
  if (TextUtils.isEmpty(instanceId) || jsonData == null) {
    return;
  }
  mJSHandler.postDelayed(WXThread.secure(new Runnable() {
    @Override
    public void run() {
      invokeRefreshInstance(instanceId, jsonData);
    }
  }), 0);
}
 
Example #20
Source File: DefaultWXStorage.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void execute(@Nullable final Runnable runnable) {
    if (mExecutorService == null) {
        mExecutorService = Executors.newSingleThreadExecutor();
    }

    if(runnable != null) {
        mExecutorService.execute(WXThread.secure(runnable));
    }
}
 
Example #21
Source File: WXRenderManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void runOnThread(final String instanceId, final RenderAction action) {
  mWXRenderHandler.post(WXThread.secure(new Runnable() {

    @Override
    public void run() {
      if (mRegistries.get(instanceId) == null) {
        return;
      }
      action.executeRender(getRenderContext(instanceId));
    }
  }));
}
 
Example #22
Source File: WXRenderManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void runOnThread(final String instanceId, final IWXRenderTask task) {
  mWXRenderHandler.post(WXThread.secure(new Runnable() {

    @Override
    public void run() {
      if (mRegistries.get(instanceId) == null) {
        return;
      }
      task.execute();
    }
  }));
}
 
Example #23
Source File: CreateFinishAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void executeDom(DOMActionContext context) {
  super.executeDom(context);
  final WXSDKInstance instance = context.getInstance();
  final LayoutFinishListener listener;
  if(instance != null && (listener = instance.getLayoutFinishListener()) != null) {
    WXSDKManager.getInstance().getWXRenderManager().postOnUiThread(WXThread.secure(new Runnable() {
      @Override
      public void run() {
        listener.onLayoutFinish(instance);
      }
    }),0);
  }
}
 
Example #24
Source File: WXDomManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void post(Runnable task) {
  if (mDomHandler == null || task == null || mDomThread == null || !mDomThread.isWXThreadAlive()
      || mDomThread.getLooper() == null) {
    return;
  }
  mDomHandler.post(WXThread.secure(task));
}
 
Example #25
Source File: WXRecyclerView.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
  return super.postDelayed(WXThread.secure(action), delayMillis);
}
 
Example #26
Source File: WXDomManager.java    From weex with Apache License 2.0 4 votes vote down vote up
public WXDomManager(WXRenderManager renderManager) {
  mWXRenderManager = renderManager;
  mDomRegistries = new ConcurrentHashMap<>();
  mDomThread = new WXThread("WeeXDomThread", new WXDomHandler(this));
  mDomHandler = mDomThread.getHandler();
}
 
Example #27
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
private WXBridgeManager() {
  initWXBridge(WXEnvironment.sRemoteDebugMode);
  mJSThread = new WXThread("WeexJSBridgeThread", this);
  mJSHandler = mJSThread.getHandler();
}
 
Example #28
Source File: WXSDKManager.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public void postOnUiThread(Runnable runnable, long delayMillis) {
  mWXRenderManager.postOnUiThread(WXThread.secure(runnable), delayMillis);
}
 
Example #29
Source File: WXEditText.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
  return super.postDelayed(WXThread.secure(action), delayMillis);
}
 
Example #30
Source File: WXHorizontalScrollView.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
  return super.postDelayed(WXThread.secure(action), delayMillis);
}