Java Code Examples for com.taobao.weex.WXEnvironment#isApkDebugable()

The following examples show how to use com.taobao.weex.WXEnvironment#isApkDebugable() . 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: WXLogUtils.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public static void d(String tag, String msg) {
  if (WXEnvironment.isApkDebugable() && !TextUtils.isEmpty(msg) && WXEnvironment.sLogLevel.compare(LogLevel.DEBUG) >= 0) {
    msg = getLineNumber() + msg;
    Log.d(tag, msg);
    /** This log method will be invoked from jni code, so try to extract loglevel from message. **/
    writeConsoleLog("debug", tag + ":" + msg);
    if(msg.contains(" | __")){
      String[] msgs=msg.split(" | __");
      LogLevel level;
      if( msgs!=null && msgs.length==4 && !TextUtils.isEmpty(msgs[0]) && !TextUtils.isEmpty(msgs[2])){
        level=getLogLevel(msgs[2]);
        sendLog(level,msgs[0]);
        return;
      }
    }
    sendLog(LogLevel.DEBUG, tag + ":" + msg);
  }
}
 
Example 2
Source File: WXRenderStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
WXComponent createBodyOnDomThread(WXDomObject dom) {
  if (mWXSDKInstance == null) {
    return null;
  }
  WXDomObject domObject = new WXDomObject();
  domObject.type = WXBasicComponentType.DIV;
  domObject.ref = "god";
  mGodComponent = (WXVContainer) WXComponentFactory.newInstance(mWXSDKInstance, domObject, null);
  mGodComponent.createView(null, -1);
  if (mGodComponent == null) {
    if (WXEnvironment.isApkDebugable()) {
      WXLogUtils.e("rootView failed!");
    }
    //TODO error callback
    return null;
  }
  FrameLayout frameLayout = (FrameLayout) mGodComponent.getView();
  ViewGroup.LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  frameLayout.setLayoutParams(layoutParams);
  frameLayout.setBackgroundColor(Color.TRANSPARENT);

  WXComponent component = generateComponentTree(dom, mGodComponent);
  mGodComponent.addChild(component);
  mRegistry.put(component.getRef(), component);
  return component;
}
 
Example 3
Source File: WXBridge.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * JavaScript uses this methods to call Android code
 * @param instanceId
 * @param ref
 * @param event
 * @param callback
 * @return int
 */
public int callAddEvent(String instanceId, String ref, String event, String callback) {
  long start = System.currentTimeMillis();
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if(instance != null) {
    instance.firstScreenCreateInstanceTime(start);
  }
  int errorCode = IWXBridge.INSTANCE_RENDERING;
  try {
    errorCode = WXBridgeManager.getInstance().callAddEvent(instanceId, ref, event, callback);
  } catch (Throwable e) {
    //catch everything during call native.
    if(WXEnvironment.isApkDebugable()){
      WXLogUtils.e(TAG,"callAddEvent throw exception:" + e.getMessage());
    }
  }
  if(instance != null) {
    instance.callNativeTime(System.currentTimeMillis() - start);
  }
  return errorCode;
}
 
Example 4
Source File: WXCirclePageAdapter.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
  View pageView = null;
  try {
    pageView = shadow.get(position);
    if (WXEnvironment.isApkDebugable()) {
      WXLogUtils.d("onPageSelected >>>> instantiateItem >>>>> position:" + position + ",position % getRealCount()" + position % getRealCount());
    }
    if (pageView.getParent() == null) {
      container.addView(pageView);
    } else {
      ((ViewGroup) pageView.getParent()).removeView(pageView);
      container.addView(pageView);
    }
  } catch (Exception e) {
    WXLogUtils.e("[CirclePageAdapter] instantiateItem: ", e);
  }
  return pageView;
}
 
Example 5
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void destroy() {
  ComponentObserver observer;
  if ((observer = getInstance().getComponentObserver()) != null) {
    observer.onPreDestory(this);
  }

  if (WXEnvironment.isApkDebugable() && !WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXComponent] destroy can only be called in main thread");
  }
  if(mHost!= null && mHost.getLayerType()==View.LAYER_TYPE_HARDWARE && isLayerTypeEnabled()) {
    mHost.setLayerType(View.LAYER_TYPE_NONE, null);
  }
  removeAllEvent();
  removeStickyStyle();

  View view;
  if(mDomObj.isFixed() && (view = getHostView()) != null){
    getInstance().removeFixedView(view);
  }

  mDomObj = ImmutableDomObject.DESTROYED;
  mIsDestroyed = true;
}
 
Example 6
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public int callUpdateFinish(String instanceId, String callback) {
  if (WXEnvironment.isApkDebugable()) {
    mLodBuilder.append("[WXBridgeManager] callUpdateFinish >>>> instanceId:").append(instanceId)
            .append(", callback:").append(callback);
    WXLogUtils.d(mLodBuilder.substring(0));
    mLodBuilder.setLength(0);
  }

  if(mDestroyedInstanceId != null && mDestroyedInstanceId.contains(instanceId)){
    return IWXBridge.DESTROY_INSTANCE;
  }

  try {
    if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
      WXDomModule domModule = getDomModule(instanceId);
      Action action = Actions.getUpdateFinish();
      domModule.postAction((DOMAction)action, false);
    }
  } catch (Exception e) {
    WXLogUtils.e("[WXBridgeManager] callUpdateFinish exception: ", e);
    commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callUpdateFinish exception "+e.getCause());
  }

  if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) {
    return IWXBridge.INSTANCE_RENDERING_ERROR;
  }
  // get next tick
  getNextTick(instanceId, callback);
  return IWXBridge.INSTANCE_RENDERING;
}
 
Example 7
Source File: ExtendedStaggeredGridLayoutManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount) {
  if(positionStart ==-1){
    WXLogUtils.e("ExtendedStaggeredGridLayoutManager: onItemsRemoved  Error Invalid Index : positionStart :"+positionStart +"  itemCount:"+ itemCount);
    return ;
  }else {
    if(WXEnvironment.isApkDebugable()){
      WXLogUtils.e("ExtendedStaggeredGridLayoutManager: onItemsRemoved  positionStart :"+positionStart+"  itemCount:"+ itemCount);
    }
  }
  super.onItemsRemoved(recyclerView, positionStart, itemCount);
}
 
Example 8
Source File: WXLogUtils.java    From weex with Apache License 2.0 5 votes vote down vote up
public static void renderPerformanceLog(String type, long time) {
  if (WXEnvironment.isApkDebugable() || WXEnvironment.isPerf()) {
    builder.setLength(0);
    builder.append("[render time]").append(type).append(":").append(time);
    Log.d(WEEX_PERF_TAG, builder.substring(0));
    writeConsoleLog("debug", builder.substring(0));
  }
}
 
Example 9
Source File: WXCirclePageAdapter.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void removePageView(View view) {
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.d("onPageSelected >>>> removePageView");
  }
  views.remove(view);
  ensureShadow();
}
 
Example 10
Source File: WXLogUtils.java    From weex with Apache License 2.0 5 votes vote down vote up
public static void w(String tag, String msg) {
  if (WXEnvironment.isApkDebugable() && msg != null) {
    Log.w(tag, msg);
    writeConsoleLog("warning", tag + ":" + msg);
  }
  sendLog(LogLevel.WARN, tag+":"+msg);
}
 
Example 11
Source File: WXStreamModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onHttpFinish(final WXResponse response) {
  //compatible with old sendhttp
  if(mCallback!=null){
    mCallback.onResponse(response, mRespHeaders);
  }

  if(WXEnvironment.isApkDebugable()){
    WXLogUtils.d("WXStreamModule",response!=null && response.originalData!=null?new String(response.originalData):"response data is NUll!");
  }
}
 
Example 12
Source File: WXDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void removeFromDom(WXDomObject child) {
  if (child == null || mDomChildren == null || sDestroy.get()) {
    return;
  }

  int index = mDomChildren.indexOf(child);
  if (index == -1) {
    if (WXEnvironment.isApkDebugable()) {
      WXLogUtils.e("[WXDomObject] remove function error");
    }
    return;
  }
  mDomChildren.remove(index).parent = null;
}
 
Example 13
Source File: WXJsonUtils.java    From weex with Apache License 2.0 5 votes vote down vote up
public static String fromObjectToJSONString(Object obj) {
  try {
    return JSONObject.toJSONString(obj);
  }catch(Exception e){
    if(WXEnvironment.isApkDebugable()){
      throw new WXRuntimeException("fromObjectToJSONString parse error!");
    }
    WXLogUtils.e("fromObjectToJSONString error:"+e.getMessage());
    return "{}";
  }

}
 
Example 14
Source File: WXBridge.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * JSF render Node by callAddElement
 */
public int callAddElement(String instanceId, String ref,String dom,String index, String callback) {

  long start = System.currentTimeMillis();
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if(instance != null) {
    instance.firstScreenCreateInstanceTime(start);
  }
  int errorCode = IWXBridge.INSTANCE_RENDERING;

  try {
    errorCode = WXBridgeManager.getInstance().callAddElement(instanceId, ref,dom,index, callback);
  }catch (Throwable e){
    //catch everything during call native.
    if(WXEnvironment.isApkDebugable()){
      e.printStackTrace();
      WXLogUtils.e(TAG,"callNative throw error:"+e.getMessage());
    }
  }

  if(instance != null) {
    instance.callNativeTime(System.currentTimeMillis() - start);
  }
  if(WXEnvironment.isApkDebugable()){
    if(errorCode == IWXBridge.DESTROY_INSTANCE){
      WXLogUtils.w("destroyInstance :"+instanceId+" JSF must stop callNative");
    }
  }
  return errorCode;
}
 
Example 15
Source File: WXLogUtils.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private static void writeConsoleLog(String level, String message) {
  if (WXEnvironment.isApkDebugable()) {
    try {
      Class<?> clazz = clazzMaps.get(CLAZZ_NAME_LOG_UTIL);
      if (clazz != null) {
        Method m = clazz.getMethod("log", String.class, String.class);
        m.invoke(clazz, level, message);
      }
    } catch (Exception e) {
      Log.d(WEEX_TAG, "LogUtil not found!");
    }
  }
}
 
Example 16
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Update all components' dom info stored in {@link #mAddDom}
 */
private void updateDomObj() {
  long start = System.currentTimeMillis();
  Iterator<Map.Entry<String, AddDomInfo>> iterator = mAddDom.entrySet().iterator();
  Map.Entry<String, AddDomInfo> entry;
  AddDomInfo value;
  while (iterator.hasNext()) {
    entry = iterator.next();
    value = entry.getValue();
    updateDomObj(value.component);
  }
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.d("updateDomObj", "time:" + (System.currentTimeMillis() - start));
  }
}
 
Example 17
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onFailedToRecycleView(ListBaseViewHolder holder) {
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.d(TAG, "Failed to recycle " + holder);
  }
  return false;
}
 
Example 18
Source File: WXLogUtils.java    From weex with Apache License 2.0 4 votes vote down vote up
public static void p(String msg) {
  if (WXEnvironment.isApkDebugable() && msg != null) {
    Log.d(WEEX_PERF_TAG, msg);
    writeConsoleLog("debug", msg);
  }
}
 
Example 19
Source File: WXDomManager.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
private boolean isDomThread() {
  return !WXEnvironment.isApkDebugable() || Thread.currentThread().getId() == mDomThread.getId();
}
 
Example 20
Source File: WXLogUtils.java    From weex-uikit with MIT License 4 votes vote down vote up
public static void w(String prefix, Throwable e) {
  if (WXEnvironment.isApkDebugable()) {
    w(prefix + getStackTrace(e));
  }
}