Ejemplo n.º 1
0
  /**
   * 递归构建GroupView
   *
   * @param group
   */
  private void buildGroupView(Group group) {
    if (group == null) {
      return;
    }
    List<Group> groups = group.getGroups();
    if (groups != null && groups.size() != 0) {
      for (Group g : groups) {
        String oritentation = g.getOrientation();
        View groupView = null;
        int childCount;
        if (oritentation.equals(BasicView.HORIZONTAL)) {
          HorizontalGroupView hGroupView =
              new HorizontalGroupView(context, g, flipperPageView, this);
          childCount = hGroupView.getFrameLayout().getChildCount();
          groupView = hGroupView;

        } else {
          GroupView2 vGroupView = new GroupView2(context, g, flipperPageView, this);
          childCount = vGroupView.getFrameLayout().getChildCount();
          groupView = vGroupView;
        }
        // 如果Group里只有嵌套的Group子控件则不添加到PageView里
        if (childCount != 0) {
          String frame = g.getFrame();
          int[] frames = FrameUtil.frame2int(frame);
          // 如果该层Group覆盖了整个屏幕,那么就将该Group下的子控件添加到该Group下
          if (getBigGroupView() != null) {
            ((GroupView2) getBigGroupView()).getFrameLayout().addView(groupView);
          } else {
            getFrameLayout().addView(groupView);
          }
          if (frames[0] == 0
              && frames[1] == 0
              && frames[2] >= 1024
              && frames[3] >= 768
              && oritentation.equals(BasicView.VERTICAL)) {
            setBigGroupView(groupView);
          }
          groupViewList.add(groupView);
        } else {
          groupView = null;
        }
        List<Group> groups_ = g.getGroups();
        if (groups_ != null && groups_.size() != 0) {
          for (Group g_ : groups_) {
            buildGroupView(g_);
          }
        }
      }
    } else {
      if (firstGroup != group) {
        List<Hot> hots = group.getHots();
        List<Picture> pictures = group.getPictures();
        List<Layer> layers = group.getLayers();
        List<Animation> animations = group.getAnimations();
        List<Video> videos = group.getVideos();
        List<PictureSet> pictureSets = group.getPictureSets();
        List<Slider> sliders = group.getSliders();
        List<Shutter> shutters = group.getShutters();
        if (hots.size() != 0
            || layers.size() != 0
            || animations.size() != 0
            || videos.size() != 0
            || pictureSets.size() != 0
            || pictures.size() != 0
            || sliders.size() != 0
            || shutters.size() != 0) {
          View groupView = null;
          String oritentation = group.getOrientation();
          if (oritentation.equals(BasicView.HORIZONTAL)) {
            groupView = new HorizontalGroupView(context, group, flipperPageView, this);
          } else {
            groupView = new GroupView2(context, group, flipperPageView, this);
          }
          if (getBigGroupView() != null) {
            View bigGroupView = getBigGroupView();
            if (bigGroupView instanceof HorizontalGroupView) {
              ((HorizontalGroupView) bigGroupView).getFrameLayout().addView(groupView);
            } else if (bigGroupView instanceof GroupView2) {
              ((GroupView2) bigGroupView).getFrameLayout().addView(groupView);
            }
          } else {
            getFrameLayout().addView(groupView);
          }
          groupViewList.add(groupView);
        }
      }
    }
  }
Ejemplo n.º 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);
                 }
               }
             }
           }
         }
       }
     }
   }
 }