Example usage for android.util AttributeSet getStyleAttribute

List of usage examples for android.util AttributeSet getStyleAttribute

Introduction

In this page you can find the example usage for android.util AttributeSet getStyleAttribute.

Prototype

public int getStyleAttribute();

Source Link

Document

Return the value of the "style" attribute or 0 if there is not one.

Usage

From source file:com.facebook.widget.LoginTextView.java

/**
 * Create the LoginButton by inflating from XML
 * /*from w  w  w  .j a v  a  2  s.  com*/
 * @see View#View(Context, AttributeSet)
 */
public LoginTextView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        //         this.setGravity(Gravity.LEFT);
        //         this.setTextColor(getResources().getColor(
        //               R.color.com_facebook_loginview_text_color));
        //         this.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources()
        //               .getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        //         if (isInEditMode()) {
        //            // cannot use a drawable in edit mode, so setting the background
        //            // color instead
        //            // of a background resource.
        //            // this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
        //            // hardcoding in edit mode as getResources().getString() doesn't
        //            // seem to work in IntelliJ
        //            loginText = "Log in with Facebook";
        //         } else {
        //            // this.setBackgroundResource(R.drawable.btn_register_fb);
        //            this.setCompoundDrawablesWithIntrinsicBounds(
        //                  R.drawable.com_facebook_inverse_icon, 0, 0, 0);
        //            this.setCompoundDrawablePadding(getResources()
        //                  .getDimensionPixelSize(
        //                        R.dimen.com_facebook_loginview_compound_drawable_padding));
        //            this.setPadding(
        //                  getResources().getDimensionPixelSize(
        //                        R.dimen.com_facebook_loginview_padding_left),
        //                  getResources().getDimensionPixelSize(
        //                        R.dimen.com_facebook_loginview_padding_top),
        //                  getResources().getDimensionPixelSize(
        //                        R.dimen.com_facebook_loginview_padding_right),
        //                  getResources().getDimensionPixelSize(
        //                        R.dimen.com_facebook_loginview_padding_bottom));
        //         }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }
}

From source file:com.facebook.widget.LoginButtonDefault.java

/**
 * Create the LoginButton by inflating from XML
 * // w w w  .ja v  a  2  s .  com
 * @see View#View(Context, AttributeSet)
 */
public LoginButtonDefault(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background
            // color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't
            // seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(getResources()
                    .getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }
}

From source file:com.chao.facebookzc.widget.LoginButton.java

/**
 * Create the LoginButton by inflating from XML
 *
 * @see android.view.View#View(android.content.Context, android.util.AttributeSet)
 *//* w  w w .  j  a v a2 s  .c o  m*/
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(getResources()
                    .getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }
}

From source file:com.waz.zclient.ui.calling.CallControlButtonView.java

private void init(AttributeSet attrs) {
    setOrientation(VERTICAL);/*from  w  w  w .ja v  a2  s. c  o m*/
    setGravity(Gravity.CENTER);
    setBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));

    int circleIconDimension = 0;
    String circleIconGlyph = "";
    int circleIconStyle = 0;
    String labelText = "";
    int buttonLabelWidth = 0;
    int labelTextSize = 0;
    String labelFont = "";

    if (attrs != null) {
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.CallControlButtonView,
                0, 0);
        circleIconDimension = a.getDimensionPixelSize(R.styleable.CallControlButtonView_circleIconDimension, 0);
        circleIconGlyph = a.getString(R.styleable.CallControlButtonView_circleIconGlyph);
        circleIconStyle = attrs.getStyleAttribute();
        labelText = a.getString(R.styleable.CallControlButtonView_labelText);
        buttonLabelWidth = a.getDimensionPixelSize(R.styleable.CallControlButtonView_labelWidth, 0);
        labelTextSize = a.getDimensionPixelSize(R.styleable.CallControlButtonView_labelTextSize, 0);
        labelFont = a.getString(R.styleable.CallControlButtonView_labelFont);
        a.recycle();
    }

    buttonView = new GlyphTextView(getContext(), null, circleIconStyle);
    buttonView.setLayoutParams(new LayoutParams(circleIconDimension, circleIconDimension));
    buttonView.setText(circleIconGlyph);
    buttonView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimensionPixelSize(R.dimen.wire__icon_button__text_size));
    buttonView.setGravity(Gravity.CENTER);
    if (circleIconStyle == 0) {
        buttonView.setTextColor(new OptionsDarkTheme(getContext()).getTextColorPrimarySelector());
        buttonView.setBackground(
                ContextCompat.getDrawable(getContext(), R.drawable.selector__icon_button__background__calling));
    }
    addView(buttonView);

    buttonLabelView = new TypefaceTextView(getContext(), null, R.attr.callingControlButtonLabel);
    buttonLabelView.setText(labelText);
    buttonLabelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, labelTextSize);
    buttonLabelView.setTypeface(labelFont);
    buttonLabelView.setGravity(Gravity.CENTER);
    if (buttonLabelWidth > 0) {
        addView(buttonLabelView,
                new LinearLayout.LayoutParams(buttonLabelWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
    } else {
        addView(buttonLabelView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    ViewUtils.setMarginTop(buttonLabelView, getContext().getResources()
            .getDimensionPixelSize(R.dimen.calling__controls__button__label__margin_top));
}