List of usage examples for android.util TypedValue TYPE_STRING
int TYPE_STRING
To view the source code for android.util TypedValue TYPE_STRING.
Click Source Link
From source file:Main.java
public static int resolveColor(Context context, int colorAttr, int defaultResId) { TypedValue typedValue = new TypedValue(); boolean resolved = context.getTheme().resolveAttribute(colorAttr, typedValue, true); if (resolved) { if (typedValue.type == TypedValue.TYPE_STRING) { ColorStateList stateList = context.getResources().getColorStateList(typedValue.resourceId); if (stateList != null) return stateList.getDefaultColor(); } else {/*w w w. j a va 2 s .co m*/ return typedValue.data; } } return context.getResources().getColor(defaultResId); }
From source file:Main.java
@SuppressWarnings("deprecation") private static int getColor(Context context, int id, int defaultValue) { if (value == null) { value = new TypedValue(); }// ww w . j a v a2s. c o m try { Resources.Theme theme = context.getTheme(); if (theme != null && theme.resolveAttribute(id, value, true)) { if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT) { return value.data; } else if (value.type == TypedValue.TYPE_STRING) { return context.getResources().getColor(value.resourceId); } } } catch (Exception ignored) { } return defaultValue; }
From source file:net.yanzm.actionbarprogress.ThemeUtils.java
public static int getThemeAttrColor(@NonNull Context context, 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); }/*from ww w. j a v a 2 s . c o m*/ } return 0; }
From source file:eu.power_switch.gui.ThemeHelper.java
/** * Get Color from Theme attribute//from w w w . j ava 2 s .c o m * * @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; }
From source file:com.android.settingslib.RestrictedSwitchPreference.java
public RestrictedSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setWidgetLayoutResource(R.layout.restricted_switch_widget); mHelper = new RestrictedPreferenceHelper(context, this, attrs); if (attrs != null) { final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RestrictedSwitchPreference); final TypedValue useAdditionalSummary = attributes .peekValue(R.styleable.RestrictedSwitchPreference_useAdditionalSummary); if (useAdditionalSummary != null) { mUseAdditionalSummary = (useAdditionalSummary.type == TypedValue.TYPE_INT_BOOLEAN && useAdditionalSummary.data != 0); }//from w ww. j a v a2 s . co m final TypedValue restrictedSwitchSummary = attributes .peekValue(R.styleable.RestrictedSwitchPreference_restrictedSwitchSummary); CharSequence data = null; if (restrictedSwitchSummary != null && restrictedSwitchSummary.type == TypedValue.TYPE_STRING) { if (restrictedSwitchSummary.resourceId != 0) { data = context.getString(restrictedSwitchSummary.resourceId); } else { data = restrictedSwitchSummary.string; } } mRestrictedSwitchSummary = data == null ? null : data.toString(); } if (mRestrictedSwitchSummary == null) { mRestrictedSwitchSummary = context.getString(R.string.disabled_by_admin); } if (mUseAdditionalSummary) { setLayoutResource(R.layout.restricted_switch_preference); useAdminDisabledSummary(false); } }
From source file:org.opensilk.common.ui.util.ThemeUtils.java
public static int getThemeAttrColor(Context context, int attr) { synchronized (sTypedValue) { if (context.getTheme().resolveAttribute(attr, sTypedValue, true)) { if (sTypedValue.type >= TypedValue.TYPE_FIRST_INT && sTypedValue.type <= TypedValue.TYPE_LAST_INT) { return sTypedValue.data; } else if (sTypedValue.type == TypedValue.TYPE_STRING) { return ContextCompat.getColor(context, sTypedValue.resourceId); }/*from ww w . jav a 2 s . c o m*/ } } return 0; }
From source file:com.achep.base.dashboard.DashboardCategory.java
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;//from w ww. j ava2s . c o m } else { title = tv.string; } } sa.recycle(); }
From source file:com.weihuoya.bboo._G.java
public static int getThemeColor(int id, int defaultValue) { TypedValue value = new TypedValue(); try {/* w w w . ja v a2 s . c om*/ Context context = getContext(); Resources.Theme theme = context.getTheme(); if (theme != null && theme.resolveAttribute(id, value, true)) { if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT) { return value.data; } else if (value.type == TypedValue.TYPE_STRING) { ContextCompat.getColor(context, value.resourceId); } } } catch (Exception e) { _G.log(e.toString()); } return defaultValue; }
From source file:com.androzic.Preferences.java
/** * Parse the given XML file as a header description, adding each * parsed Header into the target list.//w w w . j a v a 2 s . c o m * * @param resid * The XML resource to load and parse. * @param target * The list in which the parsed headers should be placed. */ public void loadHeadersFromResource(int resid, List<Header> target) { Androzic application = Androzic.getApplication(); XmlResourceParser parser = null; try { Resources resources = getResources(); parser = resources.getXml(resid); AttributeSet attrs = Xml.asAttributeSet(parser); int type; //noinspection StatementWithEmptyBody while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) { // Parse next until start tag is found } String nodeName = parser.getName(); if (!"preference-headers".equals(nodeName)) { throw new RuntimeException("XML document must start with <preference-headers> tag; found" + nodeName + " at " + parser.getPositionDescription()); } Bundle curBundle = null; final int outerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } nodeName = parser.getName(); if ("header".equals(nodeName)) { Header header = new Header(); TypedArray sa = resources.obtainAttributes(attrs, R.styleable.PreferenceHeader); header.id = sa.getResourceId(R.styleable.PreferenceHeader_id, (int) HEADER_ID_UNDEFINED); TypedValue tv = sa.peekValue(R.styleable.PreferenceHeader_title); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.titleRes = tv.resourceId; } else { header.title = tv.string; } } tv = sa.peekValue(R.styleable.PreferenceHeader_summary); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.summaryRes = tv.resourceId; } else { header.summary = tv.string; } } tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbTitle); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.breadCrumbTitleRes = tv.resourceId; } else { header.breadCrumbTitle = tv.string; } } tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbShortTitle); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.breadCrumbShortTitleRes = tv.resourceId; } else { header.breadCrumbShortTitle = tv.string; } } header.iconRes = sa.getResourceId(R.styleable.PreferenceHeader_icon, 0); header.fragment = sa.getString(R.styleable.PreferenceHeader_fragment); header.help = sa.getResourceId(R.styleable.PreferenceHeader_help, 0); sa.recycle(); if (curBundle == null) { curBundle = new Bundle(); } final int innerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } String innerNodeName = parser.getName(); if (innerNodeName.equals("extra")) { resources.parseBundleExtra(innerNodeName, attrs, curBundle); XmlUtils.skipCurrentTag(parser); } else if (innerNodeName.equals("intent")) { header.intent = Intent.parseIntent(resources, parser, attrs); } else { XmlUtils.skipCurrentTag(parser); } } if (curBundle.size() > 0) { header.fragmentArguments = curBundle; curBundle = null; } if (header.id == R.id.pref_plugins && application.getPluginsPreferences().size() == 0) continue; target.add(header); } else { XmlUtils.skipCurrentTag(parser); } } } catch (XmlPullParserException | IOException e) { throw new RuntimeException("Error parsing headers", e); } finally { if (parser != null) parser.close(); } }
From source file:brut.androlib.res.decoder.ARSCDecoder.java
private ResIntBasedValue readValue() throws IOException, AndrolibException { /* 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.getHTML(data), data) : mPkg.getValueFactory().factory(type, data, null); }