Java Code Examples for android.util.AttributeSet#getStyleAttribute()

The following examples show how to use android.util.AttributeSet#getStyleAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginoutButton.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
/**
 * 加载默认的样式(蓝色)。
 * 
 * @param attrs XML 属性集合对象
 */
private void loadDefaultStyle(AttributeSet attrs) {
	if (attrs != null && 0 == attrs.getStyleAttribute()) {
		Resources res = getResources();
		this.setBackgroundResource(R.drawable.com_sina_weibo_sdk_button_blue);
		this.setPadding(res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_left),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_top),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_right),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_bottom));
		this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_com_sina_weibo_sdk_logo, 0, 0, 0);
		this.setCompoundDrawablePadding(
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_compound_drawable_padding));
        this.setTextColor(res.getColor(R.color.com_sina_weibo_sdk_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
        		res.getDimension(R.dimen.com_sina_weibo_sdk_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        this.setGravity(Gravity.CENTER);
        this.setText(R.string.com_sina_weibo_sdk_login_with_weibo_account);
	}
}
 
Example 2
Source File: LoginoutButton.java    From Simpler with Apache License 2.0 6 votes vote down vote up
/**
 * 加载默认的样式(蓝色)。
 * 
 * @param attrs XML 属性集合对象
 */
private void loadDefaultStyle(AttributeSet attrs) {
	if (attrs != null && 0 == attrs.getStyleAttribute()) {
		Resources res = getResources();
		this.setBackgroundResource(R.drawable.com_sina_weibo_sdk_button_blue);
		this.setPadding(res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_left),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_top),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_right),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_bottom));
		this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_com_sina_weibo_sdk_logo, 0, 0, 0);
		this.setCompoundDrawablePadding(
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_compound_drawable_padding));
        this.setTextColor(res.getColor(R.color.com_sina_weibo_sdk_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
        		res.getDimension(R.dimen.com_sina_weibo_sdk_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        this.setGravity(Gravity.CENTER);
        this.setText(R.string.com_sina_weibo_sdk_login_with_weibo_account);
	}
}
 
Example 3
Source File: Ui.java    From Genius-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Get Background color if the attr is color value
 *
 * @param context Context
 * @param attrs   AttributeSet
 * @return Color
 */
public static int getBackgroundColor(Context context, AttributeSet attrs) {
    int color = Color.TRANSPARENT;

    if (isHaveAttribute(attrs, "background")) {
        int styleId = attrs.getStyleAttribute();
        int[] attributesArray = new int[]{android.R.attr.background};

        try {
            TypedArray typedArray = context.obtainStyledAttributes(styleId, attributesArray);
            if (typedArray.length() > 0)
                color = typedArray.getColor(0, color);
            typedArray.recycle();
        } catch (Resources.NotFoundException e) {
            e.printStackTrace();
        }
    }

    return color;
}
 
Example 4
Source File: LoginButton.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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.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.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));
        this.setWidth(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_width));
        this.setHeight(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_height));
        this.setGravity(Gravity.CENTER);
        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";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_loginbutton_blue);
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
Example 5
Source File: LoginButton.java    From KlyphMessenger with MIT License 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 6
Source File: LoginButton.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 7
Source File: LoginButton.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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.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.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));
        this.setWidth(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_width));
        this.setHeight(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_height));
        this.setGravity(Gravity.CENTER);
        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";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_loginbutton_blue);
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
Example 8
Source File: LoginButton.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 9
Source File: LoginButton.java    From android-skeleton-project with MIT License 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 10
Source File: LoginButton.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 11
Source File: LoginButton.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 12
Source File: LoginButton.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 13
Source File: LoginButton.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
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);
    }        
}
 
Example 14
Source File: BadgeDrawableTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private TypedArray getTypedArray(@XmlRes int xmlId) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, xmlId, "badge");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = R.style.Widget_MaterialComponents_Badge;
  }
  return context
      .getTheme()
      .obtainStyledAttributes(attrs, R.styleable.Badge, R.attr.badgeStyle, style);
}
 
Example 15
Source File: ProcessCardView.java    From leanback-extensions with Apache License 2.0 5 votes vote down vote up
private static int getIconCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
	int style = attrs == null ? 0 : attrs.getStyleAttribute();

	if (style == 0) {
		TypedArray styledAttrs = context.obtainStyledAttributes(R.styleable.ProcessCardView);
		style = styledAttrs.getResourceId(R.styleable.ProcessCardView_process_theme, 0);
		styledAttrs.recycle();
	}

	return style;
}
 
Example 16
Source File: LoadingCardView.java    From leanback-extensions with Apache License 2.0 5 votes vote down vote up
private static int getLoadingCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
	int style = attrs == null ? 0 : attrs.getStyleAttribute();

	if (style == 0) {
		TypedArray styledAttrs = context.obtainStyledAttributes(R.styleable.LoadingCardView);
		style = styledAttrs.getResourceId(R.styleable.LoadingCardView_loading_theme, 0);
		styledAttrs.recycle();
	}

	return style;
}
 
Example 17
Source File: IconCardView.java    From leanback-extensions with Apache License 2.0 5 votes vote down vote up
private static int getIconCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
	int style = attrs == null ? 0 : attrs.getStyleAttribute();

	if (style == 0) {
		TypedArray styledAttrs = context.obtainStyledAttributes(R.styleable.IconCardView);
		style = styledAttrs.getResourceId(R.styleable.IconCardView_icon_theme, 0);
		styledAttrs.recycle();
	}

	return style;
}
 
Example 18
Source File: FlatTextView.java    From GreenDamFileExploere with Apache License 2.0 4 votes vote down vote up
private void init(AttributeSet attrs) {

        if (attributes == null)
            attributes = new Attributes(this, getResources());

        if (attrs != null) {

            // getting android default tags for textColor and textColorHint
            String textColorAttribute = attrs.getAttributeValue(FlatUI.androidStyleNameSpace, "textColor");
            int styleId = attrs.getStyleAttribute();
            int[] attributesArray = new int[] { android.R.attr.textColor };
            TypedArray styleTextColorTypedArray = getContext().obtainStyledAttributes(styleId, attributesArray);
            // color might have values from the entire integer range, so to find
            // out if there is any color set,
            // checking if default value is returned is not enough. Thus we get
            // color with two different
            // default values - if returned value is the same, it means color is
            // set
            int styleTextColor1 = styleTextColorTypedArray.getColor(0, -1);
            int styleTextColor2 = styleTextColorTypedArray.getColor(0, 1);
            hasOwnTextColor = textColorAttribute != null || styleTextColor1 == styleTextColor2;
            styleTextColorTypedArray.recycle();

            TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatTextView);

            // getting common attributes
            int customTheme = a.getResourceId(R.styleable.fl_FlatTextView_fl_theme, Attributes.DEFAULT_THEME);
            attributes.setThemeSilent(customTheme, getResources());

            attributes.setFontFamily(a.getString(R.styleable.fl_FlatTextView_fl_fontFamily));
            attributes.setFontWeight(a.getString(R.styleable.fl_FlatTextView_fl_fontWeight));
            attributes.setFontExtension(a.getString(R.styleable.fl_FlatTextView_fl_fontExtension));

            attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatTextView_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
            attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatTextView_fl_borderWidth, 0));

            // getting view specific attributes
            textColor = a.getInt(R.styleable.fl_FlatTextView_fl_textColor, textColor);
            backgroundColor = a.getInt(R.styleable.fl_FlatTextView_fl_backgroundColor, backgroundColor);
            customBackgroundColor = a.getInt(R.styleable.fl_FlatTextView_fl_customBackgroundColor, customBackgroundColor);

            a.recycle();
        }

        GradientDrawable gradientDrawable = new GradientDrawable();
        if (backgroundColor != Attributes.INVALID) {
            gradientDrawable.setColor(attributes.getColor(backgroundColor));
        } else if (customBackgroundColor != Attributes.INVALID) {
            gradientDrawable.setColor(customBackgroundColor);
        } else {
            gradientDrawable.setColor(Color.TRANSPARENT);
        }
        gradientDrawable.setCornerRadius(attributes.getRadius());
        gradientDrawable.setStroke(attributes.getBorderWidth(), attributes.getColor(textColor));
        setBackgroundDrawable(gradientDrawable);

        // setting the text color only if there is no android:textColor
        // attribute used
        if (!hasOwnTextColor)
            setTextColor(attributes.getColor(textColor));

        // check for IDE preview render
        if (!this.isInEditMode()) {
            Typeface typeface = FlatUI.getFont(getContext(), attributes);
            if (typeface != null)
                setTypeface(typeface);
        }
    }
 
Example 19
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a ChipDrawable from the given XML resource. All attributes from {@link
 * R.styleable#Chip} and a custom <code>style</code> attribute are supported. A chip resource may
 * look like:
 *
 * <pre>{@code
 * <chip
 *     xmlns:app="http://schemas.android.com/apk/res-auto"
 *     style="@style/Widget.MaterialComponents.Chip.Entry"
 *     app:chipIcon="@drawable/custom_icon"/>
 * }</pre>
 */
@NonNull
public static ChipDrawable createFromResource(@NonNull Context context, @XmlRes int id) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, id, "chip");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = R.style.Widget_MaterialComponents_Chip_Entry;
  }
  return createFromAttributes(context, attrs, R.attr.chipStandaloneStyle, style);
}
 
Example 20
Source File: BadgeDrawable.java    From material-components-android with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a BadgeDrawable from the given XML resource. All attributes from {@link
 * R.styleable#Badge} and a custom <code>style</code> attribute are supported. A badge resource
 * may look like:
 *
 * <pre>{@code
 * <badge
 *     xmlns:app="http://schemas.android.com/apk/res-auto"
 *     style="@style/Widget.MaterialComponents.Badge"
 *     app:maxCharacterCount="2"/>
 * }</pre>
 */
@NonNull
public static BadgeDrawable createFromResource(@NonNull Context context, @XmlRes int id) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, id, "badge");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = DEFAULT_STYLE;
  }
  return createFromAttributes(context, attrs, DEFAULT_THEME_ATTR, style);
}