Example usage for android.util TypedValue COMPLEX_UNIT_PX

List of usage examples for android.util TypedValue COMPLEX_UNIT_PX

Introduction

In this page you can find the example usage for android.util TypedValue COMPLEX_UNIT_PX.

Prototype

int COMPLEX_UNIT_PX

To view the source code for android.util TypedValue COMPLEX_UNIT_PX.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is raw pixels.

Usage

From source file:com.sina.weibo.sdk.widget.LoginButton1.java

/**
 * //from ww  w  .  j  a va2  s .  c om
 *
 * @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_withweb);
    }
}

From source file:com.myteammanager.ui.views.LoginButton.java

/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 *//*from w ww .ja  v a  2 s .c om*/
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);

        parseAttributes(attrs);
        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);
            initializeActiveSessionWithCachedToken(context);
        }
    }
}

From source file:unsorted.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        //v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);
            tab.setLayoutParams(defaultTabLayoutParams);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }/*from w  w w .j  a v  a  2 s  . c o m*/
            }
        }
    }

}

From source file:com.trk.aboutme.facebook.widget.LoginButton.java

/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 *///  w w w. j a va2  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.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);
    }
}

From source file:com.jfeinstein.jazzyviewpager.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        if (tabBackgroundResId != -1) {
            v.setBackgroundResource(tabBackgroundResId);
        }/* w  w w. j  av  a 2 s  .  co  m*/

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case
            // is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.example.percentlayout.view.PercentLayoutHelper.java

private void supportTextSize(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
    //textsize percent support
    if (view instanceof TextView) {
        PercentLayoutInfo.PercentVal textSizePercent = info.textSizePercent;
        if (textSizePercent != null) {
            int base = textSizePercent.isBaseWidth ? widthHint : heightHint;
            float textSize = (int) (base * textSizePercent.percent);
            ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }/* w w  w .  ja v a  2  s . c  o m*/
    }
}

From source file:com.mn.tiger.widget.viewpager.TGPagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);

        if (tabBackgroundResId > 0) {
            v.setBackgroundResource(tabBackgroundResId);
        }/*from w  ww .  j  av a  2  s .  co m*/

        v.setPadding(tabPaddingLeftRight, tabPaddingTop, tabPaddingLeftRight, tabPaddingBottom);

        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case
            // is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }
}

From source file:com.huyn.demogroup.relativetop.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }/*  w w w.  j a v  a  2s  .c  om*/
            }
        } else if (v instanceof LinearLayout) {

            TextView tab = (TextView) v.findViewWithTag("TEXT");
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.luckybuy.ctrls.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from www.  j  a  v a2s . co  m*/
 */
protected RadioButton createDefaultTabView(Context context) {
    RadioButton rbTab = new RadioButton(context);
    rbTab.setGravity(Gravity.CENTER);
    rbTab.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabTextSize);
    rbTab.setTypeface(Typeface.DEFAULT_BOLD);
    rbTab.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
    if (mTabLayoutEven) {
        LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(0,
                ViewGroup.LayoutParams.MATCH_PARENT, 1);
        rbTab.setLayoutParams(layoutParams);
    }
    if (mTabColorStateList != -1) {
        rbTab.setTextColor(getResources().getColorStateList(mTabColorStateList));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        rbTab.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        rbTab.setAllCaps(true);
    }

    int padding = (int) (mTabTextPadding * getResources().getDisplayMetrics().density);
    rbTab.setPadding(padding, 0, padding, 0);

    return rbTab;
}

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

/**
 * Create the LoginButton by inflating from XML
 * //  ww w  .j a  v  a  2  s  .c om
 * @see View#View(Context, AttributeSet)
 */
public NoBGLoginButton(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(android.R.color.white);
            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);
    }
}