Java Code Examples for org.xmlpull.v1.XmlPullParser#getAttributeName()

The following examples show how to use org.xmlpull.v1.XmlPullParser#getAttributeName() . 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: AtomParser.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private static String readItemLink(XmlPullParser parser) throws IOException, XmlPullParserException {
    String url = "";
    parser.require(XmlPullParser.START_TAG, null, LINK);
    boolean isHaveTargetValue = false;
    for (int i = 0; i < parser.getAttributeCount(); i++) {
        switch (parser.getAttributeName(i)) {
            case "href":
                url = parser.getAttributeValue(i);
                isHaveTargetValue = true;
                break;
        }
        if (isHaveTargetValue) {
            break; //退出
        }
    }
    parser.next();
    if (parser.next() == XmlPullParser.END_TAG) {
        parser.next();
    }
    return url;
}
 
Example 2
Source File: ManifestPullParser.java    From ic3 with Apache License 2.0 6 votes vote down vote up
private boolean handleManifestStart(XmlPullParser parser) {
  for (int i = 0; i < parser.getAttributeCount(); ++i) {
    String attributeName = parser.getAttributeName(i);
    if (attributeName.equals(PACKAGE)) {
      // No namespace requirement.
      setPackageName(parser.getAttributeValue(i));
    } else if (parser.getAttributeNamespace(i).equals(NAMESPACE) && attributeName.equals(VERSION)) {
      version = Integer.parseInt(parser.getAttributeValue(i));
    }
  }
  if (getPackageName() != null) {
    return true;
  } else {
    return false;
  }
}
 
Example 3
Source File: XMLParser.java    From QPM with Apache License 2.0 6 votes vote down vote up
/**
 * 解析自己的attribute属性
 */
private void parseAttribute(XmlPullParser parser) throws XmlPullParserException {
    int attributeCount = parser.getAttributeCount();
    for (int i = 0; i < attributeCount; i++) {
        String attributeNamespace = parser.getAttributeNamespace(i);
        String attributeName = parser.getAttributeName(i);
        String attributeValue = parser.getAttributeValue(i);
        if (TextUtils.isEmpty(attributeName)) {
            throw new XmlPullParserException("attributeName is null");
        }
        if (TextUtils.isEmpty(attributeValue)) {
            continue;
        }
        if (needParseNameSpace) {
            String key = TextUtils.isEmpty(attributeNamespace)
                    ? attributeName
                    : attributeNamespace + ":" + attributeName;
            attributeMap.put(key, attributeValue);
        } else {
            attributeMap.put(attributeName, attributeValue);
        }
    }
}
 
Example 4
Source File: AtomParser.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private static Message readFeedLink(XmlPullParser parser) throws IOException, XmlPullParserException {
    String url = "";
    parser.require(XmlPullParser.START_TAG, null, LINK);
    boolean is_false = false;
    for (int i = 0; i < parser.getAttributeCount(); i++) {
        switch (parser.getAttributeName(i)) {
            case "href":
                url = parser.getAttributeType(i);
                break;
            case "rel":
                //直接返回,这个地址是不需要的
                is_false = true;
                break;
        }
        if (is_false) {
            break;
        }
    }
    if (is_false) {
        return new Message(false);
    } else {
        parser.next();
        return new Message(true, url);
    }
}
 
Example 5
Source File: AtomParser.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private static String readItemLink(XmlPullParser parser) throws IOException, XmlPullParserException {
    String url = "";
    parser.require(XmlPullParser.START_TAG, null, LINK);
    boolean isHaveTargetValue = false;
    for (int i = 0; i < parser.getAttributeCount(); i++) {
        switch (parser.getAttributeName(i)) {
            case "href":
                url = parser.getAttributeValue(i);
                isHaveTargetValue = true;
                break;
        }
        if (isHaveTargetValue) {
            break; //退出
        }
    }
    parser.next();
    if (parser.next() == XmlPullParser.END_TAG) {
        parser.next();
    }
    return url;
}
 
Example 6
Source File: Enclosure.java    From PkRSS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an Enclosure from the current event in an XmlPullParser.
 * @param xmlParser The XmlPullParser object.
 */
public Enclosure(XmlPullParser xmlParser) {
    for(int i = 0; i < xmlParser.getAttributeCount(); i++) {
        String val = xmlParser.getAttributeValue(i);
        String att = xmlParser.getAttributeName(i);

        if(att.equalsIgnoreCase("url"))
            this.setUrl(val);

        else if(att.equalsIgnoreCase("length"))
            this.setLength(val);

        else if(att.equalsIgnoreCase("type"))
            this.setMimeType(val);
    }
}
 
Example 7
Source File: CumulusXmlParser.java    From CumulusTV with MIT License 5 votes vote down vote up
private static Advertisement parseAd(XmlPullParser parser, String adType)
        throws IOException, XmlPullParserException, ParseException{
    Long startTimeUtcMillis = null;
    Long stopTimeUtcMillis = null;
    int type = Advertisement.TYPE_VAST;
    for (int i = 0; i < parser.getAttributeCount(); ++i) {
        String attr = parser.getAttributeName(i);
        String value = parser.getAttributeValue(i);
        if (ATTR_AD_START.equalsIgnoreCase(attr)) {
            startTimeUtcMillis = DATE_FORMAT.parse(value).getTime();
        } else if (ATTR_AD_STOP.equalsIgnoreCase(attr)) {
            stopTimeUtcMillis = DATE_FORMAT.parse(value).getTime();
        } else if (ATTR_AD_TYPE.equalsIgnoreCase(attr)) {
            if (VALUE_ADVERTISEMENT_TYPE_VAST.equalsIgnoreCase(attr)) {
                type = Advertisement.TYPE_VAST;
            }
        }
    }
    String requestUrl = null;
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if (TAG_REQUEST_URL.equalsIgnoreCase(parser.getName())) {
                requestUrl = parser.nextText();
            }
        } else if (TAG_AD.equalsIgnoreCase(parser.getName())
                && parser.getEventType() == XmlPullParser.END_TAG) {
            break;
        }
    }
    Advertisement.Builder builder = new Advertisement.Builder();
    if (adType.equals(TAG_PROGRAM)) {
        if (startTimeUtcMillis == null || stopTimeUtcMillis == null) {
            throw new IllegalArgumentException(
                    "start, stop time of program ads cannot be null");
        }
        builder.setStartTimeUtcMillis(startTimeUtcMillis);
        builder.setStopTimeUtcMillis(stopTimeUtcMillis);
    }
    return builder.setType(type).setRequestUrl(requestUrl).build();
}
 
Example 8
Source File: CumulusXmlParser.java    From CumulusTV with MIT License 5 votes vote down vote up
private static XmlTvAppLink parseAppLink(XmlPullParser parser)
        throws IOException, XmlPullParserException {
    String text = null;
    Integer color = null;
    String posterUri = null;
    String intentUri = null;
    for (int i = 0; i < parser.getAttributeCount(); ++i) {
        String attr = parser.getAttributeName(i);
        String value = parser.getAttributeValue(i);
        if (ATTR_APP_LINK_TEXT.equalsIgnoreCase(attr)) {
            text = value;
        } else if (ATTR_APP_LINK_COLOR.equalsIgnoreCase(attr)) {
            color = Color.parseColor(value);
        } else if (ATTR_APP_LINK_POSTER_URI.equalsIgnoreCase(attr)) {
            posterUri = value;
        } else if (ATTR_APP_LINK_INTENT_URI.equalsIgnoreCase(attr)) {
            intentUri = value;
        }
    }

    XmlTvIcon icon = null;
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_ICON.equalsIgnoreCase(parser.getName()) && icon == null) {
            icon = parseIcon(parser);
        } else if (TAG_APP_LINK.equalsIgnoreCase(parser.getName())
                && parser.getEventType() == XmlPullParser.END_TAG) {
            break;
        }
    }

    return new XmlTvAppLink(text, color, posterUri, intentUri, icon);
}
 
Example 9
Source File: ManifestPullParser.java    From ic3 with Apache License 2.0 5 votes vote down vote up
private boolean handleProviderStart(XmlPullParser parser) {
  boolean r = handleComponentStart(parser, PROVIDER, Constants.ComponentShortType.PROVIDER);
  String readPermission = currentComponent.getPermission();
  String writePermission = currentComponent.getPermission();
  Set<String> authorities = new HashSet<String>();
  boolean grantUriPermissions = false;

  for (int i = 0; i < parser.getAttributeCount(); ++i) {
    if (!parser.getAttributeNamespace(i).equals(NAMESPACE)) {
      continue;
    }
    String attributeName = parser.getAttributeName(i);
    // permissions
    // Note: readPermission and writePermission attributes take precedence over
    // permission attribute
    // (http://developer.android.com/guide/topics/manifest/provider-element.html).
    if (attributeName.equals(READ_PERMISSION)) {
      readPermission = parser.getAttributeValue(i);
    } else if (attributeName.equals(WRITE_PERMISSION)) {
      writePermission = parser.getAttributeValue(i);
    } else if (attributeName.equals(AUTHORITIES)) {
      // the "AUTHORITIES" attribute contains a list of authorities separated by semicolons.
      String s = parser.getAttributeValue(i);
      for (String a : s.split(";")) {
        authorities.add(a);
      }
    } else if (attributeName.equals(GRANT_URI_PERMISSIONS)) {
      grantUriPermissions = !parser.getAttributeValue(i).equals("false");
    }
  }

  currentComponent =
      new ManifestProviderComponent(currentComponent.getType(), currentComponent.getName(),
          currentComponent.isExported(), currentComponent.isFoundExported(), readPermission,
          writePermission, authorities, grantUriPermissions);
  return r;
}
 
Example 10
Source File: XmlTvParser.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
private static XmlTvAppLink parseAppLink(XmlPullParser parser)
        throws IOException, XmlPullParserException {
    String text = null;
    Integer color = null;
    String posterUri = null;
    String intentUri = null;
    for (int i = 0; i < parser.getAttributeCount(); ++i) {
        String attr = parser.getAttributeName(i);
        String value = parser.getAttributeValue(i);
        if (ATTR_APP_LINK_TEXT.equalsIgnoreCase(attr)) {
            text = value;
        } else if (ATTR_APP_LINK_COLOR.equalsIgnoreCase(attr)) {
            color = Color.parseColor(value);
        } else if (ATTR_APP_LINK_POSTER_URI.equalsIgnoreCase(attr)) {
            posterUri = value;
        } else if (ATTR_APP_LINK_INTENT_URI.equalsIgnoreCase(attr)) {
            intentUri = value;
        }
    }

    XmlTvIcon icon = null;
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_ICON.equalsIgnoreCase(parser.getName())
                && icon == null) {
            icon = parseIcon(parser);
        } else if (TAG_APP_LINK.equalsIgnoreCase(parser.getName())
                && parser.getEventType() == XmlPullParser.END_TAG) {
            break;
        }
    }

    return new XmlTvAppLink(text, color, posterUri, intentUri, icon);
}
 
Example 11
Source File: ComponentDescription.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 */
private static void unrecognizedAttr(XmlPullParser p, int attr)
  throws IllegalXMLException
{
  throw new IllegalXMLException("Unrecognized attribute \"" + p.getAttributeName(attr) +
                                "\" in \"" + p.getName() + "\"-tag", p);
}
 
Example 12
Source File: SvgToPath.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private String showAttributes(XmlPullParser a) {
    String result = "";
    for(int i=0; i < a.getAttributeCount(); i++) {
        result += " " + a.getAttributeName(i) + "='" + a.getAttributeValue(i) + "'";
    }
    return result;
}
 
Example 13
Source File: XmlToJson.java    From XmlToJson with Apache License 2.0 4 votes vote down vote up
private void readTags(Tag parent, XmlPullParser xpp) {
    try {
        int eventType;
        do {
            eventType = xpp.next();
            if (eventType == XmlPullParser.START_TAG) {
                String tagName = xpp.getName();
                String path = parent.getPath() + "/" + tagName;

                boolean skipTag = mSkippedTags.contains(path);

                Tag child = new Tag(path, tagName);
                if (!skipTag) {
                    parent.addChild(child);
                }

                // Attributes are taken into account as key/values in the child
                int attrCount = xpp.getAttributeCount();
                for (int i = 0; i < attrCount; ++i) {
                    String attrName = xpp.getAttributeName(i);
                    String attrValue = xpp.getAttributeValue(i);
                    String attrPath = parent.getPath() + "/" + child.getName() + "/" + attrName;

                    // Skip Attributes
                    if (mSkippedAttributes.contains(attrPath)) {
                        continue;
                    }

                    attrName = getAttributeNameReplacement(attrPath, attrName);
                    Tag attribute = new Tag(attrPath, attrName);
                    attribute.setContent(attrValue);
                    child.addChild(attribute);
                }

                readTags(child, xpp);
            } else if (eventType == XmlPullParser.TEXT) {
                String text = xpp.getText();
                parent.setContent(text);
            } else if (eventType == XmlPullParser.END_TAG) {
                return;
            } else if (eventType == XmlPullParser.END_DOCUMENT) {
                return;
            } else {
                Log.i(TAG, "unknown xml eventType " + eventType);
            }
        } while (eventType != XmlPullParser.END_DOCUMENT);
    } catch (XmlPullParserException | IOException | NullPointerException e) {
        e.printStackTrace();
    }
}
 
Example 14
Source File: TtmlDecoder.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private TtmlNode parseNode(XmlPullParser parser, TtmlNode parent,
    Map<String, TtmlRegion> regionMap, FrameAndTickRate frameAndTickRate)
    throws SubtitleDecoderException {
  long duration = C.TIME_UNSET;
  long startTime = C.TIME_UNSET;
  long endTime = C.TIME_UNSET;
  String regionId = TtmlNode.ANONYMOUS_REGION_ID;
  String imageId = null;
  String[] styleIds = null;
  int attributeCount = parser.getAttributeCount();
  TtmlStyle style = parseStyleAttributes(parser, null);
  for (int i = 0; i < attributeCount; i++) {
    String attr = parser.getAttributeName(i);
    String value = parser.getAttributeValue(i);
    switch (attr) {
      case ATTR_BEGIN:
        startTime = parseTimeExpression(value, frameAndTickRate);
        break;
      case ATTR_END:
        endTime = parseTimeExpression(value, frameAndTickRate);
        break;
      case ATTR_DURATION:
        duration = parseTimeExpression(value, frameAndTickRate);
        break;
      case ATTR_STYLE:
        // IDREFS: potentially multiple space delimited ids
        String[] ids = parseStyleIds(value);
        if (ids.length > 0) {
          styleIds = ids;
        }
        break;
      case ATTR_REGION:
        if (regionMap.containsKey(value)) {
          // If the region has not been correctly declared or does not define a position, we use
          // the anonymous region.
          regionId = value;
        }
        break;
      case ATTR_IMAGE:
        // Parse URI reference only if refers to an element in the same document (it must start
        // with '#'). Resolving URIs from external sources is not supported.
        if (value.startsWith("#")) {
          imageId = value.substring(1);
        }
        break;
      default:
        // Do nothing.
        break;
    }
  }
  if (parent != null && parent.startTimeUs != C.TIME_UNSET) {
    if (startTime != C.TIME_UNSET) {
      startTime += parent.startTimeUs;
    }
    if (endTime != C.TIME_UNSET) {
      endTime += parent.startTimeUs;
    }
  }
  if (endTime == C.TIME_UNSET) {
    if (duration != C.TIME_UNSET) {
      // Infer the end time from the duration.
      endTime = startTime + duration;
    } else if (parent != null && parent.endTimeUs != C.TIME_UNSET) {
      // If the end time remains unspecified, then it should be inherited from the parent.
      endTime = parent.endTimeUs;
    }
  }
  return TtmlNode.buildNode(
      parser.getName(), startTime, endTime, style, styleIds, regionId, imageId);
}
 
Example 15
Source File: TtmlDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private TtmlNode parseNode(XmlPullParser parser, TtmlNode parent,
    Map<String, TtmlRegion> regionMap, FrameAndTickRate frameAndTickRate)
    throws SubtitleDecoderException {
  long duration = C.TIME_UNSET;
  long startTime = C.TIME_UNSET;
  long endTime = C.TIME_UNSET;
  String regionId = TtmlNode.ANONYMOUS_REGION_ID;
  String imageId = null;
  String[] styleIds = null;
  int attributeCount = parser.getAttributeCount();
  TtmlStyle style = parseStyleAttributes(parser, null);
  for (int i = 0; i < attributeCount; i++) {
    String attr = parser.getAttributeName(i);
    String value = parser.getAttributeValue(i);
    switch (attr) {
      case ATTR_BEGIN:
        startTime = parseTimeExpression(value, frameAndTickRate);
        break;
      case ATTR_END:
        endTime = parseTimeExpression(value, frameAndTickRate);
        break;
      case ATTR_DURATION:
        duration = parseTimeExpression(value, frameAndTickRate);
        break;
      case ATTR_STYLE:
        // IDREFS: potentially multiple space delimited ids
        String[] ids = parseStyleIds(value);
        if (ids.length > 0) {
          styleIds = ids;
        }
        break;
      case ATTR_REGION:
        if (regionMap.containsKey(value)) {
          // If the region has not been correctly declared or does not define a position, we use
          // the anonymous region.
          regionId = value;
        }
        break;
      case ATTR_IMAGE:
        // Parse URI reference only if refers to an element in the same document (it must start
        // with '#'). Resolving URIs from external sources is not supported.
        if (value.startsWith("#")) {
          imageId = value.substring(1);
        }
        break;
      default:
        // Do nothing.
        break;
    }
  }
  if (parent != null && parent.startTimeUs != C.TIME_UNSET) {
    if (startTime != C.TIME_UNSET) {
      startTime += parent.startTimeUs;
    }
    if (endTime != C.TIME_UNSET) {
      endTime += parent.startTimeUs;
    }
  }
  if (endTime == C.TIME_UNSET) {
    if (duration != C.TIME_UNSET) {
      // Infer the end time from the duration.
      endTime = startTime + duration;
    } else if (parent != null && parent.endTimeUs != C.TIME_UNSET) {
      // If the end time remains unspecified, then it should be inherited from the parent.
      endTime = parent.endTimeUs;
    }
  }
  return TtmlNode.buildNode(
      parser.getName(), startTime, endTime, style, styleIds, regionId, imageId);
}
 
Example 16
Source File: XmlToJson.java    From WechatEnhancement with GNU General Public License v3.0 4 votes vote down vote up
private void readTags(Tag parent, XmlPullParser xpp) {
    try {
        int eventType;
        do {
            eventType = xpp.next();
            if (eventType == XmlPullParser.START_TAG) {
                String tagName = xpp.getName();
                String path = parent.getPath() + "/" + tagName;

                boolean skipTag = mSkippedTags.contains(path);

                Tag child = new Tag(path, tagName);
                if (!skipTag) {
                    parent.addChild(child);
                }

                // Attributes are taken into account as key/values in the child
                int attrCount = xpp.getAttributeCount();
                for (int i = 0; i < attrCount; ++i) {
                    String attrName = xpp.getAttributeName(i);
                    String attrValue = xpp.getAttributeValue(i);
                    String attrPath = parent.getPath() + "/" + child.getName() + "/" + attrName;

                    // Skip Attributes
                    if (mSkippedAttributes.contains(attrPath)) {
                        continue;
                    }

                    attrName = getAttributeNameReplacement(attrPath, attrName);
                    Tag attribute = new Tag(attrPath, attrName);
                    attribute.setContent(attrValue);
                    child.addChild(attribute);
                }

                readTags(child, xpp);
            } else if (eventType == XmlPullParser.TEXT) {
                String text = xpp.getText();
                parent.setContent(text);
            } else if (eventType == XmlPullParser.END_TAG) {
                return;
            } else {
                Log.i(TAG, "unknown xml eventType " + eventType);
            }
        } while (eventType != XmlPullParser.END_DOCUMENT);
    } catch (XmlPullParserException | IOException | NullPointerException e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: XmlTvParser.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
private static Program parseProgram(XmlPullParser parser)
        throws IOException, XmlPullParserException, ParseException {
    String channelId = null;
    Long startTimeUtcMillis = null;
    Long endTimeUtcMillis = null;
    String videoSrc = null;
    int videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE;
    for (int i = 0; i < parser.getAttributeCount(); ++i) {
        String attr = parser.getAttributeName(i);
        String value = parser.getAttributeValue(i);
        if (ATTR_CHANNEL.equalsIgnoreCase(attr)) {
            channelId = value;
        } else if (ATTR_START.equalsIgnoreCase(attr)) {
            startTimeUtcMillis = DATE_FORMAT.parse(value).getTime();
        } else if (ATTR_STOP.equalsIgnoreCase(attr)) {
            endTimeUtcMillis = DATE_FORMAT.parse(value).getTime();
        } else if (ATTR_VIDEO_SRC.equalsIgnoreCase(attr)) {
            videoSrc = value;
        } else if (ATTR_VIDEO_TYPE.equalsIgnoreCase(attr)) {
            if (VALUE_VIDEO_TYPE_HTTP_PROGRESSIVE.equals(value)) {
                videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE;
            } else if (VALUE_VIDEO_TYPE_HLS.equals(value)) {
                videoType = TvContractUtils.SOURCE_TYPE_HLS;
            } else if (VALUE_VIDEO_TYPE_MPEG_DASH.equals(value)) {
                videoType = TvContractUtils.SOURCE_TYPE_MPEG_DASH;
            }
        }
    }
    String title = null;
    String description = null;
    XmlTvIcon icon = null;
    List<String> category = new ArrayList<>();
    List<TvContentRating> rating = new ArrayList<>();
    List<Advertisement> ads = new ArrayList<>();
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        String tagName = parser.getName();
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if (TAG_TITLE.equalsIgnoreCase(parser.getName())) {
                title = parser.nextText();
            } else if (TAG_DESC.equalsIgnoreCase(tagName)) {
                description = parser.nextText();
            } else if (TAG_ICON.equalsIgnoreCase(tagName)) {
                icon = parseIcon(parser);
            } else if (TAG_CATEGORY.equalsIgnoreCase(tagName)) {
                category.add(parser.nextText());
            } else if (TAG_RATING.equalsIgnoreCase(tagName)) {
                TvContentRating xmlTvRating = xmlTvRatingToTvContentRating(parseRating(parser));
                if (xmlTvRating != null) {
                    rating.add(xmlTvRating);
                }
            } else if (TAG_AD.equalsIgnoreCase(tagName)) {
                ads.add(parseAd(parser, TAG_PROGRAM));
            }
        } else if (TAG_PROGRAM.equalsIgnoreCase(tagName)
                && parser.getEventType() == XmlPullParser.END_TAG) {
            break;
        }
    }
    if (TextUtils.isEmpty(channelId)
            || startTimeUtcMillis == null
            || endTimeUtcMillis == null) {
        throw new IllegalArgumentException("channel, start, and end can not be null.");
    }
    InternalProviderData internalProviderData = new InternalProviderData();
    internalProviderData.setVideoType(videoType);
    internalProviderData.setVideoUrl(videoSrc);
    internalProviderData.setAds(ads);
    return new Program.Builder()
            .setChannelId(channelId.hashCode())
            .setTitle(title)
            .setDescription(description)
            .setPosterArtUri(icon.src)
            .setCanonicalGenres(category.toArray(new String[category.size()]))
            .setStartTimeUtcMillis(startTimeUtcMillis)
            .setEndTimeUtcMillis(endTimeUtcMillis)
            .setContentRatings(rating.toArray(new TvContentRating[rating.size()]))
            // NOTE: {@code COLUMN_INTERNAL_PROVIDER_DATA} is a private field
            // where TvInputService can store anything it wants. Here, we store
            // video type and video URL so that TvInputService can play the
            // video later with this field.
            .setInternalProviderData(internalProviderData)
            .build();
}
 
Example 18
Source File: DeviceFilter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public static DeviceFilter read(XmlPullParser parser)
        throws XmlPullParserException, IOException {
    int vendorId = -1;
    int productId = -1;
    int deviceClass = -1;
    int deviceSubclass = -1;
    int deviceProtocol = -1;
    String manufacturerName = null;
    String productName = null;
    String serialNumber = null;

    int count = parser.getAttributeCount();
    for (int i = 0; i < count; i++) {
        String name = parser.getAttributeName(i);
        String value = parser.getAttributeValue(i);
        // Attribute values are ints or strings
        if ("manufacturer-name".equals(name)) {
            manufacturerName = value;
        } else if ("product-name".equals(name)) {
            productName = value;
        } else if ("serial-number".equals(name)) {
            serialNumber = value;
        } else {
            int intValue;
            int radix = 10;
            if (value != null && value.length() > 2 && value.charAt(0) == '0' &&
                    (value.charAt(1) == 'x' || value.charAt(1) == 'X')) {
                // allow hex values starting with 0x or 0X
                radix = 16;
                value = value.substring(2);
            }
            try {
                intValue = Integer.parseInt(value, radix);
            } catch (NumberFormatException e) {
                Slog.e(TAG, "invalid number for field " + name, e);
                continue;
            }
            if ("vendor-id".equals(name)) {
                vendorId = intValue;
            } else if ("product-id".equals(name)) {
                productId = intValue;
            } else if ("class".equals(name)) {
                deviceClass = intValue;
            } else if ("subclass".equals(name)) {
                deviceSubclass = intValue;
            } else if ("protocol".equals(name)) {
                deviceProtocol = intValue;
            }
        }
    }
    return new DeviceFilter(vendorId, productId,
            deviceClass, deviceSubclass, deviceProtocol,
            manufacturerName, productName, serialNumber);
}
 
Example 19
Source File: ActivityRecord.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
static ActivityRecord restoreFromXml(XmlPullParser in,
        ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
    Intent intent = null;
    PersistableBundle persistentState = null;
    int launchedFromUid = 0;
    String launchedFromPackage = null;
    String resolvedType = null;
    boolean componentSpecified = false;
    int userId = 0;
    long createTime = -1;
    final int outerDepth = in.getDepth();
    TaskDescription taskDescription = new TaskDescription();

    for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
        final String attrName = in.getAttributeName(attrNdx);
        final String attrValue = in.getAttributeValue(attrNdx);
        if (DEBUG) Slog.d(TaskPersister.TAG,
                    "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
        if (ATTR_ID.equals(attrName)) {
            createTime = Long.parseLong(attrValue);
        } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
            launchedFromUid = Integer.parseInt(attrValue);
        } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
            launchedFromPackage = attrValue;
        } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
            resolvedType = attrValue;
        } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
            componentSpecified = Boolean.parseBoolean(attrValue);
        } else if (ATTR_USERID.equals(attrName)) {
            userId = Integer.parseInt(attrValue);
        } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) {
            taskDescription.restoreFromXml(attrName, attrValue);
        } else {
            Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
        }
    }

    int event;
    while (((event = in.next()) != END_DOCUMENT) &&
            (event != END_TAG || in.getDepth() >= outerDepth)) {
        if (event == START_TAG) {
            final String name = in.getName();
            if (DEBUG)
                    Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
            if (TAG_INTENT.equals(name)) {
                intent = Intent.restoreFromXml(in);
                if (DEBUG)
                        Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
            } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
                persistentState = PersistableBundle.restoreFromXml(in);
                if (DEBUG) Slog.d(TaskPersister.TAG,
                        "ActivityRecord: persistentState=" + persistentState);
            } else {
                Slog.w(TAG, "restoreActivity: unexpected name=" + name);
                XmlUtils.skipCurrentTag(in);
            }
        }
    }

    if (intent == null) {
        throw new XmlPullParserException("restoreActivity error intent=" + intent);
    }

    final ActivityManagerService service = stackSupervisor.mService;
    final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null,
            userId, Binder.getCallingUid());
    if (aInfo == null) {
        throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent +
                " resolvedType=" + resolvedType);
    }
    final ActivityRecord r = new ActivityRecord(service, null /* caller */,
            0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType,
            aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */,
            0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */,
            stackSupervisor, null /* options */, null /* sourceRecord */);

    r.persistentState = persistentState;
    r.taskDescription = taskDescription;
    r.createTime = createTime;

    return r;
}
 
Example 20
Source File: CumulusXmlParser.java    From CumulusTV with MIT License 4 votes vote down vote up
private static Channel parseChannel(XmlPullParser parser)
        throws IOException, XmlPullParserException, ParseException {
    String id = null;
    boolean repeatPrograms = false;
    for (int i = 0; i < parser.getAttributeCount(); ++i) {
        String attr = parser.getAttributeName(i);
        String value = parser.getAttributeValue(i);
        if (ATTR_ID.equalsIgnoreCase(attr)) {
            id = value;
        } else if (ATTR_REPEAT_PROGRAMS.equalsIgnoreCase(attr)) {
            repeatPrograms = "TRUE".equalsIgnoreCase(value);
        }
    }
    String displayName = null;
    String displayNumber = null;
    XmlTvIcon icon = null;
    XmlTvAppLink appLink = null;
    Advertisement advertisement = null;
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if (TAG_DISPLAY_NAME.equalsIgnoreCase(parser.getName())
                    && displayName == null) {
                displayName = parser.nextText();
            } else if (TAG_DISPLAY_NUMBER.equalsIgnoreCase(parser.getName())
                    && displayNumber == null) {
                displayNumber = parser.nextText();
            } else if (TAG_ICON.equalsIgnoreCase(parser.getName()) && icon == null) {
                icon = parseIcon(parser);
            } else if (TAG_APP_LINK.equalsIgnoreCase(parser.getName()) && appLink == null) {
                appLink = parseAppLink(parser);
            } else if (TAG_AD.equalsIgnoreCase(parser.getName()) && advertisement == null) {
                advertisement = parseAd(parser, TAG_CHANNEL);
            }
        } else if (TAG_CHANNEL.equalsIgnoreCase(parser.getName())
                && parser.getEventType() == XmlPullParser.END_TAG) {
            break;
        }
    }
    if (TextUtils.isEmpty(id) || TextUtils.isEmpty(displayName)) {
        throw new IllegalArgumentException("id and display-name can not be null.");
    }

    // Developers should assign original network ID in the right way not using the fake ID.
    InternalProviderData internalProviderData = new InternalProviderData();
    internalProviderData.setRepeatable(repeatPrograms);
    Channel.Builder builder = new Channel.Builder()
            .setDisplayName(displayName)
            .setDisplayNumber(displayNumber)
            .setOriginalNetworkId(id.hashCode())
            .setInternalProviderData(internalProviderData)
            .setTransportStreamId(0)
            .setServiceId(0);
    if (icon != null) {
        builder.setChannelLogo(icon.src);
    }
    if (appLink != null) {
        builder.setAppLinkColor(appLink.color)
                .setAppLinkIconUri(appLink.icon.src)
                .setAppLinkIntentUri(appLink.intentUri)
                .setAppLinkPosterArtUri(appLink.posterUri)
                .setAppLinkText(appLink.text);
    }
    if (advertisement != null) {
        List<Advertisement> advertisements = new ArrayList<>(1);
        advertisements.add(advertisement);
        internalProviderData.setAds(advertisements);
        builder.setInternalProviderData(internalProviderData);
    }
    return builder.build();
}