Example #1
0
  public CustVideoView(final Context context, Video video) {
    super(context);
    this.context = context;
    this.setVideo(video);
    String frame = video.getFrame();
    String closesOnEnd = video.getClosesOnEnd();
    if (closesOnEnd != null && closesOnEnd.equalsIgnoreCase("true")) {
      autoClose = true;
    }
    fullscreen = video.getFullscreen();
    FrameLayout.LayoutParams params;
    int[] frames = FrameUtil.frame2int(frame);
    frames = FrameUtil.autoAdjust(frames, context);
    // 全屏模式
    if (fullscreen.equalsIgnoreCase("true")) {
      act = (Activity) context;
      Display display = act.getWindowManager().getDefaultDisplay();
      int width = display.getWidth();
      int height = display.getHeight();
      params = new FrameLayout.LayoutParams(width, height);
      params.topMargin = 0;
      params.leftMargin = 0;
      setMeasuredDimension(width, height);
    } else {
      params = new FrameLayout.LayoutParams(frames[2], frames[3]);
      params.setMargins(frames[0], frames[1], 0, 0);
    }
    setLayoutParams(params);
    String path = AppConfigUtil.getAppResource(AppConfigUtil.MAGAZINE_ID) + video.getResource();
    setVideoPath(path);
    setVisibility(View.VISIBLE);
    setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer mp) {
            MagazineActivity act = (MagazineActivity) context;
            act.getvControllers().remove(this);
            if (autoClose) {
              setVisibility(View.INVISIBLE);
              showLayers();
            }
          }
        });
    setOnClickListener(this);
  }
Example #2
0
 /**
  * 上下滑动时资源的回收和加载,加载上中下3屏的图片资源,其余释放
  *
  * @param Y
  * @param childCount
  */
 protected void loadResource(int Y, int childCount) {
   int minY = Y - UNIT;
   int maxY = Y + UNIT * 2;
   for (int i = 0; i < childCount; i++) {
     View childView = getFrameLayout().getChildAt(i);
     if (childView instanceof FirstGroupView) {
       FirstGroupView firstGroupView = (FirstGroupView) childView;
       int childCount2 = firstGroupView.getChildCount();
       for (int j = 0; j < childCount2; j++) {
         View view = firstGroupView.getChildAt(j);
         if (view instanceof PictureView) {
           PictureView pictureView = (PictureView) view;
           LayoutParams params = (LayoutParams) pictureView.getLayoutParams();
           if (minY <= params.topMargin && params.topMargin < maxY) { // 加载FirstGroupView资源
             if (!pictureView.isLoad()) {
               Picture picture = pictureView.getPicture();
               if (picture != null) {
                 String resource = picture.getResource();
                 String imgPath =
                     AppConfigUtil.getAppResourceImage(AppConfigUtil.MAGAZINE_ID, resource);
                 Bitmap bitmap = ImageUtil.loadImage(imgPath);
                 pictureView.setImageBitmap(bitmap);
                 pictureView.setScaleType(ScaleType.FIT_XY);
               }
             }
           } else { // 释放FirstGroupView资源,如果只有一张底图,将不释放资源
             Group group = pictureView.getGroup();
             List<Picture> pictures = group.getPictures();
             if (pictures.size() >= 2) {
               ImageUtil.recycle(pictureView);
             }
           }
         }
       }
     } else if (childView instanceof GroupView2) {
       GroupView2 groupView = (GroupView2) childView;
       LayoutParams params = (LayoutParams) groupView.getLayoutParams();
       if (minY <= params.topMargin && params.topMargin < maxY) { // 加载GroupView资源
         FrameLayout frameLayout = groupView.getFrameLayout();
         int childCount2 = frameLayout.getChildCount();
         for (int j = 0; j < childCount2; j++) {
           View view = frameLayout.getChildAt(j);
           if (view instanceof PictureView) {
             PictureView pictureView = (PictureView) view;
             if (!pictureView.isLoad()) {
               Picture picture = pictureView.getPicture();
               if (picture != null) {
                 String resource = picture.getResource();
                 if (resource != null) {
                   String imgPath =
                       AppConfigUtil.getAppResourceImage(AppConfigUtil.MAGAZINE_ID, resource);
                   Bitmap bitmap = ImageUtil.loadImage(imgPath);
                   pictureView.setImageBitmap(bitmap);
                   pictureView.setScaleType(ScaleType.FIT_XY);
                 }
               }
             }
           }
         }
       } else { // 释放GroupView资源
         FrameLayout frameLayout = groupView.getFrameLayout();
         int childCount2 = frameLayout.getChildCount();
         for (int j = 0; j < childCount2; j++) {
           View view = frameLayout.getChildAt(j);
           if (view instanceof PictureView) {
             PictureView pictureView = (PictureView) view;
             ImageUtil.recycle(pictureView);
           }
         }
       }
     } else if (childView instanceof HorizontalGroupView) {
       HorizontalGroupView hGroupView = (HorizontalGroupView) childView;
       LayoutParams hparams = (LayoutParams) hGroupView.getLayoutParams();
       if (minY <= hparams.topMargin && hparams.topMargin < maxY) { // 加载GroupView资源
         FrameLayout frameLayout = hGroupView.getFrameLayout();
         int childCount2 = frameLayout.getChildCount();
         for (int j = 0; j < childCount2; j++) {
           View view = frameLayout.getChildAt(j);
           if (view instanceof PictureView) {
             PictureView pictureView = (PictureView) view;
             if (!pictureView.isLoad()) {
               Picture picture = pictureView.getPicture();
               if (picture != null) {
                 String resource = picture.getResource();
                 if (resource != null) {
                   String imgPath =
                       AppConfigUtil.getAppResourceImage(AppConfigUtil.MAGAZINE_ID, resource);
                   Bitmap bitmap = ImageUtil.loadImage(imgPath);
                   pictureView.setImageBitmap(bitmap);
                   pictureView.setScaleType(ScaleType.FIT_XY);
                 }
               }
             }
           }
         }
       }
     }
   }
 }