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.sxjs.common.widget.percentlayout.PercentLayoutHelper.java

private void supportTextSize(int widthHint, int heightHint, View view, PercentLayoutInfo info) {

    //textsize percent support

    float widthTextSizePercent = info.widthTextSizePercent;
    float heightTextSizePercent = info.heightTextSizePercent;
    float screenWidthSizePercent = info.screenWidthTextSizePercent;
    float textSize = 0f;
    if (widthTextSizePercent != -1f) {
        textSize = widthHint * widthTextSizePercent;
    } else if (heightTextSizePercent != -1f) {
        textSize = heightHint * heightTextSizePercent;
    } else if (screenWidthSizePercent != -1f) {
        textSize = ScreenUtil.getScreenWidth(view.getContext()) * screenWidthSizePercent;
    }/*from ww w .  j  a  va  2 s.  c  om*/

    if (textSize == 0)
        return;
    //Button  EditText TextView?
    if (view instanceof TextView) {
        ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
}

From source file:com.orange.ocara.ui.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//from  w w w  .j  av a  2  s  .c o m
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setBackgroundResource(tabBackgroundResId);
    tab.setTextColor(tabTextColor);
    tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    tab.setAllCaps(true);

    addTab(position, tab);
}

From source file:com.discord.chipsview.ChipsView.java

private void init() {
    mDensity = getResources().getDisplayMetrics().density;

    mChipsContainer = new RelativeLayout(getContext());
    addView(mChipsContainer);/*from   ww  w .ja va2s .co  m*/

    // Dummy item to prevent AutoCompleteTextView from receiving focus
    LinearLayout linearLayout = new LinearLayout(getContext());
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(0, 0);
    linearLayout.setLayoutParams(params);
    linearLayout.setFocusable(true);
    linearLayout.setFocusableInTouchMode(true);

    mChipsContainer.addView(linearLayout);

    mEditText = new ChipsEditText(getContext(), this);

    final int chipHeightWithPadding = (int) ((CHIP_HEIGHT * mDensity) + mVerticalSpacing);

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, chipHeightWithPadding);
    layoutParams.leftMargin = (int) (5 * mDensity);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mEditText.setLayoutParams(layoutParams);
    mEditText.setPadding(0, 0, 0, mVerticalSpacing);
    mEditText.setBackgroundColor(Color.argb(0, 0, 0, 0));
    mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    mEditText.setInputType(InputType.TYPE_CLASS_TEXT);
    mEditText.setTextColor(mChipsSearchTextColor);
    mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mChipsSearchTextSize);

    mChipsContainer.addView(mEditText);

    mRootChipsLayout = new ChipsVerticalLinearLayout(getContext(), chipHeightWithPadding);
    mRootChipsLayout.setOrientation(LinearLayout.VERTICAL);
    mRootChipsLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mRootChipsLayout.setPadding(0, (int) (SPACING_TOP * mDensity), 0, 0);
    mChipsContainer.addView(mRootChipsLayout);

    initListener();
    onChipsChanged(false);
}

From source file:com.mci.firstidol.view.ActionSheet.java

@SuppressWarnings("deprecation")
private void createItems() {
    String[] titles = getOtherButtonTitles();
    if (titles != null) {
        for (int i = 0; i < titles.length; i++) {
            Button bt = new Button(getActivity());
            bt.setId(CANCEL_BUTTON_ID + i + 1);
            bt.setOnClickListener(this);
            bt.setBackgroundDrawable(getOtherButtonBg(titles, i));
            bt.setText(titles[i]);//from w w  w. j  av a 2s . co  m
            bt.setTextColor(mAttrs.otherButtonTextColor);
            bt.setTextSize(TypedValue.COMPLEX_UNIT_PX, mAttrs.actionSheetTextSize);
            if (i > 0) {
                LinearLayout.LayoutParams params = createButtonLayoutParams();
                params.topMargin = mAttrs.otherButtonSpacing;
                mPanel.addView(bt, params);
            } else {
                mPanel.addView(bt);
            }
        }
    }
    Button bt = new Button(getActivity());
    bt.getPaint().setFakeBoldText(true);
    bt.setTextSize(TypedValue.COMPLEX_UNIT_PX, mAttrs.actionSheetTextSize);
    bt.setId(ActionSheet.CANCEL_BUTTON_ID);
    bt.setBackgroundDrawable(mAttrs.cancelButtonBackground);
    bt.setText(getCancelButtonTitle());
    bt.setTextColor(mAttrs.cancelButtonTextColor);
    bt.setOnClickListener(this);
    LinearLayout.LayoutParams params = createButtonLayoutParams();
    params.topMargin = mAttrs.cancelButtonMarginTop;
    mPanel.addView(bt, params);

    mPanel.setBackgroundDrawable(mAttrs.background);
    mPanel.setPadding(mAttrs.padding, mAttrs.padding, mAttrs.padding, mAttrs.padding);
}

From source file:pl.motyczko.scrollheader.PagerSlidingTabStrip.java

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

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

    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_PX, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
    tabStripHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabStripHeight, dm);
    mMinHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinHeight, dm);
    mIconSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIconSize, dm);
    mStrokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mStrokeWidth, dm);
    mShadowRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mShadowRadius, dm);
    mActionBarIconSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mActionBarIconSize, dm);

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

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    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);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_tabTextColor, tabTextColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_indicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_underlineHeight,
            underlineHeight);
    tabStripHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabStripHeight, tabStripHeight);
    mMinHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_android_minHeight, mMinHeight);
    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);
    mBlurBackground = a.getBoolean(R.styleable.PagerSlidingTabStrip_blurBackground, mBlurBackground);
    mKenBurnsEffect = a.getBoolean(R.styleable.PagerSlidingTabStrip_kenBurnsEffect, mKenBurnsEffect);
    mParallaxForBackground = a.getBoolean(R.styleable.PagerSlidingTabStrip_parallaxEffect,
            mParallaxForBackground);
    mIconSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_iconSize, mIconSize);
    mIconTopOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_iconTopOffset, mIconTopOffset);
    mIcon = a.getDrawable(R.styleable.PagerSlidingTabStrip_android_icon);
    mFrameColor = a.getColor(R.styleable.PagerSlidingTabStrip_frameColor, mFrameColor);
    mStrokeWidth = a.getDimension(R.styleable.PagerSlidingTabStrip_strokeWidth, mStrokeWidth);
    mFrameShadowColor = a.getColor(R.styleable.PagerSlidingTabStrip_frameShadowColor, mFrameShadowColor);
    mShadowRadius = a.getDimension(R.styleable.PagerSlidingTabStrip_shadowRadius, mShadowRadius);
    mHighlightColor = a.getColor(R.styleable.PagerSlidingTabStrip_highlightColor, mHighlightColor);
    mOverlayColorCollapsed = a.getColor(R.styleable.PagerSlidingTabStrip_overlayColorCollapsed,
            mOverlayColorCollapsed);
    mOverlayColorExpanded = a.getColor(R.styleable.PagerSlidingTabStrip_overlayColorExpanded,
            mOverlayColorExpanded);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

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

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    HorizontalScrollView.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, tabStripHeight);
    lp.gravity = Gravity.BOTTOM;
    tabsContainer.setLayoutParams(lp);
    addView(tabsContainer);

    setupIcon();

    a.recycle();
    mPageScrollHelper = new PageScrollHelper(this);
    mPageScrollHelper.setPageScrollListener(mPageScrollListener);

    setupBackground();
}

From source file:com.spt.carengine.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 .  j a v  a2  s. c  o  m
    }
}

From source file:com.android.contacts.common.list.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    View tabView;//  w ww.j a  v a  2s .  c om
    if (mTabIcons != null && position < mTabIcons.length) {
        View layout = LayoutInflater.from(getContext()).inflate(R.layout.unread_count_tab, null);
        View iconView = layout.findViewById(R.id.icon);
        iconView.setBackgroundResource(mTabIcons[position]);
        iconView.setContentDescription(tabTitle);
        TextView textView = (TextView) layout.findViewById(R.id.count);
        if (mUnreadCounts != null && mUnreadCounts[position] > 0) {
            textView.setText(Integer.toString(mUnreadCounts[position]));
            textView.setVisibility(View.VISIBLE);
            iconView.setContentDescription(
                    getResources().getQuantityString(R.plurals.tab_title_with_unread_items,
                            mUnreadCounts[position], tabTitle.toString(), mUnreadCounts[position]));
        } else {
            textView.setVisibility(View.INVISIBLE);
            iconView.setContentDescription(tabTitle);
        }
        tabView = layout;
    } else {
        final TextView textView = new TextView(getContext());
        textView.setText(tabTitle);
        textView.setBackgroundResource(R.drawable.view_pager_tab_background);

        // Assign various text appearance related attributes to child views.
        if (mTextStyle > 0) {
            textView.setTypeface(textView.getTypeface(), mTextStyle);
        }
        if (mTextSize > 0) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
        }
        if (mTextColor != null) {
            textView.setTextColor(mTextColor);
        }
        textView.setAllCaps(mTextAllCaps);
        textView.setGravity(Gravity.CENTER);

        tabView = textView;
    }

    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    tabView.setOnLongClickListener(new OnTabLongClickListener(position));

    tabView.setPadding(mSidePadding, 0, mSidePadding, 0);

    mTabStrip.addView(tabView, position,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));

    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        tabView.setSelected(true);
    }
}

From source file:com.mickledeals.views.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)}.//  w  ww  . j  ava  2  s  .  com
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            context.getResources().getDimensionPixelSize(R.dimen.sp_17));
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(Color.argb((int) (MIN_TEXT_ALPHA * 255), 255, 255, 255));
    textView.setBackgroundResource(R.drawable.selector_bg);

    //        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);
    //            textView.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
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:org.cnc.mombot.utils.ContactsEditText.java

private View createContactTextView(String text) {
    TextView tv = new TextView(getContext());
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            getContext().getResources().getDimension(R.dimen.common_textsize_larger));
    tv.setText(text);// w ww . ja va  2s .c  o  m
    tv.setBackgroundResource(R.drawable.img_bg_notify_blue);
    tv.setTextColor(Color.WHITE);
    return tv;
}

From source file:com.yooiistudios.newskit.ui.widget.viewpager.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   ww w .  j  a  v a2 s  .com
 */
protected TextView createDefaultTabView(Context context) {
    //  ? 48dp 
    TextView textView = new TextView(context);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            getResources().getDimensionPixelSize(R.dimen.news_select_sliding_tab_height)));
    textView.setGravity(Gravity.CENTER);

    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);
        textView.setBackgroundResource(outValue.resourceId);
    }

    // TextAppearance_Body2 -> sans-serif-medium, 14sp
    // ? ? ?? 
    textView.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Body2);
    textView.setTextColor(getResources().getColor(R.color.news_select_disabled_text_color)); // black with opacity 54%

    if (Display.isTablet(getContext())) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimensionPixelSize(R.dimen.text_size_subhead_material));
    } else {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimensionPixelSize(R.dimen.text_size_body_2_material));
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);

    if (Display.isTablet(getContext())) {
        padding *= 1.5;
    }
    textView.setPadding(padding, 0, padding, 0);

    return textView;
}