public String getStoryId() {
   BoxStory tag = (BoxStory) getTag();
   if (tag != null) {
     return tag.getStoryId();
   }
   return "";
 }
 private int generateBoxIdFromSectionId(BoxStory boxStory) {
   int id = (int) (ID_SET_VIDEOSECIONBOX_ID + ((new Random().nextInt(4000)) + 1));
   try {
     id = Integer.parseInt(boxStory.getStoryId());
   } catch (NumberFormatException e) {
   }
   return id;
 }
  private void setBoxStory(BoxStory boxStory) {
    GKIMLog.lf(this.getContext(), 0, TAG + "=>setBoxStory.");
    if (boxStory != null) {
      int storyLayout = boxStory.getLayout();
      mNumberOfColumn =
          (mBoxLayoutIndex > 1)
              ? 1
              : getResources().getInteger(R.integer.section_video_page_max_cols);
      mNumberOfRow = (mBoxLayoutIndex > 0) ? 1 : 2;
      // mStoryBoxWidth = boxStory.getBoxStoryWidth();
      // mStoryBoxHeight = boxStory.getBoxStoryHeight();
      GKIMLog.l(1, TAG + " setBoxStory :" + boxStory.getStoryId());
      boolean hasImage = false;
      boolean hasTitle = false;
      boolean hasShortCont = false;
      mFavorited = boxStory.isFavourited();
      mVideoIcon = boxStory.getVideo() > 0 ? true : false;

      if (boxStory.hasElementType(BoxElement.BOXELEMENT_TYPE_IMAGE)) {
        mImage = (ImageView) this.findViewById(R.id.boxview_image);
        if (mImage != null) {
          BoxElement[] imageBoxes = boxStory.getBoxElementbyType(BoxElement.BOXELEMENT_TYPE_IMAGE);
          if (imageBoxes != null) {
            BoxElement elm = imageBoxes[0];
            // NOTE: start loading from ImageFetcher
            // use only 1 time when setBoxStory.
            ImageLoader.getInstance().displayImage(elm.getContent(), mImage);
            if (mBoxLayoutIndex == 0) {
              elm.setAlignmentInBox(7);
              elm.setWidthCell(2);
            } else if (mBoxLayoutIndex == 1) {
              elm.setAlignmentInBox(-1);
              elm.setWidthCell(1);
            } else {
              elm.setAlignmentInBox(7);
              elm.setWidthCell(1);
            }
            applyRules(mImage, elm);
            mImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
          }
          hasImage = true;
        } else {
          GKIMLog.lf(this.getContext(), 4, TAG + "=>setBoxStory failed on find ImageView.");
        }
      } else {
        mNeedBackground = true;
        if (mBoxLayoutIndex == 1) {
          mNeedBackground = false;
          mImage = (ImageView) this.findViewById(R.id.boxview_image);
          mImage.setImageResource(R.drawable.ic_launcher);
          if (mImage != null) {
            BoxElement elm = new BoxElement();
            elm.setAlignmentInBox(-1);
            elm.setWidthCell(1);
            applyRules(mImage, elm);
            hasImage = true;
            mImage.setVisibility(INVISIBLE);
          }
        }
      }
      if (boxStory.hasElementType(BoxElement.BOXELEMENT_TYPE_SHORTCONTENT)) {
        mShortContent = (TextView) this.findViewById(R.id.boxview_shortcontent);
        if (mShortContent != null) {
          BoxElement[] shortTextElms =
              boxStory.getBoxElementbyType(BoxElement.BOXELEMENT_TYPE_SHORTCONTENT);
          if (shortTextElms != null) {
            BoxElement elm = shortTextElms[0];
            mShortContent.setTextColor(elm.getTextColor());
            // Note: tweak text size on xmls
            // mShortContent.setTextSize(elm.getTextSize());
            mShortContent.setTextSize(
                getResources().getDimensionPixelSize(R.dimen.section_box_title_textsize));
            mShortContent.setTypeface(
                UIUtils.getDefaultTypeFace(this.getContext().getApplicationContext(), 0),
                elm.getTextType());
            mShortContent.setText(elm.getContent());

            applyRules(mShortContent, elm);
            hasShortCont = true;
          }
        } else {
          GKIMLog.lf(this.getContext(), 4, TAG + "=>setBoxStory failed on find short TextView.");
        }
      }
      if (boxStory.hasElementType(BoxElement.BOXELEMENT_TYPE_TITLE)) {
        if (mTitle != null) {
          BoxElement[] titleElms = boxStory.getBoxElementbyType(BoxElement.BOXELEMENT_TYPE_TITLE);
          if (titleElms != null) {
            BoxElement elm = titleElms[0];
            mTitle.setTextSize(
                getResources().getDimensionPixelSize(R.dimen.section_boxvideo_title_textsize));
            mTitle.setTypeface(
                UIUtils.getDefaultTypeFace(this.getContext().getApplicationContext(), 0),
                elm.getTextType());
            // Fix: don't change color text when user read
            if (mReadBox) {
              mTitle.setTextColor(getResources().getColor(R.color.box_hasread_textcolor));
            } else {
              mTitle.setTextColor(elm.getTextColor());
            }
            if (mBoxLayoutIndex == 1) {
              elm.setWidthCell(1);
              elm.setAlignmentInBox(8);
            } else {
              elm.setAlignmentInBox(6);
            }
            applyRules(mLLTitle, elm);
            String title = elm.getContent();
            mTitle.setText(title);
            hasTitle = true;

            float textSize = TNPreferenceManager.getTextSizeBoxView();
            if (mBoxLayoutIndex == 0) {
              if (textSize > 0) {
                mTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 1.25f);
              }
            } else if (mBoxLayoutIndex == 1) {
              if (textSize > 0) {
                mTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 1.125f);
              }
            } else {
              if (textSize > 0) {
                mTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
              }
            }

            // - getResources()
            // .getInteger(
            // R.integer.extract_txt_size_height

            adjustTextLength(mTitle);
            updatelayoutIconVideo();
          }
        } else {
          GKIMLog.lf(this.getContext(), 4, TAG + "=>setBoxStory failed on find title TextView.");
        }
      }

      mLLTitle.setBackgroundColor(boxStory.getBackground1Color());
      this.setBackgroundColor(boxStory.getBackground1Color());
      // finally update the boxView's size
      GKIMLog.lf(
          this.getContext(),
          5,
          TAG
              + "=>setBoxStory, type: "
              + storyLayout
              + ", row: "
              + mNumberOfRow
              + ", col: "
              + mNumberOfColumn
              + ", with "
              + (hasImage ? "imgage, " : "")
              + (hasTitle ? "title, " : "")
              + (hasShortCont ? "short content." : ""));
      setId(generateBoxIdFromSectionId(boxStory));
      this.setTag(boxStory);
    }
  }