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.example.QQReader.OpenSourceWidget.astuetz.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);
        }/* w w  w  .  j  a  v  a 2s .  co  m*/
    }

}

From source file:info.guardianproject.notepadbot.NoteEdit.java

private void populateFields(Cursor note) {
    try {//from w  w  w .  j  av a2 s. c  o m
        if (note == null)
            return;

        mBlob = note.getBlob(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_DATA));

        mMimeType = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TYPE));

        if (mMimeType == null)
            mMimeType = "text/plain";

        boolean isImage = mMimeType.startsWith("image");

        if (isImage) {

            // Load up the image's dimensions not the image itself
            BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();

            if (mBlob.length > 100000)
                bmpFactoryOptions.inSampleSize = 4;
            else
                bmpFactoryOptions.inSampleSize = 2;

            Bitmap blobb = BitmapFactory.decodeByteArray(mBlob, 0, mBlob.length, bmpFactoryOptions);

            mImageView.setImageBitmap(blobb);
            mImageView.setVisibility(View.VISIBLE);

        } else {

            mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));

            // Focus by default on the body of the note
            mBodyText.requestFocus();
            mBodyText.setSelection(mBodyText.length());

            if (mTextSize != 0)
                mBodyText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
            mImageView.setVisibility(View.GONE);
        }

        mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
        note.close();

    } catch (Exception e) {
        Log.e("notepadbot", "error populating", e);
        Toast.makeText(this, getString(R.string.err_loading_note, e.getMessage()), Toast.LENGTH_LONG).show();
    }
}

From source file:org.mindframes.latestfm.ui.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)}./*  www. j  a  v a2s  .  c o m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(getResources().getColor(R.color.white));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, TEXT_SIZE);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setBackgroundColor(getResources().getColor(R.color.transparent));

    textView.setTextColor(getResources().getColorStateList(R.color.sliding_tab_text));

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

    textView.setPadding(HORIZONTAL_PADDING, 0, HORIZONTAL_PADDING, 0);
    return textView;
}

From source file:com.kkbox.toolkit.app.KKTabFragment.java

protected void initView(View view, int[] buttonTextResourcetId, boolean showSubFragmentAnimation,
        int currentIndex) {
    fixStateForNestedFragment();/*from w  ww  .  ja va2s . c om*/
    initView(view);
    if (this.currentIndex == -1) {
        this.currentIndex = currentIndex;
    }
    this.showSubFragmentAnimation = showSubFragmentAnimation;
    radioGroup = (RadioGroup) view.findViewById(R.id.button_radiogroup);

    TypedValue typedValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.KKTabFragmentStyle, typedValue, true);
    TypedArray array = getActivity().obtainStyledAttributes(typedValue.resourceId,
            new int[] { R.attr.KKTabButtonBackgroundLeft, R.attr.KKTabButtonBackgroundMiddle,
                    R.attr.KKTabButtonBackgroundRight });
    int tabButtonBackgroundLeftResourceId = array.getResourceId(0, -1);
    int tabButtonBackgroundMiddleResourceId = array.getResourceId(1, -1);
    int tabButtonBackgroundRightResourceId = array.getResourceId(2, -1);
    array.recycle();
    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { R.attr.KKTabBackground });
    int backgroundResourceId = array.getResourceId(0, -1);
    FrameLayout layoutRadioBar = (FrameLayout) view.findViewById(R.id.layout_radio_bar);
    if (backgroundResourceId != -1) {
        layoutRadioBar.setBackgroundResource(backgroundResourceId);
    }
    array.recycle();

    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { R.attr.KKTabOverlay });
    int overlayResourceId = array.getResourceId(0, -1);
    ImageView viewOverlay = (ImageView) view.findViewById(R.id.view_overlay);
    if (overlayResourceId != -1) {
        viewOverlay.setBackgroundResource(overlayResourceId);
    }
    array.recycle();

    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.textSize });
    int textSize = array.getDimensionPixelSize(0, -1);
    array.recycle();
    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.textColor });
    ColorStateList textColor = array.getColorStateList(0);
    array.recycle();
    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.height });
    int height = array.getDimensionPixelSize(0, -1);
    array.recycle();
    for (int i = 0; i < buttonTextResourcetId.length; i++) {
        RadioButton radioButton = new RadioButton(getActivity());
        if (i == 0 && tabButtonBackgroundLeftResourceId != -1) {
            radioButton.setBackgroundResource(tabButtonBackgroundLeftResourceId);
        } else if (i == buttonTextResourcetId.length - 1 && tabButtonBackgroundRightResourceId != -1) {
            radioButton.setBackgroundResource(tabButtonBackgroundRightResourceId);
        } else if (tabButtonBackgroundMiddleResourceId != -1) {
            radioButton.setBackgroundResource(tabButtonBackgroundMiddleResourceId);
        }
        radioButton.setText(buttonTextResourcetId[i]);
        radioButton.setButtonDrawable(new StateListDrawable());
        radioButton.setGravity(Gravity.CENTER);
        radioButton.setTextColor(textColor);
        radioButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        radioButton.setLayoutParams(new RadioGroup.LayoutParams(0, height, 1));
        radioButton.setOnClickListener(buttonClickListener);
        radioGroup.addView(radioButton);
    }
    currentFragment = null;
    radioGroup.getChildAt(this.currentIndex).performClick();

}

From source file:com.facebook.react.views.textinput.ReactTextInputManager.java

@ReactProp(name = ViewProps.FONT_SIZE, defaultFloat = ViewDefaults.FONT_SIZE_SP)
public void setFontSize(ReactEditText view, float fontSize) {
    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, (int) Math.ceil(PixelUtil.toPixelFromSP(fontSize)));
}

From source file:com.tortel.deploytrack.fragments.DeploymentFragment.java

@SuppressLint("CutPasteId")
private void setUpTextViews(View view) {
    float density = getResources().getDisplayMetrics().density;
    TextView commaView = (TextView) view.findViewById(R.id.comma);
    mDateRangeView = (TextView) view.findViewById(R.id.daterange);

    TextView main = (TextView) view.findViewById(R.id.main);
    TextView second = (TextView) view.findViewById(R.id.second);
    TextView third = (TextView) view.findViewById(R.id.third);

    switch (Prefs.getMainDisplayType()) {
    case Prefs.ViewTypes.PERCENT:
        mAnimatorType = Prefs.ViewTypes.PERCENT;
        mPercentView = main;//from  w w w  .ja  v  a  2  s. com
        mCompletedView = second;
        mRemainingView = third;
        break;
    case Prefs.ViewTypes.COMPLETE:
        mAnimatorType = Prefs.ViewTypes.COMPLETE;
        mCompletedView = main;
        mCompletedView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mCompletedView.getTextSize() - density * 20f);
        mPercentView = second;
        mRemainingView = third;
        break;
    case Prefs.ViewTypes.REMAINING:
        mAnimatorType = Prefs.ViewTypes.REMAINING;
        mRemainingView = main;
        mRemainingView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mRemainingView.getTextSize() - density * 10f);
        mPercentView = second;
        mCompletedView = third;
        break;
    }

    if (Prefs.hideDate()) {
        mDateRangeView.setVisibility(View.GONE);
    }

    // Just hide days
    if (Prefs.hideDays() && !Prefs.hidePercent()) {
        mPercentView = main;
        mAnimatorType = Prefs.ViewTypes.PERCENT;

        // Make sure nothing else is set to main
        mCompletedView = second;
        mRemainingView = second;
        second.setVisibility(View.GONE);
        third.setVisibility(View.GONE);
        commaView.setVisibility(View.GONE);
        return;
    }

    // Just hide percent
    if (Prefs.hidePercent() && !Prefs.hideDays()) {
        mPercentView.setVisibility(View.GONE);
        if (Prefs.getMainDisplayType() != Prefs.ViewTypes.PERCENT) {
            // Hide the comma too
            commaView.setVisibility(View.GONE);
        }
        return;
    }

    // If both are hidden, hide it all
    if (Prefs.hideDays() && Prefs.hidePercent()) {
        commaView.setVisibility(View.GONE);
        main.setVisibility(View.GONE);
        second.setVisibility(View.GONE);
        third.setVisibility(View.GONE);
    }
}

From source file:mx.udlap.is522.tedroid.activity.ScoresActivity.java

/** Aplica el tema estilo primario. */
private void applyPrimaryStyleTo(TextView textView) {
    textView.setTextColor(primaryColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, primaryTextSize);
    textView.setTypeface(twobitTypeface);
    textView.setLayoutParams(layoutParams);
}

From source file:mobileSoft.library.android.components.slidingtabs.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  v a 2s . c  o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);

    // TODO SFS
    // textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, this.textSize);
    // textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    // TODO SFS
    // textView.setAllCaps(true);
    textView.setTextColor(this.textColor);

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

    return textView;
}

From source file:org.chaos.fx.cnbeta.details.DetailsFragment.java

private void scaleTextSize(TextView v, float relativeSize) {
    v.setTextSize(TypedValue.COMPLEX_UNIT_PX, v.getTextSize() * relativeSize);
}

From source file:com.negaheno.ui.Components.PagerSlidingTabStrip.java

private void updateTabStyles() {

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

        View v = tabsContainer.getChildAt(i);

        v.setLayoutParams(defaultTabLayoutParams);
        v.setBackgroundResource(tabBackgroundResId);
        if (shouldExpand) {
            v.setPadding(0, 0, 0, 0);//w w  w .  j  a  va  2s. c  o m
            v.setLayoutParams(new LinearLayout.LayoutParams(-1, -1, 1.0F));
        } else {
            v.setPadding(tabPadding, 0, tabPadding, 0);
        }

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