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:mx.udlap.is522.tedroid.activity.ScoresActivity.java

/** Aplica el tema estilo secundario */
private void applySecondaryStyleTo(TextView textView) {
    textView.setTextColor(secondaryColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, secondaryTextSize);
    textView.setTypeface(twobitTypeface);
    textView.setLayoutParams(layoutParams);
}

From source file:com.android.messaging.ui.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);/*from   www.  ja v  a  2s.co  m*/
    textView.setBackgroundResource(R.drawable.contact_picker_tab_background_selector);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(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(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.frozendevs.periodictable.view.ViewPagerTabs.java

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

    /* We don't need this as far as we use text tabs only
    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);
    }
    if (mTextBackground > 0) {
        textView.setBackgroundResource(mTextBackground);
    }
    textView.setText(
            textView.getText().toString().toUpperCase(getContext().getResources().getConfiguration().locale));
    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:net.cpacm.library.indicator.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<>();
    int count = viewPager.getAdapter().getCount();
    if (viewPager.getAdapter() instanceof InfinitePagerAdapter) {
        count = ((InfinitePagerAdapter) viewPager.getAdapter()).getRealCount();
    }//from w  ww.j a v  a  2  s . c o m
    for (int i = 0; i < count; i++) {
        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);
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:com.webarch.srmobile.activities.sub.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  w w . ja  v a2s .c  o  m
 */
protected TextView createDefaultTabView(Context context) {
    Text text = new Text(context, null);
    text.setGravity(Gravity.CENTER);
    Resources resources = getResources();
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.text_2));
    text.setTextColor(resources.getColor(R.color.dark));
    int border1 = (int) resources.getDimension(R.dimen.border_1),
            border2 = (int) resources.getDimension(R.dimen.border_2);
    text.setPadding(border1, border2, border1, border2);
    return text;
}

From source file:com.gosuncn.core.percentlayout.PercentLayoutHelper.java

/**
 * Iterates over children and changes their width and height to one
 * calculated from percentage values.//from  w w  w  .  j a  va 2s.c  o  m
 * 
 * @param widthMeasureSpec
 *            Width MeasureSpec of the parent ViewGroup.
 * @param heightMeasureSpec
 *            Height MeasureSpec of the parent ViewGroup.
 */
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG,
                "adjustChildren: " + mHost + " widthMeasureSpec: " + View.MeasureSpec.toString(widthMeasureSpec)
                        + " heightMeasureSpec: " + View.MeasureSpec.toString(heightMeasureSpec));
    }
    int widthHint = View.MeasureSpec.getSize(widthMeasureSpec);
    int heightHint = View.MeasureSpec.getSize(heightMeasureSpec);

    Log.d(TAG, "widthHint = " + widthHint + " , heightHint = " + heightHint);
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "should adjust " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                // 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);
                    }
                }
                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.fillMarginLayoutParams((ViewGroup.MarginLayoutParams) params, widthHint, heightHint);
                } else {
                    info.fillLayoutParams(params, widthHint, heightHint);
                }
            }
        }
    }
}

From source file:com.auth0.android.lock.views.FormLayout.java

private void addSeparator() {
    orSeparatorMessage = new LineSpacingTextView(getContext());
    orSeparatorMessage.setText(R.string.com_auth0_lock_forms_separator);
    orSeparatorMessage.setTextColor(ContextCompat.getColor(getContext(), R.color.com_auth0_lock_text));
    orSeparatorMessage.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimension(R.dimen.com_auth0_lock_title_text));
    orSeparatorMessage.setGravity(Gravity.CENTER);
    int verticalPadding = getResources()
            .getDimensionPixelSize(R.dimen.com_auth0_lock_widget_vertical_margin_field);
    orSeparatorMessage.setPadding(0, verticalPadding, 0, verticalPadding);
    formsHolder.addView(orSeparatorMessage, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
}

From source file:odoo.controls.OSelectionField.java

@Override
public void initControl() {
    final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    removeAllViews();//ww  w. j  a  va  2s  .c  o  m
    setOrientation(VERTICAL);
    createItems();
    if (isEditable()) {
        if (mWidget != null) {
            switch (mWidget) {
            case RadioGroup:
                createRadioGroup();
                return;
            case SelectionDialog:
                txvView = new TextView(mContext);
                txvView.setLayoutParams(params);
                mAdapter = new SpinnerAdapter(mContext, android.R.layout.simple_list_item_1, items);
                setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        AlertDialog dialog = createSelectionDialog(getPos(), items, params);
                        txvView.setTag(dialog);
                        dialog.show();
                    }
                });
                if (textSize > -1) {
                    txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                }
                if (appearance > -1) {
                    txvView.setTextAppearance(mContext, appearance);
                }
                txvView.setTextColor(textColor);
                addView(txvView);
                return;
            case Searchable:
            case SearchableLive:
                txvView = new TextView(mContext);
                txvView.setLayoutParams(params);
                setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        startSearchableActivity();
                    }
                });
                if (textSize > -1) {
                    txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                }
                if (appearance > -1) {
                    txvView.setTextAppearance(mContext, appearance);
                }
                txvView.setTextColor(textColor);
                addView(txvView);
                return;
            default:
                break;
            }
        }

        // Default View
        mSpinner = new Spinner(mContext);
        mSpinner.setLayoutParams(params);
        mAdapter = new SpinnerAdapter(mContext, android.R.layout.simple_list_item_1, items);
        mSpinner.setAdapter(mAdapter);
        mSpinner.setOnItemSelectedListener(this);
        addView(mSpinner);
    } else {
        setOnClickListener(null);
        txvView = new TextView(mContext);
        if (textSize > -1) {
            txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            txvView.setTextAppearance(mContext, appearance);
        }
        txvView.setTextColor(textColor);
        addView(txvView);
    }
}

From source file:nl.atcomputing.refcard.tabs.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 w  w w .j a  va2  s  . c  o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    Resources resources = getResources();
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.textSizeSmall));
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(resources.getColor(R.color.atwhite_secondarytext));

    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 * resources.getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.wjwu.wpmain.view.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 a  v  a  2 s .  c om*/
 */
protected TextView createDefaultTabView(Context context) {
    float density = getResources().getDisplayMetrics().density;
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, TAB_VIEW_TEXT_SIZE_DP * density);
    //        textView.setTypeface(Typeface.DEFAULT_BOLD);
    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);
    }

    ColorStateList csl = context.getResources()
            .getColorStateList(ThemeAttrTools.getValueOfColorAttr(context, R.attr.c_txt_catalog));
    if (csl != null) {
        textView.setTextColor(csl);
    }

    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 * density);
    int tabHeight = getResources().getDimensionPixelSize(R.dimen.z_slidingtab_height);
    int paddingTop = (int) (tabHeight - TAB_VIEW_TEXT_SIZE_DP * density - density) / 2;
    textView.setPadding(padding, paddingTop, padding, paddingTop);
    return textView;
}