com.google.android.exoplayer2.text.Cue.AnchorType Java Examples

The following examples show how to use com.google.android.exoplayer2.text.Cue.AnchorType. 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: Cea708Decoder.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
public Cea708Cue build() {
  if (isEmpty()) {
    // The cue is empty.
    return null;
  }

  SpannableStringBuilder cueString = new SpannableStringBuilder();

  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildSpannableString());

  // TODO: Add support for right-to-left languages (i.e. where right would correspond to normal
  // alignment).
  Alignment alignment;
  switch (justification) {
    case JUSTIFICATION_FULL:
      // TODO: Add support for full justification.
    case JUSTIFICATION_LEFT:
      alignment = Alignment.ALIGN_NORMAL;
      break;
    case JUSTIFICATION_RIGHT:
      alignment = Alignment.ALIGN_OPPOSITE;
      break;
    case JUSTIFICATION_CENTER:
      alignment = Alignment.ALIGN_CENTER;
      break;
    default:
      throw new IllegalArgumentException("Unexpected justification value: " + justification);
  }

  float position;
  float line;
  if (relativePositioning) {
    position = (float) horizontalAnchor / RELATIVE_CUE_SIZE;
    line = (float) verticalAnchor / RELATIVE_CUE_SIZE;
  } else {
    position = (float) horizontalAnchor / HORIZONTAL_SIZE;
    line = (float) verticalAnchor / VERTICAL_SIZE;
  }
  // Apply screen-edge padding to the line and position.
  position = (position * 0.9f) + 0.05f;
  line = (line * 0.9f) + 0.05f;

  // anchorId specifies where the anchor should be placed on the caption cue/window. The 9
  // possible configurations are as follows:
  //   0-----1-----2
  //   |           |
  //   3     4     5
  //   |           |
  //   6-----7-----8
  @AnchorType int verticalAnchorType;
  if (anchorId % 3 == 0) {
    verticalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId % 3 == 1) {
    verticalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    verticalAnchorType = Cue.ANCHOR_TYPE_END;
  }
  // TODO: Add support for right-to-left languages (i.e. where start is on the right).
  @AnchorType int horizontalAnchorType;
  if (anchorId / 3 == 0) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId / 3 == 1) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    horizontalAnchorType = Cue.ANCHOR_TYPE_END;
  }

  boolean windowColorSet = (windowFillColor != COLOR_SOLID_BLACK);

  return new Cea708Cue(cueString, alignment, line, Cue.LINE_TYPE_FRACTION, verticalAnchorType,
      position, horizontalAnchorType, Cue.DIMEN_UNSET, windowColorSet, windowFillColor,
      priority);
}
 
Example #2
Source File: Cea708Decoder.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public Cea708Cue build() {
  if (isEmpty()) {
    // The cue is empty.
    return null;
  }

  SpannableStringBuilder cueString = new SpannableStringBuilder();

  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildSpannableString());

  // TODO: Add support for right-to-left languages (i.e. where right would correspond to normal
  // alignment).
  Alignment alignment;
  switch (justification) {
    case JUSTIFICATION_FULL:
      // TODO: Add support for full justification.
    case JUSTIFICATION_LEFT:
      alignment = Alignment.ALIGN_NORMAL;
      break;
    case JUSTIFICATION_RIGHT:
      alignment = Alignment.ALIGN_OPPOSITE;
      break;
    case JUSTIFICATION_CENTER:
      alignment = Alignment.ALIGN_CENTER;
      break;
    default:
      throw new IllegalArgumentException("Unexpected justification value: " + justification);
  }

  float position;
  float line;
  if (relativePositioning) {
    position = (float) horizontalAnchor / RELATIVE_CUE_SIZE;
    line = (float) verticalAnchor / RELATIVE_CUE_SIZE;
  } else {
    position = (float) horizontalAnchor / HORIZONTAL_SIZE;
    line = (float) verticalAnchor / VERTICAL_SIZE;
  }
  // Apply screen-edge padding to the line and position.
  position = (position * 0.9f) + 0.05f;
  line = (line * 0.9f) + 0.05f;

  // anchorId specifies where the anchor should be placed on the caption cue/window. The 9
  // possible configurations are as follows:
  //   0-----1-----2
  //   |           |
  //   3     4     5
  //   |           |
  //   6-----7-----8
  @AnchorType int verticalAnchorType;
  if (anchorId % 3 == 0) {
    verticalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId % 3 == 1) {
    verticalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    verticalAnchorType = Cue.ANCHOR_TYPE_END;
  }
  // TODO: Add support for right-to-left languages (i.e. where start is on the right).
  @AnchorType int horizontalAnchorType;
  if (anchorId / 3 == 0) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId / 3 == 1) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    horizontalAnchorType = Cue.ANCHOR_TYPE_END;
  }

  boolean windowColorSet = (windowFillColor != COLOR_SOLID_BLACK);

  return new Cea708Cue(cueString, alignment, line, Cue.LINE_TYPE_FRACTION, verticalAnchorType,
      position, horizontalAnchorType, Cue.DIMEN_UNSET, windowColorSet, windowFillColor,
      priority);
}
 
Example #3
Source File: Cea708Decoder.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public Cea708Cue build() {
  if (isEmpty()) {
    // The cue is empty.
    return null;
  }

  SpannableStringBuilder cueString = new SpannableStringBuilder();

  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildSpannableString());

  // TODO: Add support for right-to-left languages (i.e. where right would correspond to normal
  // alignment).
  Alignment alignment;
  switch (justification) {
    case JUSTIFICATION_FULL:
      // TODO: Add support for full justification.
    case JUSTIFICATION_LEFT:
      alignment = Alignment.ALIGN_NORMAL;
      break;
    case JUSTIFICATION_RIGHT:
      alignment = Alignment.ALIGN_OPPOSITE;
      break;
    case JUSTIFICATION_CENTER:
      alignment = Alignment.ALIGN_CENTER;
      break;
    default:
      throw new IllegalArgumentException("Unexpected justification value: " + justification);
  }

  float position;
  float line;
  if (relativePositioning) {
    position = (float) horizontalAnchor / RELATIVE_CUE_SIZE;
    line = (float) verticalAnchor / RELATIVE_CUE_SIZE;
  } else {
    position = (float) horizontalAnchor / HORIZONTAL_SIZE;
    line = (float) verticalAnchor / VERTICAL_SIZE;
  }
  // Apply screen-edge padding to the line and position.
  position = (position * 0.9f) + 0.05f;
  line = (line * 0.9f) + 0.05f;

  // anchorId specifies where the anchor should be placed on the caption cue/window. The 9
  // possible configurations are as follows:
  //   0-----1-----2
  //   |           |
  //   3     4     5
  //   |           |
  //   6-----7-----8
  @AnchorType int verticalAnchorType;
  if (anchorId % 3 == 0) {
    verticalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId % 3 == 1) {
    verticalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    verticalAnchorType = Cue.ANCHOR_TYPE_END;
  }
  // TODO: Add support for right-to-left languages (i.e. where start is on the right).
  @AnchorType int horizontalAnchorType;
  if (anchorId / 3 == 0) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId / 3 == 1) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    horizontalAnchorType = Cue.ANCHOR_TYPE_END;
  }

  boolean windowColorSet = (windowFillColor != COLOR_SOLID_BLACK);

  return new Cea708Cue(cueString, alignment, line, Cue.LINE_TYPE_FRACTION, verticalAnchorType,
      position, horizontalAnchorType, Cue.DIMEN_UNSET, windowColorSet, windowFillColor,
      priority);
}
 
Example #4
Source File: Cea708Decoder.java    From K-Sonic with MIT License 4 votes vote down vote up
public Cea708Cue build() {
  if (isEmpty()) {
    // The cue is empty.
    return null;
  }

  SpannableStringBuilder cueString = new SpannableStringBuilder();

  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildSpannableString());

  // TODO: Add support for right-to-left languages (i.e. where right would correspond to normal
  // alignment).
  Alignment alignment;
  switch (justification) {
    case JUSTIFICATION_FULL:
      // TODO: Add support for full justification.
    case JUSTIFICATION_LEFT:
      alignment = Alignment.ALIGN_NORMAL;
      break;
    case JUSTIFICATION_RIGHT:
      alignment = Alignment.ALIGN_OPPOSITE;
      break;
    case JUSTIFICATION_CENTER:
      alignment = Alignment.ALIGN_CENTER;
      break;
    default:
      throw new IllegalArgumentException("Unexpected justification value: " + justification);
  }

  float position;
  float line;
  if (relativePositioning) {
    position = (float) horizontalAnchor / RELATIVE_CUE_SIZE;
    line = (float) verticalAnchor / RELATIVE_CUE_SIZE;
  } else {
    position = (float) horizontalAnchor / HORIZONTAL_SIZE;
    line = (float) verticalAnchor / VERTICAL_SIZE;
  }
  // Apply screen-edge padding to the line and position.
  position = (position * 0.9f) + 0.05f;
  line = (line * 0.9f) + 0.05f;

  // anchorId specifies where the anchor should be placed on the caption cue/window. The 9
  // possible configurations are as follows:
  //   0-----1-----2
  //   |           |
  //   3     4     5
  //   |           |
  //   6-----7-----8
  @AnchorType int verticalAnchorType;
  if (anchorId % 3 == 0) {
    verticalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId % 3 == 1) {
    verticalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    verticalAnchorType = Cue.ANCHOR_TYPE_END;
  }
  // TODO: Add support for right-to-left languages (i.e. where start is on the right).
  @AnchorType int horizontalAnchorType;
  if (anchorId / 3 == 0) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId / 3 == 1) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    horizontalAnchorType = Cue.ANCHOR_TYPE_END;
  }

  boolean windowColorSet = (windowFillColor != COLOR_SOLID_BLACK);

  return new Cea708Cue(cueString, alignment, line, Cue.LINE_TYPE_FRACTION, verticalAnchorType,
      position, horizontalAnchorType, Cue.DIMEN_UNSET, windowColorSet, windowFillColor,
      priority);
}
 
Example #5
Source File: Cea708Decoder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public Cea708Cue build() {
  if (isEmpty()) {
    // The cue is empty.
    return null;
  }

  SpannableStringBuilder cueString = new SpannableStringBuilder();

  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildSpannableString());

  // TODO: Add support for right-to-left languages (i.e. where right would correspond to normal
  // alignment).
  Alignment alignment;
  switch (justification) {
    case JUSTIFICATION_FULL:
      // TODO: Add support for full justification.
    case JUSTIFICATION_LEFT:
      alignment = Alignment.ALIGN_NORMAL;
      break;
    case JUSTIFICATION_RIGHT:
      alignment = Alignment.ALIGN_OPPOSITE;
      break;
    case JUSTIFICATION_CENTER:
      alignment = Alignment.ALIGN_CENTER;
      break;
    default:
      throw new IllegalArgumentException("Unexpected justification value: " + justification);
  }

  float position;
  float line;
  if (relativePositioning) {
    position = (float) horizontalAnchor / RELATIVE_CUE_SIZE;
    line = (float) verticalAnchor / RELATIVE_CUE_SIZE;
  } else {
    position = (float) horizontalAnchor / HORIZONTAL_SIZE;
    line = (float) verticalAnchor / VERTICAL_SIZE;
  }
  // Apply screen-edge padding to the line and position.
  position = (position * 0.9f) + 0.05f;
  line = (line * 0.9f) + 0.05f;

  // anchorId specifies where the anchor should be placed on the caption cue/window. The 9
  // possible configurations are as follows:
  //   0-----1-----2
  //   |           |
  //   3     4     5
  //   |           |
  //   6-----7-----8
  @AnchorType int verticalAnchorType;
  if (anchorId % 3 == 0) {
    verticalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId % 3 == 1) {
    verticalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    verticalAnchorType = Cue.ANCHOR_TYPE_END;
  }
  // TODO: Add support for right-to-left languages (i.e. where start is on the right).
  @AnchorType int horizontalAnchorType;
  if (anchorId / 3 == 0) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId / 3 == 1) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    horizontalAnchorType = Cue.ANCHOR_TYPE_END;
  }

  boolean windowColorSet = (windowFillColor != COLOR_SOLID_BLACK);

  return new Cea708Cue(cueString, alignment, line, Cue.LINE_TYPE_FRACTION, verticalAnchorType,
      position, horizontalAnchorType, Cue.DIMEN_UNSET, windowColorSet, windowFillColor,
      priority);
}
 
Example #6
Source File: Cea708Decoder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public Cea708Cue build() {
  if (isEmpty()) {
    // The cue is empty.
    return null;
  }

  SpannableStringBuilder cueString = new SpannableStringBuilder();

  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildSpannableString());

  // TODO: Add support for right-to-left languages (i.e. where right would correspond to normal
  // alignment).
  Alignment alignment;
  switch (justification) {
    case JUSTIFICATION_FULL:
      // TODO: Add support for full justification.
    case JUSTIFICATION_LEFT:
      alignment = Alignment.ALIGN_NORMAL;
      break;
    case JUSTIFICATION_RIGHT:
      alignment = Alignment.ALIGN_OPPOSITE;
      break;
    case JUSTIFICATION_CENTER:
      alignment = Alignment.ALIGN_CENTER;
      break;
    default:
      throw new IllegalArgumentException("Unexpected justification value: " + justification);
  }

  float position;
  float line;
  if (relativePositioning) {
    position = (float) horizontalAnchor / RELATIVE_CUE_SIZE;
    line = (float) verticalAnchor / RELATIVE_CUE_SIZE;
  } else {
    position = (float) horizontalAnchor / HORIZONTAL_SIZE;
    line = (float) verticalAnchor / VERTICAL_SIZE;
  }
  // Apply screen-edge padding to the line and position.
  position = (position * 0.9f) + 0.05f;
  line = (line * 0.9f) + 0.05f;

  // anchorId specifies where the anchor should be placed on the caption cue/window. The 9
  // possible configurations are as follows:
  //   0-----1-----2
  //   |           |
  //   3     4     5
  //   |           |
  //   6-----7-----8
  @AnchorType int verticalAnchorType;
  if (anchorId % 3 == 0) {
    verticalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId % 3 == 1) {
    verticalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    verticalAnchorType = Cue.ANCHOR_TYPE_END;
  }
  // TODO: Add support for right-to-left languages (i.e. where start is on the right).
  @AnchorType int horizontalAnchorType;
  if (anchorId / 3 == 0) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_START;
  } else if (anchorId / 3 == 1) {
    horizontalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
  } else {
    horizontalAnchorType = Cue.ANCHOR_TYPE_END;
  }

  boolean windowColorSet = (windowFillColor != COLOR_SOLID_BLACK);

  return new Cea708Cue(cueString, alignment, line, Cue.LINE_TYPE_FRACTION, verticalAnchorType,
      position, horizontalAnchorType, Cue.DIMEN_UNSET, windowColorSet, windowFillColor,
      priority);
}