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:odoo.controls.OSelectionField.java

private void createRadioGroup() {
    final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    if (mRadioGroup == null) {
        mRadioGroup = new RadioGroup(mContext);
        mRadioGroup.setLayoutParams(params);
    } else {/*w w  w .  j  a v  a2  s .  c  o m*/
        removeView(mRadioGroup);
    }
    mRadioGroup.removeAllViews();
    mRadioGroup.setOnCheckedChangeListener(this);
    for (ODataRow label : items) {
        RadioButton rdoBtn = new RadioButton(mContext);
        rdoBtn.setLayoutParams(params);
        rdoBtn.setText(label.getString(mModel.getDefaultNameColumn()));
        if (textSize > -1) {
            rdoBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            rdoBtn.setTextAppearance(mContext, appearance);
        }
        rdoBtn.setTextColor(textColor);
        mRadioGroup.addView(rdoBtn);
    }
    addView(mRadioGroup);
}

From source file:com.example.view.astuetz.PagerSlidingTabStrip.java

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

    setFillViewport(true);/*www.  j av a  2  s  .  c  om*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);
    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);
    tabPaddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingTop, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
    notiTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, notiTextSize, 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);
    //
    //      showUnderline = a.getInt(R.styleable.PagerSlidingTabStrip_pstsShowUnderLine, showUnderline);
    //      indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    //      underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    //      dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    //      indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight);
    //      underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight);
    //      dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding);
    //      tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    //      tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId);
    //      shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    //      scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    //      textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    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;
    }
}

From source file:com.mixiaoxiao.mxxedgeeffect.widget.MxxPagerTitleStrip.java

public MxxPagerTitleStrip(Context context, AttributeSet attrs) {
    super(context, attrs);

    addView(mPrevText = new TextView(context));
    addView(mCurrText = new TextView(context));
    addView(mNextText = new TextView(context));

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    final int textAppearance = a.getResourceId(0, 0);
    if (textAppearance != 0) {
        mPrevText.setTextAppearance(context, textAppearance);
        mCurrText.setTextAppearance(context, textAppearance);
        mNextText.setTextAppearance(context, textAppearance);
    }//from w w w  . ja  v  a  2  s  . c  om
    final int textSize = a.getDimensionPixelSize(1, 0);
    if (textSize != 0) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    if (a.hasValue(2)) {
        final int textColor = a.getColor(2, 0);
        mPrevText.setTextColor(textColor);
        mCurrText.setTextColor(textColor);
        mNextText.setTextColor(textColor);
    }
    mGravity = a.getInteger(3, Gravity.BOTTOM);
    a.recycle();

    mTextColor = mCurrText.getTextColors().getDefaultColor();
    setNonPrimaryAlpha(SIDE_ALPHA);

    mPrevText.setEllipsize(TruncateAt.END);
    mCurrText.setEllipsize(TruncateAt.END);
    mNextText.setEllipsize(TruncateAt.END);

    boolean allCaps = false;
    if (textAppearance != 0) {
        final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS);
        allCaps = ta.getBoolean(0, false);
        ta.recycle();
    }

    if (allCaps) {
        setSingleLineAllCaps(mPrevText);
        setSingleLineAllCaps(mCurrText);
        setSingleLineAllCaps(mNextText);
    } else {
        mPrevText.setSingleLine();
        mCurrText.setSingleLine();
        mNextText.setSingleLine();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    mScaledTextSpacing = (int) (TEXT_SPACING * density);
    mCircleIndicator = new CircleIndicator(context, attrs);
    addView(mCircleIndicator);
}

From source file:com.marshalchen.common.uimodule.modifysys.PagerTitleStrip.java

public PagerTitleStrip(Context context, AttributeSet attrs) {
    super(context, attrs);

    addView(mPrevText = new TextView(context));
    addView(mCurrText = new TextView(context));
    addView(mNextText = new TextView(context));

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    final int textAppearance = a.getResourceId(0, 0);
    if (textAppearance != 0) {
        mPrevText.setTextAppearance(context, textAppearance);
        mCurrText.setTextAppearance(context, textAppearance);
        mNextText.setTextAppearance(context, textAppearance);
    }//  www  . j a  v a  2s  . c  o  m
    final int textSize = a.getDimensionPixelSize(1, 0);
    if (textSize != 0) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    if (a.hasValue(2)) {
        final int textColor = a.getColor(2, 0);
        mPrevText.setTextColor(textColor);
        mCurrText.setTextColor(textColor);
        mNextText.setTextColor(textColor);
    }
    mGravity = a.getInteger(3, Gravity.CENTER);
    a.recycle();

    mTextColor = mCurrText.getTextColors().getDefaultColor();
    setNonPrimaryAlpha(SIDE_ALPHA);

    mPrevText.setEllipsize(TruncateAt.END);
    mCurrText.setEllipsize(TruncateAt.END);
    mNextText.setEllipsize(TruncateAt.END);

    boolean allCaps = false;
    if (textAppearance != 0) {
        final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS);
        allCaps = ta.getBoolean(0, false);
        ta.recycle();
    }

    if (allCaps) {
        setSingleLineAllCaps(mPrevText);
        setSingleLineAllCaps(mCurrText);
        setSingleLineAllCaps(mNextText);
    } else {
        mPrevText.setSingleLine();
        mCurrText.setSingleLine();
        mNextText.setSingleLine();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    mScaledTextSpacing = (int) (TEXT_SPACING * density);
}

From source file:com.android.launcher3.BubbleTextView.java

public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mLauncher = Launcher.getLauncher(context);
    DeviceProfile grid = mLauncher.getDeviceProfile();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BubbleTextView, defStyle, 0);
    mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, true);
    mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
    mDeferShadowGenerationOnTouch = a.getBoolean(R.styleable.BubbleTextView_deferShadowGeneration, false);

    int display = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
    int defaultIconSize = grid.iconSizePx;
    if (display == DISPLAY_WORKSPACE) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
    } else if (display == DISPLAY_ALL_APPS) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
        setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
        defaultIconSize = grid.allAppsIconSizePx;
    } else if (display == DISPLAY_FOLDER) {
        setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
    }/*from  ww w. ja va2 s  . c o  m*/
    mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);

    if (Utilities.getIconSizePrefEnabled(context) == -1) {
        mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride, defaultIconSize);
        Utilities.setIconSizeValue(context, mIconSize);
        a.recycle();
    } else {
        mIconSize = Utilities.getIconSizePrefEnabled(context);
    }

    if (mCustomShadowsEnabled) {
        // Draw the background itself as the parent is drawn twice.
        mBackground = getBackground();
        setBackground(null);

        // Set shadow layer as the larger shadow to that the textView does not clip the shadow.
        float density = getResources().getDisplayMetrics().density;
        setShadowLayer(density * AMBIENT_SHADOW_RADIUS, 0, 0, AMBIENT_SHADOW_COLOR);
    } else {
        mBackground = null;
    }

    mLongPressHelper = new CheckLongPressHelper(this);
    mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);

    mOutlineHelper = HolographicOutlineHelper.obtain(getContext());
    setAccessibilityDelegate(mLauncher.getAccessibilityDelegate());

}

From source file:com.orangemoo.com.beta.widget.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);/*from   w  w  w  .  ja  v a 2s . co  m*/
    //        textView.setBackgroundResource(R.drawable.view_pager_tab_background);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    textView.setOnLongClickListener(new OnTabLongClickListener(position));

    // 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.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.pipit.agc.adapter.DayPickerAdapter.java

private void refitText(TextView txtv, int targetheight) {
    if (targetheight <= 0)
        return;/* w w  w  .  ja  v a  2  s .c  om*/
    Paint mTestPaint = new Paint();
    mTestPaint.set(txtv.getPaint());
    float hi = 100;
    float lo = 2;
    final float threshold = 0.5f; // How close we have to be

    while ((hi - lo) > threshold) {
        float size = (hi + lo) / 2;
        mTestPaint.setTextSize(size);
        if (mTestPaint.measureText((String) txtv.getText()) >= targetheight)
            hi = size; // too big
        else
            lo = size; // too small
    }
    // Use lo so that we undershoot rather than overshoot
    txtv.setTextSize(TypedValue.COMPLEX_UNIT_PX, lo);
}

From source file:com.chenupt.springindicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<TextView>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null) {
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        }/*from   w  ww .j a v a  2 s .c  om*/
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0) {
            textView.setBackgroundResource(textBgResId);
        }
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:net.zionsoft.obadiah.ui.adapters.TranslationListAdapter.java

private View getHeaderView(int position, View convertView, ViewGroup parent) {
    final TextView textView = (TextView) (convertView == null
            ? mInflater.inflate(R.layout.item_translation_section, parent, false)
            : convertView);/*  w  ww .ja  v  a2s . c om*/
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    textView.setText((String) getItem(position));
    return textView;
}

From source file:android.view.SpringIndicator.java

private void addTabItems() {
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        final TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null)
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0)
            textView.setBackgroundResource(textBgResId);
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override/*from w w w  .j  av  a2s. c o m*/
            public void onClick(final View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position))
                    viewPager.setCurrentItem(position);
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}