TypedArray getString - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TypedArray getString method.

This code example shows how to use the following methods:getString
        } 
    } 
 
    @Override 
    protected Object onGetDefaultValue(TypedArray a, int index) {
        return a.getString(index);
    } 
 
    protected void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) {
        ringtonePickerIntent.putExtra(
                RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
                onRestoreRingtone()); 
        ringtonePickerIntent.putExtra(
                RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault);
        if (mShowDefault) {
            ringtonePickerIntent.putExtra(
                    RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    RingtoneManager.getDefaultUri(getRingtoneType()));
        } 
        ringtonePickerIntent.putExtra(
7
CodeRank
This code example shows how to use the following methods:getString, peekValue, recycle
    private static final String INTENT_TAG_NAME = "intent";
 
    private static void parseBundleExtra(Resources resources, String tagName, AttributeSet attrs,
                                         Bundle outBundle) throws XmlPullParserException {
        TypedArray sa = resources.obtainAttributes(attrs, R.styleable.Extra);
        String name = sa.getString(R.styleable.Extra_android_name);
        if (name == null) {
            sa.recycle();
            throw new XmlPullParserException("<" + tagName
                    + "> requires an holo:name attribute at " 
                    + attrs.getPositionDescription());
        } 
        TypedValue v = sa.peekValue(R.styleable.Extra_android_value);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                outBundle.putCharSequence(name, cs);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                outBundle.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT

8
CodeRank
This code example shows how to use the following methods:getBoolean, getResourceId, getString, recycle
    public AuthenticatorDescription parseServiceAttributes(Resources res,
            String packageName, AttributeSet attrs) {
        TypedArray sa = res.obtainAttributes(attrs,
                com.android.internal.R.styleable.AccountAuthenticator); 
        try { 
            final String accountType =
                    sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
            final int labelId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_label, 0); 
            final int iconId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_icon, 0); 
            final int smallIconId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0); 
            final int prefId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0); 
            final boolean customTokens = sa.getBoolean(
                    com.android.internal.R.styleable.AccountAuthenticator_customTokens, false); 
            if (TextUtils.isEmpty(accountType)) {
                return null; 
            } 

7
CodeRank
This code example shows how to use the following methods:getResourceId, getString
 
        array.recycle();
    } 
 
    private String getStringOrReference(TypedArray array, int index) {
        String value = array.getString(index);
        if (value == null) {
            int valueResId = array.getResourceId(index, 0);
            if (valueResId == 0)
                return null; 
            else 
                return getContext().getString(valueResId);
        } else { 
            return value;
        } 
    } 
 
 
    @Override 
    protected View onCreateView(ViewGroup parent) {
6
CodeRank
This code example shows how to use the following methods:getString, recycle
 
	public String getString(String attrName) {
		int[] attr = ThemeUtils.getAttributeIds(mContext,
				new String[] { attrName }, mPackageName);
		TypedArray a = mContext.obtainStyledAttributes(mThemeId, attr);
		String s = a.getString(0);
		a.recycle();
		return s;
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getString, hasValue
        public abstract String getString(TypedArray a, int index);
        public abstract int getInt(TypedArray a, int index, int defaultValue);
        public abstract int getFlag(TypedArray a, int index);
 
        protected String parseString(TypedArray a, int index) {
            if (a.hasValue(index)) {
                return KeySpecParser.resolveTextReference(a.getString(index), mTextsSet);
            } 
            return null; 
        } 
 
        protected String[] parseStringArray(TypedArray a, int index) {
            if (a.hasValue(index)) {
                return KeySpecParser.parseCsvString(a.getString(index), mTextsSet);
            } 
            return null; 
        } 
    } 
 
    class EmptyKeyStyle extends KeyStyle { 
5
CodeRank
This code example shows how to use the following methods:getString, recycle
 
    public static final String TAG = "UiUtil";
 
    public static void setCustomFont(View textViewOrButton, Context ctx, AttributeSet attrs, int[] attributeSet, int fontId) {
        TypedArray a = ctx.obtainStyledAttributes(attrs, attributeSet);
        String customFont = a.getString(fontId);
        setCustomFont(textViewOrButton, ctx, customFont);
        a.recycle();
    } 
 
    private static boolean setCustomFont(View textViewOrButton, Context ctx, String asset) {
        if (TextUtils.isEmpty(asset))
            return false; 
        Typeface tf = null;
        try { 
            tf = getFont(ctx, asset);
            if (textViewOrButton instanceof TextView) {
                ((TextView) textViewOrButton).setTypeface(tf);
            } else { 
                ((Button) textViewOrButton).setTypeface(tf);
5
CodeRank
This code example shows how to use the following methods:getString
	/** 
	 * <i>Overridden for internal use!</i> 
	 */ 
	@Override 
	protected Object onGetDefaultValue(TypedArray a, int index) {
		return a.getString(index);
	} 
	 
	/** 
	 * <i>Overridden for internal use!</i> 
	 */ 
	@Override 
	protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
		setText(restoreValue ? getPersistedString(null) : (String) defaultValue);
	} 
	 
	/** 
	 * <i>Overridden for internal use!</i> 
	 */ 
	@Override 
5
CodeRank
This code example shows how to use the following methods:getResourceId, getString
		setOnClickListener(this);
    } 
 
    private int parseColor(final Context context, final TypedArray a, final int index, final int defaultColorRes){
        //try to get as a resource 
        final int resId = a.getResourceId(index,-1);
        if(resId > -1) return context.getResources().getColor(resId);
        //try to get as a hex string 
        final String str = a.getString(index);
        if(null != str) return Color.parseColor(str);
        //return default 
        return context.getResources().getColor(defaultColorRes);
    } 
 
    private Paint backgroundPaint() {
        Paint p = new Paint();
        p.setColor(mTagBackground);
        p.setAntiAlias(true);
        p.setFilterBitmap(true);
        p.setDither(true);
5
CodeRank
This code example shows how to use the following methods:getString, peekValue, recycle
    private static final String INTENT_TAG_NAME = "intent";
 
    private static void parseBundleExtra(Resources resources, String tagName, AttributeSet attrs,
            Bundle outBundle) throws XmlPullParserException {
        TypedArray sa = resources.obtainAttributes(attrs, R.styleable.Extra);
        String name = sa.getString(R.styleable.Extra_name);
        if (name == null) {
            sa.recycle();
            throw new XmlPullParserException("<" + tagName
                    + "> requires an holo:name attribute at " 
                    + attrs.getPositionDescription());
        } 
        TypedValue v = sa.peekValue(R.styleable.Extra_value);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                outBundle.putCharSequence(name, cs);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                outBundle.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT

5
CodeRank

Related TypedArray getString Questions & Answers:

getString Method Overview
Retrieve the string value for the attribute at index.
See Code Examples for other Android TypedArray Methods: