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.facebook.FacebookButtonBase.java

private void parseTextAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    final int colorResources[] = { android.R.attr.textColor, };
    final TypedArray colorAttrs = context.getTheme().obtainStyledAttributes(attrs, colorResources, defStyleAttr,
            defStyleRes);/*from ww  w.j  ava  2 s  . c  o  m*/
    try {
        setTextColor(colorAttrs.getColor(0, Color.WHITE));
    } finally {
        colorAttrs.recycle();
    }
    final int gravityResources[] = { android.R.attr.gravity, };
    final TypedArray gravityAttrs = context.getTheme().obtainStyledAttributes(attrs, gravityResources,
            defStyleAttr, defStyleRes);
    try {
        setGravity(gravityAttrs.getInt(0, Gravity.CENTER));
    } finally {
        gravityAttrs.recycle();
    }
    final int attrsResources[] = { android.R.attr.textSize, android.R.attr.textStyle, android.R.attr.text, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, a.getDimensionPixelSize(0, 0));
        setTypeface(Typeface.defaultFromStyle(a.getInt(1, Typeface.BOLD)));
        setText(a.getString(2));
    } finally {
        a.recycle();
    }
}

From source file:com.landenlabs.all_devtool.NumBaseFragment.java

protected void addNum(String name, int attrId, String numType) {
    int[] attrs = { attrId };
    TypedArray typedArray = m_context.getTheme().obtainStyledAttributes(attrs);
    String str = "";

    if (typedArray != null) {
        TypedValue typedValue = new TypedValue();

        try {//from  w w w.  ja  v a  2 s.  c  o m
            str = "???";
            int cnt = typedArray.getIndexCount();
            for (int idx = 0; idx != cnt; idx++) {
                int attrIdx = typedArray.getIndex(idx);
                str = typedArray.getString(attrIdx);

                int refId = typedArray.getResourceId(attrIdx, -1);
                if (refId != -1 && refId != attrId) {
                    addNum(name, refId, numType);
                }

                if (TextUtils.isEmpty(str)) {
                    float val = typedArray.getDimension(0, -1);
                    if (val != -1)
                        str = String.valueOf(val);
                }
                if (!TextUtils.isEmpty(str))
                    m_list.add(new NumInfo(name, str, numType));
            }
            if (cnt == 0) {
                if (m_context.getTheme().resolveAttribute(attrId, typedValue, true)) {
                    str = (String) typedValue.coerceToString();
                    m_list.add(new NumInfo(name, str, numType));
                }
            }
        } catch (Exception ex) {
            m_log.e("peekValue", ex);
        }

        typedArray.recycle();
    }
}

From source file:ru.tinkoff.acquiring.sdk.views.KeyView.java

private void applyAttrs(AttributeSet attrs) {
    if (attrs == null) {
        return;/*from  www .  j av a  2 s .  c o m*/
    }

    final TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.KeyView, 0, 0);

    try {
        keyCode = a.getInt(R.styleable.KeyView_keyCode, -1);

        final float textSize = a.getDimension(R.styleable.KeyView_keyTextSize, -1.F);
        if (textSize != -1.F) {
            contentPaint.setTextSize(dpToPx(textSize));
        }

        final String fontFamily = a.getString(R.styleable.KeyView_keyTextFontFamily);
        if (fontFamily != null) {
            contentPaint.setTypeface(Typeface.create(fontFamily, Typeface.NORMAL));
        }

        contentText = a.getString(R.styleable.KeyView_keyText);
        if (contentText != null) {
            textWidth = contentPaint.measureText(contentText);
        }

        final int imageDrawableId = a.getResourceId(R.styleable.KeyView_keyImage, -1);
        if (imageDrawableId != -1) {
            contentImage = BitmapFactory.decodeResource(getResources(), imageDrawableId);
        }

        final int textColor = a.getColor(R.styleable.KeyView_keyTextColor, contentPaint.getColor());
        contentPaint.setColor(textColor);

        final int circleColor = a.getColor(R.styleable.KeyView_keyCircleColor, circlePaint.getColor());
        circlePaint.setColor(circleColor);
    } finally {
        a.recycle();
    }
}

From source file:paulscode.android.mupen64plusae.preference.SeekBarPreference.java

/**
 * Constructor//  w w w.  ja  v a 2  s.c o  m
 *
 * @param context The {@link Context} this SeekBarPreference is being used in.
 * @param attrs   A collection of attributes, as found associated with a tag in an XML document.
 */
public SeekBarPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Get the attributes from the XML file, if provided
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekBarPreference);
    setMinValue(a.getInteger(R.styleable.SeekBarPreference_minimumValue, DEFAULT_MIN));
    setMaxValue(a.getInteger(R.styleable.SeekBarPreference_maximumValue, DEFAULT_MAX));
    setStepSize(a.getInteger(R.styleable.SeekBarPreference_stepSize, DEFAULT_STEP));
    setUnits(a.getString(R.styleable.SeekBarPreference_units));
    setSaveType(a.getString(R.styleable.SeekBarPreference_saveType));

    a.recycle();

    // Setup the layout
    setDialogLayoutResource(R.layout.seek_bar_preference);

    setOnPreferenceChangeListener(null);
}

From source file:im.ene.lab.design.widget.swipecards.TinderView.java

public TinderView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StackView, defStyle, 0);
    MAX_VISIBLE = a.getInt(R.styleable.StackView_max_visible_children, MAX_VISIBLE);
    MIN_ADAPTER_STACK = a.getInt(R.styleable.StackView_min_adapter_stack, MIN_ADAPTER_STACK);
    ROTATION_DEGREES = a.getFloat(R.styleable.StackView_rotation_degrees, ROTATION_DEGREES);
    String layoutStyle = a.getString(R.styleable.StackView_layout_style);
    a.recycle();/*from ww w.j  a  v a 2s .c o  m*/

    Style style = parseStyle(context, attrs, layoutStyle);
    mStyle = style == null ? new SimpleStyle() : style;
}

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

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

    round = typedArray.getInt(R.styleable.ElasticButton_button_round, round);
    bgShape.setCornerRadius(round);/*w  w w .ja  v  a  2s  .c  o  m*/

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

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

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

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

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

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

    labelStyle = typedArray.getInt(R.styleable.ElasticButton_button_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);
}

From source file:com.github.czy1121.view.CornerLabelView.java

public void init(Context context, AttributeSet attrs) {

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CornerLabelView);

    mPaddingTop = ta.getDimension(R.styleable.CornerLabelView_clvPaddingTop, dp2px(10));
    mPaddingCenter = ta.getDimension(R.styleable.CornerLabelView_clvPaddingCenter, dp2px(0));
    mPaddingBottom = ta.getDimension(R.styleable.CornerLabelView_clvPaddingBottom, dp2px(3));

    mText1.text = ta.getString(R.styleable.CornerLabelView_clvText1);
    mText1.height = ta.getDimension(R.styleable.CornerLabelView_clvText1Height, dp2px(12));
    mText1.color = ta.getColor(R.styleable.CornerLabelView_clvText1Color, 0xffffffff);
    mText1.init();//from   ww w. ja va 2s . c  o m
    mText1.reset();

    mText2.text = ta.getString(R.styleable.CornerLabelView_clvText2);
    mText2.height = ta.getDimension(R.styleable.CornerLabelView_clvText2Height, dp2px(8));
    mText2.color = ta.getColor(R.styleable.CornerLabelView_clvText2Color, 0x66ffffff);
    mText2.init();
    mText2.reset();

    int fillColor = ta.getColor(R.styleable.CornerLabelView_clvFillColor, 0x66000000);
    int flags = ta.getInteger(R.styleable.CornerLabelView_clvFlags, 0);

    ta.recycle();

    mIsLeft = (flags & 1) == 0;
    mIsTop = (flags & 2) == 0;
    mIsTriangle = (flags & 4) > 0;

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
    mPaint.setAntiAlias(true);
    mPaint.setColor(fillColor);

}

From source file:org.catrobat.paintroid.WelcomeActivity.java

private void getStyleAttributesFromXml() {
    final DisplayMetrics metrics = getBaseContext().getResources().getDisplayMetrics();
    for (TapTargetStyle text : TapTargetStyle.values()) {
        TypedArray attribute = obtainStyledAttributes(text.getResourceId(), R.styleable.IntroAttributes);

        int textSizeDp = (int) attribute.getDimension(R.styleable.IntroAttributes_android_textSize, 16);
        int textStyle = attribute.getInt(R.styleable.IntroAttributes_android_textStyle, 0);
        int color = attribute.getColor(R.styleable.IntroAttributes_android_textColor, Color.WHITE);
        String fontFamilyName = attribute.getString(R.styleable.IntroAttributes_android_fontFamily);
        Typeface typeface = Typeface.create(fontFamilyName, textStyle);

        text.setTextColor(color);/*from ww w .  j  a v a2s. c  om*/
        text.setTextSize(getSpFromDimension(textSizeDp, metrics));
        text.setTypeface(typeface);

        attribute.recycle();

    }
}

From source file:ch.bretscherhochstrasser.android.stickyviewpager.StickyViewPager.java

private void readAttributes(final Context context, final AttributeSet attrs) {
    final TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.StickyViewPager);

    for (int i = 0; i < styledAttributes.getIndexCount(); ++i) {
        final int attr = styledAttributes.getIndex(i);
        if (attr == R.styleable.StickyViewPager_swipeMarginWidth) {
            swipeMarginWidth = styledAttributes.getDimensionPixelSize(attr, swipeMarginWidth);
        } else if (attr == R.styleable.StickyViewPager_stickyPositions) {
            addStickyPositions(styledAttributes.getString(attr));
        }/*from w  ww .ja va  2  s. c  o m*/
    }
    styledAttributes.recycle();
}

From source file:com.farbod.labelledspinner.LabelledSpinner.java

private void setUpLayout(Context context, AttributeSet attrs) {
    prepareLayout(context);/*w  ww.  j  a  v  a  2s .  c  o  m*/

    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_entries);
    if (entries != null) {
        setItemsArray(entries);
    }

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

    a.recycle();
}