/**
   * 具体的转屏执行函数--使用父窗口方式
   *
   * @param container
   * @param isFullScreen
   */
  private void setIsFullModeUsingContainer(ViewGroup container, boolean isFullScreen) {
    if (container == null) {
      VDLog.e(VDVideoFullModeController.TAG, "videoview---setIsFullMode---container--return null");
      throw new IllegalArgumentException("container is null");
    }
    if (mVideoViewParams == null) {
      VDLog.e(
          VDVideoFullModeController.TAG,
          "videoview---setIsFullMode---mVideoViewParams--return null");
      mVideoViewParams = getLayoutParams();
    }
    mVideoView.beginChangeParentView();

    if (mVideoFullScreenContainer != null) {
      mVideoFullScreenContainer.removeAllViews();
    }

    if (mVideoFullScreenContainer.getParent() == null) {
      changeToRoot(mVideoFullScreenContainer);
    }
    VDVideoViewController controller = VDVideoViewController.getInstance(mContext);
    if (controller != null) {
      controller.notifyScreenOrientationSwitch(isFullScreen);
      if (mVideoView.isPlaying()) {
        controller.notifyOnShowHideADContainer(true);
      }
    }
    if (isFullScreen) {
      if (mExternalFullScreenContainer != null) {
        mExternalFullScreenContainer.setVisibility(VISIBLE);
      }
      // 横屏
      VDVideoScreenOrientation.setStatusBarVisible(mContext, true);
      mVideoFullScreenContainer.setVisibility(View.VISIBLE);

      container.removeView(this);
      mVideoFullScreenContainer.addView(
          this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    } else {
      if (mExternalFullScreenContainer != null) {
        mExternalFullScreenContainer.setVisibility(GONE);
      }
      VDVideoScreenOrientation.setStatusBarVisible(mContext, false);
      mVideoFullScreenContainer.setVisibility(View.GONE);
      // 竖屏
      if (getParent() == null) {
        container.addView(this, mVideoViewParams);
      }
    }
    for (VDVideoViewLayerContext item : mVDVideoViewLayerData.getLayerList()) {
      if (item.mIsComplexLayerType) {
        // 有复杂模式才进行横竖屏转换
        if (controller != null) item.setFullMode(isFullScreen, controller.isInsertAD());
      }
    }
    mVideoView.endChangeParentView();
    mVideoView.requestVideoLayout();
  }
 @Override
 public void onVideoUIRefresh() {
   // TODO Auto-generated method stub
   VDVideoViewController controller = VDVideoViewController.getInstance(mContext);
   if (controller == null) {
     return;
   }
   for (VDVideoViewLayerContext layerContext : mVDVideoViewLayerData.getLayerList()) {
     layerContext.refresh(controller.isInsertAD());
   }
 }
 /** 初始化屏幕部分,保证横屏进入正常 */
 public void initVideo() {
   // 全屏容器
   boolean isFullScreen = false;
   // @sunxiao1 modify ,加入只横不竖方式,直接横屏设置过去
   if (VDVideoScreenOrientation.getIsLandscape(mContext)
       || mVDVideoViewLayerData.getLayerType()
           == VDVideoViewLayerContextData.LAYER_COMPLEX_NOVERTICAL) {
     isFullScreen = true;
   }
   setIsFullScreen(isFullScreen, true);
   VDVideoFullModeController.getInstance().setIsFullScreen(isFullScreen);
   // 设置音量部分
   for (VDVideoViewLayerContext context : mVDVideoViewLayerData.getLayerList()) {
     if (context.checkSoundWidget()) {
       VDVideoViewController controller = VDVideoViewController.getInstance(mContext);
       if (controller != null) controller.mIsHasSoundWidget = true;
       break;
     }
   }
 }
  /**
   * 从layerAttrs属性中加载相应的layer,支持两种格式: 1、直接使用@layer方式组装数组 2、使用@array方式做二维数组方式
   *
   * @param context
   * @param attrs
   */
  private void readLayerAttrs(int resID) {
    // 将resourceID指向的数组加载到内存中,一般为:
    // 复杂模式:
    // <array name="sv_videoview_layers">
    // <item>@array/sv_videoview_layer_adlayer</item>
    // <item>@array/sv_videoview_layer_controllayer</item>
    // </array>
    // 或者,简单模式:
    // <array name="sina_video_videoview_layers">
    // <item>@layout/ad_layer</item>
    // <item>@layout/control_layer</item>
    // </array>
    // 格式
    TypedArray layerTypedArr = getResources().obtainTypedArray(resID);
    LayoutInflater inflater =
        (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // obtainStyledAttributes而来的数组使用getIndexCount方法取得数量
    // obtainTypedArray得到的数组使用length来得到数量
    int complexNoHorizonLayerNum = 0;
    for (int j = 0; j < layerTypedArr.length(); j++) {
      int resID2 = -1;
      resID2 = layerTypedArr.getResourceId(j, -1);

      if (resID2 == -1) {
        if (layerTypedArr != null) layerTypedArr.recycle();
        throw new IllegalArgumentException("resID2=-1");
      }

      String type = getResources().getResourceTypeName(resID2);
      if (type.equals("layout")) {
        // 简单模式
        VDVideoViewLayer layer = (VDVideoViewLayer) inflater.inflate(resID2, null);
        // 添加进入当前容器
        addView(layer, false);
        // 保存引用
        VDVideoViewLayerContext item = new VDVideoViewLayerContext();
        // 默认就是竖屏的
        layer.mIsVertical = true;
        item.addSimpleItem(layer);
        mVDVideoViewLayerData.addLayerContext(item);

      } else if (type.equals("array")) {
        // 复杂模式
        TypedArray orientationLayerArr = getResources().obtainTypedArray(resID2);
        if (orientationLayerArr.length() != 2) {
          if (layerTypedArr != null) layerTypedArr.recycle();
          if (orientationLayerArr != null) {
            orientationLayerArr.recycle();
          }
          throw new IllegalArgumentException("使用布局数组的情况下,一个数组只能容纳两个layer");
        }

        VDVideoViewLayerContext item = new VDVideoViewLayerContext();
        for (int k = 0; k < orientationLayerArr.length(); k++) {
          int resID3 = orientationLayerArr.getResourceId(k, -1);
          // 复杂模式下,无论何种情况,都要求有两个默认的layer在其中
          VDVideoViewLayer layer = new VDVideoViewLayer(mContext);
          if (resID3 == -1) {
            if (k == 1) {
              // 只允许只横不竖,那么只有竖屏,也就是k=0的时候,可以为-1,其他情况判错
              if (layerTypedArr != null) layerTypedArr.recycle();
              if (orientationLayerArr != null) {
                orientationLayerArr.recycle();
              }
              throw new IllegalArgumentException("resID3=-1");
            }
            complexNoHorizonLayerNum++;
          } else {
            layer = (VDVideoViewLayer) inflater.inflate(resID3, this, false);
          }
          boolean isGone = getIsFullMode(k);
          // 添加进入当前容器
          layer.mIsVertical = !isGone;
          addView(layer, isGone);
          // 保存引用
          item.addComplexItem(layer);
          // 判断是否是广告层
          if (layer instanceof VDVideoADLayer) {
            item.mIsInsertADLayer = true;
          }
        }
        mVDVideoViewLayerData.addLayerContext(item);
        orientationLayerArr.recycle();
      } else {
        throw new IllegalArgumentException("加入的类型错误");
      }
    }
    layerTypedArr.recycle();

    int simpleLayerNum = 0;
    int complexLayerNum = 0;

    for (VDVideoViewLayerContext value : mVDVideoViewLayerData.getLayerList()) {
      if (value.mComplexLayer.size() != 0) {
        complexLayerNum++;
      }
      if (value.mSimpleLayer != null) {
        simpleLayerNum++;
      }
    }
    if (simpleLayerNum == 0 && complexLayerNum == 0) {
      // 空的,直接返回错误
      throw new IllegalArgumentException("layout为空");
    } else if (simpleLayerNum != 0 && complexLayerNum != 0) {
      throw new IllegalArgumentException("简单模式、复杂模式只能二选一");
    } else if (simpleLayerNum != 0) {
      mVDVideoViewLayerData.setLayerType(VDVideoViewLayerContextData.LAYER_SIMPLE);
    } else if (complexLayerNum != 0) {
      if (complexNoHorizonLayerNum == complexLayerNum) {
        mVDVideoViewLayerData.setLayerType(VDVideoViewLayerContextData.LAYER_COMPLEX_NOVERTICAL);
      } else {
        mVDVideoViewLayerData.setLayerType(VDVideoViewLayerContextData.LAYER_COMPLEX_ALL);
      }
    }
    VDVideoViewController controller = VDVideoViewController.getInstance(mContext);
    if (controller != null) controller.setLayerContextData(mVDVideoViewLayerData);
  }
 /**
  * 当前所有的layer显示与关闭
  *
  * @deprecated 不要再使用,后期会关闭此方法
  * @param isGone
  */
 public void setLayersVisiblity(boolean isGone) {
   for (VDVideoViewLayerContext item : mVDVideoViewLayerData.getLayerList()) {
     item.setVisibility(isGone);
   }
 }