Example usage for android.content.res TypedArray getString

List of usage examples for android.content.res TypedArray getString

Introduction

In this page you can find the example usage for android.content.res TypedArray getString.

Prototype

@Nullable
public String getString(@StyleableRes int index) 

Source Link

Document

Retrieves the string value for the attribute at index.

Usage

From source file:com.satsuware.usefulviews.LabelledSpinner.java

/**
 * Sets up views and widget attributes/*from ww w.  ja  v a2 s  .  c om*/
 *
 * @param context Context passed from constructor
 * @param attrs AttributeSet passed from constructor
 */
private void initializeLayout(Context context, AttributeSet attrs) {
    prepareLayout(context);

    mLabel = (TextView) getChildAt(0);
    mSpinner = (Spinner) getChildAt(1);
    mDivider = getChildAt(2);
    mErrorLabel = (TextView) getChildAt(3);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LabelledSpinner, 0, 0);

    String labelText = a.getString(R.styleable.LabelledSpinner_labelText);
    mWidgetColor = a.getColor(R.styleable.LabelledSpinner_widgetColor,
            ContextCompat.getColor(context, R.color.widget_labelled_spinner_default));

    mLabel.setText(labelText);
    mLabel.setPadding(0, dpToPixels(16), 0, 0);
    mSpinner.setPadding(0, dpToPixels(8), 0, dpToPixels(8));
    mSpinner.setOnItemSelectedListener(this);

    MarginLayoutParams dividerParams = (MarginLayoutParams) mDivider.getLayoutParams();
    dividerParams.rightMargin = dpToPixels(4);
    dividerParams.bottomMargin = dpToPixels(8);
    mDivider.setLayoutParams(dividerParams);

    mLabel.setTextColor(mWidgetColor);
    mDivider.setBackgroundColor(mWidgetColor);

    alignLabelWithSpinnerItem(4);

    final CharSequence[] entries = a.getTextArray(R.styleable.LabelledSpinner_spinnerEntries);
    if (entries != null) {
        setItemsArray(entries);
    }

    mDefaultErrorEnabled = a.getBoolean(R.styleable.LabelledSpinner_defaultErrorEnabled, false);
    mDefaultErrorText = getResources().getString(R.string.widget_labelled_spinner_errorText);

    a.recycle();
}

From source file:io.nuclei.cyto.ui.view.GlideImageView.java

void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlideImageView, defStyleAttr,
            defStyleRes);/* w  w w. j a  v  a2 s.  com*/

    mCircle = a.getBoolean(R.styleable.GlideImageView_circle, false);
    mRatio = a.getFloat(R.styleable.GlideImageView_ratio, 0);
    mRadius = a.getDimensionPixelSize(R.styleable.GlideImageView_radius, 0);
    mPlaceholderId = a.getResourceId(R.styleable.GlideImageView_placeholder, 0);

    String uri = a.getString(R.styleable.GlideImageView_url);
    a.recycle();

    if (uri == null) {
        if (mPlaceholderId > 0) {
            if (mCircle || mRadius > 0) {
                if (mTransformation == null)
                    mTransformation = new CornerTransformation(getContext(), mCircle, mRadius);
                Glide.with(getContext()).load(mPlaceholderId).asBitmap().diskCacheStrategy(getStrategy())
                        .transform(mTransformation).into(this);
            } else
                Glide.with(context).load(mPlaceholderId).into(this);
        }
    } else
        setImageURI(uri);
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticCheckButton.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_round, round);
    bgShape.setCornerRadius(round);//  ww  w .  j a v  a 2  s.co m

    color = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_backgroundColor, color);
    bgShape.setColor(color);

    scale = typedArray.getFloat(R.styleable.ElasticCheckButton_checkbutton_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_duration, duration);

    labelText = typedArray.getString(R.styleable.ElasticCheckButton_checkbutton_labelText);
    view.setText(labelText);

    labelColor = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelColor, labelColor);
    view.setTextColor(labelColor);

    labelSize = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelSize, labelSize);
    view.setTextSize(labelSize);

    labelStyle = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelStyle, labelStyle);

    if (labelStyle == 0)
        view.setTypeface(null, Typeface.NORMAL);
    else if (labelStyle == 1)
        view.setTypeface(null, Typeface.BOLD);
    else if (labelStyle == 2)
        view.setTypeface(null, Typeface.ITALIC);

    alpha = typedArray.getFloat(R.styleable.ElasticCheckButton_checkbutton_alpha, alpha);

    checked = typedArray.getBoolean(R.styleable.ElasticCheckButton_checkbutton_ischecked, checked);
    if (checked)
        view.setAlpha(alpha);
}

From source file:com.facebook.litho.widget.TextSpec.java

private static void resolveStyleAttrsForTypedArray(TypedArray a, Output<TruncateAt> ellipsize,
        Output<Boolean> shouldIncludeFontPadding, Output<Float> spacingMultiplier, Output<Integer> minLines,
        Output<Integer> maxLines, Output<Integer> minEms, Output<Integer> maxEms, Output<Integer> minWidth,
        Output<Integer> maxWidth, Output<Boolean> isSingleLine, Output<CharSequence> text,
        Output<ColorStateList> textColorStateList, Output<Integer> linkColor, Output<Integer> highlightColor,
        Output<Integer> textSize, Output<Alignment> textAlignment, Output<Integer> textStyle,
        Output<Float> shadowRadius, Output<Float> shadowDx, Output<Float> shadowDy, Output<Integer> shadowColor,
        Output<VerticalGravity> verticalGravity) {
    int viewTextAlignment = View.TEXT_ALIGNMENT_GRAVITY;
    int gravity = Gravity.NO_GRAVITY;

    for (int i = 0, size = a.getIndexCount(); i < size; i++) {
        final int attr = a.getIndex(i);

        if (attr == R.styleable.Text_android_text) {
            text.set(a.getString(attr));
        } else if (attr == R.styleable.Text_android_textColor) {
            textColorStateList.set(a.getColorStateList(attr));
        } else if (attr == R.styleable.Text_android_textSize) {
            textSize.set(a.getDimensionPixelSize(attr, 0));
        } else if (attr == R.styleable.Text_android_ellipsize) {
            final int index = a.getInteger(attr, 0);
            if (index > 0) {
                ellipsize.set(TRUNCATE_AT[index - 1]);
            }//  w w  w  .  j  ava  2  s  . c o  m
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
                && attr == R.styleable.Text_android_textAlignment) {
            viewTextAlignment = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
        } else if (attr == R.styleable.Text_android_gravity) {
            gravity = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
            verticalGravity.set(getVerticalGravity(gravity));
        } else if (attr == R.styleable.Text_android_includeFontPadding) {
            shouldIncludeFontPadding.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_minLines) {
            minLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_maxLines) {
            maxLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_singleLine) {
            isSingleLine.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_textColorLink) {
            linkColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textColorHighlight) {
            highlightColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textStyle) {
            textStyle.set(a.getInteger(attr, 0));
        } else if (attr == R.styleable.Text_android_lineSpacingMultiplier) {
            spacingMultiplier.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDx) {
            shadowDx.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDy) {
            shadowDy.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowRadius) {
            shadowRadius.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowColor) {
            shadowColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_minEms) {
            minEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_maxEms) {
            maxEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_minWidth) {
            minWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MIN_WIDTH));
        } else if (attr == R.styleable.Text_android_maxWidth) {
            maxWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MAX_WIDTH));
        }
    }
}

From source file:ru.shmakinv.android.material.widget.CollapsingTextHelper.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Typeface readFontFamilyTypeface(int resId) {
    final TypedArray a = mView.getContext().obtainStyledAttributes(resId,
            new int[] { android.R.attr.fontFamily });
    try {/* w w  w.  j a  va2  s  .  c  o m*/
        final String family = a.getString(0);
        if (family != null) {
            return Typeface.create(family, Typeface.NORMAL);
        }
    } finally {
        a.recycle();
    }
    return null;
}

From source file:com.facebook.LoginButton.java

private void parseAttributes(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_login_view);
    confirmLogout = a.getBoolean(R.styleable.com_facebook_login_view_confirm_logout, true);
    fetchUserInfo = a.getBoolean(R.styleable.com_facebook_login_view_fetch_user_info, true);
    loginText = a.getString(R.styleable.com_facebook_login_view_login_text);
    logoutText = a.getString(R.styleable.com_facebook_login_view_logout_text);
    a.recycle();//  w  w  w  .j a  v  a2 s.com

}

From source file:io.plaidapp.ui.widget.FabOverlapTextView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView);

    float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP,
            getResources().getDisplayMetrics());

    setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT));
    setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0));
    setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0));

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) {
        final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance,
                android.R.style.TextAppearance);
        TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance);
        paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK));
        paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize,
                (int) defaultTextSize));
        if (atp.hasValue(R.styleable.FontTextAppearance_font)) {
            paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font)));
        }/*from   w ww .  j  a  v a2 s  .  c  om*/
        atp.recycle();
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_font)) {
        setFont(a.getString(R.styleable.FabOverlapTextView_font));
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) {
        setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0));
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) {
        setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize,
                (int) defaultTextSize));
    }

    lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0);
    topPaddingHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_topPaddingHint, 0);

    breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy,
            Layout.BREAK_STRATEGY_BALANCED);

    a.recycle();
}

From source file:com.transitionseverywhere.TransitionInflater.java

private void getTargetIds(XmlPullParser parser, AttributeSet attrs, Transition transition)
        throws XmlPullParserException, IOException {

    // Make sure we are on a start tag.
    int type;//from   www  . j  a  v a  2s.  c o  m
    int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        String name = parser.getName();
        if (name.equals("target")) {
            TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TransitionTarget);
            int id = a.getResourceId(R.styleable.TransitionTarget_targetId, 0);
            String transitionName;
            if (id != 0) {
                transition.addTarget(id);
            } else if ((id = a.getResourceId(R.styleable.TransitionTarget_excludeId, 0)) != 0) {
                transition.excludeTarget(id, true);
            } else if ((transitionName = a.getString(R.styleable.TransitionTarget_targetName)) != null) {
                transition.addTarget(transitionName);
            } else if ((transitionName = a.getString(R.styleable.TransitionTarget_excludeName)) != null) {
                transition.excludeTarget(transitionName, true);
            } else {
                String className = a.getString(R.styleable.TransitionTarget_excludeClass);
                try {
                    if (className != null) {
                        Class clazz = Class.forName(className);
                        transition.excludeTarget(clazz, true);
                    } else if ((className = a.getString(R.styleable.TransitionTarget_targetClass)) != null) {
                        Class clazz = Class.forName(className);
                        transition.addTarget(clazz);
                    }
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException("Could not create " + className, e);
                }
            }
            a.recycle();
        } else {
            throw new RuntimeException("Unknown scene name: " + parser.getName());
        }
    }
}

From source file:za.jamie.soundstage.widgets.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);//from   w  ww . j a  v a  2s. c om
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    int typefaceIndex = SANS;
    String tabFontFamily = null;
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);
    tabFontFamily = a.getString(2);
    tabStyleIndex = a.getInt(3, typefaceIndex);
    typefaceIndex = a.getInt(4, typefaceIndex);

    a.recycle();

    setTypefaceFromAttrs(tabFontFamily, typefaceIndex, tabStyleIndex);

    // get custom attrs

    int indicatorColor = 0xFF666666;
    int underlineColor = 0x1A000000;
    int dividerColor = 0x1A000000;

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_indicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_underlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_dividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_indicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_underlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_dividerPadding, dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_tabBackground, tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_shouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_scrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_textAllCaps, textAllCaps);
    tabSelectedTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_selectedTextColor, tabSelectedTextColor);

    a.recycle();

    indicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    indicatorPaint.setStyle(Style.FILL);
    indicatorPaint.setColor(indicatorColor);

    underlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    underlinePaint.setStyle(Style.FILL);
    underlinePaint.setColor(underlineColor);

    dividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    dividerPaint.setStrokeWidth(dividerWidth);
    dividerPaint.setColor(dividerColor);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);
}

From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView);

    float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP,
            getResources().getDisplayMetrics());

    setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT));
    setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0));
    setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0));

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) {
        final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance,
                android.R.style.TextAppearance);
        TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance);
        paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK));
        paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize,
                (int) defaultTextSize));
        if (atp.hasValue(R.styleable.FontTextAppearance_font)) {
            paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font)));
        }/*from  w  ww.  j  a  v a 2s .co  m*/
        atp.recycle();
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_font)) {
        setFont(a.getString(R.styleable.FabOverlapTextView_font));
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) {
        setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0));
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) {
        setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize,
                (int) defaultTextSize));
    }

    lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0);
    unalignedTopPadding = getPaddingTop();
    unalignedBottomPadding = getPaddingBottom();

    breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy,
            Layout.BREAK_STRATEGY_BALANCED);

    a.recycle();
}