Example #1
0
 @Override
 public boolean fillTypedValue(FsFile data, TypedValue typedValue) {
   typedValue.type = TypedValue.TYPE_STRING;
   typedValue.data = 0;
   typedValue.string = data.getPath();
   typedValue.assetCookie = getNextStringCookie();
   return true;
 }
Example #2
0
 @Override
 public boolean fillTypedValue(String data, TypedValue typedValue) {
   try {
     typedValue.type = TypedValue.TYPE_INT_HEX;
     typedValue.data = findValueFor(data);
     typedValue.assetCookie = 0;
     return true;
   } catch (Exception e) {
     return false;
   }
 }
Example #3
0
 @Override
 public boolean fillTypedValue(String data, TypedValue typedValue) {
   try {
     typedValue.type = TypedValue.TYPE_INT_HEX;
     typedValue.data = convertInt(data);
     typedValue.assetCookie = 0;
     return true;
   } catch (NumberFormatException nfe) {
     return false;
   }
 }
Example #4
0
 @Override
 public boolean fillTypedValue(String data, TypedValue typedValue) {
   try {
     typedValue.type = TypedValue.TYPE_INT_COLOR_ARGB8;
     typedValue.data = ResourceHelper.getColor(data);
     typedValue.assetCookie = 0;
     return true;
   } catch (NumberFormatException nfe) {
     return false;
   }
 }
Example #5
0
 private boolean getValueAt(int index, TypedValue outValue) {
   final int[] data = mData;
   final int type = data[index + AssetManager.STYLE_TYPE];
   if (type == TypedValue.TYPE_NULL) {
     return false;
   }
   outValue.type = type;
   outValue.data = data[index + AssetManager.STYLE_DATA];
   outValue.assetCookie = data[index + AssetManager.STYLE_ASSET_COOKIE];
   outValue.resourceId = data[index + AssetManager.STYLE_RESOURCE_ID];
   outValue.changingConfigurations = data[index + AssetManager.STYLE_CHANGING_CONFIGURATIONS];
   outValue.density = data[index + AssetManager.STYLE_DENSITY];
   outValue.string = (type == TypedValue.TYPE_STRING) ? loadStringValueAt(index) : null;
   return true;
 }
Example #6
0
    @Override
    public boolean fillTypedValue(String data, TypedValue typedValue) {
      try {
        int flags = 0;
        for (String key : data.split("\\|")) {
          flags |= findValueFor(key);
        }

        typedValue.type = TypedValue.TYPE_INT_HEX;
        typedValue.data = flags;
        typedValue.assetCookie = 0;
        return true;
      } catch (Exception e) {
        return false;
      }
    }
Example #7
0
    @Override
    public boolean fillTypedValue(String data, TypedValue typedValue) {
      typedValue.type = TypedValue.TYPE_INT_BOOLEAN;
      typedValue.assetCookie = 0;

      if ("true".equalsIgnoreCase(data)) {
        typedValue.data = 1;
      } else if ("false".equalsIgnoreCase(data)) {
        typedValue.data = 0;
      } else {
        try {
          int intValue = Integer.parseInt(data);
          typedValue.data = intValue == 0 ? 0 : 1;
        } catch (NumberFormatException e) {
          return false;
        }
      }
      return true;
    }
Example #8
0
  public static void convertAndFill(
      Attribute attribute,
      TypedValue outValue,
      ResourceLoader resourceLoader,
      String qualifiers,
      AttrData attrData,
      boolean resolveRefs) {
    // short-circuit Android caching of loaded resources cuz our string positions don't remain
    // stable...
    outValue.assetCookie = getNextStringCookie();

    // TODO: Handle resource and style references
    if (attribute.isStyleReference()) {
      return;
    }

    ResourceIndex resourceIndex = resourceLoader.getResourceIndex();
    while (attribute.isResourceReference()) {
      ResName resName = attribute.getResourceReference();
      Integer resourceId = resourceIndex.getResourceId(resName);
      if (resourceId == null) {
        throw new Resources.NotFoundException("unknown resource " + resName);
      }
      outValue.type = TypedValue.TYPE_REFERENCE;
      outValue.resourceId = resourceId;
      TypedResource dereferencedRef = resourceLoader.getValue(resName, qualifiers);

      if (dereferencedRef == null) {
        if (resName.type.equals("id")) {
          return;
        } else if (resName.type.equals("layout")) {
          return; // resourceId is good enough, right?
        } else if (resName.type.equals("dimen")) {
          return;
        } else if (resName.type.equals("transition")) {
          return;
        } else if (resName.type.equals("interpolator")) {
          return;
        } else if (resName.type.equals("menu")) {
          return;
        } else if (resName.type.equals("raw")) {
          return;
        } else if (DrawableResourceLoader.isStillHandledHere(resName)) {
          // wtf. color and drawable references reference are all kinds of stupid.
          DrawableNode drawableNode = resourceLoader.getDrawableNode(resName, qualifiers);
          if (drawableNode == null) {
            throw new Resources.NotFoundException("can't find file for " + resName);
          } else {
            outValue.type = TypedValue.TYPE_STRING;
            outValue.data = 0;
            outValue.assetCookie = getNextStringCookie();
            outValue.string = drawableNode.getFsFile().getPath();
            return;
          }
        } else {
          throw new RuntimeException("huh? " + resName);
        }
      } else {
        if (dereferencedRef.isFile()) {
          outValue.type = TypedValue.TYPE_STRING;
          outValue.data = 0;
          outValue.assetCookie = getNextStringCookie();
          outValue.string = dereferencedRef.asString();
          return;
        } else if (dereferencedRef.getData() instanceof String) {
          attribute =
              new Attribute(attribute.resName, dereferencedRef.asString(), resName.packageName);
          if (attribute.isResourceReference()) {
            continue;
          }
          if (resolveRefs) {
            getConverter(dereferencedRef.getResType()).fillTypedValue(attribute.value, outValue);
            return;
          }
        }
      }
      break;
    }

    if (attribute.isNull()) {
      outValue.type = TypedValue.TYPE_NULL;
      return;
    }

    String format = attrData.getFormat();
    String[] types = format.split("\\|");
    for (String type : types) {
      if ("reference".equals(type)) continue; // already handled above
      Converter converter = getConverterFor(attrData, type);

      if (converter != null) {
        if (converter.fillTypedValue(attribute.value, outValue)) {
          return;
        }
      }
    }
  }