Java Code Examples for android.util.TypedValue#TYPE_STRING

The following examples show how to use android.util.TypedValue#TYPE_STRING . 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: PreferenceXmlUtil.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
private static String getData(Context context, AttributeSet set, int attribute)
        throws ReflectiveOperationException {
    final TypedArray sa = context.obtainStyledAttributes(set, new int[] {attribute});
    try {
        final TypedValue tv = sa.peekValue(0);
        CharSequence data = null;
        if (tv != null && tv.type == TypedValue.TYPE_STRING) {
            if (tv.resourceId != 0) {
                data = context.getText(tv.resourceId);
            } else {
                data = tv.string;
            }
        }
        return (data != null) ? data.toString() : null;
    } finally {
        sa.recycle();
    }
}
 
Example 2
Source File: AssetManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the string value associated with a particular resource
 * identifier for the current configuration.
 *
 * @param resId the resource identifier to load
 * @param bagEntryId the index into the bag to load
 * @return the string value, or {@code null}
 */
@Nullable CharSequence getResourceBagText(@StringRes int resId, int bagEntryId) {
    synchronized (this) {
        ensureValidLocked();
        final TypedValue outValue = mValue;
        final int cookie = nativeGetResourceBagValue(mObject, resId, bagEntryId, outValue);
        if (cookie <= 0) {
            return null;
        }

        // Convert the changing configurations flags populated by native code.
        outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
                outValue.changingConfigurations);

        if (outValue.type == TypedValue.TYPE_STRING) {
            return mApkAssets[cookie - 1].getStringFromPool(outValue.data);
        }
        return outValue.coerceToString();
    }
}
 
Example 3
Source File: AssetManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Populates {@code outValue} with the data associated a particular
 * resource identifier for the current configuration.
 *
 * @param resId the resource identifier to load
 * @param densityDpi the density bucket for which to load the resource
 * @param outValue the typed value in which to put the data
 * @param resolveRefs {@code true} to resolve references, {@code false}
 *                    to leave them unresolved
 * @return {@code true} if the data was loaded into {@code outValue},
 *         {@code false} otherwise
 */
boolean getResourceValue(@AnyRes int resId, int densityDpi, @NonNull TypedValue outValue,
        boolean resolveRefs) {
    Preconditions.checkNotNull(outValue, "outValue");
    synchronized (this) {
        ensureValidLocked();
        final int cookie = nativeGetResourceValue(
                mObject, resId, (short) densityDpi, outValue, resolveRefs);
        if (cookie <= 0) {
            return false;
        }

        // Convert the changing configurations flags populated by native code.
        outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
                outValue.changingConfigurations);

        if (outValue.type == TypedValue.TYPE_STRING) {
            outValue.string = mApkAssets[cookie - 1].getStringFromPool(outValue.data);
        }
        return true;
    }
}
 
Example 4
Source File: DashboardCategory.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
public DashboardCategory(Context context, AttributeSet attrs) {
    TypedArray sa = context.obtainStyledAttributes(attrs, R.styleable.DashboardTile);

    id = sa.getResourceId(R.styleable.DashboardTile_dashboard_id, CAT_ID_UNDEFINED);

    TypedValue tv = sa.peekValue(R.styleable.DashboardTile_dashboard_title);
    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
        if (tv.resourceId != 0) {
            titleRes = tv.resourceId;
        } else {
            title = tv.string;
        }
    }

    sa.recycle();
}
 
Example 5
Source File: TypedArray.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean getValueAt(int index, TypedValue outValue) {
    final int[] data = mData;
    final int type = data[index + STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return false;
    }
    outValue.type = type;
    outValue.data = data[index + STYLE_DATA];
    outValue.assetCookie = data[index + STYLE_ASSET_COOKIE];
    outValue.resourceId = data[index + STYLE_RESOURCE_ID];
    outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
            data[index + STYLE_CHANGING_CONFIGURATIONS]);
    outValue.density = data[index + STYLE_DENSITY];
    outValue.string = (type == TypedValue.TYPE_STRING) ? loadStringValueAt(index) : null;
    return true;
}
 
Example 6
Source File: ThemeHelper.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get Color from Theme attribute
 *
 * @param context Activity context
 * @param attr    Attribute ressource ID
 * @return Color as Int
 */
@ColorInt
public static int getThemeAttrColor(Context context, @AttrRes int attr) {
    TypedValue typedValue = new TypedValue();
    if (context.getTheme().resolveAttribute(attr, typedValue, true)) {
        if (typedValue.type >= TypedValue.TYPE_FIRST_INT
                && typedValue.type <= TypedValue.TYPE_LAST_INT) {
            return typedValue.data;
        } else if (typedValue.type == TypedValue.TYPE_STRING) {
            return ContextCompat.getColor(context, typedValue.resourceId);
        }
    }

    return 0;
}
 
Example 7
Source File: AXMLPrinter.java    From LibScout with Apache License 2.0 5 votes vote down vote up
public static String getAttributeValue(AXmlResourceParser parser,int index) {
	int type=parser.getAttributeValueType(index);
	int data=parser.getAttributeValueData(index);
	if (type==TypedValue.TYPE_STRING) {
		return parser.getAttributeValue(index);
	}
	if (type==TypedValue.TYPE_ATTRIBUTE) {
		return String.format("?%s%08X",getPackage(data),data);
	}
	if (type==TypedValue.TYPE_REFERENCE) {
		return String.format("@%s%08X",getPackage(data),data);
	}
	if (type==TypedValue.TYPE_FLOAT) {
		return String.valueOf(Float.intBitsToFloat(data));
	}
	if (type==TypedValue.TYPE_INT_HEX) {
		return String.format("0x%08X",data);
	}
	if (type==TypedValue.TYPE_INT_BOOLEAN) {
		return data!=0?"true":"false";
	}
	if (type==TypedValue.TYPE_DIMENSION) {
		return Float.toString(complexToFloat(data))+
			DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type==TypedValue.TYPE_FRACTION) {
		return Float.toString(complexToFloat(data))+
			FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type>=TypedValue.TYPE_FIRST_COLOR_INT && type<=TypedValue.TYPE_LAST_COLOR_INT) {
		return String.format("#%08X",data);
	}
	if (type>=TypedValue.TYPE_FIRST_INT && type<=TypedValue.TYPE_LAST_INT) {
		return String.valueOf(data);
	}
	return String.format("<0x%X, type 0x%02X>",data,type);
}
 
Example 8
Source File: ThemeHelper.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get Color from Theme attribute
 *
 * @param context Activity context
 * @param attr    Attribute ressource ID
 * @return Color as Int
 */
@ColorInt
public static int getThemeAttrColor(Context context, @AttrRes int attr) {
    TypedValue typedValue = new TypedValue();
    if (context.getTheme().resolveAttribute(attr, typedValue, true)) {
        if (typedValue.type >= TypedValue.TYPE_FIRST_INT
                && typedValue.type <= TypedValue.TYPE_LAST_INT) {
            return typedValue.data;
        } else if (typedValue.type == TypedValue.TYPE_STRING) {
            return ContextCompat.getColor(context, typedValue.resourceId);
        }
    }

    return 0;
}
 
Example 9
Source File: AXmlResourceParser.java    From LibScout with Apache License 2.0 5 votes vote down vote up
public String getAttributeValue(int index) {
	int offset=getAttributeOffset(index);
	int valueType=m_attributes[offset+ATTRIBUTE_IX_VALUE_TYPE];
	if (valueType==TypedValue.TYPE_STRING) {
		int valueString=m_attributes[offset+ATTRIBUTE_IX_VALUE_STRING];
		return m_strings.getString(valueString);
	}
	int valueData=m_attributes[offset+ATTRIBUTE_IX_VALUE_DATA];
	return "";//TypedValue.coerceToString(valueType,valueData);
}
 
Example 10
Source File: ResignerLogic.java    From apkReSign with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(AXmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data))
                + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data))
                + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT
            && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 11
Source File: ResValueFactory.java    From Auto.js-ApkBuilder with Apache License 2.0 5 votes vote down vote up
public ResScalarValue factory(int type, int value, String rawValue) throws IOException {
	switch (type) {
	case TypedValue.TYPE_NULL:
		return new ResReferenceValue(mPackage, 0, null);
	case TypedValue.TYPE_REFERENCE:
		return newReference(value, rawValue);
	case TypedValue.TYPE_ATTRIBUTE:
		return newReference(value, rawValue, true);
	case TypedValue.TYPE_STRING:
		return new ResStringValue(rawValue, value);
	case TypedValue.TYPE_FLOAT:
		return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue);
	case TypedValue.TYPE_DIMENSION:
		return new ResDimenValue(value, rawValue);
	case TypedValue.TYPE_FRACTION:
		return new ResFractionValue(value, rawValue);
	case TypedValue.TYPE_INT_BOOLEAN:
		return new ResBoolValue(value != 0, value, rawValue);
	case 0x07:
		return newReference(value, rawValue);
	}

	if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
		return new ResColorValue(value, rawValue);
	}
	if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
		return new ResIntValue(value, rawValue, type);
	}

	throw new IOException("Invalid value type: " + type);
}
 
Example 12
Source File: ManifestReader.java    From Android-Plugin-Framework with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public String getAttributeValue(int index) {
    int offset = getAttributeOffset(index);
    int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
    if (valueType == TypedValue.TYPE_STRING) {
        int valueString = m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING];
        return m_strings.getString(valueString);
    }
    int valueData = m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
    return "";// TypedValue.coerceToString(valueType,valueData);
}
 
Example 13
Source File: ManifestReader.java    From Android-Plugin-Framework with MIT License 5 votes vote down vote up
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    if (type == 0x07) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 14
Source File: XmlManifestReader.java    From AndroidPlugin with MIT License 5 votes vote down vote up
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data))
                + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data))
                + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT
            && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 15
Source File: ARSCDecoder.java    From Auto.js-ApkBuilder with Apache License 2.0 5 votes vote down vote up
private ResValue readValue() throws IOException {
/* size */
      mIn.skipCheckShort((short) 8);
/* zero */
      mIn.skipCheckByte((byte) 0);
      byte type = mIn.readByte();
      int data = mIn.readInt();

      return type == TypedValue.TYPE_STRING ? mPkg.getValueFactory().factory(mTableStrings.getString(data), data)
              : mPkg.getValueFactory().factory(type, data, null);
  }
 
Example 16
Source File: LayoutManager.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public RecyclerView.LayoutParams generateLayoutParams(@NonNull Context c, AttributeSet attrs) {
    // Just so we don't build layout params multiple times.

    boolean isString;
    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.superslim_LayoutManager);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        TypedValue value = new TypedValue();
        a.getValue(R.styleable.superslim_LayoutManager_slm_section_sectionManager, value);
        isString = value.type == TypedValue.TYPE_STRING;
    } else {
        isString =
                a.getType(R.styleable.superslim_LayoutManager_slm_section_sectionManager)
                        == TypedValue.TYPE_STRING;
    }
    String sectionManager = null;
    int sectionManagerKind;
    if (isString) {
        sectionManager = a
                .getString(R.styleable.superslim_LayoutManager_slm_section_sectionManager);
        if (TextUtils.isEmpty(sectionManager)) {
            sectionManagerKind = SECTION_MANAGER_LINEAR;
        } else {
            sectionManagerKind = SECTION_MANAGER_CUSTOM;
        }
    } else {
        sectionManagerKind = a
                .getInt(R.styleable.superslim_LayoutManager_slm_section_sectionManager,
                        SECTION_MANAGER_LINEAR);
    }
    a.recycle();

    return getSLM(sectionManagerKind, sectionManager).generateLayoutParams(c, attrs);
}
 
Example 17
Source File: AXmlResourceParser.java    From apkReSign with Apache License 2.0 5 votes vote down vote up
public String getAttributeValue(int index) {
	int offset=getAttributeOffset(index);
	int valueType=m_attributes[offset+ATTRIBUTE_IX_VALUE_TYPE];
	if (valueType==TypedValue.TYPE_STRING) {
		int valueString=m_attributes[offset+ATTRIBUTE_IX_VALUE_STRING];
		return m_strings.getString(valueString);
	}
	int valueData=m_attributes[offset+ATTRIBUTE_IX_VALUE_DATA];
	return "";//TypedValue.coerceToString(valueType,valueData);
}
 
Example 18
Source File: AXMLPrinter.java    From Android-Applications-Info with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(AXmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) +
                DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) +
                FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example 19
Source File: ResourceUtils.java    From simple-keyboard with Apache License 2.0 4 votes vote down vote up
public static boolean isStringValue(final TypedValue v) {
    return v.type == TypedValue.TYPE_STRING;
}
 
Example 20
Source File: ResourceUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
public static boolean isStringValue(final TypedValue v) {
    return v.type == TypedValue.TYPE_STRING;
}